diff --git a/.hgignore b/.hgignore index 776ca1b5..94d6c873 100644 --- a/.hgignore +++ b/.hgignore @@ -7,3 +7,4 @@ syntax: regexp ^seminaryuploads/* ^www/analytics/config/config.ini.php* ^www/analytics/temp/* +^app/lib/phpqrcode/cache/* diff --git a/agents/intermediate/CharactergroupsqueststationsAgent.inc b/agents/intermediate/CharactergroupsqueststationsAgent.inc new file mode 100644 index 00000000..9de435b3 --- /dev/null +++ b/agents/intermediate/CharactergroupsqueststationsAgent.inc @@ -0,0 +1,103 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\agents\intermediate; + + + /** + * Agent to display Character groups Quest stations. + * + * @author Oliver Hanraths + */ + class CharactergroupsqueststationsAgent extends \nre\agents\IntermediateAgent + { + + + + + /** + * Action: index. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function index(\nre\core\Request $request, \nre\core\Response $response) + { + } + + + /** + * Action: station. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function station(\nre\core\Request $request, \nre\core\Response $response) + { + // Add Moodpic + $this->addSubAgent('Moodpic', 'seminary', $request->getParam(3), 'charactergroups'); + } + + + /** + * Action: create. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function create(\nre\core\Request $request, \nre\core\Response $response) + { + // Add Moodpic + $this->addSubAgent('Moodpic', 'seminary', $request->getParam(3), 'charactergroups'); + } + + + /** + * Action: edit. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function edit(\nre\core\Request $request, \nre\core\Response $response) + { + // Add Moodpic + $this->addSubAgent('Moodpic', 'seminary', $request->getParam(3), 'charactergroups'); + } + + + /** + * Action: edittask. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function edittask(\nre\core\Request $request, \nre\core\Response $response) + { + // Add Moodpic + $this->addSubAgent('Moodpic', 'seminary', $request->getParam(3), 'charactergroups'); + } + + + /** + * Action: delete. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function delete(\nre\core\Request $request, \nre\core\Response $response) + { + // Add Moodpic + $this->addSubAgent('Moodpic', 'seminary', $request->getParam(3), 'charactergroups'); + } + + } + +?> diff --git a/agents/intermediate/QrAgent.inc b/agents/intermediate/QrAgent.inc new file mode 100644 index 00000000..89314a46 --- /dev/null +++ b/agents/intermediate/QrAgent.inc @@ -0,0 +1,38 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\agents\intermediate; + + + /** + * Agent to redirect to a page from a (short) QR-code link. + * + * @author Oliver Hanraths + */ + class QrAgent extends \nre\agents\IntermediateAgent + { + + + + + /** + * Action: index. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function index(\nre\core\Request $request, \nre\core\Response $response) + { + } + + } + +?> diff --git a/agents/intermediate/QrcodesAgent.inc b/agents/intermediate/QrcodesAgent.inc new file mode 100644 index 00000000..45a15782 --- /dev/null +++ b/agents/intermediate/QrcodesAgent.inc @@ -0,0 +1,38 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\agents\intermediate; + + + /** + * Agent to generate and show QR-codes. + * + * @author Oliver Hanraths + */ + class QrcodesAgent extends \nre\agents\IntermediateAgent + { + + + + + /** + * Action: index. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function index(\nre\core\Request $request, \nre\core\Response $response) + { + } + + } + +?> diff --git a/app/agents/StationtypeAgent.inc b/app/agents/StationtypeAgent.inc new file mode 100644 index 00000000..5598afb5 --- /dev/null +++ b/app/agents/StationtypeAgent.inc @@ -0,0 +1,298 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\agents; + + + /** + * Abstract class for implementing a StationtypeAgent. + * + * @author Oliver Hanraths + */ + abstract class StationtypeAgent extends \nre\agents\BottomlevelAgent + { + /** + * Current request + * + * @var \nre\core\Request + */ + private $request; + /** + * Current response + * + * @var \nre\core\Response + */ + private $response; + + + + + /** + * Load a StationtypeAgent. + * + * @static + * @throws \hhu\z\exceptions\StationtypeAgentNotFoundException + * @throws \hhu\z\exceptions\StationtypeAgentNotValidException + * @param string $stationtypeName Name of the StationtypeAgent to load + */ + public static function load($stationtypeName) + { + // Determine full classname + $className = self::getClassName($stationtypeName); + + try { + // Load class + static::loadClass($stationtypeName, $className); + + // Validate class + static::checkClass($className, get_class()); + } + catch(\nre\exceptions\ClassNotValidException $e) { + throw new \hhu\z\exceptions\StationtypeAgentNotValidException($e->getClassName()); + } + catch(\nre\exceptions\ClassNotFoundException $e) { + throw new \hhu\z\exceptions\StationtypeAgentNotFoundException($e->getClassName()); + } + } + + + /** + * Instantiate a StationtypeAgent (Factory Pattern). + * + * @static + * @throws \nre\exceptions\DatamodelException + * @throws \nre\exceptions\DriverNotValidException + * @throws \nre\exceptions\DriverNotFoundException + * @throws \nre\exceptions\ViewNotFoundException + * @throws \hhu\z\exceptions\StationtypeModelNotValidException + * @throws \hhu\z\exceptions\StationtypeModelNotFoundException + * @throws \hhu\z\exceptions\StationtypeControllerNotValidException + * @throws \hhu\z\exceptions\StationtypeControllerNotFoundException + * @param string $stationtypeName Name of the StationtypeAgent to instantiate + * @param Request $request Current request + * @param Response $response Current respone + * @param Logger $log Log-system + */ + public static function factory($stationtypeName, \nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null) + { + // Determine full classname + $className = self::getClassName($stationtypeName); + + // Construct and return Stationmodule + return new $className($request, $response, $log); + } + + + /** + * Determine the Agent-classname for the given Stationtype-name. + * + * @static + * @param string $stationtypeName Stationtype-name to get Agent-classname of + * @param string $agentType Agent type of given Agent name + * @return string Classname for the Stationtype-name + */ + private static function getClassName($stationtypeName, $agentType=null) + { + $className = \nre\core\ClassLoader::concatClassNames( + $stationtypeName, + \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), + 'agent' + ); + + + return \nre\configs\AppConfig::$app['namespace']."stationtypes\\$className"; + } + + + /** + * Load the class of a StationtypeAgent. + * + * @static + * @throws \nre\exceptions\ClassNotFoundException + * @param string $stationtypeName Name of the StationtypeAgent to load + * @param string $fullClassName Name of the class to load + */ + private static function loadClass($stationtypeName, $fullClassName) + { + // Determine folder to look in + $className = explode('\\', $fullClassName); + $className = array_pop($className); + + // Determine filename + $fileName = ROOT.DS. + \nre\configs\AppConfig::$dirs['stationtypes'].DS. + strtolower($stationtypeName).DS.$className.\nre\configs\CoreConfig::getFileExt('includes'); + + // Check file + if(!file_exists($fileName)) + { + throw new \nre\exceptions\ClassNotFoundException( + $fullClassName + ); + } + + // Include file + include_once($fileName); + } + + + /** + * Check inheritance of the StationtypeAgent-class. + * + * @static + * @throws \nre\exceptions\ClassNotValidException + * @param string $className Name of the class to check + * @param string $parentClassName Name of the parent class + */ + public static function checkClass($className, $parentClassName) + { + // Check if class is subclass of parent class + if(!is_subclass_of($className, $parentClassName)) { + throw new \nre\exceptions\ClassNotValidException( + $className + ); + } + } + + + + + /** + * Construct a new StationtypeAgent. + * + * @throws \nre\exceptions\DatamodelException + * @throws \nre\exceptions\DriverNotValidException + * @throws \nre\exceptions\DriverNotFoundException + * @throws \nre\exceptions\ViewNotFoundException + * @throws \nre\exceptions\ModelNotValidException + * @throws \nre\exceptions\ModelNotFoundException + * @throws \hhu\z\exceptions\StationtypeModelNotValidException + * @throws \hhu\z\exceptions\StationtypeModelNotFoundException + * @throws \hhu\z\exceptions\StationtypeControllerNotValidException + * @throws \hhu\z\exceptions\StationtypeControllerNotFoundException + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + * @param \nre\core\Logger $log Log-system + */ + protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null) + { + // Store values + $this->request = $request; + $this->response = $response; + + + // Call parent constructor + parent::__construct($request, $response, $log); + } + + + + + /** + * Save the answer of a Character group for a Station. + * + * @param array $seminary Current Seminary data + * @param array $questgroup Current Questgroup data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $group Current Character data + * @param array $answers Character answers for the Quest + */ + public function saveAnswer($seminary, $groupsgroup, $quest, $station, $group, $answer) + { + $this->controller->saveAnswer( + $seminary, + $groupsgroup, + $quest, + $station, + $group, + $answer + ); + } + + + /** + * Check if the answer of a Character group for a Station matches the + * correct one. + * + * @param array $seminary Current Seminary data + * @param array $questgroup Current Questgroup data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $group Current Character group data + * @param array $answers Character answers for the Quest + */ + public function matchAnswer($seminary, $groupsgroup, $quest, $station, $group, $answer) + { + return $this->controller->matchAnswer( + $seminary, + $groupsgroup, + $quest, + $station, + $group, + $answer + ); + } + + + + + /** + * Load the Controller of this Agent. + * + * @throws \nre\exceptions\DatamodelException + * @throws \nre\exceptions\DriverNotValidException + * @throws \nre\exceptions\DriverNotFoundException + * @throws \nre\exceptions\ViewNotFoundException + * @throws \nre\exceptions\ModelNotValidException + * @throws \nre\exceptions\ModelNotFoundException + * @throws \hhu\z\exceptions\StationxuesttypeModelNotValidException + * @throws \hhu\z\exceptions\StationtypeModelNotFoundException + * @throws \hhu\z\exceptions\StationtypeControllerNotValidException + * @throws \hhu\z\exceptions\StationtypeControllerNotFoundException + */ + protected function loadController() + { + // Determine Controller name + $controllerName = \nre\core\ClassLoader::stripClassType( + \nre\core\ClassLoader::getClassName(get_class($this)) + ); + + // Determine ToplevelAgent + $toplevelAgentName = $this->response->getParam(0); + if(is_null($toplevelAgentName)) { + $toplevelAgentName = $this->request->getParam(0, 'toplevel'); + $this->response->addParam($toplevelAgentName); + } + + // Determine Action + $action = $this->response->getParam(2); + if(is_null($action)) { + $action = $this->request->getParam(2, 'action'); + $this->response->addParam($action); + } + + + // Load Controller + \hhu\z\controllers\StationtypeController::load($controllerName); + + // Construct Controller + $this->controller = \hhu\z\controllers\StationtypeController::factory( + $controllerName, + $toplevelAgentName, + $action, + $this + ); + } + + } + +?> diff --git a/app/controllers/StationtypeController.inc b/app/controllers/StationtypeController.inc new file mode 100644 index 00000000..00e2d3b1 --- /dev/null +++ b/app/controllers/StationtypeController.inc @@ -0,0 +1,320 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\controllers; + + + /** + * Abstract class for implementing a StationtypeController. + * + * @author Oliver Hanraths + */ + abstract class StationtypeController extends \hhu\z\Controller + { + /** + * Required models + * + * @var array + */ + public $models = array('seminaries'); //, 'questgroups', 'quests', 'characters'); + + + + + + /** + * Save the answer of a Character group for a Station. + * + * @param array $seminary Current Seminary data + * @param array $groupsgroup Current Groups group data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $charactergroup Current Character group data + * @param array $answer Character group answer for the Station + */ + public abstract function saveAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer); + + + /** + * Check if answer of a Character group for a Station matches the correct one. + * + * @param array $seminary Current Seminary data + * @param array $groupsgroup Current Groups group data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $charactergroup Current Character group data + * @param array $answer Character group answer for the Station + * @return boolean True/false for a right/wrong answer + */ + public abstract function matchAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer); + + + /** + * Action: quest. + * + * Show the task of a Station. + * + * @param array $seminary Current Seminary data + * @param array $groupsgroup Current Groups group data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $charactergroup Current Character group data + */ + public abstract function quest($seminary, $groupsgroup, $quest, $station, $charactergroup); + + + /** + * Action: edittask. + * + * Edit the task of a Station. + * + * @param array $seminary Current Seminary data + * @param array $groupsgroup Current Groups group data + * @param array $quest Current Quest data + * @param array $station Current Station data + */ + public abstract function edittask($seminary, $groupsgroup, $quest, $station); + + + + + /** + * Load a StationtypeController. + * + * @static + * @throws \hhu\z\exceptions\StationtypeControllerNotFoundException + * @throws \hhu\z\exceptions\StationtypeControllerNotValidException + * @param string $controllerName Name of the StationtypeController to load + */ + public static function load($controllerName) + { + // Determine full classname + $className = self::getClassName($controllerName); + + try { + // Load class + static::loadClass($controllerName, $className); + + // Validate class + static::checkClass($className, get_class()); + } + catch(\nre\exceptions\ClassNotValidException $e) { + throw new \hhu\z\exceptions\StationtypeControllerNotValidException($e->getClassName()); + } + catch(\nre\exceptions\ClassNotFoundException $e) { + throw new \hhu\z\exceptions\StationtypeControllerNotFoundException($e->getClassName()); + } + } + + + /** + * Instantiate a StationtypeController (Factory Pattern). + * + * @static + * @throws \nre\exceptions\DatamodelException + * @throws \nre\exceptions\DriverNotFoundException + * @throws \nre\exceptions\DriverNotValidException + * @throws \nre\exceptions\ModelNotValidException + * @throws \nre\exceptions\ModelNotFoundException + * @throws \nre\exceptions\ViewNotFoundException + * @throws \hhu\z\exceptions\StationtypeModelNotValidException + * @throws \hhu\z\exceptions\StationtypeModelNotFoundException + * @param string $controllerName Name of the StationtypeController to instantiate + * @param string $layoutName Name of the current Layout + * @param string $action Current Action + * @param \nre\core\Agent $agent Corresponding Agent + */ + public static function factory($controllerName, $layoutName, $action, $agent) + { + // Determine full classname + $className = self::getClassName($controllerName); + + // Construct and return Controller + return new $className($layoutName, $action, $agent); + } + + + /** + * Determine the Controller-classname for the given Stationtype-name. + * + * @static + * @param string $stationtypeName Stationtype-name to get Controller-classname of + * @return string Classname for the Stationtype-name + */ + private static function getClassName($stationtypeName) + { + $className = \nre\core\ClassLoader::concatClassNames( + $stationtypeName, + \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), + 'controller' + ); + + + return \nre\configs\AppConfig::$app['namespace']."stationtypes\\$className"; + } + + + /** + * Load the class of a StationtypeController + * + * @static + * @throws \nre\exceptions\ClassNotFoundException + * @param string $stationtypeName Name of the StationtypeController to load + * @param string $fullClassName Name of the class to load + */ + private static function loadClass($stationtypeName, $fullClassName) + { + // Determine folder to look in + $className = explode('\\', $fullClassName); + $className = array_pop($className); + + // Determine filename + $fileName = ROOT.DS. + \nre\configs\AppConfig::$dirs['stationtypes'].DS. + strtolower($stationtypeName).DS. + $className.\nre\configs\CoreConfig::getFileExt('includes'); + + // Check file + if(!file_exists($fileName)) + { + throw new \nre\exceptions\ClassNotFoundException( + $fullClassName + ); + } + + // Include file + include_once($fileName); + } + + + /** + * Check inheritance of the StationtypeController-class. + * + * @static + * @throws \nre\exceptions\ClassNotValidException + * @param string $className Name of the class to check + * @param string $parentClassName Name of the parent class + */ + public static function checkClass($className, $parentClassName) + { + // Check if class is subclass of parent class + if(!is_subclass_of($className, $parentClassName)) { + throw new \nre\exceptions\ClassNotValidException( + $className + ); + } + } + + + + + /** + * Construct a new application Controller. + * + * @throws \nre\exceptions\DriverNotFoundException + * @throws \nre\exceptions\DriverNotValidException + * @throws \nre\exceptions\ModelNotValidException + * @throws \nre\exceptions\ModelNotFoundException + * @throws \nre\exceptions\ViewNotFoundException + * @throws \hhu\z\exceptions\StationtypeModelNotValidException + * @throws \hhu\z\exceptions\StationtypeModelNotFoundException + * @param string $layoutName Name of the current Layout + * @param string $action Current Action + * @param Agent $agent Corresponding Agent + */ + public function __construct($layoutName, $action, $agent) + { + parent::__construct($layoutName, $action, $agent); + } + + + + + /** + * Load the Models of this Controller. + * + * @throws \nre\exceptions\DatamodelException + * @throws \nre\exceptions\DriverNotFoundException + * @throws \nre\exceptions\DriverNotValidException + * @throws \nre\exceptions\ModelNotValidException + * @throws \nre\exceptions\ModelNotFoundException + * @throws \hhu\z\exceptions\StationtypeModelNotValidException + * @throws \hhu\z\exceptions\StationtypeModelNotFoundException + */ + protected function loadModels() + { + // Load default models + parent::loadModels(); + + // Load StationtypeModel + $this->loadModel(); + } + + + /** + * Load the Model of the Stationtype. + * + * @throws \hhu\z\exceptions\StationtypeModelNotValidException + * @throws \hhu\z\exceptions\StationtypeModelNotFoundException + */ + private function loadModel() + { + // Determine Model + $model = \nre\core\ClassLoader::stripClassType( + \nre\core\ClassLoader::stripClassType( + \nre\core\ClassLoader::stripNamespace( + get_class($this) + ) + ) + ); + + // Load class + \hhu\z\models\StationtypeModel::load($model); + + // Construct Model + $modelName = ucfirst(strtolower($model)); + $this->$modelName = \hhu\z\models\StationtypeModel::factory($model); + } + + + /** + * Load the View of this StationtypeController. + * + * @throws \nre\exceptions\ViewNotFoundException + * @param string $layoutName Name of the current Layout + * @param string $action Current Action + */ + protected function loadView($layoutName, $action) + { + // Check Layout name + if(is_null($layoutName)) { + return; + } + + // Determine controller name + $controllerName = \nre\core\ClassLoader::stripClassType( + \nre\core\ClassLoader::getClassName( + get_class($this) + ) + ); + + + // Load view + $this->view = \hhu\z\views\StationtypeView::loadAndFactory( + $layoutName, + $controllerName, + $action + ); + } + + } + +?> diff --git a/app/exceptions/StationtypeAgentNotFoundException.inc b/app/exceptions/StationtypeAgentNotFoundException.inc new file mode 100644 index 00000000..90347b40 --- /dev/null +++ b/app/exceptions/StationtypeAgentNotFoundException.inc @@ -0,0 +1,79 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\exceptions; + + + /** + * Exception: StationtypeAgent not found. + * + * @author Oliver Hanraths + */ + class StationtypeAgentNotFoundException extends \nre\core\Exception + { + /** + * Error code + * + * @var int + */ + const CODE = 401; + /** + * Error message + * + * @var string + */ + const MESSAGE = 'StationtypeAgent not found'; + + /** + * Name of the class that was not found + * + * @var string + */ + private $stationtypeName; + + + + + /** + * Construct a new exception. + * + * @param string $stationtypeName Name of the StationtypeAgent that was not found + * @param string $message Error message + * @param int $code Error code + */ + function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE) + { + parent::__construct( + $message, + $code, + $stationtypeName + ); + + // Store values + $this->stationtypeName = $stationtypeName; + } + + + + + /** + * Get the name of the StationtypeAgent that was not found. + * + * @return string Name of the StationtypeAgent that was not found + */ + public function getClassName() + { + return $this->stationtypeName; + } + + } + +?> diff --git a/app/exceptions/StationtypeAgentNotValidException.inc b/app/exceptions/StationtypeAgentNotValidException.inc new file mode 100644 index 00000000..26ed5f96 --- /dev/null +++ b/app/exceptions/StationtypeAgentNotValidException.inc @@ -0,0 +1,79 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\exceptions; + + + /** + * Exception: StationtypeAgent not valid. + * + * @author Oliver Hanraths + */ + class StationtypeAgentNotValidException extends \nre\core\Exception + { + /** + * Error code + * + * @var int + */ + const CODE = 402; + /** + * Error message + * + * @var string + */ + const MESSAGE = 'StationtypeAgent not valid'; + + /** + * Name of the invalid class + * + * @var string + */ + private $stationtypeName; + + + + + /** + * Construct a new exception. + * + * @param string $stationtypeName Name of the invalid StationtypeAgent + * @param string $message Error message + * @param int $code Error code + */ + function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE) + { + parent::__construct( + $message, + $code, + $stationtypeName + ); + + // Store value + $this->stationtypeName = $stationtypeName; + } + + + + + /** + * Get the name of the invalid StationtypeAgent. + * + * @return string Name of the invalid StationtypeAgent + */ + public function getClassName() + { + return $this->stationtypeName; + } + + } + +?> diff --git a/app/exceptions/StationtypeControllerNotFoundException.inc b/app/exceptions/StationtypeControllerNotFoundException.inc new file mode 100644 index 00000000..063fc9c9 --- /dev/null +++ b/app/exceptions/StationtypeControllerNotFoundException.inc @@ -0,0 +1,79 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\exceptions; + + + /** + * Exception: StationtypeController not found. + * + * @author Oliver Hanraths + */ + class StationtypeControllerNotFoundException extends \nre\core\Exception + { + /** + * Error code + * + * @var int + */ + const CODE = 403; + /** + * Error message + * + * @var string + */ + const MESSAGE = 'StationtypeController not found'; + + /** + * Name of the class that was not found + * + * @var string + */ + private $stationtypeName; + + + + + /** + * Construct a new exception. + * + * @param string $stationtypeName Name of the StationtypeController that was not found + * @param string $message Error message + * @param int $code Error code + */ + function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE) + { + parent::__construct( + $message, + $code, + $stationtypeName + ); + + // Store values + $this->stationtypeName = $stationtypeName; + } + + + + + /** + * Get the name of the StationtypeController that was not found. + * + * @return string Name of the StationtypeController that was not found + */ + public function getClassName() + { + return $this->stationtypeName; + } + + } + +?> diff --git a/app/exceptions/StationtypeControllerNotValidException.inc b/app/exceptions/StationtypeControllerNotValidException.inc new file mode 100644 index 00000000..7bba0e1f --- /dev/null +++ b/app/exceptions/StationtypeControllerNotValidException.inc @@ -0,0 +1,79 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\exceptions; + + + /** + * Exception: StationtypeController not valid. + * + * @author Oliver Hanraths + */ + class StationtypeControllerNotValidException extends \nre\core\Exception + { + /** + * Error code + * + * @var int + */ + const CODE = 404; + /** + * Error message + * + * @var string + */ + const MESSAGE = 'StationtypeController not valid'; + + /** + * Name of the invalid class + * + * @var string + */ + private $stationtypeName; + + + + + /** + * Construct a new exception. + * + * @param string $stationtypeName Name of the invalid StationtypeController + * @param string $message Error message + * @param int $code Error code + */ + function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE) + { + parent::__construct( + $message, + $code, + $stationtypeName + ); + + // Store value + $this->stationtypeName = $stationtypeName; + } + + + + + /** + * Get the name of the invalid StationtypeController. + * + * @return string Name of the invalid StationtypeController + */ + public function getClassName() + { + return $this->stationtypeName; + } + + } + +?> diff --git a/app/exceptions/StationtypeModelNotFoundException.inc b/app/exceptions/StationtypeModelNotFoundException.inc new file mode 100644 index 00000000..5c032e77 --- /dev/null +++ b/app/exceptions/StationtypeModelNotFoundException.inc @@ -0,0 +1,79 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\exceptions; + + + /** + * Exception: StationtypeModel not found. + * + * @author Oliver Hanraths + */ + class StationtypeModelNotFoundException extends \nre\core\Exception + { + /** + * Error code + * + * @var int + */ + const CODE = 405; + /** + * Error message + * + * @var string + */ + const MESSAGE = 'StationtypeModel not found'; + + /** + * Name of the class that was not found + * + * @var string + */ + private $stationtypeName; + + + + + /** + * Construct a new exception. + * + * @param string $stationtypeName Name of the StationtypeModel that was not found + * @param string $message Error message + * @param int $code Error code + */ + function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE) + { + parent::__construct( + $message, + $code, + $stationtypeName + ); + + // Store values + $this->stationtypeName = $stationtypeName; + } + + + + + /** + * Get the name of the StationtypeModel that was not found. + * + * @return string Name of the StationtypeModel that was not found + */ + public function getClassName() + { + return $this->stationtypeName; + } + + } + +?> diff --git a/app/exceptions/StationtypeModelNotValidException.inc b/app/exceptions/StationtypeModelNotValidException.inc new file mode 100644 index 00000000..e9fcd728 --- /dev/null +++ b/app/exceptions/StationtypeModelNotValidException.inc @@ -0,0 +1,79 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\exceptions; + + + /** + * Exception: StationxuesttypeModel not valid. + * + * @author Oliver Hanraths + */ + class StationtypeModelNotValidException extends \nre\core\Exception + { + /** + * Error code + * + * @var int + */ + const CODE = 406; + /** + * Error message + * + * @var string + */ + const MESSAGE = 'StationtypeModel not valid'; + + /** + * Name of the invalid class + * + * @var string + */ + private $stationtypeName; + + + + + /** + * Construct a new exception. + * + * @param string $stationtypeName Name of the invalid StationtypeModel + * @param string $message Error message + * @param int $code Error code + */ + function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE) + { + parent::__construct( + $message, + $code, + $stationtypeName + ); + + // Store value + $this->stationtypeName = $stationtypeName; + } + + + + + /** + * Get the name of the invalid StationtypeModel. + * + * @return string Name of the invalid StationtypeModel + */ + public function getClassName() + { + return $this->stationtypeName; + } + + } + +?> diff --git a/app/lib/Phpqrcode-lib.inc b/app/lib/Phpqrcode-lib.inc new file mode 100644 index 00000000..3728e625 --- /dev/null +++ b/app/lib/Phpqrcode-lib.inc @@ -0,0 +1,33 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\lib; + + + /** + * Class to ensure that Compatibility library below is loaded. + * + * @author Oliver Hanraths + */ + class Phpqrcode + { + + /** + * Call this function to load necessary files. + */ + public static function load() + { + require_once('phpqrcode'.DS.'qrlib.php'); + } + + } + +?> diff --git a/app/lib/Phpqrcode.inc b/app/lib/Phpqrcode.inc new file mode 100644 index 00000000..f47b72ac --- /dev/null +++ b/app/lib/Phpqrcode.inc @@ -0,0 +1,3346 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\lib + { + + + /** + * Class to ensure that Compatibility library below is loaded. + * + * @author Oliver Hanraths + */ + class Phpqrcode + { + + /** + * Call this function to ensure this file is loaded. + */ + public static function load() + { + } + + } + + } + + namespace { + +/* + * PHP QR Code encoder + * + * This file contains MERGED version of PHP QR Code library. + * It was auto-generated from full version for your convenience. + * + * This merged version was configured to not requre any external files, + * with disabled cache, error loging and weker but faster mask matching. + * If you need tune it up please use non-merged version. + * + * For full version, documentation, examples of use please visit: + * + * http://phpqrcode.sourceforge.net/ + * https://sourceforge.net/projects/phpqrcode/ + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + + +/* + * Version: 1.1.4 + * Build: 2010100721 + */ + + + +//---- qrconst.php ----------------------------- + + + + + +/* + * PHP QR Code encoder + * + * Common constants + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + // Encoding modes + + define('QR_MODE_NUL', -1); + define('QR_MODE_NUM', 0); + define('QR_MODE_AN', 1); + define('QR_MODE_8', 2); + define('QR_MODE_KANJI', 3); + define('QR_MODE_STRUCTURE', 4); + + // Levels of error correction. + + define('QR_ECLEVEL_L', 0); + define('QR_ECLEVEL_M', 1); + define('QR_ECLEVEL_Q', 2); + define('QR_ECLEVEL_H', 3); + + // Supported output formats + + define('QR_FORMAT_TEXT', 0); + define('QR_FORMAT_PNG', 1); + + class qrstr { + public static function set(&$srctab, $x, $y, $repl, $replLen = false) { + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); + } + } + + + +//---- merged_config.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Config file, tuned-up for merged verion + */ + + define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there + define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true + define('QR_LOG_DIR', false); // default error logs dir + + define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code + define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false + + define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images + + + + +//---- qrtools.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Toolset, handy and debug utilites. + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRtools { + + //---------------------------------------------------------------------- + public static function binarize($frame) + { + $len = count($frame); + foreach ($frame as &$frameLine) { + + for($i=0; $i<$len; $i++) { + $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; + } + } + + return $frame; + } + + //---------------------------------------------------------------------- + public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037') + { + $barcode_array = array(); + + if (!is_array($mode)) + $mode = explode(',', $mode); + + $eccLevel = 'L'; + + if (count($mode) > 1) { + $eccLevel = $mode[1]; + } + + $qrTab = QRcode::text($code, false, $eccLevel); + $size = count($qrTab); + + $barcode_array['num_rows'] = $size; + $barcode_array['num_cols'] = $size; + $barcode_array['bcode'] = array(); + + foreach ($qrTab as $line) { + $arrAdd = array(); + foreach(str_split($line) as $char) + $arrAdd[] = ($char=='1')?1:0; + $barcode_array['bcode'][] = $arrAdd; + } + + return $barcode_array; + } + + //---------------------------------------------------------------------- + public static function clearCache() + { + self::$frames = array(); + } + + //---------------------------------------------------------------------- + public static function buildCache() + { + QRtools::markTime('before_build_cache'); + + $mask = new QRmask(); + for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { + $frame = QRspec::newFrame($a); + if (QR_IMAGE) { + $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; + QRimage::png(self::binarize($frame), $fileName, 1, 0); + } + + $width = count($frame); + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); + for ($maskNo=0; $maskNo<8; $maskNo++) + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); + } + + QRtools::markTime('after_build_cache'); + } + + //---------------------------------------------------------------------- + public static function log($outfile, $err) + { + if (QR_LOG_DIR !== false) { + if ($err != '') { + if ($outfile !== false) { + file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); + } else { + file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); + } + } + } + } + + //---------------------------------------------------------------------- + public static function dumpMask($frame) + { + $width = count($frame); + for($y=0;$y<$width;$y++) { + for($x=0;$x<$width;$x++) { + echo ord($frame[$y][$x]).','; + } + } + } + + //---------------------------------------------------------------------- + public static function markTime($markerId) + { + list($usec, $sec) = explode(" ", microtime()); + $time = ((float)$usec + (float)$sec); + + if (!isset($GLOBALS['qr_time_bench'])) + $GLOBALS['qr_time_bench'] = array(); + + $GLOBALS['qr_time_bench'][$markerId] = $time; + } + + //---------------------------------------------------------------------- + public static function timeBenchmark() + { + self::markTime('finish'); + + $lastTime = 0; + $startTime = 0; + $p = 0; + + echo ' + + '; + + foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { + if ($p > 0) { + echo ''; + } else { + $startTime = $thisTime; + } + + $p++; + $lastTime = $thisTime; + } + + echo ' + + +
BENCHMARK
till '.$markerId.': '.number_format($thisTime-$lastTime, 6).'s
TOTAL: '.number_format($lastTime-$startTime, 6).'s
'; + } + + } + + //########################################################################## + + QRtools::markTime('start'); + + + + +//---- qrspec.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * QR Code specifications + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * The following data / specifications are taken from + * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) + * or + * "Automatic identification and data capture techniques -- + * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('QRSPEC_VERSION_MAX', 40); + define('QRSPEC_WIDTH_MAX', 177); + + define('QRCAP_WIDTH', 0); + define('QRCAP_WORDS', 1); + define('QRCAP_REMINDER', 2); + define('QRCAP_EC', 3); + + class QRspec { + + public static $capacity = array( + array( 0, 0, 0, array( 0, 0, 0, 0)), + array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 + array( 25, 44, 7, array( 10, 16, 22, 28)), + array( 29, 70, 7, array( 15, 26, 36, 44)), + array( 33, 100, 7, array( 20, 36, 52, 64)), + array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 + array( 41, 172, 7, array( 36, 64, 96, 112)), + array( 45, 196, 0, array( 40, 72, 108, 130)), + array( 49, 242, 0, array( 48, 88, 132, 156)), + array( 53, 292, 0, array( 60, 110, 160, 192)), + array( 57, 346, 0, array( 72, 130, 192, 224)), //10 + array( 61, 404, 0, array( 80, 150, 224, 264)), + array( 65, 466, 0, array( 96, 176, 260, 308)), + array( 69, 532, 0, array( 104, 198, 288, 352)), + array( 73, 581, 3, array( 120, 216, 320, 384)), + array( 77, 655, 3, array( 132, 240, 360, 432)), //15 + array( 81, 733, 3, array( 144, 280, 408, 480)), + array( 85, 815, 3, array( 168, 308, 448, 532)), + array( 89, 901, 3, array( 180, 338, 504, 588)), + array( 93, 991, 3, array( 196, 364, 546, 650)), + array( 97, 1085, 3, array( 224, 416, 600, 700)), //20 + array(101, 1156, 4, array( 224, 442, 644, 750)), + array(105, 1258, 4, array( 252, 476, 690, 816)), + array(109, 1364, 4, array( 270, 504, 750, 900)), + array(113, 1474, 4, array( 300, 560, 810, 960)), + array(117, 1588, 4, array( 312, 588, 870, 1050)), //25 + array(121, 1706, 4, array( 336, 644, 952, 1110)), + array(125, 1828, 4, array( 360, 700, 1020, 1200)), + array(129, 1921, 3, array( 390, 728, 1050, 1260)), + array(133, 2051, 3, array( 420, 784, 1140, 1350)), + array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30 + array(141, 2323, 3, array( 480, 868, 1290, 1530)), + array(145, 2465, 3, array( 510, 924, 1350, 1620)), + array(149, 2611, 3, array( 540, 980, 1440, 1710)), + array(153, 2761, 3, array( 570, 1036, 1530, 1800)), + array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35 + array(161, 3034, 0, array( 600, 1120, 1680, 1980)), + array(165, 3196, 0, array( 630, 1204, 1770, 2100)), + array(169, 3362, 0, array( 660, 1260, 1860, 2220)), + array(173, 3532, 0, array( 720, 1316, 1950, 2310)), + array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40 + ); + + //---------------------------------------------------------------------- + public static function getDataLength($version, $level) + { + return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level]; + } + + //---------------------------------------------------------------------- + public static function getECCLength($version, $level) + { + return self::$capacity[$version][QRCAP_EC][$level]; + } + + //---------------------------------------------------------------------- + public static function getWidth($version) + { + return self::$capacity[$version][QRCAP_WIDTH]; + } + + //---------------------------------------------------------------------- + public static function getRemainder($version) + { + return self::$capacity[$version][QRCAP_REMINDER]; + } + + //---------------------------------------------------------------------- + public static function getMinimumVersion($size, $level) + { + + for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) { + $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; + if($words >= $size) + return $i; + } + + return -1; + } + + //###################################################################### + + public static $lengthTableBits = array( + array(10, 12, 14), + array( 9, 11, 13), + array( 8, 16, 16), + array( 8, 10, 12) + ); + + //---------------------------------------------------------------------- + public static function lengthIndicator($mode, $version) + { + if ($mode == QR_MODE_STRUCTURE) + return 0; + + if ($version <= 9) { + $l = 0; + } else if ($version <= 26) { + $l = 1; + } else { + $l = 2; + } + + return self::$lengthTableBits[$mode][$l]; + } + + //---------------------------------------------------------------------- + public static function maximumWords($mode, $version) + { + if($mode == QR_MODE_STRUCTURE) + return 3; + + if($version <= 9) { + $l = 0; + } else if($version <= 26) { + $l = 1; + } else { + $l = 2; + } + + $bits = self::$lengthTableBits[$mode][$l]; + $words = (1 << $bits) - 1; + + if($mode == QR_MODE_KANJI) { + $words *= 2; // the number of bytes is required + } + + return $words; + } + + // Error correction code ----------------------------------------------- + // Table of the error correction code (Reed-Solomon block) + // See Table 12-16 (pp.30-36), JIS X0510:2004. + + public static $eccTable = array( + array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), + array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), + array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), + array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 + array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), + array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), + array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), + array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), + array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10 + array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), + array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), + array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), + array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), + array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15 + array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), + array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), + array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), + array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), + array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20 + array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), + array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), + array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), + array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), + array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25 + array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), + array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), + array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), + array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), + array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30 + array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), + array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), + array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), + array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), + array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35 + array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), + array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), + array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), + array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), + array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40 + ); + + //---------------------------------------------------------------------- + // CACHEABLE!!! + + public static function getEccSpec($version, $level, array &$spec) + { + if (count($spec) < 5) { + $spec = array(0,0,0,0,0); + } + + $b1 = self::$eccTable[$version][$level][0]; + $b2 = self::$eccTable[$version][$level][1]; + $data = self::getDataLength($version, $level); + $ecc = self::getECCLength($version, $level); + + if($b2 == 0) { + $spec[0] = $b1; + $spec[1] = (int)($data / $b1); + $spec[2] = (int)($ecc / $b1); + $spec[3] = 0; + $spec[4] = 0; + } else { + $spec[0] = $b1; + $spec[1] = (int)($data / ($b1 + $b2)); + $spec[2] = (int)($ecc / ($b1 + $b2)); + $spec[3] = $b2; + $spec[4] = $spec[1] + 1; + } + } + + // Alignment pattern --------------------------------------------------- + + // Positions of alignment patterns. + // This array includes only the second and the third position of the + // alignment patterns. Rest of them can be calculated from the distance + // between them. + + // See Table 1 in Appendix E (pp.71) of JIS X0510:2004. + + public static $alignmentPattern = array( + array( 0, 0), + array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 + array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 + array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15 + array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20 + array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25 + array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30 + array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35 + array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40 + ); + + + /** -------------------------------------------------------------------- + * Put an alignment marker. + * @param frame + * @param width + * @param ox,oy center coordinate of the pattern + */ + public static function putAlignmentMarker(array &$frame, $ox, $oy) + { + $finder = array( + "\xa1\xa1\xa1\xa1\xa1", + "\xa1\xa0\xa0\xa0\xa1", + "\xa1\xa0\xa1\xa0\xa1", + "\xa1\xa0\xa0\xa0\xa1", + "\xa1\xa1\xa1\xa1\xa1" + ); + + $yStart = $oy-2; + $xStart = $ox-2; + + for($y=0; $y<5; $y++) { + QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); + } + } + + //---------------------------------------------------------------------- + public static function putAlignmentPattern($version, &$frame, $width) + { + if($version < 2) + return; + + $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; + if($d < 0) { + $w = 2; + } else { + $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2); + } + + if($w * $w - 3 == 1) { + $x = self::$alignmentPattern[$version][0]; + $y = self::$alignmentPattern[$version][0]; + self::putAlignmentMarker($frame, $x, $y); + return; + } + + $cx = self::$alignmentPattern[$version][0]; + for($x=1; $x<$w - 1; $x++) { + self::putAlignmentMarker($frame, 6, $cx); + self::putAlignmentMarker($frame, $cx, 6); + $cx += $d; + } + + $cy = self::$alignmentPattern[$version][0]; + for($y=0; $y<$w-1; $y++) { + $cx = self::$alignmentPattern[$version][0]; + for($x=0; $x<$w-1; $x++) { + self::putAlignmentMarker($frame, $cx, $cy); + $cx += $d; + } + $cy += $d; + } + } + + // Version information pattern ----------------------------------------- + + // Version information pattern (BCH coded). + // See Table 1 in Appendix D (pp.68) of JIS X0510:2004. + + // size: [QRSPEC_VERSION_MAX - 6] + + public static $versionPattern = array( + 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, + 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, + 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, + 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, + 0x27541, 0x28c69 + ); + + //---------------------------------------------------------------------- + public static function getVersionPattern($version) + { + if($version < 7 || $version > QRSPEC_VERSION_MAX) + return 0; + + return self::$versionPattern[$version -7]; + } + + // Format information -------------------------------------------------- + // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib) + + public static $formatInfo = array( + array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), + array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), + array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), + array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b) + ); + + public static function getFormatInfo($mask, $level) + { + if($mask < 0 || $mask > 7) + return 0; + + if($level < 0 || $level > 3) + return 0; + + return self::$formatInfo[$level][$mask]; + } + + // Frame --------------------------------------------------------------- + // Cache of initial frames. + + public static $frames = array(); + + /** -------------------------------------------------------------------- + * Put a finder pattern. + * @param frame + * @param width + * @param ox,oy upper-left coordinate of the pattern + */ + public static function putFinderPattern(&$frame, $ox, $oy) + { + $finder = array( + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" + ); + + for($y=0; $y<7; $y++) { + QRstr::set($frame, $ox, $oy+$y, $finder[$y]); + } + } + + //---------------------------------------------------------------------- + public static function createFrame($version) + { + $width = self::$capacity[$version][QRCAP_WIDTH]; + $frameLine = str_repeat ("\0", $width); + $frame = array_fill(0, $width, $frameLine); + + // Finder pattern + self::putFinderPattern($frame, 0, 0); + self::putFinderPattern($frame, $width - 7, 0); + self::putFinderPattern($frame, 0, $width - 7); + + // Separator + $yOffset = $width - 7; + + for($y=0; $y<7; $y++) { + $frame[$y][7] = "\xc0"; + $frame[$y][$width - 8] = "\xc0"; + $frame[$yOffset][7] = "\xc0"; + $yOffset++; + } + + $setPattern = str_repeat("\xc0", 8); + + QRstr::set($frame, 0, 7, $setPattern); + QRstr::set($frame, $width-8, 7, $setPattern); + QRstr::set($frame, 0, $width - 8, $setPattern); + + // Format info + $setPattern = str_repeat("\x84", 9); + QRstr::set($frame, 0, 8, $setPattern); + QRstr::set($frame, $width - 8, 8, $setPattern, 8); + + $yOffset = $width - 8; + + for($y=0; $y<8; $y++,$yOffset++) { + $frame[$y][8] = "\x84"; + $frame[$yOffset][8] = "\x84"; + } + + // Timing pattern + + for($i=1; $i<$width-15; $i++) { + $frame[6][7+$i] = chr(0x90 | ($i & 1)); + $frame[7+$i][6] = chr(0x90 | ($i & 1)); + } + + // Alignment pattern + self::putAlignmentPattern($version, $frame, $width); + + // Version information + if($version >= 7) { + $vinf = self::getVersionPattern($version); + + $v = $vinf; + + for($x=0; $x<6; $x++) { + for($y=0; $y<3; $y++) { + $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); + $v = $v >> 1; + } + } + + $v = $vinf; + for($y=0; $y<6; $y++) { + for($x=0; $x<3; $x++) { + $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); + $v = $v >> 1; + } + } + } + + // and a little bit... + $frame[$width - 8][8] = "\x81"; + + return $frame; + } + + //---------------------------------------------------------------------- + public static function debug($frame, $binary_mode = false) + { + if ($binary_mode) { + + foreach ($frame as &$frameLine) { + $frameLine = join('  ', explode('0', $frameLine)); + $frameLine = join('██', explode('1', $frameLine)); + } + + ?> + +


        '; + echo join("
        ", $frame); + echo '






'; + + } else { + + foreach ($frame as &$frameLine) { + $frameLine = join(' ', explode("\xc0", $frameLine)); + $frameLine = join('', explode("\xc1", $frameLine)); + $frameLine = join(' ', explode("\xa0", $frameLine)); + $frameLine = join('', explode("\xa1", $frameLine)); + $frameLine = join('', explode("\x84", $frameLine)); //format 0 + $frameLine = join('', explode("\x85", $frameLine)); //format 1 + $frameLine = join('', explode("\x81", $frameLine)); //special bit + $frameLine = join(' ', explode("\x90", $frameLine)); //clock 0 + $frameLine = join('', explode("\x91", $frameLine)); //clock 1 + $frameLine = join(' ', explode("\x88", $frameLine)); //version + $frameLine = join('', explode("\x89", $frameLine)); //version + $frameLine = join('♦', explode("\x01", $frameLine)); + $frameLine = join('⋅', explode("\0", $frameLine)); + } + + ?> + + "; + echo join("
", $frame); + echo "
"; + + } + } + + //---------------------------------------------------------------------- + public static function serial($frame) + { + return gzcompress(join("\n", $frame), 9); + } + + //---------------------------------------------------------------------- + public static function unserial($code) + { + return explode("\n", gzuncompress($code)); + } + + //---------------------------------------------------------------------- + public static function newFrame($version) + { + if($version < 1 || $version > QRSPEC_VERSION_MAX) + return null; + + if(!isset(self::$frames[$version])) { + + $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat'; + + if (QR_CACHEABLE) { + if (file_exists($fileName)) { + self::$frames[$version] = self::unserial(file_get_contents($fileName)); + } else { + self::$frames[$version] = self::createFrame($version); + file_put_contents($fileName, self::serial(self::$frames[$version])); + } + } else { + self::$frames[$version] = self::createFrame($version); + } + } + + if(is_null(self::$frames[$version])) + return null; + + return self::$frames[$version]; + } + + //---------------------------------------------------------------------- + public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; } + public static function rsBlockNum1($spec) { return $spec[0]; } + public static function rsDataCodes1($spec) { return $spec[1]; } + public static function rsEccCodes1($spec) { return $spec[2]; } + public static function rsBlockNum2($spec) { return $spec[3]; } + public static function rsDataCodes2($spec) { return $spec[4]; } + public static function rsEccCodes2($spec) { return $spec[2]; } + public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); } + public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; } + + } + + + +//---- qrimage.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Image output of code using GD2 + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('QR_IMAGE', true); + + class QRimage { + + //---------------------------------------------------------------------- + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) + { + $image = self::image($frame, $pixelPerPoint, $outerFrame); + + if ($filename === false) { + Header("Content-type: image/png"); + ImagePng($image); + } else { + if($saveandprint===TRUE){ + ImagePng($image, $filename); + header("Content-type: image/png"); + ImagePng($image); + }else{ + ImagePng($image, $filename); + } + } + + ImageDestroy($image); + } + + //---------------------------------------------------------------------- + public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) + { + $image = self::image($frame, $pixelPerPoint, $outerFrame); + + if ($filename === false) { + Header("Content-type: image/jpeg"); + ImageJpeg($image, null, $q); + } else { + ImageJpeg($image, $filename, $q); + } + + ImageDestroy($image); + } + + //---------------------------------------------------------------------- + private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) + { + $h = count($frame); + $w = strlen($frame[0]); + + $imgW = $w + 2*$outerFrame; + $imgH = $h + 2*$outerFrame; + + $base_image =ImageCreate($imgW, $imgH); + + $col[0] = ImageColorAllocate($base_image,255,255,255); + $col[1] = ImageColorAllocate($base_image,0,0,0); + + imagefill($base_image, 0, 0, $col[0]); + + for($y=0; $y<$h; $y++) { + for($x=0; $x<$w; $x++) { + if ($frame[$y][$x] == '1') { + ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); + } + } + } + + $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); + ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); + ImageDestroy($base_image); + + return $target_image; + } + } + + + +//---- qrinput.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Input encoding class + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('STRUCTURE_HEADER_BITS', 20); + define('MAX_STRUCTURED_SYMBOLS', 16); + + class QRinputItem { + + public $mode; + public $size; + public $data; + public $bstream; + + public function __construct($mode, $size, $data, $bstream = null) + { + $setData = array_slice($data, 0, $size); + + if (count($setData) < $size) { + $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); + } + + if(!QRinput::check($mode, $size, $setData)) { + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData)); + return null; + } + + $this->mode = $mode; + $this->size = $size; + $this->data = $setData; + $this->bstream = $bstream; + } + + //---------------------------------------------------------------------- + public function encodeModeNum($version) + { + try { + + $words = (int)($this->size / 3); + $bs = new QRbitstream(); + + $val = 0x1; + $bs->appendNum(4, $val); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); + + for($i=0; $i<$words; $i++) { + $val = (ord($this->data[$i*3 ]) - ord('0')) * 100; + $val += (ord($this->data[$i*3+1]) - ord('0')) * 10; + $val += (ord($this->data[$i*3+2]) - ord('0')); + $bs->appendNum(10, $val); + } + + if($this->size - $words * 3 == 1) { + $val = ord($this->data[$words*3]) - ord('0'); + $bs->appendNum(4, $val); + } else if($this->size - $words * 3 == 2) { + $val = (ord($this->data[$words*3 ]) - ord('0')) * 10; + $val += (ord($this->data[$words*3+1]) - ord('0')); + $bs->appendNum(7, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeAn($version) + { + try { + $words = (int)($this->size / 2); + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x02); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); + + for($i=0; $i<$words; $i++) { + $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; + $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); + + $bs->appendNum(11, $val); + } + + if($this->size & 1) { + $val = QRinput::lookAnTable(ord($this->data[$words * 2])); + $bs->appendNum(6, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeMode8($version) + { + try { + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x4); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); + + for($i=0; $i<$this->size; $i++) { + $bs->appendNum(8, ord($this->data[$i])); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeKanji($version) + { + try { + + $bs = new QRbitrtream(); + + $bs->appendNum(4, 0x8); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); + + for($i=0; $i<$this->size; $i+=2) { + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); + if($val <= 0x9ffc) { + $val -= 0x8140; + } else { + $val -= 0xc140; + } + + $h = ($val >> 8) * 0xc0; + $val = ($val & 0xff) + $h; + + $bs->appendNum(13, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeStructure() + { + try { + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x03); + $bs->appendNum(4, ord($this->data[1]) - 1); + $bs->appendNum(4, ord($this->data[0]) - 1); + $bs->appendNum(8, ord($this->data[2])); + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function estimateBitStreamSizeOfEntry($version) + { + $bits = 0; + + if($version == 0) + $version = 1; + + switch($this->mode) { + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; + case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; + default: + return 0; + } + + $l = QRspec::lengthIndicator($this->mode, $version); + $m = 1 << $l; + $num = (int)(($this->size + $m - 1) / $m); + + $bits += $num * (4 + $l); + + return $bits; + } + + //---------------------------------------------------------------------- + public function encodeBitStream($version) + { + try { + + unset($this->bstream); + $words = QRspec::maximumWords($this->mode, $version); + + if($this->size > $words) { + + $st1 = new QRinputItem($this->mode, $words, $this->data); + $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); + + $st1->encodeBitStream($version); + $st2->encodeBitStream($version); + + $this->bstream = new QRbitstream(); + $this->bstream->append($st1->bstream); + $this->bstream->append($st2->bstream); + + unset($st1); + unset($st2); + + } else { + + $ret = 0; + + switch($this->mode) { + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; + case QR_MODE_8: $ret = $this->encodeMode8($version); break; + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; + + default: + break; + } + + if($ret < 0) + return -1; + } + + return $this->bstream->size(); + + } catch (Exception $e) { + return -1; + } + } + }; + + //########################################################################## + + class QRinput { + + public $items; + + private $version; + private $level; + + //---------------------------------------------------------------------- + public function __construct($version = 0, $level = QR_ECLEVEL_L) + { + if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) { + throw new Exception('Invalid version no'); + return NULL; + } + + $this->version = $version; + $this->level = $level; + } + + //---------------------------------------------------------------------- + public function getVersion() + { + return $this->version; + } + + //---------------------------------------------------------------------- + public function setVersion($version) + { + if($version < 0 || $version > QRSPEC_VERSION_MAX) { + throw new Exception('Invalid version no'); + return -1; + } + + $this->version = $version; + + return 0; + } + + //---------------------------------------------------------------------- + public function getErrorCorrectionLevel() + { + return $this->level; + } + + //---------------------------------------------------------------------- + public function setErrorCorrectionLevel($level) + { + if($level > QR_ECLEVEL_H) { + throw new Exception('Invalid ECLEVEL'); + return -1; + } + + $this->level = $level; + + return 0; + } + + //---------------------------------------------------------------------- + public function appendEntry(QRinputItem $entry) + { + $this->items[] = $entry; + } + + //---------------------------------------------------------------------- + public function append($mode, $size, $data) + { + try { + $entry = new QRinputItem($mode, $size, $data); + $this->items[] = $entry; + return 0; + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + + public function insertStructuredAppendHeader($size, $index, $parity) + { + if( $size > MAX_STRUCTURED_SYMBOLS ) { + throw new Exception('insertStructuredAppendHeader wrong size'); + } + + if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) { + throw new Exception('insertStructuredAppendHeader wrong index'); + } + + $buf = array($size, $index, $parity); + + try { + $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf); + array_unshift($this->items, $entry); + return 0; + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function calcParity() + { + $parity = 0; + + foreach($this->items as $item) { + if($item->mode != QR_MODE_STRUCTURE) { + for($i=$item->size-1; $i>=0; $i--) { + $parity ^= $item->data[$i]; + } + } + } + + return $parity; + } + + //---------------------------------------------------------------------- + public static function checkModeNum($size, $data) + { + for($i=0; $i<$size; $i++) { + if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){ + return false; + } + } + + return true; + } + + //---------------------------------------------------------------------- + public static function estimateBitsModeNum($size) + { + $w = (int)$size / 3; + $bits = $w * 10; + + switch($size - $w * 3) { + case 1: + $bits += 4; + break; + case 2: + $bits += 7; + break; + default: + break; + } + + return $bits; + } + + //---------------------------------------------------------------------- + public static $anTable = array( + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + ); + + //---------------------------------------------------------------------- + public static function lookAnTable($c) + { + return (($c > 127)?-1:self::$anTable[$c]); + } + + //---------------------------------------------------------------------- + public static function checkModeAn($size, $data) + { + for($i=0; $i<$size; $i++) { + if (self::lookAnTable(ord($data[$i])) == -1) { + return false; + } + } + + return true; + } + + //---------------------------------------------------------------------- + public static function estimateBitsModeAn($size) + { + $w = (int)($size / 2); + $bits = $w * 11; + + if($size & 1) { + $bits += 6; + } + + return $bits; + } + + //---------------------------------------------------------------------- + public static function estimateBitsMode8($size) + { + return $size * 8; + } + + //---------------------------------------------------------------------- + public function estimateBitsModeKanji($size) + { + return (int)(($size / 2) * 13); + } + + //---------------------------------------------------------------------- + public static function checkModeKanji($size, $data) + { + if($size & 1) + return false; + + for($i=0; $i<$size; $i+=2) { + $val = (ord($data[$i]) << 8) | ord($data[$i+1]); + if( $val < 0x8140 + || ($val > 0x9ffc && $val < 0xe040) + || $val > 0xebbf) { + return false; + } + } + + return true; + } + + /*********************************************************************** + * Validation + **********************************************************************/ + + public static function check($mode, $size, $data) + { + if($size <= 0) + return false; + + switch($mode) { + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; + case QR_MODE_AN: return self::checkModeAn($size, $data); break; + case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; + case QR_MODE_8: return true; break; + case QR_MODE_STRUCTURE: return true; break; + + default: + break; + } + + return false; + } + + + //---------------------------------------------------------------------- + public function estimateBitStreamSize($version) + { + $bits = 0; + + foreach($this->items as $item) { + $bits += $item->estimateBitStreamSizeOfEntry($version); + } + + return $bits; + } + + //---------------------------------------------------------------------- + public function estimateVersion() + { + $version = 0; + $prev = 0; + do { + $prev = $version; + $bits = $this->estimateBitStreamSize($prev); + $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); + if ($version < 0) { + return -1; + } + } while ($version > $prev); + + return $version; + } + + //---------------------------------------------------------------------- + public static function lengthOfCode($mode, $version, $bits) + { + $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); + switch($mode) { + case QR_MODE_NUM: + $chunks = (int)($payload / 10); + $remain = $payload - $chunks * 10; + $size = $chunks * 3; + if($remain >= 7) { + $size += 2; + } else if($remain >= 4) { + $size += 1; + } + break; + case QR_MODE_AN: + $chunks = (int)($payload / 11); + $remain = $payload - $chunks * 11; + $size = $chunks * 2; + if($remain >= 6) + $size++; + break; + case QR_MODE_8: + $size = (int)($payload / 8); + break; + case QR_MODE_KANJI: + $size = (int)(($payload / 13) * 2); + break; + case QR_MODE_STRUCTURE: + $size = (int)($payload / 8); + break; + default: + $size = 0; + break; + } + + $maxsize = QRspec::maximumWords($mode, $version); + if($size < 0) $size = 0; + if($size > $maxsize) $size = $maxsize; + + return $size; + } + + //---------------------------------------------------------------------- + public function createBitStream() + { + $total = 0; + + foreach($this->items as $item) { + $bits = $item->encodeBitStream($this->version); + + if($bits < 0) + return -1; + + $total += $bits; + } + + return $total; + } + + //---------------------------------------------------------------------- + public function convertData() + { + $ver = $this->estimateVersion(); + if($ver > $this->getVersion()) { + $this->setVersion($ver); + } + + for(;;) { + $bits = $this->createBitStream(); + + if($bits < 0) + return -1; + + $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); + if($ver < 0) { + throw new Exception('WRONG VERSION'); + return -1; + } else if($ver > $this->getVersion()) { + $this->setVersion($ver); + } else { + break; + } + } + + return 0; + } + + //---------------------------------------------------------------------- + public function appendPaddingBit(&$bstream) + { + $bits = $bstream->size(); + $maxwords = QRspec::getDataLength($this->version, $this->level); + $maxbits = $maxwords * 8; + + if ($maxbits == $bits) { + return 0; + } + + if ($maxbits - $bits < 5) { + return $bstream->appendNum($maxbits - $bits, 0); + } + + $bits += 4; + $words = (int)(($bits + 7) / 8); + + $padding = new QRbitstream(); + $ret = $padding->appendNum($words * 8 - $bits + 4, 0); + + if($ret < 0) + return $ret; + + $padlen = $maxwords - $words; + + if($padlen > 0) { + + $padbuf = array(); + for($i=0; $i<$padlen; $i++) { + $padbuf[$i] = ($i&1)?0x11:0xec; + } + + $ret = $padding->appendBytes($padlen, $padbuf); + + if($ret < 0) + return $ret; + + } + + $ret = $bstream->append($padding); + + return $ret; + } + + //---------------------------------------------------------------------- + public function mergeBitStream() + { + if($this->convertData() < 0) { + return null; + } + + $bstream = new QRbitstream(); + + foreach($this->items as $item) { + $ret = $bstream->append($item->bstream); + if($ret < 0) { + return null; + } + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function getBitStream() + { + + $bstream = $this->mergeBitStream(); + + if($bstream == null) { + return null; + } + + $ret = $this->appendPaddingBit($bstream); + if($ret < 0) { + return null; + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function getByteStream() + { + $bstream = $this->getBitStream(); + if($bstream == null) { + return null; + } + + return $bstream->toByte(); + } + } + + + + + + +//---- qrbitstream.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Bitstream class + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRbitstream { + + public $data = array(); + + //---------------------------------------------------------------------- + public function size() + { + return count($this->data); + } + + //---------------------------------------------------------------------- + public function allocate($setLength) + { + $this->data = array_fill(0, $setLength, 0); + return 0; + } + + //---------------------------------------------------------------------- + public static function newFromNum($bits, $num) + { + $bstream = new QRbitstream(); + $bstream->allocate($bits); + + $mask = 1 << ($bits - 1); + for($i=0; $i<$bits; $i++) { + if($num & $mask) { + $bstream->data[$i] = 1; + } else { + $bstream->data[$i] = 0; + } + $mask = $mask >> 1; + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public static function newFromBytes($size, $data) + { + $bstream = new QRbitstream(); + $bstream->allocate($size * 8); + $p=0; + + for($i=0; $i<$size; $i++) { + $mask = 0x80; + for($j=0; $j<8; $j++) { + if($data[$i] & $mask) { + $bstream->data[$p] = 1; + } else { + $bstream->data[$p] = 0; + } + $p++; + $mask = $mask >> 1; + } + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function append(QRbitstream $arg) + { + if (is_null($arg)) { + return -1; + } + + if($arg->size() == 0) { + return 0; + } + + if($this->size() == 0) { + $this->data = $arg->data; + return 0; + } + + $this->data = array_values(array_merge($this->data, $arg->data)); + + return 0; + } + + //---------------------------------------------------------------------- + public function appendNum($bits, $num) + { + if ($bits == 0) + return 0; + + $b = QRbitstream::newFromNum($bits, $num); + + if(is_null($b)) + return -1; + + $ret = $this->append($b); + unset($b); + + return $ret; + } + + //---------------------------------------------------------------------- + public function appendBytes($size, $data) + { + if ($size == 0) + return 0; + + $b = QRbitstream::newFromBytes($size, $data); + + if(is_null($b)) + return -1; + + $ret = $this->append($b); + unset($b); + + return $ret; + } + + //---------------------------------------------------------------------- + public function toByte() + { + + $size = $this->size(); + + if($size == 0) { + return array(); + } + + $data = array_fill(0, (int)(($size + 7) / 8), 0); + $bytes = (int)($size / 8); + + $p = 0; + + for($i=0; $i<$bytes; $i++) { + $v = 0; + for($j=0; $j<8; $j++) { + $v = $v << 1; + $v |= $this->data[$p]; + $p++; + } + $data[$i] = $v; + } + + if($size & 7) { + $v = 0; + for($j=0; $j<($size & 7); $j++) { + $v = $v << 1; + $v |= $this->data[$p]; + $p++; + } + $data[$bytes] = $v; + } + + return $data; + } + + } + + + + +//---- qrsplit.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Input splitting classes + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * The following data / specifications are taken from + * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) + * or + * "Automatic identification and data capture techniques -- + * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + class QRsplit { + + public $dataStr = ''; + public $input; + public $modeHint; + + //---------------------------------------------------------------------- + public function __construct($dataStr, $input, $modeHint) + { + $this->dataStr = $dataStr; + $this->input = $input; + $this->modeHint = $modeHint; + } + + //---------------------------------------------------------------------- + public static function isdigitat($str, $pos) + { + if ($pos >= strlen($str)) + return false; + + return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); + } + + //---------------------------------------------------------------------- + public static function isalnumat($str, $pos) + { + if ($pos >= strlen($str)) + return false; + + return (QRinput::lookAnTable(ord($str[$pos])) >= 0); + } + + //---------------------------------------------------------------------- + public function identifyMode($pos) + { + if ($pos >= strlen($this->dataStr)) + return QR_MODE_NUL; + + $c = $this->dataStr[$pos]; + + if(self::isdigitat($this->dataStr, $pos)) { + return QR_MODE_NUM; + } else if(self::isalnumat($this->dataStr, $pos)) { + return QR_MODE_AN; + } else if($this->modeHint == QR_MODE_KANJI) { + + if ($pos+1 < strlen($this->dataStr)) + { + $d = $this->dataStr[$pos+1]; + $word = (ord($c) << 8) | ord($d); + if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { + return QR_MODE_KANJI; + } + } + } + + return QR_MODE_8; + } + + //---------------------------------------------------------------------- + public function eatNum() + { + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 0; + while(self::isdigitat($this->dataStr, $p)) { + $p++; + } + + $run = $p; + $mode = $this->identifyMode($p); + + if($mode == QR_MODE_8) { + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln + + QRinput::estimateBitsMode8(1) // + 4 + l8 + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 + if($dif > 0) { + return $this->eat8(); + } + } + if($mode == QR_MODE_AN) { + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln + + QRinput::estimateBitsModeAn(1) // + 4 + la + - QRinput::estimateBitsModeAn($run + 1);// - 4 - la + if($dif > 0) { + return $this->eatAn(); + } + } + + $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eatAn() + { + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 0; + + while(self::isalnumat($this->dataStr, $p)) { + if(self::isdigitat($this->dataStr, $p)) { + $q = $p; + while(self::isdigitat($this->dataStr, $q)) { + $q++; + } + + $dif = QRinput::estimateBitsModeAn($p) // + 4 + la + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln + - QRinput::estimateBitsModeAn($q); // - 4 - la + + if($dif < 0) { + break; + } else { + $p = $q; + } + } else { + $p++; + } + } + + $run = $p; + + if(!self::isalnumat($this->dataStr, $p)) { + $dif = QRinput::estimateBitsModeAn($run) + 4 + $la + + QRinput::estimateBitsMode8(1) // + 4 + l8 + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 + if($dif > 0) { + return $this->eat8(); + } + } + + $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eatKanji() + { + $p = 0; + + while($this->identifyMode($p) == QR_MODE_KANJI) { + $p += 2; + } + + $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eat8() + { + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 1; + $dataStrLen = strlen($this->dataStr); + + while($p < $dataStrLen) { + + $mode = $this->identifyMode($p); + if($mode == QR_MODE_KANJI) { + break; + } + if($mode == QR_MODE_NUM) { + $q = $p; + while(self::isdigitat($this->dataStr, $q)) { + $q++; + } + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln + - QRinput::estimateBitsMode8($q); // - 4 - l8 + if($dif < 0) { + break; + } else { + $p = $q; + } + } else if($mode == QR_MODE_AN) { + $q = $p; + while(self::isalnumat($this->dataStr, $q)) { + $q++; + } + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 + + QRinput::estimateBitsModeAn($q - $p) + 4 + $la + - QRinput::estimateBitsMode8($q); // - 4 - l8 + if($dif < 0) { + break; + } else { + $p = $q; + } + } else { + $p++; + } + } + + $run = $p; + $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); + + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function splitString() + { + while (strlen($this->dataStr) > 0) + { + if($this->dataStr == '') + return 0; + + $mode = $this->identifyMode(0); + + switch ($mode) { + case QR_MODE_NUM: $length = $this->eatNum(); break; + case QR_MODE_AN: $length = $this->eatAn(); break; + case QR_MODE_KANJI: + if ($hint == QR_MODE_KANJI) + $length = $this->eatKanji(); + else $length = $this->eat8(); + break; + default: $length = $this->eat8(); break; + + } + + if($length == 0) return 0; + if($length < 0) return -1; + + $this->dataStr = substr($this->dataStr, $length); + } + } + + //---------------------------------------------------------------------- + public function toUpper() + { + $stringLen = strlen($this->dataStr); + $p = 0; + + while ($p<$stringLen) { + $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint); + if($mode == QR_MODE_KANJI) { + $p += 2; + } else { + if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) { + $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); + } + $p++; + } + } + + return $this->dataStr; + } + + //---------------------------------------------------------------------- + public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) + { + if(is_null($string) || $string == '\0' || $string == '') { + throw new Exception('empty string!!!'); + } + + $split = new QRsplit($string, $input, $modeHint); + + if(!$casesensitive) + $split->toUpper(); + + return $split->splitString(); + } + } + + + +//---- qrrscode.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Reed-Solomon error correction support + * + * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q + * (libfec is released under the GNU Lesser General Public License.) + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRrsItem { + + public $mm; // Bits per symbol + public $nn; // Symbols per block (= (1<= $this->nn) { + $x -= $this->nn; + $x = ($x >> $this->mm) + ($x & $this->nn); + } + + return $x; + } + + //---------------------------------------------------------------------- + public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) + { + // Common code for intializing a Reed-Solomon control block (char or int symbols) + // Copyright 2004 Phil Karn, KA9Q + // May be used under the terms of the GNU Lesser General Public License (LGPL) + + $rs = null; + + // Check parameter ranges + if($symsize < 0 || $symsize > 8) return $rs; + if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; + if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; + if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! + if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding + + $rs = new QRrsItem(); + $rs->mm = $symsize; + $rs->nn = (1<<$symsize)-1; + $rs->pad = $pad; + + $rs->alpha_to = array_fill(0, $rs->nn+1, 0); + $rs->index_of = array_fill(0, $rs->nn+1, 0); + + // PHP style macro replacement ;) + $NN =& $rs->nn; + $A0 =& $NN; + + // Generate Galois field lookup tables + $rs->index_of[0] = $A0; // log(zero) = -inf + $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 + $sr = 1; + + for($i=0; $i<$rs->nn; $i++) { + $rs->index_of[$sr] = $i; + $rs->alpha_to[$i] = $sr; + $sr <<= 1; + if($sr & (1<<$symsize)) { + $sr ^= $gfpoly; + } + $sr &= $rs->nn; + } + + if($sr != 1){ + // field generator polynomial is not primitive! + $rs = NULL; + return $rs; + } + + /* Form RS code generator polynomial from its roots */ + $rs->genpoly = array_fill(0, $nroots+1, 0); + + $rs->fcr = $fcr; + $rs->prim = $prim; + $rs->nroots = $nroots; + $rs->gfpoly = $gfpoly; + + /* Find prim-th root of 1, used in decoding */ + for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) + ; // intentional empty-body loop! + + $rs->iprim = (int)($iprim / $prim); + $rs->genpoly[0] = 1; + + for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { + $rs->genpoly[$i+1] = 1; + + // Multiply rs->genpoly[] by @**(root + x) + for ($j = $i; $j > 0; $j--) { + if ($rs->genpoly[$j] != 0) { + $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; + } else { + $rs->genpoly[$j] = $rs->genpoly[$j-1]; + } + } + // rs->genpoly[0] can never be zero + $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)]; + } + + // convert rs->genpoly[] to index form for quicker encoding + for ($i = 0; $i <= $nroots; $i++) + $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; + + return $rs; + } + + //---------------------------------------------------------------------- + public function encode_rs_char($data, &$parity) + { + $MM =& $this->mm; + $NN =& $this->nn; + $ALPHA_TO =& $this->alpha_to; + $INDEX_OF =& $this->index_of; + $GENPOLY =& $this->genpoly; + $NROOTS =& $this->nroots; + $FCR =& $this->fcr; + $PRIM =& $this->prim; + $IPRIM =& $this->iprim; + $PAD =& $this->pad; + $A0 =& $NN; + + $parity = array_fill(0, $NROOTS, 0); + + for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) { + + $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; + if($feedback != $A0) { + // feedback term is non-zero + + // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must + // always be for the polynomials constructed by init_rs() + $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); + + for($j=1;$j<$NROOTS;$j++) { + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; + } + } + + // Shift + array_shift($parity); + if($feedback != $A0) { + array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); + } else { + array_push($parity, 0); + } + } + } + } + + //########################################################################## + + class QRrs { + + public static $items = array(); + + //---------------------------------------------------------------------- + public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) + { + foreach(self::$items as $rs) { + if($rs->pad != $pad) continue; + if($rs->nroots != $nroots) continue; + if($rs->mm != $symsize) continue; + if($rs->gfpoly != $gfpoly) continue; + if($rs->fcr != $fcr) continue; + if($rs->prim != $prim) continue; + + return $rs; + } + + $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad); + array_unshift(self::$items, $rs); + + return $rs; + } + } + + + +//---- qrmask.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Masking + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('N1', 3); + define('N2', 3); + define('N3', 40); + define('N4', 10); + + class QRmask { + + public $runLength = array(); + + //---------------------------------------------------------------------- + public function __construct() + { + $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); + } + + //---------------------------------------------------------------------- + public function writeFormatInformation($width, &$frame, $mask, $level) + { + $blacks = 0; + $format = QRspec::getFormatInfo($mask, $level); + + for($i=0; $i<8; $i++) { + if($format & 1) { + $blacks += 2; + $v = 0x85; + } else { + $v = 0x84; + } + + $frame[8][$width - 1 - $i] = chr($v); + if($i < 6) { + $frame[$i][8] = chr($v); + } else { + $frame[$i + 1][8] = chr($v); + } + $format = $format >> 1; + } + + for($i=0; $i<7; $i++) { + if($format & 1) { + $blacks += 2; + $v = 0x85; + } else { + $v = 0x84; + } + + $frame[$width - 7 + $i][8] = chr($v); + if($i == 0) { + $frame[8][7] = chr($v); + } else { + $frame[8][6 - $i] = chr($v); + } + + $format = $format >> 1; + } + + return $blacks; + } + + //---------------------------------------------------------------------- + public function mask0($x, $y) { return ($x+$y)&1; } + public function mask1($x, $y) { return ($y&1); } + public function mask2($x, $y) { return ($x%3); } + public function mask3($x, $y) { return ($x+$y)%3; } + public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; } + public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; } + public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; } + public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; } + + //---------------------------------------------------------------------- + private function generateMaskNo($maskNo, $width, $frame) + { + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); + + for($y=0; $y<$width; $y++) { + for($x=0; $x<$width; $x++) { + if(ord($frame[$y][$x]) & 0x80) { + $bitMask[$y][$x] = 0; + } else { + $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); + $bitMask[$y][$x] = ($maskFunc == 0)?1:0; + } + + } + } + + return $bitMask; + } + + //---------------------------------------------------------------------- + public static function serial($bitFrame) + { + $codeArr = array(); + + foreach ($bitFrame as $line) + $codeArr[] = join('', $line); + + return gzcompress(join("\n", $codeArr), 9); + } + + //---------------------------------------------------------------------- + public static function unserial($code) + { + $codeArr = array(); + + $codeLines = explode("\n", gzuncompress($code)); + foreach ($codeLines as $line) + $codeArr[] = str_split($line); + + return $codeArr; + } + + //---------------------------------------------------------------------- + public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) + { + $b = 0; + $bitMask = array(); + + $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat'; + + if (QR_CACHEABLE) { + if (file_exists($fileName)) { + $bitMask = self::unserial(file_get_contents($fileName)); + } else { + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); + if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) + mkdir(QR_CACHE_DIR.'mask_'.$maskNo); + file_put_contents($fileName, self::serial($bitMask)); + } + } else { + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); + } + + if ($maskGenOnly) + return; + + $d = $s; + + for($y=0; $y<$width; $y++) { + for($x=0; $x<$width; $x++) { + if($bitMask[$y][$x] == 1) { + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); + } + $b += (int)(ord($d[$y][$x]) & 1); + } + } + + return $b; + } + + //---------------------------------------------------------------------- + public function makeMask($width, $frame, $maskNo, $level) + { + $masked = array_fill(0, $width, str_repeat("\0", $width)); + $this->makeMaskNo($maskNo, $width, $frame, $masked); + $this->writeFormatInformation($width, $masked, $maskNo, $level); + + return $masked; + } + + //---------------------------------------------------------------------- + public function calcN1N3($length) + { + $demerit = 0; + + for($i=0; $i<$length; $i++) { + + if($this->runLength[$i] >= 5) { + $demerit += (N1 + ($this->runLength[$i] - 5)); + } + if($i & 1) { + if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) { + $fact = (int)($this->runLength[$i] / 3); + if(($this->runLength[$i-2] == $fact) && + ($this->runLength[$i-1] == $fact) && + ($this->runLength[$i+1] == $fact) && + ($this->runLength[$i+2] == $fact)) { + if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) { + $demerit += N3; + } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) { + $demerit += N3; + } + } + } + } + } + return $demerit; + } + + //---------------------------------------------------------------------- + public function evaluateSymbol($width, $frame) + { + $head = 0; + $demerit = 0; + + for($y=0; $y<$width; $y++) { + $head = 0; + $this->runLength[0] = 1; + + $frameY = $frame[$y]; + + if ($y>0) + $frameYM = $frame[$y-1]; + + for($x=0; $x<$width; $x++) { + if(($x > 0) && ($y > 0)) { + $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); + $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); + + if(($b22 | ($w22 ^ 1))&1) { + $demerit += N2; + } + } + if(($x == 0) && (ord($frameY[$x]) & 1)) { + $this->runLength[0] = -1; + $head = 1; + $this->runLength[$head] = 1; + } else if($x > 0) { + if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { + $head++; + $this->runLength[$head] = 1; + } else { + $this->runLength[$head]++; + } + } + } + + $demerit += $this->calcN1N3($head+1); + } + + for($x=0; $x<$width; $x++) { + $head = 0; + $this->runLength[0] = 1; + + for($y=0; $y<$width; $y++) { + if($y == 0 && (ord($frame[$y][$x]) & 1)) { + $this->runLength[0] = -1; + $head = 1; + $this->runLength[$head] = 1; + } else if($y > 0) { + if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { + $head++; + $this->runLength[$head] = 1; + } else { + $this->runLength[$head]++; + } + } + } + + $demerit += $this->calcN1N3($head+1); + } + + return $demerit; + } + + + //---------------------------------------------------------------------- + public function mask($width, $frame, $level) + { + $minDemerit = PHP_INT_MAX; + $bestMaskNum = 0; + $bestMask = array(); + + $checked_masks = array(0,1,2,3,4,5,6,7); + + if (QR_FIND_FROM_RANDOM !== false) { + + $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); + for ($i = 0; $i < $howManuOut; $i++) { + $remPos = rand (0, count($checked_masks)-1); + unset($checked_masks[$remPos]); + $checked_masks = array_values($checked_masks); + } + + } + + $bestMask = $frame; + + foreach($checked_masks as $i) { + $mask = array_fill(0, $width, str_repeat("\0", $width)); + + $demerit = 0; + $blacks = 0; + $blacks = $this->makeMaskNo($i, $width, $frame, $mask); + $blacks += $this->writeFormatInformation($width, $mask, $i, $level); + $blacks = (int)(100 * $blacks / ($width * $width)); + $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); + $demerit += $this->evaluateSymbol($width, $mask); + + if($demerit < $minDemerit) { + $minDemerit = $demerit; + $bestMask = $mask; + $bestMaskNum = $i; + } + } + + return $bestMask; + } + + //---------------------------------------------------------------------- + } + + + + +//---- qrencode.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Main encoder classes. + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRrsblock { + public $dataLength; + public $data = array(); + public $eccLength; + public $ecc = array(); + + public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs) + { + $rs->encode_rs_char($data, $ecc); + + $this->dataLength = $dl; + $this->data = $data; + $this->eccLength = $el; + $this->ecc = $ecc; + } + }; + + //########################################################################## + + class QRrawcode { + public $version; + public $datacode = array(); + public $ecccode = array(); + public $blocks; + public $rsblocks = array(); //of RSblock + public $count; + public $dataLength; + public $eccLength; + public $b1; + + //---------------------------------------------------------------------- + public function __construct(QRinput $input) + { + $spec = array(0,0,0,0,0); + + $this->datacode = $input->getByteStream(); + if(is_null($this->datacode)) { + throw new Exception('null imput string'); + } + + QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec); + + $this->version = $input->getVersion(); + $this->b1 = QRspec::rsBlockNum1($spec); + $this->dataLength = QRspec::rsDataLength($spec); + $this->eccLength = QRspec::rsEccLength($spec); + $this->ecccode = array_fill(0, $this->eccLength, 0); + $this->blocks = QRspec::rsBlockNum($spec); + + $ret = $this->init($spec); + if($ret < 0) { + throw new Exception('block alloc error'); + return null; + } + + $this->count = 0; + } + + //---------------------------------------------------------------------- + public function init(array $spec) + { + $dl = QRspec::rsDataCodes1($spec); + $el = QRspec::rsEccCodes1($spec); + $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); + + + $blockNo = 0; + $dataPos = 0; + $eccPos = 0; + for($i=0; $iecccode,$eccPos); + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); + + $dataPos += $dl; + $eccPos += $el; + $blockNo++; + } + + if(QRspec::rsBlockNum2($spec) == 0) + return 0; + + $dl = QRspec::rsDataCodes2($spec); + $el = QRspec::rsEccCodes2($spec); + $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); + + if($rs == NULL) return -1; + + for($i=0; $iecccode,$eccPos); + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); + + $dataPos += $dl; + $eccPos += $el; + $blockNo++; + } + + return 0; + } + + //---------------------------------------------------------------------- + public function getCode() + { + $ret; + + if($this->count < $this->dataLength) { + $row = $this->count % $this->blocks; + $col = $this->count / $this->blocks; + if($col >= $this->rsblocks[0]->dataLength) { + $row += $this->b1; + } + $ret = $this->rsblocks[$row]->data[$col]; + } else if($this->count < $this->dataLength + $this->eccLength) { + $row = ($this->count - $this->dataLength) % $this->blocks; + $col = ($this->count - $this->dataLength) / $this->blocks; + $ret = $this->rsblocks[$row]->ecc[$col]; + } else { + return 0; + } + $this->count++; + + return $ret; + } + } + + //########################################################################## + + class QRcode { + + public $version; + public $width; + public $data; + + //---------------------------------------------------------------------- + public function encodeMask(QRinput $input, $mask) + { + if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { + throw new Exception('wrong version'); + } + if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { + throw new Exception('wrong level'); + } + + $raw = new QRrawcode($input); + + QRtools::markTime('after_raw'); + + $version = $raw->version; + $width = QRspec::getWidth($version); + $frame = QRspec::newFrame($version); + + $filler = new FrameFiller($width, $frame); + if(is_null($filler)) { + return NULL; + } + + // inteleaved data and ecc codes + for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { + $code = $raw->getCode(); + $bit = 0x80; + for($j=0; $j<8; $j++) { + $addr = $filler->next(); + $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); + $bit = $bit >> 1; + } + } + + QRtools::markTime('after_filler'); + + unset($raw); + + // remainder bits + $j = QRspec::getRemainder($version); + for($i=0; $i<$j; $i++) { + $addr = $filler->next(); + $filler->setFrameAt($addr, 0x02); + } + + $frame = $filler->frame; + unset($filler); + + + // masking + $maskObj = new QRmask(); + if($mask < 0) { + + if (QR_FIND_BEST_MASK) { + $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); + } else { + $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel()); + } + } else { + $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); + } + + if($masked == NULL) { + return NULL; + } + + QRtools::markTime('after_mask'); + + $this->version = $version; + $this->width = $width; + $this->data = $masked; + + return $this; + } + + //---------------------------------------------------------------------- + public function encodeInput(QRinput $input) + { + return $this->encodeMask($input, -1); + } + + //---------------------------------------------------------------------- + public function encodeString8bit($string, $version, $level) + { + if(string == NULL) { + throw new Exception('empty string!'); + return NULL; + } + + $input = new QRinput($version, $level); + if($input == NULL) return NULL; + + $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); + if($ret < 0) { + unset($input); + return NULL; + } + return $this->encodeInput($input); + } + + //---------------------------------------------------------------------- + public function encodeString($string, $version, $level, $hint, $casesensitive) + { + + if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { + throw new Exception('bad hint'); + return NULL; + } + + $input = new QRinput($version, $level); + if($input == NULL) return NULL; + + $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); + if($ret < 0) { + return NULL; + } + + return $this->encodeInput($input); + } + + //---------------------------------------------------------------------- + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encodePNG($text, $outfile, $saveandprint=false); + } + + //---------------------------------------------------------------------- + public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encode($text, $outfile); + } + + //---------------------------------------------------------------------- + public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encodeRAW($text, $outfile); + } + } + + //########################################################################## + + class FrameFiller { + + public $width; + public $frame; + public $x; + public $y; + public $dir; + public $bit; + + //---------------------------------------------------------------------- + public function __construct($width, &$frame) + { + $this->width = $width; + $this->frame = $frame; + $this->x = $width - 1; + $this->y = $width - 1; + $this->dir = -1; + $this->bit = -1; + } + + //---------------------------------------------------------------------- + public function setFrameAt($at, $val) + { + $this->frame[$at['y']][$at['x']] = chr($val); + } + + //---------------------------------------------------------------------- + public function getFrameAt($at) + { + return ord($this->frame[$at['y']][$at['x']]); + } + + //---------------------------------------------------------------------- + public function next() + { + do { + + if($this->bit == -1) { + $this->bit = 0; + return array('x'=>$this->x, 'y'=>$this->y); + } + + $x = $this->x; + $y = $this->y; + $w = $this->width; + + if($this->bit == 0) { + $x--; + $this->bit++; + } else { + $x++; + $y += $this->dir; + $this->bit--; + } + + if($this->dir < 0) { + if($y < 0) { + $y = 0; + $x -= 2; + $this->dir = 1; + if($x == 6) { + $x--; + $y = 9; + } + } + } else { + if($y == $w) { + $y = $w - 1; + $x -= 2; + $this->dir = -1; + if($x == 6) { + $x--; + $y -= 8; + } + } + } + if($x < 0 || $y < 0) return null; + + $this->x = $x; + $this->y = $y; + + } while(ord($this->frame[$y][$x]) & 0x80); + + return array('x'=>$x, 'y'=>$y); + } + + } ; + + //########################################################################## + + class QRencode { + + public $casesensitive = true; + public $eightbit = false; + + public $version = 0; + public $size = 3; + public $margin = 4; + + public $structured = 0; // not supported yet + + public $level = QR_ECLEVEL_L; + public $hint = QR_MODE_8; + + //---------------------------------------------------------------------- + public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = new QRencode(); + $enc->size = $size; + $enc->margin = $margin; + + switch ($level.'') { + case '0': + case '1': + case '2': + case '3': + $enc->level = $level; + break; + case 'l': + case 'L': + $enc->level = QR_ECLEVEL_L; + break; + case 'm': + case 'M': + $enc->level = QR_ECLEVEL_M; + break; + case 'q': + case 'Q': + $enc->level = QR_ECLEVEL_Q; + break; + case 'h': + case 'H': + $enc->level = QR_ECLEVEL_H; + break; + } + + return $enc; + } + + //---------------------------------------------------------------------- + public function encodeRAW($intext, $outfile = false) + { + $code = new QRcode(); + + if($this->eightbit) { + $code->encodeString8bit($intext, $this->version, $this->level); + } else { + $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); + } + + return $code->data; + } + + //---------------------------------------------------------------------- + public function encode($intext, $outfile = false) + { + $code = new QRcode(); + + if($this->eightbit) { + $code->encodeString8bit($intext, $this->version, $this->level); + } else { + $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); + } + + QRtools::markTime('after_encode'); + + if ($outfile!== false) { + file_put_contents($outfile, join("\n", QRtools::binarize($code->data))); + } else { + return QRtools::binarize($code->data); + } + } + + //---------------------------------------------------------------------- + public function encodePNG($intext, $outfile = false,$saveandprint=false) + { + try { + + ob_start(); + $tab = $this->encode($intext); + $err = ob_get_contents(); + ob_end_clean(); + + if ($err != '') + QRtools::log($outfile, $err); + + $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); + + QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint); + + } catch (Exception $e) { + + QRtools::log($outfile, $e->getMessage()); + + } + } + } + +} diff --git a/app/lib/phpqrcode/CHANGELOG b/app/lib/phpqrcode/CHANGELOG new file mode 100644 index 00000000..1088530c --- /dev/null +++ b/app/lib/phpqrcode/CHANGELOG @@ -0,0 +1,38 @@ +* 1.0.0 build 2010031920 + + - first public release + - help in readme, install + - cleanup ans separation of QRtools and QRspec + - now TCPDF binding requires minimal changes in TCPDF, having most of job + done in QRtools tcpdfBarcodeArray + - nicer QRtools::timeBenchmark output + - license and copyright notices in files + - indent cleanup - from tab to 4spc, keep it that way please :) + - sf project, repository, wiki + - simple code generator in index.php + +* 1.1.0 build 2010032113 + + - added merge tool wich generate merged version of code + located in phpqrcode.php + - splited qrconst.php from qrlib.php + +* 1.1.1 build 2010032405 + + - patch by Rick Seymour allowing saving PNG and displaying it at the same time + - added version info in VERSION file + - modified merge tool to include version info into generated file + - fixed e-mail in almost all head comments + +* 1.1.2 build 2010032722 + + - full integration with TCPDF thanks to Nicola Asuni, it's author + - fixed bug with alphanumeric encoding detection + +* 1.1.3 build 2010081807 + + - short opening tags replaced with standard ones + +* 1.1.4 build 2010100721 + + - added missing static keyword QRinput::check (found by Luke Brookhart, Onjax LLC) diff --git a/app/lib/phpqrcode/INSTALL b/app/lib/phpqrcode/INSTALL new file mode 100644 index 00000000..eac6b072 --- /dev/null +++ b/app/lib/phpqrcode/INSTALL @@ -0,0 +1,67 @@ +== REQUIREMENTS == + + * PHP5 + * PHP GD2 extension with JPEG and PNG support + +== INSTALLATION == + +If you want to recreate cache by yourself make sure cache directory is +writable and you have permisions to write into it. Also make sure you are +able to read files in it if you have cache option enabled + +== CONFIGURATION == + +Feel free to modify config constants in qrconfig.php file. Read about it in +provided comments and project wiki page (links in README file) + +== QUICK START == + +Notice: probably you should'nt use all of this in same script :) + +encode('PHP QR Code :)'); +QRspec::debug($tab, true); + +== TCPDF INTEGRATION == + +Inside bindings/tcpdf you will find slightly modified 2dbarcodes.php. +Instal phpqrcode liblaty inside tcpdf folder, then overwrite (or merge) +2dbarcodes.php + +Then use similar as example #50 from TCPDF examples: + + true, + 'padding' => 4, + 'fgcolor' => array(0,0,0), + 'bgcolor' => false, //array(255,255,255) +); + +//code name: QR, specify error correction level after semicolon (L,M,Q,H) +$pdf->write2DBarcode('PHP QR Code :)', 'QR,L', '', '', 30, 30, $style, 'N'); diff --git a/app/lib/phpqrcode/LICENSE b/app/lib/phpqrcode/LICENSE new file mode 100644 index 00000000..18833032 --- /dev/null +++ b/app/lib/phpqrcode/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/app/lib/phpqrcode/README b/app/lib/phpqrcode/README new file mode 100644 index 00000000..a022fb5e --- /dev/null +++ b/app/lib/phpqrcode/README @@ -0,0 +1,45 @@ +This is PHP implementation of QR Code 2-D barcode generator. It is pure-php +LGPL-licensed implementation based on C libqrencode by Kentaro Fukuchi. + +== LICENSING == + +Copyright (C) 2010 by Dominik Dzienia + +This library is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the Free +Software Foundation; either version 3 of the License, or any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU Lesser General Public License (LICENSE file) +for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this library; if not, write to the Free Software Foundation, Inc., 51 +Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +== INSTALATION AND USAGE == + + * INSTALL file + * http://sourceforge.net/apps/mediawiki/phpqrcode/index.php?title=Main_Page + +== CONTACT == + +Fell free to contact me via e-mail (deltalab at poczta dot fm) or using +folowing project pages: + + * http://sourceforge.net/projects/phpqrcode/ + * http://phpqrcode.sourceforge.net/ + +== ACKNOWLEDGMENTS == + +Based on C libqrencode library (ver. 3.1.1) +Copyright (C) 2006-2010 by Kentaro Fukuchi +http://megaui.net/fukuchi/works/qrencode/index.en.html + +QR Code is registered trademarks of DENSO WAVE INCORPORATED in JAPAN and other +countries. + +Reed-Solomon code encoder is written by Phil Karn, KA9Q. +Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q + \ No newline at end of file diff --git a/app/lib/phpqrcode/VERSION b/app/lib/phpqrcode/VERSION new file mode 100644 index 00000000..9f99279e --- /dev/null +++ b/app/lib/phpqrcode/VERSION @@ -0,0 +1,2 @@ +1.1.4 +2010100721 \ No newline at end of file diff --git a/app/lib/phpqrcode/bindings/tcpdf/qrcode.php b/app/lib/phpqrcode/bindings/tcpdf/qrcode.php new file mode 100644 index 00000000..7995460b --- /dev/null +++ b/app/lib/phpqrcode/bindings/tcpdf/qrcode.php @@ -0,0 +1,2875 @@ + +// http://phpqrcode.sourceforge.net/ +// https://sourceforge.net/projects/phpqrcode/ +// +// The "PHP QR Code encoder" is based on +// "C libqrencode library" (ver. 3.1.1) +// License: GNU-LGPL 2.1 +// Copyright (C) 2006-2010 by Kentaro Fukuchi +// http://megaui.net/fukuchi/works/qrencode/index.en.html +// +// Reed-Solomon code encoder is written by Phil Karn, KA9Q. +// Copyright (C) 2002-2006 Phil Karn, KA9Q +// +// QR Code is registered trademark of DENSO WAVE INCORPORATED +// http://www.denso-wave.com/qrcode/index-e.html +// --------------------------------------------------------- +// +// Author: Nicola Asuni +// +// (c) Copyright 2010: +// Nicola Asuni +// Tecnick.com S.r.l. +// Via della Pace, 11 +// 09044 Quartucciu (CA) +// ITALY +// www.tecnick.com +// info@tecnick.com +//============================================================+ + +/** + * Class to create QR-code arrays for TCPDF class. + * QR Code symbol is a 2D barcode that can be scanned by handy terminals such as a mobile phone with CCD. + * The capacity of QR Code is up to 7000 digits or 4000 characters, and has high robustness. + * This class supports QR Code model 2, described in JIS (Japanese Industrial Standards) X0510:2004 or ISO/IEC 18004. + * Currently the following features are not supported: ECI and FNC1 mode, Micro QR Code, QR Code model 1, Structured mode. + * + * This class is derived from "PHP QR Code encoder" by Dominik Dzienia (http://phpqrcode.sourceforge.net/) based on "libqrencode C library 3.1.1." by Kentaro Fukuchi (http://megaui.net/fukuchi/works/qrencode/index.en.html), contains Reed-Solomon code written by Phil Karn, KA9Q. QR Code is registered trademark of DENSO WAVE INCORPORATED (http://www.denso-wave.com/qrcode/index-e.html). + * Please read comments on this class source file for full copyright and license information. + * + * @package com.tecnick.tcpdf + * @abstract Class for generating QR-code array for TCPDF. + * @author Nicola Asuni + * @copyright 2010 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com + * @link http://www.tcpdf.org + * @license http://www.gnu.org/copyleft/lesser.html LGPL + * @version 1.0.002 + */ + +// definitions +if (!defined('QRCODEDEFS')) { + + /** + * Indicate that definitions for this class are set + */ + define('QRCODEDEFS', true); + + // ----------------------------------------------------- + + // Encoding modes (characters which can be encoded in QRcode) + + /** + * Encoding mode + */ + define('QR_MODE_NL', -1); + + /** + * Encoding mode numeric (0-9). 3 characters are encoded to 10bit length. In theory, 7089 characters or less can be stored in a QRcode. + */ + define('QR_MODE_NM', 0); + + /** + * Encoding mode alphanumeric (0-9A-Z $%*+-./:) 45characters. 2 characters are encoded to 11bit length. In theory, 4296 characters or less can be stored in a QRcode. + */ + define('QR_MODE_AN', 1); + + /** + * Encoding mode 8bit byte data. In theory, 2953 characters or less can be stored in a QRcode. + */ + define('QR_MODE_8B', 2); + + /** + * Encoding mode KANJI. A KANJI character (multibyte character) is encoded to 13bit length. In theory, 1817 characters or less can be stored in a QRcode. + */ + define('QR_MODE_KJ', 3); + + /** + * Encoding mode STRUCTURED (currently unsupported) + */ + define('QR_MODE_ST', 4); + + // ----------------------------------------------------- + + // Levels of error correction. + // QRcode has a function of an error correcting for miss reading that white is black. + // Error correcting is defined in 4 level as below. + + /** + * Error correction level L : About 7% or less errors can be corrected. + */ + define('QR_ECLEVEL_L', 0); + + /** + * Error correction level M : About 15% or less errors can be corrected. + */ + define('QR_ECLEVEL_M', 1); + + /** + * Error correction level Q : About 25% or less errors can be corrected. + */ + define('QR_ECLEVEL_Q', 2); + + /** + * Error correction level H : About 30% or less errors can be corrected. + */ + define('QR_ECLEVEL_H', 3); + + // ----------------------------------------------------- + + // Version. Size of QRcode is defined as version. + // Version is from 1 to 40. + // Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. + // So version 40 is 177*177 matrix. + + /** + * Maximum QR Code version. + */ + define('QRSPEC_VERSION_MAX', 40); + + /** + * Maximum matrix size for maximum version (version 40 is 177*177 matrix). + */ + define('QRSPEC_WIDTH_MAX', 177); + + // ----------------------------------------------------- + + /** + * Matrix index to get width from $capacity array. + */ + define('QRCAP_WIDTH', 0); + + /** + * Matrix index to get number of words from $capacity array. + */ + define('QRCAP_WORDS', 1); + + /** + * Matrix index to get remainder from $capacity array. + */ + define('QRCAP_REMINDER', 2); + + /** + * Matrix index to get error correction level from $capacity array. + */ + define('QRCAP_EC', 3); + + // ----------------------------------------------------- + + // Structure (currently usupported) + + /** + * Number of header bits for structured mode + */ + define('STRUCTURE_HEADER_BITS', 20); + + /** + * Max number of symbols for structured mode + */ + define('MAX_STRUCTURED_SYMBOLS', 16); + + // ----------------------------------------------------- + + // Masks + + /** + * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column) + */ + define('N1', 3); + + /** + * Down point base value for case 2 mask pattern (module block of same color) + */ + define('N2', 3); + + /** + * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column) + */ + define('N3', 40); + + /** + * Down point base value for case 4 mask pattern (ration of dark modules in whole) + */ + define('N4', 10); + + // ----------------------------------------------------- + + // Optimization settings + + /** + * if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code + */ + define('QR_FIND_BEST_MASK', true); + + /** + * if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly + */ + define('QR_FIND_FROM_RANDOM', 2); + + /** + * when QR_FIND_BEST_MASK === false + */ + define('QR_DEFAULT_MASK', 2); + + // ----------------------------------------------------- + +} // end of definitions + +// #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*# + +if (!class_exists('QRcode', false)) { + + // for compaibility with PHP4 + if (!function_exists('str_split')) { + /** + * Convert a string to an array (needed for PHP4 compatibility) + * @param string $string The input string. + * @param int $split_length Maximum length of the chunk. + * @return If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element. + */ + function str_split($string, $split_length=1) { + if ((strlen($string) > $split_length) OR (!$split_length)) { + do { + $c = strlen($string); + $parts[] = substr($string, 0, $split_length); + $string = substr($string, $split_length); + } while ($string !== false); + } else { + $parts = array($string); + } + return $parts; + } + } + + // ##################################################### + + /** + * Class to create QR-code arrays for TCPDF class. + * QR Code symbol is a 2D barcode that can be scanned by handy terminals such as a mobile phone with CCD. + * The capacity of QR Code is up to 7000 digits or 4000 characters, and has high robustness. + * This class supports QR Code model 2, described in JIS (Japanese Industrial Standards) X0510:2004 or ISO/IEC 18004. + * Currently the following features are not supported: ECI and FNC1 mode, Micro QR Code, QR Code model 1, Structured mode. + * + * This class is derived from "PHP QR Code encoder" by Dominik Dzienia (http://phpqrcode.sourceforge.net/) based on "libqrencode C library 3.1.1." by Kentaro Fukuchi (http://megaui.net/fukuchi/works/qrencode/index.en.html), contains Reed-Solomon code written by Phil Karn, KA9Q. QR Code is registered trademark of DENSO WAVE INCORPORATED (http://www.denso-wave.com/qrcode/index-e.html). + * Please read comments on this class source file for full copyright and license information. + * + * @name QRcode + * @package com.tecnick.tcpdf + * @abstract Class for generating QR-code array for TCPDF. + * @author Nicola Asuni + * @copyright 2010 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com + * @link http://www.tcpdf.org + * @license http://www.gnu.org/copyleft/lesser.html LGPL + * @version 1.0.002 + */ + class QRcode { + + /** + * @var barcode array to be returned which is readable by TCPDF + * @access protected + */ + protected $barcode_array = array(); + + /** + * @var QR code version. Size of QRcode is defined as version. Version is from 1 to 40. Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. So version 40 is 177*177 matrix. + * @access protected + */ + protected $version = 0; + + /** + * @var Levels of error correction. See definitions for possible values. + * @access protected + */ + protected $level = QR_ECLEVEL_L; + + /** + * @var Encoding mode + * @access protected + */ + protected $hint = QR_MODE_8B; + + /** + * @var if true the input string will be converted to uppercase + * @access protected + */ + protected $casesensitive = true; + + /** + * @var structured QR code (not supported yet) + * @access protected + */ + protected $structured = 0; + + /** + * @var mask data + * @access protected + */ + protected $data; + + // FrameFiller + + /** + * @var width + * @access protected + */ + protected $width; + + /** + * @var frame + * @access protected + */ + protected $frame; + + /** + * @var X position of bit + * @access protected + */ + protected $x; + + /** + * @var Y position of bit + * @access protected + */ + protected $y; + + /** + * @var direction + * @access protected + */ + protected $dir; + + /** + * @var single bit + * @access protected + */ + protected $bit; + + // ---- QRrawcode ---- + + /** + * @var data code + * @access protected + */ + protected $datacode = array(); + + /** + * @var error correction code + * @access protected + */ + protected $ecccode = array(); + + /** + * @var blocks + * @access protected + */ + protected $blocks; + + /** + * @var Reed-Solomon blocks + * @access protected + */ + protected $rsblocks = array(); //of RSblock + + /** + * @var counter + * @access protected + */ + protected $count; + + /** + * @var data length + * @access protected + */ + protected $dataLength; + + /** + * @var error correction length + * @access protected + */ + protected $eccLength; + + /** + * @var b1 + * @access protected + */ + protected $b1; + + // ---- QRmask ---- + + /** + * @var run length + * @access protected + */ + protected $runLength = array(); + + // ---- QRsplit ---- + + /** + * @var input data string + * @access protected + */ + protected $dataStr = ''; + + /** + * @var input items + * @access protected + */ + protected $items; + + // Reed-Solomon items + + /** + * @var Reed-Solomon items + * @access protected + */ + protected $rsitems = array(); + + /** + * @var array of frames + * @access protected + */ + protected $frames = array(); + + /** + * @var alphabet-numeric convesion table + * @access protected + */ + protected $anTable = array( + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // + 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, // + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // + -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, // + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // + ); + + /** + * @var array Table of the capacity of symbols + * See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004. + * @access protected + */ + protected $capacity = array( + array( 0, 0, 0, array( 0, 0, 0, 0)), // + array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 + array( 25, 44, 7, array( 10, 16, 22, 28)), // + array( 29, 70, 7, array( 15, 26, 36, 44)), // + array( 33, 100, 7, array( 20, 36, 52, 64)), // + array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 + array( 41, 172, 7, array( 36, 64, 96, 112)), // + array( 45, 196, 0, array( 40, 72, 108, 130)), // + array( 49, 242, 0, array( 48, 88, 132, 156)), // + array( 53, 292, 0, array( 60, 110, 160, 192)), // + array( 57, 346, 0, array( 72, 130, 192, 224)), // 10 + array( 61, 404, 0, array( 80, 150, 224, 264)), // + array( 65, 466, 0, array( 96, 176, 260, 308)), // + array( 69, 532, 0, array( 104, 198, 288, 352)), // + array( 73, 581, 3, array( 120, 216, 320, 384)), // + array( 77, 655, 3, array( 132, 240, 360, 432)), // 15 + array( 81, 733, 3, array( 144, 280, 408, 480)), // + array( 85, 815, 3, array( 168, 308, 448, 532)), // + array( 89, 901, 3, array( 180, 338, 504, 588)), // + array( 93, 991, 3, array( 196, 364, 546, 650)), // + array( 97, 1085, 3, array( 224, 416, 600, 700)), // 20 + array(101, 1156, 4, array( 224, 442, 644, 750)), // + array(105, 1258, 4, array( 252, 476, 690, 816)), // + array(109, 1364, 4, array( 270, 504, 750, 900)), // + array(113, 1474, 4, array( 300, 560, 810, 960)), // + array(117, 1588, 4, array( 312, 588, 870, 1050)), // 25 + array(121, 1706, 4, array( 336, 644, 952, 1110)), // + array(125, 1828, 4, array( 360, 700, 1020, 1200)), // + array(129, 1921, 3, array( 390, 728, 1050, 1260)), // + array(133, 2051, 3, array( 420, 784, 1140, 1350)), // + array(137, 2185, 3, array( 450, 812, 1200, 1440)), // 30 + array(141, 2323, 3, array( 480, 868, 1290, 1530)), // + array(145, 2465, 3, array( 510, 924, 1350, 1620)), // + array(149, 2611, 3, array( 540, 980, 1440, 1710)), // + array(153, 2761, 3, array( 570, 1036, 1530, 1800)), // + array(157, 2876, 0, array( 570, 1064, 1590, 1890)), // 35 + array(161, 3034, 0, array( 600, 1120, 1680, 1980)), // + array(165, 3196, 0, array( 630, 1204, 1770, 2100)), // + array(169, 3362, 0, array( 660, 1260, 1860, 2220)), // + array(173, 3532, 0, array( 720, 1316, 1950, 2310)), // + array(177, 3706, 0, array( 750, 1372, 2040, 2430)) // 40 + ); + + /** + * @var array Length indicator + * @access protected + */ + protected $lengthTableBits = array( + array(10, 12, 14), + array( 9, 11, 13), + array( 8, 16, 16), + array( 8, 10, 12) + ); + + /** + * @var array Table of the error correction code (Reed-Solomon block) + * See Table 12-16 (pp.30-36), JIS X0510:2004. + * @access protected + */ + protected $eccTable = array( + array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), // + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // + array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), // + array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), // + array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 + array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), // + array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), // + array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), // + array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), // + array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), // 10 + array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), // + array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), // + array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), // + array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), // + array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), // 15 + array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), // + array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), // + array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), // + array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), // + array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), // 20 + array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), // + array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), // + array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), // + array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), // + array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), // 25 + array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), // + array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), // + array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), // + array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), // + array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30 + array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), // + array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), // + array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), // + array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), // + array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), // 35 + array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), // + array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), // + array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), // + array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), // + array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)) // 40 + ); + + /** + * @var array Positions of alignment patterns. + * This array includes only the second and the third position of the alignment patterns. Rest of them can be calculated from the distance between them. + * See Table 1 in Appendix E (pp.71) of JIS X0510:2004. + * @access protected + */ + protected $alignmentPattern = array( + array( 0, 0), + array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 + array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 + array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), // 11-15 + array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), // 16-20 + array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), // 21-25 + array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), // 26-30 + array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), // 31-35 + array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58) // 35-40 + ); + + /** + * @var array Version information pattern (BCH coded). + * See Table 1 in Appendix D (pp.68) of JIS X0510:2004. + * size: [QRSPEC_VERSION_MAX - 6] + * @access protected + */ + protected $versionPattern = array( + 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, // + 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, // + 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, // + 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, // + 0x27541, 0x28c69 + ); + + /** + * @var array Format information + * @access protected + */ + protected $formatInfo = array( + array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), // + array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), // + array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), // + array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b) // + ); + + + // ------------------------------------------------- + // ------------------------------------------------- + + + /** + * This is the class constructor. + * Creates a QRcode object + * @param string $code code to represent using QRcode + * @param string $eclevel error level:
  • L : About 7% or less errors can be corrected.
  • M : About 15% or less errors can be corrected.
  • Q : About 25% or less errors can be corrected.
  • H : About 30% or less errors can be corrected.
+ * @access public + * @since 1.0.000 + */ + public function __construct($code, $eclevel = 'L') { + $barcode_array = array(); + if ((is_null($code)) OR ($code == '\0') OR ($code == '')) { + return false; + } + // set error correction level + $this->level = array_search($eclevel, array('L', 'M', 'Q', 'H')); + if ($this->level === false) { + $this->level = QR_ECLEVEL_L; + } + if (($this->hint != QR_MODE_8B) AND ($this->hint != QR_MODE_KJ)) { + return false; + } + if (($this->version < 0) OR ($this->version > QRSPEC_VERSION_MAX)) { + return false; + } + $this->items = array(); + $this->encodeString($code); + $qrTab = $this->binarize($this->data); + $size = count($qrTab); + $barcode_array['num_rows'] = $size; + $barcode_array['num_cols'] = $size; + $barcode_array['bcode'] = array(); + foreach ($qrTab as $line) { + $arrAdd = array(); + foreach (str_split($line) as $char) { + $arrAdd[] = ($char=='1')?1:0; + } + $barcode_array['bcode'][] = $arrAdd; + } + $this->barcode_array = $barcode_array; + } + + /** + * Returns a barcode array which is readable by TCPDF + * @return array barcode array readable by TCPDF; + * @access public + */ + public function getBarcodeArray() { + return $this->barcode_array; + } + + /** + * Convert the frame in binary form + * @param array $frame array to binarize + * @return array frame in binary form + */ + protected function binarize($frame) { + $len = count($frame); + // the frame is square (width = height) + foreach ($frame as &$frameLine) { + for ($i=0; $i<$len; $i++) { + $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; + } + } + return $frame; + } + + /** + * Encode the input string to QR code + * @param string $string input string to encode + */ + protected function encodeString($string) { + $this->dataStr = $string; + if (!$this->casesensitive) { + $this->toUpper(); + } + $ret = $this->splitString(); + if ($ret < 0) { + return NULL; + } + $this->encodeMask(-1); + } + + /** + * Encode mask + * @param int $mask masking mode + */ + protected function encodeMask($mask) { + $spec = array(0, 0, 0, 0, 0); + $this->datacode = $this->getByteStream($this->items); + if (is_null($this->datacode)) { + return NULL; + } + $spec = $this->getEccSpec($this->version, $this->level, $spec); + $this->b1 = $this->rsBlockNum1($spec); + $this->dataLength = $this->rsDataLength($spec); + $this->eccLength = $this->rsEccLength($spec); + $this->ecccode = array_fill(0, $this->eccLength, 0); + $this->blocks = $this->rsBlockNum($spec); + $ret = $this->init($spec); + if ($ret < 0) { + return NULL; + } + $this->count = 0; + $this->width = $this->getWidth($this->version); + $this->frame = $this->newFrame($this->version); + $this->x = $this->width - 1; + $this->y = $this->width - 1; + $this->dir = -1; + $this->bit = -1; + // inteleaved data and ecc codes + for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) { + $code = $this->getCode(); + $bit = 0x80; + for ($j=0; $j<8; $j++) { + $addr = $this->getNextPosition(); + $this->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); + $bit = $bit >> 1; + } + } + // remainder bits + $j = $this->getRemainder($this->version); + for ($i=0; $i<$j; $i++) { + $addr = $this->getNextPosition(); + $this->setFrameAt($addr, 0x02); + } + // masking + $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); + if ($mask < 0) { + if (QR_FIND_BEST_MASK) { + $masked = $this->mask($this->width, $this->frame, $this->level); + } else { + $masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) % 8), $this->level); + } + } else { + $masked = $this->makeMask($this->width, $this->frame, $mask, $this->level); + } + if ($masked == NULL) { + return NULL; + } + $this->data = $masked; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - + + // FrameFiller + + /** + * Set frame value at specified position + * @param array $at x,y position + * @param int $val value of the character to set + */ + protected function setFrameAt($at, $val) { + $this->frame[$at['y']][$at['x']] = chr($val); + } + + /** + * Get frame value at specified position + * @param array $at x,y position + * @return value at specified position + */ + protected function getFrameAt($at) { + return ord($this->frame[$at['y']][$at['x']]); + } + + /** + * Return the next frame position + * @return array of x,y coordinates + */ + protected function getNextPosition() { + do { + if ($this->bit == -1) { + $this->bit = 0; + return array('x'=>$this->x, 'y'=>$this->y); + } + $x = $this->x; + $y = $this->y; + $w = $this->width; + if ($this->bit == 0) { + $x--; + $this->bit++; + } else { + $x++; + $y += $this->dir; + $this->bit--; + } + if ($this->dir < 0) { + if ($y < 0) { + $y = 0; + $x -= 2; + $this->dir = 1; + if ($x == 6) { + $x--; + $y = 9; + } + } + } else { + if ($y == $w) { + $y = $w - 1; + $x -= 2; + $this->dir = -1; + if ($x == 6) { + $x--; + $y -= 8; + } + } + } + if (($x < 0) OR ($y < 0)) { + return NULL; + } + $this->x = $x; + $this->y = $y; + } while(ord($this->frame[$y][$x]) & 0x80); + return array('x'=>$x, 'y'=>$y); + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - + + // QRrawcode + + /** + * Initialize code. + * @param array $spec array of ECC specification + * @return 0 in case of success, -1 in case of error + */ + protected function init($spec) { + $dl = $this->rsDataCodes1($spec); + $el = $this->rsEccCodes1($spec); + $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); + $blockNo = 0; + $dataPos = 0; + $eccPos = 0; + $endfor = $this->rsBlockNum1($spec); + for ($i=0; $i < $endfor; ++$i) { + $ecc = array_slice($this->ecccode, $eccPos); + $this->rsblocks[$blockNo] = array(); + $this->rsblocks[$blockNo]['dataLength'] = $dl; + $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos); + $this->rsblocks[$blockNo]['eccLength'] = $el; + $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); + $this->rsblocks[$blockNo]['ecc'] = $ecc; + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); + $dataPos += $dl; + $eccPos += $el; + $blockNo++; + } + if ($this->rsBlockNum2($spec) == 0) { + return 0; + } + $dl = $this->rsDataCodes2($spec); + $el = $this->rsEccCodes2($spec); + $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); + if ($rs == NULL) { + return -1; + } + $endfor = $this->rsBlockNum2($spec); + for ($i=0; $i < $endfor; ++$i) { + $ecc = array_slice($this->ecccode, $eccPos); + $this->rsblocks[$blockNo] = array(); + $this->rsblocks[$blockNo]['dataLength'] = $dl; + $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos); + $this->rsblocks[$blockNo]['eccLength'] = $el; + $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); + $this->rsblocks[$blockNo]['ecc'] = $ecc; + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); + $dataPos += $dl; + $eccPos += $el; + $blockNo++; + } + return 0; + } + + /** + * Return Reed-Solomon block code. + * @return array rsblocks + */ + protected function getCode() { + if ($this->count < $this->dataLength) { + $row = $this->count % $this->blocks; + $col = $this->count / $this->blocks; + if ($col >= $this->rsblocks[0]['dataLength']) { + $row += $this->b1; + } + $ret = $this->rsblocks[$row]['data'][$col]; + } elseif ($this->count < $this->dataLength + $this->eccLength) { + $row = ($this->count - $this->dataLength) % $this->blocks; + $col = ($this->count - $this->dataLength) / $this->blocks; + $ret = $this->rsblocks[$row]['ecc'][$col]; + } else { + return 0; + } + $this->count++; + return $ret; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - + + // QRmask + + /** + * Write Format Information on frame and returns the number of black bits + * @param int $width frame width + * @param array $frame frame + * @param array $mask masking mode + * @param int $level error correction level + * @return int blacks + */ + protected function writeFormatInformation($width, &$frame, $mask, $level) { + $blacks = 0; + $format = $this->getFormatInfo($mask, $level); + for ($i=0; $i<8; ++$i) { + if ($format & 1) { + $blacks += 2; + $v = 0x85; + } else { + $v = 0x84; + } + $frame[8][$width - 1 - $i] = chr($v); + if ($i < 6) { + $frame[$i][8] = chr($v); + } else { + $frame[$i + 1][8] = chr($v); + } + $format = $format >> 1; + } + for ($i=0; $i<7; ++$i) { + if ($format & 1) { + $blacks += 2; + $v = 0x85; + } else { + $v = 0x84; + } + $frame[$width - 7 + $i][8] = chr($v); + if ($i == 0) { + $frame[8][7] = chr($v); + } else { + $frame[8][6 - $i] = chr($v); + } + $format = $format >> 1; + } + return $blacks; + } + + /** + * mask0 + * @param int $x X position + * @param int $y Y position + * @return int mask + */ + protected function mask0($x, $y) { + return ($x + $y) & 1; + } + + /** + * mask1 + * @param int $x X position + * @param int $y Y position + * @return int mask + */ + protected function mask1($x, $y) { + return ($y & 1); + } + + /** + * mask2 + * @param int $x X position + * @param int $y Y position + * @return int mask + */ + protected function mask2($x, $y) { + return ($x % 3); + } + + /** + * mask3 + * @param int $x X position + * @param int $y Y position + * @return int mask + */ + protected function mask3($x, $y) { + return ($x + $y) % 3; + } + + /** + * mask4 + * @param int $x X position + * @param int $y Y position + * @return int mask + */ + protected function mask4($x, $y) { + return (((int)($y / 2)) + ((int)($x / 3))) & 1; + } + + /** + * mask5 + * @param int $x X position + * @param int $y Y position + * @return int mask + */ + protected function mask5($x, $y) { + return (($x * $y) & 1) + ($x * $y) % 3; + } + + /** + * mask6 + * @param int $x X position + * @param int $y Y position + * @return int mask + */ + protected function mask6($x, $y) { + return ((($x * $y) & 1) + ($x * $y) % 3) & 1; + } + + /** + * mask7 + * @param int $x X position + * @param int $y Y position + * @return int mask + */ + protected function mask7($x, $y) { + return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; + } + + /** + * Return bitmask + * @param int $maskNo mask number + * @param int $width width + * @param array $frame frame + * @return array bitmask + */ + protected function generateMaskNo($maskNo, $width, $frame) { + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); + for ($y=0; $y<$width; ++$y) { + for ($x=0; $x<$width; ++$x) { + if (ord($frame[$y][$x]) & 0x80) { + $bitMask[$y][$x] = 0; + } else { + $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); + $bitMask[$y][$x] = ($maskFunc == 0)?1:0; + } + } + } + return $bitMask; + } + + /** + * makeMaskNo + * @param int $maskNo + * @param int $width + * @param int $s + * @param int $d + * @param boolean $maskGenOnly + * @return int b + */ + protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) { + $b = 0; + $bitMask = array(); + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); + if ($maskGenOnly) { + return; + } + $d = $s; + for ($y=0; $y<$width; ++$y) { + for ($x=0; $x<$width; ++$x) { + if ($bitMask[$y][$x] == 1) { + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); + } + $b += (int)(ord($d[$y][$x]) & 1); + } + } + return $b; + } + + /** + * makeMask + * @param int $width + * @param array $frame + * @param int $maskNo + * @param int $level + * @return array mask + */ + protected function makeMask($width, $frame, $maskNo, $level) { + $masked = array_fill(0, $width, str_repeat("\0", $width)); + $this->makeMaskNo($maskNo, $width, $frame, $masked); + $this->writeFormatInformation($width, $masked, $maskNo, $level); + return $masked; + } + + /** + * calcN1N3 + * @param int $length + * @return int demerit + */ + protected function calcN1N3($length) { + $demerit = 0; + for ($i=0; $i<$length; ++$i) { + if ($this->runLength[$i] >= 5) { + $demerit += (N1 + ($this->runLength[$i] - 5)); + } + if ($i & 1) { + if (($i >= 3) AND ($i < ($length-2)) AND ($this->runLength[$i] % 3 == 0)) { + $fact = (int)($this->runLength[$i] / 3); + if (($this->runLength[$i-2] == $fact) + AND ($this->runLength[$i-1] == $fact) + AND ($this->runLength[$i+1] == $fact) + AND ($this->runLength[$i+2] == $fact)) { + if (($this->runLength[$i-3] < 0) OR ($this->runLength[$i-3] >= (4 * $fact))) { + $demerit += N3; + } elseif ((($i+3) >= $length) OR ($this->runLength[$i+3] >= (4 * $fact))) { + $demerit += N3; + } + } + } + } + } + return $demerit; + } + + /** + * evaluateSymbol + * @param int $width + * @param array $frame + * @return int demerit + */ + protected function evaluateSymbol($width, $frame) { + $head = 0; + $demerit = 0; + for ($y=0; $y<$width; ++$y) { + $head = 0; + $this->runLength[0] = 1; + $frameY = $frame[$y]; + if ($y > 0) { + $frameYM = $frame[$y-1]; + } + for ($x=0; $x<$width; ++$x) { + if (($x > 0) AND ($y > 0)) { + $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); + $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); + if (($b22 | ($w22 ^ 1)) & 1) { + $demerit += N2; + } + } + if (($x == 0) AND (ord($frameY[$x]) & 1)) { + $this->runLength[0] = -1; + $head = 1; + $this->runLength[$head] = 1; + } elseif ($x > 0) { + if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { + $head++; + $this->runLength[$head] = 1; + } else { + $this->runLength[$head]++; + } + } + } + $demerit += $this->calcN1N3($head+1); + } + for ($x=0; $x<$width; ++$x) { + $head = 0; + $this->runLength[0] = 1; + for ($y=0; $y<$width; ++$y) { + if (($y == 0) AND (ord($frame[$y][$x]) & 1)) { + $this->runLength[0] = -1; + $head = 1; + $this->runLength[$head] = 1; + } elseif ($y > 0) { + if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { + $head++; + $this->runLength[$head] = 1; + } else { + $this->runLength[$head]++; + } + } + } + $demerit += $this->calcN1N3($head+1); + } + return $demerit; + } + + /** + * mask + * @param int $width + * @param array $frame + * @param int $level + * @return array best mask + */ + protected function mask($width, $frame, $level) { + $minDemerit = PHP_INT_MAX; + $bestMaskNum = 0; + $bestMask = array(); + $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7); + if (QR_FIND_FROM_RANDOM !== false) { + $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); + for ($i = 0; $i < $howManuOut; ++$i) { + $remPos = rand (0, count($checked_masks)-1); + unset($checked_masks[$remPos]); + $checked_masks = array_values($checked_masks); + } + } + $bestMask = $frame; + foreach ($checked_masks as $i) { + $mask = array_fill(0, $width, str_repeat("\0", $width)); + $demerit = 0; + $blacks = 0; + $blacks = $this->makeMaskNo($i, $width, $frame, $mask); + $blacks += $this->writeFormatInformation($width, $mask, $i, $level); + $blacks = (int)(100 * $blacks / ($width * $width)); + $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); + $demerit += $this->evaluateSymbol($width, $mask); + if ($demerit < $minDemerit) { + $minDemerit = $demerit; + $bestMask = $mask; + $bestMaskNum = $i; + } + } + return $bestMask; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - + + // QRsplit + + /** + * Return true if the character at specified position is a number + * @param string $str string + * @param int $pos characted position + * @return boolean true of false + */ + protected function isdigitat($str, $pos) { + if ($pos >= strlen($str)) { + return false; + } + return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); + } + + /** + * Return true if the character at specified position is an alphanumeric character + * @param string $str string + * @param int $pos characted position + * @return boolean true of false + */ + protected function isalnumat($str, $pos) { + if ($pos >= strlen($str)) { + return false; + } + return ($this->lookAnTable(ord($str[$pos])) >= 0); + } + + /** + * identifyMode + * @param int $pos + * @return int mode + */ + protected function identifyMode($pos) { + if ($pos >= strlen($this->dataStr)) { + return QR_MODE_NL; + } + $c = $this->dataStr[$pos]; + if ($this->isdigitat($this->dataStr, $pos)) { + return QR_MODE_NM; + } elseif ($this->isalnumat($this->dataStr, $pos)) { + return QR_MODE_AN; + } elseif ($this->hint == QR_MODE_KJ) { + if ($pos+1 < strlen($this->dataStr)) { + $d = $this->dataStr[$pos+1]; + $word = (ord($c) << 8) | ord($d); + if (($word >= 0x8140 && $word <= 0x9ffc) OR ($word >= 0xe040 && $word <= 0xebbf)) { + return QR_MODE_KJ; + } + } + } + return QR_MODE_8B; + } + + /** + * eatNum + * @return int run + */ + protected function eatNum() { + $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); + $p = 0; + while($this->isdigitat($this->dataStr, $p)) { + $p++; + } + $run = $p; + $mode = $this->identifyMode($p); + if ($mode == QR_MODE_8B) { + $dif = $this->estimateBitsModeNum($run) + 4 + $ln + + $this->estimateBitsMode8(1) // + 4 + l8 + - $this->estimateBitsMode8($run + 1); // - 4 - l8 + if ($dif > 0) { + return $this->eat8(); + } + } + if ($mode == QR_MODE_AN) { + $dif = $this->estimateBitsModeNum($run) + 4 + $ln + + $this->estimateBitsModeAn(1) // + 4 + la + - $this->estimateBitsModeAn($run + 1);// - 4 - la + if ($dif > 0) { + return $this->eatAn(); + } + } + $this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr)); + return $run; + } + + /** + * eatAn + * @return int run + */ + protected function eatAn() { + $la = $this->lengthIndicator(QR_MODE_AN, $this->version); + $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); + $p = 0; + while($this->isalnumat($this->dataStr, $p)) { + if ($this->isdigitat($this->dataStr, $p)) { + $q = $p; + while($this->isdigitat($this->dataStr, $q)) { + $q++; + } + $dif = $this->estimateBitsModeAn($p) // + 4 + la + + $this->estimateBitsModeNum($q - $p) + 4 + $ln + - $this->estimateBitsModeAn($q); // - 4 - la + if ($dif < 0) { + break; + } else { + $p = $q; + } + } else { + $p++; + } + } + $run = $p; + if (!$this->isalnumat($this->dataStr, $p)) { + $dif = $this->estimateBitsModeAn($run) + 4 + $la + + $this->estimateBitsMode8(1) // + 4 + l8 + - $this->estimateBitsMode8($run + 1); // - 4 - l8 + if ($dif > 0) { + return $this->eat8(); + } + } + $this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr)); + return $run; + } + + /** + * eatKanji + * @return int run + */ + protected function eatKanji() { + $p = 0; + while($this->identifyMode($p) == QR_MODE_KJ) { + $p += 2; + } + $this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr)); + return $run; + } + + /** + * eat8 + * @return int run + */ + protected function eat8() { + $la = $this->lengthIndicator(QR_MODE_AN, $this->version); + $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); + $p = 1; + $dataStrLen = strlen($this->dataStr); + while($p < $dataStrLen) { + $mode = $this->identifyMode($p); + if ($mode == QR_MODE_KJ) { + break; + } + if ($mode == QR_MODE_NM) { + $q = $p; + while($this->isdigitat($this->dataStr, $q)) { + $q++; + } + $dif = $this->estimateBitsMode8($p) // + 4 + l8 + + $this->estimateBitsModeNum($q - $p) + 4 + $ln + - $this->estimateBitsMode8($q); // - 4 - l8 + if ($dif < 0) { + break; + } else { + $p = $q; + } + } elseif ($mode == QR_MODE_AN) { + $q = $p; + while($this->isalnumat($this->dataStr, $q)) { + $q++; + } + $dif = $this->estimateBitsMode8($p) // + 4 + l8 + + $this->estimateBitsModeAn($q - $p) + 4 + $la + - $this->estimateBitsMode8($q); // - 4 - l8 + if ($dif < 0) { + break; + } else { + $p = $q; + } + } else { + $p++; + } + } + $run = $p; + $this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr)); + return $run; + } + + /** + * splitString + */ + protected function splitString() { + while (strlen($this->dataStr) > 0) { + if ($this->dataStr == '') { + return 0; + } + $mode = $this->identifyMode(0); + switch ($mode) { + case QR_MODE_NM: { + $length = $this->eatNum(); + break; + } + case QR_MODE_AN: { + $length = $this->eatAn(); + break; + } + case QR_MODE_KJ: { + if ($hint == QR_MODE_KJ) { + $length = $this->eatKanji(); + } else { + $length = $this->eat8(); + } + break; + } + default: { + $length = $this->eat8(); + break; + } + } + if ($length == 0) { + return 0; + } + if ($length < 0) { + return -1; + } + $this->dataStr = substr($this->dataStr, $length); + } + } + + /** + * toUpper + */ + protected function toUpper() { + $stringLen = strlen($this->dataStr); + $p = 0; + while ($p < $stringLen) { + $mode = $this->identifyMode(substr($this->dataStr, $p), $this->hint); + if ($mode == QR_MODE_KJ) { + $p += 2; + } else { + if ((ord($this->dataStr[$p]) >= ord('a')) AND (ord($this->dataStr[$p]) <= ord('z'))) { + $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); + } + $p++; + } + } + return $this->dataStr; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - + + // QRinputItem + + /** + * newInputItem + * @param int $mode + * @param int $size + * @param array $data + * @param array $bstream + * @return array input item + */ + protected function newInputItem($mode, $size, $data, $bstream=null) { + $setData = array_slice($data, 0, $size); + if (count($setData) < $size) { + $setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0)); + } + if (!$this->check($mode, $size, $setData)) { + return NULL; + } + $inputitem = array(); + $inputitem['mode'] = $mode; + $inputitem['size'] = $size; + $inputitem['data'] = $setData; + $inputitem['bstream'] = $bstream; + return $inputitem; + } + + /** + * encodeModeNum + * @param array $inputitem + * @param int $version + * @return array input item + */ + protected function encodeModeNum($inputitem, $version) { + $words = (int)($inputitem['size'] / 3); + $inputitem['bstream'] = array(); + $val = 0x1; + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']); + for ($i=0; $i < $words; ++$i) { + $val = (ord($inputitem['data'][$i*3 ]) - ord('0')) * 100; + $val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10; + $val += (ord($inputitem['data'][$i*3+2]) - ord('0')); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val); + } + if ($inputitem['size'] - $words * 3 == 1) { + $val = ord($inputitem['data'][$words*3]) - ord('0'); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); + } elseif (($inputitem['size'] - ($words * 3)) == 2) { + $val = (ord($inputitem['data'][$words*3 ]) - ord('0')) * 10; + $val += (ord($inputitem['data'][$words*3+1]) - ord('0')); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val); + } + return $inputitem; + } + + /** + * encodeModeAn + * @param array $inputitem + * @param int $version + * @return array input item + */ + protected function encodeModeAn($inputitem, $version) { + $words = (int)($inputitem['size'] / 2); + $inputitem['bstream'] = array(); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02); + $inputitem['bstream'] = $this->appendNum(v, $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']); + for ($i=0; $i < $words; ++$i) { + $val = (int)$this->lookAnTable(ord($inputitem['data'][$i*2 ])) * 45; + $val += (int)$this->lookAnTable(ord($inputitem['data'][$i*2+1])); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val); + } + if ($inputitem['size'] & 1) { + $val = $this->lookAnTable(ord($inputitem['data'][($words * 2)])); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val); + } + return $inputitem; + } + + /** + * encodeMode8 + * @param array $inputitem + * @param int $version + * @return array input item + */ + protected function encodeMode8($inputitem, $version) { + $inputitem['bstream'] = array(); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']); + for ($i=0; $i < $inputitem['size']; ++$i) { + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i])); + } + return $inputitem; + } + + /** + * encodeModeKanji + * @param array $inputitem + * @param int $version + * @return array input item + */ + protected function encodeModeKanji($inputitem, $version) { + $inputitem['bstream'] = array(); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2)); + for ($i=0; $i<$inputitem['size']; $i+=2) { + $val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]); + if ($val <= 0x9ffc) { + $val -= 0x8140; + } else { + $val -= 0xc140; + } + $h = ($val >> 8) * 0xc0; + $val = ($val & 0xff) + $h; + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val); + } + return $inputitem; + } + + /** + * encodeModeStructure + * @param array $inputitem + * @return array input item + */ + protected function encodeModeStructure($inputitem) { + $inputitem['bstream'] = array(); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1); + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2])); + return $inputitem; + } + + /** + * encodeBitStream + * @param array $inputitem + * @param int $version + * @return array input item + */ + protected function encodeBitStream($inputitem, $version) { + $inputitem['bstream'] = array(); + $words = $this->maximumWords($inputitem['mode'], $version); + if ($inputitem['size'] > $words) { + $st1 = $this->newInputItem($inputitem['mode'], $words, $inputitem['data']); + $st2 = $this->newInputItem($inputitem['mode'], $inputitem['size'] - $words, array_slice($inputitem['data'], $words)); + $st1 = $this->encodeBitStream($st1, $version); + $st2 = $this->encodeBitStream($st2, $version); + $inputitem['bstream'] = array(); + $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']); + $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']); + } else { + switch($inputitem['mode']) { + case QR_MODE_NM: { + $inputitem = $this->encodeModeNum($inputitem, $version); + break; + } + case QR_MODE_AN: { + $inputitem = $this->encodeModeAn($inputitem, $version); + break; + } + case QR_MODE_8B: { + $inputitem = $this->encodeMode8($inputitem, $version); + break; + } + case QR_MODE_KJ: { + $inputitem = $this->encodeModeKanji($inputitem, $version); + break; + } + case QR_MODE_ST: { + $inputitem = $this->encodeModeStructure($inputitem); + break; + } + default: { + break; + } + } + } + return $inputitem; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - + + // QRinput + + /** + * Append data to an input object. + * The data is copied and appended to the input object. + * @param array items input items + * @param int $mode encoding mode. + * @param int $size size of data (byte). + * @param array $data array of input data. + * @return items + * + */ + protected function appendNewInputItem($items, $mode, $size, $data) { + $items[] = $this->newInputItem($mode, $size, $data); + return $items; + } + + /** + * insertStructuredAppendHeader + * @param array $items + * @param int $size + * @param int $index + * @param int $parity + * @return array items + */ + protected function insertStructuredAppendHeader($items, $size, $index, $parity) { + if ($size > MAX_STRUCTURED_SYMBOLS) { + return -1; + } + if (($index <= 0) OR ($index > MAX_STRUCTURED_SYMBOLS)) { + return -1; + } + $buf = array($size, $index, $parity); + $entry = $this->newInputItem(QR_MODE_ST, 3, buf); + array_unshift($items, $entry); + return $items; + } + + /** + * calcParity + * @param array $items + * @return int parity + */ + protected function calcParity($items) { + $parity = 0; + foreach ($items as $item) { + if ($item['mode'] != QR_MODE_ST) { + for ($i=$item['size']-1; $i>=0; --$i) { + $parity ^= $item['data'][$i]; + } + } + } + return $parity; + } + + /** + * checkModeNum + * @param int $size + * @param array $data + * @return boolean true or false + */ + protected function checkModeNum($size, $data) { + for ($i=0; $i<$size; ++$i) { + if ((ord($data[$i]) < ord('0')) OR (ord($data[$i]) > ord('9'))){ + return false; + } + } + return true; + } + + /** + * estimateBitsModeNum + * @param int $size + * @return int number of bits + */ + protected function estimateBitsModeNum($size) { + $w = (int)$size / 3; + $bits = $w * 10; + switch($size - $w * 3) { + case 1: { + $bits += 4; + break; + } + case 2: { + $bits += 7; + break; + } + default: { + break; + } + } + return $bits; + } + + /** + * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). + * @param int $c character value + * @return value + */ + protected function lookAnTable($c) { + return (($c > 127)?-1:$this->anTable[$c]); + } + + /** + * checkModeAn + * @param int $size + * @param array $data + * @return boolean true or false + */ + protected function checkModeAn($size, $data) { + for ($i=0; $i<$size; ++$i) { + if ($this->lookAnTable(ord($data[$i])) == -1) { + return false; + } + } + return true; + } + + /** + * estimateBitsModeAn + * @param int $size + * @return int number of bits + */ + protected function estimateBitsModeAn($size) { + $w = (int)($size / 2); + $bits = $w * 11; + if ($size & 1) { + $bits += 6; + } + return $bits; + } + + /** + * estimateBitsMode8 + * @param int $size + * @return int number of bits + */ + protected function estimateBitsMode8($size) { + return $size * 8; + } + + /** + * estimateBitsModeKanji + * @param int $size + * @return int number of bits + */ + protected function estimateBitsModeKanji($size) { + return (int)(($size / 2) * 13); + } + + /** + * checkModeKanji + * @param int $size + * @param array $data + * @return boolean true or false + */ + protected function checkModeKanji($size, $data) { + if ($size & 1) { + return false; + } + for ($i=0; $i<$size; $i+=2) { + $val = (ord($data[$i]) << 8) | ord($data[$i+1]); + if (($val < 0x8140) OR (($val > 0x9ffc) AND ($val < 0xe040)) OR ($val > 0xebbf)) { + return false; + } + } + return true; + } + + /** + * Validate the input data. + * @param int $mode encoding mode. + * @param int $size size of data (byte). + * @param array data data to validate + * @return boolean true in case of valid data, false otherwise + */ + protected function check($mode, $size, $data) { + if ($size <= 0) { + return false; + } + switch($mode) { + case QR_MODE_NM: { + return $this->checkModeNum($size, $data); + } + case QR_MODE_AN: { + return $this->checkModeAn($size, $data); + } + case QR_MODE_KJ: { + return $this->checkModeKanji($size, $data); + } + case QR_MODE_8B: { + return true; + } + case QR_MODE_ST: { + return true; + } + default: { + break; + } + } + return false; + } + + /** + * estimateBitStreamSize + * @param array $items + * @param int $version + * @return int bits + */ + protected function estimateBitStreamSize($items, $version) { + $bits = 0; + if ($version == 0) { + $version = 1; + } + foreach ($items as $item) { + switch($item['mode']) { + case QR_MODE_NM: { + $bits = $this->estimateBitsModeNum($item['size']); + break; + } + case QR_MODE_AN: { + $bits = $this->estimateBitsModeAn($item['size']); + break; + } + case QR_MODE_8B: { + $bits = $this->estimateBitsMode8($item['size']); + break; + } + case QR_MODE_KJ: { + $bits = $this->estimateBitsModeKanji($item['size']); + break; + } + case QR_MODE_ST: { + return STRUCTURE_HEADER_BITS; + } + default: { + return 0; + } + } + $l = $this->lengthIndicator($item['mode'], $version); + $m = 1 << $l; + $num = (int)(($item['size'] + $m - 1) / $m); + $bits += $num * (4 + $l); + } + return $bits; + } + + /** + * estimateVersion + * @param array $items + * @return int version + */ + protected function estimateVersion($items) { + $version = 0; + $prev = 0; + do { + $prev = $version; + $bits = $this->estimateBitStreamSize($items, $prev); + $version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); + if ($version < 0) { + return -1; + } + } while ($version > $prev); + return $version; + } + + /** + * lengthOfCode + * @param int $mode + * @param int $version + * @param int $bits + * @return int size + */ + protected function lengthOfCode($mode, $version, $bits) { + $payload = $bits - 4 - $this->lengthIndicator($mode, $version); + switch($mode) { + case QR_MODE_NM: { + $chunks = (int)($payload / 10); + $remain = $payload - $chunks * 10; + $size = $chunks * 3; + if ($remain >= 7) { + $size += 2; + } elseif ($remain >= 4) { + $size += 1; + } + break; + } + case QR_MODE_AN: { + $chunks = (int)($payload / 11); + $remain = $payload - $chunks * 11; + $size = $chunks * 2; + if ($remain >= 6) { + ++$size; + } + break; + } + case QR_MODE_8B: { + $size = (int)($payload / 8); + break; + } + case QR_MODE_KJ: { + $size = (int)(($payload / 13) * 2); + break; + } + case QR_MODE_ST: { + $size = (int)($payload / 8); + break; + } + default: { + $size = 0; + break; + } + } + $maxsize = $this->maximumWords($mode, $version); + if ($size < 0) { + $size = 0; + } + if ($size > $maxsize) { + $size = $maxsize; + } + return $size; + } + + /** + * createBitStream + * @param array $items + * @return array of items and total bits + */ + protected function createBitStream($items) { + $total = 0; + foreach ($items as $key => $item) { + $items[$key] = $this->encodeBitStream($item, $this->version); + $bits = count($items[$key]['bstream']); + $total += $bits; + } + return array($items, $total); + } + + /** + * convertData + * @param array $items + * @return array items + */ + protected function convertData($items) { + $ver = $this->estimateVersion($items); + if ($ver > $this->version) { + $this->version = $ver; + } + for (;;) { + $cbs = $this->createBitStream($items); + $items = $cbs[0]; + $bits = $cbs[1]; + if ($bits < 0) { + return -1; + } + $ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); + if ($ver < 0) { + return -1; + } elseif ($ver > $this->version) { + $this->version = $ver; + } else { + break; + } + } + return $items; + } + + /** + * Append Padding Bit to bitstream + * @param array $bstream + * @return array bitstream + */ + protected function appendPaddingBit($bstream) { + $bits = count($bstream); + $maxwords = $this->getDataLength($this->version, $this->level); + $maxbits = $maxwords * 8; + if ($maxbits == $bits) { + return 0; + } + if ($maxbits - $bits < 5) { + return $this->appendNum($bstream, $maxbits - $bits, 0); + } + $bits += 4; + $words = (int)(($bits + 7) / 8); + $padding = array(); + $padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0); + $padlen = $maxwords - $words; + if ($padlen > 0) { + $padbuf = array(); + for ($i=0; $i<$padlen; ++$i) { + $padbuf[$i] = ($i&1)?0x11:0xec; + } + $padding = $this->appendBytes($padding, $padlen, $padbuf); + } + return $this->appendBitstream($bstream, $padding); + } + + /** + * mergeBitStream + * @param array $bstream + * @return array bitstream + */ + protected function mergeBitStream($items) { + $items = $this->convertData($items); + $bstream = array(); + foreach ($items as $item) { + $bstream = $this->appendBitstream($bstream, $item['bstream']); + } + return $bstream; + } + + /** + * Returns a stream of bits. + * @param int $items + * @return array padded merged byte stream + */ + protected function getBitStream($items) { + $bstream = $this->mergeBitStream($items); + return $this->appendPaddingBit($bstream); + } + + /** + * Pack all bit streams padding bits into a byte array. + * @param int $items + * @return array padded merged byte stream + */ + protected function getByteStream($items) { + $bstream = $this->getBitStream($items); + return $this->bitstreamToByte($bstream); + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - + + // QRbitstream + + /** + * Return an array with zeros + * @param int $setLength array size + * @return array + */ + protected function allocate($setLength) { + return array_fill(0, $setLength, 0); + } + + /** + * Return new bitstream from number + * @param int $bits number of bits + * @param int $num number + * @return array bitstream + */ + protected function newFromNum($bits, $num) { + $bstream = $this->allocate($bits); + $mask = 1 << ($bits - 1); + for ($i=0; $i<$bits; ++$i) { + if ($num & $mask) { + $bstream[$i] = 1; + } else { + $bstream[$i] = 0; + } + $mask = $mask >> 1; + } + return $bstream; + } + + /** + * Return new bitstream from bytes + * @param int $size size + * @param array $data bytes + * @return array bitstream + */ + protected function newFromBytes($size, $data) { + $bstream = $this->allocate($size * 8); + $p=0; + for ($i=0; $i<$size; ++$i) { + $mask = 0x80; + for ($j=0; $j<8; ++$j) { + if ($data[$i] & $mask) { + $bstream[$p] = 1; + } else { + $bstream[$p] = 0; + } + $p++; + $mask = $mask >> 1; + } + } + return $bstream; + } + + /** + * Append one bitstream to another + * @param array $bitstream original bitstream + * @param array $append bitstream to append + * @return array bitstream + */ + protected function appendBitstream($bitstream, $append) { + if ((!is_array($append)) OR (count($append) == 0)) { + return $bitstream; + } + if (count($bitstream) == 0) { + return $append; + } + return array_values(array_merge($bitstream, $append)); + } + + /** + * Append one bitstream created from number to another + * @param array $bitstream original bitstream + * @param int $bits number of bits + * @param int $num number + * @return array bitstream + */ + protected function appendNum($bitstream, $bits, $num) { + if ($bits == 0) { + return 0; + } + $b = $this->newFromNum($bits, $num); + return $this->appendBitstream($bitstream, $b); + } + + /** + * Append one bitstream created from bytes to another + * @param array $bitstream original bitstream + * @param int $size size + * @param array $data bytes + * @return array bitstream + */ + protected function appendBytes($bitstream, $size, $data) { + if ($size == 0) { + return 0; + } + $b = $this->newFromBytes($size, $data); + return $this->appendBitstream($bitstream, $b); + } + + /** + * Convert bitstream to bytes + * @param array $bitstream original bitstream + * @return array of bytes + */ + protected function bitstreamToByte($bstream) { + $size = count($bstream); + if ($size == 0) { + return array(); + } + $data = array_fill(0, (int)(($size + 7) / 8), 0); + $bytes = (int)($size / 8); + $p = 0; + for ($i=0; $i<$bytes; $i++) { + $v = 0; + for ($j=0; $j<8; $j++) { + $v = $v << 1; + $v |= $bstream[$p]; + $p++; + } + $data[$i] = $v; + } + if ($size & 7) { + $v = 0; + for ($j=0; $j<($size & 7); $j++) { + $v = $v << 1; + $v |= $bstream[$p]; + $p++; + } + $data[$bytes] = $v; + } + return $data; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - + + // QRspec + + /** + * Replace a value on the array at the specified position + * @param array $srctab + * @param int $x X position + * @param int $y Y position + * @param string $repl value to replace + * @param int $replLen length of the repl string + * @return array srctab + */ + protected function qrstrset($srctab, $x, $y, $repl, $replLen=false) { + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); + return $srctab; + } + + /** + * Return maximum data code length (bytes) for the version. + * @param int $version version + * @param int $level error correction level + * @return int maximum size (bytes) + */ + protected function getDataLength($version, $level) { + return $this->capacity[$version][QRCAP_WORDS] - $this->capacity[$version][QRCAP_EC][$level]; + } + + /** + * Return maximum error correction code length (bytes) for the version. + * @param int $version version + * @param int $level error correction level + * @return int ECC size (bytes) + */ + protected function getECCLength($version, $level){ + return $this->capacity[$version][QRCAP_EC][$level]; + } + + /** + * Return the width of the symbol for the version. + * @param int $version version + * @return int width + */ + protected function getWidth($version) { + return $this->capacity[$version][QRCAP_WIDTH]; + } + + /** + * Return the numer of remainder bits. + * @param int $version version + * @return int number of remainder bits + */ + protected function getRemainder($version) { + return $this->capacity[$version][QRCAP_REMINDER]; + } + + /** + * Return a version number that satisfies the input code length. + * @param int $size input code length (byte) + * @param int $level error correction level + * @return int version number + */ + protected function getMinimumVersion($size, $level) { + for ($i=1; $i <= QRSPEC_VERSION_MAX; ++$i) { + $words = $this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level]; + if ($words >= $size) { + return $i; + } + } + return -1; + } + + /** + * Return the size of length indicator for the mode and version. + * @param int $mode encoding mode + * @param int $version version + * @return int the size of the appropriate length indicator (bits). + */ + protected function lengthIndicator($mode, $version) { + if ($mode == QR_MODE_ST) { + return 0; + } + if ($version <= 9) { + $l = 0; + } elseif ($version <= 26) { + $l = 1; + } else { + $l = 2; + } + return $this->lengthTableBits[$mode][$l]; + } + + /** + * Return the maximum length for the mode and version. + * @param int $mode encoding mode + * @param int $version version + * @return int the maximum length (bytes) + */ + protected function maximumWords($mode, $version) { + if ($mode == QR_MODE_ST) { + return 3; + } + if ($version <= 9) { + $l = 0; + } else if ($version <= 26) { + $l = 1; + } else { + $l = 2; + } + $bits = $this->lengthTableBits[$mode][$l]; + $words = (1 << $bits) - 1; + if ($mode == QR_MODE_KJ) { + $words *= 2; // the number of bytes is required + } + return $words; + } + + /** + * Return an array of ECC specification. + * @param int $version version + * @param int $level error correction level + * @param array $spec an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code} + * @return array spec + */ + protected function getEccSpec($version, $level, $spec) { + if (count($spec) < 5) { + $spec = array(0, 0, 0, 0, 0); + } + $b1 = $this->eccTable[$version][$level][0]; + $b2 = $this->eccTable[$version][$level][1]; + $data = $this->getDataLength($version, $level); + $ecc = $this->getECCLength($version, $level); + if ($b2 == 0) { + $spec[0] = $b1; + $spec[1] = (int)($data / $b1); + $spec[2] = (int)($ecc / $b1); + $spec[3] = 0; + $spec[4] = 0; + } else { + $spec[0] = $b1; + $spec[1] = (int)($data / ($b1 + $b2)); + $spec[2] = (int)($ecc / ($b1 + $b2)); + $spec[3] = $b2; + $spec[4] = $spec[1] + 1; + } + return $spec; + } + + /** + * Put an alignment marker. + * @param array $frame frame + * @param int $width width + * @param int $ox X center coordinate of the pattern + * @param int $oy Y center coordinate of the pattern + * @return array frame + */ + protected function putAlignmentMarker($frame, $ox, $oy) { + $finder = array( + "\xa1\xa1\xa1\xa1\xa1", + "\xa1\xa0\xa0\xa0\xa1", + "\xa1\xa0\xa1\xa0\xa1", + "\xa1\xa0\xa0\xa0\xa1", + "\xa1\xa1\xa1\xa1\xa1" + ); + $yStart = $oy - 2; + $xStart = $ox - 2; + for ($y=0; $y < 5; $y++) { + $frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]); + } + return $frame; + } + + /** + * Put an alignment pattern. + * @param int $version version + * @param array $fram frame + * @param int $width width + * @return array frame + */ + protected function putAlignmentPattern($version, $frame, $width) { + if ($version < 2) { + return $frame; + } + $d = $this->alignmentPattern[$version][1] - $this->alignmentPattern[$version][0]; + if ($d < 0) { + $w = 2; + } else { + $w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2); + } + if ($w * $w - 3 == 1) { + $x = $this->alignmentPattern[$version][0]; + $y = $this->alignmentPattern[$version][0]; + $frame = $this->putAlignmentMarker($frame, $x, $y); + return $frame; + } + $cx = $this->alignmentPattern[$version][0]; + $wo = $w - 1; + for ($x=1; $x < $wo; ++$x) { + $frame = $this->putAlignmentMarker($frame, 6, $cx); + $frame = $this->putAlignmentMarker($frame, $cx, 6); + $cx += $d; + } + $cy = $this->alignmentPattern[$version][0]; + for ($y=0; $y < $wo; ++$y) { + $cx = $this->alignmentPattern[$version][0]; + for ($x=0; $x < $wo; ++$x) { + $frame = $this->putAlignmentMarker($frame, $cx, $cy); + $cx += $d; + } + $cy += $d; + } + return $frame; + } + + /** + * Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. Use lower 18 bits. + * @param int $version version + * @return BCH encoded version information pattern + */ + protected function getVersionPattern($version) { + if (($version < 7) OR ($version > QRSPEC_VERSION_MAX)) { + return 0; + } + return $this->versionPattern[($version - 7)]; + } + + /** + * Return BCH encoded format information pattern. + * @param array $mask + * @param int $level error correction level + * @return BCH encoded format information pattern + */ + protected function getFormatInfo($mask, $level) { + if (($mask < 0) OR ($mask > 7)) { + return 0; + } + if (($level < 0) OR ($level > 3)) { + return 0; + } + return $this->formatInfo[$level][$mask]; + } + + /** + * Put a finder pattern. + * @param array $frame frame + * @param int $width width + * @param int $ox X center coordinate of the pattern + * @param int $oy Y center coordinate of the pattern + * @return array frame + */ + protected function putFinderPattern($frame, $ox, $oy) { + $finder = array( + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" + ); + for ($y=0; $y < 7; $y++) { + $frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]); + } + return $frame; + } + + /** + * Return a copy of initialized frame. + * @param int $version version + * @return Array of unsigned char. + */ + protected function createFrame($version) { + $width = $this->capacity[$version][QRCAP_WIDTH]; + $frameLine = str_repeat ("\0", $width); + $frame = array_fill(0, $width, $frameLine); + // Finder pattern + $frame = $this->putFinderPattern($frame, 0, 0); + $frame = $this->putFinderPattern($frame, $width - 7, 0); + $frame = $this->putFinderPattern($frame, 0, $width - 7); + // Separator + $yOffset = $width - 7; + for ($y=0; $y < 7; ++$y) { + $frame[$y][7] = "\xc0"; + $frame[$y][$width - 8] = "\xc0"; + $frame[$yOffset][7] = "\xc0"; + ++$yOffset; + } + $setPattern = str_repeat("\xc0", 8); + $frame = $this->qrstrset($frame, 0, 7, $setPattern); + $frame = $this->qrstrset($frame, $width-8, 7, $setPattern); + $frame = $this->qrstrset($frame, 0, $width - 8, $setPattern); + // Format info + $setPattern = str_repeat("\x84", 9); + $frame = $this->qrstrset($frame, 0, 8, $setPattern); + $frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8); + $yOffset = $width - 8; + for ($y=0; $y < 8; ++$y,++$yOffset) { + $frame[$y][8] = "\x84"; + $frame[$yOffset][8] = "\x84"; + } + // Timing pattern + $wo = $width - 15; + for ($i=1; $i < $wo; ++$i) { + $frame[6][7+$i] = chr(0x90 | ($i & 1)); + $frame[7+$i][6] = chr(0x90 | ($i & 1)); + } + // Alignment pattern + $frame = $this->putAlignmentPattern($version, $frame, $width); + // Version information + if ($version >= 7) { + $vinf = $this->getVersionPattern($version); + $v = $vinf; + for ($x=0; $x<6; ++$x) { + for ($y=0; $y<3; ++$y) { + $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); + $v = $v >> 1; + } + } + $v = $vinf; + for ($y=0; $y<6; ++$y) { + for ($x=0; $x<3; ++$x) { + $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); + $v = $v >> 1; + } + } + } + // and a little bit... + $frame[$width - 8][8] = "\x81"; + return $frame; + } + + /** + * Set new frame for the specified version. + * @param int $version version + * @return Array of unsigned char. + */ + protected function newFrame($version) { + if (($version < 1) OR ($version > QRSPEC_VERSION_MAX)) { + return NULL; + } + if (!isset($this->frames[$version])) { + $this->frames[$version] = $this->createFrame($version); + } + if (is_null($this->frames[$version])) { + return NULL; + } + return $this->frames[$version]; + } + + /** + * Return block number 0 + * @param array $spec + * @return int value + */ + protected function rsBlockNum($spec) { + return ($spec[0] + $spec[3]); + } + + /** + * Return block number 1 + * @param array $spec + * @return int value + */ + protected function rsBlockNum1($spec) { + return $spec[0]; + } + + /** + * Return data codes 1 + * @param array $spec + * @return int value + */ + protected function rsDataCodes1($spec) { + return $spec[1]; + } + + /** + * Return ecc codes 1 + * @param array $spec + * @return int value + */ + protected function rsEccCodes1($spec) { + return $spec[2]; + } + + /** + * Return block number 2 + * @param array $spec + * @return int value + */ + protected function rsBlockNum2($spec) { + return $spec[3]; + } + + /** + * Return data codes 2 + * @param array $spec + * @return int value + */ + protected function rsDataCodes2($spec) { + return $spec[4]; + } + + /** + * Return ecc codes 2 + * @param array $spec + * @return int value + */ + protected function rsEccCodes2($spec) { + return $spec[2]; + } + + /** + * Return data length + * @param array $spec + * @return int value + */ + protected function rsDataLength($spec) { + return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); + } + + /** + * Return ecc length + * @param array $spec + * @return int value + */ + protected function rsEccLength($spec) { + return ($spec[0] + $spec[3]) * $spec[2]; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - + + // QRrs + + /** + * Initialize a Reed-Solomon codec and add it to existing rsitems + * @param int $symsize symbol size, bits + * @param int $gfpoly Field generator polynomial coefficients + * @param int $fcr first root of RS code generator polynomial, index form + * @param int $prim primitive element to generate polynomial roots + * @param int $nroots RS code generator polynomial degree (number of roots) + * @param int $pad padding bytes at front of shortened block + * @return array Array of RS values:
  • mm = Bits per symbol;
  • nn = Symbols per block;
  • alpha_to = log lookup table array;
  • index_of = Antilog lookup table array;
  • genpoly = Generator polynomial array;
  • nroots = Number of generator;
  • roots = number of parity symbols;
  • fcr = First consecutive root, index form;
  • prim = Primitive element, index form;
  • iprim = prim-th root of 1, index form;
  • pad = Padding bytes in shortened block;
  • gfpoly
. + */ + protected function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) { + foreach ($this->rsitems as $rs) { + if (($rs['pad'] != $pad) OR ($rs['nroots'] != $nroots) OR ($rs['mm'] != $symsize) + OR ($rs['gfpoly'] != $gfpoly) OR ($rs['fcr'] != $fcr) OR ($rs['prim'] != $prim)) { + continue; + } + return $rs; + } + $rs = $this->init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad); + array_unshift($this->rsitems, $rs); + return $rs; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - + + // QRrsItem + + /** + * modnn + * @param array RS values + * @param int $x X position + * @return int X osition + */ + protected function modnn($rs, $x) { + while ($x >= $rs['nn']) { + $x -= $rs['nn']; + $x = ($x >> $rs['mm']) + ($x & $rs['nn']); + } + return $x; + } + + /** + * Initialize a Reed-Solomon codec and returns an array of values. + * @param int $symsize symbol size, bits + * @param int $gfpoly Field generator polynomial coefficients + * @param int $fcr first root of RS code generator polynomial, index form + * @param int $prim primitive element to generate polynomial roots + * @param int $nroots RS code generator polynomial degree (number of roots) + * @param int $pad padding bytes at front of shortened block + * @return array Array of RS values:
  • mm = Bits per symbol;
  • nn = Symbols per block;
  • alpha_to = log lookup table array;
  • index_of = Antilog lookup table array;
  • genpoly = Generator polynomial array;
  • nroots = Number of generator;
  • roots = number of parity symbols;
  • fcr = First consecutive root, index form;
  • prim = Primitive element, index form;
  • iprim = prim-th root of 1, index form;
  • pad = Padding bytes in shortened block;
  • gfpoly
. + */ + protected function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) { + // Based on Reed solomon encoder by Phil Karn, KA9Q (GNU-LGPLv2) + $rs = null; + // Check parameter ranges + if (($symsize < 0) OR ($symsize > 8)) { + return $rs; + } + if (($fcr < 0) OR ($fcr >= (1<<$symsize))) { + return $rs; + } + if (($prim <= 0) OR ($prim >= (1<<$symsize))) { + return $rs; + } + if (($nroots < 0) OR ($nroots >= (1<<$symsize))) { + return $rs; + } + if (($pad < 0) OR ($pad >= ((1<<$symsize) -1 - $nroots))) { + return $rs; + } + $rs = array(); + $rs['mm'] = $symsize; + $rs['nn'] = (1 << $symsize) - 1; + $rs['pad'] = $pad; + $rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0); + $rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0); + // PHP style macro replacement ;) + $NN =& $rs['nn']; + $A0 =& $NN; + // Generate Galois field lookup tables + $rs['index_of'][0] = $A0; // log(zero) = -inf + $rs['alpha_to'][$A0] = 0; // alpha**-inf = 0 + $sr = 1; + for ($i=0; $i<$rs['nn']; ++$i) { + $rs['index_of'][$sr] = $i; + $rs['alpha_to'][$i] = $sr; + $sr <<= 1; + if ($sr & (1 << $symsize)) { + $sr ^= $gfpoly; + } + $sr &= $rs['nn']; + } + if ($sr != 1) { + // field generator polynomial is not primitive! + return NULL; + } + // Form RS code generator polynomial from its roots + $rs['genpoly'] = array_fill(0, ($nroots + 1), 0); + $rs['fcr'] = $fcr; + $rs['prim'] = $prim; + $rs['nroots'] = $nroots; + $rs['gfpoly'] = $gfpoly; + // Find prim-th root of 1, used in decoding + for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) { + ; // intentional empty-body loop! + } + $rs['iprim'] = (int)($iprim / $prim); + $rs['genpoly'][0] = 1; + + + for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { + $rs['genpoly'][$i+1] = 1; + // Multiply rs->genpoly[] by @**(root + x) + for ($j = $i; $j > 0; --$j) { + if ($rs['genpoly'][$j] != 0) { + $rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)]; + } else { + $rs['genpoly'][$j] = $rs['genpoly'][$j-1]; + } + } + // rs->genpoly[0] can never be zero + $rs['genpoly'][0] = $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][0]] + $root)]; + } + // convert rs->genpoly[] to index form for quicker encoding + for ($i = 0; $i <= $nroots; ++$i) { + $rs['genpoly'][$i] = $rs['index_of'][$rs['genpoly'][$i]]; + } + return $rs; + } + + /** + * Encode a Reed-Solomon codec and returns the parity array + * @param array $rs RS values + * @param array $data data + * @param array $parity parity + * @return parity array + */ + protected function encode_rs_char($rs, $data, $parity) { + $MM =& $rs['mm']; // bits per symbol + $NN =& $rs['nn']; // the total number of symbols in a RS block + $ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form + $INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form + $GENPOLY =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form + $NROOTS =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block + $FCR =& $rs['fcr']; // first consecutive root, index form + $PRIM =& $rs['prim']; // primitive element, index form + $IPRIM =& $rs['iprim']; // prim-th root of 1, index form + $PAD =& $rs['pad']; // the number of pad symbols in a block + $A0 =& $NN; + $parity = array_fill(0, $NROOTS, 0); + for ($i=0; $i < ($NN - $NROOTS - $PAD); $i++) { + $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; + if ($feedback != $A0) { + // feedback term is non-zero + // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must + // always be for the polynomials constructed by init_rs() + $feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback); + for ($j=1; $j < $NROOTS; ++$j) { + $parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])]; + } + } + // Shift + array_shift($parity); + if ($feedback != $A0) { + array_push($parity, $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[0])]); + } else { + array_push($parity, 0); + } + } + return $parity; + } + + } // end QRcode class + +} // END OF "class_exists QRcode" +?> diff --git a/app/lib/phpqrcode/index.php b/app/lib/phpqrcode/index.php new file mode 100644 index 00000000..9e14b7ea --- /dev/null +++ b/app/lib/phpqrcode/index.php @@ -0,0 +1,94 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + echo "

PHP QR Code


"; + + //set it to writable location, a place for temp generated PNG files + $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR; + + //html PNG location prefix + $PNG_WEB_DIR = 'temp/'; + + include "qrlib.php"; + + //ofcourse we need rights to create temp dir + if (!file_exists($PNG_TEMP_DIR)) + mkdir($PNG_TEMP_DIR); + + + $filename = $PNG_TEMP_DIR.'test.png'; + + //processing form input + //remember to sanitize user input in real-life solution !!! + $errorCorrectionLevel = 'L'; + if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H'))) + $errorCorrectionLevel = $_REQUEST['level']; + + $matrixPointSize = 4; + if (isset($_REQUEST['size'])) + $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10); + + + if (isset($_REQUEST['data'])) { + + //it's very important! + if (trim($_REQUEST['data']) == '') + die('data cannot be empty! back'); + + // user data + $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png'; + QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2); + + } else { + + //default data + echo 'You can provide data in GET parameter: like that
'; + QRcode::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2); + + } + + //display generated file + echo '
'; + + //config form + echo '
+ Data:   + ECC:   + Size:   +

'; + + // benchmark + QRtools::timeBenchmark(); + + \ No newline at end of file diff --git a/app/lib/phpqrcode/phpqrcode.php b/app/lib/phpqrcode/phpqrcode.php new file mode 100644 index 00000000..80adb9df --- /dev/null +++ b/app/lib/phpqrcode/phpqrcode.php @@ -0,0 +1,3312 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + + +/* + * Version: 1.1.4 + * Build: 2010100721 + */ + + + +//---- qrconst.php ----------------------------- + + + + + +/* + * PHP QR Code encoder + * + * Common constants + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + // Encoding modes + + define('QR_MODE_NUL', -1); + define('QR_MODE_NUM', 0); + define('QR_MODE_AN', 1); + define('QR_MODE_8', 2); + define('QR_MODE_KANJI', 3); + define('QR_MODE_STRUCTURE', 4); + + // Levels of error correction. + + define('QR_ECLEVEL_L', 0); + define('QR_ECLEVEL_M', 1); + define('QR_ECLEVEL_Q', 2); + define('QR_ECLEVEL_H', 3); + + // Supported output formats + + define('QR_FORMAT_TEXT', 0); + define('QR_FORMAT_PNG', 1); + + class qrstr { + public static function set(&$srctab, $x, $y, $repl, $replLen = false) { + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); + } + } + + + +//---- merged_config.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Config file, tuned-up for merged verion + */ + + define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there + define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true + define('QR_LOG_DIR', false); // default error logs dir + + define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code + define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false + + define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images + + + + +//---- qrtools.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Toolset, handy and debug utilites. + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRtools { + + //---------------------------------------------------------------------- + public static function binarize($frame) + { + $len = count($frame); + foreach ($frame as &$frameLine) { + + for($i=0; $i<$len; $i++) { + $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; + } + } + + return $frame; + } + + //---------------------------------------------------------------------- + public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037') + { + $barcode_array = array(); + + if (!is_array($mode)) + $mode = explode(',', $mode); + + $eccLevel = 'L'; + + if (count($mode) > 1) { + $eccLevel = $mode[1]; + } + + $qrTab = QRcode::text($code, false, $eccLevel); + $size = count($qrTab); + + $barcode_array['num_rows'] = $size; + $barcode_array['num_cols'] = $size; + $barcode_array['bcode'] = array(); + + foreach ($qrTab as $line) { + $arrAdd = array(); + foreach(str_split($line) as $char) + $arrAdd[] = ($char=='1')?1:0; + $barcode_array['bcode'][] = $arrAdd; + } + + return $barcode_array; + } + + //---------------------------------------------------------------------- + public static function clearCache() + { + self::$frames = array(); + } + + //---------------------------------------------------------------------- + public static function buildCache() + { + QRtools::markTime('before_build_cache'); + + $mask = new QRmask(); + for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { + $frame = QRspec::newFrame($a); + if (QR_IMAGE) { + $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; + QRimage::png(self::binarize($frame), $fileName, 1, 0); + } + + $width = count($frame); + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); + for ($maskNo=0; $maskNo<8; $maskNo++) + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); + } + + QRtools::markTime('after_build_cache'); + } + + //---------------------------------------------------------------------- + public static function log($outfile, $err) + { + if (QR_LOG_DIR !== false) { + if ($err != '') { + if ($outfile !== false) { + file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); + } else { + file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); + } + } + } + } + + //---------------------------------------------------------------------- + public static function dumpMask($frame) + { + $width = count($frame); + for($y=0;$y<$width;$y++) { + for($x=0;$x<$width;$x++) { + echo ord($frame[$y][$x]).','; + } + } + } + + //---------------------------------------------------------------------- + public static function markTime($markerId) + { + list($usec, $sec) = explode(" ", microtime()); + $time = ((float)$usec + (float)$sec); + + if (!isset($GLOBALS['qr_time_bench'])) + $GLOBALS['qr_time_bench'] = array(); + + $GLOBALS['qr_time_bench'][$markerId] = $time; + } + + //---------------------------------------------------------------------- + public static function timeBenchmark() + { + self::markTime('finish'); + + $lastTime = 0; + $startTime = 0; + $p = 0; + + echo ' + + '; + + foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { + if ($p > 0) { + echo ''; + } else { + $startTime = $thisTime; + } + + $p++; + $lastTime = $thisTime; + } + + echo ' + + +
BENCHMARK
till '.$markerId.': '.number_format($thisTime-$lastTime, 6).'s
TOTAL: '.number_format($lastTime-$startTime, 6).'s
'; + } + + } + + //########################################################################## + + QRtools::markTime('start'); + + + + +//---- qrspec.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * QR Code specifications + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * The following data / specifications are taken from + * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) + * or + * "Automatic identification and data capture techniques -- + * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('QRSPEC_VERSION_MAX', 40); + define('QRSPEC_WIDTH_MAX', 177); + + define('QRCAP_WIDTH', 0); + define('QRCAP_WORDS', 1); + define('QRCAP_REMINDER', 2); + define('QRCAP_EC', 3); + + class QRspec { + + public static $capacity = array( + array( 0, 0, 0, array( 0, 0, 0, 0)), + array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 + array( 25, 44, 7, array( 10, 16, 22, 28)), + array( 29, 70, 7, array( 15, 26, 36, 44)), + array( 33, 100, 7, array( 20, 36, 52, 64)), + array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 + array( 41, 172, 7, array( 36, 64, 96, 112)), + array( 45, 196, 0, array( 40, 72, 108, 130)), + array( 49, 242, 0, array( 48, 88, 132, 156)), + array( 53, 292, 0, array( 60, 110, 160, 192)), + array( 57, 346, 0, array( 72, 130, 192, 224)), //10 + array( 61, 404, 0, array( 80, 150, 224, 264)), + array( 65, 466, 0, array( 96, 176, 260, 308)), + array( 69, 532, 0, array( 104, 198, 288, 352)), + array( 73, 581, 3, array( 120, 216, 320, 384)), + array( 77, 655, 3, array( 132, 240, 360, 432)), //15 + array( 81, 733, 3, array( 144, 280, 408, 480)), + array( 85, 815, 3, array( 168, 308, 448, 532)), + array( 89, 901, 3, array( 180, 338, 504, 588)), + array( 93, 991, 3, array( 196, 364, 546, 650)), + array( 97, 1085, 3, array( 224, 416, 600, 700)), //20 + array(101, 1156, 4, array( 224, 442, 644, 750)), + array(105, 1258, 4, array( 252, 476, 690, 816)), + array(109, 1364, 4, array( 270, 504, 750, 900)), + array(113, 1474, 4, array( 300, 560, 810, 960)), + array(117, 1588, 4, array( 312, 588, 870, 1050)), //25 + array(121, 1706, 4, array( 336, 644, 952, 1110)), + array(125, 1828, 4, array( 360, 700, 1020, 1200)), + array(129, 1921, 3, array( 390, 728, 1050, 1260)), + array(133, 2051, 3, array( 420, 784, 1140, 1350)), + array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30 + array(141, 2323, 3, array( 480, 868, 1290, 1530)), + array(145, 2465, 3, array( 510, 924, 1350, 1620)), + array(149, 2611, 3, array( 540, 980, 1440, 1710)), + array(153, 2761, 3, array( 570, 1036, 1530, 1800)), + array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35 + array(161, 3034, 0, array( 600, 1120, 1680, 1980)), + array(165, 3196, 0, array( 630, 1204, 1770, 2100)), + array(169, 3362, 0, array( 660, 1260, 1860, 2220)), + array(173, 3532, 0, array( 720, 1316, 1950, 2310)), + array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40 + ); + + //---------------------------------------------------------------------- + public static function getDataLength($version, $level) + { + return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level]; + } + + //---------------------------------------------------------------------- + public static function getECCLength($version, $level) + { + return self::$capacity[$version][QRCAP_EC][$level]; + } + + //---------------------------------------------------------------------- + public static function getWidth($version) + { + return self::$capacity[$version][QRCAP_WIDTH]; + } + + //---------------------------------------------------------------------- + public static function getRemainder($version) + { + return self::$capacity[$version][QRCAP_REMINDER]; + } + + //---------------------------------------------------------------------- + public static function getMinimumVersion($size, $level) + { + + for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) { + $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; + if($words >= $size) + return $i; + } + + return -1; + } + + //###################################################################### + + public static $lengthTableBits = array( + array(10, 12, 14), + array( 9, 11, 13), + array( 8, 16, 16), + array( 8, 10, 12) + ); + + //---------------------------------------------------------------------- + public static function lengthIndicator($mode, $version) + { + if ($mode == QR_MODE_STRUCTURE) + return 0; + + if ($version <= 9) { + $l = 0; + } else if ($version <= 26) { + $l = 1; + } else { + $l = 2; + } + + return self::$lengthTableBits[$mode][$l]; + } + + //---------------------------------------------------------------------- + public static function maximumWords($mode, $version) + { + if($mode == QR_MODE_STRUCTURE) + return 3; + + if($version <= 9) { + $l = 0; + } else if($version <= 26) { + $l = 1; + } else { + $l = 2; + } + + $bits = self::$lengthTableBits[$mode][$l]; + $words = (1 << $bits) - 1; + + if($mode == QR_MODE_KANJI) { + $words *= 2; // the number of bytes is required + } + + return $words; + } + + // Error correction code ----------------------------------------------- + // Table of the error correction code (Reed-Solomon block) + // See Table 12-16 (pp.30-36), JIS X0510:2004. + + public static $eccTable = array( + array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), + array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), + array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), + array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 + array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), + array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), + array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), + array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), + array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10 + array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), + array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), + array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), + array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), + array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15 + array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), + array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), + array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), + array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), + array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20 + array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), + array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), + array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), + array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), + array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25 + array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), + array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), + array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), + array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), + array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30 + array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), + array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), + array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), + array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), + array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35 + array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), + array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), + array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), + array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), + array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40 + ); + + //---------------------------------------------------------------------- + // CACHEABLE!!! + + public static function getEccSpec($version, $level, array &$spec) + { + if (count($spec) < 5) { + $spec = array(0,0,0,0,0); + } + + $b1 = self::$eccTable[$version][$level][0]; + $b2 = self::$eccTable[$version][$level][1]; + $data = self::getDataLength($version, $level); + $ecc = self::getECCLength($version, $level); + + if($b2 == 0) { + $spec[0] = $b1; + $spec[1] = (int)($data / $b1); + $spec[2] = (int)($ecc / $b1); + $spec[3] = 0; + $spec[4] = 0; + } else { + $spec[0] = $b1; + $spec[1] = (int)($data / ($b1 + $b2)); + $spec[2] = (int)($ecc / ($b1 + $b2)); + $spec[3] = $b2; + $spec[4] = $spec[1] + 1; + } + } + + // Alignment pattern --------------------------------------------------- + + // Positions of alignment patterns. + // This array includes only the second and the third position of the + // alignment patterns. Rest of them can be calculated from the distance + // between them. + + // See Table 1 in Appendix E (pp.71) of JIS X0510:2004. + + public static $alignmentPattern = array( + array( 0, 0), + array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 + array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 + array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15 + array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20 + array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25 + array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30 + array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35 + array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40 + ); + + + /** -------------------------------------------------------------------- + * Put an alignment marker. + * @param frame + * @param width + * @param ox,oy center coordinate of the pattern + */ + public static function putAlignmentMarker(array &$frame, $ox, $oy) + { + $finder = array( + "\xa1\xa1\xa1\xa1\xa1", + "\xa1\xa0\xa0\xa0\xa1", + "\xa1\xa0\xa1\xa0\xa1", + "\xa1\xa0\xa0\xa0\xa1", + "\xa1\xa1\xa1\xa1\xa1" + ); + + $yStart = $oy-2; + $xStart = $ox-2; + + for($y=0; $y<5; $y++) { + QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); + } + } + + //---------------------------------------------------------------------- + public static function putAlignmentPattern($version, &$frame, $width) + { + if($version < 2) + return; + + $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; + if($d < 0) { + $w = 2; + } else { + $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2); + } + + if($w * $w - 3 == 1) { + $x = self::$alignmentPattern[$version][0]; + $y = self::$alignmentPattern[$version][0]; + self::putAlignmentMarker($frame, $x, $y); + return; + } + + $cx = self::$alignmentPattern[$version][0]; + for($x=1; $x<$w - 1; $x++) { + self::putAlignmentMarker($frame, 6, $cx); + self::putAlignmentMarker($frame, $cx, 6); + $cx += $d; + } + + $cy = self::$alignmentPattern[$version][0]; + for($y=0; $y<$w-1; $y++) { + $cx = self::$alignmentPattern[$version][0]; + for($x=0; $x<$w-1; $x++) { + self::putAlignmentMarker($frame, $cx, $cy); + $cx += $d; + } + $cy += $d; + } + } + + // Version information pattern ----------------------------------------- + + // Version information pattern (BCH coded). + // See Table 1 in Appendix D (pp.68) of JIS X0510:2004. + + // size: [QRSPEC_VERSION_MAX - 6] + + public static $versionPattern = array( + 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, + 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, + 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, + 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, + 0x27541, 0x28c69 + ); + + //---------------------------------------------------------------------- + public static function getVersionPattern($version) + { + if($version < 7 || $version > QRSPEC_VERSION_MAX) + return 0; + + return self::$versionPattern[$version -7]; + } + + // Format information -------------------------------------------------- + // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib) + + public static $formatInfo = array( + array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), + array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), + array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), + array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b) + ); + + public static function getFormatInfo($mask, $level) + { + if($mask < 0 || $mask > 7) + return 0; + + if($level < 0 || $level > 3) + return 0; + + return self::$formatInfo[$level][$mask]; + } + + // Frame --------------------------------------------------------------- + // Cache of initial frames. + + public static $frames = array(); + + /** -------------------------------------------------------------------- + * Put a finder pattern. + * @param frame + * @param width + * @param ox,oy upper-left coordinate of the pattern + */ + public static function putFinderPattern(&$frame, $ox, $oy) + { + $finder = array( + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" + ); + + for($y=0; $y<7; $y++) { + QRstr::set($frame, $ox, $oy+$y, $finder[$y]); + } + } + + //---------------------------------------------------------------------- + public static function createFrame($version) + { + $width = self::$capacity[$version][QRCAP_WIDTH]; + $frameLine = str_repeat ("\0", $width); + $frame = array_fill(0, $width, $frameLine); + + // Finder pattern + self::putFinderPattern($frame, 0, 0); + self::putFinderPattern($frame, $width - 7, 0); + self::putFinderPattern($frame, 0, $width - 7); + + // Separator + $yOffset = $width - 7; + + for($y=0; $y<7; $y++) { + $frame[$y][7] = "\xc0"; + $frame[$y][$width - 8] = "\xc0"; + $frame[$yOffset][7] = "\xc0"; + $yOffset++; + } + + $setPattern = str_repeat("\xc0", 8); + + QRstr::set($frame, 0, 7, $setPattern); + QRstr::set($frame, $width-8, 7, $setPattern); + QRstr::set($frame, 0, $width - 8, $setPattern); + + // Format info + $setPattern = str_repeat("\x84", 9); + QRstr::set($frame, 0, 8, $setPattern); + QRstr::set($frame, $width - 8, 8, $setPattern, 8); + + $yOffset = $width - 8; + + for($y=0; $y<8; $y++,$yOffset++) { + $frame[$y][8] = "\x84"; + $frame[$yOffset][8] = "\x84"; + } + + // Timing pattern + + for($i=1; $i<$width-15; $i++) { + $frame[6][7+$i] = chr(0x90 | ($i & 1)); + $frame[7+$i][6] = chr(0x90 | ($i & 1)); + } + + // Alignment pattern + self::putAlignmentPattern($version, $frame, $width); + + // Version information + if($version >= 7) { + $vinf = self::getVersionPattern($version); + + $v = $vinf; + + for($x=0; $x<6; $x++) { + for($y=0; $y<3; $y++) { + $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); + $v = $v >> 1; + } + } + + $v = $vinf; + for($y=0; $y<6; $y++) { + for($x=0; $x<3; $x++) { + $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); + $v = $v >> 1; + } + } + } + + // and a little bit... + $frame[$width - 8][8] = "\x81"; + + return $frame; + } + + //---------------------------------------------------------------------- + public static function debug($frame, $binary_mode = false) + { + if ($binary_mode) { + + foreach ($frame as &$frameLine) { + $frameLine = join('  ', explode('0', $frameLine)); + $frameLine = join('██', explode('1', $frameLine)); + } + + ?> + +


        '; + echo join("
        ", $frame); + echo '






'; + + } else { + + foreach ($frame as &$frameLine) { + $frameLine = join(' ', explode("\xc0", $frameLine)); + $frameLine = join('', explode("\xc1", $frameLine)); + $frameLine = join(' ', explode("\xa0", $frameLine)); + $frameLine = join('', explode("\xa1", $frameLine)); + $frameLine = join('', explode("\x84", $frameLine)); //format 0 + $frameLine = join('', explode("\x85", $frameLine)); //format 1 + $frameLine = join('', explode("\x81", $frameLine)); //special bit + $frameLine = join(' ', explode("\x90", $frameLine)); //clock 0 + $frameLine = join('', explode("\x91", $frameLine)); //clock 1 + $frameLine = join(' ', explode("\x88", $frameLine)); //version + $frameLine = join('', explode("\x89", $frameLine)); //version + $frameLine = join('♦', explode("\x01", $frameLine)); + $frameLine = join('⋅', explode("\0", $frameLine)); + } + + ?> + + "; + echo join("
", $frame); + echo "
"; + + } + } + + //---------------------------------------------------------------------- + public static function serial($frame) + { + return gzcompress(join("\n", $frame), 9); + } + + //---------------------------------------------------------------------- + public static function unserial($code) + { + return explode("\n", gzuncompress($code)); + } + + //---------------------------------------------------------------------- + public static function newFrame($version) + { + if($version < 1 || $version > QRSPEC_VERSION_MAX) + return null; + + if(!isset(self::$frames[$version])) { + + $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat'; + + if (QR_CACHEABLE) { + if (file_exists($fileName)) { + self::$frames[$version] = self::unserial(file_get_contents($fileName)); + } else { + self::$frames[$version] = self::createFrame($version); + file_put_contents($fileName, self::serial(self::$frames[$version])); + } + } else { + self::$frames[$version] = self::createFrame($version); + } + } + + if(is_null(self::$frames[$version])) + return null; + + return self::$frames[$version]; + } + + //---------------------------------------------------------------------- + public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; } + public static function rsBlockNum1($spec) { return $spec[0]; } + public static function rsDataCodes1($spec) { return $spec[1]; } + public static function rsEccCodes1($spec) { return $spec[2]; } + public static function rsBlockNum2($spec) { return $spec[3]; } + public static function rsDataCodes2($spec) { return $spec[4]; } + public static function rsEccCodes2($spec) { return $spec[2]; } + public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); } + public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; } + + } + + + +//---- qrimage.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Image output of code using GD2 + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('QR_IMAGE', true); + + class QRimage { + + //---------------------------------------------------------------------- + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) + { + $image = self::image($frame, $pixelPerPoint, $outerFrame); + + if ($filename === false) { + Header("Content-type: image/png"); + ImagePng($image); + } else { + if($saveandprint===TRUE){ + ImagePng($image, $filename); + header("Content-type: image/png"); + ImagePng($image); + }else{ + ImagePng($image, $filename); + } + } + + ImageDestroy($image); + } + + //---------------------------------------------------------------------- + public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) + { + $image = self::image($frame, $pixelPerPoint, $outerFrame); + + if ($filename === false) { + Header("Content-type: image/jpeg"); + ImageJpeg($image, null, $q); + } else { + ImageJpeg($image, $filename, $q); + } + + ImageDestroy($image); + } + + //---------------------------------------------------------------------- + private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) + { + $h = count($frame); + $w = strlen($frame[0]); + + $imgW = $w + 2*$outerFrame; + $imgH = $h + 2*$outerFrame; + + $base_image =ImageCreate($imgW, $imgH); + + $col[0] = ImageColorAllocate($base_image,255,255,255); + $col[1] = ImageColorAllocate($base_image,0,0,0); + + imagefill($base_image, 0, 0, $col[0]); + + for($y=0; $y<$h; $y++) { + for($x=0; $x<$w; $x++) { + if ($frame[$y][$x] == '1') { + ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); + } + } + } + + $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); + ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); + ImageDestroy($base_image); + + return $target_image; + } + } + + + +//---- qrinput.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Input encoding class + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('STRUCTURE_HEADER_BITS', 20); + define('MAX_STRUCTURED_SYMBOLS', 16); + + class QRinputItem { + + public $mode; + public $size; + public $data; + public $bstream; + + public function __construct($mode, $size, $data, $bstream = null) + { + $setData = array_slice($data, 0, $size); + + if (count($setData) < $size) { + $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); + } + + if(!QRinput::check($mode, $size, $setData)) { + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData)); + return null; + } + + $this->mode = $mode; + $this->size = $size; + $this->data = $setData; + $this->bstream = $bstream; + } + + //---------------------------------------------------------------------- + public function encodeModeNum($version) + { + try { + + $words = (int)($this->size / 3); + $bs = new QRbitstream(); + + $val = 0x1; + $bs->appendNum(4, $val); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); + + for($i=0; $i<$words; $i++) { + $val = (ord($this->data[$i*3 ]) - ord('0')) * 100; + $val += (ord($this->data[$i*3+1]) - ord('0')) * 10; + $val += (ord($this->data[$i*3+2]) - ord('0')); + $bs->appendNum(10, $val); + } + + if($this->size - $words * 3 == 1) { + $val = ord($this->data[$words*3]) - ord('0'); + $bs->appendNum(4, $val); + } else if($this->size - $words * 3 == 2) { + $val = (ord($this->data[$words*3 ]) - ord('0')) * 10; + $val += (ord($this->data[$words*3+1]) - ord('0')); + $bs->appendNum(7, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeAn($version) + { + try { + $words = (int)($this->size / 2); + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x02); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); + + for($i=0; $i<$words; $i++) { + $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; + $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); + + $bs->appendNum(11, $val); + } + + if($this->size & 1) { + $val = QRinput::lookAnTable(ord($this->data[$words * 2])); + $bs->appendNum(6, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeMode8($version) + { + try { + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x4); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); + + for($i=0; $i<$this->size; $i++) { + $bs->appendNum(8, ord($this->data[$i])); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeKanji($version) + { + try { + + $bs = new QRbitrtream(); + + $bs->appendNum(4, 0x8); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); + + for($i=0; $i<$this->size; $i+=2) { + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); + if($val <= 0x9ffc) { + $val -= 0x8140; + } else { + $val -= 0xc140; + } + + $h = ($val >> 8) * 0xc0; + $val = ($val & 0xff) + $h; + + $bs->appendNum(13, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeStructure() + { + try { + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x03); + $bs->appendNum(4, ord($this->data[1]) - 1); + $bs->appendNum(4, ord($this->data[0]) - 1); + $bs->appendNum(8, ord($this->data[2])); + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function estimateBitStreamSizeOfEntry($version) + { + $bits = 0; + + if($version == 0) + $version = 1; + + switch($this->mode) { + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; + case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; + default: + return 0; + } + + $l = QRspec::lengthIndicator($this->mode, $version); + $m = 1 << $l; + $num = (int)(($this->size + $m - 1) / $m); + + $bits += $num * (4 + $l); + + return $bits; + } + + //---------------------------------------------------------------------- + public function encodeBitStream($version) + { + try { + + unset($this->bstream); + $words = QRspec::maximumWords($this->mode, $version); + + if($this->size > $words) { + + $st1 = new QRinputItem($this->mode, $words, $this->data); + $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); + + $st1->encodeBitStream($version); + $st2->encodeBitStream($version); + + $this->bstream = new QRbitstream(); + $this->bstream->append($st1->bstream); + $this->bstream->append($st2->bstream); + + unset($st1); + unset($st2); + + } else { + + $ret = 0; + + switch($this->mode) { + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; + case QR_MODE_8: $ret = $this->encodeMode8($version); break; + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; + + default: + break; + } + + if($ret < 0) + return -1; + } + + return $this->bstream->size(); + + } catch (Exception $e) { + return -1; + } + } + }; + + //########################################################################## + + class QRinput { + + public $items; + + private $version; + private $level; + + //---------------------------------------------------------------------- + public function __construct($version = 0, $level = QR_ECLEVEL_L) + { + if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) { + throw new Exception('Invalid version no'); + return NULL; + } + + $this->version = $version; + $this->level = $level; + } + + //---------------------------------------------------------------------- + public function getVersion() + { + return $this->version; + } + + //---------------------------------------------------------------------- + public function setVersion($version) + { + if($version < 0 || $version > QRSPEC_VERSION_MAX) { + throw new Exception('Invalid version no'); + return -1; + } + + $this->version = $version; + + return 0; + } + + //---------------------------------------------------------------------- + public function getErrorCorrectionLevel() + { + return $this->level; + } + + //---------------------------------------------------------------------- + public function setErrorCorrectionLevel($level) + { + if($level > QR_ECLEVEL_H) { + throw new Exception('Invalid ECLEVEL'); + return -1; + } + + $this->level = $level; + + return 0; + } + + //---------------------------------------------------------------------- + public function appendEntry(QRinputItem $entry) + { + $this->items[] = $entry; + } + + //---------------------------------------------------------------------- + public function append($mode, $size, $data) + { + try { + $entry = new QRinputItem($mode, $size, $data); + $this->items[] = $entry; + return 0; + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + + public function insertStructuredAppendHeader($size, $index, $parity) + { + if( $size > MAX_STRUCTURED_SYMBOLS ) { + throw new Exception('insertStructuredAppendHeader wrong size'); + } + + if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) { + throw new Exception('insertStructuredAppendHeader wrong index'); + } + + $buf = array($size, $index, $parity); + + try { + $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf); + array_unshift($this->items, $entry); + return 0; + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function calcParity() + { + $parity = 0; + + foreach($this->items as $item) { + if($item->mode != QR_MODE_STRUCTURE) { + for($i=$item->size-1; $i>=0; $i--) { + $parity ^= $item->data[$i]; + } + } + } + + return $parity; + } + + //---------------------------------------------------------------------- + public static function checkModeNum($size, $data) + { + for($i=0; $i<$size; $i++) { + if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){ + return false; + } + } + + return true; + } + + //---------------------------------------------------------------------- + public static function estimateBitsModeNum($size) + { + $w = (int)$size / 3; + $bits = $w * 10; + + switch($size - $w * 3) { + case 1: + $bits += 4; + break; + case 2: + $bits += 7; + break; + default: + break; + } + + return $bits; + } + + //---------------------------------------------------------------------- + public static $anTable = array( + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + ); + + //---------------------------------------------------------------------- + public static function lookAnTable($c) + { + return (($c > 127)?-1:self::$anTable[$c]); + } + + //---------------------------------------------------------------------- + public static function checkModeAn($size, $data) + { + for($i=0; $i<$size; $i++) { + if (self::lookAnTable(ord($data[$i])) == -1) { + return false; + } + } + + return true; + } + + //---------------------------------------------------------------------- + public static function estimateBitsModeAn($size) + { + $w = (int)($size / 2); + $bits = $w * 11; + + if($size & 1) { + $bits += 6; + } + + return $bits; + } + + //---------------------------------------------------------------------- + public static function estimateBitsMode8($size) + { + return $size * 8; + } + + //---------------------------------------------------------------------- + public function estimateBitsModeKanji($size) + { + return (int)(($size / 2) * 13); + } + + //---------------------------------------------------------------------- + public static function checkModeKanji($size, $data) + { + if($size & 1) + return false; + + for($i=0; $i<$size; $i+=2) { + $val = (ord($data[$i]) << 8) | ord($data[$i+1]); + if( $val < 0x8140 + || ($val > 0x9ffc && $val < 0xe040) + || $val > 0xebbf) { + return false; + } + } + + return true; + } + + /*********************************************************************** + * Validation + **********************************************************************/ + + public static function check($mode, $size, $data) + { + if($size <= 0) + return false; + + switch($mode) { + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; + case QR_MODE_AN: return self::checkModeAn($size, $data); break; + case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; + case QR_MODE_8: return true; break; + case QR_MODE_STRUCTURE: return true; break; + + default: + break; + } + + return false; + } + + + //---------------------------------------------------------------------- + public function estimateBitStreamSize($version) + { + $bits = 0; + + foreach($this->items as $item) { + $bits += $item->estimateBitStreamSizeOfEntry($version); + } + + return $bits; + } + + //---------------------------------------------------------------------- + public function estimateVersion() + { + $version = 0; + $prev = 0; + do { + $prev = $version; + $bits = $this->estimateBitStreamSize($prev); + $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); + if ($version < 0) { + return -1; + } + } while ($version > $prev); + + return $version; + } + + //---------------------------------------------------------------------- + public static function lengthOfCode($mode, $version, $bits) + { + $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); + switch($mode) { + case QR_MODE_NUM: + $chunks = (int)($payload / 10); + $remain = $payload - $chunks * 10; + $size = $chunks * 3; + if($remain >= 7) { + $size += 2; + } else if($remain >= 4) { + $size += 1; + } + break; + case QR_MODE_AN: + $chunks = (int)($payload / 11); + $remain = $payload - $chunks * 11; + $size = $chunks * 2; + if($remain >= 6) + $size++; + break; + case QR_MODE_8: + $size = (int)($payload / 8); + break; + case QR_MODE_KANJI: + $size = (int)(($payload / 13) * 2); + break; + case QR_MODE_STRUCTURE: + $size = (int)($payload / 8); + break; + default: + $size = 0; + break; + } + + $maxsize = QRspec::maximumWords($mode, $version); + if($size < 0) $size = 0; + if($size > $maxsize) $size = $maxsize; + + return $size; + } + + //---------------------------------------------------------------------- + public function createBitStream() + { + $total = 0; + + foreach($this->items as $item) { + $bits = $item->encodeBitStream($this->version); + + if($bits < 0) + return -1; + + $total += $bits; + } + + return $total; + } + + //---------------------------------------------------------------------- + public function convertData() + { + $ver = $this->estimateVersion(); + if($ver > $this->getVersion()) { + $this->setVersion($ver); + } + + for(;;) { + $bits = $this->createBitStream(); + + if($bits < 0) + return -1; + + $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); + if($ver < 0) { + throw new Exception('WRONG VERSION'); + return -1; + } else if($ver > $this->getVersion()) { + $this->setVersion($ver); + } else { + break; + } + } + + return 0; + } + + //---------------------------------------------------------------------- + public function appendPaddingBit(&$bstream) + { + $bits = $bstream->size(); + $maxwords = QRspec::getDataLength($this->version, $this->level); + $maxbits = $maxwords * 8; + + if ($maxbits == $bits) { + return 0; + } + + if ($maxbits - $bits < 5) { + return $bstream->appendNum($maxbits - $bits, 0); + } + + $bits += 4; + $words = (int)(($bits + 7) / 8); + + $padding = new QRbitstream(); + $ret = $padding->appendNum($words * 8 - $bits + 4, 0); + + if($ret < 0) + return $ret; + + $padlen = $maxwords - $words; + + if($padlen > 0) { + + $padbuf = array(); + for($i=0; $i<$padlen; $i++) { + $padbuf[$i] = ($i&1)?0x11:0xec; + } + + $ret = $padding->appendBytes($padlen, $padbuf); + + if($ret < 0) + return $ret; + + } + + $ret = $bstream->append($padding); + + return $ret; + } + + //---------------------------------------------------------------------- + public function mergeBitStream() + { + if($this->convertData() < 0) { + return null; + } + + $bstream = new QRbitstream(); + + foreach($this->items as $item) { + $ret = $bstream->append($item->bstream); + if($ret < 0) { + return null; + } + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function getBitStream() + { + + $bstream = $this->mergeBitStream(); + + if($bstream == null) { + return null; + } + + $ret = $this->appendPaddingBit($bstream); + if($ret < 0) { + return null; + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function getByteStream() + { + $bstream = $this->getBitStream(); + if($bstream == null) { + return null; + } + + return $bstream->toByte(); + } + } + + + + + + +//---- qrbitstream.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Bitstream class + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRbitstream { + + public $data = array(); + + //---------------------------------------------------------------------- + public function size() + { + return count($this->data); + } + + //---------------------------------------------------------------------- + public function allocate($setLength) + { + $this->data = array_fill(0, $setLength, 0); + return 0; + } + + //---------------------------------------------------------------------- + public static function newFromNum($bits, $num) + { + $bstream = new QRbitstream(); + $bstream->allocate($bits); + + $mask = 1 << ($bits - 1); + for($i=0; $i<$bits; $i++) { + if($num & $mask) { + $bstream->data[$i] = 1; + } else { + $bstream->data[$i] = 0; + } + $mask = $mask >> 1; + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public static function newFromBytes($size, $data) + { + $bstream = new QRbitstream(); + $bstream->allocate($size * 8); + $p=0; + + for($i=0; $i<$size; $i++) { + $mask = 0x80; + for($j=0; $j<8; $j++) { + if($data[$i] & $mask) { + $bstream->data[$p] = 1; + } else { + $bstream->data[$p] = 0; + } + $p++; + $mask = $mask >> 1; + } + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function append(QRbitstream $arg) + { + if (is_null($arg)) { + return -1; + } + + if($arg->size() == 0) { + return 0; + } + + if($this->size() == 0) { + $this->data = $arg->data; + return 0; + } + + $this->data = array_values(array_merge($this->data, $arg->data)); + + return 0; + } + + //---------------------------------------------------------------------- + public function appendNum($bits, $num) + { + if ($bits == 0) + return 0; + + $b = QRbitstream::newFromNum($bits, $num); + + if(is_null($b)) + return -1; + + $ret = $this->append($b); + unset($b); + + return $ret; + } + + //---------------------------------------------------------------------- + public function appendBytes($size, $data) + { + if ($size == 0) + return 0; + + $b = QRbitstream::newFromBytes($size, $data); + + if(is_null($b)) + return -1; + + $ret = $this->append($b); + unset($b); + + return $ret; + } + + //---------------------------------------------------------------------- + public function toByte() + { + + $size = $this->size(); + + if($size == 0) { + return array(); + } + + $data = array_fill(0, (int)(($size + 7) / 8), 0); + $bytes = (int)($size / 8); + + $p = 0; + + for($i=0; $i<$bytes; $i++) { + $v = 0; + for($j=0; $j<8; $j++) { + $v = $v << 1; + $v |= $this->data[$p]; + $p++; + } + $data[$i] = $v; + } + + if($size & 7) { + $v = 0; + for($j=0; $j<($size & 7); $j++) { + $v = $v << 1; + $v |= $this->data[$p]; + $p++; + } + $data[$bytes] = $v; + } + + return $data; + } + + } + + + + +//---- qrsplit.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Input splitting classes + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * The following data / specifications are taken from + * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) + * or + * "Automatic identification and data capture techniques -- + * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + class QRsplit { + + public $dataStr = ''; + public $input; + public $modeHint; + + //---------------------------------------------------------------------- + public function __construct($dataStr, $input, $modeHint) + { + $this->dataStr = $dataStr; + $this->input = $input; + $this->modeHint = $modeHint; + } + + //---------------------------------------------------------------------- + public static function isdigitat($str, $pos) + { + if ($pos >= strlen($str)) + return false; + + return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); + } + + //---------------------------------------------------------------------- + public static function isalnumat($str, $pos) + { + if ($pos >= strlen($str)) + return false; + + return (QRinput::lookAnTable(ord($str[$pos])) >= 0); + } + + //---------------------------------------------------------------------- + public function identifyMode($pos) + { + if ($pos >= strlen($this->dataStr)) + return QR_MODE_NUL; + + $c = $this->dataStr[$pos]; + + if(self::isdigitat($this->dataStr, $pos)) { + return QR_MODE_NUM; + } else if(self::isalnumat($this->dataStr, $pos)) { + return QR_MODE_AN; + } else if($this->modeHint == QR_MODE_KANJI) { + + if ($pos+1 < strlen($this->dataStr)) + { + $d = $this->dataStr[$pos+1]; + $word = (ord($c) << 8) | ord($d); + if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { + return QR_MODE_KANJI; + } + } + } + + return QR_MODE_8; + } + + //---------------------------------------------------------------------- + public function eatNum() + { + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 0; + while(self::isdigitat($this->dataStr, $p)) { + $p++; + } + + $run = $p; + $mode = $this->identifyMode($p); + + if($mode == QR_MODE_8) { + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln + + QRinput::estimateBitsMode8(1) // + 4 + l8 + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 + if($dif > 0) { + return $this->eat8(); + } + } + if($mode == QR_MODE_AN) { + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln + + QRinput::estimateBitsModeAn(1) // + 4 + la + - QRinput::estimateBitsModeAn($run + 1);// - 4 - la + if($dif > 0) { + return $this->eatAn(); + } + } + + $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eatAn() + { + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 0; + + while(self::isalnumat($this->dataStr, $p)) { + if(self::isdigitat($this->dataStr, $p)) { + $q = $p; + while(self::isdigitat($this->dataStr, $q)) { + $q++; + } + + $dif = QRinput::estimateBitsModeAn($p) // + 4 + la + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln + - QRinput::estimateBitsModeAn($q); // - 4 - la + + if($dif < 0) { + break; + } else { + $p = $q; + } + } else { + $p++; + } + } + + $run = $p; + + if(!self::isalnumat($this->dataStr, $p)) { + $dif = QRinput::estimateBitsModeAn($run) + 4 + $la + + QRinput::estimateBitsMode8(1) // + 4 + l8 + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 + if($dif > 0) { + return $this->eat8(); + } + } + + $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eatKanji() + { + $p = 0; + + while($this->identifyMode($p) == QR_MODE_KANJI) { + $p += 2; + } + + $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eat8() + { + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 1; + $dataStrLen = strlen($this->dataStr); + + while($p < $dataStrLen) { + + $mode = $this->identifyMode($p); + if($mode == QR_MODE_KANJI) { + break; + } + if($mode == QR_MODE_NUM) { + $q = $p; + while(self::isdigitat($this->dataStr, $q)) { + $q++; + } + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln + - QRinput::estimateBitsMode8($q); // - 4 - l8 + if($dif < 0) { + break; + } else { + $p = $q; + } + } else if($mode == QR_MODE_AN) { + $q = $p; + while(self::isalnumat($this->dataStr, $q)) { + $q++; + } + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 + + QRinput::estimateBitsModeAn($q - $p) + 4 + $la + - QRinput::estimateBitsMode8($q); // - 4 - l8 + if($dif < 0) { + break; + } else { + $p = $q; + } + } else { + $p++; + } + } + + $run = $p; + $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); + + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function splitString() + { + while (strlen($this->dataStr) > 0) + { + if($this->dataStr == '') + return 0; + + $mode = $this->identifyMode(0); + + switch ($mode) { + case QR_MODE_NUM: $length = $this->eatNum(); break; + case QR_MODE_AN: $length = $this->eatAn(); break; + case QR_MODE_KANJI: + if ($hint == QR_MODE_KANJI) + $length = $this->eatKanji(); + else $length = $this->eat8(); + break; + default: $length = $this->eat8(); break; + + } + + if($length == 0) return 0; + if($length < 0) return -1; + + $this->dataStr = substr($this->dataStr, $length); + } + } + + //---------------------------------------------------------------------- + public function toUpper() + { + $stringLen = strlen($this->dataStr); + $p = 0; + + while ($p<$stringLen) { + $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint); + if($mode == QR_MODE_KANJI) { + $p += 2; + } else { + if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) { + $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); + } + $p++; + } + } + + return $this->dataStr; + } + + //---------------------------------------------------------------------- + public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) + { + if(is_null($string) || $string == '\0' || $string == '') { + throw new Exception('empty string!!!'); + } + + $split = new QRsplit($string, $input, $modeHint); + + if(!$casesensitive) + $split->toUpper(); + + return $split->splitString(); + } + } + + + +//---- qrrscode.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Reed-Solomon error correction support + * + * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q + * (libfec is released under the GNU Lesser General Public License.) + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRrsItem { + + public $mm; // Bits per symbol + public $nn; // Symbols per block (= (1<= $this->nn) { + $x -= $this->nn; + $x = ($x >> $this->mm) + ($x & $this->nn); + } + + return $x; + } + + //---------------------------------------------------------------------- + public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) + { + // Common code for intializing a Reed-Solomon control block (char or int symbols) + // Copyright 2004 Phil Karn, KA9Q + // May be used under the terms of the GNU Lesser General Public License (LGPL) + + $rs = null; + + // Check parameter ranges + if($symsize < 0 || $symsize > 8) return $rs; + if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; + if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; + if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! + if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding + + $rs = new QRrsItem(); + $rs->mm = $symsize; + $rs->nn = (1<<$symsize)-1; + $rs->pad = $pad; + + $rs->alpha_to = array_fill(0, $rs->nn+1, 0); + $rs->index_of = array_fill(0, $rs->nn+1, 0); + + // PHP style macro replacement ;) + $NN =& $rs->nn; + $A0 =& $NN; + + // Generate Galois field lookup tables + $rs->index_of[0] = $A0; // log(zero) = -inf + $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 + $sr = 1; + + for($i=0; $i<$rs->nn; $i++) { + $rs->index_of[$sr] = $i; + $rs->alpha_to[$i] = $sr; + $sr <<= 1; + if($sr & (1<<$symsize)) { + $sr ^= $gfpoly; + } + $sr &= $rs->nn; + } + + if($sr != 1){ + // field generator polynomial is not primitive! + $rs = NULL; + return $rs; + } + + /* Form RS code generator polynomial from its roots */ + $rs->genpoly = array_fill(0, $nroots+1, 0); + + $rs->fcr = $fcr; + $rs->prim = $prim; + $rs->nroots = $nroots; + $rs->gfpoly = $gfpoly; + + /* Find prim-th root of 1, used in decoding */ + for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) + ; // intentional empty-body loop! + + $rs->iprim = (int)($iprim / $prim); + $rs->genpoly[0] = 1; + + for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { + $rs->genpoly[$i+1] = 1; + + // Multiply rs->genpoly[] by @**(root + x) + for ($j = $i; $j > 0; $j--) { + if ($rs->genpoly[$j] != 0) { + $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; + } else { + $rs->genpoly[$j] = $rs->genpoly[$j-1]; + } + } + // rs->genpoly[0] can never be zero + $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)]; + } + + // convert rs->genpoly[] to index form for quicker encoding + for ($i = 0; $i <= $nroots; $i++) + $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; + + return $rs; + } + + //---------------------------------------------------------------------- + public function encode_rs_char($data, &$parity) + { + $MM =& $this->mm; + $NN =& $this->nn; + $ALPHA_TO =& $this->alpha_to; + $INDEX_OF =& $this->index_of; + $GENPOLY =& $this->genpoly; + $NROOTS =& $this->nroots; + $FCR =& $this->fcr; + $PRIM =& $this->prim; + $IPRIM =& $this->iprim; + $PAD =& $this->pad; + $A0 =& $NN; + + $parity = array_fill(0, $NROOTS, 0); + + for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) { + + $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; + if($feedback != $A0) { + // feedback term is non-zero + + // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must + // always be for the polynomials constructed by init_rs() + $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); + + for($j=1;$j<$NROOTS;$j++) { + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; + } + } + + // Shift + array_shift($parity); + if($feedback != $A0) { + array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); + } else { + array_push($parity, 0); + } + } + } + } + + //########################################################################## + + class QRrs { + + public static $items = array(); + + //---------------------------------------------------------------------- + public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) + { + foreach(self::$items as $rs) { + if($rs->pad != $pad) continue; + if($rs->nroots != $nroots) continue; + if($rs->mm != $symsize) continue; + if($rs->gfpoly != $gfpoly) continue; + if($rs->fcr != $fcr) continue; + if($rs->prim != $prim) continue; + + return $rs; + } + + $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad); + array_unshift(self::$items, $rs); + + return $rs; + } + } + + + +//---- qrmask.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Masking + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('N1', 3); + define('N2', 3); + define('N3', 40); + define('N4', 10); + + class QRmask { + + public $runLength = array(); + + //---------------------------------------------------------------------- + public function __construct() + { + $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); + } + + //---------------------------------------------------------------------- + public function writeFormatInformation($width, &$frame, $mask, $level) + { + $blacks = 0; + $format = QRspec::getFormatInfo($mask, $level); + + for($i=0; $i<8; $i++) { + if($format & 1) { + $blacks += 2; + $v = 0x85; + } else { + $v = 0x84; + } + + $frame[8][$width - 1 - $i] = chr($v); + if($i < 6) { + $frame[$i][8] = chr($v); + } else { + $frame[$i + 1][8] = chr($v); + } + $format = $format >> 1; + } + + for($i=0; $i<7; $i++) { + if($format & 1) { + $blacks += 2; + $v = 0x85; + } else { + $v = 0x84; + } + + $frame[$width - 7 + $i][8] = chr($v); + if($i == 0) { + $frame[8][7] = chr($v); + } else { + $frame[8][6 - $i] = chr($v); + } + + $format = $format >> 1; + } + + return $blacks; + } + + //---------------------------------------------------------------------- + public function mask0($x, $y) { return ($x+$y)&1; } + public function mask1($x, $y) { return ($y&1); } + public function mask2($x, $y) { return ($x%3); } + public function mask3($x, $y) { return ($x+$y)%3; } + public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; } + public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; } + public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; } + public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; } + + //---------------------------------------------------------------------- + private function generateMaskNo($maskNo, $width, $frame) + { + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); + + for($y=0; $y<$width; $y++) { + for($x=0; $x<$width; $x++) { + if(ord($frame[$y][$x]) & 0x80) { + $bitMask[$y][$x] = 0; + } else { + $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); + $bitMask[$y][$x] = ($maskFunc == 0)?1:0; + } + + } + } + + return $bitMask; + } + + //---------------------------------------------------------------------- + public static function serial($bitFrame) + { + $codeArr = array(); + + foreach ($bitFrame as $line) + $codeArr[] = join('', $line); + + return gzcompress(join("\n", $codeArr), 9); + } + + //---------------------------------------------------------------------- + public static function unserial($code) + { + $codeArr = array(); + + $codeLines = explode("\n", gzuncompress($code)); + foreach ($codeLines as $line) + $codeArr[] = str_split($line); + + return $codeArr; + } + + //---------------------------------------------------------------------- + public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) + { + $b = 0; + $bitMask = array(); + + $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat'; + + if (QR_CACHEABLE) { + if (file_exists($fileName)) { + $bitMask = self::unserial(file_get_contents($fileName)); + } else { + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); + if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) + mkdir(QR_CACHE_DIR.'mask_'.$maskNo); + file_put_contents($fileName, self::serial($bitMask)); + } + } else { + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); + } + + if ($maskGenOnly) + return; + + $d = $s; + + for($y=0; $y<$width; $y++) { + for($x=0; $x<$width; $x++) { + if($bitMask[$y][$x] == 1) { + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); + } + $b += (int)(ord($d[$y][$x]) & 1); + } + } + + return $b; + } + + //---------------------------------------------------------------------- + public function makeMask($width, $frame, $maskNo, $level) + { + $masked = array_fill(0, $width, str_repeat("\0", $width)); + $this->makeMaskNo($maskNo, $width, $frame, $masked); + $this->writeFormatInformation($width, $masked, $maskNo, $level); + + return $masked; + } + + //---------------------------------------------------------------------- + public function calcN1N3($length) + { + $demerit = 0; + + for($i=0; $i<$length; $i++) { + + if($this->runLength[$i] >= 5) { + $demerit += (N1 + ($this->runLength[$i] - 5)); + } + if($i & 1) { + if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) { + $fact = (int)($this->runLength[$i] / 3); + if(($this->runLength[$i-2] == $fact) && + ($this->runLength[$i-1] == $fact) && + ($this->runLength[$i+1] == $fact) && + ($this->runLength[$i+2] == $fact)) { + if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) { + $demerit += N3; + } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) { + $demerit += N3; + } + } + } + } + } + return $demerit; + } + + //---------------------------------------------------------------------- + public function evaluateSymbol($width, $frame) + { + $head = 0; + $demerit = 0; + + for($y=0; $y<$width; $y++) { + $head = 0; + $this->runLength[0] = 1; + + $frameY = $frame[$y]; + + if ($y>0) + $frameYM = $frame[$y-1]; + + for($x=0; $x<$width; $x++) { + if(($x > 0) && ($y > 0)) { + $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); + $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); + + if(($b22 | ($w22 ^ 1))&1) { + $demerit += N2; + } + } + if(($x == 0) && (ord($frameY[$x]) & 1)) { + $this->runLength[0] = -1; + $head = 1; + $this->runLength[$head] = 1; + } else if($x > 0) { + if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { + $head++; + $this->runLength[$head] = 1; + } else { + $this->runLength[$head]++; + } + } + } + + $demerit += $this->calcN1N3($head+1); + } + + for($x=0; $x<$width; $x++) { + $head = 0; + $this->runLength[0] = 1; + + for($y=0; $y<$width; $y++) { + if($y == 0 && (ord($frame[$y][$x]) & 1)) { + $this->runLength[0] = -1; + $head = 1; + $this->runLength[$head] = 1; + } else if($y > 0) { + if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { + $head++; + $this->runLength[$head] = 1; + } else { + $this->runLength[$head]++; + } + } + } + + $demerit += $this->calcN1N3($head+1); + } + + return $demerit; + } + + + //---------------------------------------------------------------------- + public function mask($width, $frame, $level) + { + $minDemerit = PHP_INT_MAX; + $bestMaskNum = 0; + $bestMask = array(); + + $checked_masks = array(0,1,2,3,4,5,6,7); + + if (QR_FIND_FROM_RANDOM !== false) { + + $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); + for ($i = 0; $i < $howManuOut; $i++) { + $remPos = rand (0, count($checked_masks)-1); + unset($checked_masks[$remPos]); + $checked_masks = array_values($checked_masks); + } + + } + + $bestMask = $frame; + + foreach($checked_masks as $i) { + $mask = array_fill(0, $width, str_repeat("\0", $width)); + + $demerit = 0; + $blacks = 0; + $blacks = $this->makeMaskNo($i, $width, $frame, $mask); + $blacks += $this->writeFormatInformation($width, $mask, $i, $level); + $blacks = (int)(100 * $blacks / ($width * $width)); + $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); + $demerit += $this->evaluateSymbol($width, $mask); + + if($demerit < $minDemerit) { + $minDemerit = $demerit; + $bestMask = $mask; + $bestMaskNum = $i; + } + } + + return $bestMask; + } + + //---------------------------------------------------------------------- + } + + + + +//---- qrencode.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Main encoder classes. + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRrsblock { + public $dataLength; + public $data = array(); + public $eccLength; + public $ecc = array(); + + public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs) + { + $rs->encode_rs_char($data, $ecc); + + $this->dataLength = $dl; + $this->data = $data; + $this->eccLength = $el; + $this->ecc = $ecc; + } + }; + + //########################################################################## + + class QRrawcode { + public $version; + public $datacode = array(); + public $ecccode = array(); + public $blocks; + public $rsblocks = array(); //of RSblock + public $count; + public $dataLength; + public $eccLength; + public $b1; + + //---------------------------------------------------------------------- + public function __construct(QRinput $input) + { + $spec = array(0,0,0,0,0); + + $this->datacode = $input->getByteStream(); + if(is_null($this->datacode)) { + throw new Exception('null imput string'); + } + + QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec); + + $this->version = $input->getVersion(); + $this->b1 = QRspec::rsBlockNum1($spec); + $this->dataLength = QRspec::rsDataLength($spec); + $this->eccLength = QRspec::rsEccLength($spec); + $this->ecccode = array_fill(0, $this->eccLength, 0); + $this->blocks = QRspec::rsBlockNum($spec); + + $ret = $this->init($spec); + if($ret < 0) { + throw new Exception('block alloc error'); + return null; + } + + $this->count = 0; + } + + //---------------------------------------------------------------------- + public function init(array $spec) + { + $dl = QRspec::rsDataCodes1($spec); + $el = QRspec::rsEccCodes1($spec); + $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); + + + $blockNo = 0; + $dataPos = 0; + $eccPos = 0; + for($i=0; $iecccode,$eccPos); + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); + + $dataPos += $dl; + $eccPos += $el; + $blockNo++; + } + + if(QRspec::rsBlockNum2($spec) == 0) + return 0; + + $dl = QRspec::rsDataCodes2($spec); + $el = QRspec::rsEccCodes2($spec); + $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); + + if($rs == NULL) return -1; + + for($i=0; $iecccode,$eccPos); + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); + + $dataPos += $dl; + $eccPos += $el; + $blockNo++; + } + + return 0; + } + + //---------------------------------------------------------------------- + public function getCode() + { + $ret; + + if($this->count < $this->dataLength) { + $row = $this->count % $this->blocks; + $col = $this->count / $this->blocks; + if($col >= $this->rsblocks[0]->dataLength) { + $row += $this->b1; + } + $ret = $this->rsblocks[$row]->data[$col]; + } else if($this->count < $this->dataLength + $this->eccLength) { + $row = ($this->count - $this->dataLength) % $this->blocks; + $col = ($this->count - $this->dataLength) / $this->blocks; + $ret = $this->rsblocks[$row]->ecc[$col]; + } else { + return 0; + } + $this->count++; + + return $ret; + } + } + + //########################################################################## + + class QRcode { + + public $version; + public $width; + public $data; + + //---------------------------------------------------------------------- + public function encodeMask(QRinput $input, $mask) + { + if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { + throw new Exception('wrong version'); + } + if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { + throw new Exception('wrong level'); + } + + $raw = new QRrawcode($input); + + QRtools::markTime('after_raw'); + + $version = $raw->version; + $width = QRspec::getWidth($version); + $frame = QRspec::newFrame($version); + + $filler = new FrameFiller($width, $frame); + if(is_null($filler)) { + return NULL; + } + + // inteleaved data and ecc codes + for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { + $code = $raw->getCode(); + $bit = 0x80; + for($j=0; $j<8; $j++) { + $addr = $filler->next(); + $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); + $bit = $bit >> 1; + } + } + + QRtools::markTime('after_filler'); + + unset($raw); + + // remainder bits + $j = QRspec::getRemainder($version); + for($i=0; $i<$j; $i++) { + $addr = $filler->next(); + $filler->setFrameAt($addr, 0x02); + } + + $frame = $filler->frame; + unset($filler); + + + // masking + $maskObj = new QRmask(); + if($mask < 0) { + + if (QR_FIND_BEST_MASK) { + $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); + } else { + $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel()); + } + } else { + $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); + } + + if($masked == NULL) { + return NULL; + } + + QRtools::markTime('after_mask'); + + $this->version = $version; + $this->width = $width; + $this->data = $masked; + + return $this; + } + + //---------------------------------------------------------------------- + public function encodeInput(QRinput $input) + { + return $this->encodeMask($input, -1); + } + + //---------------------------------------------------------------------- + public function encodeString8bit($string, $version, $level) + { + if(string == NULL) { + throw new Exception('empty string!'); + return NULL; + } + + $input = new QRinput($version, $level); + if($input == NULL) return NULL; + + $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); + if($ret < 0) { + unset($input); + return NULL; + } + return $this->encodeInput($input); + } + + //---------------------------------------------------------------------- + public function encodeString($string, $version, $level, $hint, $casesensitive) + { + + if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { + throw new Exception('bad hint'); + return NULL; + } + + $input = new QRinput($version, $level); + if($input == NULL) return NULL; + + $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); + if($ret < 0) { + return NULL; + } + + return $this->encodeInput($input); + } + + //---------------------------------------------------------------------- + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encodePNG($text, $outfile, $saveandprint=false); + } + + //---------------------------------------------------------------------- + public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encode($text, $outfile); + } + + //---------------------------------------------------------------------- + public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encodeRAW($text, $outfile); + } + } + + //########################################################################## + + class FrameFiller { + + public $width; + public $frame; + public $x; + public $y; + public $dir; + public $bit; + + //---------------------------------------------------------------------- + public function __construct($width, &$frame) + { + $this->width = $width; + $this->frame = $frame; + $this->x = $width - 1; + $this->y = $width - 1; + $this->dir = -1; + $this->bit = -1; + } + + //---------------------------------------------------------------------- + public function setFrameAt($at, $val) + { + $this->frame[$at['y']][$at['x']] = chr($val); + } + + //---------------------------------------------------------------------- + public function getFrameAt($at) + { + return ord($this->frame[$at['y']][$at['x']]); + } + + //---------------------------------------------------------------------- + public function next() + { + do { + + if($this->bit == -1) { + $this->bit = 0; + return array('x'=>$this->x, 'y'=>$this->y); + } + + $x = $this->x; + $y = $this->y; + $w = $this->width; + + if($this->bit == 0) { + $x--; + $this->bit++; + } else { + $x++; + $y += $this->dir; + $this->bit--; + } + + if($this->dir < 0) { + if($y < 0) { + $y = 0; + $x -= 2; + $this->dir = 1; + if($x == 6) { + $x--; + $y = 9; + } + } + } else { + if($y == $w) { + $y = $w - 1; + $x -= 2; + $this->dir = -1; + if($x == 6) { + $x--; + $y -= 8; + } + } + } + if($x < 0 || $y < 0) return null; + + $this->x = $x; + $this->y = $y; + + } while(ord($this->frame[$y][$x]) & 0x80); + + return array('x'=>$x, 'y'=>$y); + } + + } ; + + //########################################################################## + + class QRencode { + + public $casesensitive = true; + public $eightbit = false; + + public $version = 0; + public $size = 3; + public $margin = 4; + + public $structured = 0; // not supported yet + + public $level = QR_ECLEVEL_L; + public $hint = QR_MODE_8; + + //---------------------------------------------------------------------- + public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = new QRencode(); + $enc->size = $size; + $enc->margin = $margin; + + switch ($level.'') { + case '0': + case '1': + case '2': + case '3': + $enc->level = $level; + break; + case 'l': + case 'L': + $enc->level = QR_ECLEVEL_L; + break; + case 'm': + case 'M': + $enc->level = QR_ECLEVEL_M; + break; + case 'q': + case 'Q': + $enc->level = QR_ECLEVEL_Q; + break; + case 'h': + case 'H': + $enc->level = QR_ECLEVEL_H; + break; + } + + return $enc; + } + + //---------------------------------------------------------------------- + public function encodeRAW($intext, $outfile = false) + { + $code = new QRcode(); + + if($this->eightbit) { + $code->encodeString8bit($intext, $this->version, $this->level); + } else { + $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); + } + + return $code->data; + } + + //---------------------------------------------------------------------- + public function encode($intext, $outfile = false) + { + $code = new QRcode(); + + if($this->eightbit) { + $code->encodeString8bit($intext, $this->version, $this->level); + } else { + $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); + } + + QRtools::markTime('after_encode'); + + if ($outfile!== false) { + file_put_contents($outfile, join("\n", QRtools::binarize($code->data))); + } else { + return QRtools::binarize($code->data); + } + } + + //---------------------------------------------------------------------- + public function encodePNG($intext, $outfile = false,$saveandprint=false) + { + try { + + ob_start(); + $tab = $this->encode($intext); + $err = ob_get_contents(); + ob_end_clean(); + + if ($err != '') + QRtools::log($outfile, $err); + + $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); + + QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint); + + } catch (Exception $e) { + + QRtools::log($outfile, $e->getMessage()); + + } + } + } + + diff --git a/app/lib/phpqrcode/qrbitstream.php b/app/lib/phpqrcode/qrbitstream.php new file mode 100644 index 00000000..7d4ec4a6 --- /dev/null +++ b/app/lib/phpqrcode/qrbitstream.php @@ -0,0 +1,180 @@ + + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRbitstream { + + public $data = array(); + + //---------------------------------------------------------------------- + public function size() + { + return count($this->data); + } + + //---------------------------------------------------------------------- + public function allocate($setLength) + { + $this->data = array_fill(0, $setLength, 0); + return 0; + } + + //---------------------------------------------------------------------- + public static function newFromNum($bits, $num) + { + $bstream = new QRbitstream(); + $bstream->allocate($bits); + + $mask = 1 << ($bits - 1); + for($i=0; $i<$bits; $i++) { + if($num & $mask) { + $bstream->data[$i] = 1; + } else { + $bstream->data[$i] = 0; + } + $mask = $mask >> 1; + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public static function newFromBytes($size, $data) + { + $bstream = new QRbitstream(); + $bstream->allocate($size * 8); + $p=0; + + for($i=0; $i<$size; $i++) { + $mask = 0x80; + for($j=0; $j<8; $j++) { + if($data[$i] & $mask) { + $bstream->data[$p] = 1; + } else { + $bstream->data[$p] = 0; + } + $p++; + $mask = $mask >> 1; + } + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function append(QRbitstream $arg) + { + if (is_null($arg)) { + return -1; + } + + if($arg->size() == 0) { + return 0; + } + + if($this->size() == 0) { + $this->data = $arg->data; + return 0; + } + + $this->data = array_values(array_merge($this->data, $arg->data)); + + return 0; + } + + //---------------------------------------------------------------------- + public function appendNum($bits, $num) + { + if ($bits == 0) + return 0; + + $b = QRbitstream::newFromNum($bits, $num); + + if(is_null($b)) + return -1; + + $ret = $this->append($b); + unset($b); + + return $ret; + } + + //---------------------------------------------------------------------- + public function appendBytes($size, $data) + { + if ($size == 0) + return 0; + + $b = QRbitstream::newFromBytes($size, $data); + + if(is_null($b)) + return -1; + + $ret = $this->append($b); + unset($b); + + return $ret; + } + + //---------------------------------------------------------------------- + public function toByte() + { + + $size = $this->size(); + + if($size == 0) { + return array(); + } + + $data = array_fill(0, (int)(($size + 7) / 8), 0); + $bytes = (int)($size / 8); + + $p = 0; + + for($i=0; $i<$bytes; $i++) { + $v = 0; + for($j=0; $j<8; $j++) { + $v = $v << 1; + $v |= $this->data[$p]; + $p++; + } + $data[$i] = $v; + } + + if($size & 7) { + $v = 0; + for($j=0; $j<($size & 7); $j++) { + $v = $v << 1; + $v |= $this->data[$p]; + $p++; + } + $data[$bytes] = $v; + } + + return $data; + } + + } diff --git a/app/lib/phpqrcode/qrconfig.php b/app/lib/phpqrcode/qrconfig.php new file mode 100644 index 00000000..e53dff8c --- /dev/null +++ b/app/lib/phpqrcode/qrconfig.php @@ -0,0 +1,17 @@ + + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + // Encoding modes + + define('QR_MODE_NUL', -1); + define('QR_MODE_NUM', 0); + define('QR_MODE_AN', 1); + define('QR_MODE_8', 2); + define('QR_MODE_KANJI', 3); + define('QR_MODE_STRUCTURE', 4); + + // Levels of error correction. + + define('QR_ECLEVEL_L', 0); + define('QR_ECLEVEL_M', 1); + define('QR_ECLEVEL_Q', 2); + define('QR_ECLEVEL_H', 3); + + // Supported output formats + + define('QR_FORMAT_TEXT', 0); + define('QR_FORMAT_PNG', 1); + + class qrstr { + public static function set(&$srctab, $x, $y, $repl, $replLen = false) { + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); + } + } \ No newline at end of file diff --git a/app/lib/phpqrcode/qrencode.php b/app/lib/phpqrcode/qrencode.php new file mode 100644 index 00000000..4b77a5bd --- /dev/null +++ b/app/lib/phpqrcode/qrencode.php @@ -0,0 +1,502 @@ + + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRrsblock { + public $dataLength; + public $data = array(); + public $eccLength; + public $ecc = array(); + + public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs) + { + $rs->encode_rs_char($data, $ecc); + + $this->dataLength = $dl; + $this->data = $data; + $this->eccLength = $el; + $this->ecc = $ecc; + } + }; + + //########################################################################## + + class QRrawcode { + public $version; + public $datacode = array(); + public $ecccode = array(); + public $blocks; + public $rsblocks = array(); //of RSblock + public $count; + public $dataLength; + public $eccLength; + public $b1; + + //---------------------------------------------------------------------- + public function __construct(QRinput $input) + { + $spec = array(0,0,0,0,0); + + $this->datacode = $input->getByteStream(); + if(is_null($this->datacode)) { + throw new Exception('null imput string'); + } + + QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec); + + $this->version = $input->getVersion(); + $this->b1 = QRspec::rsBlockNum1($spec); + $this->dataLength = QRspec::rsDataLength($spec); + $this->eccLength = QRspec::rsEccLength($spec); + $this->ecccode = array_fill(0, $this->eccLength, 0); + $this->blocks = QRspec::rsBlockNum($spec); + + $ret = $this->init($spec); + if($ret < 0) { + throw new Exception('block alloc error'); + return null; + } + + $this->count = 0; + } + + //---------------------------------------------------------------------- + public function init(array $spec) + { + $dl = QRspec::rsDataCodes1($spec); + $el = QRspec::rsEccCodes1($spec); + $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); + + + $blockNo = 0; + $dataPos = 0; + $eccPos = 0; + for($i=0; $iecccode,$eccPos); + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); + + $dataPos += $dl; + $eccPos += $el; + $blockNo++; + } + + if(QRspec::rsBlockNum2($spec) == 0) + return 0; + + $dl = QRspec::rsDataCodes2($spec); + $el = QRspec::rsEccCodes2($spec); + $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); + + if($rs == NULL) return -1; + + for($i=0; $iecccode,$eccPos); + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); + + $dataPos += $dl; + $eccPos += $el; + $blockNo++; + } + + return 0; + } + + //---------------------------------------------------------------------- + public function getCode() + { + $ret; + + if($this->count < $this->dataLength) { + $row = $this->count % $this->blocks; + $col = $this->count / $this->blocks; + if($col >= $this->rsblocks[0]->dataLength) { + $row += $this->b1; + } + $ret = $this->rsblocks[$row]->data[$col]; + } else if($this->count < $this->dataLength + $this->eccLength) { + $row = ($this->count - $this->dataLength) % $this->blocks; + $col = ($this->count - $this->dataLength) / $this->blocks; + $ret = $this->rsblocks[$row]->ecc[$col]; + } else { + return 0; + } + $this->count++; + + return $ret; + } + } + + //########################################################################## + + class QRcode { + + public $version; + public $width; + public $data; + + //---------------------------------------------------------------------- + public function encodeMask(QRinput $input, $mask) + { + if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { + throw new Exception('wrong version'); + } + if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { + throw new Exception('wrong level'); + } + + $raw = new QRrawcode($input); + + QRtools::markTime('after_raw'); + + $version = $raw->version; + $width = QRspec::getWidth($version); + $frame = QRspec::newFrame($version); + + $filler = new FrameFiller($width, $frame); + if(is_null($filler)) { + return NULL; + } + + // inteleaved data and ecc codes + for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { + $code = $raw->getCode(); + $bit = 0x80; + for($j=0; $j<8; $j++) { + $addr = $filler->next(); + $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); + $bit = $bit >> 1; + } + } + + QRtools::markTime('after_filler'); + + unset($raw); + + // remainder bits + $j = QRspec::getRemainder($version); + for($i=0; $i<$j; $i++) { + $addr = $filler->next(); + $filler->setFrameAt($addr, 0x02); + } + + $frame = $filler->frame; + unset($filler); + + + // masking + $maskObj = new QRmask(); + if($mask < 0) { + + if (QR_FIND_BEST_MASK) { + $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); + } else { + $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel()); + } + } else { + $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); + } + + if($masked == NULL) { + return NULL; + } + + QRtools::markTime('after_mask'); + + $this->version = $version; + $this->width = $width; + $this->data = $masked; + + return $this; + } + + //---------------------------------------------------------------------- + public function encodeInput(QRinput $input) + { + return $this->encodeMask($input, -1); + } + + //---------------------------------------------------------------------- + public function encodeString8bit($string, $version, $level) + { + if(string == NULL) { + throw new Exception('empty string!'); + return NULL; + } + + $input = new QRinput($version, $level); + if($input == NULL) return NULL; + + $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); + if($ret < 0) { + unset($input); + return NULL; + } + return $this->encodeInput($input); + } + + //---------------------------------------------------------------------- + public function encodeString($string, $version, $level, $hint, $casesensitive) + { + + if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { + throw new Exception('bad hint'); + return NULL; + } + + $input = new QRinput($version, $level); + if($input == NULL) return NULL; + + $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); + if($ret < 0) { + return NULL; + } + + return $this->encodeInput($input); + } + + //---------------------------------------------------------------------- + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encodePNG($text, $outfile, $saveandprint=false); + } + + //---------------------------------------------------------------------- + public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encode($text, $outfile); + } + + //---------------------------------------------------------------------- + public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encodeRAW($text, $outfile); + } + } + + //########################################################################## + + class FrameFiller { + + public $width; + public $frame; + public $x; + public $y; + public $dir; + public $bit; + + //---------------------------------------------------------------------- + public function __construct($width, &$frame) + { + $this->width = $width; + $this->frame = $frame; + $this->x = $width - 1; + $this->y = $width - 1; + $this->dir = -1; + $this->bit = -1; + } + + //---------------------------------------------------------------------- + public function setFrameAt($at, $val) + { + $this->frame[$at['y']][$at['x']] = chr($val); + } + + //---------------------------------------------------------------------- + public function getFrameAt($at) + { + return ord($this->frame[$at['y']][$at['x']]); + } + + //---------------------------------------------------------------------- + public function next() + { + do { + + if($this->bit == -1) { + $this->bit = 0; + return array('x'=>$this->x, 'y'=>$this->y); + } + + $x = $this->x; + $y = $this->y; + $w = $this->width; + + if($this->bit == 0) { + $x--; + $this->bit++; + } else { + $x++; + $y += $this->dir; + $this->bit--; + } + + if($this->dir < 0) { + if($y < 0) { + $y = 0; + $x -= 2; + $this->dir = 1; + if($x == 6) { + $x--; + $y = 9; + } + } + } else { + if($y == $w) { + $y = $w - 1; + $x -= 2; + $this->dir = -1; + if($x == 6) { + $x--; + $y -= 8; + } + } + } + if($x < 0 || $y < 0) return null; + + $this->x = $x; + $this->y = $y; + + } while(ord($this->frame[$y][$x]) & 0x80); + + return array('x'=>$x, 'y'=>$y); + } + + } ; + + //########################################################################## + + class QRencode { + + public $casesensitive = true; + public $eightbit = false; + + public $version = 0; + public $size = 3; + public $margin = 4; + + public $structured = 0; // not supported yet + + public $level = QR_ECLEVEL_L; + public $hint = QR_MODE_8; + + //---------------------------------------------------------------------- + public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = new QRencode(); + $enc->size = $size; + $enc->margin = $margin; + + switch ($level.'') { + case '0': + case '1': + case '2': + case '3': + $enc->level = $level; + break; + case 'l': + case 'L': + $enc->level = QR_ECLEVEL_L; + break; + case 'm': + case 'M': + $enc->level = QR_ECLEVEL_M; + break; + case 'q': + case 'Q': + $enc->level = QR_ECLEVEL_Q; + break; + case 'h': + case 'H': + $enc->level = QR_ECLEVEL_H; + break; + } + + return $enc; + } + + //---------------------------------------------------------------------- + public function encodeRAW($intext, $outfile = false) + { + $code = new QRcode(); + + if($this->eightbit) { + $code->encodeString8bit($intext, $this->version, $this->level); + } else { + $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); + } + + return $code->data; + } + + //---------------------------------------------------------------------- + public function encode($intext, $outfile = false) + { + $code = new QRcode(); + + if($this->eightbit) { + $code->encodeString8bit($intext, $this->version, $this->level); + } else { + $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); + } + + QRtools::markTime('after_encode'); + + if ($outfile!== false) { + file_put_contents($outfile, join("\n", QRtools::binarize($code->data))); + } else { + return QRtools::binarize($code->data); + } + } + + //---------------------------------------------------------------------- + public function encodePNG($intext, $outfile = false,$saveandprint=false) + { + try { + + ob_start(); + $tab = $this->encode($intext); + $err = ob_get_contents(); + ob_end_clean(); + + if ($err != '') + QRtools::log($outfile, $err); + + $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); + + QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint); + + } catch (Exception $e) { + + QRtools::log($outfile, $e->getMessage()); + + } + } + } diff --git a/app/lib/phpqrcode/qrimage.php b/app/lib/phpqrcode/qrimage.php new file mode 100644 index 00000000..10b0a6e1 --- /dev/null +++ b/app/lib/phpqrcode/qrimage.php @@ -0,0 +1,95 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('QR_IMAGE', true); + + class QRimage { + + //---------------------------------------------------------------------- + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) + { + $image = self::image($frame, $pixelPerPoint, $outerFrame); + + if ($filename === false) { + Header("Content-type: image/png"); + ImagePng($image); + } else { + if($saveandprint===TRUE){ + ImagePng($image, $filename); + header("Content-type: image/png"); + ImagePng($image); + }else{ + ImagePng($image, $filename); + } + } + + ImageDestroy($image); + } + + //---------------------------------------------------------------------- + public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) + { + $image = self::image($frame, $pixelPerPoint, $outerFrame); + + if ($filename === false) { + Header("Content-type: image/jpeg"); + ImageJpeg($image, null, $q); + } else { + ImageJpeg($image, $filename, $q); + } + + ImageDestroy($image); + } + + //---------------------------------------------------------------------- + private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) + { + $h = count($frame); + $w = strlen($frame[0]); + + $imgW = $w + 2*$outerFrame; + $imgH = $h + 2*$outerFrame; + + $base_image =ImageCreate($imgW, $imgH); + + $col[0] = ImageColorAllocate($base_image,255,255,255); + $col[1] = ImageColorAllocate($base_image,0,0,0); + + imagefill($base_image, 0, 0, $col[0]); + + for($y=0; $y<$h; $y++) { + for($x=0; $x<$w; $x++) { + if ($frame[$y][$x] == '1') { + ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); + } + } + } + + $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); + ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); + ImageDestroy($base_image); + + return $target_image; + } + } \ No newline at end of file diff --git a/app/lib/phpqrcode/qrinput.php b/app/lib/phpqrcode/qrinput.php new file mode 100644 index 00000000..0f6d7f94 --- /dev/null +++ b/app/lib/phpqrcode/qrinput.php @@ -0,0 +1,729 @@ + + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('STRUCTURE_HEADER_BITS', 20); + define('MAX_STRUCTURED_SYMBOLS', 16); + + class QRinputItem { + + public $mode; + public $size; + public $data; + public $bstream; + + public function __construct($mode, $size, $data, $bstream = null) + { + $setData = array_slice($data, 0, $size); + + if (count($setData) < $size) { + $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); + } + + if(!QRinput::check($mode, $size, $setData)) { + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData)); + return null; + } + + $this->mode = $mode; + $this->size = $size; + $this->data = $setData; + $this->bstream = $bstream; + } + + //---------------------------------------------------------------------- + public function encodeModeNum($version) + { + try { + + $words = (int)($this->size / 3); + $bs = new QRbitstream(); + + $val = 0x1; + $bs->appendNum(4, $val); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); + + for($i=0; $i<$words; $i++) { + $val = (ord($this->data[$i*3 ]) - ord('0')) * 100; + $val += (ord($this->data[$i*3+1]) - ord('0')) * 10; + $val += (ord($this->data[$i*3+2]) - ord('0')); + $bs->appendNum(10, $val); + } + + if($this->size - $words * 3 == 1) { + $val = ord($this->data[$words*3]) - ord('0'); + $bs->appendNum(4, $val); + } else if($this->size - $words * 3 == 2) { + $val = (ord($this->data[$words*3 ]) - ord('0')) * 10; + $val += (ord($this->data[$words*3+1]) - ord('0')); + $bs->appendNum(7, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeAn($version) + { + try { + $words = (int)($this->size / 2); + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x02); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); + + for($i=0; $i<$words; $i++) { + $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; + $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); + + $bs->appendNum(11, $val); + } + + if($this->size & 1) { + $val = QRinput::lookAnTable(ord($this->data[$words * 2])); + $bs->appendNum(6, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeMode8($version) + { + try { + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x4); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); + + for($i=0; $i<$this->size; $i++) { + $bs->appendNum(8, ord($this->data[$i])); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeKanji($version) + { + try { + + $bs = new QRbitrtream(); + + $bs->appendNum(4, 0x8); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); + + for($i=0; $i<$this->size; $i+=2) { + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); + if($val <= 0x9ffc) { + $val -= 0x8140; + } else { + $val -= 0xc140; + } + + $h = ($val >> 8) * 0xc0; + $val = ($val & 0xff) + $h; + + $bs->appendNum(13, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeStructure() + { + try { + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x03); + $bs->appendNum(4, ord($this->data[1]) - 1); + $bs->appendNum(4, ord($this->data[0]) - 1); + $bs->appendNum(8, ord($this->data[2])); + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function estimateBitStreamSizeOfEntry($version) + { + $bits = 0; + + if($version == 0) + $version = 1; + + switch($this->mode) { + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; + case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; + default: + return 0; + } + + $l = QRspec::lengthIndicator($this->mode, $version); + $m = 1 << $l; + $num = (int)(($this->size + $m - 1) / $m); + + $bits += $num * (4 + $l); + + return $bits; + } + + //---------------------------------------------------------------------- + public function encodeBitStream($version) + { + try { + + unset($this->bstream); + $words = QRspec::maximumWords($this->mode, $version); + + if($this->size > $words) { + + $st1 = new QRinputItem($this->mode, $words, $this->data); + $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); + + $st1->encodeBitStream($version); + $st2->encodeBitStream($version); + + $this->bstream = new QRbitstream(); + $this->bstream->append($st1->bstream); + $this->bstream->append($st2->bstream); + + unset($st1); + unset($st2); + + } else { + + $ret = 0; + + switch($this->mode) { + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; + case QR_MODE_8: $ret = $this->encodeMode8($version); break; + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; + + default: + break; + } + + if($ret < 0) + return -1; + } + + return $this->bstream->size(); + + } catch (Exception $e) { + return -1; + } + } + }; + + //########################################################################## + + class QRinput { + + public $items; + + private $version; + private $level; + + //---------------------------------------------------------------------- + public function __construct($version = 0, $level = QR_ECLEVEL_L) + { + if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) { + throw new Exception('Invalid version no'); + return NULL; + } + + $this->version = $version; + $this->level = $level; + } + + //---------------------------------------------------------------------- + public function getVersion() + { + return $this->version; + } + + //---------------------------------------------------------------------- + public function setVersion($version) + { + if($version < 0 || $version > QRSPEC_VERSION_MAX) { + throw new Exception('Invalid version no'); + return -1; + } + + $this->version = $version; + + return 0; + } + + //---------------------------------------------------------------------- + public function getErrorCorrectionLevel() + { + return $this->level; + } + + //---------------------------------------------------------------------- + public function setErrorCorrectionLevel($level) + { + if($level > QR_ECLEVEL_H) { + throw new Exception('Invalid ECLEVEL'); + return -1; + } + + $this->level = $level; + + return 0; + } + + //---------------------------------------------------------------------- + public function appendEntry(QRinputItem $entry) + { + $this->items[] = $entry; + } + + //---------------------------------------------------------------------- + public function append($mode, $size, $data) + { + try { + $entry = new QRinputItem($mode, $size, $data); + $this->items[] = $entry; + return 0; + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + + public function insertStructuredAppendHeader($size, $index, $parity) + { + if( $size > MAX_STRUCTURED_SYMBOLS ) { + throw new Exception('insertStructuredAppendHeader wrong size'); + } + + if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) { + throw new Exception('insertStructuredAppendHeader wrong index'); + } + + $buf = array($size, $index, $parity); + + try { + $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf); + array_unshift($this->items, $entry); + return 0; + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function calcParity() + { + $parity = 0; + + foreach($this->items as $item) { + if($item->mode != QR_MODE_STRUCTURE) { + for($i=$item->size-1; $i>=0; $i--) { + $parity ^= $item->data[$i]; + } + } + } + + return $parity; + } + + //---------------------------------------------------------------------- + public static function checkModeNum($size, $data) + { + for($i=0; $i<$size; $i++) { + if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){ + return false; + } + } + + return true; + } + + //---------------------------------------------------------------------- + public static function estimateBitsModeNum($size) + { + $w = (int)$size / 3; + $bits = $w * 10; + + switch($size - $w * 3) { + case 1: + $bits += 4; + break; + case 2: + $bits += 7; + break; + default: + break; + } + + return $bits; + } + + //---------------------------------------------------------------------- + public static $anTable = array( + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + ); + + //---------------------------------------------------------------------- + public static function lookAnTable($c) + { + return (($c > 127)?-1:self::$anTable[$c]); + } + + //---------------------------------------------------------------------- + public static function checkModeAn($size, $data) + { + for($i=0; $i<$size; $i++) { + if (self::lookAnTable(ord($data[$i])) == -1) { + return false; + } + } + + return true; + } + + //---------------------------------------------------------------------- + public static function estimateBitsModeAn($size) + { + $w = (int)($size / 2); + $bits = $w * 11; + + if($size & 1) { + $bits += 6; + } + + return $bits; + } + + //---------------------------------------------------------------------- + public static function estimateBitsMode8($size) + { + return $size * 8; + } + + //---------------------------------------------------------------------- + public function estimateBitsModeKanji($size) + { + return (int)(($size / 2) * 13); + } + + //---------------------------------------------------------------------- + public static function checkModeKanji($size, $data) + { + if($size & 1) + return false; + + for($i=0; $i<$size; $i+=2) { + $val = (ord($data[$i]) << 8) | ord($data[$i+1]); + if( $val < 0x8140 + || ($val > 0x9ffc && $val < 0xe040) + || $val > 0xebbf) { + return false; + } + } + + return true; + } + + /*********************************************************************** + * Validation + **********************************************************************/ + + public static function check($mode, $size, $data) + { + if($size <= 0) + return false; + + switch($mode) { + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; + case QR_MODE_AN: return self::checkModeAn($size, $data); break; + case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; + case QR_MODE_8: return true; break; + case QR_MODE_STRUCTURE: return true; break; + + default: + break; + } + + return false; + } + + + //---------------------------------------------------------------------- + public function estimateBitStreamSize($version) + { + $bits = 0; + + foreach($this->items as $item) { + $bits += $item->estimateBitStreamSizeOfEntry($version); + } + + return $bits; + } + + //---------------------------------------------------------------------- + public function estimateVersion() + { + $version = 0; + $prev = 0; + do { + $prev = $version; + $bits = $this->estimateBitStreamSize($prev); + $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); + if ($version < 0) { + return -1; + } + } while ($version > $prev); + + return $version; + } + + //---------------------------------------------------------------------- + public static function lengthOfCode($mode, $version, $bits) + { + $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); + switch($mode) { + case QR_MODE_NUM: + $chunks = (int)($payload / 10); + $remain = $payload - $chunks * 10; + $size = $chunks * 3; + if($remain >= 7) { + $size += 2; + } else if($remain >= 4) { + $size += 1; + } + break; + case QR_MODE_AN: + $chunks = (int)($payload / 11); + $remain = $payload - $chunks * 11; + $size = $chunks * 2; + if($remain >= 6) + $size++; + break; + case QR_MODE_8: + $size = (int)($payload / 8); + break; + case QR_MODE_KANJI: + $size = (int)(($payload / 13) * 2); + break; + case QR_MODE_STRUCTURE: + $size = (int)($payload / 8); + break; + default: + $size = 0; + break; + } + + $maxsize = QRspec::maximumWords($mode, $version); + if($size < 0) $size = 0; + if($size > $maxsize) $size = $maxsize; + + return $size; + } + + //---------------------------------------------------------------------- + public function createBitStream() + { + $total = 0; + + foreach($this->items as $item) { + $bits = $item->encodeBitStream($this->version); + + if($bits < 0) + return -1; + + $total += $bits; + } + + return $total; + } + + //---------------------------------------------------------------------- + public function convertData() + { + $ver = $this->estimateVersion(); + if($ver > $this->getVersion()) { + $this->setVersion($ver); + } + + for(;;) { + $bits = $this->createBitStream(); + + if($bits < 0) + return -1; + + $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); + if($ver < 0) { + throw new Exception('WRONG VERSION'); + return -1; + } else if($ver > $this->getVersion()) { + $this->setVersion($ver); + } else { + break; + } + } + + return 0; + } + + //---------------------------------------------------------------------- + public function appendPaddingBit(&$bstream) + { + $bits = $bstream->size(); + $maxwords = QRspec::getDataLength($this->version, $this->level); + $maxbits = $maxwords * 8; + + if ($maxbits == $bits) { + return 0; + } + + if ($maxbits - $bits < 5) { + return $bstream->appendNum($maxbits - $bits, 0); + } + + $bits += 4; + $words = (int)(($bits + 7) / 8); + + $padding = new QRbitstream(); + $ret = $padding->appendNum($words * 8 - $bits + 4, 0); + + if($ret < 0) + return $ret; + + $padlen = $maxwords - $words; + + if($padlen > 0) { + + $padbuf = array(); + for($i=0; $i<$padlen; $i++) { + $padbuf[$i] = ($i&1)?0x11:0xec; + } + + $ret = $padding->appendBytes($padlen, $padbuf); + + if($ret < 0) + return $ret; + + } + + $ret = $bstream->append($padding); + + return $ret; + } + + //---------------------------------------------------------------------- + public function mergeBitStream() + { + if($this->convertData() < 0) { + return null; + } + + $bstream = new QRbitstream(); + + foreach($this->items as $item) { + $ret = $bstream->append($item->bstream); + if($ret < 0) { + return null; + } + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function getBitStream() + { + + $bstream = $this->mergeBitStream(); + + if($bstream == null) { + return null; + } + + $ret = $this->appendPaddingBit($bstream); + if($ret < 0) { + return null; + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function getByteStream() + { + $bstream = $this->getBitStream(); + if($bstream == null) { + return null; + } + + return $bstream->toByte(); + } + } + + + \ No newline at end of file diff --git a/app/lib/phpqrcode/qrlib.php b/app/lib/phpqrcode/qrlib.php new file mode 100644 index 00000000..d55c4af2 --- /dev/null +++ b/app/lib/phpqrcode/qrlib.php @@ -0,0 +1,43 @@ + + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + $QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR; + + // Required libs + + include $QR_BASEDIR."qrconst.php"; + include $QR_BASEDIR."qrconfig.php"; + include $QR_BASEDIR."qrtools.php"; + include $QR_BASEDIR."qrspec.php"; + include $QR_BASEDIR."qrimage.php"; + include $QR_BASEDIR."qrinput.php"; + include $QR_BASEDIR."qrbitstream.php"; + include $QR_BASEDIR."qrsplit.php"; + include $QR_BASEDIR."qrrscode.php"; + include $QR_BASEDIR."qrmask.php"; + include $QR_BASEDIR."qrencode.php"; + diff --git a/app/lib/phpqrcode/qrmask.php b/app/lib/phpqrcode/qrmask.php new file mode 100644 index 00000000..b14d7ae1 --- /dev/null +++ b/app/lib/phpqrcode/qrmask.php @@ -0,0 +1,328 @@ + + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('N1', 3); + define('N2', 3); + define('N3', 40); + define('N4', 10); + + class QRmask { + + public $runLength = array(); + + //---------------------------------------------------------------------- + public function __construct() + { + $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); + } + + //---------------------------------------------------------------------- + public function writeFormatInformation($width, &$frame, $mask, $level) + { + $blacks = 0; + $format = QRspec::getFormatInfo($mask, $level); + + for($i=0; $i<8; $i++) { + if($format & 1) { + $blacks += 2; + $v = 0x85; + } else { + $v = 0x84; + } + + $frame[8][$width - 1 - $i] = chr($v); + if($i < 6) { + $frame[$i][8] = chr($v); + } else { + $frame[$i + 1][8] = chr($v); + } + $format = $format >> 1; + } + + for($i=0; $i<7; $i++) { + if($format & 1) { + $blacks += 2; + $v = 0x85; + } else { + $v = 0x84; + } + + $frame[$width - 7 + $i][8] = chr($v); + if($i == 0) { + $frame[8][7] = chr($v); + } else { + $frame[8][6 - $i] = chr($v); + } + + $format = $format >> 1; + } + + return $blacks; + } + + //---------------------------------------------------------------------- + public function mask0($x, $y) { return ($x+$y)&1; } + public function mask1($x, $y) { return ($y&1); } + public function mask2($x, $y) { return ($x%3); } + public function mask3($x, $y) { return ($x+$y)%3; } + public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; } + public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; } + public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; } + public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; } + + //---------------------------------------------------------------------- + private function generateMaskNo($maskNo, $width, $frame) + { + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); + + for($y=0; $y<$width; $y++) { + for($x=0; $x<$width; $x++) { + if(ord($frame[$y][$x]) & 0x80) { + $bitMask[$y][$x] = 0; + } else { + $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); + $bitMask[$y][$x] = ($maskFunc == 0)?1:0; + } + + } + } + + return $bitMask; + } + + //---------------------------------------------------------------------- + public static function serial($bitFrame) + { + $codeArr = array(); + + foreach ($bitFrame as $line) + $codeArr[] = join('', $line); + + return gzcompress(join("\n", $codeArr), 9); + } + + //---------------------------------------------------------------------- + public static function unserial($code) + { + $codeArr = array(); + + $codeLines = explode("\n", gzuncompress($code)); + foreach ($codeLines as $line) + $codeArr[] = str_split($line); + + return $codeArr; + } + + //---------------------------------------------------------------------- + public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) + { + $b = 0; + $bitMask = array(); + + $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat'; + + if (QR_CACHEABLE) { + if (file_exists($fileName)) { + $bitMask = self::unserial(file_get_contents($fileName)); + } else { + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); + if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) + mkdir(QR_CACHE_DIR.'mask_'.$maskNo); + file_put_contents($fileName, self::serial($bitMask)); + } + } else { + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); + } + + if ($maskGenOnly) + return; + + $d = $s; + + for($y=0; $y<$width; $y++) { + for($x=0; $x<$width; $x++) { + if($bitMask[$y][$x] == 1) { + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); + } + $b += (int)(ord($d[$y][$x]) & 1); + } + } + + return $b; + } + + //---------------------------------------------------------------------- + public function makeMask($width, $frame, $maskNo, $level) + { + $masked = array_fill(0, $width, str_repeat("\0", $width)); + $this->makeMaskNo($maskNo, $width, $frame, $masked); + $this->writeFormatInformation($width, $masked, $maskNo, $level); + + return $masked; + } + + //---------------------------------------------------------------------- + public function calcN1N3($length) + { + $demerit = 0; + + for($i=0; $i<$length; $i++) { + + if($this->runLength[$i] >= 5) { + $demerit += (N1 + ($this->runLength[$i] - 5)); + } + if($i & 1) { + if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) { + $fact = (int)($this->runLength[$i] / 3); + if(($this->runLength[$i-2] == $fact) && + ($this->runLength[$i-1] == $fact) && + ($this->runLength[$i+1] == $fact) && + ($this->runLength[$i+2] == $fact)) { + if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) { + $demerit += N3; + } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) { + $demerit += N3; + } + } + } + } + } + return $demerit; + } + + //---------------------------------------------------------------------- + public function evaluateSymbol($width, $frame) + { + $head = 0; + $demerit = 0; + + for($y=0; $y<$width; $y++) { + $head = 0; + $this->runLength[0] = 1; + + $frameY = $frame[$y]; + + if ($y>0) + $frameYM = $frame[$y-1]; + + for($x=0; $x<$width; $x++) { + if(($x > 0) && ($y > 0)) { + $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); + $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); + + if(($b22 | ($w22 ^ 1))&1) { + $demerit += N2; + } + } + if(($x == 0) && (ord($frameY[$x]) & 1)) { + $this->runLength[0] = -1; + $head = 1; + $this->runLength[$head] = 1; + } else if($x > 0) { + if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { + $head++; + $this->runLength[$head] = 1; + } else { + $this->runLength[$head]++; + } + } + } + + $demerit += $this->calcN1N3($head+1); + } + + for($x=0; $x<$width; $x++) { + $head = 0; + $this->runLength[0] = 1; + + for($y=0; $y<$width; $y++) { + if($y == 0 && (ord($frame[$y][$x]) & 1)) { + $this->runLength[0] = -1; + $head = 1; + $this->runLength[$head] = 1; + } else if($y > 0) { + if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { + $head++; + $this->runLength[$head] = 1; + } else { + $this->runLength[$head]++; + } + } + } + + $demerit += $this->calcN1N3($head+1); + } + + return $demerit; + } + + + //---------------------------------------------------------------------- + public function mask($width, $frame, $level) + { + $minDemerit = PHP_INT_MAX; + $bestMaskNum = 0; + $bestMask = array(); + + $checked_masks = array(0,1,2,3,4,5,6,7); + + if (QR_FIND_FROM_RANDOM !== false) { + + $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); + for ($i = 0; $i < $howManuOut; $i++) { + $remPos = rand (0, count($checked_masks)-1); + unset($checked_masks[$remPos]); + $checked_masks = array_values($checked_masks); + } + + } + + $bestMask = $frame; + + foreach($checked_masks as $i) { + $mask = array_fill(0, $width, str_repeat("\0", $width)); + + $demerit = 0; + $blacks = 0; + $blacks = $this->makeMaskNo($i, $width, $frame, $mask); + $blacks += $this->writeFormatInformation($width, $mask, $i, $level); + $blacks = (int)(100 * $blacks / ($width * $width)); + $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); + $demerit += $this->evaluateSymbol($width, $mask); + + if($demerit < $minDemerit) { + $minDemerit = $demerit; + $bestMask = $mask; + $bestMaskNum = $i; + } + } + + return $bestMask; + } + + //---------------------------------------------------------------------- + } diff --git a/app/lib/phpqrcode/qrrscode.php b/app/lib/phpqrcode/qrrscode.php new file mode 100644 index 00000000..591129a3 --- /dev/null +++ b/app/lib/phpqrcode/qrrscode.php @@ -0,0 +1,210 @@ + + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRrsItem { + + public $mm; // Bits per symbol + public $nn; // Symbols per block (= (1<= $this->nn) { + $x -= $this->nn; + $x = ($x >> $this->mm) + ($x & $this->nn); + } + + return $x; + } + + //---------------------------------------------------------------------- + public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) + { + // Common code for intializing a Reed-Solomon control block (char or int symbols) + // Copyright 2004 Phil Karn, KA9Q + // May be used under the terms of the GNU Lesser General Public License (LGPL) + + $rs = null; + + // Check parameter ranges + if($symsize < 0 || $symsize > 8) return $rs; + if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; + if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; + if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! + if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding + + $rs = new QRrsItem(); + $rs->mm = $symsize; + $rs->nn = (1<<$symsize)-1; + $rs->pad = $pad; + + $rs->alpha_to = array_fill(0, $rs->nn+1, 0); + $rs->index_of = array_fill(0, $rs->nn+1, 0); + + // PHP style macro replacement ;) + $NN =& $rs->nn; + $A0 =& $NN; + + // Generate Galois field lookup tables + $rs->index_of[0] = $A0; // log(zero) = -inf + $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 + $sr = 1; + + for($i=0; $i<$rs->nn; $i++) { + $rs->index_of[$sr] = $i; + $rs->alpha_to[$i] = $sr; + $sr <<= 1; + if($sr & (1<<$symsize)) { + $sr ^= $gfpoly; + } + $sr &= $rs->nn; + } + + if($sr != 1){ + // field generator polynomial is not primitive! + $rs = NULL; + return $rs; + } + + /* Form RS code generator polynomial from its roots */ + $rs->genpoly = array_fill(0, $nroots+1, 0); + + $rs->fcr = $fcr; + $rs->prim = $prim; + $rs->nroots = $nroots; + $rs->gfpoly = $gfpoly; + + /* Find prim-th root of 1, used in decoding */ + for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) + ; // intentional empty-body loop! + + $rs->iprim = (int)($iprim / $prim); + $rs->genpoly[0] = 1; + + for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { + $rs->genpoly[$i+1] = 1; + + // Multiply rs->genpoly[] by @**(root + x) + for ($j = $i; $j > 0; $j--) { + if ($rs->genpoly[$j] != 0) { + $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; + } else { + $rs->genpoly[$j] = $rs->genpoly[$j-1]; + } + } + // rs->genpoly[0] can never be zero + $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)]; + } + + // convert rs->genpoly[] to index form for quicker encoding + for ($i = 0; $i <= $nroots; $i++) + $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; + + return $rs; + } + + //---------------------------------------------------------------------- + public function encode_rs_char($data, &$parity) + { + $MM =& $this->mm; + $NN =& $this->nn; + $ALPHA_TO =& $this->alpha_to; + $INDEX_OF =& $this->index_of; + $GENPOLY =& $this->genpoly; + $NROOTS =& $this->nroots; + $FCR =& $this->fcr; + $PRIM =& $this->prim; + $IPRIM =& $this->iprim; + $PAD =& $this->pad; + $A0 =& $NN; + + $parity = array_fill(0, $NROOTS, 0); + + for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) { + + $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; + if($feedback != $A0) { + // feedback term is non-zero + + // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must + // always be for the polynomials constructed by init_rs() + $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); + + for($j=1;$j<$NROOTS;$j++) { + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; + } + } + + // Shift + array_shift($parity); + if($feedback != $A0) { + array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); + } else { + array_push($parity, 0); + } + } + } + } + + //########################################################################## + + class QRrs { + + public static $items = array(); + + //---------------------------------------------------------------------- + public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) + { + foreach(self::$items as $rs) { + if($rs->pad != $pad) continue; + if($rs->nroots != $nroots) continue; + if($rs->mm != $symsize) continue; + if($rs->gfpoly != $gfpoly) continue; + if($rs->fcr != $fcr) continue; + if($rs->prim != $prim) continue; + + return $rs; + } + + $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad); + array_unshift(self::$items, $rs); + + return $rs; + } + } \ No newline at end of file diff --git a/app/lib/phpqrcode/qrspec.php b/app/lib/phpqrcode/qrspec.php new file mode 100644 index 00000000..92aea0c7 --- /dev/null +++ b/app/lib/phpqrcode/qrspec.php @@ -0,0 +1,592 @@ + + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * The following data / specifications are taken from + * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) + * or + * "Automatic identification and data capture techniques -- + * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('QRSPEC_VERSION_MAX', 40); + define('QRSPEC_WIDTH_MAX', 177); + + define('QRCAP_WIDTH', 0); + define('QRCAP_WORDS', 1); + define('QRCAP_REMINDER', 2); + define('QRCAP_EC', 3); + + class QRspec { + + public static $capacity = array( + array( 0, 0, 0, array( 0, 0, 0, 0)), + array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 + array( 25, 44, 7, array( 10, 16, 22, 28)), + array( 29, 70, 7, array( 15, 26, 36, 44)), + array( 33, 100, 7, array( 20, 36, 52, 64)), + array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 + array( 41, 172, 7, array( 36, 64, 96, 112)), + array( 45, 196, 0, array( 40, 72, 108, 130)), + array( 49, 242, 0, array( 48, 88, 132, 156)), + array( 53, 292, 0, array( 60, 110, 160, 192)), + array( 57, 346, 0, array( 72, 130, 192, 224)), //10 + array( 61, 404, 0, array( 80, 150, 224, 264)), + array( 65, 466, 0, array( 96, 176, 260, 308)), + array( 69, 532, 0, array( 104, 198, 288, 352)), + array( 73, 581, 3, array( 120, 216, 320, 384)), + array( 77, 655, 3, array( 132, 240, 360, 432)), //15 + array( 81, 733, 3, array( 144, 280, 408, 480)), + array( 85, 815, 3, array( 168, 308, 448, 532)), + array( 89, 901, 3, array( 180, 338, 504, 588)), + array( 93, 991, 3, array( 196, 364, 546, 650)), + array( 97, 1085, 3, array( 224, 416, 600, 700)), //20 + array(101, 1156, 4, array( 224, 442, 644, 750)), + array(105, 1258, 4, array( 252, 476, 690, 816)), + array(109, 1364, 4, array( 270, 504, 750, 900)), + array(113, 1474, 4, array( 300, 560, 810, 960)), + array(117, 1588, 4, array( 312, 588, 870, 1050)), //25 + array(121, 1706, 4, array( 336, 644, 952, 1110)), + array(125, 1828, 4, array( 360, 700, 1020, 1200)), + array(129, 1921, 3, array( 390, 728, 1050, 1260)), + array(133, 2051, 3, array( 420, 784, 1140, 1350)), + array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30 + array(141, 2323, 3, array( 480, 868, 1290, 1530)), + array(145, 2465, 3, array( 510, 924, 1350, 1620)), + array(149, 2611, 3, array( 540, 980, 1440, 1710)), + array(153, 2761, 3, array( 570, 1036, 1530, 1800)), + array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35 + array(161, 3034, 0, array( 600, 1120, 1680, 1980)), + array(165, 3196, 0, array( 630, 1204, 1770, 2100)), + array(169, 3362, 0, array( 660, 1260, 1860, 2220)), + array(173, 3532, 0, array( 720, 1316, 1950, 2310)), + array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40 + ); + + //---------------------------------------------------------------------- + public static function getDataLength($version, $level) + { + return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level]; + } + + //---------------------------------------------------------------------- + public static function getECCLength($version, $level) + { + return self::$capacity[$version][QRCAP_EC][$level]; + } + + //---------------------------------------------------------------------- + public static function getWidth($version) + { + return self::$capacity[$version][QRCAP_WIDTH]; + } + + //---------------------------------------------------------------------- + public static function getRemainder($version) + { + return self::$capacity[$version][QRCAP_REMINDER]; + } + + //---------------------------------------------------------------------- + public static function getMinimumVersion($size, $level) + { + + for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) { + $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; + if($words >= $size) + return $i; + } + + return -1; + } + + //###################################################################### + + public static $lengthTableBits = array( + array(10, 12, 14), + array( 9, 11, 13), + array( 8, 16, 16), + array( 8, 10, 12) + ); + + //---------------------------------------------------------------------- + public static function lengthIndicator($mode, $version) + { + if ($mode == QR_MODE_STRUCTURE) + return 0; + + if ($version <= 9) { + $l = 0; + } else if ($version <= 26) { + $l = 1; + } else { + $l = 2; + } + + return self::$lengthTableBits[$mode][$l]; + } + + //---------------------------------------------------------------------- + public static function maximumWords($mode, $version) + { + if($mode == QR_MODE_STRUCTURE) + return 3; + + if($version <= 9) { + $l = 0; + } else if($version <= 26) { + $l = 1; + } else { + $l = 2; + } + + $bits = self::$lengthTableBits[$mode][$l]; + $words = (1 << $bits) - 1; + + if($mode == QR_MODE_KANJI) { + $words *= 2; // the number of bytes is required + } + + return $words; + } + + // Error correction code ----------------------------------------------- + // Table of the error correction code (Reed-Solomon block) + // See Table 12-16 (pp.30-36), JIS X0510:2004. + + public static $eccTable = array( + array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), + array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), + array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), + array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 + array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), + array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), + array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), + array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), + array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10 + array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), + array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), + array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), + array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), + array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15 + array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), + array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), + array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), + array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), + array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20 + array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), + array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), + array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), + array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), + array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25 + array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), + array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), + array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), + array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), + array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30 + array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), + array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), + array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), + array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), + array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35 + array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), + array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), + array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), + array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), + array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40 + ); + + //---------------------------------------------------------------------- + // CACHEABLE!!! + + public static function getEccSpec($version, $level, array &$spec) + { + if (count($spec) < 5) { + $spec = array(0,0,0,0,0); + } + + $b1 = self::$eccTable[$version][$level][0]; + $b2 = self::$eccTable[$version][$level][1]; + $data = self::getDataLength($version, $level); + $ecc = self::getECCLength($version, $level); + + if($b2 == 0) { + $spec[0] = $b1; + $spec[1] = (int)($data / $b1); + $spec[2] = (int)($ecc / $b1); + $spec[3] = 0; + $spec[4] = 0; + } else { + $spec[0] = $b1; + $spec[1] = (int)($data / ($b1 + $b2)); + $spec[2] = (int)($ecc / ($b1 + $b2)); + $spec[3] = $b2; + $spec[4] = $spec[1] + 1; + } + } + + // Alignment pattern --------------------------------------------------- + + // Positions of alignment patterns. + // This array includes only the second and the third position of the + // alignment patterns. Rest of them can be calculated from the distance + // between them. + + // See Table 1 in Appendix E (pp.71) of JIS X0510:2004. + + public static $alignmentPattern = array( + array( 0, 0), + array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 + array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 + array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15 + array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20 + array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25 + array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30 + array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35 + array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40 + ); + + + /** -------------------------------------------------------------------- + * Put an alignment marker. + * @param frame + * @param width + * @param ox,oy center coordinate of the pattern + */ + public static function putAlignmentMarker(array &$frame, $ox, $oy) + { + $finder = array( + "\xa1\xa1\xa1\xa1\xa1", + "\xa1\xa0\xa0\xa0\xa1", + "\xa1\xa0\xa1\xa0\xa1", + "\xa1\xa0\xa0\xa0\xa1", + "\xa1\xa1\xa1\xa1\xa1" + ); + + $yStart = $oy-2; + $xStart = $ox-2; + + for($y=0; $y<5; $y++) { + QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); + } + } + + //---------------------------------------------------------------------- + public static function putAlignmentPattern($version, &$frame, $width) + { + if($version < 2) + return; + + $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; + if($d < 0) { + $w = 2; + } else { + $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2); + } + + if($w * $w - 3 == 1) { + $x = self::$alignmentPattern[$version][0]; + $y = self::$alignmentPattern[$version][0]; + self::putAlignmentMarker($frame, $x, $y); + return; + } + + $cx = self::$alignmentPattern[$version][0]; + for($x=1; $x<$w - 1; $x++) { + self::putAlignmentMarker($frame, 6, $cx); + self::putAlignmentMarker($frame, $cx, 6); + $cx += $d; + } + + $cy = self::$alignmentPattern[$version][0]; + for($y=0; $y<$w-1; $y++) { + $cx = self::$alignmentPattern[$version][0]; + for($x=0; $x<$w-1; $x++) { + self::putAlignmentMarker($frame, $cx, $cy); + $cx += $d; + } + $cy += $d; + } + } + + // Version information pattern ----------------------------------------- + + // Version information pattern (BCH coded). + // See Table 1 in Appendix D (pp.68) of JIS X0510:2004. + + // size: [QRSPEC_VERSION_MAX - 6] + + public static $versionPattern = array( + 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, + 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, + 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, + 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, + 0x27541, 0x28c69 + ); + + //---------------------------------------------------------------------- + public static function getVersionPattern($version) + { + if($version < 7 || $version > QRSPEC_VERSION_MAX) + return 0; + + return self::$versionPattern[$version -7]; + } + + // Format information -------------------------------------------------- + // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib) + + public static $formatInfo = array( + array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), + array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), + array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), + array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b) + ); + + public static function getFormatInfo($mask, $level) + { + if($mask < 0 || $mask > 7) + return 0; + + if($level < 0 || $level > 3) + return 0; + + return self::$formatInfo[$level][$mask]; + } + + // Frame --------------------------------------------------------------- + // Cache of initial frames. + + public static $frames = array(); + + /** -------------------------------------------------------------------- + * Put a finder pattern. + * @param frame + * @param width + * @param ox,oy upper-left coordinate of the pattern + */ + public static function putFinderPattern(&$frame, $ox, $oy) + { + $finder = array( + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" + ); + + for($y=0; $y<7; $y++) { + QRstr::set($frame, $ox, $oy+$y, $finder[$y]); + } + } + + //---------------------------------------------------------------------- + public static function createFrame($version) + { + $width = self::$capacity[$version][QRCAP_WIDTH]; + $frameLine = str_repeat ("\0", $width); + $frame = array_fill(0, $width, $frameLine); + + // Finder pattern + self::putFinderPattern($frame, 0, 0); + self::putFinderPattern($frame, $width - 7, 0); + self::putFinderPattern($frame, 0, $width - 7); + + // Separator + $yOffset = $width - 7; + + for($y=0; $y<7; $y++) { + $frame[$y][7] = "\xc0"; + $frame[$y][$width - 8] = "\xc0"; + $frame[$yOffset][7] = "\xc0"; + $yOffset++; + } + + $setPattern = str_repeat("\xc0", 8); + + QRstr::set($frame, 0, 7, $setPattern); + QRstr::set($frame, $width-8, 7, $setPattern); + QRstr::set($frame, 0, $width - 8, $setPattern); + + // Format info + $setPattern = str_repeat("\x84", 9); + QRstr::set($frame, 0, 8, $setPattern); + QRstr::set($frame, $width - 8, 8, $setPattern, 8); + + $yOffset = $width - 8; + + for($y=0; $y<8; $y++,$yOffset++) { + $frame[$y][8] = "\x84"; + $frame[$yOffset][8] = "\x84"; + } + + // Timing pattern + + for($i=1; $i<$width-15; $i++) { + $frame[6][7+$i] = chr(0x90 | ($i & 1)); + $frame[7+$i][6] = chr(0x90 | ($i & 1)); + } + + // Alignment pattern + self::putAlignmentPattern($version, $frame, $width); + + // Version information + if($version >= 7) { + $vinf = self::getVersionPattern($version); + + $v = $vinf; + + for($x=0; $x<6; $x++) { + for($y=0; $y<3; $y++) { + $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); + $v = $v >> 1; + } + } + + $v = $vinf; + for($y=0; $y<6; $y++) { + for($x=0; $x<3; $x++) { + $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); + $v = $v >> 1; + } + } + } + + // and a little bit... + $frame[$width - 8][8] = "\x81"; + + return $frame; + } + + //---------------------------------------------------------------------- + public static function debug($frame, $binary_mode = false) + { + if ($binary_mode) { + + foreach ($frame as &$frameLine) { + $frameLine = join('  ', explode('0', $frameLine)); + $frameLine = join('██', explode('1', $frameLine)); + } + + ?> + +


        '; + echo join("
        ", $frame); + echo '






'; + + } else { + + foreach ($frame as &$frameLine) { + $frameLine = join(' ', explode("\xc0", $frameLine)); + $frameLine = join('', explode("\xc1", $frameLine)); + $frameLine = join(' ', explode("\xa0", $frameLine)); + $frameLine = join('', explode("\xa1", $frameLine)); + $frameLine = join('', explode("\x84", $frameLine)); //format 0 + $frameLine = join('', explode("\x85", $frameLine)); //format 1 + $frameLine = join('', explode("\x81", $frameLine)); //special bit + $frameLine = join(' ', explode("\x90", $frameLine)); //clock 0 + $frameLine = join('', explode("\x91", $frameLine)); //clock 1 + $frameLine = join(' ', explode("\x88", $frameLine)); //version + $frameLine = join('', explode("\x89", $frameLine)); //version + $frameLine = join('♦', explode("\x01", $frameLine)); + $frameLine = join('⋅', explode("\0", $frameLine)); + } + + ?> + + "; + echo join("
", $frame); + echo "
"; + + } + } + + //---------------------------------------------------------------------- + public static function serial($frame) + { + return gzcompress(join("\n", $frame), 9); + } + + //---------------------------------------------------------------------- + public static function unserial($code) + { + return explode("\n", gzuncompress($code)); + } + + //---------------------------------------------------------------------- + public static function newFrame($version) + { + if($version < 1 || $version > QRSPEC_VERSION_MAX) + return null; + + if(!isset(self::$frames[$version])) { + + $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat'; + + if (QR_CACHEABLE) { + if (file_exists($fileName)) { + self::$frames[$version] = self::unserial(file_get_contents($fileName)); + } else { + self::$frames[$version] = self::createFrame($version); + file_put_contents($fileName, self::serial(self::$frames[$version])); + } + } else { + self::$frames[$version] = self::createFrame($version); + } + } + + if(is_null(self::$frames[$version])) + return null; + + return self::$frames[$version]; + } + + //---------------------------------------------------------------------- + public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; } + public static function rsBlockNum1($spec) { return $spec[0]; } + public static function rsDataCodes1($spec) { return $spec[1]; } + public static function rsEccCodes1($spec) { return $spec[2]; } + public static function rsBlockNum2($spec) { return $spec[3]; } + public static function rsDataCodes2($spec) { return $spec[4]; } + public static function rsEccCodes2($spec) { return $spec[2]; } + public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); } + public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; } + + } \ No newline at end of file diff --git a/app/lib/phpqrcode/qrsplit.php b/app/lib/phpqrcode/qrsplit.php new file mode 100644 index 00000000..d75b8273 --- /dev/null +++ b/app/lib/phpqrcode/qrsplit.php @@ -0,0 +1,311 @@ + + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * The following data / specifications are taken from + * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) + * or + * "Automatic identification and data capture techniques -- + * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + class QRsplit { + + public $dataStr = ''; + public $input; + public $modeHint; + + //---------------------------------------------------------------------- + public function __construct($dataStr, $input, $modeHint) + { + $this->dataStr = $dataStr; + $this->input = $input; + $this->modeHint = $modeHint; + } + + //---------------------------------------------------------------------- + public static function isdigitat($str, $pos) + { + if ($pos >= strlen($str)) + return false; + + return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); + } + + //---------------------------------------------------------------------- + public static function isalnumat($str, $pos) + { + if ($pos >= strlen($str)) + return false; + + return (QRinput::lookAnTable(ord($str[$pos])) >= 0); + } + + //---------------------------------------------------------------------- + public function identifyMode($pos) + { + if ($pos >= strlen($this->dataStr)) + return QR_MODE_NUL; + + $c = $this->dataStr[$pos]; + + if(self::isdigitat($this->dataStr, $pos)) { + return QR_MODE_NUM; + } else if(self::isalnumat($this->dataStr, $pos)) { + return QR_MODE_AN; + } else if($this->modeHint == QR_MODE_KANJI) { + + if ($pos+1 < strlen($this->dataStr)) + { + $d = $this->dataStr[$pos+1]; + $word = (ord($c) << 8) | ord($d); + if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { + return QR_MODE_KANJI; + } + } + } + + return QR_MODE_8; + } + + //---------------------------------------------------------------------- + public function eatNum() + { + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 0; + while(self::isdigitat($this->dataStr, $p)) { + $p++; + } + + $run = $p; + $mode = $this->identifyMode($p); + + if($mode == QR_MODE_8) { + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln + + QRinput::estimateBitsMode8(1) // + 4 + l8 + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 + if($dif > 0) { + return $this->eat8(); + } + } + if($mode == QR_MODE_AN) { + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln + + QRinput::estimateBitsModeAn(1) // + 4 + la + - QRinput::estimateBitsModeAn($run + 1);// - 4 - la + if($dif > 0) { + return $this->eatAn(); + } + } + + $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eatAn() + { + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 0; + + while(self::isalnumat($this->dataStr, $p)) { + if(self::isdigitat($this->dataStr, $p)) { + $q = $p; + while(self::isdigitat($this->dataStr, $q)) { + $q++; + } + + $dif = QRinput::estimateBitsModeAn($p) // + 4 + la + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln + - QRinput::estimateBitsModeAn($q); // - 4 - la + + if($dif < 0) { + break; + } else { + $p = $q; + } + } else { + $p++; + } + } + + $run = $p; + + if(!self::isalnumat($this->dataStr, $p)) { + $dif = QRinput::estimateBitsModeAn($run) + 4 + $la + + QRinput::estimateBitsMode8(1) // + 4 + l8 + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 + if($dif > 0) { + return $this->eat8(); + } + } + + $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eatKanji() + { + $p = 0; + + while($this->identifyMode($p) == QR_MODE_KANJI) { + $p += 2; + } + + $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eat8() + { + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 1; + $dataStrLen = strlen($this->dataStr); + + while($p < $dataStrLen) { + + $mode = $this->identifyMode($p); + if($mode == QR_MODE_KANJI) { + break; + } + if($mode == QR_MODE_NUM) { + $q = $p; + while(self::isdigitat($this->dataStr, $q)) { + $q++; + } + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln + - QRinput::estimateBitsMode8($q); // - 4 - l8 + if($dif < 0) { + break; + } else { + $p = $q; + } + } else if($mode == QR_MODE_AN) { + $q = $p; + while(self::isalnumat($this->dataStr, $q)) { + $q++; + } + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 + + QRinput::estimateBitsModeAn($q - $p) + 4 + $la + - QRinput::estimateBitsMode8($q); // - 4 - l8 + if($dif < 0) { + break; + } else { + $p = $q; + } + } else { + $p++; + } + } + + $run = $p; + $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); + + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function splitString() + { + while (strlen($this->dataStr) > 0) + { + if($this->dataStr == '') + return 0; + + $mode = $this->identifyMode(0); + + switch ($mode) { + case QR_MODE_NUM: $length = $this->eatNum(); break; + case QR_MODE_AN: $length = $this->eatAn(); break; + case QR_MODE_KANJI: + if ($hint == QR_MODE_KANJI) + $length = $this->eatKanji(); + else $length = $this->eat8(); + break; + default: $length = $this->eat8(); break; + + } + + if($length == 0) return 0; + if($length < 0) return -1; + + $this->dataStr = substr($this->dataStr, $length); + } + } + + //---------------------------------------------------------------------- + public function toUpper() + { + $stringLen = strlen($this->dataStr); + $p = 0; + + while ($p<$stringLen) { + $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint); + if($mode == QR_MODE_KANJI) { + $p += 2; + } else { + if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) { + $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); + } + $p++; + } + } + + return $this->dataStr; + } + + //---------------------------------------------------------------------- + public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) + { + if(is_null($string) || $string == '\0' || $string == '') { + throw new Exception('empty string!!!'); + } + + $split = new QRsplit($string, $input, $modeHint); + + if(!$casesensitive) + $split->toUpper(); + + return $split->splitString(); + } + } \ No newline at end of file diff --git a/app/lib/phpqrcode/qrtools.php b/app/lib/phpqrcode/qrtools.php new file mode 100644 index 00000000..3012db49 --- /dev/null +++ b/app/lib/phpqrcode/qrtools.php @@ -0,0 +1,172 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRtools { + + //---------------------------------------------------------------------- + public static function binarize($frame) + { + $len = count($frame); + foreach ($frame as &$frameLine) { + + for($i=0; $i<$len; $i++) { + $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; + } + } + + return $frame; + } + + //---------------------------------------------------------------------- + public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037') + { + $barcode_array = array(); + + if (!is_array($mode)) + $mode = explode(',', $mode); + + $eccLevel = 'L'; + + if (count($mode) > 1) { + $eccLevel = $mode[1]; + } + + $qrTab = QRcode::text($code, false, $eccLevel); + $size = count($qrTab); + + $barcode_array['num_rows'] = $size; + $barcode_array['num_cols'] = $size; + $barcode_array['bcode'] = array(); + + foreach ($qrTab as $line) { + $arrAdd = array(); + foreach(str_split($line) as $char) + $arrAdd[] = ($char=='1')?1:0; + $barcode_array['bcode'][] = $arrAdd; + } + + return $barcode_array; + } + + //---------------------------------------------------------------------- + public static function clearCache() + { + self::$frames = array(); + } + + //---------------------------------------------------------------------- + public static function buildCache() + { + QRtools::markTime('before_build_cache'); + + $mask = new QRmask(); + for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { + $frame = QRspec::newFrame($a); + if (QR_IMAGE) { + $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; + QRimage::png(self::binarize($frame), $fileName, 1, 0); + } + + $width = count($frame); + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); + for ($maskNo=0; $maskNo<8; $maskNo++) + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); + } + + QRtools::markTime('after_build_cache'); + } + + //---------------------------------------------------------------------- + public static function log($outfile, $err) + { + if (QR_LOG_DIR !== false) { + if ($err != '') { + if ($outfile !== false) { + file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); + } else { + file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); + } + } + } + } + + //---------------------------------------------------------------------- + public static function dumpMask($frame) + { + $width = count($frame); + for($y=0;$y<$width;$y++) { + for($x=0;$x<$width;$x++) { + echo ord($frame[$y][$x]).','; + } + } + } + + //---------------------------------------------------------------------- + public static function markTime($markerId) + { + list($usec, $sec) = explode(" ", microtime()); + $time = ((float)$usec + (float)$sec); + + if (!isset($GLOBALS['qr_time_bench'])) + $GLOBALS['qr_time_bench'] = array(); + + $GLOBALS['qr_time_bench'][$markerId] = $time; + } + + //---------------------------------------------------------------------- + public static function timeBenchmark() + { + self::markTime('finish'); + + $lastTime = 0; + $startTime = 0; + $p = 0; + + echo ' + + '; + + foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { + if ($p > 0) { + echo ''; + } else { + $startTime = $thisTime; + } + + $p++; + $lastTime = $thisTime; + } + + echo ' + + +
BENCHMARK
till '.$markerId.': '.number_format($thisTime-$lastTime, 6).'s
TOTAL: '.number_format($lastTime-$startTime, 6).'s
'; + } + + } + + //########################################################################## + + QRtools::markTime('start'); + \ No newline at end of file diff --git a/app/lib/phpqrcode/tools/merge.bat b/app/lib/phpqrcode/tools/merge.bat new file mode 100644 index 00000000..b60a4853 --- /dev/null +++ b/app/lib/phpqrcode/tools/merge.bat @@ -0,0 +1,2 @@ +php ./merge.php +pause \ No newline at end of file diff --git a/app/lib/phpqrcode/tools/merge.php b/app/lib/phpqrcode/tools/merge.php new file mode 100644 index 00000000..19d338b3 --- /dev/null +++ b/app/lib/phpqrcode/tools/merge.php @@ -0,0 +1,70 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + $QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; + $QR_TOOLSDIR = dirname(__FILE__).DIRECTORY_SEPARATOR; + + $outputFile = $QR_BASEDIR.'phpqrcode.php'; + + // Required libs + + $fileList = array( + $QR_BASEDIR.'qrconst.php', + $QR_TOOLSDIR.'merged_config.php', + $QR_BASEDIR.'qrtools.php', + $QR_BASEDIR.'qrspec.php', + $QR_BASEDIR.'qrimage.php', + $QR_BASEDIR.'qrinput.php', + $QR_BASEDIR.'qrbitstream.php', + $QR_BASEDIR.'qrsplit.php', + $QR_BASEDIR.'qrrscode.php', + $QR_BASEDIR.'qrmask.php', + $QR_BASEDIR.'qrencode.php' + ); + + $headerFile = $QR_TOOLSDIR.'merged_header.php'; + $versionFile = $QR_BASEDIR.'VERSION'; + + $outputCode = ''; + + foreach($fileList as $fileName) { + $outputCode .= "\n\n".'//---- '.basename($fileName).' -----------------------------'."\n\n"; + $anotherCode = file_get_contents($fileName); + $anotherCode = preg_replace ('/^<\?php/', '', $anotherCode); + $anotherCode = preg_replace ('/\?>\*$/', '', $anotherCode); + $outputCode .= "\n\n".$anotherCode."\n\n"; + } + + $versionDataEx = explode("\n", file_get_contents($versionFile)); + + $outputContents = file_get_contents($headerFile); + $outputContents .= "\n\n/*\n * Version: ".trim($versionDataEx[0])."\n * Build: ".trim($versionDataEx[1])."\n */\n\n"; + $outputContents .= $outputCode; + + file_put_contents($outputFile, $outputContents); + + \ No newline at end of file diff --git a/app/lib/phpqrcode/tools/merge.sh b/app/lib/phpqrcode/tools/merge.sh new file mode 100644 index 00000000..e4c2fbcb --- /dev/null +++ b/app/lib/phpqrcode/tools/merge.sh @@ -0,0 +1,2 @@ +#!/bin/sh +php ./merge.php \ No newline at end of file diff --git a/app/lib/phpqrcode/tools/merged_config.php b/app/lib/phpqrcode/tools/merged_config.php new file mode 100644 index 00000000..55ddb450 --- /dev/null +++ b/app/lib/phpqrcode/tools/merged_config.php @@ -0,0 +1,17 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + \ No newline at end of file diff --git a/app/models/StationtypeModel.inc b/app/models/StationtypeModel.inc new file mode 100644 index 00000000..4af53507 --- /dev/null +++ b/app/models/StationtypeModel.inc @@ -0,0 +1,165 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\models; + + + /** + * Abstract class for implementing a StationtypeModel. + * + * @author Oliver Hanraths + */ + abstract class StationtypeModel extends \hhu\z\Model + { + + + + + /** + * Load a Model. + * + * @static + * @throws \hhu\z\exceptions\StationtypeModelNotFoundException + * @throws \hhu\z\exceptions\StationtypeModelNotValidException + * @param string $modelName Name of the StationtypeModel to load + */ + public static function load($modelName) + { + // Determine full classname + $className = self::getClassName($modelName); + + try { + // Load class + static::loadClass($modelName, $className); + + // Validate class + static::checkClass($className, get_class()); + } + catch(\nre\exceptions\ClassNotValidException $e) { + throw new \hhu\z\exceptions\StationtypeModelNotValidException($e->getClassName()); + } + catch(\nre\exceptions\ClassNotFoundException $e) { + throw new \hhu\z\exceptions\StationtypeModelNotFoundException($e->getClassName()); + } + } + + + /** + * Instantiate a StationtypeModel (Factory Pattern). + * + * @static + * @param string $stationtypeName Name of the StationtypeModel to instantiate + */ + public static function factory($stationtypeName) + { + // Determine full classname + $className = self::getClassName($stationtypeName); + + // Construct and return Model + return new $className(); + } + + + /** + * Determine the Model-classname for the given Stationtype-name. + * + * @static + * @param string $stationtypeName Stationtype-name to get Model-classname of + * @return string Classname for the Stationtype-name + */ + private static function getClassName($stationtypeName) + { + $className = \nre\core\ClassLoader::concatClassNames( + $stationtypeName, + \nre\core\ClassLoader::stripClassType( + \nre\core\ClassLoader::stripNamespace( + get_class() + ) + ), + 'model' + ); + + + return \nre\configs\AppConfig::$app['namespace']."stationtypes\\$className"; + } + + + /** + * Load the class of a StationtypeModel. + * + * @static + * @throws \nre\exceptions\ClassNotFoundException + * @param string $stationtypeName Name of the StationtypeModel to load + * @param string $fullClassName Name of the class to load + */ + private static function loadClass($stationtypeName, $fullClassName) + { + // Determine folder to look in + $className = explode('\\', $fullClassName); + $className = array_pop($className); + + // Determine filename + $fileName = ROOT.DS. + \nre\configs\AppConfig::$dirs['stationtypes'].DS. + strtolower($stationtypeName).DS. + $className.\nre\configs\CoreConfig::getFileExt('includes'); + + // Check file + if(!file_exists($fileName)) + { + throw new \nre\exceptions\ClassNotFoundException( + $fullClassName + ); + } + + // Include file + include_once($fileName); + } + + + /** + * Check inheritance of the StationtypeModel-class. + * + * @static + * @throws \nre\exceptions\ClassNotValidException + * @param string $className Name of the class to check + * @param string $parentClassName Name of the parent class + */ + public static function checkClass($className, $parentClassName) + { + // Check if class is subclass of parent class + if(!is_subclass_of($className, $parentClassName)) { + throw new \nre\exceptions\ClassNotValidException( + $className + ); + } + } + + + + + /** + * Construct a new StationtypeModel. + * + * @throws \nre\exceptions\DatamodelException + * @throws \nre\exceptions\DriverNotFoundException + * @throws \nre\exceptions\DriverNotValidException + * @throws \hhu\z\exceptions\StationtypeModelNotValidException + * @throws \hhu\z\exceptions\StationtypeModelNotFoundException + */ + public function __construct() + { + parent::__construct(); + } + + } + +?> diff --git a/app/views/StationtypeView.inc b/app/views/StationtypeView.inc new file mode 100644 index 00000000..99bb3c0e --- /dev/null +++ b/app/views/StationtypeView.inc @@ -0,0 +1,79 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\views; + + + /** + * Abstract class for implementing a StationtypeView. + * + * @author Oliver Hanraths + */ + class StationtypeView extends \nre\core\View + { + + + + + /** + * Load and instantiate the StationtypeView of a StationtypeAgent. + * + * @throws \nre\exceptions\ViewNotFoundException + * @param string $layoutName Name of Layout in use + * @param string $agentName Name of the Agent + * @param string $action Current Action + * @param bool $isToplevel Agent is a ToplevelAgent + */ + public static function loadAndFactory($layoutName, $agentName=null, $action=null, $isToplevel=false) + { + return new StationtypeView($layoutName, $agentName, $action, $isToplevel); + } + + + + + /** + * Construct a new StationtypeView. + * + * @throws \nre\exceptions\ViewNotFoundException + * @param string $layoutName Name of Layout in use + * @param string $agentName Name of the Agent + * @param string $action Current Action + * @param bool $isToplevel Agent is a ToplevelAgent + */ + protected function __construct($layoutName, $agentName=null, $action=null, $isToplevel=false) + { + // Create template filename + // LayoutName + $fileName = ROOT.DS. + \nre\configs\AppConfig::$dirs['stationtypes'].DS. + strtolower($agentName).DS. + strtolower($layoutName).DS; + + // Action + $fileName .= strtolower($action); + + // File extension + $fileName .= \nre\configs\CoreConfig::getFileExt('views'); + + + // Check template file + if(!file_exists($fileName)) { + throw new \nre\exceptions\ViewNotFoundException($fileName); + } + + // Save filename + $this->templateFilename = $fileName; + } + + } + +?> diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index 910f2d7c..585f6723 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -71,6 +71,7 @@ 'media' => 'media', 'seminarymedia' => 'seminarymedia', 'questtypes' => 'questtypes', + 'stationtypes' => 'stationtypes', 'temporary' => 'tmp', 'uploads' => 'uploads', 'seminaryuploads' => 'seminaryuploads' @@ -304,6 +305,10 @@ array('^charactergroupsquests/([^/]+)/([^/]+)/create/?$', 'charactergroupsquests/create/$1/$2', true), array('^charactergroupsquests/([^/]+)/([^/]+)/([^/]+)/?$', 'charactergroupsquests/quest/$1/$2/$3', true), array('^charactergroupsquests/([^/]+)/([^/]+)/([^/]+)/(edit|delete|manage)/?$', 'charactergroupsquests/$4/$1/$2/$3', true), + array('^charactergroupsqueststations/([^/]+)/([^/]+)/([^/]+)/?$', 'charactergroupsqueststations/index/$1/$2/$3?layout=ajax', true), + array('^charactergroupsqueststations/([^/]+)/([^/]+)/([^/]+)/create/?$', 'charactergroupsqueststations/create/$1/$2/$3', true), + array('^charactergroupsqueststations/([^/]+)/([^/]+)/([^/]+)/([^/]+)/(edit|edittask|delete)/?$', 'charactergroupsqueststations/$5/$1/$2/$3/$4', true), + array('^charactergroupsqueststations/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$', 'charactergroupsqueststations/station/$1/$2/$3/$4', true), array('^achievements/([^/]+)/(create|manage)/?$', 'achievements/$2/$1', true), array('^achievements/([^/]+)/([^/]+)/(edit|conditions|moveup|movedown|delete)/?$', 'achievements/$3/$1/$2', true), array('^achievements/([^/]+)/?$', 'achievements/index/$1', true), @@ -316,7 +321,8 @@ array('^pages/([^/]+)/(edit|delete)$', 'pages/$2/$1', true), array('^pages/(?!(create|edit|delete))/?', 'pages/page/$1', true), array('^media/(.*)$', 'media/$1?layout=binary', false), - array('^uploads/(.*)$', 'uploads/$1?layout=binary', false) + array('^uploads/(.*)$', 'uploads/$1?layout=binary', false), + array('^qrcodes/(.*)$', 'qrcodes/$1?layout=binary', false) ); @@ -358,6 +364,9 @@ array('^charactergroupsquests/create/([^/]+)/([^/]+)/?$', 'charactergroupsquests/$1/$2/create', true), array('^charactergroupsquests/quest/(.*)$', 'charactergroupsquests/$1', true), array('^charactergroupsquests/(edit|delete|manage)/([^/]+)/([^/]+)/([^/]+)$', 'charactergroupsquests/$2/$3/$4/$1', true), + array('^charactergroupsqueststations/index/(.*)$', 'charactergroupsqueststations/$1', true), + array('^charactergroupsqueststations/station/(.*)$', 'charactergroupsqueststations/$1', true), + array('^charactergroupsqueststations/(create|edit|edittask|delete)/(.*)$', 'charactergroupsqueststations/$2/$1', true), array('^achievements/index/(.*)$', 'achievements/$1', true), array('^achievements/(create|manage)/(.*)$', 'achievements/$2/$1', true), array('^achievements/(edit|conditions|moveup|movedown|delete)/(.*)$', 'achievements/$2/$1', true), diff --git a/controllers/CharactergroupsquestsController.inc b/controllers/CharactergroupsquestsController.inc index 21c1778e..24fdeafc 100644 --- a/controllers/CharactergroupsquestsController.inc +++ b/controllers/CharactergroupsquestsController.inc @@ -25,7 +25,7 @@ * * @var array */ - public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'media', 'questgroups', 'uploads'); + public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'media', 'questgroups', 'uploads'); /** * Required components * @@ -78,6 +78,30 @@ $questgroup = $this->Questgroups->getQuestgroupById($quest['questgroups_id']); $questgroup['entered'] = $this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], self::$character['id']); + // Get Character group + $charactergroup = null; + $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']); + $charactergroups = $this->Charactergroups->getGroupsForCharacter($character['id']); + if(!empty($charactergroups)) { + // TODO Multiple Character groups + $charactergroup = $charactergroups[0]; + } + + // Get Stations + $stations = null; + if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) { + $stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']); + } + elseif(!is_null($charactergroup)) { + $stations = $this->Charactergroupsqueststations->getStationsForQuestAndGroup($quest['id'], $charactergroup['id']); + foreach($stations as &$station) { + $station['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation( + $station['id'], + $charactergroup['id'] + ); + } + } + // Get Character groups-groups $groups = $this->Charactergroups->getGroupsForQuest($quest['id']); @@ -98,6 +122,7 @@ $this->set('groupsgroup', $groupsgroup); $this->set('quest', $quest); $this->set('questgroup', $questgroup); + $this->set('stations', $stations); $this->set('groups', $groups); $this->set('uploads', $uploads); } diff --git a/controllers/CharactergroupsqueststationsController.inc b/controllers/CharactergroupsqueststationsController.inc new file mode 100644 index 00000000..6000f874 --- /dev/null +++ b/controllers/CharactergroupsqueststationsController.inc @@ -0,0 +1,937 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\controllers; + + + /** + * Controller of the CharactergroupsqueststationAgent to display Character + * groups Quest stations. + * + * @author Oliver Hanraths + */ + class CharactergroupsqueststationsController extends \hhu\z\controllers\SeminaryController + { + /** + * Required models + * + * @var array + */ + public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'stationtypes', 'media'); + /** + * Required components + * + * @var array + */ + public $components = array('validation'); + /** + * User permissions + * + * @var array + */ + public $permissions = array( + 'index' => array('admin', 'moderator', 'user'), + 'station' => array('admin', 'moderator', 'user') + ); + /** + * User seminary permissions + * + * @var array + */ + public $seminaryPermissions = array( + 'index' => array('admin', 'moderator', 'user'), + 'station' => array('admin', 'moderator', 'user') + ); + + + + + /** + * Action: index. + * + * Show all stations of a Character groups Quest. + * + * @throws \nre\exceptions\IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $groupsgroupUrl URL-Title of a Character groups-group + * @param string $questUrl URL-Title of a Character groups Quest + */ + public function index($seminaryUrl, $groupsgroupUrl, $questUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl); + + // Get Character groups-group Quests + $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); + + // Get Character group + $charactergroup = null; + $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']); + $charactergroups = $this->Charactergroups->getGroupsForCharacter($character['id']); + if(!empty($charactergroups)) { + // TODO Multiple Character groups + $charactergroup = $charactergroups[0]; + } + + // Get Stations + $stations = null; + if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) { + $stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']); + } + elseif(!is_null($charactergroup)) { + $stations = $this->Charactergroupsqueststations->getStationsForQuestAndGroup($quest['id'], $charactergroup['id']); + } + + + // Pass data to view + $this->set('stations', $stations); + $this->set('hasgroup', !is_null($charactergroup)); + } + + + /** + * Action: station. + * + * Show a station of a Character groups Quest. + * + * @throws \nre\exceptions\IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $groupsgroupUrl URL-Title of a Character groups-group + * @param string $questUrl URL-Title of a Character groups Quest + * @param string $stationUrl URL of station + */ + public function station($seminaryUrl, $groupsgroupUrl, $questUrl, $stationUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl); + + // Get Character groups-group Quests + $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); + + // Get Station + $station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl); + if(!is_null($station['stationpicture_id'])) { + $station['picture'] = $this->Media->getSeminaryMediaById($station['stationpicture_id']); + } + + // Get Character group + $charactergroup = null; + $character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']); + $charactergroups = $this->Charactergroups->getGroupsForCharacter($character['id']); + if(!empty($charactergroups)) { + // TODO Multiple Character groups + $charactergroup = $charactergroups[0]; + } + + // TODO Check permissions + + // Set status “entered” + if(!is_null($charactergroup)) { + $this->Charactergroupsqueststations->setStationEntered($station['id'], $charactergroup['id']); + } + + // Get Character groups-groups + $groups = null; + if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) + { + $groups = $this->Charactergroups->getGroupsForQueststation($station['id']); + foreach($groups as &$group) { + $group['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation( + $station['id'], + $group['id'] + ); + } + } + + // Task + $task = null; + $stationtype = $this->Stationtypes->getStationtypeById($station['stationtype_id']); + if(!is_null($stationtype['classname'])) { + $task = $this->renderTask($stationtype['classname'], $seminary, $groupsgroup, $quest, $station, $charactergroup); + } + else + { + // Mark Station as solved + if(!is_null($charactergroup)) { + $this->Charactergroupsqueststations->setStationSolved($station['id'], $charactergroup['id']); + } + } + + // Status + $solved = false; + $tried = false; + if(!is_null($charactergroup)) { + $solved = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation($station['id'], $charactergroup['id']); + if(!$solved) { + $tried = $this->Charactergroupsqueststations->hasCharactergroupTriedStation($station['id'], $charactergroup['id']); + } + } + + + // Set title + $this->addTitle($station['title']); + $this->addTitle($quest['title']); + $this->addTitle($groupsgroup['name']); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('groupsgroup', $groupsgroup); + $this->set('quest', $quest); + $this->set('station', $station); + $this->set('task', $task); + $this->set('groups', $groups); + $this->set('solved', $solved); + $this->set('tried', $tried); + } + + + /** + * Action: create. + * + * Create a new Character groups Quest Station for a Character + * groups Quest. + * + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $groupsgroupUrl URL-Title of a Character groups-group + * @param string $questUrl URL-Title of a Character groups Quest + */ + public function create($seminaryUrl, $groupsgroupUrl, $questUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl); + + // Get Character groups-group Quests + $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); + + // Get Quest types + $stationtypes = $this->Stationtypes->getStationtypes(); + foreach($stationtypes as &$stationtype) { + $stationtype['selected'] = false; + } + + // Get allowed mimetypes + $mimetypes = \nre\configs\AppConfig::$mimetypes['icons']; + + // Values + $title = ''; + $prolog = ''; + $task = ''; + $longitude = null; + $latitude = null; + $rightText = ''; + $wrongText = ''; + $fields = array('title'); + $validation = array(); + + // Create a new Station + if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create'))) + { + // Get params and validate them + $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields); + $title = $this->request->getPostParam('title'); + if($this->Charactergroupsqueststations->stationTitleExists($quest['id'], $title)) { + $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true); + } + $prolog = $this->request->getPostParam('prolog'); + $task = $this->request->getPostParam('task'); + $longitude = $this->request->getPostParam('longitude'); + $latitude = $this->request->getPostParam('latitude'); + $rightText = $this->request->getPostParam('rightText'); + $wrongText = $this->request->getPostParam('wrongText'); + + // Validate Stationtype + $stationtypeIndex = null; + foreach($stationtypes as $index => &$stationtype) + { + $stationtype['selected'] = ($stationtype['url'] == $this->request->getPostParam('stationtype')); + if($stationtype['selected']) { + $stationtypeIndex = $index; + } + } + if(is_null($stationtypeIndex)) { + throw new \nre\exceptions\ParamsNotValidException($stationtype); + } + + // Validate icon + $icon = null; + if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE) + { + $icon = $_FILES['icon']; + + // Check error + if($icon['error'] !== UPLOAD_ERR_OK) { + $validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']); + } + + // Check mimetype + $mediaMimetype = null; + $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']); + foreach($mimetypes as &$mimetype) { + if($mimetype['mimetype'] == $icon['mimetype']) { + $mediaMimetype = $mimetype; + break; + } + } + if(is_null($mediaMimetype)) { + $validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']); + } + elseif($icon['size'] > $mediaMimetype['size']) { + $validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']); + } + } + + // Create new Station + if($validation === true) + { + $stationId = $this->Charactergroupsqueststations->createStation( + $quest['id'], + $stationtypes[$stationtypeIndex]['id'], + $title, + $prolog, + $task, + $latitude, + $longitude, + $rightText, + $wrongText + ); + $station = $this->Charactergroupsqueststations->getStationById($stationId); + + // Upload icon + if(!is_null($icon)) + { + $mediaId = $this->Media->createQuestMedia( + $this->Auth->getUserId(), + $seminary['id'], + sprintf('charactergroupsqueststation-%s', $station['url']), + '', + $icon['mimetype'], + $icon['tmp_name'] + ); + if($mediaId !== false) { + $this->Charactergroupsqueststations->setPictureForStation($station['id'], $mediaId); + } + } + + // Redirect to Station page + $this->redirect( + $this->linker->link( + array( + 'station', + $seminary['url'], + $groupsgroup['url'], + $quest['url'], + $station['url'] + ), + 1 + ) + ); + } + } + + + // Set title + $this->addTitleLocalized('Create Station'); + $this->addTitle($quest['title']); + $this->addTitle($groupsgroup['name']); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('groupsgroup', $groupsgroup); + $this->set('quest', $quest); + $this->set('title', $title); + $this->set('prolog', $prolog); + $this->set('task', $task); + $this->set('longitude', $longitude); + $this->set('latitude', $latitude); + $this->set('righttext', $rightText); + $this->set('wrongtext', $wrongText); + $this->set('mimetypes', $mimetypes); + $this->set('stationtypes', $stationtypes); + $this->set('validation', $validation); + } + + + /** + * Action: edit. + * + * Edit a Station of a Character groups Quest. + * + * @throws \nre\exceptions\IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $groupsgroupUrl URL-Title of a Character groups-group + * @param string $questUrl URL-Title of a Character groups Quest + * @param string $stationUrl URL of station + */ + public function edit($seminaryUrl, $groupsgroupUrl, $questUrl, $stationUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl); + + // Get Character groups-group Quests + $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); + + // Get Station + $station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl); + + // Get Quest types + $stationtypes = $this->Stationtypes->getStationtypes(); + foreach($stationtypes as &$stationtype) { + $stationtype['selected'] = ($stationtype['id'] == $station['stationtype_id']); + } + + // Get allowed mimetypes + $mimetypes = \nre\configs\AppConfig::$mimetypes['icons']; + + // Values + $title = $station['title']; + $prolog = $station['prolog']; + $task = $station['task']; + $longitude = $station['longitude']; + $latitude = $station['latitude']; + $rightText = $station['righttext']; + $wrongText = $station['wrongtext']; + $fields = array('title'); + $validation = array(); + + // Check request method + if($this->request->getRequestMethod() == 'POST' && (!is_null($this->request->getPostParam('edit')) || !is_null($this->request->getPostParam('edit-task')))) + { + // Get params and validate them + $validation = $this->Validation->validateParams($this->request->getPostParams(), $fields); + $title = $this->request->getPostParam('title'); + if($this->Charactergroupsqueststations->stationTitleExists($quest['id'], $title, $station['id'])) { + $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true); + } + $prolog = $this->request->getPostParam('prolog'); + $task = $this->request->getPostParam('task'); + $longitude = $this->request->getPostParam('longitude'); + $latitude = $this->request->getPostParam('latitude'); + $rightText = $this->request->getPostParam('rightText'); + $wrongText = $this->request->getPostParam('wrongText'); + + // Validate Stationtype + $stationtypeIndex = null; + foreach($stationtypes as $index => &$stationtype) + { + $stationtype['selected'] = ($stationtype['url'] == $this->request->getPostParam('stationtype')); + if($stationtype['selected']) { + $stationtypeIndex = $index; + } + } + if(is_null($stationtypeIndex)) { + throw new \nre\exceptions\ParamsNotValidException($stationtype); + } + + // Validate icon + $icon = null; + if(!empty($_FILES) && array_key_exists('icon', $_FILES) && $_FILES['icon']['error'] != UPLOAD_ERR_NO_FILE) + { + $icon = $_FILES['icon']; + + // Check error + if($icon['error'] !== UPLOAD_ERR_OK) { + $validation = $this->Validation->addValidationResult($validation, 'icon', 'error', $icon['error']); + } + + // Check mimetype + $mediaMimetype = null; + $icon['mimetype'] = \hhu\z\Utils::getMimetype($icon['tmp_name'], $icon['type']); + foreach($mimetypes as &$mimetype) { + if($mimetype['mimetype'] == $icon['mimetype']) { + $mediaMimetype = $mimetype; + break; + } + } + if(is_null($mediaMimetype)) { + $validation = $this->Validation->addValidationResult($validation, 'icon', 'mimetype', $icon['mimetype']); + } + elseif($icon['size'] > $mediaMimetype['size']) { + $validation = $this->Validation->addValidationResult($validation, 'icon', 'size', $mediaMimetype['size']); + } + } + + // Edit Station + if($validation === true) + { + $this->Charactergroupsqueststations->editStation( + $station['id'], + $stationtypes[$stationtypeIndex]['id'], + $title, + $prolog, + $task, + $latitude, + $longitude, + $rightText, + $wrongText + ); + $station = $this->Charactergroupsqueststations->getStationById($station['id']); + + // Upload icon + if(!is_null($icon)) + { + $mediaId = $this->Media->createQuestMedia( + $this->Auth->getUserId(), + $seminary['id'], + sprintf('charactergroupsqueststation-%s', $station['url']), + '', + $icon['mimetype'], + $icon['tmp_name'] + ); + if($mediaId !== false) { + $this->Charactergroupsqueststations->setPictureForStation($station['id'], $mediaId); + } + } + + // Redirect + if(!is_null($this->request->getPostParam('edit-task'))) { + // To task editing + $this->redirect( + $this->linker->link( + array( + 'edittask', + $seminary['url'], + $groupsgroup['url'], + $quest['url'], + $station['url'] + ), + 1 + ) + ); + } + else { + // To Station page + $this->redirect( + $this->linker->link( + array( + 'station', + $seminary['url'], + $groupsgroup['url'], + $quest['url'], + $station['url'] + ), + 1 + ) + ); + } + } + } + + + // Set title + $this->addTitleLocalized('Edit Station'); + $this->addTitle($station['title']); + $this->addTitle($quest['title']); + $this->addTitle($groupsgroup['name']); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('groupsgroup', $groupsgroup); + $this->set('quest', $quest); + $this->set('title', $title); + $this->set('prolog', $prolog); + $this->set('task', $task); + $this->set('longitude', $longitude); + $this->set('latitude', $latitude); + $this->set('righttext', $rightText); + $this->set('wrongtext', $wrongText); + $this->set('mimetypes', $mimetypes); + $this->set('stationtypes', $stationtypes); + $this->set('validation', $validation); + } + + + /** + * TODO Action: edittask. + * + * Edit the task of a Character groups Quest Station. + * + * @throws \nre\exceptions\IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $groupsgroupUrl URL-Title of a Character groups-group + * @param string $questUrl URL-Title of a Character groups Quest + * @param string $stationUrl URL of station + */ + public function edittask($seminaryUrl, $groupsgroupUrl, $questUrl, $stationUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl); + + // Get Character groups-group Quests + $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); + + // Get Station + $station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl); + + // Render editing task + $task = null; + $stationtype = $this->Stationtypes->getStationtypeById($station['stationtype_id']); + if(!is_null($stationtype['classname'])) { + $task = $this->renderTaskEditing($stationtype['classname'], $seminary, $groupsgroup, $quest, $station); + } + + + // Set title + $this->addTitleLocalized('Edit Station task'); + $this->addTitle($station['title']); + $this->addTitle($quest['title']); + $this->addTitle($groupsgroup['name']); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('groupsgroup', $groupsgroup); + $this->set('quest', $quest); + $this->set('task', $task); + } + + + /** + * Action: delete. + * + * Delete a Station of a Character groups Quest. + * + * @throws \nre\exceptions\IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $groupsgroupUrl URL-Title of a Character groups-group + * @param string $questUrl URL-Title of a Character groups Quest + * @param string $stationUrl URL of station + */ + public function delete($seminaryUrl, $groupsgroupUrl, $questUrl, $stationUrl) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl); + + // Get Character groups-group Quests + $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); + + // Get Station + $station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl); + + // Check request method + if($this->request->getRequestMethod() == 'POST') + { + // Check confirmation + if(!is_null($this->request->getPostParam('delete'))) + { + // Delete seminary + $this->Charactergroupsqueststations->deleteStation( + $station['id'] + ); + + // Redirect to overview + $this->redirect( + $this->linker->link( + array( + 'charactergroupsquests', + 'quest', + $seminary['url'], + $groupsgroup['url'], + $quest['url'] + ), + 0, true, null, true, 'stations' + ) + ); + } + + // Redirect to entry + $this->redirect( + $this->linker->link( + array( + 'station', + $seminary['url'], + $groupsgroup['url'], + $quest['url'], + $station['url'] + ), + 1 + ) + ); + } + + + // Set title + $this->addTitleLocalized('Delete Station'); + $this->addTitle($station['title']); + $this->addTitle($quest['title']); + $this->addTitle($groupsgroup['name']); + $this->addTitle($seminary['title']); + + // Pass data to view + $this->set('seminary', $seminary); + $this->set('groupsgroup', $groupsgroup); + $this->set('quest', $quest); + $this->set('station', $station); + } + + + + + /** + * Render and handle the task of a Station. + * + * @param string $stationtypeClassname Name of the class for the Stationtype of a Station + * @param array $seminary Seminary data + * @param array $questgroup Questgroup data + * @param array $quest Quest data + * @param array $station Station data + * @param array $charactergroup Charactergroup data + * @return string Rendered output + */ + private function renderTask($stationtypeClassname, $seminary, $groupsgroup, $quest, $station, $charactergroup) + { + $task = null; + try { + // Generate request and response + $request = clone $this->request; + $response = $this->createStationtypeResponse('quest', $seminary, $groupsgroup, $quest, $station, $charactergroup); + + // Load Stationtype Agent + $stationtypeAgent = $this->loadStationtypeAgent($stationtypeClassname, $request, $response); + + // Solve Quest + if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit'))) + { + // Get user answers + $answer = $this->request->getPostParam('answer'); + + // Save answers in database + try { + // save answer + if(!is_null($charactergroup)) { + if(!$this->Charactergroupsqueststations->hasCharactergroupSolvedStation($station['id'], $charactergroup['id'])) { + $stationtypeAgent->saveAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer); + } + } + + // Match answer with correct one + $status = $stationtypeAgent->matchAnswer( + $seminary, + $groupsgroup, + $quest, + $station, + $charactergroup, + $answer + ); + if($status === true) + { + if(!is_null($charactergroup)) + { + // Mark Station as solved + $this->Charactergroupsqueststations->setStationSolved($station['id'], $charactergroup['id']); + } + + // Redirect + $this->redirect($this->linker->link(array(), 6, true, null, false, 'task')); + } + elseif($status === false) + { + if(!is_null($charactergroup)) { + // Mark Station as unsolved + $this->Charactergroupsqueststations->setStationUnsolved( + $station['id'], + $charactergroup['id'] + ); + } + + // Redirect + $this->redirect($this->linker->link(array(), 6, true, null, false, 'task')); + } + else { + // Redirect + $this->redirect($this->linker->link(array(), 6, true, null, false, 'task')); + } + } + catch(\hhu\z\exceptions\SubmissionNotValidException $e) { + $response->addParam($e); + } + } + + // Render Task + $task = $this->runStationtypeAgent($stationtypeAgent, $request, $response); + } + catch(\nre\exceptions\ViewNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\nre\exceptions\ActionNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeModelNotValidException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeModelNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeControllerNotValidException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeControllerNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeAgentNotValidException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\stationtypeAgentNotFoundException $e) { + $task = $e->getMessage(); + } + + + // Return rendered output + return $task; + } + + + /** + * Render editing of a Station task. + * + * @param string $stationtypeClassname Name of the class for the Stationtype of a Station + * @param array $seminary Seminary data + * @param array $groupsgroup Groupsgroup data + * @param array $quest Quest data + * @param array $station Station data + * @return string Rendered output + */ + private function renderTaskEditing($stationtypeClassname, $seminary, $groupsgroup, $quest, $station) + { + $task = null; + try { + // Generate request and response + $request = clone $this->request; + $response = $this->createStationtypeResponse('edittask', $seminary, $groupsgroup, $quest, $station); + + // Load Stationtype Agent + $stationtypeAgent = $this->loadStationtypeAgent($stationtypeClassname, $request, $response); + + // Render Task + $task = $this->runStationtypeAgent($stationtypeAgent, $request, $response); + } + catch(\nre\exceptions\ViewNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\nre\exceptions\ActionNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeModelNotValidException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeModelNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeControllerNotValidException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeControllerNotFoundException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\StationtypeAgentNotValidException $e) { + $task = $e->getMessage(); + } + catch(\hhu\z\exceptions\stationtypeAgentNotFoundException $e) { + $task = $e->getMessage(); + } + + + // Return rendered output + return $task; + } + + + /** + * Create a response for the Stationtype rendering. + * + * @param string $action Action to run + * @param mixed $param Additional parameters to add to the response + * @return \nre\core\Response Generated response + */ + private function createStationtypeResponse($action, $param1) + { + // Clone current response + $response = clone $this->response; + // Clear parameters + $response->clearParams(1); + + // Add Action + $response->addParams( + null, + $action + ); + + // Add additional parameters + foreach(array_slice(func_get_args(), 1) as $param) { + $response->addParam($param); + } + + + // Return response + return $response; + } + + + /** + * Load and construct the StationtypeAgent for a Stationtype. + * + * @param string $stationtypeClassname Name of the class for the Stationtype of a Station + * @param \nre\core\Request $request Request + * @param \nre\core\Response $response Response + * @return \hhu\z\agents\StationtypeAgent Stationtype Agent + */ + private function loadStationtypeAgent($stationtypeClassname, $request, $response) + { + // Load Agent + \hhu\z\agents\StationtypeAgent::load($stationtypeClassname); + + + // Construct and return Agent + return \hhu\z\agents\StationtypeAgent::factory($stationtypeClassname, $request, $response); + } + + + /** + * Run and render the Agent for a StationtypeAgent and return ist output. + * + * @param \nre\core\Agent $stationtypeAgent StationtypeAgent to run and render + * @param \nre\core\Request $request Request + * @param \nre\core\Response $response Response + * @return string Rendered output + */ + private function runStationtypeAgent($stationtypeAgent, $request, $response) + { + // Run Agent + $stationtypeAgent->run($request, $response); + + + // Render and return output + return $stationtypeAgent->render(); + } + + } + +?> diff --git a/controllers/QrController.inc b/controllers/QrController.inc new file mode 100644 index 00000000..2e391f14 --- /dev/null +++ b/controllers/QrController.inc @@ -0,0 +1,67 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\controllers; + + + /** + * Controller of the QrAgent to redirect to a page from a (short) QR-code + * link. + * + * @author Oliver Hanraths + */ + class QrController extends \hhu\z\controllers\SeminaryController + { + /** + * Required models + * + * @var array + */ + public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations'); + + + + + /** + * Action: cgqs. + * + * Redirect to a Character groups Quest Station. + * + * @param int $stationId ID of Character groups Quest Station + */ + public function cgqs($stationId) + { + // Get station + $station = $this->Charactergroupsqueststations->getStationById($stationId); + + // Get Character groups Quests + $quest = $this->Charactergroupsquests->getQuestById($station['charactergroupsquest_id']); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupById($quest['charactergroupsgroup_id']); + + // Get seminary + $seminary = $this->Seminaries->getSeminaryById($groupsgroup['seminary_id']); + + // Redirect + $this->redirect($this->linker->link(array( + 'charactergroupsqueststations', + 'station', + $seminary['url'], + $groupsgroup['url'], + $quest['url'], + $station['url'] + ))); + } + + } + +?> diff --git a/controllers/QrcodesController.inc b/controllers/QrcodesController.inc new file mode 100644 index 00000000..93ab03e5 --- /dev/null +++ b/controllers/QrcodesController.inc @@ -0,0 +1,269 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\controllers; + + + /** + * Controller of the QrcodeAgent to generate and show QR-codes. + * + * @author Oliver Hanraths + */ + class QrcodesController extends \hhu\z\controllers\SeminaryController + { + /** + * Required models + * + * @var array + */ + public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations'); + + + + + /** + * Prefilter. + * + * @param \nre\core\Request $request Current request + * @param \nre\core\Response $response Current response + */ + public function preFilter(\nre\core\Request $request, \nre\core\Response $response) + { + parent::preFilter($request, $response); + + // Set headers for caching control + $response->addHeader("Pragma: public"); + $response->addHeader("Cache-control: must-revalidate"); + $response->addHeader("Date: ".gmdate(\DateTime::RFC822)); + } + + + /** + * Action: charactergroupsqueststation + * + * Display a QR-code for a Character groups Quest station. + * + * @throws \nre\exceptions\IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $groupsgroupUrl URL-Title of a Character groups-group + * @param string $questUrl URL-Title of a Character groups Quest + * @param string $stationUrl URL of Character groups Quest station + */ + public function charactergroupsqueststation($seminaryUrl, $groupsgroupUrl, $questUrl, $stationUrl, $size=1) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character groups-group + $groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl); + + // Get Character groups Quests + $quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl); + + // Get station + $station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl); + + // Generate QR-code + $url = $this->linker->link(array('qr', 'cgqs', $station['id']), 0, true, null, true, null, true); + $file = $this->generateQRcode($url, $size); + if(is_null($file)) { + return; + } + + + // Pass data to view + $this->set('file', $file); + } + + + + + /** + * Determine file information and set the HTTP-header for + * caching accordingly. + * + * @param string $fileName Filename + * @return boolean HTTP-status 304 was set (in cache) + */ + private function setCacheHeaders($fileName) + { + // Determine last change of file + $fileLastModified = gmdate('r', filemtime($fileName)); + + // Generate E-Tag + $fileEtag = hash('sha256', $fileLastModified.$fileName); + + + // Set header + $this->response->addHeader("Last-Modified: ".$fileLastModified); + $this->response->addHeader("Etag: ".$fileEtag); + // HTTP-status + $headerModifiedSince = $this->request->getServerParam('HTTP_IF_MODIFIED_SINCE'); + $headerNoneMatch = $this->request->getServerParam('HTTP_IF_NONE_MATCH'); + if( + !is_null($headerModifiedSince) && strtotime($fileLastModified) <= strtotime($headerModifiedSince) && + !is_null($headerNoneMatch) && $headerNoneMatch == $fileEtag + ) { + $this->response->setExit(true); + $this->response->addHeader(\nre\core\WebUtils::getHttpHeader(304)); + + return true; + } + + + return false; + } + + + private function generateQRcode($text, $size) + { + \hhu\z\lib\Phpqrcode::load(); + \QRcode::png($text, false, QR_ECLEVEL_L, intval($size), 1); + + + return null; + } + + + /** + * Determine the file for a medium and process it if necessary. + * + * @throws \nre\exceptions\IdNotFoundException + * @throws \nre\exceptions\ParamsNotValidException + * @param array $media Medium to get file for + * @param string $action Action for processing the media + * @return object File for the medium (or null if medium is cached) + */ + private function getMediaFile($media, $action=null) + { + // Get format + $format = explode('/', $media['mimetype']); + $format = $format[1]; + + // Set content-type + $this->response->addHeader("Content-type: ".$media['mimetype'].""); + + // Set filename + $media['filename'] = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$media['id']; + if(!file_exists($media['filename'])) { + throw new \nre\exceptions\IdNotFoundException($media['id'].': '.$media['url']); + } + + // Cache + if($this->setCacheHeaders($media['filename'])) { + return null; + } + + // Load and process file + $file = null; + if(is_null($action) || !in_array(strtoupper($format), self::getImageTypes())) + { + // Do not process the file + $file = file_get_contents($media['filename']); + } + else + { + // Process file + switch($action) + { + case 'questgroup': + case 'quest': + case 'avatar': + case 'charactergroup': + case 'charactergroupsquest': + $file = self::resizeImage( + $media['filename'], + $format, + \nre\configs\AppConfig::$media[$action]['width'], + \nre\configs\AppConfig::$media[$action]['height'] + ); + break; + default: + throw new ParamsNotValidException($action); + break; + } + } + + + // Return file + return $file; + } + + + /** + * Get supported image types. + * + * @return array List of supported image types + */ + private static function getImageTypes() + { + $im = new \Imagick(); + + + return $im->queryFormats(); + } + + + /** + * Resize an image. + * + * @param string $fileName Absolute pathname of image to resize + * @param string $mimeType Mimetype of target image + * @param int $width Max. width to resize to + * @param int $height Max. height to resize to + * @return mixed Resized image + */ + private static function resizeImage($fileName, $mimeType, $width, $height) + { + // Read image from cache + $tempFileName = ROOT.DS.\nre\configs\AppConfig::$dirs['temporary'].DS.'media-'.basename($fileName).'-'.$width.'x'.$height; + if(file_exists($tempFileName)) + { + // Check age of file + if(filemtime($fileName) > filemtime($tempFileName)) { + // Too old, delete + unlink($tempFileName); + } + else { + // Valid, read and return + return file_get_contents($tempFileName); + } + } + + + // ImageMagick + $im = new \Imagick($fileName); + + // Calculate new size + $geometry = $im->getImageGeometry(); + if($geometry['width'] < $width) { + $width = $geometry['width']; + } + if($geometry['height'] < $height) { + $height = $geometry['width']; + } + + // Process + $im->thumbnailImage($width, $height, true); + $im->contrastImage(1); + $im->setImageFormat($mimeType); + + // Save temporary file + $im->writeImage($tempFileName); + + + // Return resized image + return $im; + } + + } + +?> diff --git a/db/create.sql b/db/create.sql index a1fe59a8..cb2f4b87 100644 --- a/db/create.sql +++ b/db/create.sql @@ -1,8 +1,8 @@ --- MySQL dump 10.15 Distrib 10.0.22-MariaDB, for Linux (x86_64) +-- MySQL dump 10.16 Distrib 10.1.10-MariaDB, for Linux (x86_64) -- -- Host: localhost Database: z -- ------------------------------------------------------ --- Server version 10.0.22-MariaDB-log +-- Server version 10.1.10-MariaDB-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -568,6 +568,61 @@ CREATE TABLE `charactergroupsquests_seminaryuploads` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `charactergroupsqueststations` +-- + +DROP TABLE IF EXISTS `charactergroupsqueststations`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `charactergroupsqueststations` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `charactergroupsquest_id` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `stationtype_id` int(11) NOT NULL, + `title` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `url` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `pos` int(10) unsigned NOT NULL, + `stationpicture_id` int(11) DEFAULT NULL, + `prolog` text COLLATE utf8mb4_unicode_ci NOT NULL, + `task` text COLLATE utf8mb4_unicode_ci NOT NULL, + `latitude` decimal(10,6) DEFAULT NULL, + `longitude` decimal(10,6) DEFAULT NULL, + `righttext` text COLLATE utf8mb4_unicode_ci NOT NULL, + `wrongtext` text COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `charactergroupsquest_id_2` (`charactergroupsquest_id`,`url`), + UNIQUE KEY `charactergroupsquest_id_3` (`charactergroupsquest_id`,`pos`), + KEY `charactergroupsquest_id` (`charactergroupsquest_id`), + KEY `charactergroupsqueststationtype_id` (`stationtype_id`), + KEY `stationpicture_id` (`stationpicture_id`) USING BTREE, + CONSTRAINT `charactergroupsqueststations_ibfk_1` FOREIGN KEY (`charactergroupsquest_id`) REFERENCES `charactergroupsquests` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `charactergroupsqueststations_ibfk_2` FOREIGN KEY (`stationpicture_id`) REFERENCES `seminarymedia` (`id`) ON DELETE SET NULL ON UPDATE SET NULL, + CONSTRAINT `charactergroupsqueststations_ibfk_3` FOREIGN KEY (`stationtype_id`) REFERENCES `stationtypes` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `charactergroupsqueststations_charactergroups` +-- + +DROP TABLE IF EXISTS `charactergroupsqueststations_charactergroups`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `charactergroupsqueststations_charactergroups` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `charactergroupsqueststation_id` int(11) NOT NULL, + `charactergroup_id` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `status` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `charactergroupsqueststation_id` (`charactergroupsqueststation_id`), + KEY `charactergroup_id` (`charactergroup_id`), + CONSTRAINT `charactergroupsqueststations_charactergroups_ibfk_1` FOREIGN KEY (`charactergroupsqueststation_id`) REFERENCES `charactergroupsqueststations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `charactergroupsqueststations_charactergroups_ibfk_2` FOREIGN KEY (`charactergroup_id`) REFERENCES `charactergroups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `characterroles` -- @@ -1915,6 +1970,105 @@ CREATE TABLE `seminaryuploads` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `stationtypes` +-- + +DROP TABLE IF EXISTS `stationtypes`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `stationtypes` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `title` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `url` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, + `classname` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `title` (`title`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `stationtypes_keyword` +-- + +DROP TABLE IF EXISTS `stationtypes_keyword`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `stationtypes_keyword` ( + `station_id` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `created_user_id` int(11) NOT NULL, + `keyword_regex` varchar(256) COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`station_id`), + KEY `created_user_id` (`created_user_id`), + CONSTRAINT `stationtypes_keyword_ibfk_1` FOREIGN KEY (`station_id`) REFERENCES `charactergroupsqueststations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `stationtypes_keyword_ibfk_2` FOREIGN KEY (`created_user_id`) REFERENCES `users` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `stationtypes_keyword_charactergroups` +-- + +DROP TABLE IF EXISTS `stationtypes_keyword_charactergroups`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `stationtypes_keyword_charactergroups` ( + `station_id` int(11) NOT NULL, + `charactergroup_id` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `keyword` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`station_id`,`charactergroup_id`), + KEY `charactergroup_id` (`charactergroup_id`), + CONSTRAINT `stationtypes_keyword_charactergroups_ibfk_1` FOREIGN KEY (`station_id`) REFERENCES `charactergroupsqueststations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `stationtypes_keyword_charactergroups_ibfk_2` FOREIGN KEY (`charactergroup_id`) REFERENCES `charactergroups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `stationtypes_multiplechoice` +-- + +DROP TABLE IF EXISTS `stationtypes_multiplechoice`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `stationtypes_multiplechoice` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `created_user_id` int(11) NOT NULL, + `station_id` int(11) NOT NULL, + `pos` int(11) NOT NULL, + `answer` text COLLATE utf8mb4_unicode_ci NOT NULL, + `tick` tinyint(1) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `questtypes_multiplechoice_id_2` (`station_id`,`pos`), + KEY `created_user_id` (`created_user_id`), + KEY `questtypes_multiplechoice_id` (`station_id`), + CONSTRAINT `stationtypes_multiplechoice_ibfk_1` FOREIGN KEY (`created_user_id`) REFERENCES `users` (`id`), + CONSTRAINT `stationtypes_multiplechoice_ibfk_2` FOREIGN KEY (`station_id`) REFERENCES `charactergroupsqueststations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `stationtypes_multiplechoice_charactergroups` +-- + +DROP TABLE IF EXISTS `stationtypes_multiplechoice_charactergroups`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `stationtypes_multiplechoice_charactergroups` ( + `stationtypes_multiplechoice_id` int(11) NOT NULL, + `charactergroup_id` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `ticked` tinyint(1) NOT NULL, + PRIMARY KEY (`stationtypes_multiplechoice_id`,`charactergroup_id`), + KEY `character_id` (`charactergroup_id`), + CONSTRAINT `stationtypes_multiplechoice_charactergroups_ibfk_1` FOREIGN KEY (`stationtypes_multiplechoice_id`) REFERENCES `stationtypes_multiplechoice` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `stationtypes_multiplechoice_charactergroups_ibfk_2` FOREIGN KEY (`charactergroup_id`) REFERENCES `charactergroups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `userroles` -- @@ -2317,4 +2471,4 @@ DELIMITER ; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2015-10-30 22:27:53 +-- Dump completed on 2016-01-15 13:19:51 diff --git a/db/import.sql b/db/import.sql index da3199f6..24c2c902 100644 --- a/db/import.sql +++ b/db/import.sql @@ -1,13 +1,13 @@ --- MySQL dump 10.15 Distrib 10.0.17-MariaDB, for Linux (x86_64) +-- MySQL dump 10.16 Distrib 10.1.9-MariaDB, for Linux (x86_64) -- --- Host: localhost Database: z_default +-- Host: localhost Database: z -- ------------------------------------------------------ --- Server version 10.0.17-MariaDB-log +-- Server version 10.1.9-MariaDB-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; +/*!40101 SET NAMES utf8mb4 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; @@ -20,7 +20,7 @@ LOCK TABLES `achievementconditions` WRITE; /*!40000 ALTER TABLE `achievementconditions` DISABLE KEYS */; -INSERT INTO `achievementconditions` VALUES (1,'2014-04-16 19:36:54','date'),(2,'2014-04-16 19:36:54','character'),(3,'2014-04-16 19:36:59','quest'),(4,'2014-04-16 19:36:59','achievement'); +INSERT INTO `achievementconditions` (`id`, `created`, `condition`) VALUES (1,'2014-04-16 19:36:54','date'),(2,'2014-04-16 19:36:54','character'),(3,'2014-04-16 19:36:59','quest'),(4,'2014-04-16 19:36:59','achievement'); /*!40000 ALTER TABLE `achievementconditions` ENABLE KEYS */; UNLOCK TABLES; @@ -177,13 +177,31 @@ LOCK TABLES `charactergroupsquests_seminaryuploads` WRITE; /*!40000 ALTER TABLE `charactergroupsquests_seminaryuploads` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Dumping data for table `charactergroupsqueststations` +-- + +LOCK TABLES `charactergroupsqueststations` WRITE; +/*!40000 ALTER TABLE `charactergroupsqueststations` DISABLE KEYS */; +/*!40000 ALTER TABLE `charactergroupsqueststations` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `charactergroupsqueststations_charactergroups` +-- + +LOCK TABLES `charactergroupsqueststations_charactergroups` WRITE; +/*!40000 ALTER TABLE `charactergroupsqueststations_charactergroups` DISABLE KEYS */; +/*!40000 ALTER TABLE `charactergroupsqueststations_charactergroups` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Dumping data for table `characterroles` -- LOCK TABLES `characterroles` WRITE; /*!40000 ALTER TABLE `characterroles` DISABLE KEYS */; -INSERT INTO `characterroles` VALUES (1,'2014-04-16 14:42:54','admin'),(2,'2014-04-16 14:42:54','moderator'),(3,'2014-04-16 14:43:00','user'),(4,'2014-04-16 14:43:00','guest'); +INSERT INTO `characterroles` (`id`, `created`, `name`) VALUES (1,'2014-04-16 14:42:54','admin'),(2,'2014-04-16 14:42:54','moderator'),(3,'2014-04-16 14:43:00','user'),(4,'2014-04-16 14:43:00','guest'); /*!40000 ALTER TABLE `characterroles` ENABLE KEYS */; UNLOCK TABLES; @@ -250,6 +268,15 @@ LOCK TABLES `media` WRITE; /*!40000 ALTER TABLE `media` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Dumping data for table `pages` +-- + +LOCK TABLES `pages` WRITE; +/*!40000 ALTER TABLE `pages` DISABLE KEYS */; +/*!40000 ALTER TABLE `pages` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Dumping data for table `questgroups` -- @@ -382,7 +409,7 @@ UNLOCK TABLES; LOCK TABLES `questtexttypes` WRITE; /*!40000 ALTER TABLE `questtexttypes` DISABLE KEYS */; -INSERT INTO `questtexttypes` VALUES (1,'2014-04-17 09:24:21','Prolog','Prolog'),(2,'2014-04-17 09:24:21','Hint','Hint'),(3,'2014-04-17 09:24:27','Epilog','Epilog'); +INSERT INTO `questtexttypes` (`id`, `created`, `type`, `url`) VALUES (1,'2014-04-17 09:24:21','Prolog','Prolog'),(2,'2014-04-17 09:24:21','Hint','Hint'),(3,'2014-04-17 09:24:27','Epilog','Epilog'); /*!40000 ALTER TABLE `questtexttypes` ENABLE KEYS */; UNLOCK TABLES; @@ -401,7 +428,7 @@ UNLOCK TABLES; LOCK TABLES `questtypes` WRITE; /*!40000 ALTER TABLE `questtypes` DISABLE KEYS */; -INSERT INTO `questtypes` VALUES (1,'2014-04-16 18:44:44','Empty','Empty',NULL),(2,'2014-04-16 18:44:44','Boss Fight','Boss-Fight','bossfight'),(3,'2014-04-16 18:45:19','Choice Input','Choice-Input','choiceinput'),(4,'2014-04-16 18:46:02','Crossword','Crossword','crossword'),(5,'2014-04-16 18:46:02','Drag&Drop','Drag&Drop','dragndrop'),(6,'2014-04-16 18:46:23','Multiple Choice','Multiple-Choice','multiplechoice'),(7,'2014-04-16 18:46:23','Submit','Submit','submit'),(8,'2014-04-16 18:46:43','Text Input','Text-Input','textinput'); +INSERT INTO `questtypes` (`id`, `created`, `title`, `url`, `classname`) VALUES (1,'2014-04-16 18:44:44','Empty','Empty',NULL),(2,'2014-04-16 18:44:44','Boss Fight','Boss-Fight','bossfight'),(3,'2014-04-16 18:45:19','Choice Input','Choice-Input','choiceinput'),(4,'2014-04-16 18:46:02','Crossword','Crossword','crossword'),(5,'2014-04-16 18:46:02','Drag&Drop','Drag&Drop','dragndrop'),(6,'2014-04-16 18:46:23','Multiple Choice','Multiple-Choice','multiplechoice'),(7,'2014-04-16 18:46:23','Submit','Submit','submit'),(8,'2014-04-16 18:46:43','Text Input','Text-Input','textinput'); /*!40000 ALTER TABLE `questtypes` ENABLE KEYS */; UNLOCK TABLES; @@ -645,7 +672,7 @@ UNLOCK TABLES; LOCK TABLES `seminarycharacterfieldtypes` WRITE; /*!40000 ALTER TABLE `seminarycharacterfieldtypes` DISABLE KEYS */; -INSERT INTO `seminarycharacterfieldtypes` VALUES (1,'2014-04-16 18:50:16','Number','Number'),(2,'2014-04-16 18:50:16','Varchar','Varchar'),(3,'2014-04-16 18:50:24','Text','Text'),(4,'2014-04-16 18:50:24','List','List'); +INSERT INTO `seminarycharacterfieldtypes` (`id`, `created`, `title`, `url`) VALUES (1,'2014-04-16 18:50:16','Number','Number'),(2,'2014-04-16 18:50:16','Varchar','Varchar'),(3,'2014-04-16 18:50:24','Text','Text'),(4,'2014-04-16 18:50:24','List','List'); /*!40000 ALTER TABLE `seminarycharacterfieldtypes` ENABLE KEYS */; UNLOCK TABLES; @@ -667,13 +694,59 @@ LOCK TABLES `seminaryuploads` WRITE; /*!40000 ALTER TABLE `seminaryuploads` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Dumping data for table `stationtypes` +-- + +LOCK TABLES `stationtypes` WRITE; +/*!40000 ALTER TABLE `stationtypes` DISABLE KEYS */; +INSERT INTO `stationtypes` (`id`, `created`, `title`, `url`, `classname`) VALUES (1,'2015-12-25 15:50:52','Empty','Empty',NULL),(2,'2015-12-25 15:50:52','Keyword','Keyword','keyword'),(3,'2015-12-25 15:51:16','Multiple Choice','Multiple-Choice','multiplechoice'); +/*!40000 ALTER TABLE `stationtypes` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `stationtypes_keyword` +-- + +LOCK TABLES `stationtypes_keyword` WRITE; +/*!40000 ALTER TABLE `stationtypes_keyword` DISABLE KEYS */; +/*!40000 ALTER TABLE `stationtypes_keyword` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `stationtypes_keyword_charactergroups` +-- + +LOCK TABLES `stationtypes_keyword_charactergroups` WRITE; +/*!40000 ALTER TABLE `stationtypes_keyword_charactergroups` DISABLE KEYS */; +/*!40000 ALTER TABLE `stationtypes_keyword_charactergroups` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `stationtypes_multiplechoice` +-- + +LOCK TABLES `stationtypes_multiplechoice` WRITE; +/*!40000 ALTER TABLE `stationtypes_multiplechoice` DISABLE KEYS */; +/*!40000 ALTER TABLE `stationtypes_multiplechoice` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping data for table `stationtypes_multiplechoice_charactergroups` +-- + +LOCK TABLES `stationtypes_multiplechoice_charactergroups` WRITE; +/*!40000 ALTER TABLE `stationtypes_multiplechoice_charactergroups` DISABLE KEYS */; +/*!40000 ALTER TABLE `stationtypes_multiplechoice_charactergroups` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Dumping data for table `userroles` -- LOCK TABLES `userroles` WRITE; /*!40000 ALTER TABLE `userroles` DISABLE KEYS */; -INSERT INTO `userroles` VALUES (1,'2014-04-16 14:42:54','admin'),(2,'2014-04-16 14:42:54','moderator'),(3,'2014-04-16 14:43:00','user'),(4,'2014-04-16 14:43:00','guest'); +INSERT INTO `userroles` (`id`, `created`, `name`) VALUES (1,'2014-04-16 14:42:54','admin'),(2,'2014-04-16 14:42:54','moderator'),(3,'2014-04-16 14:43:00','user'),(4,'2014-04-16 14:43:00','guest'); /*!40000 ALTER TABLE `userroles` ENABLE KEYS */; UNLOCK TABLES; @@ -683,7 +756,7 @@ UNLOCK TABLES; LOCK TABLES `users` WRITE; /*!40000 ALTER TABLE `users` DISABLE KEYS */; -INSERT INTO `users` VALUES (1,'2015-04-26 11:24:04','admin','admin','Admin','Admin','','$2y$10$1zCozXcIGak552mkv/K3vOPddrisvPlokJvUjHtHj6VBBRcmznXCG',1); +INSERT INTO `users` (`id`, `created`, `username`, `url`, `surname`, `prename`, `email`, `password`, `mailing`) VALUES (1,'2015-04-26 11:24:04','admin','admin','Admin','Admin','','$2y$10$1zCozXcIGak552mkv/K3vOPddrisvPlokJvUjHtHj6VBBRcmznXCG',1); /*!40000 ALTER TABLE `users` ENABLE KEYS */; UNLOCK TABLES; @@ -693,7 +766,7 @@ UNLOCK TABLES; LOCK TABLES `users_userroles` WRITE; /*!40000 ALTER TABLE `users_userroles` DISABLE KEYS */; -INSERT INTO `users_userroles` VALUES (1,1,'2015-04-26 11:33:36'); +INSERT INTO `users_userroles` (`user_id`, `userrole_id`, `created`) VALUES (1,1,'2015-04-26 11:33:36'); /*!40000 ALTER TABLE `users_userroles` ENABLE KEYS */; UNLOCK TABLES; @@ -714,4 +787,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2015-04-26 13:34:20 +-- Dump completed on 2015-12-25 16:51:58 diff --git a/models/CharactergroupsModel.inc b/models/CharactergroupsModel.inc index 1b36324a..5c237c74 100644 --- a/models/CharactergroupsModel.inc +++ b/models/CharactergroupsModel.inc @@ -95,7 +95,7 @@ public function getGroupsgroupById($groupsgroupId) { $data = $this->db->query( - 'SELECT id, name, url, preferred '. + 'SELECT id, seminary_id, name, url, preferred '. 'FROM charactergroupsgroups '. 'WHERE id = ?', 'i', @@ -400,6 +400,28 @@ } + /** + * Get Character groups that have entered a Character groups Quest + * station. + * + * @param int $stationId ID of station + * @return array List of groups + */ + public function getGroupsForQueststation($stationId) + { + return $this->db->query( + 'SELECT charactergroups.id, charactergroups.name, charactergroups.url, charactergroupsqueststations_charactergroups.created '. + 'FROM charactergroupsqueststations_charactergroups '. + 'INNER JOIN charactergroups ON charactergroups.id = charactergroupsqueststations_charactergroups.charactergroup_id '. + 'WHERE charactergroupsqueststations_charactergroups.charactergroupsqueststation_id = ? AND status = ? '. + 'ORDER BY charactergroupsqueststations_charactergroups.created ASC', + 'ii', + $stationId, + CharactergroupsqueststationsModel::STATUS_ENTERED + ); + } + + /** * Check if a Character group name already exists. * diff --git a/models/CharactergroupsquestsModel.inc b/models/CharactergroupsquestsModel.inc index 61de9715..7b21674f 100644 --- a/models/CharactergroupsquestsModel.inc +++ b/models/CharactergroupsquestsModel.inc @@ -97,7 +97,7 @@ public function getQuestById($questId) { $data = $this->db->query( - 'SELECT id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '. + 'SELECT id, charactergroupsgroup_id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id '. 'FROM charactergroupsquests '. 'WHERE id = ?', 'i', diff --git a/models/CharactergroupsqueststationsModel.inc b/models/CharactergroupsqueststationsModel.inc new file mode 100644 index 00000000..9169b5b0 --- /dev/null +++ b/models/CharactergroupsqueststationsModel.inc @@ -0,0 +1,415 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\models; + + + /** + * Model of the CharactergroupsqueststationsAgent to interact with + * Charactergroupsqueststations-table. + * + * @author Oliver Hanraths + */ + class CharactergroupsqueststationsModel extends \hhu\z\Model + { + /** + * Status: Entered + * + * @var int; + */ + const STATUS_ENTERED = 0; + /** + * Status: Unsolved + * + * @var int; + */ + const STATUS_UNSOLVED = 2; + /** + * Status: Solved + * + * @var int; + */ + const STATUS_SOLVED = 3; + + + + + /** + * Construct a new CharactergroupsqueststationsModel. + */ + public function __construct() + { + parent::__construct(); + } + + + + + /** + * Get a Station by its ID. + * + * @throws \nre\exceptions\IdNotFoundException + * @param int $stationId ID of Station to get + * @return array Station data + */ + public function getStationById($stationId) + { + $data = $this->db->query( + 'SELECT id, charactergroupsquest_id, stationtype_id, title, url, stationpicture_id, prolog, task, latitude, longitude, righttext, wrongtext '. + 'FROM charactergroupsqueststations '. + 'WHERE id = ?', + 'i', + $stationId + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException($stationId); + } + + + return $data[0]; + } + + + /** + * Get a Station by its ID. + * + * @throws \nre\exceptions\IdNotFoundException + * @param int $stationId ID of Station to get + * @return array Station data + */ + public function getStationByUrl($groupsquestId, $stationUrl) + { + $data = $this->db->query( + 'SELECT id, charactergroupsquest_id, stationtype_id, title, url, stationpicture_id, prolog, task, latitude, longitude, righttext, wrongtext '. + 'FROM charactergroupsqueststations '. + 'WHERE charactergroupsquest_id = ? AND url = ?', + 'is', + $groupsquestId, + $stationUrl + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException($stationUrl); + } + + + return $data[0]; + } + + /** + * Get all Stations for a Character groups Quest. + * + * @param int $questId ID of the Character groups Quest + * @return array List of Stations + */ + public function getStationsForQuest($questId) + { + return $this->db->query( + 'SELECT id, title, url, stationpicture_id, latitude, longitude '. + 'FROM charactergroupsqueststations '. + 'WHERE charactergroupsquest_id = ? '. + 'ORDER BY pos ASC', + 'i', + $questId + ); + } + + + /** + * Get all Stations for a Character groups Quest and a Character group. + * + * @param int $questId ID of Character groups Quest + * @param int $groupId ID of Character group + * @return array List of Station + */ + public function getStationsForQuestAndGroup($questId, $groupId) + { + return $this->db->query( + 'SELECT charactergroupsqueststations.id, charactergroupsqueststations_charactergroups.created, title, url, stationpicture_id, latitude, longitude '. + 'FROM charactergroupsqueststations_charactergroups '. + 'INNER JOIN charactergroupsqueststations ON charactergroupsqueststations.id = charactergroupsqueststations_charactergroups.charactergroupsqueststation_id '. + 'WHERE '. + 'charactergroupsqueststations_charactergroups.charactergroup_id = ? AND '. + 'charactergroupsqueststations_charactergroups.status = ? AND '. + 'charactergroupsquest_id = ? '. + 'ORDER BY charactergroupsqueststations_charactergroups.created ASC', + 'iii', + $groupId, + self::STATUS_ENTERED, + $questId + ); + } + + + /** + * Mark a Station as entered for a Character group. + * + * @param int $stationId ID of Station to mark + * @param int $groupId ID of Character group + */ + public function setStationEntered($stationId, $groupId) + { + $this->setStatus($stationId, $groupId, self::STATUS_ENTERED); + } + + + /** + * Mark a Station as solved for a Character group. + * + * @param int $stationId ID of Station to mark + * @param int $groupId ID of Character group + */ + public function setStationSolved($stationId, $groupId) + { + $this->setStatus($stationId, $groupId, self::STATUS_SOLVED); + } + + + /** + * Mark a Station as unsolved for a Character group. + * + * @param int $stationId ID of Station to mark + * @param int $groupId ID of Character group + */ + public function setStationUnsolved($stationId, $groupId) + { + $this->setStatus($stationId, $groupId, self::STATUS_UNSOLVED); + } + + + /** + * Check if a Character group has tried to solve a Station. + * + * @param int $stationId ID of Station to check + * @param int $groupId ID of Character group to check + * @return bool Whether the group has tried the station or not + */ + public function hasCharactergroupTriedStation($stationId, $groupId) + { + $data = $this->db->query( + 'SELECT created '. + 'FROM charactergroupsqueststations_charactergroups '. + 'WHERE charactergroupsqueststation_id = ? AND charactergroup_id = ? AND (status = ? OR status = ?)', + 'iiii', + $stationId, + $groupId, + self::STATUS_UNSOLVED, + self::STATUS_SOLVED + ); + if(!empty($data)) { + return $data[0]['created']; + } + + + return false; + } + + + /** + * Check if a Character group has solved a Station. + * + * @param int $questId ID of Quest to check + * @param int $groupId ID of Character to check + * @result boolean Whether Character has solved the Quest or not + */ + public function hasCharactergroupSolvedStation($stationId, $groupId) + { + $data = $this->db->query( + 'SELECT created '. + 'FROM charactergroupsqueststations_charactergroups '. + 'WHERE charactergroupsqueststation_id = ? AND charactergroup_id = ? AND status = ?', + 'iii', + $stationId, + $groupId, + self::STATUS_SOLVED + ); + if(!empty($data)) { + return $data[0]['created']; + } + + + return false; + } + + + /** + * Check if a Character groups Quest Station title already exists. + * + * @param int $questId ID of Character groups Quest + * @param string $title Station title to check + * @param int $stationId Do not check this ID (for editing) + * @return boolean Whether Station title exists or not + */ + public function stationTitleExists($questId, $title, $stationId=null) + { + $data = $this->db->query( + 'SELECT id '. + 'FROM charactergroupsqueststations '. + 'WHERE charactergroupsquest_id = ? AND (title = ? OR url = ?)', + 'iss', + $questId, + $title, + \nre\core\Linker::createLinkParam($title) + ); + + return (!empty($data) && (is_null($stationId) || $stationId != $data[0]['id'])); + } + + + /** + * Set the media for a Character groups Quest Station. + * + * @param int $stationId ID of Station to upload media for + * @param int $mediaId ID of Station media + */ + public function setPictureForStation($station, $mediaId) + { + $this->db->query( + 'UPDATE charactergroupsqueststations '. + 'SET stationpicture_id = ? '. + 'WHERE id = ?', + 'ii', + $mediaId, + $station + ); + } + + + /** + * Create a new Character groups Quest Station. + * + * @param int $questId ID of Quest to create the Station for + * @param int $stationtypeId ID of Station type + * @param string $title Title + * @param string $prolog Prolog + * @param string $task Task description + * @param int $latitude GPS latitude + * @param int $longitude GPS longitude + * @param string $righttext Text for correctly solved task + * @param string $wrongtext Text for failed task + * @return int ID of newly created station + */ + public function createStation($questId, $stationtypeId, $title, $prolog, $task, $latitude, $longitude, $righttext, $wrongtext) + { + // Get position + $pos = $this->db->query( + 'SELECT COALESCE(MAX(pos),0)+1 AS pos '. + 'FROM charactergroupsqueststations '. + 'WHERE charactergroupsquest_id = ?', + 'i', + $questId + ); + $pos = $pos[0]['pos']; + + // Create Station + $this->db->query( + 'INSERT INTO charactergroupsqueststations '. + '(charactergroupsquest_id, stationtype_id, title, url, pos, prolog, task, latitude, longitude, righttext, wrongtext) '. + 'VALUES '. + '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', + 'iississddss', + $questId, $stationtypeId, $title, + \nre\core\Linker::createLinkParam($title), $pos, + $prolog, $task, $latitude, $longitude, $righttext, $wrongtext + ); + + + // Return ID of newly created Station + return $this->db->getInsertId(); + } + + + /** + * Edit a Character groups Quest Station. + * + * @param int $stationId ID of Station to edit + * @param int $stationtypeId ID of Station type + * @param string $title Title + * @param string $prolog Prolog + * @param string $task Task description + * @param int $latitude GPS latitude + * @param int $longitude GPS longitude + * @param string $righttext Text for correctly solved task + * @param string $wrongtext Text for failed task + */ + public function editStation($stationId, $stationtypeId, $title, $prolog, $task, $latitude, $longitude, $righttext, $wrongtext) + { + $this->db->query( + 'UPDATE charactergroupsqueststations '. + 'SET stationtype_id = ?, title = ?, url = ?, prolog = ?, task = ?, latitude = ?, longitude = ?, righttext = ?, wrongtext = ? '. + 'WHERE id = ?', + 'issssddssi', + $stationtypeId, $title, + \nre\core\Linker::createLinkParam($title), + $prolog, $task, $latitude, $longitude, $righttext, $wrongtext, + $stationId + ); + } + + + /** + * Delete a Character-group Quest station. + * + * @param int $stationId ID of Station to delete + */ + public function deleteStation($stationId) + { + $this->db->query( + 'DELETE FROM charactergroupsqueststations '. + 'WHERE ID = ?', + 'i', + $stationId + ); + } + + + + + + /** + * Mark a Station for a Character group. + * + * @param int $stationId ID of Station to mark + * @param int $groupId ID of Character group + * @param int $status Status to set + */ + private function setStatus($stationId, $groupId, $status) + { + // Check if status is already set + $count = $this->db->query( + 'SELECT count(*) AS c '. + 'FROM charactergroupsqueststations_charactergroups '. + 'WHERE charactergroupsqueststation_id = ? AND charactergroup_id = ? AND status = ?', + 'iii', + $stationId, + $groupId, + $status + ); + if(!empty($count) && intval($count[0]['c']) > 0) { + // Do not set status twice + return; + } + + // Set status + $this->db->query( + 'INSERT INTO charactergroupsqueststations_charactergroups '. + '(charactergroupsqueststation_id, charactergroup_id, status) '. + 'VALUES '. + '(?, ?, ?) ', + 'iii', + $stationId, + $groupId, + $status + ); + } + + } + +?> diff --git a/models/StationtypesModel.inc b/models/StationtypesModel.inc new file mode 100644 index 00000000..e46422a2 --- /dev/null +++ b/models/StationtypesModel.inc @@ -0,0 +1,77 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\models; + + + /** + * Model to interact with stationtypes-table. + * + * @author Oliver Hanraths + */ + class StationtypesModel extends \hhu\z\Model + { + + + + + /** + * Construct a new Model. + */ + public function __construct() + { + parent::__construct(); + } + + + + + /** + * Get all registered Stationtypes. + * + * @return array List of registered Stationtypes + */ + public function getStationtypes() + { + return $this->db->query( + 'SELECT id, title, url, classname '. + 'FROM stationtypes '. + 'ORDER BY title ASC' + ); + } + + + /** + * Get a Stationtype by its ID. + * + * @param int $stationtypeId ID of Stationtype + * @return array Stationtype data + */ + public function getStationtypeById($stationtypeId) + { + $data = $this->db->query( + 'SELECT title, classname '. + 'FROM stationtypes '. + 'WHERE id = ?', + 'i', + $stationtypeId + ); + if(empty($data)) { + throw new \nre\exceptions\IdNotFoundException($stationtypeId); + } + + + return $data = $data[0]; + } + + } + +?> diff --git a/stationtypes/keyword/KeywordStationtypeAgent.inc b/stationtypes/keyword/KeywordStationtypeAgent.inc new file mode 100644 index 00000000..f96c2ea7 --- /dev/null +++ b/stationtypes/keyword/KeywordStationtypeAgent.inc @@ -0,0 +1,24 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\stationtypes; + + + /** + * StationtypeAgent for keyword access. + * + * @author Oliver Hanraths + */ + class KeywordStationtypeAgent extends \hhu\z\agents\StationtypeAgent + { + } + +?> diff --git a/stationtypes/keyword/KeywordStationtypeController.inc b/stationtypes/keyword/KeywordStationtypeController.inc new file mode 100644 index 00000000..cf219885 --- /dev/null +++ b/stationtypes/keyword/KeywordStationtypeController.inc @@ -0,0 +1,168 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\stationtypes; + + + /** + * Controller of the StationtypeAgent for keyword access. + * + * @author Oliver Hanraths + */ + class KeywordStationtypeController extends \hhu\z\controllers\StationtypeController + { + /** + * Required components + * + * @var array + */ + public $components = array('validation', 'questtypedata'); + + + + + /** + * Save the answer of a Character group for a Station. + * + * @param array $seminary Current Seminary data + * @param array $groupsgroup Current Groups group data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $charactergroup Current Character group data + * @param array $answer Character group answer for the Station + */ + public function saveAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer) + { + $this->Keyword->setCharactergroupSubmission($station['id'], $charactergroup['id'], $answer); + } + + + /** + * Check if answer of a Character group for a Station matches the correct one. + * + * @param array $seminary Current Seminary data + * @param array $groupsgroup Current Groups group data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $charactergroup Current Character group data + * @param array $answer Character group answer for the Station + * @return boolean True/false for a right/wrong answer + */ + public function matchAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer) + { + // Get right answers + $task = $this->Keyword->getKeywordTask($station['id']); + + // Match regex with user answers + return $this->isMatching($task['keyword_regex'], $answer); + } + + + /** + * Action: quest. + * + * Show the task of a Station. + * + * @param array $seminary Current Seminary data + * @param array $groupsgroup Current Groups group data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $charactergroup Current Character group data + */ + public function quest($seminary, $groupsgroup, $quest, $station, $charactergroup) + { + } + + + /** + * Action: edittask. + * + * Edit the task of a Station. + * + * @param array $seminary Current Seminary data + * @param array $groupsgroup Current Groups group data + * @param array $quest Current Quest data + * @param array $station Current Station data + */ + public function edittask($seminary, $groupsgroup, $quest, $station) + { + // Get right answers + $task = $this->Keyword->getKeywordTask($station['id']); + + // Values + $keyword = $task['keyword_regex']; + $validations = array(); + + // Save data + if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('save'))) + { + // Get params and validate them + $keyword = $this->request->getPostParam('keyword'); + + // Validate regex + $keywordValidation = @preg_match($keyword, '') !== false; + if($keywordValidation !== true) { + $validations = $this->Validation->addValidationResult($validations, 'keyword', 'regex', $keywordValidation); + } + + // Save and redirect + if(empty($validations)) + { + // Save keyword + $this->Keyword->setKeywordForStation( + $this->Auth->getUserId(), + $station['id'], + $keyword + ); + + // Redirect + $this->redirect( + $this->linker->link( + array( + 'station', + $seminary['url'], + $groupsgroup['url'], + $quest['url'], + $station['url'] + ), + 1 + ) + ); + } + } + + + // Pass data to view + $this->set('keyword', $keyword); + $this->set('validations', $validations); + } + + + + + /** + * Check if an Character answer matches a Regex. + * + * @param string $regex Regex to match against + * @param string $answer Character answer to match + * @return boolean Whether answer matches Regex or not + */ + private function isMatching($regex, $answer) + { + $score = preg_match($regex, trim($answer)); + + + return ($score !== false && $score > 0); + } + + } + +?> diff --git a/stationtypes/keyword/KeywordStationtypeModel.inc b/stationtypes/keyword/KeywordStationtypeModel.inc new file mode 100644 index 00000000..8ba39749 --- /dev/null +++ b/stationtypes/keyword/KeywordStationtypeModel.inc @@ -0,0 +1,97 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\stationtypes; + + + /** + * Model of the StationtypeAgent for keyword access. + * + * @author Oliver Hanraths + */ + class KeywordStationtypeModel extends \hhu\z\models\StationtypeModel + { + + + + + /** + * Get the task of a keyword Station + * + * @param int $stationId ID of Station + * @return array Task data + */ + public function getKeywordTask($stationId) + { + $data = $this->db->query( + 'SELECT keyword_regex '. + 'FROM stationtypes_keyword '. + 'WHERE station_id = ?', + 'i', + $stationId + ); + if(!empty($data)) { + return $data[0]; + } + + + return null; + } + + + /** + * Set the keyword (regex) for a Station. + * + * @param int $userId ID of creating user + * @param int $stationId ID ot Station to set keyword for + * @param string $keyword Keyword (regex) + */ + public function setKeywordForStation($userId, $stationId, $keyword) + { + $this->db->query( + 'INSERT INTO stationtypes_keyword '. + '(station_id, created_user_id, keyword_regex) '. + 'VALUES '. + '(?, ?, ?) '. + 'ON DUPLICATE KEY UPDATE '. + 'created_user_id = ?, keyword_regex = ?', + 'iisis', + $stationId, $userId, $keyword, + $userId, $keyword + ); + } + + + /** + * Save Character group’s submitted answer for a station. + * + * @param int $stationId ID of Station + * @param int $charactergroupId ID of Character group + * @param string $answer Submitted answer + */ + public function setCharactergroupSubmission($stationId, $charactergroupId, $answer) + { + $this->db->query( + 'INSERT INTO stationtypes_keyword_charactergroups '. + '(station_id, charactergroup_id, keyword) '. + 'VALUES '. + '(?, ?, ?) '. + 'ON DUPLICATE KEY UPDATE '. + 'keyword = ?', + 'iiss', + $stationId, $charactergroupId, $answer, $answer + ); + var_dump("saved"); + } + + } + +?> diff --git a/stationtypes/keyword/html/edittask.tpl b/stationtypes/keyword/html/edittask.tpl new file mode 100644 index 00000000..5097eb0f --- /dev/null +++ b/stationtypes/keyword/html/edittask.tpl @@ -0,0 +1,29 @@ + +
    + &$settings) : ?> +
  • +
      + $value) : ?> +
    • + +
    • + +
    +
  • + +
+ + +
+
+ + +
+ +
diff --git a/stationtypes/keyword/html/quest.tpl b/stationtypes/keyword/html/quest.tpl new file mode 100644 index 00000000..20ee3c20 --- /dev/null +++ b/stationtypes/keyword/html/quest.tpl @@ -0,0 +1,4 @@ +
+ + +
diff --git a/stationtypes/multiplechoice/MultiplechoiceStationtypeAgent.inc b/stationtypes/multiplechoice/MultiplechoiceStationtypeAgent.inc new file mode 100644 index 00000000..e2b59fa1 --- /dev/null +++ b/stationtypes/multiplechoice/MultiplechoiceStationtypeAgent.inc @@ -0,0 +1,24 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\stationtypes; + + + /** + * StationtypeAgent for a multiple choice task. + * + * @author Oliver Hanraths + */ + class MultiplechoiceStationtypeAgent extends \hhu\z\agents\StationtypeAgent + { + } + +?> diff --git a/stationtypes/multiplechoice/MultiplechoiceStationtypeController.inc b/stationtypes/multiplechoice/MultiplechoiceStationtypeController.inc new file mode 100644 index 00000000..c1f0bc75 --- /dev/null +++ b/stationtypes/multiplechoice/MultiplechoiceStationtypeController.inc @@ -0,0 +1,192 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\stationtypes; + + + /** + * Controller of the StationtypeAgent for a multiple choice task. + * + * @author Oliver Hanraths + */ + class MultiplechoiceStationtypeController extends \hhu\z\controllers\StationtypeController + { + + + + + /** + * Save the answer of a Character group for a Station. + * + * @param array $seminary Current Seminary data + * @param array $questgroup Current Questgroup data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $charactergroup Current Character group data + * @param array $answer Character group answer for the Station + */ + public function saveAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer) + { + $answers = (!is_array($answer)) ? array() : $answer; + $solutions = $this->Multiplechoice->getAnswers($station['id']); + foreach($solutions as &$solution) + { + $answer = (array_key_exists($solution['pos']-1, $answers)) ? true : false; + $this->Multiplechoice->setCharactergroupSubmission($solution['id'], $charactergroup['id'], $answer); + } + } + + + /** + * Check if answer of a Character group for a Station matches the correct one. + * + * @param array $seminary Current Seminary data + * @param array $questgroup Current Questgroup data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $charactergroup Current Character group data + * @param array $answer Character group answer for the Station + * @return boolean True/false for a right/wrong answer + */ + public function matchAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer) + { + $answers = (!is_array($answer)) ? array() : $answer; + $solutions = $this->Multiplechoice->getAnswers($station['id']); + foreach($solutions as &$solution) + { + if(is_null($solution['tick'])) { + continue; + } + if($solution['tick']) { + if(!array_key_exists($solution['pos']-1, $answers)) { + return false; + } + } + else { + if(array_key_exists($solution['pos']-1, $answers)) { + return false; + } + } + } + + + // All questions correct answerd + return true; + } + + + /** + * Action: quest. + * + * Show the task of a Station. + * + * @param array $seminary Current Seminary data + * @param array $questgroup Current Questgroup data + * @param array $quest Current Quest data + * @param array $station Current Station data + * @param array $charactergroup Current Character group data + */ + public function quest($seminary, $groupsgroup, $quest, $station, $charactergroup) + { + // Get answers + $answers = $this->Multiplechoice->getAnswers($station['id']); + + + // Pass data to view + $this->set('answers', $answers); + } + + + /** + * Action: edittask. + * + * Edit the task of a Station. + * + * @param array $seminary Current Seminary data + * @param array $groupsgroup Current Groups group data + * @param array $quest Current Quest data + * @param array $station Current Station data + */ + public function edittask($seminary, $groupsgroup, $quest, $station) + { + // Get questions + $answers = $this->Multiplechoice->getAnswers($station['id']); + + // Save data + if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('save'))) + { + // Get params + $answers = $this->request->getPostParam('answers'); + if(is_null($answers)) { + $answers = array(); + } + $answers = array_values($answers); + + // Save answers + foreach($answers as $answerIndex => &$answer) + { + $this->Multiplechoice->setAnswer( + $this->Auth->getUserId(), + $station['id'], + $answerIndex + 1, + $answer['answer'], + array_key_exists('tick', $answer) + ); + } + + // Delete deleted answers + $this->Multiplechoice->deleteAnswers( + $station['id'], + count($answers) + ); + + // Redirect + $this->redirect( + $this->linker->link( + array( + 'station', + $seminary['url'], + $groupsgroup['url'], + $quest['url'], + $station['url'] + ), + 1 + ) + ); + } + + + // Pass data to view + $this->set('task', $station['task']); + $this->set('answers', $answers); + } + + + + + /** + * Check if an Character answer matches a Regex. + * + * @param string $regex Regex to match against + * @param string $answer Character answer to match + * @return boolean Whether answer matches Regex or not + */ + private function isMatching($regex, $answer) + { + $score = preg_match($regex, trim($answer)); + + + return ($score !== false && $score > 0); + } + + } + +?> diff --git a/stationtypes/multiplechoice/MultiplechoiceStationtypeModel.inc b/stationtypes/multiplechoice/MultiplechoiceStationtypeModel.inc new file mode 100644 index 00000000..312f0070 --- /dev/null +++ b/stationtypes/multiplechoice/MultiplechoiceStationtypeModel.inc @@ -0,0 +1,117 @@ + + * @copyright 2014 Heinrich-Heine-Universität Düsseldorf + * @license http://www.gnu.org/licenses/gpl.html + * @link https://bitbucket.org/coderkun/the-legend-of-z + */ + + namespace hhu\z\stationtypes; + + + /** + * Model of the StationtypeAgent for a multiple choice task. + * + * @author Oliver Hanraths + */ + class MultiplechoiceStationtypeModel extends \hhu\z\models\StationtypeModel + { + + + + + /** + * Get all answers for a Station + * + * @param int $stationId ID of Station + * @return array List of answers + */ + public function getAnswers($stationId) + { + return $this->db->query( + 'SELECT id, pos, answer, tick '. + 'FROM stationtypes_multiplechoice '. + 'WHERE station_id = ? '. + 'ORDER BY pos', + 'i', + $stationId + ); + } + + + /** + * Set an answer for a Station. + * + * @param int $userId ID of creating user + * @param int $stationId ID of Station to set answer for + * @param int $pos Position of answer + * @param string $answer Answer text + * @param int $tick Whether the answer is correct or not + */ + public function setAnswer($userId, $stationId, $pos, $answer, $tick) + { + $this->db->query( + 'INSERT INTO stationtypes_multiplechoice '. + '(created_user_id, station_id, pos, answer, tick) '. + 'VALUES '. + '(?, ?, ?, ?, ?) '. + 'ON DUPLICATE KEY UPDATE '. + 'answer = ?, tick = ?', + 'iiisisi', + $userId, + $stationId, + $pos, + $answer, + $tick, + $answer, + $tick + ); + } + + + /** + * Delete all answers of a Station above a given index. + * + * @param int $stationId ID of Station to delete answers for + * @param int $offset Offset to delete answers above + */ + public function deleteAnswers($stationId, $offset) + { + // Delete answers + $this->db->query( + 'DELETE FROM stationtypes_multiplechoice '. + 'WHERE station_id = ? AND pos > ?', + 'ii', + $stationId, + $offset + ); + } + + + /** + * Save Character group’s submitted answer for a station. + * + * @param int $stationId ID of Station + * @param int $charactergroupId ID of Character group + * @param string $answer Submitted answer + */ + public function setCharactergroupSubmission($answerId, $charactergroupId, $answer) + { + $this->db->query( + 'INSERT INTO stationtypes_multiplechoice_charactergroups '. + '(stationtypes_multiplechoice_id, charactergroup_id, ticked) '. + 'VALUES '. + '(?, ?, ?) '. + 'ON DUPLICATE KEY UPDATE '. + 'ticked = ?', + 'iiii', + $answerId, $charactergroupId, $answer, $answer + ); + } + + } + +?> diff --git a/stationtypes/multiplechoice/html/edittask.tpl b/stationtypes/multiplechoice/html/edittask.tpl new file mode 100644 index 00000000..80317f00 --- /dev/null +++ b/stationtypes/multiplechoice/html/edittask.tpl @@ -0,0 +1,59 @@ +
+
+ + t($task)?> +
+
+ +
    + &$answer) : ?> +
  • + + + +
    +
  • + +
  • + +
  • +
+
+ +
+ + diff --git a/stationtypes/multiplechoice/html/quest.tpl b/stationtypes/multiplechoice/html/quest.tpl new file mode 100644 index 00000000..79872785 --- /dev/null +++ b/stationtypes/multiplechoice/html/quest.tpl @@ -0,0 +1,11 @@ +
+
    + &$answer) : ?> +
  1. + + +
  2. + +
+ +
diff --git a/views/ajax/charactergroupsqueststations/index.tpl b/views/ajax/charactergroupsqueststations/index.tpl new file mode 100644 index 00000000..4a15f972 --- /dev/null +++ b/views/ajax/charactergroupsqueststations/index.tpl @@ -0,0 +1,45 @@ + 'Feature', + 'id' => $station['id'], + 'properties' => array( + 'name' => $station['title'], + ), + 'geometry' => array( + 'type' => 'Point', + 'coordinates' => $coordinate + ) + ); + } + } + + // Add lines between points + if($hasgroup) { + $features[] = array( + 'type' => 'Feature', + 'name' => 'Line', + 'geometry' => array( + 'type' => 'LineString', + 'coordinates' => $coordinates + ) + ); + } + +?> + 'FeatureCollection', + 'features' => $features +))?> diff --git a/views/binary/qrcodes/charactergroupsqueststation.tpl b/views/binary/qrcodes/charactergroupsqueststation.tpl new file mode 100644 index 00000000..0d6fb0df --- /dev/null +++ b/views/binary/qrcodes/charactergroupsqueststation.tpl @@ -0,0 +1 @@ + diff --git a/views/html/charactergroupsquests/quest.tpl b/views/html/charactergroupsquests/quest.tpl index cad646bc..85f4d48d 100644 --- a/views/html/charactergroupsquests/quest.tpl +++ b/views/html/charactergroupsquests/quest.tpl @@ -39,26 +39,68 @@

-

t($quest['description'])?>

+
+

t($quest['description'])?>

+

-

t($quest['rules'])?>

+
+

t($quest['rules'])?>

+

-

t($quest['won_text'])?>

+
+

t($quest['won_text'])?>

+

-

t($quest['lost_text'])?>

+
+

t($quest['lost_text'])?>

+
+
+

+
+ + 0) : ?> + + + +
    + +
  1. + + + format(new \DateTime($station['created']))?> + format(new \DateTime($station['created']))?> + + + + + + + +
  2. + +
+ +

.

+ +
+

    @@ -71,3 +113,94 @@
+ + diff --git a/views/html/charactergroupsqueststations/create.tpl b/views/html/charactergroupsqueststations/create.tpl new file mode 100644 index 00000000..c46c3374 --- /dev/null +++ b/views/html/charactergroupsqueststations/create.tpl @@ -0,0 +1,155 @@ + + + +

+ +
    + &$settings) : ?> +
  • +
      + $value) : ?> +
    • + +
    • + +
    +
  • + +
+ +
+
+ + +

:

+
    + +
  • 0) : ?>(  MiB)
  • + +
+
+
+ +
+ + +
+
+ + +
+
+ + /> +
+
+
+
+
+
+
+
+
+ +
+ diff --git a/views/html/charactergroupsqueststations/delete.tpl b/views/html/charactergroupsqueststations/delete.tpl new file mode 100644 index 00000000..700225f6 --- /dev/null +++ b/views/html/charactergroupsqueststations/delete.tpl @@ -0,0 +1,14 @@ + + + +

+ +
+ + +
diff --git a/views/html/charactergroupsqueststations/edit.tpl b/views/html/charactergroupsqueststations/edit.tpl new file mode 100644 index 00000000..08c96a0e --- /dev/null +++ b/views/html/charactergroupsqueststations/edit.tpl @@ -0,0 +1,171 @@ + + + +

+ +
    + &$settings) : ?> +
  • +
      + $value) : ?> +
    • + +
    • + +
    +
  • + +
+ +
+
+ + +

:

+
    + +
  • 0) : ?>(  MiB)
  • + +
+
+
+ +
+ + +
+
+ + +
+
+ + /> +
+
+
+
+
+
+
+
+
+ + + + +
+ diff --git a/views/html/charactergroupsqueststations/edittask.tpl b/views/html/charactergroupsqueststations/edittask.tpl new file mode 100644 index 00000000..b2dcbae0 --- /dev/null +++ b/views/html/charactergroupsqueststations/edittask.tpl @@ -0,0 +1,12 @@ + + + +

+ + + diff --git a/views/html/charactergroupsqueststations/station.tpl b/views/html/charactergroupsqueststations/station.tpl new file mode 100644 index 00000000..80c2a5ab --- /dev/null +++ b/views/html/charactergroupsqueststations/station.tpl @@ -0,0 +1,136 @@ + + + + 0) : ?> + + + + +

+ +
    + +
  • + 0)?'N':'S', $station['longitude'], ($station['longitude']>0)?'E':'W')?> +
  • + + 0) : ?> +
  • + + + +
  • + +
+ + +
+
+ +
+ + + +
+

+
    + +
  1. + + format(new \DateTime($group['created']))?> + format(new \DateTime($group['created']))?> + + + + + + format(new \DateTime($group['solved']))))?> + + +
  2. + +
+
+ + + +
+
+

+ ', '', str_replace('

', '', $t->t($station['prolog'])))?> +

+
+
+ + + +
+

+ + +
+ t($station['righttext'])?> +
+ +
+ t($station['wrongtext'])?> +
+ +
+ t($station['task'])?> + +
+ +
+ diff --git a/views/html/html.tpl b/views/html/html.tpl index 3a6af342..652d0c1f 100644 --- a/views/html/html.tpl +++ b/views/html/html.tpl @@ -9,7 +9,7 @@ <?=(isset($title)) ? $title : \nre\configs\AppConfig::$app['name']?> - + diff --git a/views/html/qr/cgqs.tpl b/views/html/qr/cgqs.tpl new file mode 100644 index 00000000..e69de29b diff --git a/views/html/seminarymenu/index.tpl b/views/html/seminarymenu/index.tpl index aecee44b..ea24d4b3 100644 --- a/views/html/seminarymenu/index.tpl +++ b/views/html/seminarymenu/index.tpl @@ -5,6 +5,6 @@
  • -
  • +
  • diff --git a/www/css/ol.css b/www/css/ol.css index 2b52dc14..e22b6f42 100644 --- a/www/css/ol.css +++ b/www/css/ol.css @@ -1 +1 @@ -.ol-mouse-position{top:8px;right:8px;position:absolute}.ol-scale-line{background:#95b9e6;background:rgba(0,60,136,.3);border-radius:4px;bottom:8px;left:8px;padding:2px;position:absolute}.ol-scale-line-inner{border:1px solid #eee;border-top:none;color:#eee;font-size:10px;text-align:center;margin:1px;will-change:contents,width}.ol-overlay-container{will-change:left,right,top,bottom}.ol-unsupported{display:none}.ol-viewport .ol-unselectable{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent}.ol-control{position:absolute;background-color:#eee;background-color:rgba(255,255,255,.4);border-radius:4px;padding:2px}.ol-control:hover{background-color:rgba(255,255,255,.6)}.ol-zoom{top:.5em;left:.5em}.ol-rotate{top:.5em;right:.5em;transition:opacity .25s linear,visibility 0s linear}.ol-rotate.ol-hidden{opacity:0;visibility:hidden;transition:opacity .25s linear,visibility 0s linear .25s}.ol-zoom-extent{top:4.643em;left:.5em}.ol-full-screen{right:.5em;top:.5em}@media print{.ol-control{display:none}}.ol-control button{display:block;margin:1px;padding:0;color:#fff;font-size:1.14em;font-weight:700;text-decoration:none;text-align:center;height:1.375em;width:1.375em;line-height:.4em;background-color:#7b98bc;background-color:rgba(0,60,136,.5);border:none;border-radius:2px}.ol-control button::-moz-focus-inner{border:none;padding:0}.ol-zoom-extent button{line-height:1.4em}.ol-compass{display:block;font-weight:400;font-size:1.2em;will-change:transform}.ol-touch .ol-control button{font-size:1.5em}.ol-touch .ol-zoom-extent{top:5.5em}.ol-control button:focus,.ol-control button:hover{text-decoration:none;background-color:#4c6079;background-color:rgba(0,60,136,.7)}.ol-zoom .ol-zoom-in{border-radius:2px 2px 0 0}.ol-zoom .ol-zoom-out{border-radius:0 0 2px 2px}.ol-attribution{text-align:right;bottom:.5em;right:.5em;max-width:calc(100% - 1.3em)}.ol-attribution ul{margin:0;padding:0 .5em;font-size:.7rem;line-height:1.375em;color:#000;text-shadow:0 0 2px #fff}.ol-attribution li{display:inline;list-style:none;line-height:inherit}.ol-attribution li:not(:last-child):after{content:" "}.ol-attribution img{max-height:2em;max-width:inherit}.ol-attribution button,.ol-attribution ul{display:inline-block}.ol-attribution.ol-collapsed ul{display:none}.ol-attribution.ol-logo-only ul{display:block}.ol-attribution:not(.ol-collapsed){background:rgba(255,255,255,.8)}.ol-attribution.ol-uncollapsible{bottom:0;right:0;border-radius:4px 0 0;height:1.1em;line-height:1em}.ol-attribution.ol-logo-only{background:0 0;bottom:.4em;height:1.1em;line-height:1em}.ol-attribution.ol-uncollapsible img{margin-top:-.2em;max-height:1.6em}.ol-attribution.ol-logo-only button,.ol-attribution.ol-uncollapsible button{display:none}.ol-zoomslider{position:absolute;top:4.5em;left:.5em;background:#eee;background:rgba(255,255,255,.4);width:24px;height:200px}.ol-zoomslider-thumb{position:absolute;background:#7b98bc;background:rgba(0,60,136,.5);border-radius:2px;cursor:pointer;height:10px;width:22px;margin:3px}.ol-touch .ol-zoomslider{top:5.5em;width:2.052em}.ol-touch .ol-zoomslider-thumb{width:1.8em}.ol-overviewmap{position:absolute;left:.5em;bottom:.5em}.ol-overviewmap.ol-uncollapsible{bottom:0;left:0;border-radius:0 4px 0 0}.ol-overviewmap .ol-overviewmap-map,.ol-overviewmap button{display:inline-block}.ol-overviewmap .ol-overviewmap-map{border:1px solid #7b98bc;height:150px;margin:2px;width:150px}.ol-overviewmap:not(.ol-collapsed) button{bottom:1px;left:2px;position:absolute}.ol-overviewmap.ol-collapsed .ol-overviewmap-map,.ol-overviewmap.ol-uncollapsible button{display:none}.ol-overviewmap:not(.ol-collapsed){background:rgba(255,255,255,.8)}.ol-overviewmap-box{border:2px dotted rgba(0,60,136,.7)} \ No newline at end of file +.ol-control,.ol-scale-line{position:absolute;padding:2px}.ol-box{box-sizing:border-box;border-radius:2px;border:2px solid #00f}.ol-mouse-position{top:8px;right:8px;position:absolute}.ol-scale-line{background:#95b9e6;background:rgba(0,60,136,.3);border-radius:4px;bottom:8px;left:8px}.ol-scale-line-inner{border:1px solid #eee;border-top:none;color:#eee;font-size:10px;text-align:center;margin:1px;will-change:contents,width}.ol-overlay-container{will-change:left,right,top,bottom}.ol-unsupported{display:none}.ol-viewport .ol-unselectable{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent}.ol-control{background-color:#eee;background-color:rgba(255,255,255,.4);border-radius:4px}.ol-control:hover{background-color:rgba(255,255,255,.6)}.ol-zoom{top:.5em;left:.5em}.ol-rotate{top:.5em;right:.5em;transition:opacity .25s linear,visibility 0s linear}.ol-rotate.ol-hidden{opacity:0;visibility:hidden;transition:opacity .25s linear,visibility 0s linear .25s}.ol-zoom-extent{top:4.643em;left:.5em}.ol-full-screen{right:.5em;top:.5em}@media print{.ol-control{display:none}}.ol-control button{display:block;margin:1px;padding:0;color:#fff;font-size:1.14em;font-weight:700;text-decoration:none;text-align:center;height:1.375em;width:1.375em;line-height:.4em;background-color:#7b98bc;background-color:rgba(0,60,136,.5);border:none;border-radius:2px}.ol-control button::-moz-focus-inner{border:none;padding:0}.ol-zoom-extent button{line-height:1.4em}.ol-compass{display:block;font-weight:400;font-size:1.2em;will-change:transform}.ol-touch .ol-control button{font-size:1.5em}.ol-touch .ol-zoom-extent{top:5.5em}.ol-control button:focus,.ol-control button:hover{text-decoration:none;background-color:#4c6079;background-color:rgba(0,60,136,.7)}.ol-zoom .ol-zoom-in{border-radius:2px 2px 0 0}.ol-zoom .ol-zoom-out{border-radius:0 0 2px 2px}.ol-attribution{text-align:right;bottom:.5em;right:.5em;max-width:calc(100% - 1.3em)}.ol-attribution ul{margin:0;padding:0 .5em;font-size:.7rem;line-height:1.375em;color:#000;text-shadow:0 0 2px #fff}.ol-attribution li{display:inline;list-style:none;line-height:inherit}.ol-attribution li:not(:last-child):after{content:" "}.ol-attribution img{max-height:2em;max-width:inherit;vertical-align:middle}.ol-attribution button,.ol-attribution ul{display:inline-block}.ol-attribution.ol-collapsed ul{display:none}.ol-attribution.ol-logo-only ul{display:block}.ol-attribution:not(.ol-collapsed){background:rgba(255,255,255,.8)}.ol-attribution.ol-uncollapsible{bottom:0;right:0;border-radius:4px 0 0;height:1.1em;line-height:1em}.ol-attribution.ol-logo-only{background:0 0;bottom:.4em;height:1.1em;line-height:1em}.ol-attribution.ol-uncollapsible img{margin-top:-.2em;max-height:1.6em}.ol-attribution.ol-logo-only button,.ol-attribution.ol-uncollapsible button{display:none}.ol-zoomslider{top:4.5em;left:.5em;height:200px}.ol-zoomslider button{position:relative;height:10px}.ol-touch .ol-zoomslider{top:5.5em}.ol-overviewmap{left:.5em;bottom:.5em}.ol-overviewmap.ol-uncollapsible{bottom:0;left:0;border-radius:0 4px 0 0}.ol-overviewmap .ol-overviewmap-map,.ol-overviewmap button{display:inline-block}.ol-overviewmap .ol-overviewmap-map{border:1px solid #7b98bc;height:150px;margin:2px;width:150px}.ol-overviewmap:not(.ol-collapsed) button{bottom:1px;left:2px;position:absolute}.ol-overviewmap.ol-collapsed .ol-overviewmap-map,.ol-overviewmap.ol-uncollapsible button{display:none}.ol-overviewmap:not(.ol-collapsed){background:rgba(255,255,255,.8)}.ol-overviewmap-box{border:2px dotted rgba(0,60,136,.7)} \ No newline at end of file diff --git a/www/js/ol.js b/www/js/ol.js index 41b30076..bfca8855 100644 --- a/www/js/ol.js +++ b/www/js/ol.js @@ -1,207 +1,212 @@ // OpenLayers 3. See http://openlayers.org/ // License: https://raw.githubusercontent.com/openlayers/ol3/master/LICENSE.md -// Version: v3.4.0 +// Version: v3.11.2 (function (root, factory) { - if (typeof define === "function" && define.amd) { - define([], factory); - } else if (typeof exports === "object") { + if (typeof exports === "object") { module.exports = factory(); + } else if (typeof define === "function" && define.amd) { + define([], factory); } else { root.ol = factory(); } }(this, function () { var OPENLAYERS = {}; - var l,aa=aa||{},ba=this;function m(b){return void 0!==b}function t(b,c,d){b=b.split(".");d=d||ba;b[0]in d||!d.execScript||d.execScript("var "+b[0]);for(var e;b.length&&(e=b.shift());)!b.length&&m(c)?d[e]=c:d[e]?d=d[e]:d=d[e]={}}function ca(){}function da(b){b.Pa=function(){return b.xf?b.xf:b.xf=new b}} -function ea(b){var c=typeof b;if("object"==c)if(b){if(b instanceof Array)return"array";if(b instanceof Object)return c;var d=Object.prototype.toString.call(b);if("[object Window]"==d)return"object";if("[object Array]"==d||"number"==typeof b.length&&"undefined"!=typeof b.splice&&"undefined"!=typeof b.propertyIsEnumerable&&!b.propertyIsEnumerable("splice"))return"array";if("[object Function]"==d||"undefined"!=typeof b.call&&"undefined"!=typeof b.propertyIsEnumerable&&!b.propertyIsEnumerable("call"))return"function"}else return"null"; -else if("function"==c&&"undefined"==typeof b.call)return"object";return c}function fa(b){return null===b}function ga(b){return"array"==ea(b)}function ha(b){var c=ea(b);return"array"==c||"object"==c&&"number"==typeof b.length}function ia(b){return"string"==typeof b}function ja(b){return"number"==typeof b}function ka(b){return"function"==ea(b)}function la(b){var c=typeof b;return"object"==c&&null!=b||"function"==c}function ma(b){return b[na]||(b[na]=++oa)} -var na="closure_uid_"+(1E9*Math.random()>>>0),oa=0;function pa(b,c,d){return b.call.apply(b.bind,arguments)}function qa(b,c,d){if(!b)throw Error();if(2")&&(b=b.replace(Ga,">"));-1!=b.indexOf('"')&&(b=b.replace(Ha,"""));-1!=b.indexOf("'")&&(b=b.replace(Ia,"'"));-1!=b.indexOf("\x00")&&(b=b.replace(Ja,"�"));return b}var Ea=/&/g,Fa=//g,Ha=/"/g,Ia=/'/g,Ja=/\x00/g,Da=/[\x00&<>"']/; -function Ka(b){b=m(void 0)?b.toFixed(void 0):String(b);var c=b.indexOf(".");-1==c&&(c=b.length);c=Math.max(0,2-c);return Array(c+1).join("0")+b} -function La(b,c){for(var d=0,e=Aa(String(b)).split("."),f=Aa(String(c)).split("."),g=Math.max(e.length,f.length),h=0;0==d&&hc?1:0};var Oa=Array.prototype;function Pa(b,c){return Oa.indexOf.call(b,c,void 0)}function Qa(b,c,d){Oa.forEach.call(b,c,d)}function Ra(b,c){return Oa.filter.call(b,c,void 0)}function Sa(b,c,d){return Oa.map.call(b,c,d)}function Ta(b,c){return Oa.some.call(b,c,void 0)}function Ua(b,c){var d=Va(b,c,void 0);return 0>d?null:ia(b)?b.charAt(d):b[d]}function Va(b,c,d){for(var e=b.length,f=ia(b)?b.split(""):b,g=0;g=arguments.length?Oa.slice.call(b,c):Oa.slice.call(b,c,d)}function db(b,c){b.sort(c||fb)}function gb(b,c){if(!ha(b)||!ha(c)||b.length!=c.length)return!1;for(var d=b.length,e=hb,f=0;fc?1:bparseFloat(b))?String(c):b}(),Ob={};function Pb(b){return Ob[b]||(Ob[b]=0<=La(Nb,b))}var Qb=ba.document,Rb=Qb&&Gb?Mb()||("CSS1Compat"==Qb.compatMode?parseInt(Nb,10):5):void 0;var Sb="https:"===ba.location.protocol,Tb=Gb&&!Pb("9.0")&&""!==Nb;function Vb(b,c,d){return Math.min(Math.max(b,c),d)}function Wb(b,c){var d=b%c;return 0>d*c?d+c:d}function Xb(b,c,d){return b+d*(c-b)}function Yb(b){return b*Math.PI/180};function Zb(b){return function(c){if(m(c))return[Vb(c[0],b[0],b[2]),Vb(c[1],b[1],b[3])]}}function $b(b){return b};function ac(b,c,d){var e=b.length;if(b[0]<=c)return 0;if(!(c<=b[e-1]))if(0d)for(d=1;dg?1:.5,e=Math.floor(Math.log(c/e)/Math.log(b)+g),f=Math.max(e+f,0),m(d)&&(f=Math.min(f,d)),c/Math.pow(b,f)}};function dc(b){if(m(b))return 0}function ec(b,c){if(m(b))return b+c}function fc(b){var c=2*Math.PI/b;return function(b,e){if(m(b))return b=Math.floor((b+e)/c+.5)*c}}function gc(){var b=Yb(5);return function(c,d){if(m(c))return Math.abs(c+d)<=b?0:c+d}};function hc(b,c,d){this.center=b;this.resolution=c;this.rotation=d};var ic=!Gb||Gb&&9<=Rb,jc=!Gb||Gb&&9<=Rb,kc=Gb&&!Pb("9");!Ib||Pb("528");Hb&&Pb("1.9b")||Gb&&Pb("8")||Fb&&Pb("9.5")||Ib&&Pb("528");Hb&&!Pb("8")||Gb&&Pb("9");function lc(){0!=mc&&(nc[ma(this)]=this);this.oa=this.oa;this.qa=this.qa}var mc=0,nc={};lc.prototype.oa=!1;lc.prototype.Jc=function(){if(!this.oa&&(this.oa=!0,this.P(),0!=mc)){var b=ma(this);delete nc[b]}};function oc(b,c){var d=sa(pc,c);b.oa?d.call(void 0):(b.qa||(b.qa=[]),b.qa.push(m(void 0)?ra(d,void 0):d))}lc.prototype.P=function(){if(this.qa)for(;this.qa.length;)this.qa.shift()()};function pc(b){b&&"function"==typeof b.Jc&&b.Jc()};function qc(b,c){this.type=b;this.b=this.target=c;this.e=!1;this.og=!0}qc.prototype.pb=function(){this.e=!0};qc.prototype.preventDefault=function(){this.og=!1};function rc(b){b.pb()}function tc(b){b.preventDefault()};var uc=Gb?"focusout":"DOMFocusOut";function vc(b){vc[" "](b);return b}vc[" "]=ca;function wc(b,c){qc.call(this,b?b.type:"");this.relatedTarget=this.b=this.target=null;this.i=this.f=this.button=this.screenY=this.screenX=this.clientY=this.clientX=this.offsetY=this.offsetX=0;this.k=this.d=this.c=this.n=!1;this.state=null;this.g=!1;this.a=null;b&&xc(this,b,c)}v(wc,qc);var yc=[1,4,2]; -function xc(b,c,d){b.a=c;var e=b.type=c.type;b.target=c.target||c.srcElement;b.b=d;if(d=c.relatedTarget){if(Hb){var f;a:{try{vc(d.nodeName);f=!0;break a}catch(g){}f=!1}f||(d=null)}}else"mouseover"==e?d=c.fromElement:"mouseout"==e&&(d=c.toElement);b.relatedTarget=d;Object.defineProperties?Object.defineProperties(b,{offsetX:{configurable:!0,enumerable:!0,get:b.of,set:b.cm},offsetY:{configurable:!0,enumerable:!0,get:b.pf,set:b.dm}}):(b.offsetX=b.of(),b.offsetY=b.pf());b.clientX=void 0!==c.clientX?c.clientX: -c.pageX;b.clientY=void 0!==c.clientY?c.clientY:c.pageY;b.screenX=c.screenX||0;b.screenY=c.screenY||0;b.button=c.button;b.f=c.keyCode||0;b.i=c.charCode||("keypress"==e?c.keyCode:0);b.n=c.ctrlKey;b.c=c.altKey;b.d=c.shiftKey;b.k=c.metaKey;b.g=Jb?c.metaKey:c.ctrlKey;b.state=c.state;c.defaultPrevented&&b.preventDefault()}function zc(b){return(ic?0==b.a.button:"click"==b.type?!0:!!(b.a.button&yc[0]))&&!(Ib&&Jb&&b.n)}l=wc.prototype; -l.pb=function(){wc.T.pb.call(this);this.a.stopPropagation?this.a.stopPropagation():this.a.cancelBubble=!0};l.preventDefault=function(){wc.T.preventDefault.call(this);var b=this.a;if(b.preventDefault)b.preventDefault();else if(b.returnValue=!1,kc)try{if(b.ctrlKey||112<=b.keyCode&&123>=b.keyCode)b.keyCode=-1}catch(c){}};l.zh=function(){return this.a};l.of=function(){return Ib||void 0!==this.a.offsetX?this.a.offsetX:this.a.layerX}; -l.cm=function(b){Object.defineProperties(this,{offsetX:{writable:!0,enumerable:!0,configurable:!0,value:b}})};l.pf=function(){return Ib||void 0!==this.a.offsetY?this.a.offsetY:this.a.layerY};l.dm=function(b){Object.defineProperties(this,{offsetY:{writable:!0,enumerable:!0,configurable:!0,value:b}})};var Ac="closure_listenable_"+(1E6*Math.random()|0);function Bc(b){return!(!b||!b[Ac])}var Cc=0;function Dc(b,c,d,e,f){this.$b=b;this.a=null;this.src=c;this.type=d;this.Bc=!!e;this.yd=f;this.key=++Cc;this.uc=this.cd=!1}function Ec(b){b.uc=!0;b.$b=null;b.a=null;b.src=null;b.yd=null};function Fc(b){this.src=b;this.a={};this.c=0}Fc.prototype.add=function(b,c,d,e,f){var g=b.toString();b=this.a[g];b||(b=this.a[g]=[],this.c++);var h=Gc(b,c,e,f);-1f.keyCode||void 0!=f.returnValue)){a:{var g=!1;if(0==f.keyCode)try{f.keyCode=-1;break a}catch(h){g=!0}if(g||void 0==f.returnValue)f.returnValue=!0}f=[];for(g=d.b;g;g=g.parentNode)f.push(g);for(var g=b.type,k=f.length-1;!d.e&&0<=k;k--){d.b=f[k];var n=Xc(f[k],g,!0,d),e=e&&n}for(k=0;!d.e&&k>>0);function Oc(b){if(ka(b))return b;b[Zc]||(b[Zc]=function(c){return b.handleEvent(c)});return b[Zc]};function $c(b){return function(){return b}}var ad=$c(!1),bd=$c(!0),cd=$c(null);function dd(b){return b}function ed(b){var c;c=c||0;return function(){return b.apply(this,Array.prototype.slice.call(arguments,0,c))}}function fd(b){var c=arguments,d=c.length;return function(){for(var b,f=0;f=d||(1<=d?(h=k,f=g):(h+=d*n,f+=d*p));return[h,f]}function xd(b,c){var d=Wb(b+180,360)-180,e=Math.abs(Math.round(3600*d));return Math.floor(e/3600)+"\u00b0 "+Math.floor(e/60%60)+"\u2032 "+Math.floor(e%60)+"\u2033 "+c.charAt(0>d?1:0)} -function yd(b,c,d){return m(b)?c.replace("{x}",b[0].toFixed(d)).replace("{y}",b[1].toFixed(d)):""}function zd(b,c){for(var d=!0,e=b.length-1;0<=e;--e)if(b[e]!=c[e]){d=!1;break}return d}function Ad(b,c){var d=Math.cos(c),e=Math.sin(c),f=b[1]*d+b[0]*e;b[0]=b[0]*d-b[1]*e;b[1]=f;return b}function Bd(b,c){var d=b[0]-c[0],e=b[1]-c[1];return d*d+e*e}function Cd(b,c){return yd(b,"{x}, {y}",c)};function Dd(b){this.length=b.length||b;for(var c=0;ce&&(k=k|4);hf&&(k|=2);0===k&&(k=1);return k}function Sd(){return[Infinity,Infinity,-Infinity,-Infinity]}function Vd(b,c,d,e,f){return m(f)?(f[0]=b,f[1]=c,f[2]=d,f[3]=e,f):[b,c,d,e]} -function be(b,c){var d=b[0],e=b[1];return Vd(d,e,d,e,c)}function ce(b,c){return b[0]==c[0]&&b[2]==c[2]&&b[1]==c[1]&&b[3]==c[3]}function de(b,c){c[0]b[2]&&(b[2]=c[2]);c[1]b[3]&&(b[3]=c[3]);return b}function Td(b,c){c[0]b[2]&&(b[2]=c[0]);c[1]b[3]&&(b[3]=c[1])} -function ee(b,c,d,e,f){for(;dg;++g)h=f[g],k=e[g],f[g]=b[0]+h*c-k*d,e[g]=b[1]+h*d+k*c;return Ud(f,e,void 0)}function ne(b){return b[3]-b[1]} -function oe(b,c,d){d=m(d)?d:Sd();pe(b,c)&&(d[0]=b[0]>c[0]?b[0]:c[0],d[1]=b[1]>c[1]?b[1]:c[1],d[2]=b[2]=c[0]&&b[1]<=c[3]&&b[3]>=c[1]}function re(b){return b[2]>>0),oa=0; +function pa(b,c,d){return b.call.apply(b.bind,arguments)}function qa(b,c,d){if(!b)throw Error();if(2")&&(b=b.replace(Ia,">"));-1!=b.indexOf('"')&&(b=b.replace(Ja,"""));-1!=b.indexOf("'")&&(b=b.replace(La,"'"));-1!=b.indexOf("\x00")&&(b=b.replace(Ma,"�"));return b}var Ga=/&/g,Ha=//g,Ja=/"/g,La=/'/g,Ma=/\x00/g,Fa=/[\x00&<>"']/,Na=String.prototype.repeat?function(b,c){return b.repeat(c)}:function(b,c){return Array(c+1).join(b)}; +function Oa(b){b=ca(void 0)?b.toFixed(void 0):String(b);var c=b.indexOf(".");-1==c&&(c=b.length);return Na("0",Math.max(0,2-c))+b} +function Pa(b,c){for(var d=0,e=Ca(String(b)).split("."),f=Ca(String(c)).split("."),g=Math.max(e.length,f.length),h=0;0==d&&hc?1:0};function Sa(b,c,d){return Math.min(Math.max(b,c),d)}var Ta=function(){var b;"cosh"in Math?b=Math.cosh:b=function(b){b=Math.exp(b);return(b+1/b)/2};return b}();function Ua(b,c,d,e,f,g){var h=f-d,k=g-e;if(0!==h||0!==k){var m=((b-d)*h+(c-e)*k)/(h*h+k*k);1d?null:ia(b)?b.charAt(d):b[d]}function gb(b,c,d){for(var e=b.length,f=ia(b)?b.split(""):b,g=0;g=arguments.length?Za.slice.call(b,c):Za.slice.call(b,c,d)}function ob(b,c){b.sort(c||pb)}function qb(b){for(var c=rb,d=0;dc?1:bd)for(d=1;dg?1:.5))+f,0),void 0!==d&&(e=Math.min(e,d)),c/Math.pow(b,e)}};function zb(b){if(void 0!==b)return 0}function Ab(b,c){if(void 0!==b)return b+c}function Bb(b){var c=2*Math.PI/b;return function(b,e){if(void 0!==b)return b=Math.floor((b+e)/c+.5)*c}}function Cb(){var b=Wa(5);return function(c,d){if(void 0!==c)return Math.abs(c+d)<=b?0:c+d}};function Db(b,c,d){this.center=b;this.resolution=c;this.rotation=d};var Eb;a:{var Fb=ba.navigator;if(Fb){var Gb=Fb.userAgent;if(Gb){Eb=Gb;break a}}Eb=""}function Hb(b){return-1!=Eb.indexOf(b)};function Ib(b,c,d){for(var e in b)c.call(d,b[e],e,b)}function Jb(b,c){for(var d in b)if(c.call(void 0,b[d],d,b))return!0;return!1}function Kb(b){var c=0,d;for(d in b)c++;return c}function Lb(b){var c=[],d=0,e;for(e in b)c[d++]=b[e];return c}function Mb(b){var c=[],d=0,e;for(e in b)c[d++]=e;return c}function Nb(b,c){return c in b}function Ob(b,c){for(var d in b)if(b[d]==c)return!0;return!1}function Pb(b,c){for(var d in b)if(c.call(void 0,b[d],d,b))return d} +function Qb(b){for(var c in b)return!1;return!0}function Rb(b){for(var c in b)delete b[c]}function Sb(b,c,d){return c in b?b[c]:d}function Tb(b,c){var d=[];return c in b?b[c]:b[c]=d}function Ub(b){var c={},d;for(d in b)c[d]=b[d];return c}function Vb(b){var c=fa(b);if("object"==c||"array"==c){if(ka(b.clone))return b.clone();var c="array"==c?[]:{},d;for(d in b)c[d]=Vb(b[d]);return c}return b}var Wb="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "); +function Xb(b,c){for(var d,e,f=1;fparseFloat(b))?String(c):b}(),ic={};function jc(b){return ic[b]||(ic[b]=0<=Pa(hc,b))}var kc=ba.document,lc=kc&&Zb?gc()||("CSS1Compat"==kc.compatMode?parseInt(hc,10):5):void 0;var mc=!Zb||9<=lc,nc=!Zb||9<=lc,oc=Zb&&!jc("9");!bc||jc("528");ac&&jc("1.9b")||Zb&&jc("8")||Yb&&jc("9.5")||bc&&jc("528");ac&&!jc("8")||Zb&&jc("9");function pc(){0!=qc&&(rc[w(this)]=this);this.ia=this.ia;this.oa=this.oa}var qc=0,rc={};pc.prototype.ia=!1;pc.prototype.Ec=function(){if(!this.ia&&(this.ia=!0,this.X(),0!=qc)){var b=w(this);delete rc[b]}};function tc(b,c){var d=sa(uc,c);b.ia?d.call(void 0):(b.oa||(b.oa=[]),b.oa.push(ca(void 0)?ra(d,void 0):d))}pc.prototype.X=function(){if(this.oa)for(;this.oa.length;)this.oa.shift()()};function uc(b){b&&"function"==typeof b.Ec&&b.Ec()};function vc(b,c){this.type=b;this.g=this.target=c;this.i=!1;this.Qh=!0}vc.prototype.b=function(){this.i=!0};vc.prototype.preventDefault=function(){this.Qh=!1};function wc(b){b.b()}function xc(b){b.preventDefault()};var yc=Zb?"focusout":"DOMFocusOut";function zc(b){zc[" "](b);return b}zc[" "]=da;function Ac(b,c){vc.call(this,b?b.type:"");this.relatedTarget=this.g=this.target=null;this.u=this.j=this.button=this.screenY=this.screenX=this.clientY=this.clientX=this.offsetY=this.offsetX=0;this.A=this.f=this.c=this.B=!1;this.state=null;this.l=!1;this.a=null;if(b){var d=this.type=b.type,e=b.changedTouches?b.changedTouches[0]:null;this.target=b.target||b.srcElement;this.g=c;var f=b.relatedTarget;if(f){if(ac){var g;a:{try{zc(f.nodeName);g=!0;break a}catch(h){}g=!1}g||(f=null)}}else"mouseover"==d? +f=b.fromElement:"mouseout"==d&&(f=b.toElement);this.relatedTarget=f;null===e?(this.offsetX=bc||void 0!==b.offsetX?b.offsetX:b.layerX,this.offsetY=bc||void 0!==b.offsetY?b.offsetY:b.layerY,this.clientX=void 0!==b.clientX?b.clientX:b.pageX,this.clientY=void 0!==b.clientY?b.clientY:b.pageY,this.screenX=b.screenX||0,this.screenY=b.screenY||0):(this.clientX=void 0!==e.clientX?e.clientX:e.pageX,this.clientY=void 0!==e.clientY?e.clientY:e.pageY,this.screenX=e.screenX||0,this.screenY=e.screenY||0);this.button= +b.button;this.j=b.keyCode||0;this.u=b.charCode||("keypress"==d?b.keyCode:0);this.B=b.ctrlKey;this.c=b.altKey;this.f=b.shiftKey;this.A=b.metaKey;this.l=cc?b.metaKey:b.ctrlKey;this.state=b.state;this.a=b;b.defaultPrevented&&this.preventDefault()}}y(Ac,vc);var Bc=[1,4,2];function Cc(b){return(mc?0==b.a.button:"click"==b.type?!0:!!(b.a.button&Bc[0]))&&!(bc&&cc&&b.B)}Ac.prototype.b=function(){Ac.da.b.call(this);this.a.stopPropagation?this.a.stopPropagation():this.a.cancelBubble=!0}; +Ac.prototype.preventDefault=function(){Ac.da.preventDefault.call(this);var b=this.a;if(b.preventDefault)b.preventDefault();else if(b.returnValue=!1,oc)try{if(b.ctrlKey||112<=b.keyCode&&123>=b.keyCode)b.keyCode=-1}catch(c){}};var Dc="closure_listenable_"+(1E6*Math.random()|0);function Ec(b){return!(!b||!b[Dc])}var Fc=0;function Gc(b,c,d,e,f){this.listener=b;this.a=null;this.src=c;this.type=d;this.ad=!!e;this.je=f;this.key=++Fc;this.Tc=this.Ud=!1}function Hc(b){b.Tc=!0;b.listener=null;b.a=null;b.src=null;b.je=null};function Ic(b){this.src=b;this.a={};this.c=0}Ic.prototype.add=function(b,c,d,e,f){var g=b.toString();b=this.a[g];b||(b=this.a[g]=[],this.c++);var h=Jc(b,c,e,f);-1f.keyCode||void 0!=f.returnValue)){a:{var g=!1;if(0==f.keyCode)try{f.keyCode=-1;break a}catch(m){g=!0}if(g||void 0==f.returnValue)f.returnValue=!0}f=[];for(g=d.g;g;g=g.parentNode)f.push(g);for(var g=b.type,h=f.length-1;!d.i&&0<=h;h--){d.g=f[h];var k=$c(f[h],g,!0,d),e=e&&k}for(h=0;!d.i&&h>>0);function Qc(b){if(ka(b))return b;b[bd]||(b[bd]=function(c){return b.handleEvent(c)});return b[bd]};function cd(){pc.call(this);this.zb=new Ic(this);this.Nd=this;this.eb=null}y(cd,pc);cd.prototype[Dc]=!0;l=cd.prototype;l.addEventListener=function(b,c,d,e){C(this,b,c,d,e)};l.removeEventListener=function(b,c,d,e){Yc(this,b,c,d,e)}; +l.o=function(b){var c,d=this.eb;if(d)for(c=[];d;d=d.eb)c.push(d);var d=this.Nd,e=b.type||b;if(ia(b))b=new vc(b,d);else if(b instanceof vc)b.target=b.target||d;else{var f=b;b=new vc(e,d);Xb(b,f)}var f=!0,g;if(c)for(var h=c.length-1;!b.i&&0<=h;h--)g=b.g=c[h],f=dd(g,e,!0,b)&&f;b.i||(g=b.g=d,f=dd(g,e,!0,b)&&f,b.i||(f=dd(g,e,!1,b)&&f));if(c)for(h=0;!b.i&&hd*c?d+c:d}function qd(b,c,d){return b+d*(c-b)};function rd(b,c){b[0]+=c[0];b[1]+=c[1];return b}function sd(b,c){var d=b[0],e=b[1],f=c[0],g=c[1],h=f[0],f=f[1],k=g[0],g=g[1],m=k-h,n=g-f,d=0===m&&0===n?0:(m*(d-h)+n*(e-f))/(m*m+n*n||0);0>=d||(1<=d?(h=k,f=g):(h+=d*m,f+=d*n));return[h,f]}function td(b,c){var d=pd(b+180,360)-180,e=Math.abs(Math.round(3600*d));return Math.floor(e/3600)+"\u00b0 "+Oa(Math.floor(e/60%60))+"\u2032 "+Oa(Math.floor(e%60))+"\u2033 "+c.charAt(0>d?1:0)} +function ud(b,c,d){return b?c.replace("{x}",b[0].toFixed(d)).replace("{y}",b[1].toFixed(d)):""}function vd(b,c){for(var d=!0,e=b.length-1;0<=e;--e)if(b[e]!=c[e]){d=!1;break}return d}function wd(b,c){var d=Math.cos(c),e=Math.sin(c),f=b[1]*d+b[0]*e;b[0]=b[0]*d-b[1]*e;b[1]=f;return b}function xd(b,c){var d=b[0]-c[0],e=b[1]-c[1];return d*d+e*e}function yd(b,c){return xd(b,sd(b,c))}function zd(b,c){return ud(b,"{x}, {y}",c)};function Ad(b){this.length=b.length||b;for(var c=0;ce&&(k=k|4);hf&&(k|=2);0===k&&(k=1);return k}function Od(){return[Infinity,Infinity,-Infinity,-Infinity]} +function Rd(b,c,d,e,f){return f?(f[0]=b,f[1]=c,f[2]=d,f[3]=e,f):[b,c,d,e]}function Zd(b,c){var d=b[0],e=b[1];return Rd(d,e,d,e,c)}function $d(b,c,d,e,f){f=Rd(Infinity,Infinity,-Infinity,-Infinity,f);return ae(f,b,c,d,e)}function be(b,c){return b[0]==c[0]&&b[2]==c[2]&&b[1]==c[1]&&b[3]==c[3]}function ce(b,c){c[0]b[2]&&(b[2]=c[2]);c[1]b[3]&&(b[3]=c[3]);return b} +function Pd(b,c){c[0]b[2]&&(b[2]=c[0]);c[1]b[3]&&(b[3]=c[1])}function ae(b,c,d,e,f){for(;dg;++g)h=f[g],k=e[g],f[g]=b[0]+h*c-k*d,e[g]=b[1]+h*d+k*c;return Qd(f,e,void 0)}function le(b){return b[3]-b[1]}function oe(b,c,d){d=d?d:Od();pe(b,c)&&(d[0]=b[0]>c[0]?b[0]:c[0],d[1]=b[1]>c[1]?b[1]:c[1],d[2]=b[2]=c[0]&&b[1]<=c[3]&&b[3]>=c[1]}function je(b){return b[2]this.H)}return m(b)?this.o+b:b};l.pe=function(b,c){if(!re(b)){this.Ha(ke(b));var d=this.k(b,c),e=this.constrainResolution(d,0,0);eb?$e(2*b):1-$e(2*(b-.5))};function cf(b){var c=b.source,d=m(b.start)?b.start:ta(),e=c[0],f=c[1],g=m(b.duration)?b.duration:1E3,h=m(b.easing)?b.easing:$e;return function(b,c){if(c.time>=1;return d.join("")}function jf(b){return gf(b[0],b[1],b[2])};function kf(b,c,d,e){this.a=b;this.d=c;this.b=d;this.c=e}function lf(b,c,d,e,f){return m(f)?(f.a=b,f.d=c,f.b=d,f.c=e,f):new kf(b,c,d,e)}kf.prototype.contains=function(b){return mf(this,b[1],b[2])};function mf(b,c,d){return b.a<=c&&c<=b.d&&b.b<=d&&d<=b.c}function nf(b,c){return b.a==c.a&&b.b==c.b&&b.d==c.d&&b.c==c.c}function of(b){return b.d-b.a+1}function pf(b,c){return b.a<=c.d&&b.d>=c.a&&b.b<=c.c&&b.c>=c.b};function qf(b){this.c=b.html;this.a=m(b.tileRanges)?b.tileRanges:null}qf.prototype.b=function(){return this.c};var rf=!Gb||Gb&&9<=Rb;!Hb&&!Gb||Gb&&Gb&&9<=Rb||Hb&&Pb("1.9.1");Gb&&Pb("9");Eb("area base br col command embed hr img input keygen link meta param source track wbr".split(" "));Eb("action","cite","data","formaction","href","manifest","poster","src");Eb("embed","iframe","link","object","script","style","template");function sf(b,c){this.x=m(b)?b:0;this.y=m(c)?c:0}l=sf.prototype;l.clone=function(){return new sf(this.x,this.y)};l.ceil=function(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);return this};l.floor=function(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);return this};l.round=function(){this.x=Math.round(this.x);this.y=Math.round(this.y);return this};l.scale=function(b,c){var d=ja(c)?c:b;this.x*=b;this.y*=d;return this};function tf(b,c){this.width=b;this.height=c}l=tf.prototype;l.clone=function(){return new tf(this.width,this.height)};l.la=function(){return!(this.width*this.height)};l.ceil=function(){this.width=Math.ceil(this.width);this.height=Math.ceil(this.height);return this};l.floor=function(){this.width=Math.floor(this.width);this.height=Math.floor(this.height);return this};l.round=function(){this.width=Math.round(this.width);this.height=Math.round(this.height);return this}; -l.scale=function(b,c){var d=ja(c)?c:b;this.width*=b;this.height*=d;return this};function uf(b){return b?new vf(wf(b)):xa||(xa=new vf)}function xf(b){var c=document;return ia(b)?c.getElementById(b):b}function yf(b,c){mb(c,function(c,e){"style"==e?b.style.cssText=c:"class"==e?b.className=c:"for"==e?b.htmlFor=c:e in zf?b.setAttribute(zf[e],c):0==e.lastIndexOf("aria-",0)||0==e.lastIndexOf("data-",0)?b.setAttribute(e,c):b[e]=c})} -var zf={cellpadding:"cellPadding",cellspacing:"cellSpacing",colspan:"colSpan",frameborder:"frameBorder",height:"height",maxlength:"maxLength",role:"role",rowspan:"rowSpan",type:"type",usemap:"useMap",valign:"vAlign",width:"width"};function Af(b){b=b.document.documentElement;return new tf(b.clientWidth,b.clientHeight)} -function Bf(b,c,d){var e=arguments,f=document,g=e[0],h=e[1];if(!rf&&h&&(h.name||h.type)){g=["<",g];h.name&&g.push(' name="',Ba(h.name),'"');if(h.type){g.push(' type="',Ba(h.type),'"');var k={};Db(k,h);delete k.type;h=k}g.push(">");g=g.join("")}g=f.createElement(g);h&&(ia(h)?g.className=h:ga(h)?g.className=h.join(" "):yf(g,h));2d;++d)e[d]=c[d].toFixed(6);d=e.join(",")}else d=c.join(",");Qf(b,"matrix3d("+d+")")}else if(Of()){e=[c[0],c[1],c[4],c[5],c[12],c[13]];if(m(6)){var f=Array(6);for(d=0;6>d;++d)f[d]=e[d].toFixed(6);d=f.join(",")}else d=e.join(",");Qf(b,"matrix("+d+")")}else b.style.left=Math.round(c[12])+"px",b.style.top=Math.round(c[13])+"px"};var Sf=["experimental-webgl","webgl","webkit-3d","moz-webgl"];function Tf(b,c){var d,e,f=Sf.length;for(e=0;e=this.left&&b.right<=this.right&&b.top>=this.top&&b.bottom<=this.bottom:b.x>=this.left&&b.x<=this.right&&b.y>=this.top&&b.y<=this.bottom:!1}; +function Ae(b){this.radius=b}Ae.prototype.c=function(b){for(var c=0,d=b.length,e=b[d-1][0],f=b[d-1][1],g=0;gb||0!==this.i&&b<=this.i)return this;var c=b.toString();if(this.j.hasOwnProperty(c))return this.j[c];var d=this.Kc(b);if(d.ja().lengthf&&(f=g);g=k;h=m}return f}function mf(b,c,d,e,f){var g,h;g=0;for(h=d.length;gk){for(;ct&&(n=p,t=v)}t>f&&(m[(n-c)/e]=1,r+eG&&EaG)&&(0>la&&Lla)||(z[h++]=v,z[h++]=O,B=v,A=O);v=K;O=I}}z[h++]=v;z[h++]=O}}k.push(h);c=p}return h};function wf(b,c){df.call(this);this.g=this.l=-1;this.ma(b,c)}y(wf,df);l=wf.prototype;l.clone=function(){var b=new wf(null);xf(b,this.b,this.v.slice());return b};l.mb=function(b,c,d,e){if(eg!=p>g&&f<(n-k)*(g-m)/(p-m)+k&&(h=!h);k=n;m=p}return h}function Af(b,c,d,e,f,g){if(0===d.length||!zf(b,c,d[0],e,f,g))return!1;var h;c=1;for(h=d.length;cq&&(n=(n+p)/2,Af(b,c,d,e,n,r)&&(x=n,q=z));n=p}isNaN(x)&&(x=f[g]);return h?(h.push(x,r),h):[x,r]};function Cf(b,c,d,e,f,g){for(var h=[b[c],b[c+1]],k=[],m;c+e=f[0]&&g[2]<=f[2]||g[1]>=f[1]&&g[3]<=f[3]?!0:Cf(b,c,d,e,function(b,c){var d=!1,e=Yd(f,b),g=Yd(f,c);if(1===e||1===g)d=!0;else{var q=f[0],r=f[1],t=f[2],x=f[3],z=c[0],B=c[1],A=(B-b[1])/(z-b[0]);g&2&&!(e&2)&&(d=z-(B-x)/A,d=d>=q&&d<=t);d||!(g&4)||e&4||(d=B-(z-t)*A,d=d>=r&&d<=x);d||!(g&8)||e&8||(d=z-(B-r)/A,d=d>=q&&d<=t);d||!(g&16)||e&16||(d=B-(z-q)*A,d=d>=r&&d<=x)}return d}):!1} +function Ef(b,c,d,e,f){var g=d[0];if(!(Df(b,c,g,e,f)||zf(b,c,g,e,f[0],f[1])||zf(b,c,g,e,f[0],f[3])||zf(b,c,g,e,f[2],f[1])||zf(b,c,g,e,f[2],f[3])))return!1;if(1===d.length)return!0;c=1;for(g=d.length;cb||this.g.length<=b)return null;var c=new wf(null);xf(c,this.b,this.v.slice(0===b?0:this.g[b-1],this.g[b]));return c};l.ae=function(){var b=this.b,c=this.v,d=this.g,e=[],f=0,g,h;g=0;for(h=d.length;gthis.i)}return void 0!==b?this.f+b:b}; +l.jf=function(b,c,d){b instanceof df||(b=Lf(b));var e=d||{};d=void 0!==e.padding?e.padding:[0,0,0,0];var f=void 0!==e.constrainResolution?e.constrainResolution:!0,g=void 0!==e.nearest?e.nearest:!1,h;void 0!==e.minResolution?h=e.minResolution:void 0!==e.maxZoom?h=this.constrainResolution(this.a,e.maxZoom-this.f,0):h=0;var k=b.ja(),m=this.Ea(),e=Math.cos(-m),m=Math.sin(-m),n=Infinity,p=Infinity,q=-Infinity,r=-Infinity;b=b.ra();for(var t=0,x=k.length;tb?Wf(2*b):1-Wf(2*(b-.5))};function Zf(b){var c=b.source,d=b.start?b.start:Date.now(),e=c[0],f=c[1],g=void 0!==b.duration?b.duration:1E3,h=b.easing?b.easing:Wf;return function(b,c){if(c.time>=1;return d.join("")}function fg(b){return dg(b[0],b[1],b[2])};function gg(b,c,d,e){this.a=b;this.f=c;this.c=d;this.b=e}gg.prototype.contains=function(b){return hg(this,b[1],b[2])};function hg(b,c,d){return b.a<=c&&c<=b.f&&b.c<=d&&d<=b.b}function ig(b,c){return b.a==c.a&&b.c==c.c&&b.f==c.f&&b.b==c.b}function jg(b){return b.b-b.c+1}function kg(b){return b.f-b.a+1}function lg(b,c){return b.a<=c.f&&b.f>=c.a&&b.c<=c.b&&b.b>=c.c};function mg(b){this.c=b.html;this.a=b.tileRanges?b.tileRanges:null}mg.prototype.b=function(){return this.c};function ng(b,c,d){vc.call(this,b,d);this.element=c}y(ng,vc);function og(b){id.call(this);this.a=b?b:[];pg(this)}y(og,id);l=og.prototype;l.clear=function(){for(;0");g=g.join("")}g=f.createElement(g);h&&(ia(h)?g.className=h:ga(h)?g.className=h.join(" "):Eg(g,h));2=this.left&&b.right<=this.right&&b.top>=this.top&&b.bottom<=this.bottom:b.x>=this.left&&b.x<=this.right&&b.y>=this.top&&b.y<=this.bottom:!1}; l.ceil=function(){this.top=Math.ceil(this.top);this.right=Math.ceil(this.right);this.bottom=Math.ceil(this.bottom);this.left=Math.ceil(this.left);return this};l.floor=function(){this.top=Math.floor(this.top);this.right=Math.floor(this.right);this.bottom=Math.floor(this.bottom);this.left=Math.floor(this.left);return this};l.round=function(){this.top=Math.round(this.top);this.right=Math.round(this.right);this.bottom=Math.round(this.bottom);this.left=Math.round(this.left);return this}; -l.scale=function(b,c){var d=ja(c)?c:b;this.left*=b;this.right*=b;this.top*=d;this.bottom*=d;return this};function Cg(b,c,d,e){this.left=b;this.top=c;this.width=d;this.height=e}l=Cg.prototype;l.clone=function(){return new Cg(this.left,this.top,this.width,this.height)};l.contains=function(b){return b instanceof Cg?this.left<=b.left&&this.left+this.width>=b.left+b.width&&this.top<=b.top&&this.top+this.height>=b.top+b.height:b.x>=this.left&&b.x<=this.left+this.width&&b.y>=this.top&&b.y<=this.top+this.height}; -function Dg(b,c){var d=c.xb.f};function Zg(b,c){hd.call(this);this.a=b;this.state=c}v(Zg,hd);function $g(b){b.dispatchEvent("change")}Zg.prototype.qb=function(){return ma(this).toString()};Zg.prototype.e=function(){return this.a};function ah(b){qd.call(this);this.e=ze(b.projection);this.f=m(b.attributions)?b.attributions:null;this.D=b.logo;this.q=m(b.state)?b.state:"ready"}v(ah,qd);l=ah.prototype;l.Jd=ca;l.Y=function(){return this.f};l.X=function(){return this.D};l.Z=function(){return this.e};l.$=function(){return this.q};function bh(b,c){b.q=c;b.l()};function ch(b){this.minZoom=m(b.minZoom)?b.minZoom:0;this.a=b.resolutions;this.maxZoom=this.a.length-1;this.f=m(b.origin)?b.origin:null;this.g=null;m(b.origins)&&(this.g=b.origins);this.c=null;m(b.tileSizes)&&(this.c=b.tileSizes);this.e=m(b.tileSize)?b.tileSize:null===this.c?256:void 0;this.b=null;m(b.widths)&&(this.b=b.widths)}var dh=[0,0,0];l=ch.prototype;l.Db=function(){return dd};l.gd=function(b,c,d,e,f){f=eh(this,b,f);for(b=b[0]-1;b>=this.minZoom;){if(c.call(d,b,fh(this,f,b,e)))return!0;--b}return!1}; -l.md=function(){return this.maxZoom};l.pd=function(){return this.minZoom};l.Lb=function(b){return null===this.f?this.g[b]:this.f};l.na=function(b){return this.a[b]};l.Qd=function(){return this.a};l.td=function(b,c,d){return b[0]Ca.d)if(pf(U,new kf(Wb(N.a,eb),Wb(N.d,eb),N.b,N.c))||of(N)>eb&&pf(U,Ca)){r=!0;break a}}r=!1}}}else r=!1;r?(n in y&&delete y[n],u[n]=k):y[n]=k}c=[u,y];d=c[0];c=c[1];for(var R in this.k)R in d?(this.e[R]||(Mg(this.k[R],!0),this.e[R]=!0),delete d[R]):R in c?(this.e[R]&&(Mg(this.k[R],!1),delete this.e[R]),delete c[R]):(If(this.k[R]),delete this.k[R],delete this.e[R]);for(R in d)e= -Ef("LI"),e.innerHTML=d[R].c,this.r.appendChild(e),this.k[R]=e,this.e[R]=!0;for(R in c)e=Ef("LI"),e.innerHTML=c[R].c,Mg(e,!1),this.r.appendChild(e),this.k[R]=e;R=!wb(this.e)||!wb(b.logos);this.p!=R&&(Mg(this.element,R),this.p=R);R&&wb(this.e)?yg(this.element,"ol-logo-only"):zg(this.element,"ol-logo-only");var Ma;b=b.logos;R=this.N;for(Ma in R)Ma in b||(If(R[Ma]),delete R[Ma]);for(var sb in b)sb in R||(Ma=new Image,Ma.src=sb,d=b[sb],""===d?d=Ma:(d=Bf("A",{href:d}),d.appendChild(Ma)),this.o.appendChild(d), -R[sb]=d);Mg(this.o,!wb(b))}}l=th.prototype;l.Dj=function(b){b.preventDefault();vh(this)};function vh(b){Ag(b.element,"ol-collapsed");b.d?Jf(b.D,b.H):Jf(b.H,b.D);b.d=!b.d}l.Cj=function(){return this.g};l.Fj=function(b){this.g!==b&&(this.g=b,Ag(this.element,"ol-uncollapsible"),!b&&this.d&&vh(this))};l.Ej=function(b){this.g&&this.d!==b&&vh(this)};l.Bj=function(){return this.d};function wh(b){b=m(b)?b:{};var c=m(b.className)?b.className:"ol-rotate",d=m(b.label)?b.label:"\u21e7";this.d=null;ia(d)?this.d=Bf("SPAN","ol-compass",d):(this.d=d,yg(this.d,"ol-compass"));d=Bf("BUTTON",{"class":c+"-reset",type:"button",title:m(b.tipLabel)?b.tipLabel:"Reset rotation"},this.d);w(d,"click",wh.prototype.o,!1,this);w(d,["mouseout",uc],function(){this.blur()},!1);c=Bf("DIV",c+" ol-unselectable ol-control",d);Ug.call(this,{element:c,render:m(b.render)?b.render:xh,target:b.target});this.g= -m(b.duration)?b.duration:250;this.e=m(b.autoHide)?b.autoHide:!0;this.k=void 0;this.e&&yg(this.element,"ol-hidden")}v(wh,Ug);wh.prototype.o=function(b){b.preventDefault();b=this.a;var c=b.a();if(null!==c){for(var d=c.d();d<-Math.PI;)d+=2*Math.PI;for(;d>Math.PI;)d-=2*Math.PI;m(d)&&(02*this.b&&Uh(this),!0):!1};function Uh(b){if(b.b!=b.a.length){for(var c=0,d=0;c=b||96<=b&&106>=b||65<=b&&90>=b||Ib&&0==b)return!0;switch(b){case 32:case 63:case 107:case 109:case 110:case 111:case 186:case 59:case 189:case 187:case 61:case 188:case 190:case 191:case 192:case 222:case 219:case 220:case 221:return!0;default:return!1}}function ai(b){if(Hb)b=bi(b);else if(Jb&&Ib)a:switch(b){case 93:b=91;break a}return b} -function bi(b){switch(b){case 61:return 187;case 59:return 186;case 173:return 189;case 224:return 91;case 0:return 224;default:return b}};function ci(b,c){hd.call(this);b&&di(this,b,c)}v(ci,hd);l=ci.prototype;l.ba=null;l.Ad=null;l.ue=null;l.Bd=null;l.Qa=-1;l.Gb=-1;l.je=!1; -var ei={3:13,12:144,63232:38,63233:40,63234:37,63235:39,63236:112,63237:113,63238:114,63239:115,63240:116,63241:117,63242:118,63243:119,63244:120,63245:121,63246:122,63247:123,63248:44,63272:46,63273:36,63275:35,63276:33,63277:34,63289:144,63302:45},fi={Up:38,Down:40,Left:37,Right:39,Enter:13,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,"U+007F":46,Home:36,End:35,PageUp:33,PageDown:34,Insert:45},gi=Gb||Ib&&Pb("525"),hi=Jb&&Hb; -ci.prototype.a=function(b){Ib&&(17==this.Qa&&!b.n||18==this.Qa&&!b.c||Jb&&91==this.Qa&&!b.k)&&(this.Gb=this.Qa=-1);-1==this.Qa&&(b.n&&17!=b.f?this.Qa=17:b.c&&18!=b.f?this.Qa=18:b.k&&91!=b.f&&(this.Qa=91));gi&&!Yh(b.f,this.Qa,b.d,b.n,b.c)?this.handleEvent(b):(this.Gb=ai(b.f),hi&&(this.je=b.c))};ci.prototype.c=function(b){this.Gb=this.Qa=-1;this.je=b.c}; -ci.prototype.handleEvent=function(b){var c=b.a,d,e,f=c.altKey;Gb&&"keypress"==b.type?(d=this.Gb,e=13!=d&&27!=d?c.keyCode:0):Ib&&"keypress"==b.type?(d=this.Gb,e=0<=c.charCode&&63232>c.charCode&&$h(d)?c.charCode:0):Fb?(d=this.Gb,e=$h(d)?c.keyCode:0):(d=c.keyCode||this.Gb,e=c.charCode||0,hi&&(f=this.je),Jb&&63==e&&224==d&&(d=191));var g=d=ai(d),h=c.keyIdentifier;d?63232<=d&&d in ei?g=ei[d]:25==d&&b.d&&(g=9):h&&h in fi&&(g=fi[h]);this.Qa=g;b=new ii(g,e,0,c);b.c=f;this.dispatchEvent(b)}; -function di(b,c,d){b.Bd&&ji(b);b.ba=c;b.Ad=w(b.ba,"keypress",b,d);b.ue=w(b.ba,"keydown",b.a,d,b);b.Bd=w(b.ba,"keyup",b.c,d,b)}function ji(b){b.Ad&&(Wc(b.Ad),Wc(b.ue),Wc(b.Bd),b.Ad=null,b.ue=null,b.Bd=null);b.ba=null;b.Qa=-1;b.Gb=-1}ci.prototype.P=function(){ci.T.P.call(this);ji(this)};function ii(b,c,d,e){wc.call(this,e);this.type="key";this.f=b;this.i=c}v(ii,wc);function ki(b,c){hd.call(this);var d=this.ba=b;(d=la(d)&&1==d.nodeType?this.ba:this.ba?this.ba.body:null)&&Fg(d,"direction");this.a=w(this.ba,Hb?"DOMMouseScroll":"mousewheel",this,c)}v(ki,hd); -ki.prototype.handleEvent=function(b){var c=0,d=0,e=0;b=b.a;if("mousewheel"==b.type){d=1;if(Gb||Ib&&(Kb||Pb("532.0")))d=40;e=li(-b.wheelDelta,d);m(b.wheelDeltaX)?(c=li(-b.wheelDeltaX,d),d=li(-b.wheelDeltaY,d)):d=e}else e=b.detail,100e&&(e=-3),m(b.axis)&&b.axis===b.HORIZONTAL_AXIS?c=e:d=e;ja(this.c)&&Vb(c,-this.c,this.c);ja(this.b)&&(d=Vb(d,-this.b,this.b));c=new mi(e,b,0,d);this.dispatchEvent(c)};function li(b,c){return Ib&&(Jb||Lb)&&0!=b%c?b:b/c} -ki.prototype.P=function(){ki.T.P.call(this);Wc(this.a);this.a=null};function mi(b,c,d,e){wc.call(this,c);this.type="mousewheel";this.detail=b;this.q=e}v(mi,wc);function ni(b,c,d){qc.call(this,b);this.a=c;b=m(d)?d:{};this.buttons=oi(b);this.pressure=pi(b,this.buttons);this.bubbles=zb(b,"bubbles",!1);this.cancelable=zb(b,"cancelable",!1);this.view=zb(b,"view",null);this.detail=zb(b,"detail",null);this.screenX=zb(b,"screenX",0);this.screenY=zb(b,"screenY",0);this.clientX=zb(b,"clientX",0);this.clientY=zb(b,"clientY",0);this.button=zb(b,"button",0);this.relatedTarget=zb(b,"relatedTarget",null);this.pointerId=zb(b,"pointerId",0);this.width=zb(b,"width",0);this.height= -zb(b,"height",0);this.pointerType=zb(b,"pointerType","");this.isPrimary=zb(b,"isPrimary",!1);c.preventDefault&&(this.preventDefault=function(){c.preventDefault()})}v(ni,qc);function oi(b){if(b.buttons||qi)b=b.buttons;else switch(b.which){case 1:b=1;break;case 2:b=4;break;case 3:b=2;break;default:b=0}return b}function pi(b,c){var d=0;b.pressure?d=b.pressure:d=c?.5:0;return d}var qi=!1;try{qi=1===(new MouseEvent("click",{buttons:1})).buttons}catch(ri){};function si(b,c){this.a=b;this.f=c};function ti(b){si.call(this,b,{mousedown:this.Wi,mousemove:this.Xi,mouseup:this.$i,mouseover:this.Zi,mouseout:this.Yi});this.c=b.c;this.b=[]}v(ti,si);function ui(b,c){for(var d=b.b,e=c.clientX,f=c.clientY,g=0,h=d.length,k;g=Math.abs(e-k[0])&&25>=n)return!0}return!1}function vi(b){var c=wi(b,b.a),d=c.preventDefault;c.preventDefault=function(){b.preventDefault();d()};c.pointerId=1;c.isPrimary=!0;c.pointerType="mouse";return c}l=ti.prototype; -l.Wi=function(b){if(!ui(this,b)){(1).toString()in this.c&&this.cancel(b);var c=vi(b);this.c[(1).toString()]=b;xi(this.a,yi,c,b)}};l.Xi=function(b){if(!ui(this,b)){var c=vi(b);xi(this.a,zi,c,b)}};l.$i=function(b){if(!ui(this,b)){var c=this.c[(1).toString()];c&&c.button===b.button&&(c=vi(b),xi(this.a,Ai,c,b),yb(this.c,(1).toString()))}};l.Zi=function(b){if(!ui(this,b)){var c=vi(b);Bi(this.a,c,b)}};l.Yi=function(b){if(!ui(this,b)){var c=vi(b);Ci(this.a,c,b)}}; -l.cancel=function(b){var c=vi(b);this.a.cancel(c,b);yb(this.c,(1).toString())};function Di(b){si.call(this,b,{MSPointerDown:this.ej,MSPointerMove:this.fj,MSPointerUp:this.ij,MSPointerOut:this.gj,MSPointerOver:this.hj,MSPointerCancel:this.dj,MSGotPointerCapture:this.bj,MSLostPointerCapture:this.cj});this.c=b.c;this.b=["","unavailable","touch","pen","mouse"]}v(Di,si);function Ei(b,c){var d=c;ja(c.a.pointerType)&&(d=wi(c,c.a),d.pointerType=b.b[c.a.pointerType]);return d}l=Di.prototype;l.ej=function(b){this.c[b.a.pointerId]=b;var c=Ei(this,b);xi(this.a,yi,c,b)}; -l.fj=function(b){var c=Ei(this,b);xi(this.a,zi,c,b)};l.ij=function(b){var c=Ei(this,b);xi(this.a,Ai,c,b);yb(this.c,b.a.pointerId)};l.gj=function(b){var c=Ei(this,b);Ci(this.a,c,b)};l.hj=function(b){var c=Ei(this,b);Bi(this.a,c,b)};l.dj=function(b){var c=Ei(this,b);this.a.cancel(c,b);yb(this.c,b.a.pointerId)};l.cj=function(b){this.a.dispatchEvent(new ni("lostpointercapture",b,b.a))};l.bj=function(b){this.a.dispatchEvent(new ni("gotpointercapture",b,b.a))};function Fi(b){si.call(this,b,{pointerdown:this.ql,pointermove:this.rl,pointerup:this.ul,pointerout:this.sl,pointerover:this.tl,pointercancel:this.pl,gotpointercapture:this.li,lostpointercapture:this.Vi})}v(Fi,si);l=Fi.prototype;l.ql=function(b){Gi(this.a,b)};l.rl=function(b){Gi(this.a,b)};l.ul=function(b){Gi(this.a,b)};l.sl=function(b){Gi(this.a,b)};l.tl=function(b){Gi(this.a,b)};l.pl=function(b){Gi(this.a,b)};l.Vi=function(b){Gi(this.a,b)};l.li=function(b){Gi(this.a,b)};function Hi(b,c){si.call(this,b,{touchstart:this.pm,touchmove:this.om,touchend:this.nm,touchcancel:this.mm});this.c=b.c;this.g=c;this.b=void 0;this.e=0;this.d=void 0}v(Hi,si);l=Hi.prototype;l.ng=function(){this.e=0;this.d=void 0}; -function Ii(b,c,d){c=wi(c,d);c.pointerId=d.identifier+2;c.bubbles=!0;c.cancelable=!0;c.detail=b.e;c.button=0;c.buttons=1;c.width=d.webkitRadiusX||d.radiusX||0;c.height=d.webkitRadiusY||d.radiusY||0;c.pressure=d.webkitForce||d.force||.5;c.isPrimary=b.b===d.identifier;c.pointerType="touch";c.clientX=d.clientX;c.clientY=d.clientY;c.screenX=d.screenX;c.screenY=d.screenY;return c} -function Ji(b,c,d){function e(){c.preventDefault()}var f=Array.prototype.slice.call(c.a.changedTouches),g=f.length,h,k;for(h=0;h=c.length){var f=[],g,h,k;for(g=0;g=b.minResolution&&cb.d&&(b.d=e.d),e.bb.c&&(b.c=e.c)):b[c][d]=e:(b[c]={},b[c][d]=e)}function wj(b,c,d){return[c*(Math.round(b[0]/c)+d[0]%2/2),c*(Math.round(b[1]/c)+d[1]%2/2)]} -function xj(b,c,d,e,f,g,h,k,n,p){var q=ma(c).toString();q in b.wantedTiles||(b.wantedTiles[q]={});var r=b.wantedTiles[q];b=b.tileQueue;var s=d.minZoom,u,y,z,A,E,x;for(x=h;x>=s;--x)for(y=fh(d,g,x,y),z=d.na(x),A=y.a;A<=y.d;++A)for(E=y.b;E<=y.c;++E)h-x<=k?(u=c.Vb(x,A,E,e,f),0==u.state&&(r[jf(u.a)]=!0,u.qb()in b.b||yj(b,[u,q,ih(d,u.a),z])),m(n)&&n.call(p,u)):c.Oe(x,A,E)};function zj(b){this.o=b.opacity;this.p=b.rotateWithView;this.i=b.rotation;this.k=b.scale;this.r=b.snapToPixel}l=zj.prototype;l.Ld=function(){return this.o};l.rd=function(){return this.p};l.Md=function(){return this.i};l.Nd=function(){return this.k};l.sd=function(){return this.r};l.Od=function(b){this.i=b};l.Pd=function(b){this.k=b};function Aj(b){b=m(b)?b:{};this.f=m(b.anchor)?b.anchor:[.5,.5];this.d=null;this.c=m(b.anchorOrigin)?b.anchorOrigin:"top-left";this.g=m(b.anchorXUnits)?b.anchorXUnits:"fraction";this.n=m(b.anchorYUnits)?b.anchorYUnits:"fraction";var c=m(b.crossOrigin)?b.crossOrigin:null,d=m(b.img)?b.img:null,e=b.src;m(e)&&0!==e.length||null===d||(e=d.src);var f=m(b.src)?0:2,g=Bj.Pa(),h=g.get(e,c);null===h&&(h=new Cj(d,e,c,f),g.set(e,c,h));this.a=h;this.D=m(b.offset)?b.offset:[0,0];this.b=m(b.offsetOrigin)?b.offsetOrigin: -"top-left";this.e=null;this.q=m(b.size)?b.size:null;zj.call(this,{opacity:m(b.opacity)?b.opacity:1,rotation:m(b.rotation)?b.rotation:0,scale:m(b.scale)?b.scale:1,snapToPixel:m(b.snapToPixel)?b.snapToPixel:!0,rotateWithView:m(b.rotateWithView)?b.rotateWithView:!1})}v(Aj,zj);l=Aj.prototype; -l.wb=function(){if(null!==this.d)return this.d;var b=this.f,c=this.gb();if("fraction"==this.g||"fraction"==this.n){if(null===c)return null;b=this.f.slice();"fraction"==this.g&&(b[0]*=c[0]);"fraction"==this.n&&(b[1]*=c[1])}if("top-left"!=this.c){if(null===c)return null;b===this.f&&(b=this.f.slice());if("top-right"==this.c||"bottom-right"==this.c)b[0]=-b[0]+c[0];if("bottom-left"==this.c||"bottom-right"==this.c)b[1]=-b[1]+c[1]}return this.d=b};l.Bb=function(){return this.a.a};l.kd=function(){return this.a.c}; -l.Pc=function(){return this.a.b};l.Kd=function(){var b=this.a;if(null===b.f)if(b.n){var c=b.c[0],d=b.c[1],e=Nf(c,d);e.fillRect(0,0,c,d);b.f=e.canvas}else b.f=b.a;return b.f};l.Cb=function(){if(null!==this.e)return this.e;var b=this.D;if("top-left"!=this.b){var c=this.gb(),d=this.a.c;if(null===c||null===d)return null;b=b.slice();if("top-right"==this.b||"bottom-right"==this.b)b[0]=d[0]-c[0]-b[0];if("bottom-left"==this.b||"bottom-right"==this.b)b[1]=d[1]-c[1]-b[1]}return this.e=b};l.Gk=function(){return this.a.e}; -l.gb=function(){return null===this.q?this.a.c:this.q};l.we=function(b,c){return w(this.a,"change",b,!1,c)};l.load=function(){this.a.load()};l.Ne=function(b,c){Vc(this.a,"change",b,!1,c)};function Cj(b,c,d,e){hd.call(this);this.f=null;this.a=null===b?new Image:b;null!==d&&(this.a.crossOrigin=d);this.d=null;this.b=e;this.c=null;this.e=c;this.n=!1}v(Cj,hd);Cj.prototype.g=function(){this.b=3;Qa(this.d,Wc);this.d=null;this.dispatchEvent("change")}; -Cj.prototype.i=function(){this.b=2;this.c=[this.a.width,this.a.height];Qa(this.d,Wc);this.d=null;var b=Nf(1,1);b.drawImage(this.a,0,0);try{b.getImageData(0,0,1,1)}catch(c){this.n=!0}this.dispatchEvent("change")};Cj.prototype.load=function(){if(0==this.b){this.b=1;this.d=[Uc(this.a,"error",this.g,!1,this),Uc(this.a,"load",this.i,!1,this)];try{this.a.src=this.e}catch(b){this.g()}}};function Bj(){this.a={};this.c=0}da(Bj);Bj.prototype.clear=function(){this.a={};this.c=0}; -Bj.prototype.get=function(b,c){var d=c+":"+b;return d in this.a?this.a[d]:null};Bj.prototype.set=function(b,c,d){this.a[c+":"+b]=d;++this.c};function Dj(b,c){lc.call(this);this.g=c;this.b=null;this.e={};this.q={}}v(Dj,lc);function Ej(b){var c=b.viewState,d=b.coordinateToPixelMatrix;lj(d,b.size[0]/2,b.size[1]/2,1/c.resolution,-1/c.resolution,-c.rotation,-c.center[0],-c.center[1]);Nd(d,b.pixelToCoordinateMatrix)}l=Dj.prototype;l.P=function(){mb(this.e,pc);Dj.T.P.call(this)}; -function Fj(){var b=Bj.Pa();if(32>1;){var n=2*c+1,p=2*c+2,n=pc;){var h=d-1>>1;if(b[h]>g)e[d]=e[h],b[d]=b[h],d=h;else break}e[d]=f;b[d]=g}function Mj(b){var c=b.e,d=b.a,e=b.c,f=0,g=d.length,h,k,n;for(k=0;k>1)-1;0<=c;c--)Kj(b,c)};function Nj(b,c){Ij.call(this,function(c){return b.apply(null,c)},function(b){return b[0].qb()});this.n=c;this.d=0}v(Nj,Ij);Nj.prototype.g=function(b){b=b.target.state;if(2===b||3===b||4===b)--this.d,this.n()};function Oj(b,c,d){this.d=b;this.b=c;this.e=d;this.a=[];this.c=this.f=0}Oj.prototype.update=function(b,c){this.a.push(b,c,ta())};function Pj(b,c){var d=b.d,e=b.c,f=b.b-e,g=Qj(b);return cf({source:c,duration:g,easing:function(b){return e*(Math.exp(d*b*g)-1)/f}})}function Qj(b){return Math.log(b.b/b.c)/b.d};function Rj(b){qd.call(this);this.k=null;this.d(!0);this.handleEvent=b.handleEvent}v(Rj,qd);Rj.prototype.b=function(){return this.get("active")};Rj.prototype.getActive=Rj.prototype.b;Rj.prototype.d=function(b){this.set("active",b)};Rj.prototype.setActive=Rj.prototype.d;Rj.prototype.setMap=function(b){this.k=b};function Sj(b,c,d,e,f){if(null!=d){var g=c.d(),h=c.b();m(g)&&m(h)&&m(f)&&0d.a.length)d=!1;else{var e=ta()-d.e,f=d.a.length-3;if(d.a[f+2]e;)g-=3;var e=d.a[f+2]-d.a[g+2],h=d.a[f]-d.a[g],f=d.a[f+1]-d.a[g+1];d.f=Math.atan2(f,h);d.c=Math.sqrt(h*h+f*f)/e;d=d.c>d.b}}d&&(d=this.a,d=(d.b-d.c)/d.d,f=this.a.f,g=c.b(),this.g=Pj(this.a,g),b.La(this.g),g=b.e(g),d=b.sa([g[0]-d*Math.cos(f),g[1]-d*Math.sin(f)]),d=c.i(d),c.Ha(d));Ye(c,-1);b.render(); -return!1}this.e=null;return!0}function ik(b){if(0b||0!==this.g&&b<=this.g)return this;var c=b.toString();if(this.e.hasOwnProperty(c))return this.e[c];var d=this.oc(b);if(d.j.lengthf&&(f=g);g=k;h=n}return f}function Bk(b,c,d,e,f){var g,h;g=0;for(h=d.length;gk){for(;cu&&(p=q,u=x)}u>f&&(n[(p-c)/e]=1,s+eU&&ebU)&&(0>Ca&&RCa)||(z[h++]=x,z[h++]=Q,A=x,E=Q);x=N;Q=L}}z[h++]=x;z[h++]=Q}}k.push(h);c=q}return h};function Lk(b,c){rk.call(this);this.b=this.n=-1;this.W(b,c)}v(Lk,rk);l=Lk.prototype;l.clone=function(){var b=new Lk(null);Mk(b,this.a,this.j.slice());return b};l.Ya=function(b,c,d,e){if(eg!=q>g&&f<(p-k)*(g-n)/(q-n)+k&&(h=!h);k=p;n=q}return h}function Rk(b,c,d,e,f,g){if(0===d.length||!Qk(b,c,d[0],e,f,g))return!1;var h;c=1;for(h=d.length;cr&&(p=(p+q)/2,Rk(b,c,d,e,p,s)&&(y=p,r=z));p=q}isNaN(y)&&(y=f[g]);return m(h)?(h.push(y,s),h):[y,s]};function Tk(b,c,d,e,f,g){for(var h=[b[c],b[c+1]],k=[],n;c+e=f[0]&&g[2]<=f[2]||g[1]>=f[1]&&g[3]<=f[3]?!0:Tk(b,c,d,e,function(b,c){var d=!1,e=ae(f,b),g=ae(f,c);if(1===e||1===g)d=!0;else{var r=f[0],s=f[1],u=f[2],y=f[3],z=c[0],A=c[1],E=(A-b[1])/(z-b[0]);g&2&&!(e&2)?(s=z-(A-y)/E,d=s>=r&&s<=u):g&4&&!(e&4)?(r=A-(z-u)*E,d=r>=s&&r<=y):g&8&&!(e&8)?(s=z-(A-s)/E,d=s>=r&&s<=u):g&16&&!(e&16)&&(r=A-(z-r)*E,d=r>=s&&r<=y)}return d}):!1} -function Vk(b,c,d,e,f){var g=d[0];if(!(Uk(b,c,g,e,f)||Qk(b,c,g,e,f[0],f[1])||Qk(b,c,g,e,f[0],f[3])||Qk(b,c,g,e,f[2],f[1])||Qk(b,c,g,e,f[2],f[3])))return!1;if(1===d.length)return!0;c=1;for(g=d.length;cb||this.b.length<=b)return null;var c=new Lk(null);Mk(c,this.a,this.j.slice(0===b?0:this.b[b-1],this.b[b]));return c};l.ld=function(){var b=this.a,c=this.j,d=this.b,e=[],f=0,g,h;g=0;for(h=d.length;gf;++f)e[f]=c.charCodeAt(d++)|c.charCodeAt(d++)<<8|c.charCodeAt(d++)<<16|c.charCodeAt(d++)<<24;else for(f=0;16>f;++f)e[f]=c[d++]|c[d++]<<8|c[d++]<<16|c[d++]<<24;c=b.a[0];d=b.a[1];var f=b.a[2],g=b.a[3],h=0,h=c+(g^d&(f^g))+e[0]+3614090360&4294967295;c=d+(h<<7&4294967295|h>>>25);h=g+(f^c&(d^f))+e[1]+3905402710&4294967295;g=c+(h<<12&4294967295|h>>>20);h=f+(d^g&(c^d))+e[2]+606105819&4294967295;f=g+(h<<17&4294967295|h>>>15);h=d+(c^f&(g^ +l.scale=function(b,c){var d=ja(c)?c:b;this.left*=b;this.right*=b;this.top*=d;this.bottom*=d;return this};function $g(b,c,d,e){this.left=b;this.top=c;this.width=d;this.height=e}l=$g.prototype;l.clone=function(){return new $g(this.left,this.top,this.width,this.height)};l.contains=function(b){return b instanceof $g?this.left<=b.left&&this.left+this.width>=b.left+b.width&&this.top<=b.top&&this.top+this.height>=b.top+b.height:b.x>=this.left&&b.x<=this.left+this.width&&b.y>=this.top&&b.y<=this.top+this.height}; +l.distance=function(b){var c=b.xb.g}function vh(b,c){for(var d,e;uh(b)&&!(d=b.a.zc,e=d.a[0].toString(),e in c&&c[e].contains(d.a));)b.pop().Ec()};function wh(b,c){cd.call(this);this.a=b;this.state=c}y(wh,cd);function xh(b){b.o("change")}wh.prototype.tb=function(){return w(this).toString()};wh.prototype.f=function(){return this.a};function yh(b){id.call(this);this.f=Fe(b.projection);this.j=void 0!==b.attributions?b.attributions:null;this.U=b.logo;this.A=void 0!==b.state?b.state:"ready";this.S=void 0!==b.wrapX?b.wrapX:!1}y(yh,id);l=yh.prototype;l.xe=wa;l.sa=function(){return this.j};l.qa=function(){return this.U};l.ta=function(){return this.f};l.ua=function(){return this.A};function zh(b){return b.S}l.na=function(b){this.j=b;this.s()};function Ah(b,c){b.A=c;b.s()};function Bh(b){this.minZoom=void 0!==b.minZoom?b.minZoom:0;this.a=b.resolutions;this.maxZoom=this.a.length-1;this.b=void 0!==b.origin?b.origin:null;this.g=null;void 0!==b.origins&&(this.g=b.origins);var c=b.extent;void 0===c||this.b||this.g||(this.b=he(c));this.j=null;void 0!==b.tileSizes&&(this.j=b.tileSizes);this.l=void 0!==b.tileSize?b.tileSize:this.j?null:256;this.u=void 0!==c?c:null;this.c=null;void 0!==b.sizes?this.c=b.sizes.map(function(b){return new gg(Math.min(0,b[0]),Math.max(b[0]-1,-1), +Math.min(0,b[1]),Math.max(b[1]-1,-1))},this):c&&Ch(this,c);this.f=[0,0]}var Dh=[0,0,0];function Eh(b,c,d,e,f){f=b.Aa(c,f);for(c=c[0]-1;c>=b.minZoom;){if(d.call(null,c,Fh(b,f,c,e)))return!0;--c}return!1}l=Bh.prototype;l.J=function(){return this.u};l.Cg=function(){return this.maxZoom};l.Dg=function(){return this.minZoom};l.Ca=function(b){return this.b?this.b:this.g[b]};l.$=function(b){return this.a[b]};l.wh=function(){return this.a}; +function Gh(b,c,d,e){return c[0]f||f>d.maxZoom)d=!1;else{var g=d.J();d=(d=g?Fh(d,g,f):d.c?d.c[f]:null)?hg(d,e,b):!0}return d?c:null}l.Xf=wa;function Sh(b,c){vc.call(this,b);this.tile=c}y(Sh,vc);function Th(b){b=b?b:{};this.D=Kg("UL");this.A=Kg("LI");this.D.appendChild(this.A);ih(this.A,!1);this.b=void 0!==b.collapsed?b.collapsed:!0;this.i=void 0!==b.collapsible?b.collapsible:!0;this.i||(this.b=!1);var c=b.className?b.className:"ol-attribution",d=b.tipLabel?b.tipLabel:"Attributions",e=b.collapseLabel?b.collapseLabel:"\u00bb";this.G=ia(e)?Hg("SPAN",{},e):e;e=b.label?b.label:"i";this.S=ia(e)?Hg("SPAN",{},e):e;d=Hg("BUTTON",{type:"button",title:d},this.i&&!this.b?this.G:this.S);C(d,"click", +this.Ll,!1,this);C(d,["mouseout",yc],function(){this.blur()},!1);c=Hg("DIV",c+" ol-unselectable ol-control"+(this.b&&this.i?" ol-collapsed":"")+(this.i?"":" ol-uncollapsible"),this.D,d);qh.call(this,{element:c,render:b.render?b.render:Uh,target:b.target});this.C=!0;this.l={};this.j={};this.T={}}y(Th,qh); +function Uh(b){if(b=b.frameState){var c,d,e,f,g,h,k,m,n,p,q,r=b.layerStatesArray,t=Ub(b.attributions),x={},z=b.viewState.projection;d=0;for(c=r.length;dla.f)if(lg(G,new gg(pd(K.a,Ea),pd(K.f,Ea),K.c,K.b))||kg(K)>Ea&&lg(G,la)){q=!0;break a}}q=!1}else q=!0}}else q=!1;q?(m in x&&delete x[m],t[m]=k):x[m]=k}c=[t,x];d=c[0];c=c[1];for(var L in this.l)L in d?(this.j[L]||(ih(this.l[L],!0),this.j[L]=!0),delete d[L]):L in c?(this.j[L]&&(ih(this.l[L],!1),delete this.j[L]),delete c[L]):(Og(this.l[L]),delete this.l[L],delete this.j[L]);for(L in d)e=Kg("LI"),e.innerHTML=d[L].c,this.D.appendChild(e),this.l[L]=e,this.j[L]=!0;for(L in c)e= +Kg("LI"),e.innerHTML=c[L].c,ih(e,!1),this.D.appendChild(e),this.l[L]=e;L=!Qb(this.j)||!Qb(b.logos);this.C!=L&&(ih(this.element,L),this.C=L);L&&Qb(this.j)?Wg(this.element,"ol-logo-only"):Xg(this.element,"ol-logo-only");var za;b=b.logos;L=this.T;for(za in L)za in b||(Og(L[za]),delete L[za]);for(var Ra in b)Ra in L||(za=new Image,za.src=Ra,d=b[Ra],""===d?d=za:(d=Hg("A",{href:d}),d.appendChild(za)),this.A.appendChild(d),L[Ra]=d);ih(this.A,!Qb(b))}else this.C&&(ih(this.element,!1),this.C=!1)}l=Th.prototype; +l.Ll=function(b){b.preventDefault();Vh(this)};function Vh(b){Yg(b.element,"ol-collapsed");b.b?Pg(b.G,b.S):Pg(b.S,b.G);b.b=!b.b}l.Kl=function(){return this.i};l.Nl=function(b){this.i!==b&&(this.i=b,Yg(this.element,"ol-uncollapsible"),!b&&this.b&&Vh(this))};l.Ml=function(b){this.i&&this.b!==b&&Vh(this)};l.Jl=function(){return this.b};function Wh(b){b=b?b:{};var c=b.className?b.className:"ol-rotate",d=b.label?b.label:"\u21e7";this.b=null;ia(d)?this.b=Hg("SPAN","ol-compass",d):(this.b=d,Wg(this.b,"ol-compass"));d=Hg("BUTTON",{"class":c+"-reset",type:"button",title:b.tipLabel?b.tipLabel:"Reset rotation"},this.b);C(d,"click",Wh.prototype.A,!1,this);c=Hg("DIV",c+" ol-unselectable ol-control",d);qh.call(this,{element:c,render:b.render?b.render:Xh,target:b.target});this.i=b.duration?b.duration:250;this.j=void 0!==b.autoHide?b.autoHide: +!0;this.l=void 0;this.j&&Wg(this.element,"ol-hidden")}y(Wh,qh);Wh.prototype.A=function(b){b.preventDefault();b=this.a;var c=b.aa();if(c){var d=c.Ea();void 0!==d&&(0Math.PI&&(d-=2*Math.PI),b.Ma(ag({rotation:d,duration:this.i,easing:Vf}))),c.te(0))}}; +function Xh(b){if(b=b.frameState){b=b.viewState.rotation;if(b!=this.l){var c="rotate("+b+"rad)";if(this.j){var d=this.element;0===b?Wg(d,"ol-hidden"):Xg(d,"ol-hidden")}this.b.style.msTransform=c;this.b.style.webkitTransform=c;this.b.style.transform=c}this.l=b}};function Yh(b){b=b?b:{};var c=b.className?b.className:"ol-zoom",d=b.delta?b.delta:1,e=b.zoomOutLabel?b.zoomOutLabel:"\u2212",f=b.zoomOutTipLabel?b.zoomOutTipLabel:"Zoom out",g=Hg("BUTTON",{"class":c+"-in",type:"button",title:b.zoomInTipLabel?b.zoomInTipLabel:"Zoom in"},b.zoomInLabel?b.zoomInLabel:"+");C(g,"click",sa(Yh.prototype.j,d),!1,this);e=Hg("BUTTON",{"class":c+"-out",type:"button",title:f},e);C(e,"click",sa(Yh.prototype.j,-d),!1,this);c=Hg("DIV",c+" ol-unselectable ol-control",g,e);qh.call(this, +{element:c,target:b.target});this.b=void 0!==b.duration?b.duration:250}y(Yh,qh);Yh.prototype.j=function(b,c){c.preventDefault();var d=this.a,e=d.aa();if(e){var f=e.$();f&&(02*this.b&&si(this),!0):!1};function si(b){if(b.b!=b.a.length){for(var c=0,d=0;c=b||96<=b&&106>=b||65<=b&&90>=b||(bc||$b)&&0==b)return!0;switch(b){case 32:case 43:case 63:case 64:case 107:case 109:case 110:case 111:case 186:case 59:case 189:case 187:case 61:case 188:case 190:case 191:case 192:case 222:case 219:case 220:case 221:return!0;default:return!1}}function yi(b){if(ac)b=zi(b);else if(cc&&bc)a:switch(b){case 93:b=91;break a}return b} +function zi(b){switch(b){case 61:return 187;case 59:return 186;case 173:return 189;case 224:return 91;case 0:return 224;default:return b}};function Ai(b,c){cd.call(this);b&&Bi(this,b,c)}y(Ai,cd);l=Ai.prototype;l.ud=null;l.le=null;l.qf=null;l.me=null;l.ib=-1;l.Zb=-1;l.bf=!1; +var Ci={3:13,12:144,63232:38,63233:40,63234:37,63235:39,63236:112,63237:113,63238:114,63239:115,63240:116,63241:117,63242:118,63243:119,63244:120,63245:121,63246:122,63247:123,63248:44,63272:46,63273:36,63275:35,63276:33,63277:34,63289:144,63302:45},Di={Up:38,Down:40,Left:37,Right:39,Enter:13,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,"U+007F":46,Home:36,End:35,PageUp:33,PageDown:34,Insert:45},Ei=Zb||$b||bc&&jc("525"),Fi=cc&∾ +Ai.prototype.a=function(b){if(bc||$b)if(17==this.ib&&!b.B||18==this.ib&&!b.c||cc&&91==this.ib&&!b.A)this.Zb=this.ib=-1;-1==this.ib&&(b.B&&17!=b.j?this.ib=17:b.c&&18!=b.j?this.ib=18:b.A&&91!=b.j&&(this.ib=91));Ei&&!wi(b.j,this.ib,b.f,b.B,b.c)?this.handleEvent(b):(this.Zb=yi(b.j),Fi&&(this.bf=b.c))};Ai.prototype.c=function(b){this.Zb=this.ib=-1;this.bf=b.c}; +Ai.prototype.handleEvent=function(b){var c=b.a,d,e,f=c.altKey;Zb&&"keypress"==b.type?(d=this.Zb,e=13!=d&&27!=d?c.keyCode:0):(bc||$b)&&"keypress"==b.type?(d=this.Zb,e=0<=c.charCode&&63232>c.charCode&&xi(d)?c.charCode:0):Yb&&!bc?(d=this.Zb,e=xi(d)?c.keyCode:0):(d=c.keyCode||this.Zb,e=c.charCode||0,Fi&&(f=this.bf),cc&&63==e&&224==d&&(d=191));var g=d=yi(d),h=c.keyIdentifier;d?63232<=d&&d in Ci?g=Ci[d]:25==d&&b.f&&(g=9):h&&h in Di&&(g=Di[h]);this.ib=g;b=new Gi(g,e,0,c);b.c=f;this.o(b)}; +function Bi(b,c,d){b.me&&Hi(b);b.ud=c;b.le=C(b.ud,"keypress",b,d);b.qf=C(b.ud,"keydown",b.a,d,b);b.me=C(b.ud,"keyup",b.c,d,b)}function Hi(b){b.le&&(Zc(b.le),Zc(b.qf),Zc(b.me),b.le=null,b.qf=null,b.me=null);b.ud=null;b.ib=-1;b.Zb=-1}Ai.prototype.X=function(){Ai.da.X.call(this);Hi(this)};function Gi(b,c,d,e){Ac.call(this,e);this.type="key";this.j=b;this.u=c}y(Gi,Ac);function Ii(b,c){cd.call(this);var d=this.a=b;(d=ma(d)&&1==d.nodeType?this.a:this.a?this.a.body:null)&&bh(d,"direction");this.c=C(this.a,ac?"DOMMouseScroll":"mousewheel",this,c)}y(Ii,cd); +Ii.prototype.handleEvent=function(b){var c=0,d=0;b=b.a;if("mousewheel"==b.type){c=1;if(Zb||bc&&(dc||jc("532.0")))c=40;d=Ji(-b.wheelDelta,c);c=ca(b.wheelDeltaX)?Ji(-b.wheelDeltaY,c):d}else d=b.detail,100d&&(d=-3),ca(b.axis)&&b.axis===b.HORIZONTAL_AXIS||(c=d);ja(this.b)&&(c=Math.min(Math.max(c,-this.b),this.b));d=new Ki(d,b,0,c);this.o(d)};function Ji(b,c){return bc&&(cc||ec)&&0!=b%c?b:b/c}Ii.prototype.X=function(){Ii.da.X.call(this);Zc(this.c);this.c=null}; +function Ki(b,c,d,e){Ac.call(this,c);this.type="mousewheel";this.detail=b;this.C=e}y(Ki,Ac);function Li(b,c,d){vc.call(this,b);this.a=c;b=d?d:{};this.buttons=Mi(b);this.pressure=Ni(b,this.buttons);this.bubbles="bubbles"in b?b.bubbles:!1;this.cancelable="cancelable"in b?b.cancelable:!1;this.view="view"in b?b.view:null;this.detail="detail"in b?b.detail:null;this.screenX="screenX"in b?b.screenX:0;this.screenY="screenY"in b?b.screenY:0;this.clientX="clientX"in b?b.clientX:0;this.clientY="clientY"in b?b.clientY:0;this.button="button"in b?b.button:0;this.relatedTarget="relatedTarget"in b?b.relatedTarget: +null;this.pointerId="pointerId"in b?b.pointerId:0;this.width="width"in b?b.width:0;this.height="height"in b?b.height:0;this.pointerType="pointerType"in b?b.pointerType:"";this.isPrimary="isPrimary"in b?b.isPrimary:!1;c.preventDefault&&(this.preventDefault=function(){c.preventDefault()})}y(Li,vc);function Mi(b){if(b.buttons||Oi)b=b.buttons;else switch(b.which){case 1:b=1;break;case 2:b=4;break;case 3:b=2;break;default:b=0}return b} +function Ni(b,c){var d=0;b.pressure?d=b.pressure:d=c?.5:0;return d}var Oi=!1;try{Oi=1===(new MouseEvent("click",{buttons:1})).buttons}catch(b){};function Pi(b,c){var d=Kg("CANVAS");b&&(d.width=b);c&&(d.height=c);return d.getContext("2d")} +var Qi=function(){var b;return function(){if(void 0===b)if(ba.getComputedStyle){var c=Kg("P"),d,e={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};document.body.appendChild(c);for(var f in e)f in c.style&&(c.style[f]="translate(1px,1px)",d=ba.getComputedStyle(c).getPropertyValue(e[f]));Og(c);b=d&&"none"!==d}else b=!1;return b}}(),Ri=function(){var b;return function(){if(void 0===b)if(ba.getComputedStyle){var c= +Kg("P"),d,e={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};document.body.appendChild(c);for(var f in e)f in c.style&&(c.style[f]="translate3d(1px,1px,1px)",d=ba.getComputedStyle(c).getPropertyValue(e[f]));Og(c);b=d&&"none"!==d}else b=!1;return b}}();function Si(b,c){var d=b.style;d.WebkitTransform=c;d.MozTransform=c;d.a=c;d.msTransform=c;d.transform=c;Zb&&jc("9.0")&&(b.style.transformOrigin="0 0")} +function Ti(b,c){var d;if(Ri()){var e=Array(16);for(d=0;16>d;++d)e[d]=c[d].toFixed(6);Si(b,"matrix3d("+e.join(",")+")")}else if(Qi()){var e=[c[0],c[1],c[4],c[5],c[12],c[13]],f=Array(6);for(d=0;6>d;++d)f[d]=e[d].toFixed(6);Si(b,"matrix("+f.join(",")+")")}else b.style.left=Math.round(c[12])+"px",b.style.top=Math.round(c[13])+"px"};var Ui=["experimental-webgl","webgl","webkit-3d","moz-webgl"];function Vi(b,c){var d,e,f=Ui.length;for(e=0;e=Math.abs(e-k[0])&&25>=m)return!0}return!1}function lj(b){var c=mj(b,b.a),d=c.preventDefault;c.preventDefault=function(){b.preventDefault();d()};c.pointerId=1;c.isPrimary=!0;c.pointerType="mouse";return c}l=jj.prototype; +l.el=function(b){if(!kj(this,b)){(1).toString()in this.c&&this.cancel(b);var c=lj(b);this.c[(1).toString()]=b;nj(this.a,oj,c,b)}};l.fl=function(b){if(!kj(this,b)){var c=lj(b);nj(this.a,pj,c,b)}};l.il=function(b){if(!kj(this,b)){var c=this.c[(1).toString()];c&&c.button===b.button&&(c=lj(b),nj(this.a,qj,c,b),delete this.c[(1).toString()])}};l.hl=function(b){if(!kj(this,b)){var c=lj(b);rj(this.a,c,b)}};l.gl=function(b){if(!kj(this,b)){var c=lj(b);sj(this.a,c,b)}}; +l.cancel=function(b){var c=lj(b);this.a.cancel(c,b);delete this.c[(1).toString()]};function tj(b){ij.call(this,b,{MSPointerDown:this.nl,MSPointerMove:this.ol,MSPointerUp:this.rl,MSPointerOut:this.pl,MSPointerOver:this.ql,MSPointerCancel:this.ml,MSGotPointerCapture:this.kl,MSLostPointerCapture:this.ll});this.c=b.c;this.b=["","unavailable","touch","pen","mouse"]}y(tj,ij);function uj(b,c){var d=c;ja(c.a.pointerType)&&(d=mj(c,c.a),d.pointerType=b.b[c.a.pointerType]);return d}l=tj.prototype;l.nl=function(b){this.c[b.a.pointerId.toString()]=b;var c=uj(this,b);nj(this.a,oj,c,b)}; +l.ol=function(b){var c=uj(this,b);nj(this.a,pj,c,b)};l.rl=function(b){var c=uj(this,b);nj(this.a,qj,c,b);delete this.c[b.a.pointerId.toString()]};l.pl=function(b){var c=uj(this,b);sj(this.a,c,b)};l.ql=function(b){var c=uj(this,b);rj(this.a,c,b)};l.ml=function(b){var c=uj(this,b);this.a.cancel(c,b);delete this.c[b.a.pointerId.toString()]};l.ll=function(b){this.a.o(new Li("lostpointercapture",b,b.a))};l.kl=function(b){this.a.o(new Li("gotpointercapture",b,b.a))};function vj(b){ij.call(this,b,{pointerdown:this.Vn,pointermove:this.Wn,pointerup:this.Zn,pointerout:this.Xn,pointerover:this.Yn,pointercancel:this.Un,gotpointercapture:this.rk,lostpointercapture:this.dl})}y(vj,ij);l=vj.prototype;l.Vn=function(b){wj(this.a,b)};l.Wn=function(b){wj(this.a,b)};l.Zn=function(b){wj(this.a,b)};l.Xn=function(b){wj(this.a,b)};l.Yn=function(b){wj(this.a,b)};l.Un=function(b){wj(this.a,b)};l.dl=function(b){wj(this.a,b)};l.rk=function(b){wj(this.a,b)};function xj(b,c){ij.call(this,b,{touchstart:this.ap,touchmove:this.$o,touchend:this.Zo,touchcancel:this.Yo});this.c=b.c;this.i=c;this.b=void 0;this.j=0;this.f=void 0}y(xj,ij);l=xj.prototype;l.Ph=function(){this.j=0;this.f=void 0}; +function yj(b,c,d){c=mj(c,d);c.pointerId=d.identifier+2;c.bubbles=!0;c.cancelable=!0;c.detail=b.j;c.button=0;c.buttons=1;c.width=d.webkitRadiusX||d.radiusX||0;c.height=d.webkitRadiusY||d.radiusY||0;c.pressure=d.webkitForce||d.force||.5;c.isPrimary=b.b===d.identifier;c.pointerType="touch";c.clientX=d.clientX;c.clientY=d.clientY;c.screenX=d.screenX;c.screenY=d.screenY;return c} +function zj(b,c,d){function e(){c.preventDefault()}var f=Array.prototype.slice.call(c.a.changedTouches),g=f.length,h,k;for(h=0;h=c.length){var f=[],g,h,k;for(g=0;g=b.minResolution&&cb.f&&(b.f=e.f),e.cb.b&&(b.b=e.b)):b[c][d]=e:(b[c]={},b[c][d]=e)}function sk(b,c,d){return[c*(Math.round(b[0]/c)+d[0]%2/2),c*(Math.round(b[1]/c)+d[1]%2/2)]} +function tk(b,c,d,e,f,g,h,k,m,n){var p=w(c).toString();p in b.wantedTiles||(b.wantedTiles[p]={});var q=b.wantedTiles[p];b=b.tileQueue;var r=d.minZoom,t,x,z,B,A,v;for(v=h;v>=r;--v)for(x=Fh(d,g,v,x),z=d.$(v),B=x.a;B<=x.f;++B)for(A=x.c;A<=x.b;++A)h-v<=k?(t=c.Ob(v,B,A,e,f),0==t.state&&(q[fg(t.a)]=!0,t.tb()in b.b||uk(b,[t,p,Jh(d,t.a),z])),void 0!==m&&m.call(n,t)):c.Xf(v,B,A,f)};function vk(b){this.A=b.opacity;this.D=b.rotateWithView;this.u=b.rotation;this.i=b.scale;this.G=b.snapToPixel}l=vk.prototype;l.Ae=function(){return this.A};l.ce=function(){return this.D};l.Be=function(){return this.u};l.Ce=function(){return this.i};l.de=function(){return this.G};l.De=function(b){this.A=b};l.Ee=function(b){this.u=b};l.Fe=function(b){this.i=b};function wk(b){b=b||{};this.g=void 0!==b.anchor?b.anchor:[.5,.5];this.f=null;this.c=void 0!==b.anchorOrigin?b.anchorOrigin:"top-left";this.l=void 0!==b.anchorXUnits?b.anchorXUnits:"fraction";this.B=void 0!==b.anchorYUnits?b.anchorYUnits:"fraction";var c=void 0!==b.crossOrigin?b.crossOrigin:null,d=void 0!==b.img?b.img:null,e=void 0!==b.imgSize?b.imgSize:null,f=b.src;void 0!==f&&0!==f.length||!d||(f=d.src);var g=void 0!==b.src?0:2,h=xk.Yb(),k=h.get(f,c);k||(k=new yk(d,f,e,c,g),h.set(f,c,k));this.a= +k;this.ia=void 0!==b.offset?b.offset:[0,0];this.b=void 0!==b.offsetOrigin?b.offsetOrigin:"top-left";this.j=null;this.C=void 0!==b.size?b.size:null;vk.call(this,{opacity:void 0!==b.opacity?b.opacity:1,rotation:void 0!==b.rotation?b.rotation:0,scale:void 0!==b.scale?b.scale:1,snapToPixel:void 0!==b.snapToPixel?b.snapToPixel:!0,rotateWithView:void 0!==b.rotateWithView?b.rotateWithView:!1})}y(wk,vk);l=wk.prototype; +l.Xb=function(){if(this.f)return this.f;var b=this.g,c=this.Bb();if("fraction"==this.l||"fraction"==this.B){if(!c)return null;b=this.g.slice();"fraction"==this.l&&(b[0]*=c[0]);"fraction"==this.B&&(b[1]*=c[1])}if("top-left"!=this.c){if(!c)return null;b===this.g&&(b=this.g.slice());if("top-right"==this.c||"bottom-right"==this.c)b[0]=-b[0]+c[0];if("bottom-left"==this.c||"bottom-right"==this.c)b[1]=-b[1]+c[1]}return this.f=b};l.fc=function(){return this.a.a};l.qd=function(){return this.a.b};l.Bd=function(){return this.a.c}; +l.ze=function(){var b=this.a;if(!b.g)if(b.l){var c=b.b[0],d=b.b[1],e=Pi(c,d);e.fillRect(0,0,c,d);b.g=e.canvas}else b.g=b.a;return b.g};l.Ca=function(){if(this.j)return this.j;var b=this.ia;if("top-left"!=this.b){var c=this.Bb(),d=this.a.b;if(!c||!d)return null;b=b.slice();if("top-right"==this.b||"bottom-right"==this.b)b[0]=d[0]-c[0]-b[0];if("bottom-left"==this.b||"bottom-right"==this.b)b[1]=d[1]-c[1]-b[1]}return this.j=b};l.fn=function(){return this.a.j};l.Bb=function(){return this.C?this.C:this.a.b}; +l.sf=function(b,c){return C(this.a,"change",b,!1,c)};l.load=function(){this.a.load()};l.Wf=function(b,c){Yc(this.a,"change",b,!1,c)};function yk(b,c,d,e,f){cd.call(this);this.g=null;this.a=b?b:new Image;null!==e&&(this.a.crossOrigin=e);this.f=null;this.c=f;this.b=d;this.j=c;this.l=!1;2==this.c&&zk(this)}y(yk,cd);function zk(b){var c=Pi(1,1);try{c.drawImage(b.a,0,0),c.getImageData(0,0,1,1)}catch(d){b.l=!0}}yk.prototype.i=function(){this.c=3;this.f.forEach(Zc);this.f=null;this.o("change")}; +yk.prototype.B=function(){this.c=2;this.b=[this.a.width,this.a.height];this.f.forEach(Zc);this.f=null;zk(this);this.o("change")};yk.prototype.load=function(){if(0==this.c){this.c=1;this.f=[Xc(this.a,"error",this.i,!1,this),Xc(this.a,"load",this.B,!1,this)];try{this.a.src=this.j}catch(b){this.i()}}};function xk(){this.a={};this.c=0}ea(xk);xk.prototype.clear=function(){this.a={};this.c=0};xk.prototype.get=function(b,c){var d=c+":"+b;return d in this.a?this.a[d]:null}; +xk.prototype.set=function(b,c,d){this.a[c+":"+b]=d;++this.c};function Ak(b,c){pc.call(this);this.j=c;this.f={};this.u={}}y(Ak,pc);function Bk(b){var c=b.viewState,d=b.coordinateToPixelMatrix;ik(d,b.size[0]/2,b.size[1]/2,1/c.resolution,-1/c.resolution,-c.rotation,-c.center[0],-c.center[1]);Jd(d,b.pixelToCoordinateMatrix)}l=Ak.prototype;l.X=function(){Ib(this.f,uc);Ak.da.X.call(this)}; +function Ck(){var b=xk.Yb();if(32q[2])m=[t+r*Math.ceil((q[0]-t)/r),b[1]]}q=c.layerStatesArray;for(r=q.length-1;0<=r;--r){var t=q[r],x=t.layer;if(!t.rb||fk(t,n)&&f.call(g,x)){var z=Dk(this,x);x.fa()&&(k=z.Za(zh(x.fa())?m:b,c,t.rb?d:h,e));if(k)return k}}}; +l.jh=function(b,c,d,e,f,g){var h,k=c.viewState.resolution,m=c.layerStatesArray,n;for(n=m.length-1;0<=n;--n){h=m[n];var p=h.layer;if(fk(h,k)&&f.call(g,p)&&(h=Dk(this,p).sc(b,c,d,e)))return h}};l.kh=function(b,c,d,e){return void 0!==this.Af(b,c,ue,this,d,e)};function Dk(b,c){var d=w(c).toString();if(d in b.f)return b.f[d];var e=b.gf(c);b.f[d]=e;b.u[d]=C(e,"change",b.Dk,!1,b);return e}l.Dk=function(){this.j.render()};l.Me=wa; +l.Do=function(b,c){for(var d in this.f)if(!(c&&d in c.layerStates)){var e=d,f=this.f[e];delete this.f[e];Zc(this.u[e]);delete this.u[e];uc(f)}};function Ek(b,c){for(var d in b.f)if(!(d in c.layerStates)){c.postRenderFunctions.push(ra(b.Do,b));break}}function rb(b,c){return b.zIndex-c.zIndex};function Fk(b,c){this.i=b;this.g=c;this.a=[];this.c=[];this.b={}}Fk.prototype.clear=function(){this.a.length=0;this.c.length=0;Rb(this.b)};function Gk(b){var c=b.a,d=b.c,e=c[0];1==c.length?(c.length=0,d.length=0):(c[0]=c.pop(),d[0]=d.pop(),Hk(b,0));c=b.g(e);delete b.b[c];return e}function uk(b,c){var d=b.i(c);Infinity!=d&&(b.a.push(c),b.c.push(d),b.b[b.g(c)]=!0,Ik(b,0,b.a.length-1))}Fk.prototype.nc=function(){return this.a.length};Fk.prototype.Ka=function(){return 0===this.a.length}; +function Hk(b,c){for(var d=b.a,e=b.c,f=d.length,g=d[c],h=e[c],k=c;c>1;){var m=2*c+1,n=2*c+2,m=nc;){var h=d-1>>1;if(b[h]>g)e[d]=e[h],b[d]=b[h],d=h;else break}e[d]=f;b[d]=g}function Jk(b){var c=b.i,d=b.a,e=b.c,f=0,g=d.length,h,k,m;for(k=0;k>1)-1;0<=c;c--)Hk(b,c)};function Kk(b,c){Fk.call(this,function(c){return b.apply(null,c)},function(b){return b[0].tb()});this.l=c;this.f=0}y(Kk,Fk);Kk.prototype.j=function(b){b=b.target;var c=b.state;if(2===c||3===c||4===c)Yc(b,"change",this.j,!1,this),--this.f,this.l()};function Lk(b,c,d){for(var e=0,f;b.fd.a.length)d=!1;else{var e=Date.now()-d.j,f=d.a.length-3;if(d.a[f+2]e;)g-=3;var e=d.a[f+2]-d.a[g+2],h=d.a[f]-d.a[g],f=d.a[f+1]-d.a[g+1];d.g=Math.atan2(f,h);d.c=Math.sqrt(h*h+f*f)/e;d=d.c>d.b}}d&&(d=this.a,d=(d.b-d.c)/d.f,f=this.a.g,g=c.Ta(),this.i=Nk(this.a,g),b.Ma(this.i),g=b.Oa(g),d=b.Fa([g[0]-d*Math.cos(f),g[1]-d*Math.sin(f)]),d=c.Wd(d),c.jb(d));Tf(c,-1);b.render(); +return!1}this.f=null;return!0}function el(b){if(0this.D&&(this.a=!0));this.i=d;b=b.map;d=fh(b.a);e=cl(this.j);e[0]-=d.x;e[1]-=d.y;this.f=b.Fa(e);this.a&&(d=b.aa(),e=d.Ea(),b.render(),Pk(b,d,e+c,this.f))}function El(b){if(2>this.j.length){b=b.map;var c=b.aa();Tf(c,-1);if(this.a){var d=c.Ea(),e=this.f,f=this.A,d=c.constrainRotation(d,0);Pk(b,c,d,e,f)}return!1}return!0} +function Cl(b){return 2<=this.j.length?(b=b.map,this.f=null,this.i=void 0,this.a=!1,this.l=0,this.C||Tf(b.aa(),1),b.render(),!0):!1}Bl.prototype.xc=te;function Fl(b){al.call(this,{handleDownEvent:Gl,handleDragEvent:Hl,handleUpEvent:Il});b=b?b:{};this.f=null;this.l=void 0!==b.duration?b.duration:400;this.a=void 0;this.i=1}y(Fl,al);function Hl(b){var c=1,d=this.j[0],e=this.j[1],f=d.clientX-e.clientX,d=d.clientY-e.clientY,f=Math.sqrt(f*f+d*d);void 0!==this.a&&(c=this.a/f);this.a=f;1!=c&&(this.i=c);b=b.map;var f=b.aa(),d=f.$(),e=fh(b.a),g=cl(this.j);g[0]-=e.x;g[1]-=e.y;this.f=b.Fa(g);b.render();Rk(b,f,d*c,this.f)} +function Il(b){if(2>this.j.length){b=b.map;var c=b.aa();Tf(c,-1);var d=c.$(),e=this.f,f=this.l,d=c.constrainResolution(d,0,this.i-1);Rk(b,c,d,e,f);return!1}return!0}function Gl(b){return 2<=this.j.length?(b=b.map,this.f=null,this.a=void 0,this.i=1,this.C||Tf(b.aa(),1),b.render(),!0):!1}Fl.prototype.xc=te;function Jl(b){b=b?b:{};var c=new og,d=new Mk(-.005,.05,100);(void 0!==b.altShiftDragRotate?b.altShiftDragRotate:1)&&c.push(new hl);(void 0!==b.doubleClickZoom?b.doubleClickZoom:1)&&c.push(new Sk({delta:b.zoomDelta,duration:b.zoomDuration}));(void 0!==b.dragPan?b.dragPan:1)&&c.push(new dl({kinetic:d}));(void 0!==b.pinchRotate?b.pinchRotate:1)&&c.push(new Bl);(void 0!==b.pinchZoom?b.pinchZoom:1)&&c.push(new Fl({duration:b.zoomDuration}));if(void 0!==b.keyboard?b.keyboard:1)c.push(new vl),c.push(new xl({delta:b.zoomDelta, +duration:b.zoomDuration}));(void 0!==b.mouseWheelZoom?b.mouseWheelZoom:1)&&c.push(new zl({duration:b.zoomDuration}));(void 0!==b.shiftDragZoom?b.shiftDragZoom:1)&&c.push(new ul({duration:b.zoomDuration}));return c};function Kl(b){var c=b||{};b=Ub(c);delete b.layers;c=c.layers;ak.call(this,b);this.b=[];this.a={};C(this,kd("layers"),this.Fk,!1,this);c?ga(c)&&(c=new og(c.slice())):c=new og;this.gh(c)}y(Kl,ak);l=Kl.prototype;l.he=function(){this.qb()&&this.s()}; +l.Fk=function(){this.b.forEach(Zc);this.b.length=0;var b=this.Pc();this.b.push(C(b,"add",this.Ek,!1,this),C(b,"remove",this.Gk,!1,this));Ib(this.a,function(b){b.forEach(Zc)});Rb(this.a);var b=b.a,c,d,e;c=0;for(d=b.length;cf;++f)e[f]=c.charCodeAt(d++)|c.charCodeAt(d++)<<8|c.charCodeAt(d++)<<16|c.charCodeAt(d++)<<24;else for(f=0;16>f;++f)e[f]=c[d++]|c[d++]<<8|c[d++]<<16|c[d++]<<24;c=b.a[0];d=b.a[1];var f=b.a[2],g=b.a[3],h=0,h=c+(g^d&(f^g))+e[0]+3614090360&4294967295;c=d+(h<<7&4294967295|h>>>25);h=g+(f^c&(d^f))+e[1]+3905402710&4294967295;g=c+(h<<12&4294967295|h>>>20);h=f+(d^g&(c^d))+e[2]+606105819&4294967295;f=g+(h<<17&4294967295|h>>>15);h=d+(c^f&(g^ c))+e[3]+3250441966&4294967295;d=f+(h<<22&4294967295|h>>>10);h=c+(g^d&(f^g))+e[4]+4118548399&4294967295;c=d+(h<<7&4294967295|h>>>25);h=g+(f^c&(d^f))+e[5]+1200080426&4294967295;g=c+(h<<12&4294967295|h>>>20);h=f+(d^g&(c^d))+e[6]+2821735955&4294967295;f=g+(h<<17&4294967295|h>>>15);h=d+(c^f&(g^c))+e[7]+4249261313&4294967295;d=f+(h<<22&4294967295|h>>>10);h=c+(g^d&(f^g))+e[8]+1770035416&4294967295;c=d+(h<<7&4294967295|h>>>25);h=g+(f^c&(d^f))+e[9]+2336552879&4294967295;g=c+(h<<12&4294967295|h>>>20);h=f+ (d^g&(c^d))+e[10]+4294925233&4294967295;f=g+(h<<17&4294967295|h>>>15);h=d+(c^f&(g^c))+e[11]+2304563134&4294967295;d=f+(h<<22&4294967295|h>>>10);h=c+(g^d&(f^g))+e[12]+1804603682&4294967295;c=d+(h<<7&4294967295|h>>>25);h=g+(f^c&(d^f))+e[13]+4254626195&4294967295;g=c+(h<<12&4294967295|h>>>20);h=f+(d^g&(c^d))+e[14]+2792965006&4294967295;f=g+(h<<17&4294967295|h>>>15);h=d+(c^f&(g^c))+e[15]+1236535329&4294967295;d=f+(h<<22&4294967295|h>>>10);h=c+(f^g&(d^f))+e[1]+4129170786&4294967295;c=d+(h<<5&4294967295| h>>>27);h=g+(d^f&(c^d))+e[6]+3225465664&4294967295;g=c+(h<<9&4294967295|h>>>23);h=f+(c^d&(g^c))+e[11]+643717713&4294967295;f=g+(h<<14&4294967295|h>>>18);h=d+(g^c&(f^g))+e[0]+3921069994&4294967295;d=f+(h<<20&4294967295|h>>>12);h=c+(f^g&(d^f))+e[5]+3593408605&4294967295;c=d+(h<<5&4294967295|h>>>27);h=g+(d^f&(c^d))+e[10]+38016083&4294967295;g=c+(h<<9&4294967295|h>>>23);h=f+(c^d&(g^c))+e[15]+3634488961&4294967295;f=g+(h<<14&4294967295|h>>>18);h=d+(g^c&(f^g))+e[4]+3889429448&4294967295;d=f+(h<<20&4294967295| @@ -211,754 +216,802 @@ c^d)+e[7]+4139469664&4294967295;f=g+(h<<16&4294967295|h>>>16);h=d+(f^g^c)+e[10]+ g=c+(h<<11&4294967295|h>>>21);h=f+(g^c^d)+e[15]+530742520&4294967295;f=g+(h<<16&4294967295|h>>>16);h=d+(f^g^c)+e[2]+3299628645&4294967295;d=f+(h<<23&4294967295|h>>>9);h=c+(f^(d|~g))+e[0]+4096336452&4294967295;c=d+(h<<6&4294967295|h>>>26);h=g+(d^(c|~f))+e[7]+1126891415&4294967295;g=c+(h<<10&4294967295|h>>>22);h=f+(c^(g|~d))+e[14]+2878612391&4294967295;f=g+(h<<15&4294967295|h>>>17);h=d+(g^(f|~c))+e[5]+4237533241&4294967295;d=f+(h<<21&4294967295|h>>>11);h=c+(f^(d|~g))+e[12]+1700485571&4294967295;c=d+ (h<<6&4294967295|h>>>26);h=g+(d^(c|~f))+e[3]+2399980690&4294967295;g=c+(h<<10&4294967295|h>>>22);h=f+(c^(g|~d))+e[10]+4293915773&4294967295;f=g+(h<<15&4294967295|h>>>17);h=d+(g^(f|~c))+e[1]+2240044497&4294967295;d=f+(h<<21&4294967295|h>>>11);h=c+(f^(d|~g))+e[8]+1873313359&4294967295;c=d+(h<<6&4294967295|h>>>26);h=g+(d^(c|~f))+e[15]+4264355552&4294967295;g=c+(h<<10&4294967295|h>>>22);h=f+(c^(g|~d))+e[6]+2734768916&4294967295;f=g+(h<<15&4294967295|h>>>17);h=d+(g^(f|~c))+e[13]+1309151649&4294967295; d=f+(h<<21&4294967295|h>>>11);h=c+(f^(d|~g))+e[4]+4149444226&4294967295;c=d+(h<<6&4294967295|h>>>26);h=g+(d^(c|~f))+e[11]+3174756917&4294967295;g=c+(h<<10&4294967295|h>>>22);h=f+(c^(g|~d))+e[2]+718787259&4294967295;f=g+(h<<15&4294967295|h>>>17);h=d+(g^(f|~c))+e[9]+3951481745&4294967295;b.a[0]=b.a[0]+c&4294967295;b.a[1]=b.a[1]+(f+(h<<21&4294967295|h>>>11))&4294967295;b.a[2]=b.a[2]+f&4294967295;b.a[3]=b.a[3]+g&4294967295} -nl.prototype.update=function(b,c){m(c)||(c=b.length);for(var d=c-this.c,e=this.f,f=this.b,g=0;gc.b?c.c:2*c.c)-c.b);d[0]=128;for(b=1;bb;++b)for(var f=0;32>f;f+=8)d[e++]=c.a[b]>>>f&255; -if(8192>d.length)c=String.fromCharCode.apply(null,d);else for(c="",b=0;bthis.o&&(this.a=!0));this.g=d;b=b.map;d=Jg(b.b);e=gk(this.f);e[0]-=d.x;e[1]-=d.y;this.e=b.sa(e);this.a&&(d=b.a(),e=d.d(),b.render(),Sj(b,d,e+c,this.e))}function Ll(b){if(2>this.f.length){b=b.map;var c=b.a();Ye(c,-1);if(this.a){var d=c.d(),e=this.e,d=c.constrainRotation(d,0);Sj(b,c,d,e,250)}return!1}return!0} -function Jl(b){return 2<=this.f.length?(b=b.map,this.e=null,this.g=void 0,this.a=!1,this.i=0,this.q||Ye(b.a(),1),b.render(),!0):!1}Il.prototype.r=ad;function Ml(b){ek.call(this,{handleDownEvent:Nl,handleDragEvent:Ol,handleUpEvent:Pl});b=m(b)?b:{};this.e=null;this.i=m(b.duration)?b.duration:400;this.a=void 0;this.g=1}v(Ml,ek);function Ol(b){var c=1,d=this.f[0],e=this.f[1],f=d.clientX-e.clientX,d=d.clientY-e.clientY,f=Math.sqrt(f*f+d*d);m(this.a)&&(c=this.a/f);this.a=f;1!=c&&(this.g=c);b=b.map;var f=b.a(),d=f.a(),e=Jg(b.b),g=gk(this.f);g[0]-=e.x;g[1]-=e.y;this.e=b.sa(g);b.render();Uj(b,f,d*c,this.e)} -function Pl(b){if(2>this.f.length){b=b.map;var c=b.a();Ye(c,-1);var d=c.a(),e=this.e,f=this.i,d=c.constrainResolution(d,0,this.g-1);Uj(b,c,d,e,f);return!1}return!0}function Nl(b){return 2<=this.f.length?(b=b.map,this.e=null,this.a=void 0,this.g=1,this.q||Ye(b.a(),1),b.render(),!0):!1}Ml.prototype.r=ad;function Ql(b){b=m(b)?b:{};var c=new lg,d=new Oj(-.005,.05,100);(m(b.altShiftDragRotate)?b.altShiftDragRotate:1)&&c.push(new lk);(m(b.doubleClickZoom)?b.doubleClickZoom:1)&&c.push(new Vj({delta:b.zoomDelta,duration:b.zoomDuration}));(m(b.dragPan)?b.dragPan:1)&&c.push(new hk({kinetic:d}));(m(b.pinchRotate)?b.pinchRotate:1)&&c.push(new Il);(m(b.pinchZoom)?b.pinchZoom:1)&&c.push(new Ml({duration:b.zoomDuration}));if(m(b.keyboard)?b.keyboard:1)c.push(new Cl),c.push(new El({delta:b.zoomDelta,duration:b.zoomDuration})); -(m(b.mouseWheelZoom)?b.mouseWheelZoom:1)&&c.push(new Gl({duration:b.zoomDuration}));(m(b.shiftDragZoom)?b.shiftDragZoom:1)&&c.push(new Bl);return c};function G(b){var c=m(b)?b:{};b=Bb(c);delete b.layers;c=c.layers;C.call(this,b);this.a=null;w(this,ud("layers"),this.Di,!1,this);null!=c?ga(c)&&(c=new lg(c.slice())):c=new lg;this.r(c)}v(G,C);l=G.prototype;l.sf=function(){this.b()&&this.l()}; -l.Di=function(){null!==this.a&&(Qa(qb(this.a),Wc),this.a=null);var b=this.ac();if(null!=b){this.a={add:w(b,"add",this.Ci,!1,this),remove:w(b,"remove",this.Ei,!1,this)};var b=b.a,c,d,e;c=0;for(d=b.length;cthis.f&&(this.f=this.b.lineWidth,this.d=null)}; -function wm(b,c,d){mm.call(this,b,c,d);this.b={ff:void 0,Ic:void 0,Dc:void 0,Ec:null,Fc:void 0,Gc:void 0,Hc:void 0,fillStyle:void 0,strokeStyle:void 0,lineCap:void 0,lineDash:null,lineJoin:void 0,lineWidth:void 0,miterLimit:void 0}}v(wm,mm); -function xm(b,c,d,e,f){var g=b.b,h=[1];b.c.push(h);b.a.push(h);var k,h=0;for(k=e.length;hthis.f&&(this.f=d.lineWidth,this.d=null))}; -function ym(b){var c=b.b,d=c.fillStyle,e=c.strokeStyle,f=c.lineCap,g=c.lineDash,h=c.lineJoin,k=c.lineWidth,n=c.miterLimit;m(d)&&c.ff!=d&&(b.c.push([9,d]),c.ff=c.fillStyle);!m(e)||c.Ic==e&&c.Dc==f&&c.Ec==g&&c.Fc==h&&c.Gc==k&&c.Hc==n||(b.c.push([10,e,k,f,h,n,g]),c.Ic=e,c.Dc=f,c.Ec=g,c.Fc=h,c.Gc=k,c.Hc=n)}function zm(b,c,d){mm.call(this,b,c,d);this.D=this.r=this.p=null;this.n="";this.o=this.q=this.k=this.i=0;this.g=this.e=this.b=null}v(zm,mm); -zm.prototype.vb=function(b,c,d,e,f,g){if(""!==this.n&&null!==this.g&&(null!==this.b||null!==this.e)){if(null!==this.b){f=this.b;var h=this.p;if(null===h||h.fillStyle!=f.fillStyle){var k=[9,f.fillStyle];this.c.push(k);this.a.push(k);null===h?this.p={fillStyle:f.fillStyle}:h.fillStyle=f.fillStyle}}null!==this.e&&(f=this.e,h=this.r,null===h||h.lineCap!=f.lineCap||h.lineDash!=f.lineDash||h.lineJoin!=f.lineJoin||h.lineWidth!=f.lineWidth||h.miterLimit!=f.miterLimit||h.strokeStyle!=f.strokeStyle)&&(k=[10, -f.strokeStyle,f.lineWidth,f.lineCap,f.lineJoin,f.miterLimit,f.lineDash,!1],this.c.push(k),this.a.push(k),null===h?this.r={lineCap:f.lineCap,lineDash:f.lineDash,lineJoin:f.lineJoin,lineWidth:f.lineWidth,miterLimit:f.miterLimit,strokeStyle:f.strokeStyle}:(h.lineCap=f.lineCap,h.lineDash=f.lineDash,h.lineJoin=f.lineJoin,h.lineWidth=f.lineWidth,h.miterLimit=f.miterLimit,h.strokeStyle=f.strokeStyle));f=this.g;h=this.D;if(null===h||h.font!=f.font||h.textAlign!=f.textAlign||h.textBaseline!=f.textBaseline)k= -[11,f.font,f.textAlign,f.textBaseline],this.c.push(k),this.a.push(k),null===h?this.D={font:f.font,textAlign:f.textAlign,textBaseline:f.textBaseline}:(h.font=f.font,h.textAlign=f.textAlign,h.textBaseline=f.textBaseline);om(this,g);f=this.coordinates.length;b=nm(this,b,c,d,e,!1);b=[5,f,b,this.n,this.i,this.k,this.q,this.o,null!==this.b,null!==this.e];this.c.push(b);this.a.push(b);rm(this,g)}}; -zm.prototype.Ca=function(b){if(null===b)this.n="";else{var c=b.a;null===c?this.b=null:(c=c.a,c=sg(null===c?rl:c),null===this.b?this.b={fillStyle:c}:this.b.fillStyle=c);var d=b.e;if(null===d)this.e=null;else{var c=d.a,e=d.d,f=d.b,g=d.f,h=d.c,d=d.e,e=m(e)?e:"round",f=null!=f?f.slice():sl,g=m(g)?g:"round",h=m(h)?h:1,d=m(d)?d:10,c=sg(null===c?tl:c);if(null===this.e)this.e={lineCap:e,lineDash:f,lineJoin:g,lineWidth:h,miterLimit:d,strokeStyle:c};else{var k=this.e;k.lineCap=e;k.lineDash=f;k.lineJoin=g;k.lineWidth= -h;k.miterLimit=d;k.strokeStyle=c}}var n=b.d,c=b.i,e=b.k,f=b.f,h=b.c,d=b.b,g=b.g,k=b.n;b=m(n)?n:"10px sans-serif";g=m(g)?g:"center";k=m(k)?k:"middle";null===this.g?this.g={font:b,textAlign:g,textBaseline:k}:(n=this.g,n.font=b,n.textAlign=g,n.textBaseline=k);this.n=m(d)?d:"";this.i=m(c)?c:0;this.k=m(e)?e:0;this.q=m(f)?f:0;this.o=m(h)?h:1}};function Am(b,c,d,e){this.i=b;this.d=c;this.n=d;this.f=e;this.c={};this.e=Nf(1,1);this.g=Hd()} -function Bm(b){for(var c in b.c){var d=b.c[c],e;for(e in d)d[e].Kb()}}Am.prototype.b=function(b,c,d,e,f){var g=this.g;lj(g,.5,.5,1/c,-1/c,-d,-b[0],-b[1]);var h=this.e;h.clearRect(0,0,1,1);var k;m(this.f)&&(k=Sd(),Td(k,b),Wd(k,c*this.f,k));return Cm(this,h,g,d,e,function(b){if(0b||0!==this.g&&b>1,q=h(d,g[p]),0s?(d=(d-g[-s-2])/(g[-s-1]-g[-s-2]),c+=(-s-2)*e,g=Xb(b[c],b[c+e],d),h=Xb(b[c+1],b[c+e+1],d)):(g=b[c+s*e],h=b[c+s*e+1])}return null!=f? -(f[0]=g,f[1]=h,f):[g,h]}function Rm(b,c,d,e,f,g){if(d==c)return null;if(f>1,fb||this.b.length<=b)return null;var c=new Tm(null);Um(c,this.a,this.j.slice(0===b?0:this.b[b-1],this.b[b]));return c};l.Lc=function(){var b=this.j,c=this.b,d=this.a,e=[],f=0,g,h;g=0;for(h=c.length;gb||c<=b)return null;c=new Nk(null);Ok(c,this.a,this.j.slice(b*this.B,(b+1)*this.B));return c};l.Gd=function(){var b=this.j,c=this.a,d=this.B,e=[],f,g;f=0;for(g=b.length;fb||this.b.length<=b)return null;var c;0===b?c=0:(c=this.b[b-1],c=c[c.length-1]);b=this.b[b].slice();var d=b[b.length-1];if(0!==c){var e,f;e=0;for(f=b.length;e=b[0]&&c[3]>=b[1]}function r(b,c,d,e,f){for(var g=[c,d],h;g.length;)d=g.pop(),c=g.pop(),d-c<=e||(h=c+Math.ceil((d-c)/e/2)*e,s(b,c,d,h,f),g.push(c,h,h,d))}function s(b,c,d,e,f){for(var g,h,k,n,p;d>c;){600h-g/2?-1:1),k=Math.max(c,Math.floor(e-h*n/g+p)),h=Math.min(d,Math.floor(e+(g-h)*n/g+p)),s(b,k,h,e,f));g=b[e];h=c;n=d;u(b,c,e);for(0f(b[h],g);)h++;for(;0this.ie)this.eh(e,c),c--;else break;this.Yg(d,e,c)},eh:function(b,c){var e=b[c],f=e.children.length,g=this.Ye;this.Zg(e,g,f);f={children:e.children.splice(this.$g(e,g,f)),height:e.height};e.za&&(f.za=!0);d(e,this.Ka);d(f,this.Ka);c?b[c-1].children.push(f):this.Ze(e, -f)},Ze:function(b,c){this.data={children:[b,c],height:b.height+1};d(this.data,this.Ka)},$g:function(b,c,d){var f,g,h,n,p,q,r;p=q=Infinity;for(f=c;f<=d-c;f++){g=e(b,0,f,this.Ka);h=e(b,f,d,this.Ka);var s=g,u=h;n=Math.max(s[0],u[0]);var Ma=Math.max(s[1],u[1]),sb=Math.min(s[2],u[2]),s=Math.min(s[3],u[3]);n=Math.max(0,sb-n)*Math.max(0,s-Ma);g=k(g)+k(h);n=c;q--)r=b.children[q],f(k,b.za?g(r):r.bbox),p+=n(k);return p},Yg:function(b,c,d){for(;0<=d;d--)f(c[d].bbox,b)},bh:function(b){for(var c=b.length-1,e;0<=c;c--)0===b[c].children.length?0A||this.b[1]>E)?(x.width=A,x.height=E,this.b=[A,E],this.i=!Jm(this.b),this.d=null):(A=this.b[0],E=this.b[1],(x=p!=this.o)||(x=this.d,x=!(x.a<=z.a&&z.d<=x.d&&x.b<=z.b&&z.c<=x.c)),x&&(this.d=null)));var N,L;null===this.d?(A/=q,E/=q,N=z.a-Math.floor((A-of(z))/2),L=z.b-Math.floor((E-(z.c-z.b+1))/2),this.o=p,this.p=q,this.d=new kf(N,N+A-1,L,L+E-1),this.n=Array(A*E),E=this.d):(E=this.d,A=of(E));x={};x[p]={};var U=[],Ca=this.ed(h,x),eb=g.ea(),R=Sd(),Ma=new kf(0,0,0,0),sb,$a,Ub;for(L= -z.a;L<=z.d;++L)for(Ub=z.b;Ub<=z.c;++Ub)$a=h.Vb(p,L,Ub,d,f),N=$a.state,2==N||4==N||3==N&&!eb?x[p][jf($a.a)]=$a:(sb=k.gd($a.a,Ca,null,Ma,R),sb||(U.push($a),sb=k.td($a.a,Ma,R),null===sb||Ca(p+1,sb)));Ca=0;for(sb=U.length;CaU&&Hf(this.target,z.target,0)}else{if(!b.viewHints[0]&&!b.viewHints[1]){Q=fh(z.d,s,z.b[0],E);U=[];x=L=void 0;for(x in z.c)L=z.c[x],Q.contains(L.a)||U.push(L);eb=Q=void 0;Q= -0;for(eb=U.length;Q=k;){n=this.b[p];u=this.k[p];x=ma(u).toString();if(!m(r[x])&&(!m(y)||pe(y,u.R().J()))&&(g.clear(g.COLOR_BUFFER_BIT|g.DEPTH_BUFFER_BIT),g.drawElements(4,q-n,e,n*b),q=s(u))){r=q;break a}q=n;p--}r=void 0}else g.clear(g.COLOR_BUFFER_BIT|g.DEPTH_BUFFER_BIT),mo(this,g,b,r,this.g,this.e),r=(r=s(null))?r:void 0;x=r}else mo(this,g,b,r,this.ia,this.o);g.disableVertexAttribArray(A.d); -g.disableVertexAttribArray(A.a);g.disableVertexAttribArray(A.f);g.disableVertexAttribArray(A.c);g.disableVertexAttribArray(A.b);return x}; -function mo(b,c,d,e,f,g){var h=d.b?5125:5123;d=d.b?4:2;if(wb(e)){var k;b=0;e=f.length;for(k=0;bc[0]|| -c[0]>f[0]||0>c[1]||c[1]>f[1])&&(null===this.g&&(this.g=Nf(1,1)),this.g.clearRect(0,0,1,1),this.g.drawImage(this.d.a(),c[0],c[1],1,1,0,0,1,1),0e?c[0]=e-d:0>f&&(c[0]=Math.abs(f)+d), -0>g?c[1]=g-d:0>h&&(c[1]=Math.abs(h)+d),0===c[0]&&0===c[1])||(d=b.a().b(),e=b.e(d),c=[e[0]+c[0],e[1]+c[1]],null!==this.g&&(this.g.source=d,b.La(cf(this.g))),b.a().Ha(b.sa(c)))}}};l.Li=function(){Uo(this)};l.Le=function(b){this.set("element",b)};M.prototype.setElement=M.prototype.Le;M.prototype.setMap=function(b){this.set("map",b)};M.prototype.setMap=M.prototype.setMap;M.prototype.o=function(b){this.set("offset",b)};M.prototype.setOffset=M.prototype.o;M.prototype.e=function(b){this.set("position",b)}; -M.prototype.setPosition=M.prototype.e;function Vo(b,c){var d=wf(b);Fg(b,"position");var e=new sf(0,0),f;f=d?wf(d):document;f=!Gb||Gb&&9<=Rb||Lf(uf(f))?f.documentElement:f.body;b!=f&&(f=Ig(b),d=Mf(uf(d)),e.x=f.left+d.x,e.y=f.top+d.y);return[e.x,e.y,e.x+c[0],e.y+c[1]]}M.prototype.p=function(b){this.set("positioning",b)};M.prototype.setPositioning=M.prototype.p; -function Uo(b){var c=b.d(),d=b.q();if(m(c)&&null!==c.d&&m(d)){var d=c.e(d),e=c.f(),c=b.ba.style,f=b.i(),g=b.k(),h=f[0],f=f[1];if("bottom-right"==g||"center-right"==g||"top-right"==g)""!==b.a.Dd&&(b.a.Dd=c.left=""),h=Math.round(e[0]-d[0]-h)+"px",b.a.Zd!=h&&(b.a.Zd=c.right=h);else{""!==b.a.Zd&&(b.a.Zd=c.right="");if("bottom-center"==g||"center-center"==g||"top-center"==g)h-=Kg(b.ba).width/2;h=Math.round(d[0]+h)+"px";b.a.Dd!=h&&(b.a.Dd=c.left=h)}if("bottom-left"==g||"bottom-center"==g||"bottom-right"== -g)""!==b.a.$d&&(b.a.$d=c.top=""),d=Math.round(e[1]-d[1]-f)+"px",b.a.bd!=d&&(b.a.bd=c.bottom=d);else{""!==b.a.bd&&(b.a.bd=c.bottom="");if("center-left"==g||"center-center"==g||"center-right"==g)f-=Kg(b.ba).height/2;d=Math.round(d[1]+f)+"px";b.a.$d!=d&&(b.a.$d=c.top=d)}b.a.visible||(Mg(b.ba,!0),b.a.visible=!0)}else b.a.visible&&(Mg(b.ba,!1),b.a.visible=!1)};function Wo(b){b=m(b)?b:{};this.e=m(b.collapsed)?b.collapsed:!0;this.g=m(b.collapsible)?b.collapsible:!0;this.g||(this.e=!1);var c=m(b.className)?b.className:"ol-overviewmap",d=m(b.tipLabel)?b.tipLabel:"Overview map",e=m(b.collapseLabel)?b.collapseLabel:"\u00ab";this.o=ia(e)?Bf("SPAN",{},e):e;e=m(b.label)?b.label:"\u00bb";this.p=ia(e)?Bf("SPAN",{},e):e;d=Bf("BUTTON",{type:"button",title:d},this.g&&!this.e?this.o:this.p);w(d,"click",this.Ij,!1,this);w(d,["mouseout",uc],function(){this.blur()},!1); -var e=Bf("DIV","ol-overviewmap-map"),f=this.d=new K({controls:new lg,interactions:new lg,target:e});m(b.layers)&&b.layers.forEach(function(b){f.af(b)},this);var g=Bf("DIV","ol-overviewmap-box");this.k=new M({position:[0,0],positioning:"bottom-left",element:g});this.d.bf(this.k);c=Bf("DIV",c+" ol-unselectable ol-control"+(this.e&&this.g?" ol-collapsed":"")+(this.g?"":" ol-uncollapsible"),e,d);Ug.call(this,{element:c,render:m(b.render)?b.render:Xo,target:b.target})}v(Wo,Ug);l=Wo.prototype; -l.setMap=function(b){var c=this.a;null===b&&null!==c&&Vc(c,ud("view"),this.Ff,!1,this);Wo.T.setMap.call(this,b);null!==b&&(0===this.d.ea().Ib()&&this.d.K("layergroup",b),Yo(this),w(b,ud("view"),this.Ff,!1,this),this.d.q(),Zo(this))};function Yo(b){var c=b.a.a();null===c||b.d.a().K("rotation",c)} -function Xo(){var b=this.a,c=this.d;if(null!==b.d&&null!==c.d){var d=b.f(),b=b.a().g(d),e=c.f(),d=c.a().g(e),f=c.e(je(b)),c=c.e(he(b)),c=new tf(Math.abs(f[0]-c[0]),Math.abs(f[1]-c[1])),f=e[0],e=e[1];c.width<.1*f||c.height<.1*e||c.width>.75*f||c.height>.75*e?Zo(this):Zd(d,b)||(b=this.d,d=this.a.a(),b.a().Ha(d.b()))}$o(this)}l.Ff=function(){Yo(this)};function Zo(b){var c=b.a;b=b.d;var d=c.f(),c=c.a().g(d),d=b.f();b=b.a();var e=Math.log(7.5)/Math.LN2;se(c,1/(.1*Math.pow(2,e/2)));b.pe(c,d)} -function $o(b){var c=b.a,d=b.d;if(null!==c.d&&null!==d.d){var e=c.f(),f=c.a(),g=d.a();d.f();var c=f.d(),h=b.k,d=b.k.b(),f=f.g(e),e=g.a(),g=ge(f),f=ie(f),k;b=b.a.a().b();m(b)&&(k=[g[0]-b[0],g[1]-b[1]],Ad(k,c),vd(k,b));h.e(k);null!=d&&(k=new tf(Math.abs((g[0]-f[0])/e),Math.abs((f[1]-g[1])/e)),c=Lf(uf(wf(d))),!Gb||Pb("10")||c&&Pb("8")?(d=d.style,Hb?d.MozBoxSizing="border-box":Ib?d.WebkitBoxSizing="border-box":d.boxSizing="border-box",d.width=Math.max(k.width,0)+"px",d.height=Math.max(k.height,0)+"px"): -(b=d.style,c?(c=Pg(d,"padding"),d=Sg(d),b.pixelWidth=k.width-d.left-c.left-c.right-d.right,b.pixelHeight=k.height-d.top-c.top-c.bottom-d.bottom):(b.pixelWidth=k.width,b.pixelHeight=k.height)))}}l.Ij=function(b){b.preventDefault();ap(this)};function ap(b){Ag(b.element,"ol-collapsed");b.e?Jf(b.o,b.p):Jf(b.p,b.o);b.e=!b.e;var c=b.d;b.e||null!==c.d||(c.q(),Zo(b),Uc(c,"postrender",function(){$o(this)},!1,b))}l.Hj=function(){return this.g}; -l.Kj=function(b){this.g!==b&&(this.g=b,Ag(this.element,"ol-uncollapsible"),!b&&this.e&&ap(this))};l.Jj=function(b){this.g&&this.e!==b&&ap(this)};l.Gj=function(){return this.e};function bp(b){b=m(b)?b:{};var c=m(b.className)?b.className:"ol-scale-line";this.g=Bf("DIV",c+"-inner");this.ba=Bf("DIV",c+" ol-unselectable",this.g);this.r=null;this.k=m(b.minWidth)?b.minWidth:64;this.d=!1;this.H=void 0;this.D="";this.e=null;Ug.call(this,{element:this.ba,render:m(b.render)?b.render:cp,target:b.target});w(this,ud("units"),this.N,!1,this);this.p(b.units||"metric")}v(bp,Ug);var dp=[1,2,5];bp.prototype.o=function(){return this.get("units")};bp.prototype.getUnits=bp.prototype.o; -function cp(b){b=b.frameState;null===b?this.r=null:this.r=b.viewState;ep(this)}bp.prototype.N=function(){ep(this)};bp.prototype.p=function(b){this.set("units",b)};bp.prototype.setUnits=bp.prototype.p; -function ep(b){var c=b.r;if(null===c)b.d&&(Mg(b.ba,!1),b.d=!1);else{var d=c.center,e=c.projection,c=e.getPointResolution(c.resolution,d),f=e.c,g=b.o();"degrees"!=f||"metric"!=g&&"imperial"!=g&&"us"!=g&&"nautical"!=g?"degrees"!=f&&"degrees"==g?(null===b.e&&(b.e=De(e,ze("EPSG:4326"))),d=Math.cos(Yb(b.e(d)[1])),e=ve.radius,e/=we[f],c*=180/(Math.PI*d*e)):b.e=null:(b.e=null,d=Math.cos(Yb(d[1])),c*=Math.PI*d*ve.radius/180);d=b.k*c;f="";"degrees"==g?d<1/60?(f="\u2033",c*=3600):1>d?(f="\u2032",c*=60):f="\u00b0": -"imperial"==g?.9144>d?(f="in",c/=.0254):1609.344>d?(f="ft",c/=.3048):(f="mi",c/=1609.344):"nautical"==g?(c/=1852,f="nm"):"metric"==g?1>d?(f="mm",c*=1E3):1E3>d?f="m":(f="km",c/=1E3):"us"==g&&(.9144>d?(f="in",c*=39.37):1609.344>d?(f="ft",c/=.30480061):(f="mi",c/=1609.3472));for(d=3*Math.floor(Math.log(b.k*c)/Math.log(10));;){e=dp[d%3]*Math.pow(10,Math.floor(d/3));g=Math.round(e/c);if(isNaN(g)){Mg(b.ba,!1);b.d=!1;return}if(g>=b.k)break;++d}c=e+" "+f;b.D!=c&&(b.g.innerHTML=c,b.D=c);b.H!=g&&(b.g.style.width= -g+"px",b.H=g);b.d||(Mg(b.ba,!0),b.d=!0)}};function fp(b){lc.call(this);this.c=b;this.a={}}v(fp,lc);var gp=[];fp.prototype.Ra=function(b,c,d,e){ga(c)||(c&&(gp[0]=c.toString()),c=gp);for(var f=0;fd.height?(this.g=1,d=new Cg(0,0,e,0)):(this.g=rp,d=new Cg(0,0,0,c));this.d.a=d||new Cg(NaN,NaN,NaN,NaN);this.o=!0}b=b.frameState.viewState.resolution;b!==this.e&&(this.e=b,b=1-We(this.a.a())(b),d=this.d,c=Kf(this.element),1==this.g?Gg(c,d.a.left+d.a.width*b):Gg(c, -d.a.left,d.a.top+d.a.height*b))}}l.ni=function(b){var c=this.a,d=c.a(),e=d.a();c.La(ef({resolution:e,duration:200,easing:Ze}));b=tp(this,b.offsetX-this.k[0]/2,b.offsetY-this.k[1]/2);b=up(this,b);d.f(d.constrainResolution(b))};l.qi=function(){Ye(this.a.a(),1)};l.oi=function(b){b=tp(this,b.left,b.top);this.e=up(this,b);this.a.a().f(this.e)};l.pi=function(){var b=this.a,c=b.a();Ye(c,-1);b.La(ef({resolution:this.e,duration:200,easing:Ze}));b=c.constrainResolution(this.e);c.f(b)}; -function tp(b,c,d){var e=b.d.a;return Vb(1===b.g?(c-e.left)/e.width:(d-e.top)/e.height,0,1)}function up(b,c){return Ve(b.a.a())(1-c)};function vp(b){b=m(b)?b:{};this.d=m(b.extent)?b.extent:null;var c=m(b.className)?b.className:"ol-zoom-extent",d=Bf("BUTTON",{type:"button",title:m(b.tipLabel)?b.tipLabel:"Fit to extent"},m(b.label)?b.label:"E");w(d,"click",this.e,!1,this);w(d,["mouseout",uc],function(){this.blur()},!1);c=Bf("DIV",c+" ol-unselectable ol-control",d);Ug.call(this,{element:c,target:b.target})}v(vp,Ug); -vp.prototype.e=function(b){b.preventDefault();var c=this.a;b=c.a();var d=null===this.d?b.p.J():this.d,c=c.f();b.pe(d,c)};function wp(b){qd.call(this);b=m(b)?b:{};this.a=null;w(this,ud("tracking"),this.k,!1,this);this.b(m(b.tracking)?b.tracking:!1)}v(wp,qd);wp.prototype.P=function(){this.b(!1);wp.T.P.call(this)}; -wp.prototype.q=function(b){b=b.a;if(null!=b.alpha){var c=Yb(b.alpha);this.set("alpha",c);"boolean"==typeof b.absolute&&b.absolute?this.set("heading",c):null!=b.webkitCompassHeading&&null!=b.webkitCompassAccuracy&&-1!=b.webkitCompassAccuracy&&this.set("heading",Yb(b.webkitCompassHeading))}null!=b.beta&&this.set("beta",Yb(b.beta));null!=b.gamma&&this.set("gamma",Yb(b.gamma));this.l()};wp.prototype.f=function(){return this.get("alpha")};wp.prototype.getAlpha=wp.prototype.f;wp.prototype.e=function(){return this.get("beta")}; -wp.prototype.getBeta=wp.prototype.e;wp.prototype.g=function(){return this.get("gamma")};wp.prototype.getGamma=wp.prototype.g;wp.prototype.i=function(){return this.get("heading")};wp.prototype.getHeading=wp.prototype.i;wp.prototype.d=function(){return this.get("tracking")};wp.prototype.getTracking=wp.prototype.d;wp.prototype.k=function(){if($f){var b=this.d();b&&null===this.a?this.a=w(ba,"deviceorientation",this.q,!1,this):b||null===this.a||(Wc(this.a),this.a=null)}}; -wp.prototype.b=function(b){this.set("tracking",b)};wp.prototype.setTracking=wp.prototype.b;function xp(b){qd.call(this);this.i=b;w(this.i,["change","input"],this.g,!1,this);w(this,ud("value"),this.k,!1,this);w(this,ud("checked"),this.e,!1,this)}v(xp,qd);xp.prototype.a=function(){return this.get("checked")};xp.prototype.getChecked=xp.prototype.a;xp.prototype.b=function(){return this.get("value")};xp.prototype.getValue=xp.prototype.b;xp.prototype.f=function(b){this.set("value",b)};xp.prototype.setValue=xp.prototype.f;xp.prototype.d=function(b){this.set("checked",b)}; -xp.prototype.setChecked=xp.prototype.d;xp.prototype.g=function(){var b=this.i;"checkbox"===b.type||"radio"===b.type?this.d(b.checked):this.f(b.value)};xp.prototype.e=function(){this.i.checked=this.a()};xp.prototype.k=function(){this.i.value=this.b()};function O(b){qd.call(this);this.aa=void 0;this.b="geometry";this.g=null;this.a=void 0;this.e=null;w(this,ud(this.b),this.xd,!1,this);m(b)&&(b instanceof pk||null===b?this.Sa(b):this.C(b))}v(O,qd);O.prototype.clone=function(){var b=new O(this.I());b.f(this.b);var c=this.R();null!=c&&b.Sa(c.clone());c=this.g;null===c||b.i(c);return b};O.prototype.R=function(){return this.get(this.b)};O.prototype.getGeometry=O.prototype.R;l=O.prototype;l.Jh=function(){return this.aa};l.Ih=function(){return this.b}; -l.qj=function(){return this.g};l.rj=function(){return this.a};l.xi=function(){this.l()};l.xd=function(){null!==this.e&&(Wc(this.e),this.e=null);var b=this.R();null!=b&&(this.e=w(b,"change",this.xi,!1,this),this.l())};l.Sa=function(b){this.set(this.b,b)};O.prototype.setGeometry=O.prototype.Sa;O.prototype.i=function(b){this.g=b;null===b?b=void 0:ka(b)||(b=ga(b)?b:[b],b=$c(b));this.a=b;this.l()};O.prototype.d=function(b){this.aa=b;this.l()}; -O.prototype.f=function(b){Vc(this,ud(this.b),this.xd,!1,this);this.b=b;w(this,ud(this.b),this.xd,!1,this);this.xd()};function yp(b){b=m(b)?b:{};this.g=this.f=this.d=this.c=this.b=this.a=null;this.e=void 0;this.Ef(m(b.style)?b.style:zl);m(b.features)?ga(b.features)?this.Tc(new lg(b.features.slice())):this.Tc(b.features):this.Tc(new lg);m(b.map)&&this.setMap(b.map)}l=yp.prototype;l.Cf=function(b){this.a.push(b)};l.kj=function(){return this.a};l.lj=function(){return this.d};l.Df=function(){zp(this)};l.vi=function(b){b=b.element;this.c[ma(b).toString()]=w(b,"change",this.Df,!1,this);zp(this)}; -l.wi=function(b){b=ma(b.element).toString();Wc(this.c[b]);delete this.c[b];zp(this)};l.oj=function(){zp(this)};l.pj=function(b){if(null!==this.a){var c=this.e;m(c)||(c=zl);var d=b.a;b=b.frameState;var e=b.viewState.resolution,f=cn(e,b.pixelRatio),g,h,k,n;this.a.forEach(function(b){n=b.a;k=m(n)?n.call(b,e):c(b,e);if(null!=k)for(h=k.length,g=0;gd?b[1]="?":d==c.length-1&&(b[1]=void 0)}return b.join("")} -function Ur(b,c,d){if(ga(c))for(var e=0;ec)throw Error("Bad port number "+c);b.tc=c}else b.tc=null}function Zr(b,c,d){c instanceof as?(b.a=c,gs(b.a,b.Yb)):(d||(c=bs(c,hs)),b.a=new as(c,0,b.Yb))}function is(b){return b instanceof Wr?b.clone():new Wr(b,void 0)} -function js(b,c){b instanceof Wr||(b=is(b));c instanceof Wr||(c=is(c));var d=b,e=c,f=d.clone(),g=!!e.Pb;g?Xr(f,e.Pb):g=!!e.gc;g?f.gc=e.gc:g=!!e.sb;g?f.sb=e.sb:g=null!=e.tc;var h=e.rb;if(g)Yr(f,e.tc);else if(g=!!e.rb)if("/"!=h.charAt(0)&&(d.sb&&!d.rb?h="/"+h:(d=f.rb.lastIndexOf("/"),-1!=d&&(h=f.rb.substr(0,d+1)+h))),d=h,".."==d||"."==d)h="";else if(-1!=d.indexOf("./")||-1!=d.indexOf("/.")){for(var h=0==d.lastIndexOf("/",0),d=d.split("/"),k=[],n=0;n>4&15).toString(16)+(b&15).toString(16)} -var cs=/[#\/\?@]/g,es=/[\#\?:]/g,ds=/[\#\?]/g,hs=/[\#\?@]/g,fs=/#/g;function as(b,c,d){this.a=b||null;this.c=!!d}function ls(b){b.ga||(b.ga=new Th,b.ya=0,b.a&&Sr(b.a,function(c,d){b.add(decodeURIComponent(c.replace(/\+/g," ")),d)}))}l=as.prototype;l.ga=null;l.ya=null;l.Tb=function(){ls(this);return this.ya};l.add=function(b,c){ls(this);this.a=null;b=ms(this,b);var d=this.ga.get(b);d||this.ga.set(b,d=[]);d.push(c);this.ya++;return this}; -l.remove=function(b){ls(this);b=ms(this,b);return Vh(this.ga.c,b)?(this.a=null,this.ya-=this.ga.get(b).length,this.ga.remove(b)):!1};l.clear=function(){this.ga=this.a=null;this.ya=0};l.la=function(){ls(this);return 0==this.ya};function ns(b,c){ls(b);c=ms(b,c);return Vh(b.ga.c,c)}l.G=function(){ls(this);for(var b=this.ga.ob(),c=this.ga.G(),d=[],e=0;ee;++e){var f=parseInt(d[e],10).toString(16);d[e]=1==f.length?"0"+f:f}Oq(b,d.join(""))} -function pt(b,c,d){Bq({node:b},qt,rt,[c],d)}function st(b,c,d){var e={node:b};null!=c.aa&&b.setAttribute("id",c.aa);b=c.I();var f=c.a;m(f)&&(f=f.call(c,0),null!==f&&0f?~(f<<1):f<<1;d="";e=0;for(f=b.length;e>=5;h=g+63;k+=String.fromCharCode(h);d+=k}return d} -function Cu(b,c){var d=m(c)?c:1E5,e=[],f=0,g=0,h,k;h=0;for(k=b.length;hn?(e.push(f),g=f=0):g+=5}f=0;for(g=e.length;f>1):h>>1;f=0;for(g=e.length;f=b||"."==b&&!d} -function dv(b){var c=b.c.charAt(++b.a),d={position:b.a,value:c};if("("==c)d.type=2;else if(","==c)d.type=5;else if(")"==c)d.type=3;else if(fv(c)||"-"==c){d.type=4;var e,c=b.a,f=!1;do"."==e&&(f=!0),e=b.c.charAt(++b.a);while(fv(e,f));b=parseFloat(b.c.substring(c,b.a--));d.value=b}else if("a"<=c&&"z">=c||"A"<=c&&"Z">=c){d.type=1;c=b.a;do e=b.c.charAt(++b.a);while("a"<=e&&"z">=e||"A"<=e&&"Z">=e);b=b.c.substring(c,b.a--).toUpperCase();d.value=b}else{if(" "==c||"\t"==c||"\r"==c||"\n"==c)return dv(b);if(""=== -c)d.type=6;else throw Error("Unexpected character: "+c);}return d}function bv(b){this.c=b}l=bv.prototype;l.match=function(b){if(b=this.a.type==b)this.a=dv(this.c);return b}; -function ev(b){var c=b.a;if(b.match(1)){var d=c.value;if("GEOMETRYCOLLECTION"==d){a:{if(b.match(2)){c=[];do c.push(ev(b));while(b.match(5));if(b.match(3)){b=c;break a}}else if(gv(b)){b=[];break a}throw Error(hv(b));}return new Mm(b)}var e=iv[d],c=jv[d];if(!m(e)||!m(c))throw Error("Invalid geometry type: "+d);b=e.call(b);return new c(b)}throw Error(hv(b));}l.De=function(){if(this.match(2)){var b=kv(this);if(this.match(3))return b}else if(gv(this))return null;throw Error(hv(this));}; -l.Ce=function(){if(this.match(2)){var b=lv(this);if(this.match(3))return b}else if(gv(this))return[];throw Error(hv(this));};l.Ee=function(){if(this.match(2)){var b=mv(this);if(this.match(3))return b}else if(gv(this))return[];throw Error(hv(this));};l.nl=function(){if(this.match(2)){var b;if(2==this.a.type)for(b=[this.De()];this.match(5);)b.push(this.De());else b=lv(this);if(this.match(3))return b}else if(gv(this))return[];throw Error(hv(this));}; -l.ml=function(){if(this.match(2)){var b=mv(this);if(this.match(3))return b}else if(gv(this))return[];throw Error(hv(this));};l.ol=function(){if(this.match(2)){for(var b=[this.Ee()];this.match(5);)b.push(this.Ee());if(this.match(3))return b}else if(gv(this))return[];throw Error(hv(this));};function kv(b){for(var c=[],d=0;2>d;++d){var e=b.a;if(b.match(4))c.push(e.value);else break}if(2==c.length)return c;throw Error(hv(b));}function lv(b){for(var c=[kv(b)];b.match(5);)c.push(kv(b));return c} -function mv(b){for(var c=[b.Ce()];b.match(5);)c.push(b.Ce());return c}function gv(b){var c=1==b.a.type&&"EMPTY"==b.a.value;c&&(b.a=dv(b.c));return c}function hv(b){return"Unexpected `"+b.a.value+"` at position "+b.a.position+" in `"+b.c.c+"`"}var jv={POINT:Nk,LINESTRING:Tm,POLYGON:F,MULTIPOINT:Ym,MULTILINESTRING:Vm,MULTIPOLYGON:Zm},iv={POINT:bv.prototype.De,LINESTRING:bv.prototype.Ce,POLYGON:bv.prototype.Ee,MULTIPOINT:bv.prototype.nl,MULTILINESTRING:bv.prototype.ml,MULTIPOLYGON:bv.prototype.ol};function nv(){this.version=void 0}v(nv,gu);nv.prototype.c=function(b){for(b=b.firstChild;null!==b;b=b.nextSibling)if(1==b.nodeType)return this.a(b);return null};nv.prototype.a=function(b){this.version=Aa(b.getAttribute("version"));b=V({version:this.version},ov,b,[]);return m(b)?b:null};function pv(b,c){return V({},qv,b,c)}function rv(b,c){return V({},sv,b,c)}function tv(b,c){var d=pv(b,c);if(m(d)){var e=[Mq(b.getAttribute("width")),Mq(b.getAttribute("height"))];d.size=e;return d}} -function uv(b,c){return V([],vv,b,c)} -var wv=[null,"http://www.opengis.net/wms"],ov=S(wv,{Service:P(function(b,c){return V({},xv,b,c)}),Capability:P(function(b,c){return V({},yv,b,c)})}),yv=S(wv,{Request:P(function(b,c){return V({},zv,b,c)}),Exception:P(function(b,c){return V([],Av,b,c)}),Layer:P(function(b,c){return V({},Bv,b,c)})}),xv=S(wv,{Name:P(W),Title:P(W),Abstract:P(W),KeywordList:P(uv),OnlineResource:P(fu),ContactInformation:P(function(b,c){return V({},Cv,b,c)}),Fees:P(W),AccessConstraints:P(W),LayerLimit:P(Lq),MaxWidth:P(Lq), -MaxHeight:P(Lq)}),Cv=S(wv,{ContactPersonPrimary:P(function(b,c){return V({},Dv,b,c)}),ContactPosition:P(W),ContactAddress:P(function(b,c){return V({},Ev,b,c)}),ContactVoiceTelephone:P(W),ContactFacsimileTelephone:P(W),ContactElectronicMailAddress:P(W)}),Dv=S(wv,{ContactPerson:P(W),ContactOrganization:P(W)}),Ev=S(wv,{AddressType:P(W),Address:P(W),City:P(W),StateOrProvince:P(W),PostCode:P(W),Country:P(W)}),Av=S(wv,{Format:rq(W)}),Bv=S(wv,{Name:P(W),Title:P(W),Abstract:P(W),KeywordList:P(uv),CRS:tq(W), -EX_GeographicBoundingBox:P(function(b,c){var d=V({},Fv,b,c);if(m(d)){var e=d.westBoundLongitude,f=d.southBoundLatitude,g=d.eastBoundLongitude,d=d.northBoundLatitude;return m(e)&&m(f)&&m(g)&&m(d)?[e,f,g,d]:void 0}}),BoundingBox:tq(function(b){var c=[Kq(b.getAttribute("minx")),Kq(b.getAttribute("miny")),Kq(b.getAttribute("maxx")),Kq(b.getAttribute("maxy"))],d=[Kq(b.getAttribute("resx")),Kq(b.getAttribute("resy"))];return{crs:b.getAttribute("CRS"),extent:c,res:d}}),Dimension:tq(function(b){return{name:b.getAttribute("name"), -units:b.getAttribute("units"),unitSymbol:b.getAttribute("unitSymbol"),"default":b.getAttribute("default"),multipleValues:Hq(b.getAttribute("multipleValues")),nearestValue:Hq(b.getAttribute("nearestValue")),current:Hq(b.getAttribute("current")),values:W(b)}}),Attribution:P(function(b,c){return V({},Gv,b,c)}),AuthorityURL:tq(function(b,c){var d=pv(b,c);if(m(d))return d.name=b.getAttribute("name"),d}),Identifier:tq(W),MetadataURL:tq(function(b,c){var d=pv(b,c);if(m(d))return d.type=b.getAttribute("type"), -d}),DataURL:tq(pv),FeatureListURL:tq(pv),Style:tq(function(b,c){return V({},Hv,b,c)}),MinScaleDenominator:P(Jq),MaxScaleDenominator:P(Jq),Layer:tq(function(b,c){var d=c[c.length-1],e=V({},Bv,b,c);if(m(e)){var f=Hq(b.getAttribute("queryable"));m(f)||(f=d.queryable);e.queryable=m(f)?f:!1;f=Mq(b.getAttribute("cascaded"));m(f)||(f=d.cascaded);e.cascaded=f;f=Hq(b.getAttribute("opaque"));m(f)||(f=d.opaque);e.opaque=m(f)?f:!1;f=Hq(b.getAttribute("noSubsets"));m(f)||(f=d.noSubsets);e.noSubsets=m(f)?f:!1; -f=Kq(b.getAttribute("fixedWidth"));m(f)||(f=d.fixedWidth);e.fixedWidth=f;f=Kq(b.getAttribute("fixedHeight"));m(f)||(f=d.fixedHeight);e.fixedHeight=f;Qa(["Style","CRS","AuthorityURL"],function(b){var c=d[b];if(m(c)){var f=Ab(e,b),f=f.concat(c);e[b]=f}});Qa("EX_GeographicBoundingBox BoundingBox Dimension Attribution MinScaleDenominator MaxScaleDenominator".split(" "),function(b){m(e[b])||(e[b]=d[b])});return e}})}),Gv=S(wv,{Title:P(W),OnlineResource:P(fu),LogoURL:P(tv)}),Fv=S(wv,{westBoundLongitude:P(Jq), -eastBoundLongitude:P(Jq),southBoundLatitude:P(Jq),northBoundLatitude:P(Jq)}),zv=S(wv,{GetCapabilities:P(rv),GetMap:P(rv),GetFeatureInfo:P(rv)}),sv=S(wv,{Format:tq(W),DCPType:tq(function(b,c){return V({},Iv,b,c)})}),Iv=S(wv,{HTTP:P(function(b,c){return V({},Jv,b,c)})}),Jv=S(wv,{Get:P(pv),Post:P(pv)}),Hv=S(wv,{Name:P(W),Title:P(W),Abstract:P(W),LegendURL:tq(tv),StyleSheetURL:P(pv),StyleURL:P(pv)}),qv=S(wv,{Format:P(W),OnlineResource:P(fu)}),vv=S(wv,{Keyword:rq(W)});function Kv(){this.b="http://mapserver.gis.umn.edu/mapserver";this.c=new $q;this.defaultDataProjection=null}v(Kv,Cq); -function Lv(b,c,d){c.namespaceURI=b.b;var e=$p(c),f=[];if(0===c.childNodes.length)return f;"msGMLOutput"==e&&Qa(c.childNodes,function(b){if(1===b.nodeType){var c=d[0],e=b.localName,n=RegExp,p;p="_layer".replace(/([-()\[\]{}+?*.$\^|,:#c.b?c.c:2*c.c)-c.b);b[0]=128;for(var d=1;dd;++d)for(var f=0;32>f;f+=8)b[e++]=c.a[d]>>> +f&255;if(8192>=b.length)c=String.fromCharCode.apply(null,b);else for(c="",d=0;dthis.g&&(this.g=this.b.lineWidth,this.f=null)}; +function Nm(b,c,d){Dm.call(this,b,c,d);this.b={pg:void 0,hd:void 0,cd:void 0,dd:null,ed:void 0,fd:void 0,gd:void 0,fillStyle:void 0,strokeStyle:void 0,lineCap:void 0,lineDash:null,lineJoin:void 0,lineWidth:void 0,miterLimit:void 0}}y(Nm,Dm); +function Om(b,c,d,e,f){var g=b.b,h=[1];b.c.push(h);b.a.push(h);var k,h=0;for(k=e.length;hthis.g&&(this.g=d.lineWidth,this.f=null)):(d.strokeStyle=void 0,d.lineCap=void 0,d.lineDash=null,d.lineJoin=void 0,d.lineWidth=void 0,d.miterLimit=void 0)}; +function Pm(b){var c=b.b,d=c.fillStyle,e=c.strokeStyle,f=c.lineCap,g=c.lineDash,h=c.lineJoin,k=c.lineWidth,m=c.miterLimit;void 0!==d&&c.pg!=d&&(b.c.push([9,d]),c.pg=c.fillStyle);void 0===e||c.hd==e&&c.cd==f&&c.dd==g&&c.ed==h&&c.fd==k&&c.gd==m||(b.c.push([10,e,k,f,h,m,g]),c.hd=e,c.cd=f,c.dd=g,c.ed=h,c.fd=k,c.gd=m)}function Qm(b,c,d){Dm.call(this,b,c,d);this.ia=this.G=this.D=null;this.l="";this.C=this.A=this.u=this.B=0;this.i=this.j=this.b=null}y(Qm,Dm); +Qm.prototype.Hb=function(b,c,d,e,f,g){if(""!==this.l&&this.i&&(this.b||this.j)){if(this.b){f=this.b;var h=this.D;if(!h||h.fillStyle!=f.fillStyle){var k=[9,f.fillStyle];this.c.push(k);this.a.push(k);h?h.fillStyle=f.fillStyle:this.D={fillStyle:f.fillStyle}}}this.j&&(f=this.j,h=this.G,h&&h.lineCap==f.lineCap&&h.lineDash==f.lineDash&&h.lineJoin==f.lineJoin&&h.lineWidth==f.lineWidth&&h.miterLimit==f.miterLimit&&h.strokeStyle==f.strokeStyle||(k=[10,f.strokeStyle,f.lineWidth,f.lineCap,f.lineJoin,f.miterLimit, +f.lineDash,!1],this.c.push(k),this.a.push(k),h?(h.lineCap=f.lineCap,h.lineDash=f.lineDash,h.lineJoin=f.lineJoin,h.lineWidth=f.lineWidth,h.miterLimit=f.miterLimit,h.strokeStyle=f.strokeStyle):this.G={lineCap:f.lineCap,lineDash:f.lineDash,lineJoin:f.lineJoin,lineWidth:f.lineWidth,miterLimit:f.miterLimit,strokeStyle:f.strokeStyle}));f=this.i;h=this.ia;h&&h.font==f.font&&h.textAlign==f.textAlign&&h.textBaseline==f.textBaseline||(k=[11,f.font,f.textAlign,f.textBaseline],this.c.push(k),this.a.push(k),h? +(h.font=f.font,h.textAlign=f.textAlign,h.textBaseline=f.textBaseline):this.ia={font:f.font,textAlign:f.textAlign,textBaseline:f.textBaseline});Fm(this,g);f=this.coordinates.length;b=Em(this,b,c,d,e,!1);b=[5,f,b,this.l,this.B,this.u,this.A,this.C,!!this.b,!!this.j];this.c.push(b);this.a.push(b);Im(this,g)}}; +Qm.prototype.ab=function(b){if(b){var c=b.a;c?(c=c.a,c=vg(c?c:Tl),this.b?this.b.fillStyle=c:this.b={fillStyle:c}):this.b=null;var d=b.l;if(d){var c=d.a,e=d.f,f=d.b,g=d.g,h=d.c,d=d.j,e=void 0!==e?e:"round",f=f?f.slice():Ul,g=void 0!==g?g:"round",h=void 0!==h?h:1,d=void 0!==d?d:10,c=vg(c?c:Vl);if(this.j){var k=this.j;k.lineCap=e;k.lineDash=f;k.lineJoin=g;k.lineWidth=h;k.miterLimit=d;k.strokeStyle=c}else this.j={lineCap:e,lineDash:f,lineJoin:g,lineWidth:h,miterLimit:d,strokeStyle:c}}else this.j=null; +var m=b.f,c=b.g,e=b.j,f=b.i,h=b.c,d=b.b,g=b.B,k=b.u;b=void 0!==m?m:"10px sans-serif";g=void 0!==g?g:"center";k=void 0!==k?k:"middle";this.i?(m=this.i,m.font=b,m.textAlign=g,m.textBaseline=k):this.i={font:b,textAlign:g,textBaseline:k};this.l=void 0!==d?d:"";this.B=void 0!==c?c:0;this.u=void 0!==e?e:0;this.A=void 0!==f?f:0;this.C=void 0!==h?h:1}else this.l=""};function Rm(b,c,d,e){this.u=b;this.g=c;this.B=d;this.j=e;this.c={};this.i=Pi(1,1);this.l=Dd()} +function Sm(b){for(var c in b.c){var d=b.c[c],e;for(e in d)d[e].ve()}}Rm.prototype.f=function(b,c,d,e,f){var g=this.l;ik(g,.5,.5,1/c,-1/c,-d,-b[0],-b[1]);var h=this.i;h.clearRect(0,0,1,1);var k;void 0!==this.j&&(k=Od(),Pd(k,b),Sd(k,c*this.j,k));return Tm(this,h,g,d,e,function(b){if(0za&&(za=Ka,n=Ra)}if(0===za){h=null;break a}za=h[n];h[n]=h[m];h[m]=za;for(n=m+1;nthis.a/2){var c=[[b.source[0][0],b.source[0][1]],[b.source[1][0],b.source[1][1]],[b.source[2][0],b.source[2][1]]];c[0][0]-p>this.a/2&&(c[0][0]-=this.a);c[1][0]-p>this.a/2&&(c[1][0]-=this.a);c[2][0]-p>this.a/2&&(c[2][0]-=this.a);Math.max(c[0][0],c[1][0],c[2][0])-Math.min(c[0][0],c[1][0],c[2][0])q,t=!1;if(0b.u),t)){Math.abs(c[0]-e[0])<=Math.abs(c[1]-e[1])?(r=[(d[0]+e[0])/2,(d[1]+e[1])/2],p=b.c(r),q=[(f[0]+c[0])/2,(f[1]+c[1])/2],t=b.c(q),fn(b,c,d,r,q,g,h,p,t,n-1),fn(b,q,r,e,f,t,p,k,m,n-1)):(r=[(c[0]+d[0])/2,(c[1]+d[1])/2],p=b.c(r),q=[(e[0]+f[0])/2,(e[1]+f[1])/2],t=b.c(q),fn(b,c,r,q,f,g,p,t,m,n-1),fn(b,r,d,e,q,p,h,k,t,n-1));return}if(r){if(!b.B)return;b.l=!0}b.f.push({source:[g,k,m],target:[c,e,f]});b.f.push({source:[g,h,k],target:[c,d,e]})}} +function gn(b){var c=Od();b.f.forEach(function(b){b=b.source;Pd(c,b[0]);Pd(c,b[1]);Pd(c,b[2])});return c};function hn(b,c,d,e,f,g){this.C=c;this.A=b.J();var h=c.J(),k=h?oe(d,h):d,h=bn(b,c,me(k),e);this.B=new en(b,c,k,this.A,.5*h);this.i=e;this.g=d;b=gn(this.B);this.u=(this.c=g(b,h,f))?this.c.b:1;this.f=this.l=null;f=2;g=[];this.c&&(f=0,g=this.c.j);gk.call(this,d,e,this.u,f,g)}y(hn,gk);hn.prototype.X=function(){1==this.state&&(Zc(this.f),this.f=null);hn.da.X.call(this)};hn.prototype.a=function(){return this.l}; +function jn(b){var c=b.c.state;2==c&&(b.l=dn(ke(b.g)/b.i,le(b.g)/b.i,b.u,b.c.$(),0,b.i,b.g,b.B,[{extent:b.c.J(),image:b.c.a()}]));b.state=c;hk(b)}hn.prototype.load=function(){if(0==this.state){this.state=1;hk(this);var b=this.c.state;2==b||3==b?jn(this):(this.f=this.c.Qa("change",function(){var b=this.c.state;if(2==b||3==b)Zc(this.f),this.f=null,jn(this)},!1,this),this.c.load())}};function kn(b){yh.call(this,{attributions:b.attributions,extent:b.extent,logo:b.logo,projection:b.projection,state:b.state});this.G=void 0!==b.resolutions?b.resolutions:null;this.a=null;this.va=0}y(kn,yh);function ln(b,c){if(b.G){var d=wb(b.G,c,0);c=b.G[d]}return c} +kn.prototype.C=function(b,c,d,e){var f=this.f;if(f&&e&&!Xe(f,e)){if(this.a){if(this.va==this.c&&Xe(this.a.C,e)&&this.a.$()==c&&this.a.b==d&&be(this.a.J(),b))return this.a;this.a.Ec();this.a=null}this.a=new hn(f,e,b,c,d,ra(function(b,c,d){return this.pd(b,c,d,f)},this));this.va=this.c;return this.a}f&&(e=f);return this.pd(b,c,d,e)};kn.prototype.D=function(b){b=b.target;switch(b.state){case 1:this.o(new mn(nn,b));break;case 2:this.o(new mn(on,b));break;case 3:this.o(new mn(pn,b))}}; +function qn(b,c){b.a().src=c}function mn(b,c){vc.call(this,b);this.image=c}y(mn,vc);var nn="imageloadstart",on="imageloadend",pn="imageloaderror";function rn(b){kn.call(this,{attributions:b.attributions,logo:b.logo,projection:b.projection,resolutions:b.resolutions,state:void 0!==b.state?b.state:void 0});this.ga=b.canvasFunction;this.Z=null;this.ea=0;this.pa=void 0!==b.ratio?b.ratio:1.5}y(rn,kn);rn.prototype.pd=function(b,c,d,e){c=ln(this,c);var f=this.Z;if(f&&this.ea==this.c&&f.$()==c&&f.b==d&&Xd(f.J(),b))return f;b=b.slice();qe(b,this.pa);(e=this.ga(b,c,d,[ke(b)/c*d,le(b)/c*d],e))&&(f=new $m(b,c,d,this.j,e));this.Z=f;this.ea=this.c;return f};function sn(b){id.call(this);this.wa=void 0;this.a="geometry";this.f=null;this.g=void 0;this.b=null;C(this,kd(this.a),this.ge,!1,this);void 0!==b&&(b instanceof bf||!b?this.La(b):this.I(b))}y(sn,id);l=sn.prototype;l.clone=function(){var b=new sn(this.P());b.vc(this.a);var c=this.W();c&&b.La(c.clone());(c=this.f)&&b.vf(c);return b};l.W=function(){return this.get(this.a)};l.Na=function(){return this.wa};l.Mj=function(){return this.a};l.vl=function(){return this.f};l.Qb=function(){return this.g}; +l.wl=function(){this.s()};l.ge=function(){this.b&&(Zc(this.b),this.b=null);var b=this.W();b&&(this.b=C(b,"change",this.wl,!1,this));this.s()};l.La=function(b){this.set(this.a,b)};l.vf=function(b){this.g=(this.f=b)?tn(b):void 0;this.s()};l.ic=function(b){this.wa=b;this.s()};l.vc=function(b){Yc(this,kd(this.a),this.ge,!1,this);this.a=b;C(this,kd(this.a),this.ge,!1,this);this.ge()};function tn(b){if(!ka(b)){var c;c=ga(b)?b:[b];b=function(){return c}}return b};function un(b){b.prototype.then=b.prototype.then;b.prototype.$goog_Thenable=!0}function vn(b){if(!b)return!1;try{return!!b.$goog_Thenable}catch(c){return!1}};function wn(b,c,d){this.f=d;this.b=b;this.g=c;this.c=0;this.a=null}wn.prototype.get=function(){var b;0d?b[1]="?":d==c.length-1&&(b[1]=void 0)}return b.join("")}function mo(b,c,d){if(ga(c))for(var e=0;e=b[0]&&c[3]>=b[1]}function q(b,c,d,e,f){for(var g=[c,d],h;g.length;)d=g.pop(),c=g.pop(),d-c<=e||(h=c+Math.ceil((d-c)/e/2)*e,r(b,c,d,h,f),g.push(c,h,h,d))}function r(b,c,d,e,f){for(var g,h,k,m,n;d>c;){600h-g/2?-1:1),k=Math.max(c,Math.floor(e-h*m/g+n)),h=Math.min(d,Math.floor(e+(g-h)*m/g+n)),r(b,k,h,e,f));g=b[e];h=c;m=d;t(b,c,e);for(0f(b[h],g);)h++;for(;0this.af)this.fj(e,c),c--;else break;this.Ui(d,e,c)},fj:function(b,c){var e=b[c],f=e.children.length,g=this.gg;this.Vi(e,g,f);f=this.Wi(e,g,f);f={children:e.children.splice(f,e.children.length-f),height:e.height};e.Pa&&(f.Pa=!0);d(e,this.cb);d(f,this.cb);c?b[c-1].children.push(f):this.ig(e, +f)},ig:function(b,c){this.data={children:[b,c],height:b.height+1};d(this.data,this.cb)},Wi:function(b,c,d){var f,g,h,m,n,p,q;n=p=Infinity;for(f=c;f<=d-c;f++)g=e(b,0,f,this.cb),h=e(b,f,d,this.cb),m=Math.max(0,Math.min(g[2],h[2])-Math.max(g[0],h[0]))*Math.max(0,Math.min(g[3],h[3])-Math.max(g[1],h[1])),g=k(g)+k(h),m=c;p--)q=b.children[p],f(k,b.Pa?g(q):q.bbox),n+=m(k);return n},Ui:function(b,c,d){for(;0<=d;d--)f(c[d].bbox,b)},Yi:function(b){for(var c=b.length-1,e;0<=c;c--)0===b[c].children.length?0B||this.b[1]> +A)?(v.width=B,v.height=A,this.b=[B,A],this.B=!Bm(this.b),this.f=null):(B=this.b[0],A=this.b[1],(v=n!=this.C)||(v=this.f,v=!(v.a<=z.a&&z.f<=v.f&&v.c<=z.c&&z.b<=v.b)),v&&(this.f=null))):(O=Pi(B,A),this.j=O.canvas,this.b=[B,A],this.i=O,this.B=!Bm(this.b));var K,I;this.f?(A=this.f,B=kg(A)):(B/=p[0],A/=p[1],K=z.a-Math.floor((B-kg(z))/2),I=z.c-Math.floor((A-jg(z))/2),this.C=n,this.G=p[0],this.D=p[1],this.f=new gg(K,K+B-1,I,I+A-1),this.l=Array(B*A),A=this.f);v={};v[n]={};var G=[],la=this.bd(h,f,v),Ea=g.b(), +L=Od(),za=new gg(0,0,0,0),Ra,Ka,kb;for(I=z.a;I<=z.f;++I)for(kb=z.c;kb<=z.b;++kb)Ka=h.Ob(n,I,kb,d,f),K=Ka.state,2==K||4==K||3==K&&!Ea?v[n][fg(Ka.a)]=Ka:(Ra=Eh(k,Ka.a,la,za,L),Ra||(G.push(Ka),(Ra=Gh(k,Ka.a,za,L))&&la(n+1,Ra)));la=0;for(Ra=G.length;lam[2];)++n,p=k*n,p=zm(this,b,p),q.b(r,f,p,h,g),c-=k;p=zm(this,b,0)}r!=d&&(ym(this,"render",r,b,p),d.drawImage(r.canvas,0,0));r.globalAlpha=t}ym(this,"postcompose",d,b,p)};Sp.prototype.Za=function(b,c,d,e){if(this.b){var f=c.viewState.resolution,g=c.viewState.rotation,h=this.a,k=c.layerStates[w(h)],m={};return this.b.f(b,f,g,k.rb?c.skippedFeatureUids:{},function(b){var c=w(b).toString();if(!(c in m))return m[c]=!0,d.call(e,b,h)})}};Sp.prototype.A=function(){mk(this)}; +Sp.prototype.zd=function(b){function c(b){var c,e=b.Qb();e?c=e.call(b,n):(e=d.b)&&(c=e(b,n));if(c){if(c){var f,g=!1,e=0;for(f=c.length;eG&&Ng(this.target,z.target,0)}else{if(!b.viewHints[0]&&!b.viewHints[1]){O=Fh(z.g,r,z.b[0],A);G=[];v=I=void 0;for(v in z.c)I=z.c[v],O.contains(I.a)||G.push(I);Ea= +O=void 0;O=0;for(Ea=G.length;O=n;){x=b.b[g];d=b.u[g]; +e=w(d).toString();if(void 0===k[e]&&d.W()&&(void 0===p||pe(p,d.W().J()))&&(q.clear(q.COLOR_BUFFER_BIT|q.DEPTH_BUFFER_BIT),q.drawElements(4,t-x,f,x*c),t=m(d))){b=t;break a}t=x;g--}b=void 0}else q.clear(q.COLOR_BUFFER_BIT|q.DEPTH_BUFFER_BIT),Jq(b,q,c,k,b.i,b.j),b=(b=m(null))?b:void 0;x=b}q.disableVertexAttribArray(r.f);q.disableVertexAttribArray(r.a);q.disableVertexAttribArray(r.g);q.disableVertexAttribArray(r.c);q.disableVertexAttribArray(r.b);return x} +function Jq(b,c,d,e,f,g){var h=d.b?5125:5123;d=d.b?4:2;if(Qb(e)){var k;b=0;e=f.length;for(k=0;bc[0]||c[0]>f[0]||0> +c[1]||c[1]>f[1])&&(this.i||(this.i=Pi(1,1)),this.i.clearRect(0,0,1,1),this.i.drawImage(this.f.a(),c[0],c[1],1,1,0,0,1,1),0e?c[0]=e-d:0>f&&(c[0]= +Math.abs(f)+d),0>g?c[1]=g-d:0>h&&(c[1]=Math.abs(h)+d),0===c[0]&&0===c[1])||(d=b.aa().Ta(),e=b.Oa(d),c=[e[0]+c[0],e[1]+c[1]],this.g&&(this.g.source=d,b.Ma(Zf(this.g))),b.aa().jb(b.Fa(c)))}}};l.Pk=function(){nr(this)};l.Uh=function(b){this.set("element",b)};l.setMap=function(b){this.set("map",b)};l.Zh=function(b){this.set("offset",b)};l.xf=function(b){this.set("position",b)}; +function or(b,c){var d=Cg(b),e=new yg(0,0),f;f=d?Cg(d):document;f=!Zb||9<=lc||Sg(Ag(f))?f.documentElement:f.body;b!=f&&(f=eh(b),d=Tg(Ag(d)),e.x=f.left+d.x,e.y=f.top+d.y);return[e.x,e.y,e.x+c[0],e.y+c[1]]}l.bi=function(b){this.set("positioning",b)};function pr(b,c){b.a.visible!==c&&(ih(b.b,c),b.a.visible=c)} +function nr(b){var c=b.se(),d=b.Yg();if(void 0!==c&&c.b&&void 0!==d){var d=c.Oa(d),e=c.Ra(),c=b.b.style,f=b.Eg(),g=b.Fg(),h=f[0],f=f[1];if("bottom-right"==g||"center-right"==g||"top-right"==g)""!==b.a.oe&&(b.a.oe=c.left=""),h=Math.round(e[0]-d[0]-h)+"px",b.a.Ne!=h&&(b.a.Ne=c.right=h);else{""!==b.a.Ne&&(b.a.Ne=c.right="");if("bottom-center"==g||"center-center"==g||"top-center"==g)h-=gh(b.b).width/2;h=Math.round(d[0]+h)+"px";b.a.oe!=h&&(b.a.oe=c.left=h)}if("bottom-left"==g||"bottom-center"==g||"bottom-right"== +g)""!==b.a.Oe&&(b.a.Oe=c.top=""),d=Math.round(e[1]-d[1]-f)+"px",b.a.Td!=d&&(b.a.Td=c.bottom=d);else{""!==b.a.Td&&(b.a.Td=c.bottom="");if("center-left"==g||"center-center"==g||"center-right"==g)f-=gh(b.b).height/2;d=Math.round(d[1]+f)+"px";b.a.Oe!=d&&(b.a.Oe=c.top=d)}pr(b,!0)}else pr(b,!1)};function qr(b){b=b?b:{};this.j=void 0!==b.collapsed?b.collapsed:!0;this.i=void 0!==b.collapsible?b.collapsible:!0;this.i||(this.j=!1);var c=b.className?b.className:"ol-overviewmap",d=b.tipLabel?b.tipLabel:"Overview map",e=b.collapseLabel?b.collapseLabel:"\u00ab";this.A=ia(e)?Hg("SPAN",{},e):e;e=b.label?b.label:"\u00bb";this.C=ia(e)?Hg("SPAN",{},e):e;d=Hg("BUTTON",{type:"button",title:d},this.i&&!this.j?this.A:this.C);C(d,"click",this.Rl,!1,this);var e=Hg("DIV","ol-overviewmap-map"),f=this.b=new S({controls:new og, +interactions:new og,target:e,view:b.view});b.layers&&b.layers.forEach(function(b){f.jg(b)},this);var g=Hg("DIV","ol-overviewmap-box");this.l=new mr({position:[0,0],positioning:"bottom-left",element:g});this.b.kg(this.l);c=Hg("DIV",c+" ol-unselectable ol-control"+(this.j&&this.i?" ol-collapsed":"")+(this.i?"":" ol-uncollapsible"),e,d);qh.call(this,{element:c,render:b.render?b.render:rr,target:b.target})}y(qr,qh);l=qr.prototype; +l.setMap=function(b){var c=this.a;b!==c&&(c&&(c=c.aa())&&Yc(c,kd("rotation"),this.ie,!1,this),qr.da.setMap.call(this,b),b&&(this.u.push(C(b,"propertychange",this.Ik,!1,this)),0===this.b.Xg().$b()&&this.b.Xh(b.oc()),b=b.aa()))&&(C(b,kd("rotation"),this.ie,!1,this),Sf(b)&&(this.b.Uc(),sr(this)))};l.Ik=function(b){"view"===b.key&&((b=b.oldValue)&&Yc(b,kd("rotation"),this.ie,!1,this),b=this.a.aa(),C(b,kd("rotation"),this.ie,!1,this))};l.ie=function(){this.b.aa().te(this.a.aa().Ea())}; +function rr(){var b=this.a,c=this.b;if(b.b&&c.b){var d=b.Ra(),b=b.aa().Zc(d),e=c.Ra(),d=c.aa().Zc(e),f=c.Oa(he(b)),c=c.Oa(fe(b)),c=new zg(Math.abs(f[0]-c[0]),Math.abs(f[1]-c[1])),f=e[0],e=e[1];c.width<.1*f||c.height<.1*e||c.width>.75*f||c.height>.75*e?sr(this):Xd(d,b)||(b=this.b,d=this.a.aa(),b.aa().jb(d.Ta()))}tr(this)}function sr(b){var c=b.a;b=b.b;var d=c.Ra(),c=c.aa().Zc(d),d=b.Ra();b=b.aa();qe(c,1/(.1*Math.pow(2,Math.log(7.5)/Math.LN2/2)));b.jf(c,d)} +function tr(b){var c=b.a,d=b.b;if(c.b&&d.b){var e=c.Ra(),f=c.aa(),g=d.aa();d.Ra();var c=f.Ea(),h=b.l,d=b.l.re(),f=f.Zc(e),e=g.$(),g=ee(f),f=ge(f),k;if(b=b.a.aa().Ta())k=[g[0]-b[0],g[1]-b[1]],wd(k,c),rd(k,b);h.xf(k);d&&(k=new zg(Math.abs((g[0]-f[0])/e),Math.abs((f[1]-g[1])/e)),c=Sg(Ag(Cg(d))),!Zb||jc("10")||c&&jc("8")?(d=d.style,ac?d.MozBoxSizing="border-box":bc?d.WebkitBoxSizing="border-box":d.boxSizing="border-box",d.width=Math.max(k.width,0)+"px",d.height=Math.max(k.height,0)+"px"):(b=d.style,c? +(c=lh(d,"padding"),d=oh(d),b.pixelWidth=k.width-d.left-c.left-c.right-d.right,b.pixelHeight=k.height-d.top-c.top-c.bottom-d.bottom):(b.pixelWidth=k.width,b.pixelHeight=k.height)))}}l.Rl=function(b){b.preventDefault();ur(this)};function ur(b){Yg(b.element,"ol-collapsed");b.j?Pg(b.A,b.C):Pg(b.C,b.A);b.j=!b.j;var c=b.b;b.j||c.b||(c.Uc(),sr(b),Xc(c,"postrender",function(){tr(this)},!1,b))}l.Ql=function(){return this.i}; +l.Tl=function(b){this.i!==b&&(this.i=b,Yg(this.element,"ol-uncollapsible"),!b&&this.j&&ur(this))};l.Sl=function(b){this.i&&this.j!==b&&ur(this)};l.Pl=function(){return this.j};l.ak=function(){return this.b};function vr(b){b=b?b:{};var c=b.className?b.className:"ol-scale-line";this.l=Hg("DIV",c+"-inner");this.i=Hg("DIV",c+" ol-unselectable",this.l);this.C=null;this.A=void 0!==b.minWidth?b.minWidth:64;this.b=!1;this.S=void 0;this.D="";this.j=null;qh.call(this,{element:this.i,render:b.render?b.render:wr,target:b.target});C(this,kd("units"),this.Z,!1,this);this.T(b.units||"metric")}y(vr,qh);var xr=[1,2,5];vr.prototype.G=function(){return this.get("units")}; +function wr(b){(b=b.frameState)?this.C=b.viewState:this.C=null;yr(this)}vr.prototype.Z=function(){yr(this)};vr.prototype.T=function(b){this.set("units",b)}; +function yr(b){var c=b.C;if(c){var d=c.center,e=c.projection,c=e.getPointResolution(c.resolution,d),f=e.c,g=b.G();"degrees"!=f||"metric"!=g&&"imperial"!=g&&"us"!=g&&"nautical"!=g?"degrees"!=f&&"degrees"==g?(b.j||(b.j=Je(e,Fe("EPSG:4326"))),d=Math.cos(Wa(b.j(d)[1])),e=Be.radius,e/=Ce[f],c*=180/(Math.PI*d*e)):b.j=null:(b.j=null,d=Math.cos(Wa(d[1])),c*=Math.PI*d*Be.radius/180);d=b.A*c;f="";"degrees"==g?d<1/60?(f="\u2033",c*=3600):1>d?(f="\u2032",c*=60):f="\u00b0":"imperial"==g?.9144>d?(f="in",c/=.0254): +1609.344>d?(f="ft",c/=.3048):(f="mi",c/=1609.344):"nautical"==g?(c/=1852,f="nm"):"metric"==g?1>d?(f="mm",c*=1E3):1E3>d?f="m":(f="km",c/=1E3):"us"==g&&(.9144>d?(f="in",c*=39.37):1609.344>d?(f="ft",c/=.30480061):(f="mi",c/=1609.3472));for(d=3*Math.floor(Math.log(b.A*c)/Math.log(10));;){e=xr[d%3]*Math.pow(10,Math.floor(d/3));g=Math.round(e/c);if(isNaN(g)){ih(b.i,!1);b.b=!1;return}if(g>=b.A)break;++d}c=e+" "+f;b.D!=c&&(b.l.innerHTML=c,b.D=c);b.S!=g&&(b.l.style.width=g+"px",b.S=g);b.b||(ih(b.i,!0),b.b= +!0)}else b.b&&(ih(b.i,!1),b.b=!1)};function zr(b){pc.call(this);this.c=b;this.a={}}y(zr,pc);var Ar=[];zr.prototype.Qa=function(b,c,d,e){ga(c)||(c&&(Ar[0]=c.toString()),c=Ar);for(var f=0;fd.height?(this.i=1,d=new $g(0,0,e,0)):(this.i=Kr,d=new $g(0,0,0,c));this.b.a=d||new $g(NaN,NaN,NaN,NaN);this.C=!0}b=b.frameState.viewState.resolution;b!==this.j&&(this.j=b,b=1-Qf(this.a.aa())(b),d=this.b,c=Qg(this.element),1==this.i?ch(c,d.a.left+d.a.width*b):ch(c,d.a.left, +d.a.top+d.a.height*b))}}l.sk=function(b){var c=this.a,d=c.aa(),e=d.$();c.Ma(bg({resolution:e,duration:this.A,easing:Vf}));b=Mr(this,Nr(this,b.offsetX-this.l[0]/2,b.offsetY-this.l[1]/2));d.Ub(d.constrainResolution(b))};l.vk=function(){Tf(this.a.aa(),1)};l.tk=function(b){this.j=Mr(this,Nr(this,b.left,b.top));this.a.aa().Ub(this.j)};l.uk=function(){var b=this.a,c=b.aa();Tf(c,-1);b.Ma(bg({resolution:this.j,duration:this.A,easing:Vf}));b=c.constrainResolution(this.j);c.Ub(b)}; +function Nr(b,c,d){var e=b.b.a;return Sa(1===b.i?(c-e.left)/e.width:(d-e.top)/e.height,0,1)}function Mr(b,c){return Pf(b.a.aa())(1-c)};function Or(b){b=b?b:{};this.b=b.extent?b.extent:null;var c=b.className?b.className:"ol-zoom-extent",d=Hg("BUTTON",{type:"button",title:b.tipLabel?b.tipLabel:"Fit to extent"},b.label?b.label:"E");C(d,"click",this.j,!1,this);c=Hg("DIV",c+" ol-unselectable ol-control",d);qh.call(this,{element:c,target:b.target})}y(Or,qh);Or.prototype.j=function(b){b.preventDefault();var c=this.a;b=c.aa();var d=this.b?this.b:b.g.J(),c=c.Ra();b.jf(d,c)};function Pr(b){id.call(this);b=b?b:{};this.a=null;C(this,kd("tracking"),this.ul,!1,this);this.uf(void 0!==b.tracking?b.tracking:!1)}y(Pr,id);l=Pr.prototype;l.X=function(){this.uf(!1);Pr.da.X.call(this)}; +l.On=function(b){b=b.a;if(null!==b.alpha){var c=Wa(b.alpha);this.set("alpha",c);"boolean"==typeof b.absolute&&b.absolute?this.set("heading",c):ja(b.webkitCompassHeading)&&-1!=b.webkitCompassAccuracy&&this.set("heading",Wa(b.webkitCompassHeading))}null!==b.beta&&this.set("beta",Wa(b.beta));null!==b.gamma&&this.set("gamma",Wa(b.gamma));this.s()};l.Bj=function(){return this.get("alpha")};l.Ej=function(){return this.get("beta")};l.Kj=function(){return this.get("gamma")};l.tl=function(){return this.get("heading")}; +l.Tg=function(){return this.get("tracking")};l.ul=function(){if($i){var b=this.Tg();b&&!this.a?this.a=C(ba,"deviceorientation",this.On,!1,this):!b&&this.a&&(Zc(this.a),this.a=null)}};l.uf=function(b){this.set("tracking",b)};function Qr(){this.defaultDataProjection=null}function Rr(b,c,d){var e;d&&(e={dataProjection:d.dataProjection?d.dataProjection:b.Ia(c),featureProjection:d.featureProjection});return Sr(b,e)}function Sr(b,c){var d;c&&(d={featureProjection:c.featureProjection,dataProjection:c.dataProjection?c.dataProjection:b.defaultDataProjection,rightHanded:c.rightHanded});return d} +function Tr(b,c,d){var e=d?Fe(d.featureProjection):null;d=d?Fe(d.dataProjection):null;return e&&d&&!Xe(e,d)?b instanceof bf?(c?b.clone():b).kb(c?e:d,c?d:e):af(c?b.slice():b,c?e:d,c?d:e):b};function Ur(){this.defaultDataProjection=null}y(Ur,Qr);function Vr(b){return ma(b)?b:ia(b)?(b=ao(b))?b:null:null}l=Ur.prototype;l.V=function(){return"json"};l.Tb=function(b,c){return this.Rc(Vr(b),Rr(this,b,c))};l.Ba=function(b,c){return this.Jf(Vr(b),Rr(this,b,c))};l.Sc=function(b,c){return this.Dh(Vr(b),Rr(this,b,c))};l.Ia=function(b){return this.Kh(Vr(b))};l.Jd=function(b,c){return bo(this.Vc(b,c))};l.Vb=function(b,c){return bo(this.Re(b,c))};l.Wc=function(b,c){return bo(this.Te(b,c))};function Wr(b,c,d,e,f){var g=NaN,h=NaN,k=(d-c)/e;if(0!==k)if(1==k)g=b[c],h=b[c+1];else if(2==k)g=.5*b[c]+.5*b[c+e],h=.5*b[c+1]+.5*b[c+e+1];else{var h=b[c],k=b[c+1],m=0,g=[0],n;for(n=c+e;n>1,p=h(d,g[n]),0r?(d=(d-g[-r-2])/(g[-r-1]-g[-r-2]),c+=(-r-2)*e,g=qd(b[c],b[c+e],d),h=qd(b[c+1],b[c+e+1],d)):(g=b[c+r*e],h=b[c+r*e+1])}return f?(f[0]= +g,f[1]=h,f):[g,h]}function Xr(b,c,d,e,f,g){if(d==c)return null;if(f>1,fb||this.g.length<=b)return null;var c=new T(null);c.ba(this.b,this.v.slice(0===b?0:this.g[b-1],this.g[b]));return c}; +l.rd=function(){var b=this.v,c=this.g,d=this.b,e=[],f=0,g,h;g=0;for(h=c.length;gb||c<=b)return null;c=new D(null);c.ba(this.b,this.v.slice(b*this.a,(b+1)*this.a));return c};l.ue=function(){var b=this.v,c=this.b,d=this.a,e=[],f,g;f=0;for(g=b.length;fb||this.g.length<=b)return null;var c;0===b?c=0:(c=this.g[b-1],c=c[c.length-1]);b=this.g[b].slice();var d=b[b.length-1];if(0!==c){var e,f;e=0;for(f=b.length;eb||0!==this.i&&bc)throw Error("Bad port number "+c);b.l=c}else b.l=null}function It(b,c,d){c instanceof Kt?(b.b=c,Qt(b.b,b.j)):(d||(c=Lt(c,Rt)),b.b=new Kt(c,0,b.j))}function St(b){return b instanceof Ft?b.clone():new Ft(b,void 0)} +function Tt(b,c){b instanceof Ft||(b=St(b));c instanceof Ft||(c=St(c));var d=b,e=c,f=d.clone(),g=!!e.f;g?Gt(f,e.f):g=!!e.i;g?f.i=e.i:g=!!e.c;g?f.c=e.c:g=null!=e.l;var h=e.a;if(g)Ht(f,e.l);else if(g=!!e.a)if("/"!=h.charAt(0)&&(d.c&&!d.a?h="/"+h:(d=f.a.lastIndexOf("/"),-1!=d&&(h=f.a.substr(0,d+1)+h))),d=h,".."==d||"."==d)h="";else if(-1!=d.indexOf("./")||-1!=d.indexOf("/.")){for(var h=0==d.lastIndexOf("/",0),d=d.split("/"),k=[],m=0;m>4&15).toString(16)+(b&15).toString(16)} +var Mt=/[#\/\?@]/g,Ot=/[\#\?:]/g,Nt=/[\#\?]/g,Rt=/[\#\?@]/g,Pt=/#/g;function Kt(b,c,d){this.c=this.a=null;this.b=b||null;this.f=!!d}function Vt(b){b.a||(b.a=new ri,b.c=0,b.b&&ko(b.b,function(c,d){b.add(decodeURIComponent(c.replace(/\+/g," ")),d)}))}l=Kt.prototype;l.nc=function(){Vt(this);return this.c};l.add=function(b,c){Vt(this);this.b=null;b=Wt(this,b);var d=this.a.get(b);d||this.a.set(b,d=[]);d.push(c);this.c++;return this}; +l.remove=function(b){Vt(this);b=Wt(this,b);return ti(this.a.c,b)?(this.b=null,this.c-=this.a.get(b).length,this.a.remove(b)):!1};l.clear=function(){this.a=this.b=null;this.c=0};l.Ka=function(){Vt(this);return 0==this.c};function Xt(b,c){Vt(b);c=Wt(b,c);return ti(b.a.c,c)}l.O=function(){Vt(this);for(var b=this.a.pc(),c=this.a.O(),d=[],e=0;ee;++e){var f=parseInt(d[e],10).toString(16);d[e]=1==f.length?"0"+f:f}Es(b,d.join(""))} +function dv(b,c,d){sp({node:b},ev,fv,[c],d)}function gv(b,c,d){var e={node:b};c.Na()&&b.setAttribute("id",c.Na());b=c.P();var f=c.Qb();if(f&&(f=f.call(c,0))&&0>1,x=-7;g=e?g-1:0;var z=e?-1:1,B=b[c+g];g+=z;e=B&(1<<-x)-1;B>>=-x;for(x+=q;0>=-x;for(x+=f;0>1,B=23===g?Math.pow(2,-24)-Math.pow(2,-77):0;q=f?0:q-1;var A=f?1:-1,v=0>c||0===c&&0>1/c?1:0;c=Math.abs(c);isNaN(c)||Infinity===c?(c=isNaN(c)?1:0,f=x):(f=Math.floor(Math.log(c)/Math.LN2),1>c*(r=Math.pow(2,-f))&&(f--,r*=2),c=1<=f+z?c+B/r:c+B*Math.pow(2,1-z),2<=c*r&&(f++,r/=2),f+z>=x?(c=0,f=x):1<=f+z?(c=(c*r-1)*Math.pow(2,g),f+=z):(c=c*Math.pow(2,z-1)*Math.pow(2,g),f=0));for(;8<=g;b[e+q]=c&255,q+=A,c/=256,g-=8);f=f<g)if(h)if(56320>g){e.push(239,191,189);h=g;continue}else g=h-55296<<10|g-56320|65536,h=null;else{56319< +g||f+1===c?e.push(239,191,189):h=g;continue}else h&&(e.push(239,191,189),h=null);128>g?e.push(g):2048>g?e.push(g>>6|192,g&63|128):65536>g?e.push(g>>12|224,g>>6&63|128,g&63|128):e.push(g>>18|240,g>>12&63|128,g>>6&63|128,g&63|128)}return e}c.ka=g;var k=b("ieee754"),m,n,p;m={Mh:function(b){return(this[b]|this[b+1]<<8|this[b+2]<<16)+16777216*this[b+3]},Yf:function(b,c){this[c]=b;this[c+1]=b>>>8;this[c+2]=b>>>16;this[c+3]=b>>>24},Eh:function(b){return(this[b]|this[b+1]<<8|this[b+2]<<16)+(this[b+3]<<24)}, +Nf:function(b){return k.read(this,b,!0,23,4)},Hf:function(b){return k.read(this,b,!0,52,8)},pi:function(b,c){return k.write(this,b,c,!0,23,4)},mi:function(b,c){return k.write(this,b,c,!0,52,8)},toString:function(b,c,e){var f=b="";e=Math.min(this.length,e||this.length);for(c=c||0;c=g?(b+=decodeURIComponent(f)+String.fromCharCode(g),f=""):f+="%"+g.toString(16)}return b+=decodeURIComponent(f)},write:function(b,c){for(var e=b===n?p:h(b),f=0;f>3,c,this);this.ca===g&&this.Xo(f)}return c},lo:function(){var b=this.Eb.Nf(this.ca);this.ca+=4;return b},ho:function(){var b=this.Eb.Hf(this.ca);this.ca+=8;return b},za:function(){var b=this.Eb,c,e,f,g,h;c=b[this.ca++];if(128>c)return c;c=c&127;f=b[this.ca++];if(128>f)return c|f<<7;f=(f&127)<<7;g=b[this.ca++];if(128>g)return c|f|g<<14;g=(g&127)<<14;h=b[this.ca++];if(128>h)return c|f|g|h<<21;e=b[this.ca++];c=(c|f|g|(h&127)<<21)+268435456*(e&127);if(128>e)return c;e=b[this.ca++];c+=34359738368* +(e&127);if(128>e)return c;e=b[this.ca++];c+=4398046511104*(e&127);if(128>e)return c;e=b[this.ca++];c+=562949953421312*(e&127);if(128>e)return c;e=b[this.ca++];c+=72057594037927936*(e&127);if(128>e)return c;e=b[this.ca++];c+=0x7fffffffffffffff*(e&127);if(128>e)return c;throw Error("Expected varint not more than 10 bytes");},wo:function(){var b=this.ca,c=this.za();if(cf?g<<7*f:g* +Math.pow(2,7*f));return-c-1},Fd:function(){var b=this.za();return 1===b%2?(b+1)/-2:b/2},eo:function(){return Boolean(this.za())},Qf:function(){var b=this.za()+this.ca,c=this.Eb.toString("utf8",this.ca,b);this.ca=b;return c},Xo:function(b){b=b&7;if(b===h.f)for(;127>3),f--,1===e||2===e)g+=b.Fd(),h+=b.Fd(),1===e&&(z&&x.push(z),z=[]),z.push(new k(g,h));else if(7===e)z&&z.push(z[0].clone());else throw Error("unknown command "+e);z&&x.push(z);return x};g.prototype.bbox=function(){var b=this.lc;b.ca=this.Ye;for(var c=b.za()+b.ca,e=1,f=0,g=0,h=0,k=Infinity,z=-Infinity,B=Infinity,A= +-Infinity;b.ca>3),f--,1===e||2===e)g+=b.Fd(),h+=b.Fd(),gz&&(z=g),hA&&(A=h);else if(7!==e)throw Error("unknown command "+e);return[k,B,z,A]}},{"point-geometry":1}],5:[function(b,c){function g(b,c){this.version=1;this.name=null;this.extent=4096;this.length=0;this.lc=b;this.Pd=[];this.Rd=[];this.Od=[];b.Lf(h,this,c);this.length=this.Od.length}function h(b,c,e){15===b?c.version=e.za():1===b?c.name=e.Qf():5===b?c.extent=e.za():2===b?c.Od.push(e.ca): +3===b?c.Pd.push(e.Qf()):4===b&&c.Rd.push(k(e))}function k(b){for(var c=null,e=b.za()+b.ca;b.ca>3,c=1===c?b.Qf():2===c?b.lo():3===c?b.ho():4===c?b.wo():5===c?b.za():6===c?b.Fd():7===c?b.eo():null;return c}var m=b("./vectortilefeature.js");c.ka=g;g.prototype.feature=function(b){if(0>b||b>=this.Od.length)throw Error("feature index out of bounds");this.lc.ca=this.Od[b];b=this.lc.za()+this.lc.ca;return new m(this.lc,b,this.extent,this.Pd,this.Rd)}},{"./vectortilefeature.js":4}]},{},[2])(2)}); +zp=c.ka})();function Ov(b){this.defaultDataProjection=null;b=b?b:{};this.defaultDataProjection=new De({code:"EPSG:3857",units:"tile-pixels"});this.a=b.featureClass?b.featureClass:Vm;this.f=b.geometryName?b.geometryName:"geometry";this.c=b.layerName?b.layerName:"layer";this.b=b.layers?b.layers:null}y(Ov,Qr);Ov.prototype.V=function(){return"arraybuffer"}; +Ov.prototype.Ba=function(b,c){var d=this.b,e=new yp(b),e=new zp.Si(e),f=[],g=this.a,h,k,m;for(m in e.layers)if(!d||-1!=d.indexOf(m)){h=e.layers[m];for(var n=0,p=h.length;nf?~(f<<1):f<<1;d="";e=0;for(f=b.length;e>=5;h=g+63;k+=String.fromCharCode(h);d+=k}return d} +function sw(b,c){var d=c?c:1E5,e=[],f=0,g=0,h,k;h=0;for(k=b.length;hm?(e.push(f),g=f=0):g+=5}f=0;for(g=e.length;f>1):h>>1;f=0;for(g=e.length;f=b||"."==b&&!(void 0!==c&&c)} +function Uw(b){var c=b.c.charAt(++b.a),d={position:b.a,value:c};if("("==c)d.type=2;else if(","==c)d.type=5;else if(")"==c)d.type=3;else if(Ww(c)||"-"==c){d.type=4;var e,c=b.a,f=!1,g=!1;do{if("."==e)f=!0;else if("e"==e||"E"==e)g=!0;e=b.c.charAt(++b.a)}while(Ww(e,f)||!g&&("e"==e||"E"==e)||g&&("-"==e||"+"==e));b=parseFloat(b.c.substring(c,b.a--));d.value=b}else if("a"<=c&&"z">=c||"A"<=c&&"Z">=c){d.type=1;c=b.a;do e=b.c.charAt(++b.a);while("a"<=e&&"z">=e||"A"<=e&&"Z">=e);b=b.c.substring(c,b.a--).toUpperCase(); +d.value=b}else{if(" "==c||"\t"==c||"\r"==c||"\n"==c)return Uw(b);if(""===c)d.type=6;else throw Error("Unexpected character: "+c);}return d}function Sw(b){this.c=b}l=Sw.prototype;l.match=function(b){if(b=this.a.type==b)this.a=Uw(this.c);return b}; +function Vw(b){var c=b.a;if(b.match(1)){var d=c.value;if("GEOMETRYCOLLECTION"==d){a:{if(b.match(2)){c=[];do c.push(Vw(b));while(b.match(5));if(b.match(3)){b=c;break a}}else if(Xw(b)){b=[];break a}throw Error(Yw(b));}return new js(b)}var e=Zw[d],c=$w[d];if(!e||!c)throw Error("Invalid geometry type: "+d);b=e.call(b);return new c(b)}throw Error(Yw(b));}l.Ef=function(){if(this.match(2)){var b=ax(this);if(this.match(3))return b}else if(Xw(this))return null;throw Error(Yw(this));}; +l.Df=function(){if(this.match(2)){var b=bx(this);if(this.match(3))return b}else if(Xw(this))return[];throw Error(Yw(this));};l.Ff=function(){if(this.match(2)){var b=cx(this);if(this.match(3))return b}else if(Xw(this))return[];throw Error(Yw(this));};l.Sn=function(){if(this.match(2)){var b;if(2==this.a.type)for(b=[this.Ef()];this.match(5);)b.push(this.Ef());else b=bx(this);if(this.match(3))return b}else if(Xw(this))return[];throw Error(Yw(this));}; +l.Rn=function(){if(this.match(2)){var b=cx(this);if(this.match(3))return b}else if(Xw(this))return[];throw Error(Yw(this));};l.Tn=function(){if(this.match(2)){for(var b=[this.Ff()];this.match(5);)b.push(this.Ff());if(this.match(3))return b}else if(Xw(this))return[];throw Error(Yw(this));};function ax(b){for(var c=[],d=0;2>d;++d){var e=b.a;if(b.match(4))c.push(e.value);else break}if(2==c.length)return c;throw Error(Yw(b));}function bx(b){for(var c=[ax(b)];b.match(5);)c.push(ax(b));return c} +function cx(b){for(var c=[b.Df()];b.match(5);)c.push(b.Df());return c}function Xw(b){var c=1==b.a.type&&"EMPTY"==b.a.value;c&&(b.a=Uw(b.c));return c}function Yw(b){return"Unexpected `"+b.a.value+"` at position "+b.a.position+" in `"+b.c.c+"`"}var $w={POINT:D,LINESTRING:T,POLYGON:E,MULTIPOINT:$r,MULTILINESTRING:U,MULTIPOLYGON:V},Zw={POINT:Sw.prototype.Ef,LINESTRING:Sw.prototype.Df,POLYGON:Sw.prototype.Ff,MULTIPOINT:Sw.prototype.Sn,MULTILINESTRING:Sw.prototype.Rn,MULTIPOLYGON:Sw.prototype.Tn};function dx(){this.version=void 0}y(dx,Xv);dx.prototype.c=function(b){for(b=b.firstChild;b;b=b.nextSibling)if(1==b.nodeType)return this.a(b);return null};dx.prototype.a=function(b){this.version=b.getAttribute("version").trim();return(b=Q({version:this.version},ex,b,[]))?b:null};function fx(b,c){return Q({},gx,b,c)}function hx(b,c){return Q({},ix,b,c)}function jx(b,c){var d=fx(b,c);if(d){var e=[Cs(b.getAttribute("width")),Cs(b.getAttribute("height"))];d.size=e;return d}} +function kx(b,c){return Q([],lx,b,c)} +var mx=[null,"http://www.opengis.net/wms"],ex=P(mx,{Service:M(function(b,c){return Q({},nx,b,c)}),Capability:M(function(b,c){return Q({},ox,b,c)})}),ox=P(mx,{Request:M(function(b,c){return Q({},px,b,c)}),Exception:M(function(b,c){return Q([],qx,b,c)}),Layer:M(function(b,c){return Q({},rx,b,c)})}),nx=P(mx,{Name:M(W),Title:M(W),Abstract:M(W),KeywordList:M(kx),OnlineResource:M(Wv),ContactInformation:M(function(b,c){return Q({},sx,b,c)}),Fees:M(W),AccessConstraints:M(W),LayerLimit:M(Bs),MaxWidth:M(Bs), +MaxHeight:M(Bs)}),sx=P(mx,{ContactPersonPrimary:M(function(b,c){return Q({},tx,b,c)}),ContactPosition:M(W),ContactAddress:M(function(b,c){return Q({},ux,b,c)}),ContactVoiceTelephone:M(W),ContactFacsimileTelephone:M(W),ContactElectronicMailAddress:M(W)}),tx=P(mx,{ContactPerson:M(W),ContactOrganization:M(W)}),ux=P(mx,{AddressType:M(W),Address:M(W),City:M(W),StateOrProvince:M(W),PostCode:M(W),Country:M(W)}),qx=P(mx,{Format:jp(W)}),rx=P(mx,{Name:M(W),Title:M(W),Abstract:M(W),KeywordList:M(kx),CRS:lp(W), +EX_GeographicBoundingBox:M(function(b,c){var d=Q({},vx,b,c);if(d){var e=d.westBoundLongitude,f=d.southBoundLatitude,g=d.eastBoundLongitude,d=d.northBoundLatitude;return void 0===e||void 0===f||void 0===g||void 0===d?void 0:[e,f,g,d]}}),BoundingBox:lp(function(b){var c=[As(b.getAttribute("minx")),As(b.getAttribute("miny")),As(b.getAttribute("maxx")),As(b.getAttribute("maxy"))],d=[As(b.getAttribute("resx")),As(b.getAttribute("resy"))];return{crs:b.getAttribute("CRS"),extent:c,res:d}}),Dimension:lp(function(b){return{name:b.getAttribute("name"), +units:b.getAttribute("units"),unitSymbol:b.getAttribute("unitSymbol"),"default":b.getAttribute("default"),multipleValues:xs(b.getAttribute("multipleValues")),nearestValue:xs(b.getAttribute("nearestValue")),current:xs(b.getAttribute("current")),values:W(b)}}),Attribution:M(function(b,c){return Q({},wx,b,c)}),AuthorityURL:lp(function(b,c){var d=fx(b,c);if(d)return d.name=b.getAttribute("name"),d}),Identifier:lp(W),MetadataURL:lp(function(b,c){var d=fx(b,c);if(d)return d.type=b.getAttribute("type"), +d}),DataURL:lp(fx),FeatureListURL:lp(fx),Style:lp(function(b,c){return Q({},xx,b,c)}),MinScaleDenominator:M(zs),MaxScaleDenominator:M(zs),Layer:lp(function(b,c){var d=c[c.length-1],e=Q({},rx,b,c);if(e){var f=xs(b.getAttribute("queryable"));void 0===f&&(f=d.queryable);e.queryable=void 0!==f?f:!1;f=Cs(b.getAttribute("cascaded"));void 0===f&&(f=d.cascaded);e.cascaded=f;f=xs(b.getAttribute("opaque"));void 0===f&&(f=d.opaque);e.opaque=void 0!==f?f:!1;f=xs(b.getAttribute("noSubsets"));void 0===f&&(f=d.noSubsets); +e.noSubsets=void 0!==f?f:!1;(f=As(b.getAttribute("fixedWidth")))||(f=d.fixedWidth);e.fixedWidth=f;(f=As(b.getAttribute("fixedHeight")))||(f=d.fixedHeight);e.fixedHeight=f;["Style","CRS","AuthorityURL"].forEach(function(b){if(b in d){var c=Tb(e,b),c=c.concat(d[b]);e[b]=c}});"EX_GeographicBoundingBox BoundingBox Dimension Attribution MinScaleDenominator MaxScaleDenominator".split(" ").forEach(function(b){b in e||(e[b]=d[b])});return e}})}),wx=P(mx,{Title:M(W),OnlineResource:M(Wv),LogoURL:M(jx)}),vx= +P(mx,{westBoundLongitude:M(zs),eastBoundLongitude:M(zs),southBoundLatitude:M(zs),northBoundLatitude:M(zs)}),px=P(mx,{GetCapabilities:M(hx),GetMap:M(hx),GetFeatureInfo:M(hx)}),ix=P(mx,{Format:lp(W),DCPType:lp(function(b,c){return Q({},yx,b,c)})}),yx=P(mx,{HTTP:M(function(b,c){return Q({},zx,b,c)})}),zx=P(mx,{Get:M(fx),Post:M(fx)}),xx=P(mx,{Name:M(W),Title:M(W),Abstract:M(W),LegendURL:lp(jx),StyleSheetURL:M(fx),StyleURL:M(fx)}),gx=P(mx,{Format:M(W),OnlineResource:M(Wv)}),lx=P(mx,{Keyword:jp(W)});function Ax(){this.b="http://mapserver.gis.umn.edu/mapserver";this.a=new Hs;this.defaultDataProjection=null}y(Ax,ss); +Ax.prototype.hc=function(b,c){var d={featureType:this.featureType,featureNS:this.featureNS};c&&Xb(d,Rr(this,b,c));var e=[d];b.namespaceURI=this.b;var f=So(b),d=[];if(0!==b.childNodes.length){if("msGMLOutput"==f)for(var g=0,h=b.childNodes.length;g=c[0]||b[1]<=c[1]&&b[3]>=c[1]?!0:de(b,this.ng,this)):!1}; +l.Ul=function(b){var c=this.a,d=this.v[c]-this.v[0],e=b.slice();e[c]=e[0]+d;for(d=1;dg[2])&&(k*=Math.ceil((g[0]-d)/k),e=[e[0]+ +k,e[1],e[2]+k,e[3]]);d=this.u[0];g=this.u[1];k=-1;n=Math.pow(this.U*h,2);q=[];r=[];h=0;for(m=Xx.length;h=c.n&&c.cancel())}this.o?this.o.call(this.q,this):this.i=!0;this.a||(b=new Kw,Lw(this),Mw(this,!1,b))}};Jw.prototype.k=function(b,c){this.g=!1;Mw(this,b,c)};function Mw(b,c,d){b.a=!0;b.b=d;b.d=!c;Nw(b)} -function Lw(b){if(b.a){if(!b.i)throw new Ow;b.i=!1}}function Pw(b,c,d,e){b.f.push([c,d,e]);b.a&&Nw(b)}Jw.prototype.then=function(b,c,d){var e,f,g=new vw(function(b,c){e=b;f=c});Pw(this,e,function(b){b instanceof Kw?g.cancel():f(b)});return g.then(b,c,d)};mw(Jw);function Qw(b){return Ta(b.f,function(b){return ka(b[1])})} -function Nw(b){if(b.e&&b.a&&Qw(b)){var c=b.e,d=Rw[c];d&&(ba.clearTimeout(d.aa),delete Rw[c]);b.e=0}b.c&&(b.c.n--,delete b.c);for(var c=b.b,e=d=!1;b.f.length&&!b.g;){var f=b.f.shift(),g=f[0],h=f[1],f=f[2];if(g=b.d?h:g)try{var k=g.call(f||b.q,c);m(k)&&(b.d=b.d&&(k==c||k instanceof Error),b.b=c=k);nw(c)&&(e=!0,b.g=!0)}catch(n){c=n,b.d=!0,Qw(b)||(d=!0)}}b.b=c;e&&(k=ra(b.k,b,!0),e=ra(b.k,b,!1),c instanceof Jw?(Pw(c,k,e),c.p=!0):c.then(k,e));d&&(c=new Sw(c),Rw[c.aa]=c,b.e=c.aa)} -function Ow(){wa.call(this)}v(Ow,wa);Ow.prototype.message="Deferred has already fired";Ow.prototype.name="AlreadyCalledError";function Kw(){wa.call(this)}v(Kw,wa);Kw.prototype.message="Deferred was canceled";Kw.prototype.name="CanceledError";function Sw(b){this.aa=ba.setTimeout(ra(this.c,this),0);this.a=b}Sw.prototype.c=function(){delete Rw[this.aa];throw this.a;};var Rw={};function Tw(b,c){m(b.name)?(this.name=b.name,this.code=Uw[b.name]):(this.code=b.code,this.name=Vw(b.code));wa.call(this,za("%s %s",this.name,c))}v(Tw,wa);function Vw(b){var c=vb(Uw,function(c){return b==c});if(!m(c))throw Error("Invalid code: "+b);return c}var Uw={AbortError:3,EncodingError:5,InvalidModificationError:9,InvalidStateError:7,NotFoundError:1,NotReadableError:4,NoModificationAllowedError:6,PathExistsError:12,QuotaExceededError:10,SecurityError:2,SyntaxError:8,TypeMismatchError:11};function Ww(b,c){qc.call(this,b.type,c)}v(Ww,qc);function Xw(){hd.call(this);this.hb=new FileReader;this.hb.onloadstart=ra(this.a,this);this.hb.onprogress=ra(this.a,this);this.hb.onload=ra(this.a,this);this.hb.onabort=ra(this.a,this);this.hb.onerror=ra(this.a,this);this.hb.onloadend=ra(this.a,this)}v(Xw,hd);Xw.prototype.getError=function(){return this.hb.error&&new Tw(this.hb.error,"reading file")};Xw.prototype.a=function(b){this.dispatchEvent(new Ww(b,this))};Xw.prototype.P=function(){Xw.T.P.call(this);delete this.hb}; -function Yw(b){var c=new Jw;b.Ra("loadend",sa(function(b,c){var f=c.hb.result,g=c.getError();null==f||g?(Lw(b),Mw(b,!1,g)):(Lw(b),Mw(b,!0,f));c.Jc()},c,b));return c};function Zw(b){b=m(b)?b:{};Rj.call(this,{handleEvent:bd});this.e=m(b.formatConstructors)?b.formatConstructors:[];this.q=m(b.projection)?ze(b.projection):null;this.f=null;this.a=void 0}v(Zw,Rj);Zw.prototype.P=function(){m(this.a)&&Wc(this.a);Zw.T.P.call(this)};Zw.prototype.g=function(b){b=b.a.dataTransfer.files;var c,d,e;c=0;for(d=b.length;c=e*e+c*c&&(qx(this,b),null===this.i?rx(this,b):this.a===lx||this.a===ox&&null!==this.i||sx(this,b)?this.U():(b=b.coordinate,e=this.g.R(),this.a===mx?(this.i=b.slice(),c=e.Q(),c.push(b.slice()),e.W(c)):this.a===nx&&(this.e[0].push(b.slice()),e.W(this.e)),tx(this)),d=!1);return d} -function qx(b,c){if(b.a===lx&&null===b.i)rx(b,c);else if(null===b.i){var d=c.coordinate.slice();null===b.p?(b.p=new O(new Nk(d)),tx(b)):b.p.R().W(d)}else{var d=c.coordinate,e=b.g.R(),f,g;b.a===lx?(g=e.Q(),g[0]=d[0],g[1]=d[1],e.W(g)):(b.a===mx?f=e.Q():b.a===nx?f=b.e[0]:b.a===ox&&(f=e.Oc()),sx(b,c)&&(d=b.i.slice()),b.p.R().W(d),g=f[f.length-1],g[0]=d[0],g[1]=d[1],b.a===mx?e.W(f):b.a===nx?(g=b.o.R(),g.W(f),e.W(b.e)):b.a===ox&&(g=b.o.R(),g.W([e.Oc(),d]),e.Hf(g.If())));tx(b)}return!0} -function sx(b,c){var d=!1;if(null!==b.g){var e=b.g.R(),f=!1,g=[b.i];b.a===mx?f=2b.Fa,g=[b.e[0][0],b.e[0][b.e[0].length-2]]);if(f)for(var e=c.map,f=0,h=g.length;fd?h[1]:h[0]);Cx(b,k);d={};d[ma(h)]=!0;c=1;for(n=g.length;cd&&(b.index+=f)})}function Ax(){var b=Al();return function(){return b.Point}};function Fx(b,c,d){qc.call(this,b);this.selected=c;this.deselected=d}v(Fx,qc); -function Gx(b){Rj.call(this,{handleEvent:Hx});b=m(b)?b:{};this.i=m(b.condition)?b.condition:Zj;this.e=m(b.addCondition)?b.addCondition:ad;this.p=m(b.removeCondition)?b.removeCondition:ad;this.D=m(b.toggleCondition)?b.toggleCondition:bk;this.g=m(b.multi)?b.multi:!1;var c;if(m(b.layers))if(ka(b.layers))c=b.layers;else{var d=b.layers;c=function(b){return Wa(d,b)}}else c=bd;this.f=c;this.a=new yp({style:m(b.style)?b.style:Ix()});b=this.a.a;w(b,"add",this.q,!1,this);w(b,"remove",this.r,!1,this)}v(Gx,Rj); -Gx.prototype.o=function(){return this.a.a}; -function Hx(b){if(!this.i(b))return!0;var c=this.e(b),d=this.p(b),e=this.D(b),f=b.map,g=this.a.a,h=[],k=[],n=!1;if(c||d||e){f.qe(b.pixel,function(b){-1==Pa(g.a,b)?(c||e)&&k.push(b):(d||e)&&h.push(b)},void 0,this.f);for(f=h.length-1;0<=f;--f)g.remove(h[f]);g.xe(k);if(0c.d?(k=Wb(k,of(c)),c=[h,k,b[2]]):c=b):(h=b[1],c=kh(d,b[0],c),c=hc.d?null:b):c=b;e=null===c?void 0:this.tileUrlFunction(c,e,f);e=new this.tileClass(b,m(e)?0:4,m(e)?e:"",this.crossOrigin,this.tileLoadFunction); -w(e,"change",this.tk,!1,this);this.a.set(g,e);return e};l.bb=function(){return this.tileLoadFunction};l.cb=function(){return this.tileUrlFunction};l.tk=function(b){b=b.target;switch(b.state){case 1:this.dispatchEvent(new sh("tileloadstart",b));break;case 2:this.dispatchEvent(new sh("tileloadend",b));break;case 3:this.dispatchEvent(new sh("tileloaderror",b))}};l.jb=function(b){this.a.clear();this.tileLoadFunction=b;this.l()};l.ua=function(b){this.a.clear();this.tileUrlFunction=b;this.l()}; -l.Oe=function(b,c,d){b=this.nb(b,c,d);Wg(this.a,b)&&this.a.get(b)};function ey(b){var c=m(b.extent)?b.extent:Sl,d=oh(c,b.maxZoom,b.tileSize);ch.call(this,{minZoom:b.minZoom,origin:le(c,"top-left"),resolutions:d,tileSize:b.tileSize})}v(ey,ch);ey.prototype.Db=function(b){b=m(b)?b:{};var c=this.minZoom,d=this.maxZoom,e=null;if(m(b.extent)){var e=Array(d+1),f;for(f=0;f<=d;++f)e[f]=f=this.minZoom;--b)if(e.a=e.d>>=1,e.b=e.c>>=1,c.call(d,b,e))return!0;return!1};function fy(b){cy.call(this,{crossOrigin:"anonymous",opaque:!0,projection:ze("EPSG:3857"),state:"loading",tileLoadFunction:b.tileLoadFunction,wrapX:m(b.wrapX)?b.wrapX:!0});this.d=m(b.culture)?b.culture:"en-us";this.b=m(b.maxZoom)?b.maxZoom:-1;var c=new Wr((Sb?"https:":"http:")+"//dev.virtualearth.net/REST/v1/Imagery/Metadata/"+b.imagerySet);(new Sx(c,"jsonp")).send({include:"ImageryProviders",uriScheme:Sb?"https":"http",key:b.key},ra(this.g,this))}v(fy,cy);var gy=new qf({html:'Terms of Use'}); -fy.prototype.g=function(b){if(200!=b.statusCode||"OK"!=b.statusDescription||"ValidCredentials"!=b.authenticationResultCode||1!=b.resourceSets.length||1!=b.resourceSets[0].resources.length)bh(this,"error");else{var c=b.brandLogoUri;Sb&&-1==c.indexOf("https")&&(c=c.replace("http","https"));var d=b.resourceSets[0].resources[0],e=-1==this.b?d.zoomMax:this.b,f=new ey({extent:lh(this.e),minZoom:d.zoomMin,maxZoom:e,tileSize:d.imageWidth});this.tileGrid=f;var g=this.d;this.tileUrlFunction=ay(f.Db(),Zx(Sa(d.imageUrlSubdomains, -function(b){var c=d.imageUrl.replace("{subdomain}",b).replace("{culture}",g);return function(b){return null===b?void 0:c.replace("{quadkey}",hf(b))}})));if(d.imageryProviders){var h=De(ze("EPSG:4326"),this.e);b=Sa(d.imageryProviders,function(b){var c=b.attribution,d={};Qa(b.coverageAreas,function(b){var c=b.zoomMin,g=Math.min(b.zoomMax,e);b=b.bbox;b=te([b[1],b[0],b[3],b[2]],h);var k,n;for(k=c;k<=g;++k)n=k.toString(),c=fh(f,b,k),n in d?d[n].push(c):d[n]=[c]});return new qf({html:c,tileRanges:d})}); -b.push(gy);this.f=b}this.D=c;bh(this,"ready")}};function hy(b){vn.call(this,{attributions:b.attributions,extent:b.extent,logo:b.logo,projection:b.projection});this.p=void 0;this.r=m(b.distance)?b.distance:20;this.o=[];this.a=b.source;this.a.s("change",hy.prototype.N,this)}v(hy,vn);hy.prototype.H=function(){return this.a};hy.prototype.Hb=function(b,c,d){c!==this.p&&(this.clear(),this.p=c,this.a.Hb(b,c,d),iy(this),this.Ga(this.o))};hy.prototype.N=function(){this.clear();iy(this);this.Ga(this.o);this.l()}; -function iy(b){if(m(b.p)){b.o.length=0;for(var c=Sd(),d=b.r*b.p,e=b.a.Aa(),f={},g=0,h=e.length;gk*h?g*f/(k*p):h*f/(n*p);d=ke(d);e={OPERATION:this.U?"GETDYNAMICMAPOVERLAYIMAGE":"GETMAPIMAGE",VERSION:"2.0.0",LOCALE:"en",CLIENTAGENT:"ol.source.ImageMapGuide source",CLIP:"1",SETDISPLAYDPI:this.g,SETDISPLAYWIDTH:Math.round(e[0]),SETDISPLAYHEIGHT:Math.round(e[1]),SETVIEWSCALE:f,SETVIEWCENTERX:d[0],SETVIEWCENTERY:d[1]};Db(e,c);return Tr(Vr([b],e))};l.ak=function(b){this.b=null;this.a=b;this.l()};function My(b){var c=m(b.attributions)?b.attributions:null,d=b.imageExtent,e,f;m(b.imageSize)&&(e=ne(d)/b.imageSize[1],f=[e]);var g=m(b.crossOrigin)?b.crossOrigin:null,h=m(b.imageLoadFunction)?b.imageLoadFunction:nn;gn.call(this,{attributions:c,logo:b.logo,projection:ze(b.projection),resolutions:f});this.a=new gw(d,e,1,c,b.url,g,h)}v(My,gn);My.prototype.sc=function(b){return pe(b,this.a.J())?this.a:null};function Ny(b){b=m(b)?b:{};gn.call(this,{attributions:b.attributions,logo:b.logo,projection:b.projection,resolutions:b.resolutions});this.S=m(b.crossOrigin)?b.crossOrigin:null;this.d=b.url;this.k=m(b.imageLoadFunction)?b.imageLoadFunction:nn;this.b=b.params;this.g=!0;Oy(this);this.N=b.serverType;this.U=m(b.hidpi)?b.hidpi:!0;this.a=null;this.o=[0,0];this.H=0;this.p=m(b.ratio)?b.ratio:1.5}v(Ny,gn);var Py=[101,101];l=Ny.prototype; -l.hk=function(b,c,d,e){if(m(this.d)){var f=me(b,c,0,Py),g={SERVICE:"WMS",VERSION:"1.3.0",REQUEST:"GetFeatureInfo",FORMAT:"image/png",TRANSPARENT:!0,QUERY_LAYERS:this.b.LAYERS};Db(g,this.b,e);e=Math.floor((f[3]-b[1])/c);g[this.g?"I":"X"]=Math.floor((b[0]-f[0])/c);g[this.g?"J":"Y"]=e;return Qy(this,f,Py,1,ze(d),g)}};l.jk=function(){return this.b}; -l.sc=function(b,c,d,e){if(!m(this.d))return null;c=hn(this,c);1==d||this.U&&m(this.N)||(d=1);var f=this.a;if(null!==f&&this.H==this.c&&f.resolution==c&&f.f==d&&Zd(f.J(),b))return f;f={SERVICE:"WMS",VERSION:"1.3.0",REQUEST:"GetMap",FORMAT:"image/png",TRANSPARENT:!0};Db(f,this.b);b=b.slice();var g=(b[0]+b[2])/2,h=(b[1]+b[3])/2;if(1!=this.p){var k=this.p*qe(b)/2,n=this.p*ne(b)/2;b[0]=g-k;b[1]=h-n;b[2]=g+k;b[3]=h+n}var k=c/d,n=Math.ceil(qe(b)/k),p=Math.ceil(ne(b)/k);b[0]=g-k*n/2;b[2]=g+k*n/2;b[1]=h-k* -p/2;b[3]=h+k*p/2;this.o[0]=n;this.o[1]=p;e=Qy(this,b,this.o,d,e,f);this.a=new gw(b,c,d,this.f,e,this.S,this.k);this.H=this.c;w(this.a,"change",this.r,!1,this);return this.a};l.ik=function(){return this.k}; -function Qy(b,c,d,e,f,g){g[b.g?"CRS":"SRS"]=f.a;"STYLES"in b.b||(g.STYLES=new String(""));if(1!=e)switch(b.N){case "geoserver":g.FORMAT_OPTIONS="dpi:"+(90*e+.5|0);break;case "mapserver":g.MAP_RESOLUTION=90*e;break;case "carmentaserver":case "qgis":g.DPI=90*e}g.WIDTH=d[0];g.HEIGHT=d[1];d=f.b;var h;b.g&&"ne"==d.substr(0,2)?h=[c[1],c[0],c[3],c[2]]:h=c;g.BBOX=h.join(",");return Tr(Vr([b.d],g))}l.kk=function(){return this.d};l.lk=function(b){this.a=null;this.k=b;this.l()}; -l.mk=function(b){b!=this.d&&(this.d=b,this.a=null,this.l())};l.nk=function(b){Db(this.b,b);Oy(this);this.a=null;this.l()};function Oy(b){b.g=0<=La(zb(b.b,"VERSION","1.3.0"),"1.3")};function Ry(b){b=m(b)?b:{};$.call(this,{attributions:b.attributions,doc:b.doc,format:new qs({extractStyles:b.extractStyles,defaultStyle:b.defaultStyle}),logo:b.logo,node:b.node,projection:b.projection,text:b.text,url:b.url,urls:b.urls})}v(Ry,$);function Sy(b){var c=m(b.projection)?b.projection:"EPSG:3857",d=new ey({extent:lh(c),maxZoom:b.maxZoom,tileSize:b.tileSize});cy.call(this,{attributions:b.attributions,crossOrigin:b.crossOrigin,logo:b.logo,projection:c,tileGrid:d,tileLoadFunction:b.tileLoadFunction,tilePixelRatio:b.tilePixelRatio,tileUrlFunction:$x,wrapX:m(b.wrapX)?b.wrapX:!0});this.i=d.Db();m(b.tileUrlFunction)?this.ua(b.tileUrlFunction):m(b.urls)?this.ua(Yx(b.urls)):m(b.url)&&this.b(b.url)}v(Sy,cy); -Sy.prototype.ua=function(b){Sy.T.ua.call(this,ay(this.i,b))};Sy.prototype.b=function(b){this.ua(Yx(by(b)))};function Ty(b){b=m(b)?b:{};var c;m(b.attributions)?c=b.attributions:c=[Uy];var d=Sb?"https:":"http:";Sy.call(this,{attributions:c,crossOrigin:m(b.crossOrigin)?b.crossOrigin:"anonymous",opaque:!0,maxZoom:m(b.maxZoom)?b.maxZoom:19,tileLoadFunction:b.tileLoadFunction,url:m(b.url)?b.url:d+"//{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png",wrapX:b.wrapX})}v(Ty,Sy);var Uy=new qf({html:'© OpenStreetMap contributors.'});function Vy(b){b=m(b)?b:{};var c=Wy[b.layer];this.d=b.layer;var d=Sb?"https:":"http:";Sy.call(this,{attributions:c.attributions,crossOrigin:"anonymous",logo:"//developer.mapquest.com/content/osm/mq_logo.png",maxZoom:c.maxZoom,opaque:!0,tileLoadFunction:b.tileLoadFunction,url:m(b.url)?b.url:d+"//otile{1-4}-s.mqcdn.com/tiles/1.0.0/"+this.d+"/{z}/{x}/{y}.jpg"})}v(Vy,Sy); -var Xy=new qf({html:'Tiles Courtesy of MapQuest'}),Wy={osm:{maxZoom:19,attributions:[Xy,Uy]},sat:{maxZoom:18,attributions:[Xy,new qf({html:"Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency"})]},hyb:{maxZoom:18,attributions:[Xy,Uy]}};Vy.prototype.g=function(){return this.d};function Yy(b){b=m(b)?b:{};$.call(this,{attributions:b.attributions,doc:b.doc,format:new $t,logo:b.logo,node:b.node,projection:b.projection,text:b.text,url:b.url,urls:b.urls})}v(Yy,$);function Zy(b){Z.call(this,{attributions:b.attributions,format:b.format,logo:b.logo,projection:b.projection});this.p=new qn;this.r=b.loader;this.H=m(b.strategy)?b.strategy:Kx;this.o={}}v(Zy,Z);Zy.prototype.lb=function(b){var c=[],d,e;d=0;for(e=b.length;dStamen Design, under CC BY 3.0.'}),Uy];function dz(b){b=m(b)?b:{};var c=m(b.params)?b.params:{};cy.call(this,{attributions:b.attributions,logo:b.logo,projection:b.projection,tileGrid:b.tileGrid,tileLoadFunction:b.tileLoadFunction,tileUrlFunction:ra(this.rk,this),wrapX:m(b.wrapX)?b.wrapX:!0});var d=b.urls;!m(d)&&m(b.url)&&(d=by(b.url));this.d=null!=d?d:[];this.b=c;this.g=Sd()}v(dz,cy);l=dz.prototype;l.ok=function(){return this.b};l.Xb=function(b,c,d){b=dz.T.Xb.call(this,b,c,d);return 1==c?b:b*c+.5|0};l.pk=function(){return this.d}; -l.qk=function(b){b=m(b)?by(b):null;this.Of(b)};l.Of=function(b){this.d=null!=b?b:[];this.l()}; -l.rk=function(b,c,d){var e=this.tileGrid;null===e&&(e=rh(this,d));if(!(e.a.length<=b[0])){var f=eh(e,b,this.g),g=e.pa(b[0]);1!=c&&(g=g*c+.5|0);e={F:"image",FORMAT:"PNG32",TRANSPARENT:!0};Db(e,this.b);var h=this.d;0==h.length?b=void 0:(d=d.a.split(":").pop(),e.SIZE=g+","+g,e.BBOX=f.join(","),e.BBOXSR=d,e.IMAGESR=d,e.DPI=90*c,b=1==h.length?h[0]:h[Wb((b[1]<p||n<=p)return null;b=b[2];return b<-n||-1g||e>g;)f.push([Math.ceil(d/g),Math.ceil(e/g)]),g+=g;break;case "truncated":for(;d>g||e>g;)f.push([Math.ceil(d/g),Math.ceil(e/g)]),d>>=1,e>>=1}f.push([1,1]);f.reverse();for(var g=[1],h=[0],e=1,d=f.length;ethis.b||d+this.a>this.b)return null;e=Cz(this,!1,b,c,d,e,g);if(null===e)return null;b=Cz(this,!0,b,c,d,m(f)?f:cd,g);return{offsetX:e.offsetX,offsetY:e.offsetY,image:e.image,wf:b.image}}; -function Cz(b,c,d,e,f,g,h){var k=c?b.e:b.f,n,p,q;p=0;for(q=k.length;p=c+this.a&&g.height>=d+this.a)return k={offsetX:g.x+this.a,offsetY:g.y+this.a,image:this.b},this.d[b]=k,e.call(f,this.f,g.x+this.a,g.y+this.a),b=h,c=c+this.a,d=d+this.a,f=e=void 0,g.width-c>g.height-d?(e={x:g.x+c,y:g.y,width:g.width-c,height:g.height},f={x:g.x,y:g.y+d,width:c,height:g.height-d},Dz(this,b,e,f)):(e={x:g.x+c,y:g.y,width:g.width-c,height:d},f={x:g.x,y:g.y+d,width:g.width,height:g.height- -d},Dz(this,b,e,f)),k;return null};function Dz(b,c,d,e){c=[c,1];0e&&(e=0);f=d.TileMatrixSetLink[e].TileMatrixSet;e=d.WGS84BoundingBox;m(e)&&(g=ze("EPSG:4326").J(),g=e[0]== -g[0]&&e[2]==g[2]);var h=d.Format[0];m(c.format)&&(h=c.format);e=Va(d.Style,function(b){return m(c.style)?b.Title==c.style:b.isDefault});0>e&&(e=0);e=d.Style[e].Identifier;var k={};m(d.Dimension)&&Qa(d.Dimension,function(b){var c=b.Identifier,d=b["default"];m(d)||(d=b.values[0]);k[c]=d});var n=Ua(b.Contents.TileMatrixSet,function(b){return b.Identifier==f}),p=uz(n),n=m(c.projection)?ze(c.projection):ze(n.SupportedCRS.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/,"$1:$3")),q=[],r=c.requestEncoding,r= -m(r)?r:"";if(b.OperationsMetadata.hasOwnProperty("GetTile")&&0!=r.lastIndexOf("REST",0)){var d=b.OperationsMetadata.GetTile.DCP.HTTP.Get,s=Ua(d[0].Constraint,function(b){return"GetEncoding"==b.name}).AllowedValues.Value;0=c.l&&c.cancel())}this.C?this.C.call(this.A,this):this.B=!0;this.a||(b=new gy,hy(this),iy(this,!1,b))}};fy.prototype.u=function(b,c){this.i=!1;iy(this,b,c)};function iy(b,c,d){b.a=!0;b.b=d;b.f=!c;jy(b)} +function hy(b){if(b.a){if(!b.B)throw new ky;b.B=!1}}fy.prototype.$c=function(b){hy(this);iy(this,!0,b)};function ly(b,c,d,e){b.g.push([c,d,e]);b.a&&jy(b)}fy.prototype.then=function(b,c,d){var e,f,g=new Hn(function(b,c){e=b;f=c});ly(this,e,function(b){b instanceof gy?g.cancel():f(b)});return g.then(b,c,d)};un(fy);function my(b){return eb(b.g,function(b){return ka(b[1])})} +function jy(b){if(b.j&&b.a&&my(b)){var c=b.j,d=ny[c];d&&(ba.clearTimeout(d.wa),delete ny[c]);b.j=0}b.c&&(b.c.l--,delete b.c);for(var c=b.b,e=d=!1;b.g.length&&!b.i;){var f=b.g.shift(),g=f[0],h=f[1],f=f[2];if(g=b.f?h:g)try{var k=g.call(f||b.A,c);ca(k)&&(b.f=b.f&&(k==c||k instanceof Error),b.b=c=k);if(vn(c)||"function"===typeof ba.Promise&&c instanceof ba.Promise)e=!0,b.i=!0}catch(m){c=m,b.f=!0,my(b)||(d=!0)}}b.b=c;e&&(k=ra(b.u,b,!0),e=ra(b.u,b,!1),c instanceof fy?(ly(c,k,e),c.D=!0):c.then(k,e));d&& +(c=new oy(c),ny[c.wa]=c,b.j=c.wa)}function ky(){xa.call(this)}y(ky,xa);ky.prototype.message="Deferred has already fired";ky.prototype.name="AlreadyCalledError";function gy(){xa.call(this)}y(gy,xa);gy.prototype.message="Deferred was canceled";gy.prototype.name="CanceledError";function oy(b){this.wa=ba.setTimeout(ra(this.c,this),0);this.a=b}oy.prototype.c=function(){delete ny[this.wa];throw this.a;};var ny={};function py(b,c){ca(b.name)?(this.name=b.name,this.code=qy[b.name]):(this.code=b.code,this.name=ry(b.code));xa.call(this,Ba("%s %s",this.name,c))}y(py,xa);function ry(b){var c=Pb(qy,function(c){return b==c});if(!ca(c))throw Error("Invalid code: "+b);return c}var qy={AbortError:3,EncodingError:5,InvalidModificationError:9,InvalidStateError:7,NotFoundError:1,NotReadableError:4,NoModificationAllowedError:6,PathExistsError:12,QuotaExceededError:10,SecurityError:2,SyntaxError:8,TypeMismatchError:11};function sy(b,c){vc.call(this,b.type,c)}y(sy,vc);function ty(){cd.call(this);this.ub=new FileReader;this.ub.onloadstart=ra(this.a,this);this.ub.onprogress=ra(this.a,this);this.ub.onload=ra(this.a,this);this.ub.onabort=ra(this.a,this);this.ub.onerror=ra(this.a,this);this.ub.onloadend=ra(this.a,this)}y(ty,cd);ty.prototype.getError=function(){return this.ub.error&&new py(this.ub.error,"reading file")};ty.prototype.a=function(b){this.o(new sy(b,this))};ty.prototype.X=function(){ty.da.X.call(this);delete this.ub}; +function uy(b){var c=new fy;b.Qa("loadend",sa(function(b,c){var f=c.ub.result,g=c.getError();null==f||g?(hy(b),iy(b,!1,g)):b.$c(f);c.Ec()},c,b));return c};function vy(b){b=b?b:{};Ok.call(this,{handleEvent:ue});this.j=b.formatConstructors?b.formatConstructors:[];this.A=b.projection?Fe(b.projection):null;this.f=null;this.a=void 0}y(vy,Ok);vy.prototype.X=function(){this.a&&Zc(this.a);vy.da.X.call(this)};vy.prototype.i=function(b){b=b.a.dataTransfer.files;var c,d,e;c=0;for(d=b.length;cb.xa:b.f===Jy&&(e=b.a[0].length>b.xa,f=[b.a[0][0],b.a[0][b.a[0].length-2]]);if(e)for(var e=c.map,g=0,h=f.length;gb.pa,b.D(g,e);else if(b.f===Jy){g=b.a[0];g.push(d.slice());if(f=g.length>b.pa)b.l=g[0];b.D(b.a,e)}Sy(b);f&&b.md()}l.Ao=function(){var b=this.i.W(),c,d;this.f===Ly?(c=this.a,c.splice(-2,1),this.D(c,b)):this.f===Jy&&(c=this.a[0],c.splice(-2,1),d=this.A.W(),d.ma(c),this.D(this.a,b));0===c.length&&(this.l=null);Sy(this)}; +l.md=function(){var b=Ty(this),c=this.a,d=b.W();this.f===Ly?(c.pop(),this.D(c,d)):this.f===Jy&&(c[0].pop(),c[0].push(c[0][0]),this.D(c,d));"MultiPoint"===this.T?b.La(new $r([c])):"MultiLineString"===this.T?b.La(new U([c])):"MultiPolygon"===this.T&&b.La(new V([c]));this.o(new Dy("drawend",b));this.fb&&this.fb.push(b);this.Db&&this.Db.Ad(b)};function Ty(b){b.l=null;var c=b.i;c&&(b.i=null,b.G=null,b.A=null,b.ga.fa().clear(!0));return c} +l.bm=function(b){var c=b.W();this.i=b;this.a=c.Y();b=this.a[this.a.length-1];this.l=b.slice();this.a.push(b.slice());Sy(this);this.o(new Dy("drawstart",this.i))};l.xc=te;function Sy(b){var c=[];b.i&&c.push(b.i);b.A&&c.push(b.A);b.G&&c.push(b.G);b=b.ga.fa();b.clear(!0);b.Dc(c)}l.ki=function(){var b=this.u,c=this.b();b&&c||Ty(this);this.ga.setMap(c?b:null)}; +function Iy(b){var c;"Point"===b||"MultiPoint"===b?c=Ky:"LineString"===b||"MultiLineString"===b?c=Ly:"Polygon"===b||"MultiPolygon"===b?c=Jy:"Circle"===b&&(c=Qy);return c}var Ky="Point",Ly="LineString",Jy="Polygon",Qy="Circle";function Uy(b,c,d){vc.call(this,b);this.features=c;this.mapBrowserPointerEvent=d}y(Uy,vc); +function Vy(b){al.call(this,{handleDownEvent:Wy,handleDragEvent:Xy,handleEvent:Yy,handleUpEvent:Zy});this.pa=b.deleteCondition?b.deleteCondition:ze(Xk,Wk);this.va=this.f=null;this.ea=[0,0];this.D=this.U=!1;this.a=new Bp;this.G=void 0!==b.pixelTolerance?b.pixelTolerance:10;this.l=this.ga=!1;this.i=null;this.S=new H({source:new R({useSpatialIndex:!1,wrapX:!!b.wrapX}),style:b.style?b.style:$y(),updateWhileAnimating:!0,updateWhileInteracting:!0});this.T={Point:this.im,LineString:this.bh,LinearRing:this.bh, +Polygon:this.jm,MultiPoint:this.gm,MultiLineString:this.fm,MultiPolygon:this.hm,GeometryCollection:this.em};this.A=b.features;this.A.forEach(this.zf,this);C(this.A,"add",this.cm,!1,this);C(this.A,"remove",this.dm,!1,this)}y(Vy,al);l=Vy.prototype;l.zf=function(b){var c=b.W();c.V()in this.T&&this.T[c.V()].call(this,b,c);(c=this.u)&&az(this,this.ea,c);C(b,"change",this.ah,!1,this)};function bz(b,c){b.D||(b.D=!0,b.o(new Uy("modifystart",b.A,c)))} +function cz(b,c){dz(b,c);b.f&&0===b.A.$b()&&(b.S.fa().Qc(b.f),b.f=null);Yc(c,"change",b.ah,!1,b)}function dz(b,c){var d=b.a,e=[];d.forEach(function(b){c===b.feature&&e.push(b)});for(var f=e.length-1;0<=f;--f)d.remove(e[f])}l.setMap=function(b){this.S.setMap(b);Vy.da.setMap.call(this,b)};l.cm=function(b){this.zf(b.element)};l.ah=function(b){this.l||(b=b.target,cz(this,b),this.zf(b))};l.dm=function(b){cz(this,b.element)}; +l.im=function(b,c){var d=c.Y(),d={feature:b,geometry:c,la:[d,d]};this.a.ya(c.J(),d)};l.gm=function(b,c){var d=c.Y(),e,f,g;f=0;for(g=d.length;fd?h[1]:h[0]);ez(b,k);d={};d[w(h)]=!0;c=1;for(m=g.length;cd&&(b.index+=f)})}function $y(){var b=hm();return function(){return b.Point}};function hz(b,c,d,e){vc.call(this,b);this.selected=c;this.deselected=d;this.mapBrowserEvent=e}y(hz,vc); +function iz(b){Ok.call(this,{handleEvent:jz});b=b?b:{};this.C=b.condition?b.condition:Wk;this.l=b.addCondition?b.addCondition:te;this.D=b.removeCondition?b.removeCondition:te;this.G=b.toggleCondition?b.toggleCondition:Yk;this.A=b.multi?b.multi:!1;this.j=b.filter?b.filter:ue;var c;if(b.layers)if(ka(b.layers))c=b.layers;else{var d=b.layers;c=function(b){return vb(d,b)}}else c=ue;this.i=c;this.a={};this.f=new H({source:new R({useSpatialIndex:!1,features:b.features,wrapX:b.wrapX}),style:b.style?b.style: +kz(),updateWhileAnimating:!0,updateWhileInteracting:!0});b=this.f.fa().b;C(b,"add",this.km,!1,this);C(b,"remove",this.nm,!1,this)}y(iz,Ok);l=iz.prototype;l.lm=function(){return this.f.fa().b};l.mm=function(b){b=w(b);return this.a[b]}; +function jz(b){if(!this.C(b))return!0;var c=this.l(b),d=this.D(b),e=this.G(b),f=!c&&!d&&!e,g=b.map,h=this.f.fa().b,k=[],m=[],n=!1;if(f)g.od(b.pixel,function(b,c){if(!c||this.j(b,c)){m.push(b);var d=w(b);this.a[d]=c;return!this.A}},this,this.i),0f?h[1]:h[0],d=c.Oa(m),d=[Math.round(d[0]),Math.round(d[1])]);c=m;g&&(b.coordinate=c.slice(0,2),b.pixel=d);return bl.call(this,b)} +function nz(){var b=Lb(this.A);b.length&&(b.forEach(this.ji,this),this.A={});return!1}function oz(b,c){return yd(this.S,b.la)-yd(this.S,c.la)};function pz(b,c,d){vc.call(this,b);this.features=c;this.coordinate=d}y(pz,vc);function qz(b){al.call(this,{handleDownEvent:rz,handleDragEvent:sz,handleMoveEvent:tz,handleUpEvent:uz});this.l=void 0;this.a=null;this.f=void 0!==b.features?b.features:null;this.i=null}y(qz,al);function rz(b){this.i=vz(this,b.pixel,b.map);return!this.a&&this.i?(this.a=b.coordinate,tz.call(this,b),this.o(new pz("translatestart",this.f,b.coordinate)),!0):!1} +function uz(b){return this.a?(this.a=null,tz.call(this,b),this.o(new pz("translateend",this.f,b.coordinate)),!0):!1}function sz(b){if(this.a){b=b.coordinate;var c=b[0]-this.a[0],d=b[1]-this.a[1];if(this.f)this.f.forEach(function(b){var e=b.W();e.Oc(c,d);b.La(e)});else if(this.i){var e=this.i.W();e.Oc(c,d);this.i.La(e)}this.a=b;this.o(new pz("translating",this.f,b))}} +function tz(b){var c=b.map.Lc();if(b=b.map.od(b.pixel,function(b){return b})){var d=!1;this.f&&vb(this.f.a,b)&&(d=!0);this.l=c.style.cursor;c.style.cursor=this.a?"-webkit-grabbing":d?"-webkit-grab":"pointer";c.style.cursor=this.a?d?"grab":"pointer":"grabbing"}else c.style.cursor=void 0!==this.l?this.l:"",this.l=void 0}function vz(b,c,d){var e=null;c=d.od(c,function(b){return b});b.f&&vb(b.f.a,c)&&(e=c);return e};function X(b){b=b?b:{};var c=Ub(b);delete c.gradient;delete c.radius;delete c.blur;delete c.shadow;delete c.weight;H.call(this,c);this.g=null;this.Z=void 0!==b.shadow?b.shadow:250;this.T=void 0;this.U=null;C(this,kd("gradient"),this.zk,!1,this);this.Wh(b.gradient?b.gradient:wz);this.Sh(void 0!==b.blur?b.blur:15);this.ih(void 0!==b.radius?b.radius:8);C(this,[kd("blur"),kd("radius")],this.Lg,!1,this);this.Lg();var d=b.weight?b.weight:"weight",e;ia(d)?e=function(b){return b.get(d)}:e=d;this.f(ra(function(b){b= +e(b);b=void 0!==b?Sa(b,0,1):1;var c=255*b|0,d=this.U[c];d||(d=[new cm({image:new wk({opacity:b,src:this.T})})],this.U[c]=d);return d},this));this.set("renderOrder",null);C(this,"render",this.Rk,!1,this)}y(X,H);var wz=["#00f","#0ff","#0f0","#ff0","#f00"];l=X.prototype;l.tg=function(){return this.get("blur")};l.Ag=function(){return this.get("gradient")};l.hh=function(){return this.get("radius")}; +l.zk=function(){for(var b=this.Ag(),c=Pi(1,256),d=c.createLinearGradient(0,0,1,256),e=1/(b.length-1),f=0,g=b.length;f=e)this.state=4;else if(this.u=new en(b,d,h,g,e*(void 0!==n?n:.5)),0===this.u.f.length)this.state=4;else if(this.l=Kh(c,e),d=gn(this.u),g&&(b.b?(d[1]=Sa(d[1],g[1],g[3]), +d[3]=Sa(d[3],g[1],g[3])):d=oe(d,g)),ie(d))if(b=Fh(c,d,this.l),100>kg(b)*jg(b)){for(c=b.a;c<=b.f;c++)for(d=b.c;d<=b.b;d++)(n=m(this.l,c,d,k))&&this.c.push(n);0===this.c.length&&(this.state=4)}else this.state=3;else this.state=4}y(xz,wh);xz.prototype.X=function(){1==this.state&&(this.b.forEach(Zc),this.b=null);xz.da.X.call(this)};xz.prototype.Sa=function(b){if(void 0!==b){var c=w(b);if(c in this.g)return this.g[c];b=Qb(this.g)?this.j:this.j.cloneNode(!1);return this.g[c]=b}return this.j}; +function yz(b){var c=[];b.c.forEach(function(b){b&&2==b.state&&c.push({extent:this.i.Aa(b.a),image:b.Sa()})},b);b.c.length=0;var d=b.a,e=d[0],f=b.B.Ha(e),g=ja(f)?f:f[0],f=ja(f)?f:f[1],e=b.B.$(e),h=b.i.$(b.l),d=b.B.Aa(d);b.j=dn(g,f,b.A,h,b.i.J(),e,d,b.u,c,b.C);b.state=2;xh(b)} +xz.prototype.load=function(){if(0==this.state){this.state=1;xh(this);var b=0;this.b=[];this.c.forEach(function(c){var d=c.state;if(0==d||1==d){b++;var e;e=c.Qa("change",function(){var d=c.state;if(2==d||3==d||4==d)Zc(e),b--,0===b&&(this.b.forEach(Zc),this.b=null,yz(this))},!1,this);this.b.push(e)}},this);this.c.forEach(function(b){0==b.state&&b.load()});0===b&&yz(this)}};function zz(b,c){var d=c||{},e=d.document||document,f=Kg("SCRIPT"),g={Rh:f,yc:void 0},h=new fy(Az,g),k=null,m=null!=d.timeout?d.timeout:5E3;0Terms of Use'}); +Oz.prototype.D=function(b){if(200!=b.statusCode||"OK"!=b.statusDescription||"ValidCredentials"!=b.authenticationResultCode||1!=b.resourceSets.length||1!=b.resourceSets[0].resources.length)Ah(this,"error");else{var c=b.brandLogoUri;-1==c.indexOf("https")&&(c=c.replace("http","https"));var d=b.resourceSets[0].resources[0],e=-1==this.g?d.zoomMax:this.g;b=Mh(this.f);var f=Oh({extent:b,minZoom:d.zoomMin,maxZoom:e,tileSize:d.imageWidth==d.imageHeight?d.imageWidth:[d.imageWidth,d.imageHeight]});this.tileGrid= +f;var g=this.l;this.tileUrlFunction=Wp(d.imageUrlSubdomains.map(function(b){var c=[0,0,0],e=d.imageUrl.replace("{subdomain}",b).replace("{culture}",g);return function(b){if(b)return cg(b[0],b[1],-b[2]-1,c),e.replace("{quadkey}",eg(c))}}));if(d.imageryProviders){var h=Je(Fe("EPSG:4326"),this.f);b=d.imageryProviders.map(function(b){var c=b.attribution,d={};b.coverageAreas.forEach(function(b){var c=b.zoomMin,g=Math.min(b.zoomMax,e);b=b.bbox;b=re([b[1],b[0],b[3],b[2]],h);var k,m;for(k=c;k<=g;++k)m=k.toString(), +c=Fh(f,b,k),m in d?d[m].push(c):d[m]=[c]});return new mg({html:c,tileRanges:d})});b.push(Pz);this.na(b)}this.U=c;Ah(this,"ready")}};function Qz(b){R.call(this,{attributions:b.attributions,extent:b.extent,logo:b.logo,projection:b.projection,wrapX:b.wrapX});this.G=void 0;this.ea=void 0!==b.distance?b.distance:20;this.D=[];this.C=b.source;this.C.H("change",Qz.prototype.va,this)}y(Qz,R);Qz.prototype.ga=function(){return this.C};Qz.prototype.Mc=function(b,c,d){this.C.Mc(b,c,d);c!==this.G&&(this.clear(),this.G=c,Rz(this),this.Dc(this.D))};Qz.prototype.va=function(){this.clear();Rz(this);this.Dc(this.D);this.s()}; +function Rz(b){if(void 0!==b.G){b.D.length=0;for(var c=Od(),d=b.ea*b.G,e=b.C.ye(),f={},g=0,h=e.length;gk*d?h*g/(k*n):d*g/(m*n),SETVIEWCENTERX:f[0],SETVIEWCENTERY:f[1]};Xb(e,c);return lo(no([b],e))};l.Gm=function(b){this.g=null;this.b=b;this.s()};function Uz(b){var c=void 0!==b.attributions?b.attributions:null,d=b.imageExtent,e,f;void 0!==b.imageSize&&(e=le(d)/b.imageSize[1],f=[e]);var g=void 0!==b.crossOrigin?b.crossOrigin:null,h=void 0!==b.imageLoadFunction?b.imageLoadFunction:qn;kn.call(this,{attributions:c,logo:b.logo,projection:Fe(b.projection),resolutions:f});this.b=new $x(d,e,1,c,b.url,g,h);C(this.b,"change",this.D,!1,this)}y(Uz,kn);Uz.prototype.pd=function(b){return pe(b,this.b.J())?this.b:null};function Vz(b){b=b||{};kn.call(this,{attributions:b.attributions,logo:b.logo,projection:b.projection,resolutions:b.resolutions});this.pa=void 0!==b.crossOrigin?b.crossOrigin:null;this.i=b.url;this.T=void 0!==b.imageLoadFunction?b.imageLoadFunction:qn;this.g=b.params;this.u=!0;Wz(this);this.ga=b.serverType;this.xa=void 0!==b.hidpi?b.hidpi:!0;this.b=null;this.Z=[0,0];this.ea=0;this.l=void 0!==b.ratio?b.ratio:1.5}y(Vz,kn);var Xz=[101,101];l=Vz.prototype; +l.Nm=function(b,c,d,e){if(void 0!==this.i){var f=ne(b,c,0,Xz),g={SERVICE:"WMS",VERSION:"1.3.0",REQUEST:"GetFeatureInfo",FORMAT:"image/png",TRANSPARENT:!0,QUERY_LAYERS:this.g.LAYERS};Xb(g,this.g,e);e=Math.floor((f[3]-b[1])/c);g[this.u?"I":"X"]=Math.floor((b[0]-f[0])/c);g[this.u?"J":"Y"]=e;return Yz(this,f,Xz,1,Fe(d),g)}};l.Pm=function(){return this.g}; +l.pd=function(b,c,d,e){if(void 0===this.i)return null;c=ln(this,c);1==d||this.xa&&void 0!==this.ga||(d=1);b=b.slice();var f=(b[0]+b[2])/2,g=(b[1]+b[3])/2,h=c/d,k=ke(b)/h,h=le(b)/h,m=this.b;if(m&&this.ea==this.c&&m.$()==c&&m.b==d&&Xd(m.J(),b))return m;if(1!=this.l){var m=this.l*ke(b)/2,n=this.l*le(b)/2;b[0]=f-m;b[1]=g-n;b[2]=f+m;b[3]=g+n}f={SERVICE:"WMS",VERSION:"1.3.0",REQUEST:"GetMap",FORMAT:"image/png",TRANSPARENT:!0};Xb(f,this.g);this.Z[0]=Math.ceil(k*this.l);this.Z[1]=Math.ceil(h*this.l);e=Yz(this, +b,this.Z,d,e,f);this.b=new $x(b,c,d,this.j,e,this.pa,this.T);this.ea=this.c;C(this.b,"change",this.D,!1,this);return this.b};l.Om=function(){return this.T}; +function Yz(b,c,d,e,f,g){g[b.u?"CRS":"SRS"]=f.a;"STYLES"in b.g||(g.STYLES=new String(""));if(1!=e)switch(b.ga){case "geoserver":e=90*e+.5|0;g.FORMAT_OPTIONS="FORMAT_OPTIONS"in g?g.FORMAT_OPTIONS+(";dpi:"+e):"dpi:"+e;break;case "mapserver":g.MAP_RESOLUTION=90*e;break;case "carmentaserver":case "qgis":g.DPI=90*e}g.WIDTH=d[0];g.HEIGHT=d[1];d=f.g;var h;b.u&&"ne"==d.substr(0,2)?h=[c[1],c[0],c[3],c[2]]:h=c;g.BBOX=h.join(",");return lo(no([b.i],g))}l.Qm=function(){return this.i}; +l.Rm=function(b){this.b=null;this.T=b;this.s()};l.Sm=function(b){b!=this.i&&(this.i=b,this.b=null,this.s())};l.Tm=function(b){Xb(this.g,b);Wz(this);this.b=null;this.s()};function Wz(b){b.u=0<=Pa(Sb(b.g,"VERSION","1.3.0"),"1.3")};function Zz(b){var c=void 0!==b.projection?b.projection:"EPSG:3857",d=void 0!==b.tileGrid?b.tileGrid:Oh({extent:Mh(c),maxZoom:b.maxZoom,tileSize:b.tileSize});Y.call(this,{attributions:b.attributions,crossOrigin:b.crossOrigin,logo:b.logo,projection:c,reprojectionErrorThreshold:b.reprojectionErrorThreshold,tileGrid:d,tileLoadFunction:b.tileLoadFunction,tilePixelRatio:b.tilePixelRatio,tileUrlFunction:b.tileUrlFunction,url:b.url,urls:b.urls,wrapX:void 0!==b.wrapX?b.wrapX:!0})}y(Zz,Y);function $z(b){b=b||{};var c;void 0!==b.attributions?c=b.attributions:c=[aA];Zz.call(this,{attributions:c,crossOrigin:void 0!==b.crossOrigin?b.crossOrigin:"anonymous",opaque:!0,maxZoom:void 0!==b.maxZoom?b.maxZoom:19,reprojectionErrorThreshold:b.reprojectionErrorThreshold,tileLoadFunction:b.tileLoadFunction,url:void 0!==b.url?b.url:"https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png",wrapX:b.wrapX})}y($z,Zz);var aA=new mg({html:'© OpenStreetMap contributors.'});function bA(b){b=b||{};var c=cA[b.layer];this.g=b.layer;Zz.call(this,{attributions:c.attributions,crossOrigin:"anonymous",logo:"https://developer.mapquest.com/content/osm/mq_logo.png",maxZoom:c.maxZoom,reprojectionErrorThreshold:b.reprojectionErrorThreshold,opaque:!0,tileLoadFunction:b.tileLoadFunction,url:void 0!==b.url?b.url:"https://otile{1-4}-s.mqcdn.com/tiles/1.0.0/"+this.g+"/{z}/{x}/{y}.jpg"})}y(bA,Zz); +var dA=new mg({html:'Tiles Courtesy of MapQuest'}),cA={osm:{maxZoom:19,attributions:[dA,aA]},sat:{maxZoom:18,attributions:[dA,new mg({html:"Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency"})]},hyb:{maxZoom:18,attributions:[dA,aA]}};bA.prototype.l=function(){return this.g};(function(){var b={},c={ka:b};(function(d){if("object"===typeof b&&"undefined"!==typeof c)c.ka=d();else{var e;"undefined"!==typeof window?e=window:"undefined"!==typeof global?e=global:"undefined"!==typeof self?e=self:e=this;e.Bp=d()}})(function(){return function e(b,c,h){function k(n,q){if(!c[n]){if(!b[n]){var r="function"==typeof require&&require;if(!q&&r)return r(n,!0);if(m)return m(n,!0);r=Error("Cannot find module '"+n+"'");throw r.code="MODULE_NOT_FOUND",r;}r=c[n]={ka:{}};b[n][0].call(r.ka,function(c){var e= +b[n][1][c];return k(e?e:c)},r,r.ka,e,b,c,h)}return c[n].ka}for(var m="function"==typeof require&&require,n=0;nthis.bj;)this.Yc.shift().$c(null,null)};m.prototype.eg=function(){if(0===this.Qd&&0Stamen Design, under CC BY 3.0.'}),aA];function qA(b){b=b||{};var c=void 0!==b.params?b.params:{};Y.call(this,{attributions:b.attributions,crossOrigin:b.crossOrigin,logo:b.logo,projection:b.projection,reprojectionErrorThreshold:b.reprojectionErrorThreshold,tileGrid:b.tileGrid,tileLoadFunction:b.tileLoadFunction,tileUrlFunction:ra(this.G,this),url:b.url,urls:b.urls,wrapX:void 0!==b.wrapX?b.wrapX:!0});this.g=c;this.l=Od()}y(qA,Y);qA.prototype.D=function(){return this.g}; +qA.prototype.Pb=function(b,c,d){b=qA.da.Pb.call(this,b,c,d);return 1==c?b:nd(b,c,this.b)}; +qA.prototype.G=function(b,c,d){var e=this.tileGrid;e||(e=this.hb(d));if(!(e.a.length<=b[0])){var f=e.Aa(b,this.l),g=od(e.Ha(b[0]),this.b);1!=c&&(g=nd(g,c,this.b));e={F:"image",FORMAT:"PNG32",TRANSPARENT:!0};Xb(e,this.g);var h=this.urls;h?(d=d.a.split(":").pop(),e.SIZE=g[0]+","+g[1],e.BBOX=f.join(","),e.BBOXSR=d,e.IMAGESR=d,e.DPI=Math.round(90*c),b=1==h.length?h[0]:h[pd((b[1]<g||e>g;)f.push([Math.ceil(d/g),Math.ceil(e/g)]),g+=g;break;case "truncated":for(;d>g||e>g;)f.push([Math.ceil(d/g),Math.ceil(e/g)]),d>>=1,e>>=1}f.push([1,1]);f.reverse();for(var g=[1],h=[0],e=1,d=f.length;ethis.b||d+this.a>this.b)return null;e=KA(this,!1,b,c,d,e,g);if(!e)return null;b=KA(this,!0,b,c,d,void 0!==f?f:ve,g);return{offsetX:e.offsetX,offsetY:e.offsetY,image:e.image,Mg:b.image}}; +function KA(b,c,d,e,f,g,h){var k=c?b.j:b.g,m,n,p;n=0;for(p=k.length;n=c+this.a&&g.height>=d+this.a)return k={offsetX:g.x+this.a,offsetY:g.y+this.a,image:this.b},this.f[b]=k,e.call(f,this.g,g.x+this.a,g.y+this.a),b=h,c=c+this.a,d=d+this.a,f=e=void 0,g.width-c>g.height-d?(e={x:g.x+c,y:g.y,width:g.width-c,height:g.height},f={x:g.x,y:g.y+d,width:c,height:g.height-d},LA(this,b,e,f)):(e={x:g.x+c,y:g.y,width:g.width-c,height:d},f={x:g.x,y:g.y+d,width:g.width,height:g.height- +d},LA(this,b,e,f)),k;return null};function LA(b,c,d,e){c=[c,1];0f&&(f=0);g=d.TileMatrixSetLink[f].TileMatrixSet; +var h=d.Format[0];"format"in c&&(h=c.format);f=gb(d.Style,function(b){return"style"in c?b.Title==c.style:b.isDefault});0>f&&(f=0);f=d.Style[f].Identifier;var k={};"Dimension"in d&&d.Dimension.forEach(function(b){var c=b.Identifier,d=b.Default;void 0===d&&(d=b.Value[0]);k[c]=d});var m=fb(b.Contents.TileMatrixSet,function(b){return b.Identifier==g}),n;n="projection"in c?Fe(c.projection):Fe(m.SupportedCRS.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/,"$1:$3"));var p=d.WGS84BoundingBox,q,r;void 0!==p&& +(r=Fe("EPSG:4326").J(),r=p[0]==r[0]&&p[2]==r[2],q=af(p,"EPSG:4326",n),(p=n.J())&&(Xd(p,q)||(q=void 0)));var m=EA(m,q),t=[];q=c.requestEncoding;q=void 0!==q?q:"";if(b.hasOwnProperty("OperationsMetadata")&&b.OperationsMetadata.hasOwnProperty("GetTile")&&0!==q.indexOf("REST"))for(var d=b.OperationsMetadata.GetTile.DCP.HTTP.Get,p=0,x=d.length;p