Batch 5a: application core folders
This commit is contained in:
11
application/cache/index.html
vendored
Executable file
11
application/cache/index.html
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
135
application/config/autoload.php
Executable file
135
application/config/autoload.php
Executable file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| AUTO-LOADER
|
||||
| -------------------------------------------------------------------
|
||||
| This file specifies which systems should be loaded by default.
|
||||
|
|
||||
| In order to keep the framework as light-weight as possible only the
|
||||
| absolute minimal resources are loaded by default. For example,
|
||||
| the database is not connected to automatically since no assumption
|
||||
| is made regarding whether you intend to use it. This file lets
|
||||
| you globally define which systems you would like loaded with every
|
||||
| request.
|
||||
|
|
||||
| -------------------------------------------------------------------
|
||||
| Instructions
|
||||
| -------------------------------------------------------------------
|
||||
|
|
||||
| These are the things you can load automatically:
|
||||
|
|
||||
| 1. Packages
|
||||
| 2. Libraries
|
||||
| 3. Drivers
|
||||
| 4. Helper files
|
||||
| 5. Custom config files
|
||||
| 6. Language files
|
||||
| 7. Models
|
||||
|
|
||||
*/
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Packages
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['packages'] = array(APPPATH.'third_party', '/usr/local/shared');
|
||||
|
|
||||
*/
|
||||
$autoload['packages'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Libraries
|
||||
| -------------------------------------------------------------------
|
||||
| These are the classes located in system/libraries/ or your
|
||||
| application/libraries/ directory, with the addition of the
|
||||
| 'database' library, which is somewhat of a special case.
|
||||
|
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['libraries'] = array('database', 'email', 'session');
|
||||
|
|
||||
| You can also supply an alternative library name to be assigned
|
||||
| in the controller:
|
||||
|
|
||||
| $autoload['libraries'] = array('user_agent' => 'ua');
|
||||
*/
|
||||
$autoload['libraries'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Drivers
|
||||
| -------------------------------------------------------------------
|
||||
| These classes are located in system/libraries/ or in your
|
||||
| application/libraries/ directory, but are also placed inside their
|
||||
| own subdirectory and they extend the CI_Driver_Library class. They
|
||||
| offer multiple interchangeable driver options.
|
||||
|
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['drivers'] = array('cache');
|
||||
|
|
||||
| You can also supply an alternative property name to be assigned in
|
||||
| the controller:
|
||||
|
|
||||
| $autoload['drivers'] = array('cache' => 'cch');
|
||||
|
|
||||
*/
|
||||
$autoload['drivers'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Helper Files
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['helper'] = array('url', 'file');
|
||||
*/
|
||||
$autoload['helper'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Config files
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['config'] = array('config1', 'config2');
|
||||
|
|
||||
| NOTE: This item is intended for use ONLY if you have created custom
|
||||
| config files. Otherwise, leave it blank.
|
||||
|
|
||||
*/
|
||||
$autoload['config'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Language files
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['language'] = array('lang1', 'lang2');
|
||||
|
|
||||
| NOTE: Do not include the "_lang" part of your file. For example
|
||||
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
||||
|
|
||||
*/
|
||||
$autoload['language'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Models
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['model'] = array('first_model', 'second_model');
|
||||
|
|
||||
| You can also supply an alternative model name to be assigned
|
||||
| in the controller:
|
||||
|
|
||||
| $autoload['model'] = array('first_model' => 'first');
|
||||
*/
|
||||
$autoload['model'] = array();
|
||||
524
application/config/config.php
Executable file
524
application/config/config.php
Executable file
@@ -0,0 +1,524 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Base Site URL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| URL to your CodeIgniter root. Typically this will be your base URL,
|
||||
| WITH a trailing slash:
|
||||
|
|
||||
| http://example.com/
|
||||
|
|
||||
| WARNING: You MUST set this value!
|
||||
|
|
||||
| If it is not set, then CodeIgniter will try guess the protocol and path
|
||||
| your installation, but due to security concerns the hostname will be set
|
||||
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
|
||||
| The auto-detection mechanism exists only for convenience during
|
||||
| development and MUST NOT be used in production!
|
||||
|
|
||||
| If you need to allow multiple domains, remember that this file is still
|
||||
| a PHP script and you can easily do that on your own.
|
||||
|
|
||||
*/
|
||||
$config['base_url'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Index File
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Typically this will be your index.php file, unless you've renamed it to
|
||||
| something else. If you are using mod_rewrite to remove the page set this
|
||||
| variable so that it is blank.
|
||||
|
|
||||
*/
|
||||
$config['index_page'] = 'index.php';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| URI PROTOCOL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This item determines which server global should be used to retrieve the
|
||||
| URI string. The default setting of 'REQUEST_URI' works for most servers.
|
||||
| If your links do not seem to work, try one of the other delicious flavors:
|
||||
|
|
||||
| 'REQUEST_URI' Uses $_SERVER['REQUEST_URI']
|
||||
| 'QUERY_STRING' Uses $_SERVER['QUERY_STRING']
|
||||
| 'PATH_INFO' Uses $_SERVER['PATH_INFO']
|
||||
|
|
||||
| WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
|
||||
*/
|
||||
$config['uri_protocol'] = 'REQUEST_URI';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| URL suffix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option allows you to add a suffix to all URLs generated by CodeIgniter.
|
||||
| For more information please see the user guide:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/urls.html
|
||||
*/
|
||||
$config['url_suffix'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Language
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This determines which set of language files should be used. Make sure
|
||||
| there is an available translation if you intend to use something other
|
||||
| than english.
|
||||
|
|
||||
*/
|
||||
$config['language'] = 'english';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Character Set
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This determines which character set is used by default in various methods
|
||||
| that require a character set to be provided.
|
||||
|
|
||||
| See http://php.net/htmlspecialchars for a list of supported charsets.
|
||||
|
|
||||
*/
|
||||
$config['charset'] = 'UTF-8';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable/Disable System Hooks
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If you would like to use the 'hooks' feature you must enable it by
|
||||
| setting this variable to TRUE (boolean). See the user guide for details.
|
||||
|
|
||||
*/
|
||||
$config['enable_hooks'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Class Extension Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This item allows you to set the filename/classname prefix when extending
|
||||
| native libraries. For more information please see the user guide:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/core_classes.html
|
||||
| https://codeigniter.com/user_guide/general/creating_libraries.html
|
||||
|
|
||||
*/
|
||||
$config['subclass_prefix'] = 'MY_';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Composer auto-loading
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Enabling this setting will tell CodeIgniter to look for a Composer
|
||||
| package auto-loader script in application/vendor/autoload.php.
|
||||
|
|
||||
| $config['composer_autoload'] = TRUE;
|
||||
|
|
||||
| Or if you have your vendor/ directory located somewhere else, you
|
||||
| can opt to set a specific path as well:
|
||||
|
|
||||
| $config['composer_autoload'] = '/path/to/vendor/autoload.php';
|
||||
|
|
||||
| For more information about Composer, please visit http://getcomposer.org/
|
||||
|
|
||||
| Note: This will NOT disable or override the CodeIgniter-specific
|
||||
| autoloading (application/config/autoload.php)
|
||||
*/
|
||||
$config['composer_autoload'] = false;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allowed URL Characters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This lets you specify which characters are permitted within your URLs.
|
||||
| When someone tries to submit a URL with disallowed characters they will
|
||||
| get a warning message.
|
||||
|
|
||||
| As a security measure you are STRONGLY encouraged to restrict URLs to
|
||||
| as few characters as possible. By default only these are allowed: a-z 0-9~%.:_-
|
||||
|
|
||||
| Leave blank to allow all characters -- but only if you are insane.
|
||||
|
|
||||
| The configured value is actually a regular expression character group
|
||||
| and it will be executed as: ! preg_match('/^[<permitted_uri_chars>]+$/i
|
||||
|
|
||||
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
||||
|
|
||||
*/
|
||||
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable Query Strings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By default CodeIgniter uses search-engine friendly segment based URLs:
|
||||
| example.com/who/what/where/
|
||||
|
|
||||
| You can optionally enable standard query string based URLs:
|
||||
| example.com?who=me&what=something&where=here
|
||||
|
|
||||
| Options are: TRUE or FALSE (boolean)
|
||||
|
|
||||
| The other items let you set the query string 'words' that will
|
||||
| invoke your controllers and its functions:
|
||||
| example.com/index.php?c=controller&m=function
|
||||
|
|
||||
| Please note that some of the helpers won't work as expected when
|
||||
| this feature is enabled, since CodeIgniter is designed primarily to
|
||||
| use segment based URLs.
|
||||
|
|
||||
*/
|
||||
$config['enable_query_strings'] = FALSE;
|
||||
$config['controller_trigger'] = 'c';
|
||||
$config['function_trigger'] = 'm';
|
||||
$config['directory_trigger'] = 'd';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allow $_GET array
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By default CodeIgniter enables access to the $_GET array. If for some
|
||||
| reason you would like to disable it, set 'allow_get_array' to FALSE.
|
||||
|
|
||||
| WARNING: This feature is DEPRECATED and currently available only
|
||||
| for backwards compatibility purposes!
|
||||
|
|
||||
*/
|
||||
$config['allow_get_array'] = TRUE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Error Logging Threshold
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You can enable error logging by setting a threshold over zero. The
|
||||
| threshold determines what gets logged. Threshold options are:
|
||||
|
|
||||
| 0 = Disables logging, Error logging TURNED OFF
|
||||
| 1 = Error Messages (including PHP errors)
|
||||
| 2 = Debug Messages
|
||||
| 3 = Informational Messages
|
||||
| 4 = All Messages
|
||||
|
|
||||
| You can also pass an array with threshold levels to show individual error types
|
||||
|
|
||||
| array(2) = Debug Messages, without Error Messages
|
||||
|
|
||||
| For a live site you'll usually only enable Errors (1) to be logged otherwise
|
||||
| your log files will fill up very fast.
|
||||
|
|
||||
*/
|
||||
$config['log_threshold'] = 0;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Error Logging Directory Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Leave this BLANK unless you would like to set something other than the default
|
||||
| application/logs/ directory. Use a full server path with trailing slash.
|
||||
|
|
||||
*/
|
||||
$config['log_path'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log File Extension
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The default filename extension for log files. The default 'php' allows for
|
||||
| protecting the log files via basic scripting, when they are to be stored
|
||||
| under a publicly accessible directory.
|
||||
|
|
||||
| Note: Leaving it blank will default to 'php'.
|
||||
|
|
||||
*/
|
||||
$config['log_file_extension'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log File Permissions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The file system permissions to be applied on newly created log files.
|
||||
|
|
||||
| IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
|
||||
| integer notation (i.e. 0700, 0644, etc.)
|
||||
*/
|
||||
$config['log_file_permissions'] = 0644;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Date Format for Logs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Each item that is logged has an associated date. You can use PHP date
|
||||
| codes to set your own date formatting
|
||||
|
|
||||
*/
|
||||
$config['log_date_format'] = 'Y-m-d H:i:s';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Error Views Directory Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Leave this BLANK unless you would like to set something other than the default
|
||||
| application/views/errors/ directory. Use a full server path with trailing slash.
|
||||
|
|
||||
*/
|
||||
$config['error_views_path'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Directory Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Leave this BLANK unless you would like to set something other than the default
|
||||
| application/cache/ directory. Use a full server path with trailing slash.
|
||||
|
|
||||
*/
|
||||
$config['cache_path'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Include Query String
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Whether to take the URL query string into consideration when generating
|
||||
| output cache files. Valid options are:
|
||||
|
|
||||
| FALSE = Disabled
|
||||
| TRUE = Enabled, take all query parameters into account.
|
||||
| Please be aware that this may result in numerous cache
|
||||
| files generated for the same page over and over again.
|
||||
| array('q') = Enabled, but only take into account the specified list
|
||||
| of query parameters.
|
||||
|
|
||||
*/
|
||||
$config['cache_query_string'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Encryption Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If you use the Encryption class, you must set an encryption key.
|
||||
| See the user guide for more info.
|
||||
|
|
||||
| https://codeigniter.com/user_guide/libraries/encryption.html
|
||||
|
|
||||
*/
|
||||
$config['encryption_key'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Variables
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| 'sess_driver'
|
||||
|
|
||||
| The storage driver to use: files, database, redis, memcached
|
||||
|
|
||||
| 'sess_cookie_name'
|
||||
|
|
||||
| The session cookie name, must contain only [0-9a-z_-] characters
|
||||
|
|
||||
| 'sess_expiration'
|
||||
|
|
||||
| The number of SECONDS you want the session to last.
|
||||
| Setting to 0 (zero) means expire when the browser is closed.
|
||||
|
|
||||
| 'sess_save_path'
|
||||
|
|
||||
| The location to save sessions to, driver dependent.
|
||||
|
|
||||
| For the 'files' driver, it's a path to a writable directory.
|
||||
| WARNING: Only absolute paths are supported!
|
||||
|
|
||||
| For the 'database' driver, it's a table name.
|
||||
| Please read up the manual for the format with other session drivers.
|
||||
|
|
||||
| IMPORTANT: You are REQUIRED to set a valid save path!
|
||||
|
|
||||
| 'sess_match_ip'
|
||||
|
|
||||
| Whether to match the user's IP address when reading the session data.
|
||||
|
|
||||
| WARNING: If you're using the database driver, don't forget to update
|
||||
| your session table's PRIMARY KEY when changing this setting.
|
||||
|
|
||||
| 'sess_time_to_update'
|
||||
|
|
||||
| How many seconds between CI regenerating the session ID.
|
||||
|
|
||||
| 'sess_regenerate_destroy'
|
||||
|
|
||||
| Whether to destroy session data associated with the old session ID
|
||||
| when auto-regenerating the session ID. When set to FALSE, the data
|
||||
| will be later deleted by the garbage collector.
|
||||
|
|
||||
| Other session cookie settings are shared with the rest of the application,
|
||||
| except for 'cookie_prefix' and 'cookie_httponly', which are ignored here.
|
||||
|
|
||||
*/
|
||||
$config['sess_driver'] = 'files';
|
||||
$config['sess_cookie_name'] = 'ci_session';
|
||||
$config['sess_expiration'] = 7200;
|
||||
$config['sess_save_path'] = NULL;
|
||||
$config['sess_match_ip'] = FALSE;
|
||||
$config['sess_time_to_update'] = 300;
|
||||
$config['sess_regenerate_destroy'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cookie Related Variables
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions
|
||||
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
|
||||
| 'cookie_path' = Typically will be a forward slash
|
||||
| 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists.
|
||||
| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
|
||||
|
|
||||
| Note: These settings (with the exception of 'cookie_prefix' and
|
||||
| 'cookie_httponly') will also affect sessions.
|
||||
|
|
||||
*/
|
||||
$config['cookie_prefix'] = '';
|
||||
$config['cookie_domain'] = '';
|
||||
$config['cookie_path'] = '/';
|
||||
$config['cookie_secure'] = FALSE;
|
||||
$config['cookie_httponly'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Standardize newlines
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Determines whether to standardize newline characters in input data,
|
||||
| meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value.
|
||||
|
|
||||
| WARNING: This feature is DEPRECATED and currently available only
|
||||
| for backwards compatibility purposes!
|
||||
|
|
||||
*/
|
||||
$config['standardize_newlines'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global XSS Filtering
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Determines whether the XSS filter is always active when GET, POST or
|
||||
| COOKIE data is encountered
|
||||
|
|
||||
| WARNING: This feature is DEPRECATED and currently available only
|
||||
| for backwards compatibility purposes!
|
||||
|
|
||||
*/
|
||||
$config['global_xss_filtering'] = FALSE; // DEFAULT
|
||||
// $config['global_xss_filtering'] = TRUE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cross Site Request Forgery
|
||||
|--------------------------------------------------------------------------
|
||||
| Enables a CSRF cookie token to be set. When set to TRUE, token will be
|
||||
| checked on a submitted form. If you are accepting user data, it is strongly
|
||||
| recommended CSRF protection be enabled.
|
||||
|
|
||||
| 'csrf_token_name' = The token name
|
||||
| 'csrf_cookie_name' = The cookie name
|
||||
| 'csrf_expire' = The number in seconds the token should expire.
|
||||
| 'csrf_regenerate' = Regenerate token on every submission
|
||||
| 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks
|
||||
*/
|
||||
$config['csrf_protection'] = FALSE;
|
||||
$config['csrf_token_name'] = 'csrf_test_name';
|
||||
$config['csrf_cookie_name'] = 'csrf_cookie_name';
|
||||
$config['csrf_expire'] = 7200;
|
||||
$config['csrf_regenerate'] = TRUE;
|
||||
$config['csrf_exclude_uris'] = array();
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Output Compression
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Enables Gzip output compression for faster page loads. When enabled,
|
||||
| the output class will test whether your server supports Gzip.
|
||||
| Even if it does, however, not all browsers support compression
|
||||
| so enable only if you are reasonably sure your visitors can handle it.
|
||||
|
|
||||
| Only used if zlib.output_compression is turned off in your php.ini.
|
||||
| Please do not use it together with httpd-level output compression.
|
||||
|
|
||||
| VERY IMPORTANT: If you are getting a blank page when compression is enabled it
|
||||
| means you are prematurely outputting something to your browser. It could
|
||||
| even be a line of whitespace at the end of one of your scripts. For
|
||||
| compression to work, nothing can be sent before the output buffer is called
|
||||
| by the output class. Do not 'echo' any values with compression enabled.
|
||||
|
|
||||
*/
|
||||
$config['compress_output'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Master Time Reference
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Options are 'local' or any PHP supported timezone. This preference tells
|
||||
| the system whether to use your server's local time as the master 'now'
|
||||
| reference, or convert it to the configured one timezone. See the 'date
|
||||
| helper' page of the user guide for information regarding date handling.
|
||||
|
|
||||
*/
|
||||
$config['time_reference'] = 'local';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Rewrite PHP Short Tags
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If your PHP installation does not have short tag support enabled CI
|
||||
| can rewrite the tags on-the-fly, enabling you to utilize that syntax
|
||||
| in your view files. Options are TRUE or FALSE (boolean)
|
||||
|
|
||||
| Note: You need to have eval() enabled for this to work.
|
||||
|
|
||||
*/
|
||||
$config['rewrite_short_tags'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Reverse Proxy IPs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If your server is behind a reverse proxy, you must whitelist the proxy
|
||||
| IP addresses from which CodeIgniter should trust headers such as
|
||||
| HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP in order to properly identify
|
||||
| the visitor's IP address.
|
||||
|
|
||||
| You can use both an array or a comma-separated list of proxy addresses,
|
||||
| as well as specifying whole subnets. Here are a few examples:
|
||||
|
|
||||
| Comma-separated: '10.0.1.200,192.168.5.0/24'
|
||||
| Array: array('10.0.1.200', '192.168.5.0/24')
|
||||
*/
|
||||
$config['proxy_ips'] = '';
|
||||
85
application/config/constants.php
Executable file
85
application/config/constants.php
Executable file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Display Debug backtrace
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If set to TRUE, a backtrace will be displayed along with php errors. If
|
||||
| error_reporting is disabled, the backtrace will not display, regardless
|
||||
| of this setting
|
||||
|
|
||||
*/
|
||||
defined('SHOW_DEBUG_BACKTRACE') OR define('SHOW_DEBUG_BACKTRACE', TRUE);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| File and Directory Modes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These prefs are used when checking and setting modes when working
|
||||
| with the file system. The defaults are fine on servers with proper
|
||||
| security, but you may wish (or even need) to change the values in
|
||||
| certain environments (Apache running a separate process for each
|
||||
| user, PHP under CGI with Apache suEXEC, etc.). Octal values should
|
||||
| always be used to set the mode correctly.
|
||||
|
|
||||
*/
|
||||
defined('FILE_READ_MODE') OR define('FILE_READ_MODE', 0644);
|
||||
defined('FILE_WRITE_MODE') OR define('FILE_WRITE_MODE', 0666);
|
||||
defined('DIR_READ_MODE') OR define('DIR_READ_MODE', 0755);
|
||||
defined('DIR_WRITE_MODE') OR define('DIR_WRITE_MODE', 0755);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| File Stream Modes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These modes are used when working with fopen()/popen()
|
||||
|
|
||||
*/
|
||||
defined('FOPEN_READ') OR define('FOPEN_READ', 'rb');
|
||||
defined('FOPEN_READ_WRITE') OR define('FOPEN_READ_WRITE', 'r+b');
|
||||
defined('FOPEN_WRITE_CREATE_DESTRUCTIVE') OR define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care
|
||||
defined('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE') OR define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care
|
||||
defined('FOPEN_WRITE_CREATE') OR define('FOPEN_WRITE_CREATE', 'ab');
|
||||
defined('FOPEN_READ_WRITE_CREATE') OR define('FOPEN_READ_WRITE_CREATE', 'a+b');
|
||||
defined('FOPEN_WRITE_CREATE_STRICT') OR define('FOPEN_WRITE_CREATE_STRICT', 'xb');
|
||||
defined('FOPEN_READ_WRITE_CREATE_STRICT') OR define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Exit Status Codes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Used to indicate the conditions under which the script is exit()ing.
|
||||
| While there is no universal standard for error codes, there are some
|
||||
| broad conventions. Three such conventions are mentioned below, for
|
||||
| those who wish to make use of them. The CodeIgniter defaults were
|
||||
| chosen for the least overlap with these conventions, while still
|
||||
| leaving room for others to be defined in future versions and user
|
||||
| applications.
|
||||
|
|
||||
| The three main conventions used for determining exit status codes
|
||||
| are as follows:
|
||||
|
|
||||
| Standard C/C++ Library (stdlibc):
|
||||
| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
|
||||
| (This link also contains other GNU-specific conventions)
|
||||
| BSD sysexits.h:
|
||||
| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits
|
||||
| Bash scripting:
|
||||
| http://tldp.org/LDP/abs/html/exitcodes.html
|
||||
|
|
||||
*/
|
||||
defined('EXIT_SUCCESS') OR define('EXIT_SUCCESS', 0); // no errors
|
||||
defined('EXIT_ERROR') OR define('EXIT_ERROR', 1); // generic error
|
||||
defined('EXIT_CONFIG') OR define('EXIT_CONFIG', 3); // configuration error
|
||||
defined('EXIT_UNKNOWN_FILE') OR define('EXIT_UNKNOWN_FILE', 4); // file not found
|
||||
defined('EXIT_UNKNOWN_CLASS') OR define('EXIT_UNKNOWN_CLASS', 5); // unknown class
|
||||
defined('EXIT_UNKNOWN_METHOD') OR define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
|
||||
defined('EXIT_USER_INPUT') OR define('EXIT_USER_INPUT', 7); // invalid user input
|
||||
defined('EXIT_DATABASE') OR define('EXIT_DATABASE', 8); // database error
|
||||
defined('EXIT__AUTO_MIN') OR define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
|
||||
defined('EXIT__AUTO_MAX') OR define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
|
||||
185
application/config/database-mcu.php
Executable file
185
application/config/database-mcu.php
Executable file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| DATABASE CONNECTIVITY SETTINGS
|
||||
| -------------------------------------------------------------------
|
||||
| This file will contain the settings needed to access your database.
|
||||
|
|
||||
| For complete instructions please consult the 'Database Connection'
|
||||
| page of the User Guide.
|
||||
|
|
||||
| -------------------------------------------------------------------
|
||||
| EXPLANATION OF VARIABLES
|
||||
| -------------------------------------------------------------------
|
||||
|
|
||||
| ['dsn'] The full DSN string describe a connection to the database.
|
||||
| ['hostname'] The hostname of your database server.
|
||||
| ['username'] The username used to connect to the database
|
||||
| ['password'] The password used to connect to the database
|
||||
| ['database'] The name of the database you want to connect to
|
||||
| ['dbdriver'] The database driver. e.g.: mysqli.
|
||||
| Currently supported:
|
||||
| cubrid, ibase, mssql, mysql, mysqli, oci8,
|
||||
| odbc, pdo, postgre, sqlite, sqlite3, sqlsrv
|
||||
| ['dbprefix'] You can add an optional prefix, which will be added
|
||||
| to the table name when using the Query Builder class
|
||||
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
|
||||
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
|
||||
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
|
||||
| ['cachedir'] The path to the folder where cache files should be stored
|
||||
| ['char_set'] The character set used in communicating with the database
|
||||
| ['dbcollat'] The character collation used in communicating with the database
|
||||
| NOTE: For MySQL and MySQLi databases, this setting is only used
|
||||
| as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
|
||||
| (and in table creation queries made with DB Forge).
|
||||
| There is an incompatibility in PHP with mysql_real_escape_string() which
|
||||
| can make your site vulnerable to SQL injection if you are using a
|
||||
| multi-byte character set and are running versions lower than these.
|
||||
| Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
|
||||
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
|
||||
| ['encrypt'] Whether or not to use an encrypted connection.
|
||||
|
|
||||
| 'mysql' (deprecated), 'sqlsrv' and 'pdo/sqlsrv' drivers accept TRUE/FALSE
|
||||
| 'mysqli' and 'pdo/mysql' drivers accept an array with the following options:
|
||||
|
|
||||
| 'ssl_key' - Path to the private key file
|
||||
| 'ssl_cert' - Path to the public key certificate file
|
||||
| 'ssl_ca' - Path to the certificate authority file
|
||||
| 'ssl_capath' - Path to a directory containing trusted CA certificates in PEM format
|
||||
| 'ssl_cipher' - List of *allowed* ciphers to be used for the encryption, separated by colons (':')
|
||||
| 'ssl_verify' - TRUE/FALSE; Whether verify the server certificate or not ('mysqli' only)
|
||||
|
|
||||
| ['compress'] Whether or not to use client compression (MySQL only)
|
||||
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
|
||||
| - good for ensuring strict SQL while developing
|
||||
| ['ssl_options'] Used to set various SSL options that can be used when making SSL connections.
|
||||
| ['failover'] array - A array with 0 or more data for connections if the main should fail.
|
||||
| ['save_queries'] TRUE/FALSE - Whether to "save" all executed queries.
|
||||
| NOTE: Disabling this will also effectively disable both
|
||||
| $this->db->last_query() and profiling of DB queries.
|
||||
| When you run a query, with this setting set to TRUE (default),
|
||||
| CodeIgniter will store the SQL statement for debugging purposes.
|
||||
| However, this may cause high memory usage, especially if you run
|
||||
| a lot of SQL queries ... disable this to avoid that problem.
|
||||
|
|
||||
| The $active_group variable lets you choose which connection group to
|
||||
| make active. By default there is only one group (the 'default' group).
|
||||
|
|
||||
| The $query_builder variables lets you determine whether or not to load
|
||||
| the query builder class.
|
||||
*/
|
||||
$active_group = 'default';
|
||||
$query_builder = TRUE;
|
||||
|
||||
$db['default'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'mcupramita123321',
|
||||
'database' => 'one',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
);
|
||||
|
||||
|
||||
$db['onedev'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'mcupramita123321',
|
||||
'database' => 'one',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
);
|
||||
|
||||
$db['clinicdev'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'mcupramita123321',
|
||||
'database' => 'one_clinic',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
);
|
||||
|
||||
$db['antrione'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'mcupramita123321',
|
||||
'database' => 'antrione',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
);
|
||||
|
||||
$db['onelog'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'mcupramita123321',
|
||||
'database' => 'one_log',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
);
|
||||
1992
application/config/database.php
Executable file
1992
application/config/database.php
Executable file
File diff suppressed because it is too large
Load Diff
24
application/config/doctypes.php
Executable file
24
application/config/doctypes.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
$_doctypes = array(
|
||||
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
|
||||
'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
||||
'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
||||
'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
||||
'xhtml-basic11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
|
||||
'html5' => '<!DOCTYPE html>',
|
||||
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
||||
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
||||
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
|
||||
'mathml1' => '<!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd">',
|
||||
'mathml2' => '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">',
|
||||
'svg10' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
|
||||
'svg11' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',
|
||||
'svg11-basic' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">',
|
||||
'svg11-tiny' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">',
|
||||
'xhtml-math-svg-xh' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||
'xhtml-math-svg-sh' => '<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||
'xhtml-rdfa-1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
|
||||
'xhtml-rdfa-2' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">'
|
||||
);
|
||||
103
application/config/foreign_chars.php
Executable file
103
application/config/foreign_chars.php
Executable file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Foreign Characters
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains an array of foreign characters for transliteration
|
||||
| conversion used by the Text helper
|
||||
|
|
||||
*/
|
||||
$foreign_characters = array(
|
||||
'/ä|æ|ǽ/' => 'ae',
|
||||
'/ö|œ/' => 'oe',
|
||||
'/ü/' => 'ue',
|
||||
'/Ä/' => 'Ae',
|
||||
'/Ü/' => 'Ue',
|
||||
'/Ö/' => 'Oe',
|
||||
'/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ|А/' => 'A',
|
||||
'/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ|а/' => 'a',
|
||||
'/Б/' => 'B',
|
||||
'/б/' => 'b',
|
||||
'/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
|
||||
'/ç|ć|ĉ|ċ|č/' => 'c',
|
||||
'/Д/' => 'D',
|
||||
'/д/' => 'd',
|
||||
'/Ð|Ď|Đ|Δ/' => 'Dj',
|
||||
'/ð|ď|đ|δ/' => 'dj',
|
||||
'/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ|Е|Э/' => 'E',
|
||||
'/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ|е|э/' => 'e',
|
||||
'/Ф/' => 'F',
|
||||
'/ф/' => 'f',
|
||||
'/Ĝ|Ğ|Ġ|Ģ|Γ|Г|Ґ/' => 'G',
|
||||
'/ĝ|ğ|ġ|ģ|γ|г|ґ/' => 'g',
|
||||
'/Ĥ|Ħ/' => 'H',
|
||||
'/ĥ|ħ/' => 'h',
|
||||
'/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị|И|Ы/' => 'I',
|
||||
'/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị|и|ы|ї/' => 'i',
|
||||
'/Ĵ/' => 'J',
|
||||
'/ĵ/' => 'j',
|
||||
'/Ķ|Κ|К/' => 'K',
|
||||
'/ķ|κ|к/' => 'k',
|
||||
'/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ|Л/' => 'L',
|
||||
'/ĺ|ļ|ľ|ŀ|ł|λ|л/' => 'l',
|
||||
'/М/' => 'M',
|
||||
'/м/' => 'm',
|
||||
'/Ñ|Ń|Ņ|Ň|Ν|Н/' => 'N',
|
||||
'/ñ|ń|ņ|ň|ʼn|ν|н/' => 'n',
|
||||
'/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ|О/' => 'O',
|
||||
'/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ|о/' => 'o',
|
||||
'/П/' => 'P',
|
||||
'/п/' => 'p',
|
||||
'/Ŕ|Ŗ|Ř|Ρ|Р/' => 'R',
|
||||
'/ŕ|ŗ|ř|ρ|р/' => 'r',
|
||||
'/Ś|Ŝ|Ş|Ș|Š|Σ|С/' => 'S',
|
||||
'/ś|ŝ|ş|ș|š|ſ|σ|ς|с/' => 's',
|
||||
'/Ț|Ţ|Ť|Ŧ|τ|Т/' => 'T',
|
||||
'/ț|ţ|ť|ŧ|т/' => 't',
|
||||
'/Þ|þ/' => 'th',
|
||||
'/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự|У/' => 'U',
|
||||
'/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự|у/' => 'u',
|
||||
'/Ƴ|Ɏ|Ỵ|Ẏ|Ӳ|Ӯ|Ў|Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ|Й/' => 'Y',
|
||||
'/ẙ|ʏ|ƴ|ɏ|ỵ|ẏ|ӳ|ӯ|ў|ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ|й/' => 'y',
|
||||
'/В/' => 'V',
|
||||
'/в/' => 'v',
|
||||
'/Ŵ/' => 'W',
|
||||
'/ŵ/' => 'w',
|
||||
'/Ź|Ż|Ž|Ζ|З/' => 'Z',
|
||||
'/ź|ż|ž|ζ|з/' => 'z',
|
||||
'/Æ|Ǽ/' => 'AE',
|
||||
'/ß/' => 'ss',
|
||||
'/IJ/' => 'IJ',
|
||||
'/ij/' => 'ij',
|
||||
'/Œ/' => 'OE',
|
||||
'/ƒ/' => 'f',
|
||||
'/ξ/' => 'ks',
|
||||
'/π/' => 'p',
|
||||
'/β/' => 'v',
|
||||
'/μ/' => 'm',
|
||||
'/ψ/' => 'ps',
|
||||
'/Ё/' => 'Yo',
|
||||
'/ё/' => 'yo',
|
||||
'/Є/' => 'Ye',
|
||||
'/є/' => 'ye',
|
||||
'/Ї/' => 'Yi',
|
||||
'/Ж/' => 'Zh',
|
||||
'/ж/' => 'zh',
|
||||
'/Х/' => 'Kh',
|
||||
'/х/' => 'kh',
|
||||
'/Ц/' => 'Ts',
|
||||
'/ц/' => 'ts',
|
||||
'/Ч/' => 'Ch',
|
||||
'/ч/' => 'ch',
|
||||
'/Ш/' => 'Sh',
|
||||
'/ш/' => 'sh',
|
||||
'/Щ/' => 'Shch',
|
||||
'/щ/' => 'shch',
|
||||
'/Ъ|ъ|Ь|ь/' => '',
|
||||
'/Ю/' => 'Yu',
|
||||
'/ю/' => 'yu',
|
||||
'/Я/' => 'Ya',
|
||||
'/я/' => 'ya'
|
||||
);
|
||||
13
application/config/hooks.php
Executable file
13
application/config/hooks.php
Executable file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Hooks
|
||||
| -------------------------------------------------------------------------
|
||||
| This file lets you define "hooks" to extend CI without hacking the core
|
||||
| files. Please see the user guide for info:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/hooks.html
|
||||
|
|
||||
*/
|
||||
11
application/config/index.html
Executable file
11
application/config/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
19
application/config/memcached.php
Executable file
19
application/config/memcached.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Memcached settings
|
||||
| -------------------------------------------------------------------------
|
||||
| Your Memcached servers can be specified below.
|
||||
|
|
||||
| See: https://codeigniter.com/user_guide/libraries/caching.html#memcached
|
||||
|
|
||||
*/
|
||||
$config = array(
|
||||
'default' => array(
|
||||
'hostname' => '127.0.0.1',
|
||||
'port' => '11211',
|
||||
'weight' => '1',
|
||||
),
|
||||
);
|
||||
84
application/config/migration.php
Executable file
84
application/config/migration.php
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable/Disable Migrations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Migrations are disabled by default for security reasons.
|
||||
| You should enable migrations whenever you intend to do a schema migration
|
||||
| and disable it back when you're done.
|
||||
|
|
||||
*/
|
||||
$config['migration_enabled'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migration Type
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Migration file names may be based on a sequential identifier or on
|
||||
| a timestamp. Options are:
|
||||
|
|
||||
| 'sequential' = Sequential migration naming (001_add_blog.php)
|
||||
| 'timestamp' = Timestamp migration naming (20121031104401_add_blog.php)
|
||||
| Use timestamp format YYYYMMDDHHIISS.
|
||||
|
|
||||
| Note: If this configuration value is missing the Migration library
|
||||
| defaults to 'sequential' for backward compatibility with CI2.
|
||||
|
|
||||
*/
|
||||
$config['migration_type'] = 'timestamp';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migrations table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the name of the table that will store the current migrations state.
|
||||
| When migrations runs it will store in a database table which migration
|
||||
| level the system is at. It then compares the migration level in this
|
||||
| table to the $config['migration_version'] if they are not the same it
|
||||
| will migrate up. This must be set.
|
||||
|
|
||||
*/
|
||||
$config['migration_table'] = 'migrations';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Auto Migrate To Latest
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If this is set to TRUE when you load the migrations class and have
|
||||
| $config['migration_enabled'] set to TRUE the system will auto migrate
|
||||
| to your latest migration (whatever $config['migration_version'] is
|
||||
| set to). This way you do not have to call migrations anywhere else
|
||||
| in your code to have the latest migration.
|
||||
|
|
||||
*/
|
||||
$config['migration_auto_latest'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migrations version
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is used to set migration version that the file system should be on.
|
||||
| If you run $this->migration->current() this is the version that schema will
|
||||
| be upgraded / downgraded to.
|
||||
|
|
||||
*/
|
||||
$config['migration_version'] = 0;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migrations Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Path to your migrations folder.
|
||||
| Typically, it will be within your application path.
|
||||
| Also, writing permission is required within the migrations path.
|
||||
|
|
||||
*/
|
||||
$config['migration_path'] = APPPATH.'migrations/';
|
||||
184
application/config/mimes.php
Executable file
184
application/config/mimes.php
Executable file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| MIME TYPES
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains an array of mime types. It is used by the
|
||||
| Upload class to help identify allowed file types.
|
||||
|
|
||||
*/
|
||||
return array(
|
||||
'hqx' => array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'),
|
||||
'cpt' => 'application/mac-compactpro',
|
||||
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'),
|
||||
'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'),
|
||||
'dms' => 'application/octet-stream',
|
||||
'lha' => 'application/octet-stream',
|
||||
'lzh' => 'application/octet-stream',
|
||||
'exe' => array('application/octet-stream', 'application/x-msdownload'),
|
||||
'class' => 'application/octet-stream',
|
||||
'psd' => array('application/x-photoshop', 'image/vnd.adobe.photoshop'),
|
||||
'so' => 'application/octet-stream',
|
||||
'sea' => 'application/octet-stream',
|
||||
'dll' => 'application/octet-stream',
|
||||
'oda' => 'application/oda',
|
||||
'pdf' => array('application/pdf', 'application/force-download', 'application/x-download', 'binary/octet-stream'),
|
||||
'ai' => array('application/pdf', 'application/postscript'),
|
||||
'eps' => 'application/postscript',
|
||||
'ps' => 'application/postscript',
|
||||
'smi' => 'application/smil',
|
||||
'smil' => 'application/smil',
|
||||
'mif' => 'application/vnd.mif',
|
||||
'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'),
|
||||
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint', 'application/vnd.ms-office', 'application/msword'),
|
||||
'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/x-zip', 'application/zip'),
|
||||
'wbxml' => 'application/wbxml',
|
||||
'wmlc' => 'application/wmlc',
|
||||
'dcr' => 'application/x-director',
|
||||
'dir' => 'application/x-director',
|
||||
'dxr' => 'application/x-director',
|
||||
'dvi' => 'application/x-dvi',
|
||||
'gtar' => 'application/x-gtar',
|
||||
'gz' => 'application/x-gzip',
|
||||
'gzip' => 'application/x-gzip',
|
||||
'php' => array('application/x-httpd-php', 'application/php', 'application/x-php', 'text/php', 'text/x-php', 'application/x-httpd-php-source'),
|
||||
'php4' => 'application/x-httpd-php',
|
||||
'php3' => 'application/x-httpd-php',
|
||||
'phtml' => 'application/x-httpd-php',
|
||||
'phps' => 'application/x-httpd-php-source',
|
||||
'js' => array('application/x-javascript', 'text/plain'),
|
||||
'swf' => 'application/x-shockwave-flash',
|
||||
'sit' => 'application/x-stuffit',
|
||||
'tar' => 'application/x-tar',
|
||||
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
|
||||
'z' => 'application/x-compress',
|
||||
'xhtml' => 'application/xhtml+xml',
|
||||
'xht' => 'application/xhtml+xml',
|
||||
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'),
|
||||
'rar' => array('application/x-rar', 'application/rar', 'application/x-rar-compressed'),
|
||||
'mid' => 'audio/midi',
|
||||
'midi' => 'audio/midi',
|
||||
'mpga' => 'audio/mpeg',
|
||||
'mp2' => 'audio/mpeg',
|
||||
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
|
||||
'aif' => array('audio/x-aiff', 'audio/aiff'),
|
||||
'aiff' => array('audio/x-aiff', 'audio/aiff'),
|
||||
'aifc' => 'audio/x-aiff',
|
||||
'ram' => 'audio/x-pn-realaudio',
|
||||
'rm' => 'audio/x-pn-realaudio',
|
||||
'rpm' => 'audio/x-pn-realaudio-plugin',
|
||||
'ra' => 'audio/x-realaudio',
|
||||
'rv' => 'video/vnd.rn-realvideo',
|
||||
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
|
||||
'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'),
|
||||
'gif' => 'image/gif',
|
||||
'jpeg' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jpg' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jpe' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'j2k' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpf' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpg2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpx' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpm' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'mj2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'mjp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'png' => array('image/png', 'image/x-png'),
|
||||
'tiff' => 'image/tiff',
|
||||
'tif' => 'image/tiff',
|
||||
'css' => array('text/css', 'text/plain'),
|
||||
'html' => array('text/html', 'text/plain'),
|
||||
'htm' => array('text/html', 'text/plain'),
|
||||
'shtml' => array('text/html', 'text/plain'),
|
||||
'txt' => 'text/plain',
|
||||
'text' => 'text/plain',
|
||||
'log' => array('text/plain', 'text/x-log'),
|
||||
'rtx' => 'text/richtext',
|
||||
'rtf' => 'text/rtf',
|
||||
'xml' => array('application/xml', 'text/xml', 'text/plain'),
|
||||
'xsl' => array('application/xml', 'text/xsl', 'text/xml'),
|
||||
'mpeg' => 'video/mpeg',
|
||||
'mpg' => 'video/mpeg',
|
||||
'mpe' => 'video/mpeg',
|
||||
'qt' => 'video/quicktime',
|
||||
'mov' => 'video/quicktime',
|
||||
'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'),
|
||||
'movie' => 'video/x-sgi-movie',
|
||||
'doc' => array('application/msword', 'application/vnd.ms-office'),
|
||||
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'),
|
||||
'dot' => array('application/msword', 'application/vnd.ms-office'),
|
||||
'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'),
|
||||
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'),
|
||||
'word' => array('application/msword', 'application/octet-stream'),
|
||||
'xl' => 'application/excel',
|
||||
'eml' => 'message/rfc822',
|
||||
'json' => array('application/json', 'text/json'),
|
||||
'pem' => array('application/x-x509-user-cert', 'application/x-pem-file', 'application/octet-stream'),
|
||||
'p10' => array('application/x-pkcs10', 'application/pkcs10'),
|
||||
'p12' => 'application/x-pkcs12',
|
||||
'p7a' => 'application/x-pkcs7-signature',
|
||||
'p7c' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
|
||||
'p7m' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
|
||||
'p7r' => 'application/x-pkcs7-certreqresp',
|
||||
'p7s' => 'application/pkcs7-signature',
|
||||
'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert'),
|
||||
'crl' => array('application/pkix-crl', 'application/pkcs-crl'),
|
||||
'der' => 'application/x-x509-ca-cert',
|
||||
'kdb' => 'application/octet-stream',
|
||||
'pgp' => 'application/pgp',
|
||||
'gpg' => 'application/gpg-keys',
|
||||
'sst' => 'application/octet-stream',
|
||||
'csr' => 'application/octet-stream',
|
||||
'rsa' => 'application/x-pkcs7',
|
||||
'cer' => array('application/pkix-cert', 'application/x-x509-ca-cert'),
|
||||
'3g2' => 'video/3gpp2',
|
||||
'3gp' => array('video/3gp', 'video/3gpp'),
|
||||
'mp4' => 'video/mp4',
|
||||
'm4a' => 'audio/x-m4a',
|
||||
'f4v' => array('video/mp4', 'video/x-f4v'),
|
||||
'flv' => 'video/x-flv',
|
||||
'webm' => 'video/webm',
|
||||
'aac' => 'audio/x-acc',
|
||||
'm4u' => 'application/vnd.mpegurl',
|
||||
'm3u' => 'text/plain',
|
||||
'xspf' => 'application/xspf+xml',
|
||||
'vlc' => 'application/videolan',
|
||||
'wmv' => array('video/x-ms-wmv', 'video/x-ms-asf'),
|
||||
'au' => 'audio/x-au',
|
||||
'ac3' => 'audio/ac3',
|
||||
'flac' => 'audio/x-flac',
|
||||
'ogg' => array('audio/ogg', 'video/ogg', 'application/ogg'),
|
||||
'kmz' => array('application/vnd.google-earth.kmz', 'application/zip', 'application/x-zip'),
|
||||
'kml' => array('application/vnd.google-earth.kml+xml', 'application/xml', 'text/xml'),
|
||||
'ics' => 'text/calendar',
|
||||
'ical' => 'text/calendar',
|
||||
'zsh' => 'text/x-scriptzsh',
|
||||
'7z' => array('application/x-7z-compressed', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'),
|
||||
'7zip' => array('application/x-7z-compressed', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'),
|
||||
'cdr' => array('application/cdr', 'application/coreldraw', 'application/x-cdr', 'application/x-coreldraw', 'image/cdr', 'image/x-cdr', 'zz-application/zz-winassoc-cdr'),
|
||||
'wma' => array('audio/x-ms-wma', 'video/x-ms-asf'),
|
||||
'jar' => array('application/java-archive', 'application/x-java-application', 'application/x-jar', 'application/x-compressed'),
|
||||
'svg' => array('image/svg+xml', 'application/xml', 'text/xml'),
|
||||
'vcf' => 'text/x-vcard',
|
||||
'srt' => array('text/srt', 'text/plain'),
|
||||
'vtt' => array('text/vtt', 'text/plain'),
|
||||
'ico' => array('image/x-icon', 'image/x-ico', 'image/vnd.microsoft.icon'),
|
||||
'odc' => 'application/vnd.oasis.opendocument.chart',
|
||||
'otc' => 'application/vnd.oasis.opendocument.chart-template',
|
||||
'odf' => 'application/vnd.oasis.opendocument.formula',
|
||||
'otf' => 'application/vnd.oasis.opendocument.formula-template',
|
||||
'odg' => 'application/vnd.oasis.opendocument.graphics',
|
||||
'otg' => 'application/vnd.oasis.opendocument.graphics-template',
|
||||
'odi' => 'application/vnd.oasis.opendocument.image',
|
||||
'oti' => 'application/vnd.oasis.opendocument.image-template',
|
||||
'odp' => 'application/vnd.oasis.opendocument.presentation',
|
||||
'otp' => 'application/vnd.oasis.opendocument.presentation-template',
|
||||
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
||||
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
|
||||
'odt' => 'application/vnd.oasis.opendocument.text',
|
||||
'odm' => 'application/vnd.oasis.opendocument.text-master',
|
||||
'ott' => 'application/vnd.oasis.opendocument.text-template',
|
||||
'oth' => 'application/vnd.oasis.opendocument.text-web'
|
||||
);
|
||||
14
application/config/mongo_db.php
Normal file
14
application/config/mongo_db.php
Normal file
@@ -0,0 +1,14 @@
|
||||
$config['mongo_db']['active'] = 'default';
|
||||
$config['mongo_db']['default']['no_auth'] = false;
|
||||
$config['mongo_db']['default']['hostname'] = 'localhost';
|
||||
$config['mongo_db']['default']['port'] = '27017';
|
||||
$config['mongo_db']['default']['username'] = 'one';
|
||||
$config['mongo_db']['default']['password'] = 'sasone102938';
|
||||
$config['mongo_db']['default']['database'] = '';
|
||||
$config['mongo_db']['default']['db_debug'] = TRUE;
|
||||
$config['mongo_db']['default']['return_as'] = 'array';
|
||||
$config['mongo_db']['default']['write_concerns'] = (int)1;
|
||||
$config['mongo_db']['default']['journal'] = TRUE;
|
||||
$config['mongo_db']['default']['read_preference'] = 'primary';
|
||||
$config['mongo_db']['default']['read_concern'] = 'local'; //'local', 'majority' or 'linearizable'
|
||||
$config['mongo_db']['default']['legacy_support'] = TRUE;
|
||||
14
application/config/profiler.php
Executable file
14
application/config/profiler.php
Executable file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Profiler Sections
|
||||
| -------------------------------------------------------------------------
|
||||
| This file lets you determine whether or not various sections of Profiler
|
||||
| data are displayed when the Profiler is enabled.
|
||||
| Please see the user guide for info:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/profiling.html
|
||||
|
|
||||
*/
|
||||
54
application/config/routes.php
Executable file
54
application/config/routes.php
Executable file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| URI ROUTING
|
||||
| -------------------------------------------------------------------------
|
||||
| This file lets you re-map URI requests to specific controller functions.
|
||||
|
|
||||
| Typically there is a one-to-one relationship between a URL string
|
||||
| and its corresponding controller class/method. The segments in a
|
||||
| URL normally follow this pattern:
|
||||
|
|
||||
| example.com/class/method/id/
|
||||
|
|
||||
| In some instances, however, you may want to remap this relationship
|
||||
| so that a different class/function is called than the one
|
||||
| corresponding to the URL.
|
||||
|
|
||||
| Please see the user guide for complete details:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/routing.html
|
||||
|
|
||||
| -------------------------------------------------------------------------
|
||||
| RESERVED ROUTES
|
||||
| -------------------------------------------------------------------------
|
||||
|
|
||||
| There are three reserved routes:
|
||||
|
|
||||
| $route['default_controller'] = 'welcome';
|
||||
|
|
||||
| This route indicates which controller class should be loaded if the
|
||||
| URI contains no data. In the above example, the "welcome" class
|
||||
| would be loaded.
|
||||
|
|
||||
| $route['404_override'] = 'errors/page_missing';
|
||||
|
|
||||
| This route will tell the Router which controller/method to use if those
|
||||
| provided in the URL cannot be matched to a valid route.
|
||||
|
|
||||
| $route['translate_uri_dashes'] = FALSE;
|
||||
|
|
||||
| This is not exactly a route, but allows you to automatically route
|
||||
| controller and method names that contain dashes. '-' isn't a valid
|
||||
| class or method name character, so it requires translation.
|
||||
| When you set this option to TRUE, it will replace ALL dashes in the
|
||||
| controller and method URI segments.
|
||||
|
|
||||
| Examples: my-controller/index -> my_controller/index
|
||||
| my-controller/my-method -> my_controller/my_method
|
||||
*/
|
||||
$route['default_controller'] = 'welcome';
|
||||
$route['404_override'] = '';
|
||||
$route['translate_uri_dashes'] = FALSE;
|
||||
64
application/config/smileys.php
Executable file
64
application/config/smileys.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| SMILEYS
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains an array of smileys for use with the emoticon helper.
|
||||
| Individual images can be used to replace multiple smileys. For example:
|
||||
| :-) and :) use the same image replacement.
|
||||
|
|
||||
| Please see user guide for more info:
|
||||
| https://codeigniter.com/user_guide/helpers/smiley_helper.html
|
||||
|
|
||||
*/
|
||||
$smileys = array(
|
||||
|
||||
// smiley image name width height alt
|
||||
|
||||
':-)' => array('grin.gif', '19', '19', 'grin'),
|
||||
':lol:' => array('lol.gif', '19', '19', 'LOL'),
|
||||
':cheese:' => array('cheese.gif', '19', '19', 'cheese'),
|
||||
':)' => array('smile.gif', '19', '19', 'smile'),
|
||||
';-)' => array('wink.gif', '19', '19', 'wink'),
|
||||
';)' => array('wink.gif', '19', '19', 'wink'),
|
||||
':smirk:' => array('smirk.gif', '19', '19', 'smirk'),
|
||||
':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'),
|
||||
':-S' => array('confused.gif', '19', '19', 'confused'),
|
||||
':wow:' => array('surprise.gif', '19', '19', 'surprised'),
|
||||
':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'),
|
||||
':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'),
|
||||
'%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'),
|
||||
';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'),
|
||||
':P' => array('raspberry.gif', '19', '19', 'raspberry'),
|
||||
':blank:' => array('blank.gif', '19', '19', 'blank stare'),
|
||||
':long:' => array('longface.gif', '19', '19', 'long face'),
|
||||
':ohh:' => array('ohh.gif', '19', '19', 'ohh'),
|
||||
':grrr:' => array('grrr.gif', '19', '19', 'grrr'),
|
||||
':gulp:' => array('gulp.gif', '19', '19', 'gulp'),
|
||||
'8-/' => array('ohoh.gif', '19', '19', 'oh oh'),
|
||||
':down:' => array('downer.gif', '19', '19', 'downer'),
|
||||
':red:' => array('embarrassed.gif', '19', '19', 'red face'),
|
||||
':sick:' => array('sick.gif', '19', '19', 'sick'),
|
||||
':shut:' => array('shuteye.gif', '19', '19', 'shut eye'),
|
||||
':-/' => array('hmm.gif', '19', '19', 'hmmm'),
|
||||
'>:(' => array('mad.gif', '19', '19', 'mad'),
|
||||
':mad:' => array('mad.gif', '19', '19', 'mad'),
|
||||
'>:-(' => array('angry.gif', '19', '19', 'angry'),
|
||||
':angry:' => array('angry.gif', '19', '19', 'angry'),
|
||||
':zip:' => array('zip.gif', '19', '19', 'zipper'),
|
||||
':kiss:' => array('kiss.gif', '19', '19', 'kiss'),
|
||||
':ahhh:' => array('shock.gif', '19', '19', 'shock'),
|
||||
':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'),
|
||||
':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'),
|
||||
':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'),
|
||||
':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'),
|
||||
':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'),
|
||||
':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'),
|
||||
':vampire:' => array('vampire.gif', '19', '19', 'vampire'),
|
||||
':snake:' => array('snake.gif', '19', '19', 'snake'),
|
||||
':exclaim:' => array('exclaim.gif', '19', '19', 'exclaim'),
|
||||
':question:' => array('question.gif', '19', '19', 'question')
|
||||
|
||||
);
|
||||
214
application/config/user_agents.php
Executable file
214
application/config/user_agents.php
Executable file
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| USER AGENT TYPES
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains four arrays of user agent data. It is used by the
|
||||
| User Agent Class to help identify browser, platform, robot, and
|
||||
| mobile device data. The array keys are used to identify the device
|
||||
| and the array values are used to set the actual name of the item.
|
||||
*/
|
||||
$platforms = array(
|
||||
'windows nt 10.0' => 'Windows 10',
|
||||
'windows nt 6.3' => 'Windows 8.1',
|
||||
'windows nt 6.2' => 'Windows 8',
|
||||
'windows nt 6.1' => 'Windows 7',
|
||||
'windows nt 6.0' => 'Windows Vista',
|
||||
'windows nt 5.2' => 'Windows 2003',
|
||||
'windows nt 5.1' => 'Windows XP',
|
||||
'windows nt 5.0' => 'Windows 2000',
|
||||
'windows nt 4.0' => 'Windows NT 4.0',
|
||||
'winnt4.0' => 'Windows NT 4.0',
|
||||
'winnt 4.0' => 'Windows NT',
|
||||
'winnt' => 'Windows NT',
|
||||
'windows 98' => 'Windows 98',
|
||||
'win98' => 'Windows 98',
|
||||
'windows 95' => 'Windows 95',
|
||||
'win95' => 'Windows 95',
|
||||
'windows phone' => 'Windows Phone',
|
||||
'windows' => 'Unknown Windows OS',
|
||||
'android' => 'Android',
|
||||
'blackberry' => 'BlackBerry',
|
||||
'iphone' => 'iOS',
|
||||
'ipad' => 'iOS',
|
||||
'ipod' => 'iOS',
|
||||
'os x' => 'Mac OS X',
|
||||
'ppc mac' => 'Power PC Mac',
|
||||
'freebsd' => 'FreeBSD',
|
||||
'ppc' => 'Macintosh',
|
||||
'linux' => 'Linux',
|
||||
'debian' => 'Debian',
|
||||
'sunos' => 'Sun Solaris',
|
||||
'beos' => 'BeOS',
|
||||
'apachebench' => 'ApacheBench',
|
||||
'aix' => 'AIX',
|
||||
'irix' => 'Irix',
|
||||
'osf' => 'DEC OSF',
|
||||
'hp-ux' => 'HP-UX',
|
||||
'netbsd' => 'NetBSD',
|
||||
'bsdi' => 'BSDi',
|
||||
'openbsd' => 'OpenBSD',
|
||||
'gnu' => 'GNU/Linux',
|
||||
'unix' => 'Unknown Unix OS',
|
||||
'symbian' => 'Symbian OS'
|
||||
);
|
||||
|
||||
|
||||
// The order of this array should NOT be changed. Many browsers return
|
||||
// multiple browser types so we want to identify the sub-type first.
|
||||
$browsers = array(
|
||||
'OPR' => 'Opera',
|
||||
'Flock' => 'Flock',
|
||||
'Edge' => 'Edge',
|
||||
'Chrome' => 'Chrome',
|
||||
// Opera 10+ always reports Opera/9.80 and appends Version/<real version> to the user agent string
|
||||
'Opera.*?Version' => 'Opera',
|
||||
'Opera' => 'Opera',
|
||||
'MSIE' => 'Internet Explorer',
|
||||
'Internet Explorer' => 'Internet Explorer',
|
||||
'Trident.* rv' => 'Internet Explorer',
|
||||
'Shiira' => 'Shiira',
|
||||
'Firefox' => 'Firefox',
|
||||
'Chimera' => 'Chimera',
|
||||
'Phoenix' => 'Phoenix',
|
||||
'Firebird' => 'Firebird',
|
||||
'Camino' => 'Camino',
|
||||
'Netscape' => 'Netscape',
|
||||
'OmniWeb' => 'OmniWeb',
|
||||
'Safari' => 'Safari',
|
||||
'Mozilla' => 'Mozilla',
|
||||
'Konqueror' => 'Konqueror',
|
||||
'icab' => 'iCab',
|
||||
'Lynx' => 'Lynx',
|
||||
'Links' => 'Links',
|
||||
'hotjava' => 'HotJava',
|
||||
'amaya' => 'Amaya',
|
||||
'IBrowse' => 'IBrowse',
|
||||
'Maxthon' => 'Maxthon',
|
||||
'Ubuntu' => 'Ubuntu Web Browser'
|
||||
);
|
||||
|
||||
$mobiles = array(
|
||||
// legacy array, old values commented out
|
||||
'mobileexplorer' => 'Mobile Explorer',
|
||||
// 'openwave' => 'Open Wave',
|
||||
// 'opera mini' => 'Opera Mini',
|
||||
// 'operamini' => 'Opera Mini',
|
||||
// 'elaine' => 'Palm',
|
||||
'palmsource' => 'Palm',
|
||||
// 'digital paths' => 'Palm',
|
||||
// 'avantgo' => 'Avantgo',
|
||||
// 'xiino' => 'Xiino',
|
||||
'palmscape' => 'Palmscape',
|
||||
// 'nokia' => 'Nokia',
|
||||
// 'ericsson' => 'Ericsson',
|
||||
// 'blackberry' => 'BlackBerry',
|
||||
// 'motorola' => 'Motorola'
|
||||
|
||||
// Phones and Manufacturers
|
||||
'motorola' => 'Motorola',
|
||||
'nokia' => 'Nokia',
|
||||
'palm' => 'Palm',
|
||||
'iphone' => 'Apple iPhone',
|
||||
'ipad' => 'iPad',
|
||||
'ipod' => 'Apple iPod Touch',
|
||||
'sony' => 'Sony Ericsson',
|
||||
'ericsson' => 'Sony Ericsson',
|
||||
'blackberry' => 'BlackBerry',
|
||||
'cocoon' => 'O2 Cocoon',
|
||||
'blazer' => 'Treo',
|
||||
'lg' => 'LG',
|
||||
'amoi' => 'Amoi',
|
||||
'xda' => 'XDA',
|
||||
'mda' => 'MDA',
|
||||
'vario' => 'Vario',
|
||||
'htc' => 'HTC',
|
||||
'samsung' => 'Samsung',
|
||||
'sharp' => 'Sharp',
|
||||
'sie-' => 'Siemens',
|
||||
'alcatel' => 'Alcatel',
|
||||
'benq' => 'BenQ',
|
||||
'ipaq' => 'HP iPaq',
|
||||
'mot-' => 'Motorola',
|
||||
'playstation portable' => 'PlayStation Portable',
|
||||
'playstation 3' => 'PlayStation 3',
|
||||
'playstation vita' => 'PlayStation Vita',
|
||||
'hiptop' => 'Danger Hiptop',
|
||||
'nec-' => 'NEC',
|
||||
'panasonic' => 'Panasonic',
|
||||
'philips' => 'Philips',
|
||||
'sagem' => 'Sagem',
|
||||
'sanyo' => 'Sanyo',
|
||||
'spv' => 'SPV',
|
||||
'zte' => 'ZTE',
|
||||
'sendo' => 'Sendo',
|
||||
'nintendo dsi' => 'Nintendo DSi',
|
||||
'nintendo ds' => 'Nintendo DS',
|
||||
'nintendo 3ds' => 'Nintendo 3DS',
|
||||
'wii' => 'Nintendo Wii',
|
||||
'open web' => 'Open Web',
|
||||
'openweb' => 'OpenWeb',
|
||||
|
||||
// Operating Systems
|
||||
'android' => 'Android',
|
||||
'symbian' => 'Symbian',
|
||||
'SymbianOS' => 'SymbianOS',
|
||||
'elaine' => 'Palm',
|
||||
'series60' => 'Symbian S60',
|
||||
'windows ce' => 'Windows CE',
|
||||
|
||||
// Browsers
|
||||
'obigo' => 'Obigo',
|
||||
'netfront' => 'Netfront Browser',
|
||||
'openwave' => 'Openwave Browser',
|
||||
'mobilexplorer' => 'Mobile Explorer',
|
||||
'operamini' => 'Opera Mini',
|
||||
'opera mini' => 'Opera Mini',
|
||||
'opera mobi' => 'Opera Mobile',
|
||||
'fennec' => 'Firefox Mobile',
|
||||
|
||||
// Other
|
||||
'digital paths' => 'Digital Paths',
|
||||
'avantgo' => 'AvantGo',
|
||||
'xiino' => 'Xiino',
|
||||
'novarra' => 'Novarra Transcoder',
|
||||
'vodafone' => 'Vodafone',
|
||||
'docomo' => 'NTT DoCoMo',
|
||||
'o2' => 'O2',
|
||||
|
||||
// Fallback
|
||||
'mobile' => 'Generic Mobile',
|
||||
'wireless' => 'Generic Mobile',
|
||||
'j2me' => 'Generic Mobile',
|
||||
'midp' => 'Generic Mobile',
|
||||
'cldc' => 'Generic Mobile',
|
||||
'up.link' => 'Generic Mobile',
|
||||
'up.browser' => 'Generic Mobile',
|
||||
'smartphone' => 'Generic Mobile',
|
||||
'cellphone' => 'Generic Mobile'
|
||||
);
|
||||
|
||||
// There are hundreds of bots but these are the most common.
|
||||
$robots = array(
|
||||
'googlebot' => 'Googlebot',
|
||||
'msnbot' => 'MSNBot',
|
||||
'baiduspider' => 'Baiduspider',
|
||||
'bingbot' => 'Bing',
|
||||
'slurp' => 'Inktomi Slurp',
|
||||
'yahoo' => 'Yahoo',
|
||||
'ask jeeves' => 'Ask Jeeves',
|
||||
'fastcrawler' => 'FastCrawler',
|
||||
'infoseek' => 'InfoSeek Robot 1.0',
|
||||
'lycos' => 'Lycos',
|
||||
'yandex' => 'YandexBot',
|
||||
'mediapartners-google' => 'MediaPartners Google',
|
||||
'CRAZYWEBCRAWLER' => 'Crazy Webcrawler',
|
||||
'adsbot-google' => 'AdsBot Google',
|
||||
'feedfetcher-google' => 'Feedfetcher Google',
|
||||
'curious george' => 'Curious George',
|
||||
'ia_archiver' => 'Alexa Crawler',
|
||||
'MJ12bot' => 'Majestic-12',
|
||||
'Uptimebot' => 'Uptimebot'
|
||||
);
|
||||
135
application/core/MY_Controller-bkp-autologout.php
Executable file
135
application/core/MY_Controller-bkp-autologout.php
Executable file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
class MY_Controller_bkp_autologout extends CI_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
var $sys_user;
|
||||
var $sys_input;
|
||||
var $isLogin;
|
||||
var $one_salt = '545';
|
||||
var $SECRET_KEY = "--one_api-secret-2019-04-01";
|
||||
|
||||
var $group_lab = "1";
|
||||
var $lang_default_code = "ID";
|
||||
|
||||
public function broadcast($prm)
|
||||
{
|
||||
file_get_contents('http://127.0.0.1:9090/broadcast/' . $prm);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//for preflight
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
|
||||
//for disable cached
|
||||
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: no-cache');
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
global $_SERVER;
|
||||
if (isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "OPTIONS") {
|
||||
exit;
|
||||
}
|
||||
$this->sys_user = array(
|
||||
"isExists" => false,
|
||||
"user" => array(
|
||||
"userName" => "",
|
||||
"userLogin" => "",
|
||||
"userID" => 0
|
||||
)
|
||||
);
|
||||
error_reporting(0);
|
||||
$this->sys_input = json_decode($this->input->raw_input_stream, true);
|
||||
if (! $this->sys_input) {
|
||||
if (count($this->input->post()) > 0) {
|
||||
$this->sys_input = $this->input->post();
|
||||
} else {
|
||||
$this->sys_input = $this->input->get();
|
||||
}
|
||||
}
|
||||
$this->load->library("Jwt");
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (! isset($prm["token"])) {
|
||||
$this->isLogin = false;
|
||||
} else {
|
||||
$user = JWT::decode($prm["token"], $this->SECRET_KEY, true);
|
||||
unset($this->sys_input["token"]);
|
||||
$user = json_decode(json_encode($user), true);
|
||||
if ($user["M_UserID"] > 0) {
|
||||
$this->isLogin = true;
|
||||
}
|
||||
$this->sys_user = $user;
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$query = $this->db_onedev->query("update m_user SET M_UserLastAccess = now() WHERE M_UserID = ?", array($user["M_UserID"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_onedev->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
//update last accessed
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->isLogin = false;
|
||||
}
|
||||
$this->load->database();
|
||||
}
|
||||
public function sys_debug()
|
||||
{
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
public function sys_error_db($message, $db = false)
|
||||
{
|
||||
if (! $db) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $this->db->last_query(),
|
||||
"db_error" => $this->db->error()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $db->last_query(),
|
||||
"db_error" => $db->error()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
public function sys_error($message)
|
||||
{
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message
|
||||
)
|
||||
);
|
||||
}
|
||||
public function sys_ok($data)
|
||||
{
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "OK",
|
||||
"data" => $data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function clean_mysqli_connection($dbc)
|
||||
{
|
||||
while (mysqli_more_results($dbc)) {
|
||||
if (mysqli_next_result($dbc)) {
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
156
application/core/MY_Controller.php
Normal file
156
application/core/MY_Controller.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
class MY_Controller extends CI_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
var $db_inventory;
|
||||
var $db_inventory_log;
|
||||
var $db_bloodbank;
|
||||
var $db_onex;
|
||||
var $sys_user;
|
||||
var $sys_input;
|
||||
var $isLogin;
|
||||
var $one_salt = '545';
|
||||
var $SECRET_KEY = "--one_api-secret-2019-04-01";
|
||||
|
||||
var $group_lab = "1";
|
||||
var $lang_default_code = "ID";
|
||||
|
||||
public function broadcast($prm)
|
||||
{
|
||||
file_get_contents('http://127.0.0.1:9090/broadcast/' . $prm);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Refactor on 2025-02-11 after incident
|
||||
$this->input = new MY_Input();
|
||||
|
||||
//for preflight
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
|
||||
//for disable cached
|
||||
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: no-cache');
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
global $_SERVER;
|
||||
if (isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "OPTIONS") {
|
||||
exit;
|
||||
}
|
||||
$this->sys_user = array(
|
||||
"isExists" => false,
|
||||
"user" => array(
|
||||
"userName" => "",
|
||||
"userLogin" => "",
|
||||
"userID" => 0
|
||||
)
|
||||
);
|
||||
error_reporting(0);
|
||||
// Refactored on 2025-02-11
|
||||
$this->sys_input = json_decode($this->input->raw_input_stream, true);
|
||||
if (! $this->sys_input) {
|
||||
if (count($this->input->post()) > 0) {
|
||||
$this->sys_input = $this->input->post(); //default post(null, true)
|
||||
} else {
|
||||
$this->sys_input = $this->input->get(); //default get(null, true)
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->library("Jwt");
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (! isset($prm["token"])) {
|
||||
$this->isLogin = false;
|
||||
} else {
|
||||
$user = JWT::decode($prm["token"], $this->SECRET_KEY, true);
|
||||
unset($this->sys_input["token"]);
|
||||
$user = json_decode(json_encode($user), true);
|
||||
if ($user["M_UserID"] > 0) {
|
||||
$this->isLogin = true;
|
||||
}
|
||||
$this->sys_user = $user;
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$this->db_inventory = $this->load->database("inventory", true);
|
||||
$this->db_inventory_log = $this->load->database("inventory_log", true);
|
||||
$this->db_bloodbank = $this->load->database("bloodbank", true);
|
||||
$this->db_onex = "one_aditya";
|
||||
$query = $this->db_onedev->query("update m_user SET M_UserLastAccess = now() WHERE M_UserID = ?", array($user["M_UserID"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_onedev->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
//update last accessed
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->isLogin = false;
|
||||
}
|
||||
$this->load->database();
|
||||
}
|
||||
public function sys_debug()
|
||||
{
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
public function sys_error_db($message, $db = false)
|
||||
{
|
||||
if (! $db) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $this->db->last_query(),
|
||||
"db_error" => $this->db->error()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $db->last_query(),
|
||||
"db_error" => $db->error()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
public function sys_error($message)
|
||||
{
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message
|
||||
)
|
||||
);
|
||||
}
|
||||
public function sys_ok($data)
|
||||
{
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "OK",
|
||||
"data" => $data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function clean_mysqli_connection($dbc)
|
||||
{
|
||||
while (mysqli_more_results($dbc)) {
|
||||
if (mysqli_next_result($dbc)) {
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->db_onedev->close();
|
||||
$this->db_inventory->close();
|
||||
$this->db_inventory_log->close();
|
||||
$this->db_bloodbank->close();
|
||||
}
|
||||
}
|
||||
141
application/core/MY_Controller_old.php
Executable file
141
application/core/MY_Controller_old.php
Executable file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
class MY_Controller extends CI_Controller {
|
||||
var $db_onedev;
|
||||
var $db_inventory;
|
||||
var $db_inventory_log;
|
||||
var $db_bloodbank;
|
||||
var $db_onex;
|
||||
var $sys_user;
|
||||
var $sys_input;
|
||||
var $isLogin;
|
||||
var $one_salt = '545';
|
||||
var $SECRET_KEY = "--one_api-secret-2019-04-01";
|
||||
|
||||
var $group_lab = "1";
|
||||
var $lang_default_code = "ID";
|
||||
|
||||
public function broadcast($prm){
|
||||
file_get_contents('http://127.0.0.1:9090/broadcast/' . $prm);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//for preflight
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
|
||||
//for disable cached
|
||||
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: no-cache');
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
global $_SERVER;
|
||||
if ( isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "OPTIONS") {
|
||||
exit;
|
||||
}
|
||||
$this->sys_user = array(
|
||||
"isExists" => false,
|
||||
"user" => array(
|
||||
"userName" => "",
|
||||
"userLogin" => "",
|
||||
"userID" => 0
|
||||
)
|
||||
);
|
||||
error_reporting(0);
|
||||
$this->sys_input = json_decode($this->input->raw_input_stream,true);
|
||||
if (! $this->sys_input ) {
|
||||
if ( count($this->input->post()) > 0 ) {
|
||||
$this->sys_input = $this->input->post();
|
||||
} else {
|
||||
$this->sys_input = $this->input->get();
|
||||
}
|
||||
}
|
||||
$this->load->library("Jwt");
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (! isset($prm["token"])) {
|
||||
$this->isLogin = false;
|
||||
} else {
|
||||
$user = JWT::decode($prm["token"],$this->SECRET_KEY,true);
|
||||
unset($this->sys_input["token"]);
|
||||
$user = json_decode(json_encode($user),true);
|
||||
if ($user["M_UserID"] > 0 ) {
|
||||
$this->isLogin = true;
|
||||
}
|
||||
$this->sys_user = $user;
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$this->db_inventory = $this->load->database("inventory", true);
|
||||
$this->db_inventory_log = $this->load->database("inventory_log", true);
|
||||
$this->db_bloodbank = $this->load->database("bloodbank", true);
|
||||
$this->db_onex = "one_aditya";
|
||||
$query = $this->db_onedev->query("update m_user SET M_UserLastAccess = now() WHERE M_UserID = ?",array($user["M_UserID"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_onedev->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
//update last accessed
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
$this->isLogin = false;
|
||||
}
|
||||
$this->load->database();
|
||||
|
||||
}
|
||||
public function sys_debug() {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
public function sys_error_db($message,$db = false) {
|
||||
if (! $db ) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $this->db->last_query(),
|
||||
"db_error" => $this->db->error()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $db->last_query(),
|
||||
"db_error" => $db->error()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
public function sys_error($message) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message
|
||||
)
|
||||
);
|
||||
}
|
||||
public function sys_ok($data) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "OK",
|
||||
"data" => $data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function clean_mysqli_connection( $dbc )
|
||||
{
|
||||
while( mysqli_more_results($dbc) )
|
||||
{
|
||||
if(mysqli_next_result($dbc))
|
||||
{
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
292
application/core/MY_Input.php
Normal file
292
application/core/MY_Input.php
Normal file
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Enhanced Input Class
|
||||
*
|
||||
* Extends CodeIgniter's native Input class to provide additional XSS and SQL injection protection.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Input
|
||||
*/
|
||||
class MY_Input extends CI_Input
|
||||
{
|
||||
/**
|
||||
* @var CI_Controller CodeIgniter instance
|
||||
*/
|
||||
protected $CI;
|
||||
|
||||
/**
|
||||
* @var array Configuration for input sanitization
|
||||
*/
|
||||
private $config = [
|
||||
'encoding' => 'UTF-8',
|
||||
'html_entities_flags' => ENT_QUOTES,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array SQL injection patterns to detect
|
||||
*/
|
||||
private $sqlInjectionPatterns = [
|
||||
// Previous patterns
|
||||
'/\b(union\s+all|union\s+select|insert\s+into|drop\s+table|exec\s+xp|exec\s+sp)\b/i',
|
||||
'/\b(or\s+\d+=\d+|or\s+\'.*\'=\'.*\'|or\s+[\'"].*[\'"]=[\'"].*[\'"])\b/i',
|
||||
'/(\-\-\s*$|\/\*|\*\/|#\s*$)/',
|
||||
'/\b(concat|char|cast|convert|decode|encode|eval|exec)\s*\(/i',
|
||||
'/\b(xp_cmdshell|xp_regread|sp_password|sp_executesql)\b/i',
|
||||
|
||||
// Enhanced time-based injection patterns
|
||||
'/\b(?:and|or|if)\s*\(?[\s\w]*(?:sleep|delay|benchmark|wait)\s*[\(\s]*\d+[^\w\s]*\)?/i',
|
||||
|
||||
// Enhanced conditional patterns
|
||||
'/\b(?:and|or|if)\s*\([^)]*(?:sleep|delay|benchmark|wait)[^)]*\)/i',
|
||||
|
||||
// Case-insensitive function detection (including spaces and parentheses)
|
||||
'/\b(?:s[\s]*l[\s]*e[\s]*e[\s]*p|d[\s]*e[\s]*l[\s]*a[\s]*y|b[\s]*e[\s]*n[\s]*c[\s]*h[\s]*m[\s]*a[\s]*r[\s]*k)\s*\(/i',
|
||||
|
||||
// Additional patterns for IF statements
|
||||
'/\b(?:if)\s*\(\s*(?:sleep|delay|benchmark|wait)\s*\(\s*\d+\s*\)\s*,\s*\d+\s*,\s*\d+\s*\)/i',
|
||||
|
||||
// Pattern specifically for your case
|
||||
'/\band\s+if\s*\(\s*sleep\s*\(\s*\d+\s*\)\s*,\s*\d+\s*,\s*\d+\s*\)/i',
|
||||
|
||||
// Previous patterns continue
|
||||
'/\b(0x[0-9a-f]+)\b/i',
|
||||
'/(\s+and\s+\d+=\d+|\s+and\s+\'.*\'=\'.*\'|\s+and\s+[\'"].*[\'"]=[\'"].*[\'"])/i'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array Suspicious characters that might indicate SQL injection
|
||||
*/
|
||||
private $suspiciousChars = [
|
||||
';', // Statement terminator
|
||||
'\'', // Single quote
|
||||
'"', // Double quote
|
||||
'`', // Backtick
|
||||
'\\', // Backslash
|
||||
'\x00', // Null byte
|
||||
'\x1a', // Ctrl+Z
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sanitized GET data
|
||||
*
|
||||
* @param string|null $index Index for retrieving the GET data
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($index = null, $xss_clean = true)
|
||||
{
|
||||
return $this->sanitizeInput(
|
||||
parent::get($index, $xss_clean)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sanitized POST data
|
||||
*
|
||||
* @param string|null $index Index for retrieving the POST data
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return mixed
|
||||
*/
|
||||
public function post($index = null, $xss_clean = true)
|
||||
{
|
||||
return $this->sanitizeInput(
|
||||
parent::post($index, $xss_clean)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw input stream
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
// Harusnya override raw_input_stream tapi takut kalau merubah banyak fungsi yang pakai input->raw_input_stream
|
||||
// public function getRawInput()
|
||||
public function raw_input_stream()
|
||||
{
|
||||
$input = file_get_contents('php://input');
|
||||
return $this->sanitizeInput($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize input data
|
||||
*
|
||||
* @param mixed $input Input data to sanitize
|
||||
* @return mixed
|
||||
*/
|
||||
protected function sanitizeInput($input)
|
||||
{
|
||||
if (is_string($input)) {
|
||||
return $this->sanitizeString($input);
|
||||
}
|
||||
|
||||
if (is_array($input)) {
|
||||
return $this->sanitizeArray($input);
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize an array recursively
|
||||
*
|
||||
* @param array $input Array to sanitize
|
||||
* @return array
|
||||
*/
|
||||
protected function sanitizeArray(array $input): array
|
||||
{
|
||||
return array_map(
|
||||
function ($item) {
|
||||
return $this->sanitizeInput($item);
|
||||
},
|
||||
$input
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize a string value
|
||||
*
|
||||
* @param string $input String to sanitize
|
||||
* @return string
|
||||
*/
|
||||
protected function sanitizeString(string $input): string
|
||||
{
|
||||
// Return empty string for null input
|
||||
if ($input === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$clean = trim($input);
|
||||
|
||||
// Check for SQL injection attempts
|
||||
if ($this->containsSQLInjection($clean)) {
|
||||
// log_message('warning', 'Potential SQL injection detected: ' . $clean);
|
||||
return '';
|
||||
}
|
||||
|
||||
// Basic sanitization
|
||||
$clean = filter_var($clean, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
|
||||
|
||||
// Remove null bytes
|
||||
$clean = str_replace(chr(0), '', $clean);
|
||||
|
||||
// Remove control characters
|
||||
$clean = preg_replace('/[\x00-\x1F\x7F]/u', '', $clean);
|
||||
|
||||
// Convert special characters to HTML entities
|
||||
$clean = htmlspecialchars(
|
||||
$clean,
|
||||
$this->config['html_entities_flags'],
|
||||
$this->config['encoding']
|
||||
);
|
||||
|
||||
return $clean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string contains SQL injection attempts
|
||||
*
|
||||
* @param string $input String to check
|
||||
* @return bool
|
||||
*/
|
||||
protected function containsSQLInjection(string $input): bool
|
||||
{
|
||||
// Normalize input for better detection
|
||||
$normalizedInput = $this->normalizeInput($input);
|
||||
|
||||
// Check original and normalized input against patterns
|
||||
foreach ($this->sqlInjectionPatterns as $pattern) {
|
||||
if (preg_match($pattern, $input) || preg_match($pattern, $normalizedInput)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for suspicious characters
|
||||
foreach ($this->suspiciousChars as $char) {
|
||||
if (strpos($input, $char) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Additional check specifically for time-based attacks
|
||||
if ($this->containsTimeBased($normalizedInput)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize input for consistent checking
|
||||
*
|
||||
* @param string $input
|
||||
* @return string
|
||||
*/
|
||||
private function normalizeInput(string $input): string
|
||||
{
|
||||
// Convert to lowercase
|
||||
$normalized = strtolower($input);
|
||||
|
||||
// Remove extra spaces
|
||||
$normalized = preg_replace('/\s+/', ' ', $normalized);
|
||||
|
||||
// Remove url encoding
|
||||
$normalized = urldecode($normalized);
|
||||
|
||||
// Replace common obfuscation patterns
|
||||
$replacements = [
|
||||
'/s[\s]*l[\s]*e[\s]*e[\s]*p/' => 'sleep',
|
||||
'/i[\s]*f/' => 'if',
|
||||
'/a[\s]*n[\s]*d/' => 'and',
|
||||
'/o[\s]*r/' => 'or',
|
||||
'/b[\s]*e[\s]*n[\s]*c[\s]*h[\s]*m[\s]*a[\s]*r[\s]*k/' => 'benchmark',
|
||||
'/w[\s]*a[\s]*i[\s]*t[\s]*f[\s]*o[\s]*r/' => 'waitfor'
|
||||
];
|
||||
|
||||
foreach ($replacements as $pattern => $replacement) {
|
||||
$normalized = preg_replace($pattern, $replacement, $normalized);
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specific check for time-based SQL injection attempts
|
||||
*
|
||||
* @param string $input
|
||||
* @return bool
|
||||
*/
|
||||
private function containsTimeBased(string $input): bool
|
||||
{
|
||||
$timeBased = [
|
||||
// Detect IF(SLEEP()) pattern with variations
|
||||
'/if\s*\(\s*sleep\s*\(\s*\d+\s*\)\s*,\s*\d+\s*,\s*\d+\s*\)/i',
|
||||
|
||||
// Detect AND IF(SLEEP()) pattern
|
||||
'/and\s+if\s*\(\s*sleep\s*\(\s*\d+\s*\)\s*,\s*\d+\s*,\s*\d+\s*\)/i',
|
||||
|
||||
// Additional time-based patterns
|
||||
'/benchmark\s*\(\s*\d+\s*,\s*[^)]+\)/i',
|
||||
'/waitfor\s+delay\s+\'\d+\:\d+\:\d+\'/i',
|
||||
'/pg_sleep\s*\(\s*\d+\s*\)/i'
|
||||
];
|
||||
|
||||
foreach ($timeBased as $pattern) {
|
||||
if (preg_match($pattern, $input)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
11
application/core/index.html
Executable file
11
application/core/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/helpers/index.html
Executable file
11
application/helpers/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
24
application/helpers/uuid_helper.php
Normal file
24
application/helpers/uuid_helper.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* UUID versi 4 (RFC 4122) string 36 karakter: 8-4-4-4-12 hex.
|
||||
* Dipakai untuk FormRiwayatPasienUUID dan tempat lain yang butuh UUID string konsisten.
|
||||
* Hindari vsprintf("%s%s-%s-%s-%s%s%s") tanpa satu %s di grup ke-4 (format salah, grup akhir jadi 16 hex).
|
||||
*/
|
||||
if (!function_exists('lab_uuid_v4')) {
|
||||
function lab_uuid_v4() {
|
||||
$data = random_bytes(16);
|
||||
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
|
||||
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
|
||||
$h = bin2hex($data);
|
||||
return sprintf(
|
||||
'%s-%s-%s-%s-%s',
|
||||
substr($h, 0, 8),
|
||||
substr($h, 8, 4),
|
||||
substr($h, 12, 4),
|
||||
substr($h, 16, 4),
|
||||
substr($h, 20, 12)
|
||||
);
|
||||
}
|
||||
}
|
||||
11
application/hooks/index.html
Executable file
11
application/hooks/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/index.html
Executable file
11
application/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/language/english/index.html
Executable file
11
application/language/english/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/language/index.html
Executable file
11
application/language/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
197
application/libraries/Ai_whisper.php
Normal file
197
application/libraries/Ai_whisper.php
Normal file
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class Ai_whisper
|
||||
{
|
||||
const API_KEY = "a6vizxx0GoH3kDonZLnPD9qDeq8jwZyU";
|
||||
const API_URL = "https://api.deepinfra.com/v1/openai/audio/transcriptions";
|
||||
const OROUTE_API_KEY = "655f74aaeb4c97fc75d7cdfca0ba24ea133f8adf5330e8b924b4e824928502e8"; // Api Key Open Router
|
||||
public $whisperModelName = "openai/whisper-large-v3";
|
||||
public $diarizeModelName = "google/gemini-2.0-flash-001";
|
||||
public $temperatureWhisper = 0;
|
||||
public $temperatureDiarize = 0.7;
|
||||
public $whisperLanguage = "id";
|
||||
|
||||
public function with_diarization($audioPath, $persons)
|
||||
{
|
||||
if (!file_exists($audioPath)) {
|
||||
return ["status" => "ERR", "message" => "Error: File not found."];
|
||||
}
|
||||
|
||||
// Get file extension and appropriate MIME type
|
||||
$extension = strtolower(pathinfo($audioPath, PATHINFO_EXTENSION));
|
||||
$mimeType = $this->getMimeType($extension);
|
||||
|
||||
// Create CURLFile with correct MIME type
|
||||
$curlFile = new CURLFile(
|
||||
$audioPath, // File path
|
||||
$mimeType, // MIME type
|
||||
basename($audioPath) // Filename
|
||||
);
|
||||
|
||||
// Prepare the multipart form data
|
||||
$postFields = [
|
||||
'file' => $curlFile,
|
||||
'model' => $this->whisperModelName,
|
||||
'response_format' => 'verbose_json',
|
||||
'timestamp_granularities' => ['segment'],
|
||||
'language' => $this->whisperLanguage,
|
||||
];
|
||||
|
||||
// Initialize cURL session
|
||||
$ch = curl_init();
|
||||
|
||||
// Set cURL options
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => self::API_URL,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => $postFields,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Authorization: Bearer ' . self::API_KEY,
|
||||
// Don't set Content-Type header - cURL will set it automatically with boundary
|
||||
],
|
||||
CURLOPT_TIMEOUT => 300, // 5 minutes timeout for large files
|
||||
CURLOPT_SSL_VERIFYPEER => true,
|
||||
]);
|
||||
|
||||
// Execute request
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
// Handle cURL errors
|
||||
if ($error) {
|
||||
return ["status" => "ERR", "message" => "cURL Error: " . json_encode($error, true)];
|
||||
}
|
||||
|
||||
// Handle API errors
|
||||
if ($httpCode !== 200) {
|
||||
$errorData = json_decode($response, true);
|
||||
return ["status" => "ERR", "message" => "API Error: " . ($errorData['error'] ?? "Unknown error occurred")];
|
||||
}
|
||||
|
||||
// Decode and return the response
|
||||
$result = json_decode($response, true);
|
||||
return [
|
||||
'status' => 'OK',
|
||||
'data' => $this->processDiarization($result, $persons),
|
||||
];
|
||||
}
|
||||
|
||||
private function getMimeType($extension)
|
||||
{
|
||||
$mimeTypes = [
|
||||
'mp3' => 'audio/mpeg',
|
||||
'wav' => 'audio/wav',
|
||||
'm4a' => 'audio/mp4',
|
||||
'ogg' => 'audio/ogg'
|
||||
];
|
||||
|
||||
return isset($mimeTypes[$extension]) ? $mimeTypes[$extension] : 'audio/mpeg';
|
||||
}
|
||||
|
||||
// * INFO: Sementara begini dulu sampai bisa diarize pakai python
|
||||
private function processDiarization($response, $persons)
|
||||
{
|
||||
$result = [
|
||||
'diarized' => [],
|
||||
'raw' => $response
|
||||
];
|
||||
|
||||
// Create array of speaker IDs based on number of persons
|
||||
$speakers = [];
|
||||
for ($i = 1; $i <= $persons; $i++) {
|
||||
$speakers[] = sprintf("SPEAKER_%02d", $i);
|
||||
}
|
||||
|
||||
// Track current speaker index
|
||||
$currentSpeakerIndex = 0;
|
||||
$speakerCount = count($speakers);
|
||||
|
||||
foreach ($response['segments'] as $segment) {
|
||||
// * 20250224: Maybe digunakan sometime
|
||||
// $diarizedSegment = [
|
||||
// 'who' => $speakers[$currentSpeakerIndex],
|
||||
// 'start' => $segment['start'],
|
||||
// 'end' => $segment['end'],
|
||||
// 'text' => trim($segment['text'])
|
||||
// ];
|
||||
|
||||
$convo = $speakers[$currentSpeakerIndex] . ": " . trim($segment['text']);
|
||||
|
||||
$result['diarized'][] = $convo;
|
||||
// $result['raw'][] = $diarizedSegment;
|
||||
|
||||
$currentSpeakerIndex = ($currentSpeakerIndex + 1) % $speakerCount;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function langChainDiarization($response)
|
||||
{
|
||||
$prompt = "This is a Whisper transcript of a 2-person conversation using Bahasa Indonesia. " .
|
||||
"Identify speakers and segment the dialogue based on context because segmentation from whisper is sometimes wrong. " .
|
||||
"Return the result in JSON format:\n" .
|
||||
"{\n" .
|
||||
"\"text\": \"Full transcription text...\",\n" .
|
||||
"\"diarized\": [\n" .
|
||||
"{\n" .
|
||||
"\"who\": \"Speaker 1 or Speaker 2\",\n" .
|
||||
"\"start\": timestamp,\n" .
|
||||
"\"end\": timestamp,\n" .
|
||||
"\"text\": \"...\"\n" .
|
||||
"}\n" .
|
||||
"]\n" .
|
||||
"}\n" .
|
||||
"Ensure accurate segmentation and speaker attribution.\n" .
|
||||
"The convo:\n\n" .
|
||||
$response['text'];
|
||||
|
||||
$payload = json_encode([
|
||||
"model" => $this->diarizeModelName,
|
||||
"messages" => [
|
||||
[
|
||||
"role" => "system",
|
||||
"content" => "You are a helpful assistant that analyzes conversations and identifies speakers."
|
||||
],
|
||||
[
|
||||
"role" => "user",
|
||||
"content" => $prompt,
|
||||
]
|
||||
],
|
||||
"options" => ["temperature" => $this->temperatureDiarize],
|
||||
"stream" => false
|
||||
]);
|
||||
|
||||
// Initialize cURL
|
||||
$ch = curl_init(self::API_URL);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/json",
|
||||
"Authorization: Bearer " . self::API_KEY
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
|
||||
// Execute request
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return ["status" => "ERR", "message" => curl_error($ch)];
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
$response = strip_tags($response);
|
||||
$responseData = json_decode($response, true);
|
||||
$content = $responseData['choices'][0]['message']['content'];
|
||||
|
||||
if (is_null($responseData) || !isset($content)) {
|
||||
return ["status" => "ERR", "message" => "raw : $response"];
|
||||
}
|
||||
}
|
||||
}
|
||||
230
application/libraries/Autosamplingverif.php
Normal file
230
application/libraries/Autosamplingverif.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
defined("BASEPATH") or exit("No direct script access allowed");
|
||||
class Autosamplingverif
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db_onedev = $CI->load->database("default", true);
|
||||
}
|
||||
|
||||
function clean_mysqli_connection( $dbc )
|
||||
{
|
||||
while( mysqli_more_results($dbc) )
|
||||
{
|
||||
if(mysqli_next_result($dbc))
|
||||
{
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
if( get_class($result) == 'mysqli_stmt' )
|
||||
{
|
||||
mysqli_stmt_free_result($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function doaction($rst_id,$samplingtime,$userid){
|
||||
$sql = "call sp_fo_barcode_generate_again_not_exist(" . $rst_id . ")";
|
||||
$this->db_onedev->query($sql);
|
||||
$this->clean_mysqli_connection($this->db_onedev->conn_id);
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM t_orderheader
|
||||
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
||||
WHERE T_OrderHeaderID = {$rst_id}";
|
||||
//echo $sql;
|
||||
$row_addon = $this->db_onedev->query($sql)->row_array();
|
||||
|
||||
$readytime = date('Y-m-d H:i:s', strtotime($samplingtime));
|
||||
//echo $readytime;
|
||||
$sql = "UPDATE t_ordersample
|
||||
SET
|
||||
T_OrderSampleSampling = 'Y',
|
||||
T_OrderSampleSamplingDate = DATE('{$samplingtime}'),
|
||||
T_OrderSampleSamplingTime = TIME('{$samplingtime}'),
|
||||
T_OrderSampleSamplingUserID = {$userid},
|
||||
T_OrderSampleReceive = 'Y',
|
||||
T_OrderSampleReceiveDate = DATE('{$samplingtime}'),
|
||||
T_OrderSampleReceiveTime = TIME('{$samplingtime}'),
|
||||
T_OrderSampleReadyToProcessDateTime = '{$readytime}',
|
||||
T_OrderSampleVerification = 'Y',
|
||||
T_OrderSampleVerificationDate = CURDATE(),
|
||||
T_OrderSampleVerificationTime = CURTIME(),
|
||||
T_OrderSampleVerificationUserID = {$userid},
|
||||
T_OrderSampleSendHandling = 'Y',
|
||||
T_OrderSampleSendHandlingDate = CURDATE(),
|
||||
T_OrderSampleSendHandlingTime = CURTIME(),
|
||||
T_OrderSampleSendHandlingUserID = {$userid},
|
||||
T_OrderSampleReceiveUserID = {$userid},
|
||||
T_OrderSampleReceiveHandling = 'Y',
|
||||
T_OrderSampleReceiveHandlingDate = CURDATE(),
|
||||
T_OrderSampleReceiveHandlingTime = CURTIME(),
|
||||
T_OrderSampleReceiveHandlingUserID = {$userid}
|
||||
WHERE
|
||||
T_OrderSampleT_OrderHeaderID = {$rst_id}";
|
||||
$upd_ordersample = $this->db_onedev->query($sql);
|
||||
//echo $sql;
|
||||
$sql = "SELECT *
|
||||
FROM t_ordersample
|
||||
JOIN t_barcodelab ON T_OrderSampleT_BarcodeLabID = T_BarcodeLabID AND T_BarcodeLabIsActive = 'Y'
|
||||
JOIN t_sampletype ON T_SampleTypeID = T_OrderSampleT_SampleTypeID
|
||||
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
||||
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID
|
||||
WHERE
|
||||
T_OrderSampleT_OrderHeaderID = {$rst_id} AND
|
||||
T_OrderSampleIsActive = 'Y'";
|
||||
$data_loop = $this->db_onedev->query($sql)->result_array();
|
||||
if ($data_loop) {
|
||||
foreach ($data_loop as $ks => $vs) {
|
||||
$sql = "INSERT INTO t_ordersamplereq(
|
||||
T_OrderSampleReqT_OrderHeaderID,
|
||||
T_OrderSampleReqT_SampleStationID,
|
||||
T_OrderSampleReqT_OrderSampleID,
|
||||
T_OrderSampleReqNat_PositionID,
|
||||
T_OrderSampleReqStatus,
|
||||
T_OrderSampleReqs,
|
||||
T_OrderSampleReqUserID,
|
||||
T_OrderSampleReqCreated
|
||||
)
|
||||
VALUES(
|
||||
{$rst_id},
|
||||
{$vs['T_SampleStationID']},
|
||||
{$vs['T_OrderSampleID']},
|
||||
'2',
|
||||
'Y',
|
||||
'[]',
|
||||
{$userid},
|
||||
NOW()
|
||||
)ON DUPLICATE KEY UPDATE
|
||||
T_OrderSampleReqStatus = 'Y',
|
||||
T_OrderSampleReqs = '[]',
|
||||
T_OrderSampleReqUserID = {$userid}";
|
||||
//echo $sql;
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$sql = "INSERT INTO sample_by_step(
|
||||
SampleByStepM_StatusSampleCode,
|
||||
SampleByStepT_OrderHeaderID,
|
||||
SampleByStepT_BarcodeLabID,
|
||||
SampleByStepRequirementStatus,
|
||||
SampleByStepRequirements,
|
||||
SampleByStepUserID,
|
||||
SampleByStepDateTime
|
||||
)
|
||||
VALUES(
|
||||
'SAMPLING.Sampling.Sampled',
|
||||
{$rst_id},
|
||||
{$vs['T_BarcodeLabID']},
|
||||
'Y',
|
||||
'[]',
|
||||
{$userid},
|
||||
'{$row_addon['T_OrderHeaderAddOnOnlySampleTime']}'
|
||||
)";
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$sql = "INSERT INTO sample_by_step(
|
||||
SampleByStepM_StatusSampleCode,
|
||||
SampleByStepT_OrderHeaderID,
|
||||
SampleByStepT_BarcodeLabID,
|
||||
SampleByStepRequirementStatus,
|
||||
SampleByStepRequirements,
|
||||
SampleByStepUserID,
|
||||
SampleByStepDateTime
|
||||
)
|
||||
VALUES(
|
||||
'SAMPLING.Sampling.Received',
|
||||
{$rst_id},
|
||||
{$vs['T_BarcodeLabID']},
|
||||
'Y',
|
||||
'[]',
|
||||
{$userid},
|
||||
'{$row_addon['T_OrderHeaderAddOnOnlySampleTime']}'
|
||||
)";
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$sql = "INSERT INTO sample_by_step(
|
||||
SampleByStepM_StatusSampleCode,
|
||||
SampleByStepT_OrderHeaderID,
|
||||
SampleByStepT_BarcodeLabID,
|
||||
SampleByStepRequirementStatus,
|
||||
SampleByStepRequirements,
|
||||
SampleByStepUserID,
|
||||
SampleByStepDateTime
|
||||
)
|
||||
VALUES(
|
||||
'SAMPLING.Verification.Verify',
|
||||
{$prm['sample']['T_OrderHeaderID']},
|
||||
{$prm['sample']['T_BarcodeLabID']},
|
||||
'{$prm['sample']['requirement_status']}',
|
||||
'{$requirements}',
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$sql = "INSERT INTO sample_by_step(
|
||||
SampleByStepM_StatusSampleCode,
|
||||
SampleByStepT_OrderHeaderID,
|
||||
SampleByStepT_BarcodeLabID,
|
||||
SampleByStepRequirementStatus,
|
||||
SampleByStepRequirements,
|
||||
SampleByStepUserID,
|
||||
SampleByStepDateTime
|
||||
)
|
||||
VALUES(
|
||||
'SAMPLING.Verification.To.Handling',
|
||||
{$prm['sample']['T_OrderHeaderID']},
|
||||
{$prm['sample']['T_BarcodeLabID']},
|
||||
'{$prm['sample']['requirement_status']}',
|
||||
'{$requirements}',
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$sql = "INSERT INTO sample_by_step(
|
||||
SampleByStepM_StatusSampleCode,
|
||||
SampleByStepT_OrderHeaderID,
|
||||
SampleByStepT_BarcodeLabID,
|
||||
SampleByStepRequirementStatus,
|
||||
SampleByStepRequirements,
|
||||
SampleByStepUserID,
|
||||
SampleByStepDateTime
|
||||
)
|
||||
VALUES(
|
||||
'SAMPLING.Handling.From.Verification',
|
||||
{$prm['sample']['T_OrderHeaderID']},
|
||||
{$prm['sample']['T_BarcodeLabID']},
|
||||
'{$prm['sample']['requirement_status']}',
|
||||
'{$requirements}',
|
||||
{$userid},
|
||||
NOW()
|
||||
)";
|
||||
$this->db_onedev->query($sql);
|
||||
|
||||
$query = " INSERT INTO t_sampling_queue_last_status (
|
||||
T_SamplingQueueLastStatusT_SampleStationID,
|
||||
T_SamplingQueueLastStatusT_OrderHeaderID,
|
||||
T_SamplingQueueLastStatusT_SamplingQueueStatusID,
|
||||
T_SamplingQueueLastStatusUserID)
|
||||
VALUES(
|
||||
{$vs['T_SampleStationID']},
|
||||
{$rst_id},
|
||||
'5',
|
||||
{$userid})
|
||||
ON DUPLICATE KEY UPDATE
|
||||
T_SamplingQueueLastStatusT_SamplingQueueStatusID = 5,
|
||||
T_SamplingQueueLastStatusUserID = {$userid}";
|
||||
//echo $query;
|
||||
$this->db_onedev->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
106
application/libraries/Ciqrcode.php
Normal file
106
application/libraries/Ciqrcode.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP QR Code porting for Codeigniter
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @porting author dwi.setiyadi@gmail.com
|
||||
* @original author http://phpqrcode.sourceforge.net/
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
class Ciqrcode
|
||||
{
|
||||
var $cacheable = true;
|
||||
var $cachedir = 'application/cache/';
|
||||
var $errorlog = 'application/logs/';
|
||||
var $quality = true;
|
||||
var $size = 1024;
|
||||
|
||||
function __construct($config = array()) {
|
||||
// call original library
|
||||
include "qrcode/qrconst.php";
|
||||
include "qrcode/qrtools.php";
|
||||
include "qrcode/qrspec.php";
|
||||
include "qrcode/qrimage.php";
|
||||
include "qrcode/qrinput.php";
|
||||
include "qrcode/qrbitstream.php";
|
||||
include "qrcode/qrsplit.php";
|
||||
include "qrcode/qrrscode.php";
|
||||
include "qrcode/qrmask.php";
|
||||
include "qrcode/qrencode.php";
|
||||
|
||||
$this->initialize($config);
|
||||
}
|
||||
|
||||
public function initialize($config = array()) {
|
||||
$this->cacheable = (isset($config['cacheable'])) ? $config['cacheable'] : $this->cacheable;
|
||||
$this->cachedir = (isset($config['cachedir'])) ? $config['cachedir'] : FCPATH.$this->cachedir;
|
||||
$this->errorlog = (isset($config['errorlog'])) ? $config['errorlog'] : FCPATH.$this->errorlog;
|
||||
$this->quality = (isset($config['quality'])) ? $config['quality'] : $this->quality;
|
||||
$this->size = (isset($config['size'])) ? $config['size'] : $this->size;
|
||||
|
||||
// use cache - more disk reads but less CPU power, masks and format templates are stored there
|
||||
if (!defined('QR_CACHEABLE')) define('QR_CACHEABLE', $this->cacheable);
|
||||
|
||||
// used when QR_CACHEABLE === true
|
||||
if (!defined('QR_CACHE_DIR')) define('QR_CACHE_DIR', $this->cachedir);
|
||||
|
||||
// default error logs dir
|
||||
if (!defined('QR_LOG_DIR')) define('QR_LOG_DIR', $this->errorlog);
|
||||
|
||||
// if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
|
||||
if ($this->quality) {
|
||||
if (!defined('QR_FIND_BEST_MASK')) define('QR_FIND_BEST_MASK', true);
|
||||
} else {
|
||||
if (!defined('QR_FIND_BEST_MASK')) define('QR_FIND_BEST_MASK', false);
|
||||
if (!defined('QR_DEFAULT_MASK')) define('QR_DEFAULT_MASK', $this->quality);
|
||||
}
|
||||
|
||||
// if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
|
||||
if (!defined('QR_FIND_FROM_RANDOM')) define('QR_FIND_FROM_RANDOM', false);
|
||||
|
||||
// maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
|
||||
if (!defined('QR_PNG_MAXIMUM_SIZE')) define('QR_PNG_MAXIMUM_SIZE', $this->size);
|
||||
}
|
||||
|
||||
public function generate($params = array()) {
|
||||
if (isset($params['black'])
|
||||
&& is_array($params['black'])
|
||||
&& count($params['black']) == 3
|
||||
&& array_filter($params['black'], 'is_int') === $params['black']) {
|
||||
QRimage::$black = $params['black'];
|
||||
}
|
||||
|
||||
if (isset($params['white'])
|
||||
&& is_array($params['white'])
|
||||
&& count($params['white']) == 3
|
||||
&& array_filter($params['white'], 'is_int') === $params['white']) {
|
||||
QRimage::$white = $params['white'];
|
||||
}
|
||||
|
||||
$params['data'] = (isset($params['data'])) ? $params['data'] : 'QR Code Library';
|
||||
if (isset($params['savename'])) {
|
||||
$level = 'L';
|
||||
if (isset($params['level']) && in_array($params['level'], array('L','M','Q','H'))) $level = $params['level'];
|
||||
|
||||
$size = 4;
|
||||
if (isset($params['size'])) $size = min(max((int)$params['size'], 1), 10);
|
||||
|
||||
QRcode::png($params['data'], $params['savename'], $level, $size, 2);
|
||||
return $params['savename'];
|
||||
} else {
|
||||
$level = 'L';
|
||||
if (isset($params['level']) && in_array($params['level'], array('L','M','Q','H'))) $level = $params['level'];
|
||||
|
||||
$size = 4;
|
||||
if (isset($params['size'])) $size = min(max((int)$params['size'], 1), 10);
|
||||
|
||||
QRcode::png($params['data'], NULL, $level, $size, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* end of file */
|
||||
3273
application/libraries/Etlfisik.php
Normal file
3273
application/libraries/Etlfisik.php
Normal file
File diff suppressed because it is too large
Load Diff
14
application/libraries/Excel.php
Normal file
14
application/libraries/Excel.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once APPPATH."/third_party/PHPExcel/Classes/PHPExcel.php";
|
||||
require_once APPPATH."/third_party/PHPExcel/Classes/PHPExcel/IOFactory.php";
|
||||
|
||||
class Excel extends PHPExcel {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
638
application/libraries/Generateqrreport.php
Normal file
638
application/libraries/Generateqrreport.php
Normal file
@@ -0,0 +1,638 @@
|
||||
<?php
|
||||
defined("BASEPATH") or exit("No direct script access allowed");
|
||||
|
||||
/*
|
||||
SQL DDL untuk tabel qr_printout:
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `qr_printout` (
|
||||
`QR_PrintOutID` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`QR_PrintOutT_OrderHeaderID` int(11) NOT NULL DEFAULT 0
|
||||
COMMENT 'FK ke t_orderheader',
|
||||
`QR_PrintOutGroup_ResultID` int(11) NOT NULL DEFAULT 0
|
||||
COMMENT 'FK ke m_groupresult (opsional)',
|
||||
`QR_PrintOutT_TestID` int(11) NOT NULL DEFAULT 0
|
||||
COMMENT 'FK ke m_test (opsional)',
|
||||
`QR_PrintOutGroup_ResultName` varchar(250) NOT NULL DEFAULT ''
|
||||
COMMENT 'Label group hasil cetak (snapshot)',
|
||||
`QR_PrintOutUUID` varchar(36) NOT NULL DEFAULT ''
|
||||
COMMENT 'UUID v4 unik per sesi cetak',
|
||||
`QR_PrintOutVerifyURL` varchar(500) NOT NULL DEFAULT ''
|
||||
COMMENT 'URL QR Code & tujuan upload: https://ds.com/files/{uuid}.pdf (Golang upload ke sini, pasien scan QR buka ini)',
|
||||
`QR_PrintOutReportURL` varchar(500) NOT NULL DEFAULT ''
|
||||
COMMENT 'URL sumber PDF di PHP app server (Golang HTTP-fetch dari sini untuk diupload ke dedicated server)',
|
||||
`QR_PrintOutTempFilePath` varchar(500) NOT NULL DEFAULT ''
|
||||
COMMENT 'Path absolut file PDF sementara di PHP server (untuk diambil Golang)',
|
||||
`QR_PrintOutUploadStatus` enum('pending','uploaded','failed','failed_permanent') NOT NULL DEFAULT 'pending'
|
||||
COMMENT 'Status upload: pending|uploaded|failed (retry<3)|failed_permanent (retry>=3)',
|
||||
`QR_PrintOutRetryCount` int(11) NOT NULL DEFAULT 0
|
||||
COMMENT 'Berapa kali sudah dicoba upload, maksimal 3',
|
||||
`QR_PrintOutLastRetryAt` datetime DEFAULT NULL
|
||||
COMMENT 'Waktu percobaan upload terakhir yang gagal',
|
||||
`QR_PrintOutUploadedAt` datetime DEFAULT NULL
|
||||
COMMENT 'Waktu upload PDF ke dedicated server berhasil',
|
||||
`QR_PrintOutCreatedAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
COMMENT 'Waktu token QR dibuat',
|
||||
`QR_PrintOutCreatedByUserID` int(11) NOT NULL DEFAULT 0
|
||||
COMMENT 'UserID yang mencetak laporan',
|
||||
`QR_PrintOutIsActive` tinyint(1) NOT NULL DEFAULT 1
|
||||
COMMENT '1=aktif, 0=dinonaktifkan (mis. hasil direvisi)',
|
||||
PRIMARY KEY (`QR_PrintOutID`),
|
||||
UNIQUE KEY `uq_qr_uuid` (`QR_PrintOutUUID`),
|
||||
KEY `idx_order_header` (`QR_PrintOutT_OrderHeaderID`),
|
||||
KEY `idx_upload_status` (`QR_PrintOutUploadStatus`),
|
||||
KEY `idx_retry` (`QR_PrintOutUploadStatus`, `QR_PrintOutRetryCount`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
||||
COMMENT='Token QR Code untuk verifikasi keaslian laporan hasil laboratorium';
|
||||
*/
|
||||
/**
|
||||
* Generateqrreport Library
|
||||
*
|
||||
* Library untuk generate QR Code pada laporan hasil laboratorium.
|
||||
* QR Code berisi URL langsung ke file PDF di dedicated server.
|
||||
* Saat QR di-scan, browser langsung membuka file PDF tersebut.
|
||||
*
|
||||
* Arsitektur:
|
||||
*
|
||||
* ┌─ PHP App (ini) ──────────────────────────────────────────────┐
|
||||
* │ 1. saveQRPrintout(verifyBaseURL='https://ds.com/files') │
|
||||
* │ → UUID + verifyURL = https://ds.com/files/{uuid}.pdf │
|
||||
* │ verifyURL = URL final PDF = yang di-encode ke QR Code │
|
||||
* │ 2. generateQRImageBase64(verifyURL) → embed QR ke PDF cetak │
|
||||
* │ 3. saveTempPDF() → simpan PDF sementara di /tmp/ │
|
||||
* └──────────────────────────────────────────────────────────────┘
|
||||
* │
|
||||
* ▼
|
||||
* ┌─ Golang Upload Tool ─────────────────────────────────────────┐
|
||||
* │ - Poll PHP API: getPendingUploads() │
|
||||
* │ - Ambil TempFilePath dari row │
|
||||
* │ - Upload PDF ke dedicated server pada path sesuai verifyURL │
|
||||
* │ - Berhasil → callback confirmUpload($uuid) │
|
||||
* │ - Gagal → callback incrementRetry($uuid) │
|
||||
* └──────────────────────────────────────────────────────────────┘
|
||||
*
|
||||
* ┌─ Dedicated Server ───────────────────────────────────────────┐
|
||||
* │ - Serve file PDF statis │
|
||||
* │ - URL: https://ds.com/files/{uuid}.pdf │
|
||||
* │ - Saat QR di-scan → browser langsung buka PDF ini │
|
||||
* └──────────────────────────────────────────────────────────────┘
|
||||
*
|
||||
* Tabel yang digunakan: qr_printout
|
||||
* (lihat: sql/qr_printout_updated.sql untuk DDL lengkap)
|
||||
*/
|
||||
class Generateqrreport
|
||||
{
|
||||
/** @var CI_DB_driver */
|
||||
protected $db_smartone;
|
||||
|
||||
/** @var CI_DB_driver */
|
||||
protected $db_onedev;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$CI = & get_instance();
|
||||
$this->db_smartone = $CI->load->database("default", true);
|
||||
$this->db_onedev = $CI->load->database("default", true);
|
||||
|
||||
$this->_loadQRLib();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// PRIVATE HELPERS
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Load phpqrcode library jika belum di-include.
|
||||
*/
|
||||
private function _loadQRLib()
|
||||
{
|
||||
if (!class_exists('QRcode', false)) {
|
||||
$libPath = APPPATH . 'libraries/qrcode/';
|
||||
if (!defined('QR_CACHEABLE'))
|
||||
define('QR_CACHEABLE', false);
|
||||
if (!defined('QR_CACHE_DIR'))
|
||||
define('QR_CACHE_DIR', APPPATH . 'cache/');
|
||||
if (!defined('QR_LOG_DIR'))
|
||||
define('QR_LOG_DIR', APPPATH . 'logs/');
|
||||
if (!defined('QR_FIND_BEST_MASK'))
|
||||
define('QR_FIND_BEST_MASK', true);
|
||||
if (!defined('QR_FIND_FROM_RANDOM'))
|
||||
define('QR_FIND_FROM_RANDOM', false);
|
||||
if (!defined('QR_PNG_MAXIMUM_SIZE'))
|
||||
define('QR_PNG_MAXIMUM_SIZE', 1024);
|
||||
|
||||
include_once $libPath . 'phpqrcode.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate UUID v4.
|
||||
*
|
||||
* @param bool $withHyphens true → 36 char 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
|
||||
* false → 32 char hex tanpa tanda hubung
|
||||
* @return string
|
||||
*/
|
||||
private function _generateUUID($withHyphens = true)
|
||||
{
|
||||
$data = random_bytes(16);
|
||||
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // version 4
|
||||
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // variant bits
|
||||
|
||||
$uuid = vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
|
||||
return $withHyphens ? $uuid : str_replace('-', '', $uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalisasi UUID: konversi 32-char (tanpa hyphen) ke format 36-char standar.
|
||||
*
|
||||
* @param string $uuid
|
||||
* @return string lowercase 36-char UUID
|
||||
*/
|
||||
private function _normalizeUUID($uuid)
|
||||
{
|
||||
$uuid = trim($uuid);
|
||||
if (strlen($uuid) === 32 && strpos($uuid, '-') === false) {
|
||||
$uuid = substr($uuid, 0, 8) . '-'
|
||||
. substr($uuid, 8, 4) . '-'
|
||||
. substr($uuid, 12, 4) . '-'
|
||||
. substr($uuid, 16, 4) . '-'
|
||||
. substr($uuid, 20);
|
||||
}
|
||||
return strtolower($uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validasi format UUID v4 (8-4-4-4-12).
|
||||
*
|
||||
* @param string $uuid
|
||||
* @return bool
|
||||
*/
|
||||
private function _validateUUIDFormat($uuid)
|
||||
{
|
||||
return (bool)preg_match(
|
||||
'/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/',
|
||||
strtolower($uuid)
|
||||
);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// PUBLIC METHODS — QR TOKEN
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Buat record QR baru di tabel qr_printout.
|
||||
*
|
||||
* verifyURL = URL LANGSUNG ke file PDF di dedicated server.
|
||||
* URL ini yang di-encode ke gambar QR Code.
|
||||
* Golang tool akan upload PDF ke path/URL ini.
|
||||
*
|
||||
* Contoh:
|
||||
* verifyBaseURL = 'https://files.lab.rs.com/reports'
|
||||
* verifyURL = 'https://files.lab.rs.com/reports/{uuid}.pdf'
|
||||
*
|
||||
* @param array $params Wajib:
|
||||
* - orderHeaderID (int) FK ke t_orderheader
|
||||
* - groupResultName (string) Label group, mis: 'HEMATOLOGI'
|
||||
* - verifyBaseURL (string) Base URL folder PDF di dedicated server,
|
||||
* contoh: 'https://files.lab.rs.com/reports'
|
||||
* Hasilnya: {verifyBaseURL}/{uuid}.pdf
|
||||
* Opsional:
|
||||
* - groupResultID (int) default 0
|
||||
* - testID (int) default 0
|
||||
* - createdByUserID (int) default 0
|
||||
* @return array [
|
||||
* 'success' => bool,
|
||||
* 'uuid' => string|null, // 36-char dengan hyphen
|
||||
* 'uuid_short' => string|null, // 32-char tanpa hyphen
|
||||
* 'verifyURL' => string|null, // URL PDF final = yang di-encode ke QR Code
|
||||
* 'qr_printout_id' => int|null,
|
||||
* 'message' => string
|
||||
* ]
|
||||
*/
|
||||
public function saveQRPrintout(array $params)
|
||||
{
|
||||
$required = ['orderHeaderID', 'groupResultName', 'verifyBaseURL', 'QR_PrintOutReportURL'];
|
||||
foreach ($required as $field) {
|
||||
if (empty($params[$field])) {
|
||||
return [
|
||||
'success' => false,
|
||||
'uuid' => null,
|
||||
'uuid_short' => null,
|
||||
'verifyURL' => null,
|
||||
'qr_printout_id' => null,
|
||||
'message' => "Parameter '{$field}' wajib diisi.",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$uuid = $this->_generateUUID(true);
|
||||
$uuidShort = str_replace('-', '', $uuid);
|
||||
|
||||
// verifyURL = URL langsung ke PDF: {base}/{uuid}.pdf
|
||||
// Golang akan upload PDF ke path ini di dedicated server
|
||||
$verifyURL = rtrim($params['verifyBaseURL'], '/') . '/' . str_replace('-', '', $uuid) . '.pdf';
|
||||
|
||||
$data = [
|
||||
'QR_PrintOutT_OrderHeaderID' => (int)$params['orderHeaderID'],
|
||||
'QR_PrintOutGroup_ResultID' => (int)($params['groupResultID'] ?? 0),
|
||||
'QR_PrintOutT_TestID' => (int)($params['testID'] ?? 0),
|
||||
'QR_PrintOutGroup_ResultName' => $params['groupResultName'],
|
||||
'QR_PrintOutUUID' => $uuid,
|
||||
'QR_PrintOutVerifyURL' => $verifyURL, // URL final PDF = yang di-encode ke QR Code
|
||||
'QR_PrintOutReportURL' => $params['QR_PrintOutReportURL'], // URL sumber PDF di PHP server (Golang fetch dari sini)
|
||||
'QR_PrintOutTempFilePath' => '',
|
||||
'QR_PrintOutUploadStatus' => 'pending',
|
||||
'QR_PrintOutRetryCount' => 0,
|
||||
'QR_PrintOutLastRetryAt' => null,
|
||||
'QR_PrintOutUploadedAt' => null,
|
||||
'QR_PrintOutCreatedAt' => date('Y-m-d H:i:s'),
|
||||
'QR_PrintOutCreatedByUserID' => (int)($params['createdByUserID'] ?? 0),
|
||||
'QR_PrintOutIsActive' => 1,
|
||||
];
|
||||
|
||||
$this->db_smartone->insert('qr_printout', $data);
|
||||
|
||||
if ($this->db_smartone->affected_rows() === 0) {
|
||||
return [
|
||||
'success' => false,
|
||||
'uuid' => null,
|
||||
'uuid_short' => null,
|
||||
'verifyURL' => null,
|
||||
'qr_printout_id' => null,
|
||||
'message' => 'Gagal menyimpan data QR Printout ke database.',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'uuid' => $uuid,
|
||||
'uuid_short' => $uuidShort,
|
||||
'verifyURL' => $verifyURL, // ini yang di-encode ke gambar QR Code
|
||||
'qr_printout_id' => $this->db_smartone->insert_id(),
|
||||
'message' => 'OK',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Nonaktifkan QR Code (misal karena hasil direvisi dan QR lama tidak boleh diakses).
|
||||
*
|
||||
* @param string $uuid
|
||||
* @return bool
|
||||
*/
|
||||
public function deactivateQR($uuid)
|
||||
{
|
||||
$uuid = $this->_normalizeUUID($uuid);
|
||||
$this->db_smartone->where('QR_PrintOutUUID', $uuid)
|
||||
->update('qr_printout', ['QR_PrintOutIsActive' => 0]);
|
||||
return $this->db_smartone->affected_rows() > 0;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// PUBLIC METHODS — QR IMAGE
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Generate QR Code sebagai Base64 PNG string.
|
||||
* Hasil bisa langsung di-embed ke HTML/PDF: <img src="{hasil}">
|
||||
*
|
||||
* @param string $url URL yang akan di-encode (verifyURL dari saveQRPrintout)
|
||||
* @param int $pixelSize Ukuran pixel per modul (1–10), default 5
|
||||
* @param string $errorLevel Koreksi error: L, M, Q, H (default H)
|
||||
* @return string "data:image/png;base64,..." atau '' jika gagal
|
||||
*/
|
||||
public function generateQRImageBase64($url, $pixelSize = 5, $errorLevel = 'H')
|
||||
{
|
||||
$errorLevel = in_array($errorLevel, ['L', 'M', 'Q', 'H']) ? $errorLevel : 'H';
|
||||
$pixelSize = min(max((int)$pixelSize, 1), 10);
|
||||
|
||||
ob_start();
|
||||
QRcode::png($url, false, $errorLevel, $pixelSize, 2);
|
||||
$imgData = ob_get_clean();
|
||||
|
||||
return empty($imgData) ? '' : 'data:image/png;base64,' . base64_encode($imgData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate QR Code dan simpan sebagai file PNG di disk.
|
||||
*
|
||||
* @param string $url URL yang akan di-encode
|
||||
* @param string $savePath Path lengkap tujuan, misal: FCPATH.'qrcodes/abc.png'
|
||||
* @param int $pixelSize Ukuran pixel per modul (1–10), default 5
|
||||
* @param string $errorLevel Koreksi error: L, M, Q, H (default H)
|
||||
* @return bool true jika berhasil disimpan
|
||||
*/
|
||||
public function generateQRImageFile($url, $savePath, $pixelSize = 5, $errorLevel = 'H')
|
||||
{
|
||||
$errorLevel = in_array($errorLevel, ['L', 'M', 'Q', 'H']) ? $errorLevel : 'H';
|
||||
$pixelSize = min(max((int)$pixelSize, 1), 10);
|
||||
|
||||
$dir = dirname($savePath);
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
}
|
||||
|
||||
QRcode::png($url, $savePath, $errorLevel, $pixelSize, 2);
|
||||
return file_exists($savePath);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// PUBLIC METHODS — PDF TEMP & GOLANG CALLBACK
|
||||
// =========================================================================
|
||||
|
||||
// =========================================================================
|
||||
// PUBLIC METHODS — GOLANG UPLOAD TOOL SUPPORT
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Ambil daftar record yang BELUM diupload ke dedicated server.
|
||||
* Dipakai oleh Golang upload tool sebagai polling.
|
||||
*
|
||||
* Hanya mengambil record dengan:
|
||||
* - UploadStatus = 'pending' ATAU 'failed' (masih bisa retry)
|
||||
* - RetryCount < 3
|
||||
* - IsActive = 1
|
||||
* - QR_PrintOutReportURL tidak kosong (PDF sudah tersedia di PHP server)
|
||||
*
|
||||
* Field penting untuk Golang dari setiap row:
|
||||
* - QR_PrintOutUUID : identifier
|
||||
* - QR_PrintOutVerifyURL : URL TUJUAN upload di dedicated server
|
||||
* - QR_PrintOutReportURL : URL SUMBER PDF di PHP server (Golang fetch dari sini)
|
||||
* - QR_PrintOutTempFilePath: path lokal file PDF (opsional, jika Golang akses lokal)
|
||||
*
|
||||
* @param int $limit Jumlah maksimal record (default 10)
|
||||
* @return array
|
||||
*/
|
||||
public function getPendingUploads($limit = 10)
|
||||
{
|
||||
return $this->db_smartone
|
||||
->where_in('QR_PrintOutUploadStatus', ['pending', 'failed'])
|
||||
->where('QR_PrintOutRetryCount <', 3)
|
||||
->where('QR_PrintOutIsActive', 1)
|
||||
->where('QR_PrintOutReportURL !=', '') // pastikan PDF sudah siap
|
||||
->order_by('QR_PrintOutCreatedAt', 'ASC')
|
||||
->limit((int)$limit)
|
||||
->get('qr_printout')
|
||||
->result_array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Catat bahwa satu percobaan upload gagal dan tambah retry count.
|
||||
*
|
||||
* - Jika RetryCount setelah increment < 3 → status tetap 'failed' (akan dicoba lagi)
|
||||
* - Jika RetryCount setelah increment >= 3 → status menjadi 'failed_permanent'
|
||||
* (tidak akan diambil oleh getPendingUploads() lagi)
|
||||
*
|
||||
* Dipanggil oleh Golang tool saat upload ke dedicated server gagal.
|
||||
*
|
||||
* @param string $uuid
|
||||
* @return array [
|
||||
* 'success' => bool,
|
||||
* 'retry_count' => int, // retry count setelah increment
|
||||
* 'is_permanent' => bool, // true = sudah melebihi batas, tidak akan di-retry lagi
|
||||
* 'message' => string
|
||||
* ]
|
||||
*/
|
||||
public function incrementRetry($uuid)
|
||||
{
|
||||
$uuid = $this->_normalizeUUID($uuid);
|
||||
|
||||
if (!$this->_validateUUIDFormat($uuid)) {
|
||||
return ['success' => false, 'retry_count' => 0, 'is_permanent' => false,
|
||||
'message' => 'Format UUID tidak valid.'];
|
||||
}
|
||||
|
||||
$qrRow = $this->db_smartone
|
||||
->select('QR_PrintOutRetryCount, QR_PrintOutUploadStatus')
|
||||
->where('QR_PrintOutUUID', $uuid)
|
||||
->get('qr_printout')
|
||||
->row_array();
|
||||
|
||||
if (!$qrRow) {
|
||||
return ['success' => false, 'retry_count' => 0, 'is_permanent' => false,
|
||||
'message' => 'UUID tidak ditemukan.'];
|
||||
}
|
||||
|
||||
$newRetryCount = (int)$qrRow['QR_PrintOutRetryCount'] + 1;
|
||||
$isPermanent = $newRetryCount >= 3;
|
||||
$newStatus = $isPermanent ? 'failed_permanent' : 'failed';
|
||||
|
||||
$this->db_smartone->where('QR_PrintOutUUID', $uuid)
|
||||
->update('qr_printout', [
|
||||
'QR_PrintOutRetryCount' => $newRetryCount,
|
||||
'QR_PrintOutLastRetryAt' => date('Y-m-d H:i:s'),
|
||||
'QR_PrintOutUploadStatus' => $newStatus,
|
||||
]);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'retry_count' => $newRetryCount,
|
||||
'is_permanent' => $isPermanent,
|
||||
'message' => $isPermanent
|
||||
? "Retry count mencapai {$newRetryCount}. Status menjadi 'failed_permanent'. Upload otomatis dihentikan."
|
||||
: "Retry count: {$newRetryCount}/3. Akan dicoba kembali.",
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Minta upload ulang (re-upload) untuk satu record.
|
||||
*
|
||||
* Gunakan fungsi ini ketika:
|
||||
* (a) File PDF di dedicated server sudah dihapus / kadaluarsa, ATAU
|
||||
* (b) Record sebelumnya 'failed_permanent' dan ingin dicoba ulang secara manual
|
||||
*
|
||||
* Fungsi ini akan:
|
||||
* - Reset UploadStatus → 'pending'
|
||||
* - Reset RetryCount → 0
|
||||
* - Kosongkan ReportURL (file lama di dedicated server sudah tidak valid)
|
||||
* - Wajib diikuti dengan saveTempPDF() untuk menyiapkan file PDF baru
|
||||
*
|
||||
* @param string $uuid
|
||||
* @return array ['success' => bool, 'message' => string]
|
||||
*/
|
||||
public function requestReUpload($uuid)
|
||||
{
|
||||
$uuid = $this->_normalizeUUID($uuid);
|
||||
|
||||
if (!$this->_validateUUIDFormat($uuid)) {
|
||||
return ['success' => false, 'message' => 'Format UUID tidak valid.'];
|
||||
}
|
||||
|
||||
$exists = $this->db_smartone
|
||||
->where('QR_PrintOutUUID', $uuid)
|
||||
->count_all_results('qr_printout');
|
||||
|
||||
if ($exists === 0) {
|
||||
return ['success' => false, 'message' => 'UUID tidak ditemukan.'];
|
||||
}
|
||||
|
||||
$this->db_smartone->where('QR_PrintOutUUID', $uuid)
|
||||
->update('qr_printout', [
|
||||
'QR_PrintOutUploadStatus' => 'pending',
|
||||
'QR_PrintOutRetryCount' => 0,
|
||||
'QR_PrintOutLastRetryAt' => null,
|
||||
'QR_PrintOutUploadedAt' => null,
|
||||
'QR_PrintOutTempFilePath' => '', // harus diisi ulang via saveTempPDF()
|
||||
]);
|
||||
|
||||
if ($this->db_smartone->affected_rows() === 0) {
|
||||
return ['success' => false, 'message' => 'Gagal update database.'];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => 'Record di-reset ke pending. Panggil saveTempPDF() untuk menyiapkan PDF baru.',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Konfirmasi bahwa Golang berhasil upload PDF ke dedicated server.
|
||||
*
|
||||
* URL QR_PrintOutVerifyURL tidak berubah (sudah fix sejak saveQRPrintout).
|
||||
* Fungsi ini hanya mengubah status → 'uploaded'.
|
||||
*
|
||||
* Alur Golang:
|
||||
* 1. Poll getPendingUploads() → dapat row dengan:
|
||||
* QR_PrintOutReportURL (fetch PDF dari PHP server via HTTP)
|
||||
* QR_PrintOutVerifyURL (upload PDF ke dedicated server di path ini)
|
||||
* 2. Download PDF dari QR_PrintOutReportURL
|
||||
* 3. Upload ke dedicated server sesuai QR_PrintOutVerifyURL
|
||||
* 4. Callback PHP: confirmUpload($uuid)
|
||||
*
|
||||
* @param string $uuid UUID record qr_printout
|
||||
* @return array ['success' => bool, 'message' => string]
|
||||
*/
|
||||
public function confirmUpload($uuid)
|
||||
{
|
||||
$uuid = $this->_normalizeUUID($uuid);
|
||||
|
||||
if (!$this->_validateUUIDFormat($uuid)) {
|
||||
return ['success' => false, 'message' => 'Format UUID tidak valid.'];
|
||||
}
|
||||
|
||||
$exists = $this->db_smartone
|
||||
->where('QR_PrintOutUUID', $uuid)
|
||||
->count_all_results('qr_printout');
|
||||
|
||||
if ($exists === 0) {
|
||||
return ['success' => false, 'message' => 'UUID tidak ditemukan di database.'];
|
||||
}
|
||||
|
||||
$this->db_smartone->where('QR_PrintOutUUID', $uuid)
|
||||
->update('qr_printout', [
|
||||
'QR_PrintOutUploadStatus' => 'uploaded',
|
||||
'QR_PrintOutUploadedAt' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
if ($this->db_smartone->affected_rows() === 0) {
|
||||
return ['success' => false, 'message' => 'Gagal update database.'];
|
||||
}
|
||||
|
||||
return ['success' => true, 'message' => 'OK'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tandai upload gagal permanen tanpa menambah retry count.
|
||||
* Gunakan ini hanya untuk override manual (mis. admin force-fail).
|
||||
* Untuk kasus normal, gunakan incrementRetry() agar retry count terlacak.
|
||||
*
|
||||
* @param string $uuid
|
||||
* @return bool
|
||||
*/
|
||||
public function markUploadFailed($uuid)
|
||||
{
|
||||
$uuid = $this->_normalizeUUID($uuid);
|
||||
$this->db_smartone->where('QR_PrintOutUUID', $uuid)
|
||||
->update('qr_printout', [
|
||||
'QR_PrintOutUploadStatus' => 'failed_permanent',
|
||||
'QR_PrintOutRetryCount' => 3,
|
||||
]);
|
||||
return $this->db_smartone->affected_rows() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset URL report (untuk upload ulang jika laporan direvisi).
|
||||
* @deprecated Gunakan requestReUpload() yang lebih lengkap.
|
||||
*
|
||||
* @param string $uuid
|
||||
* @return array ['success' => bool, 'message' => string]
|
||||
*/
|
||||
public function resetReportURL($uuid)
|
||||
{
|
||||
return $this->requestReUpload($uuid);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// PUBLIC METHODS — VERIFIKASI (dipakai dedicated server / controller publik)
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Ambil URL PDF report berdasarkan UUID.
|
||||
*
|
||||
* Dipakai jika PHP app perlu tahu URL PDF (mis. untuk redirect).
|
||||
* Scan tracking dihandle oleh dedicated server.
|
||||
*
|
||||
* @param string $uuid UUID (36 atau 32 char)
|
||||
* @return array [
|
||||
* 'success' => bool,
|
||||
* 'report_url' => string|null,
|
||||
* 'qr_info' => array|null,
|
||||
* 'message' => string
|
||||
* ]
|
||||
*/
|
||||
public function getReportURL($uuid)
|
||||
{
|
||||
$uuid = $this->_normalizeUUID($uuid);
|
||||
|
||||
if (!$this->_validateUUIDFormat($uuid)) {
|
||||
return ['success' => false, 'report_url' => null, 'qr_info' => null,
|
||||
'message' => 'Format UUID tidak valid.'];
|
||||
}
|
||||
|
||||
$qrRow = $this->db_smartone
|
||||
->where('QR_PrintOutUUID', $uuid)
|
||||
->where('QR_PrintOutIsActive', 1)
|
||||
->get('qr_printout')
|
||||
->row_array();
|
||||
|
||||
if (!$qrRow) {
|
||||
return ['success' => false, 'report_url' => null, 'qr_info' => null,
|
||||
'message' => 'QR Code tidak ditemukan atau sudah tidak aktif.'];
|
||||
}
|
||||
|
||||
// verifyURL = URL langsung ke PDF, hanya valid jika sudah ter-upload
|
||||
if ($qrRow['QR_PrintOutUploadStatus'] !== 'uploaded') {
|
||||
$status = $qrRow['QR_PrintOutUploadStatus'];
|
||||
$msg = $status === 'failed_permanent'
|
||||
? 'Upload PDF gagal permanen. Hubungi admin laboratorium.'
|
||||
: 'Report PDF sedang diproses. Coba beberapa saat lagi.';
|
||||
return ['success' => false, 'report_url' => null, 'qr_info' => $qrRow, 'message' => $msg];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'report_url' => $qrRow['QR_PrintOutVerifyURL'], // URL langsung ke PDF
|
||||
'qr_info' => $qrRow,
|
||||
'message' => 'OK',
|
||||
];
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// LEGACY / UTILITY
|
||||
// =========================================================================
|
||||
|
||||
function clean_mysqli_connection($dbc)
|
||||
{
|
||||
while (mysqli_more_results($dbc)) {
|
||||
if (mysqli_next_result($dbc)) {
|
||||
$result = mysqli_use_result($dbc);
|
||||
if (get_class($result) == 'mysqli_stmt') {
|
||||
mysqli_stmt_free_result($result);
|
||||
}
|
||||
else {
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3250
application/libraries/Genkelainan.php
Normal file
3250
application/libraries/Genkelainan.php
Normal file
File diff suppressed because it is too large
Load Diff
1050
application/libraries/Genreportfisik.php
Normal file
1050
application/libraries/Genreportfisik.php
Normal file
File diff suppressed because it is too large
Load Diff
3967
application/libraries/Genresultfisik.php
Normal file
3967
application/libraries/Genresultfisik.php
Normal file
File diff suppressed because it is too large
Load Diff
279
application/libraries/ImageManipulator.php
Executable file
279
application/libraries/ImageManipulator.php
Executable file
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
class ImageManipulator
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* Image manipulator constructor
|
||||
*
|
||||
* @param string $file OPTIONAL Path to image file or image data as string
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($file = null)
|
||||
{
|
||||
if (null !== $file) {
|
||||
if (is_file($file)) {
|
||||
$this->setImageFile($file);
|
||||
} else {
|
||||
$this->setImageString($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image resource from file
|
||||
*
|
||||
* @param string $file Path to image file
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setImageFile($file)
|
||||
{
|
||||
if (!(is_readable($file) && is_file($file))) {
|
||||
throw new InvalidArgumentException("Image file $file is not readable");
|
||||
}
|
||||
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
|
||||
list ($this->width, $this->height, $type) = getimagesize($file);
|
||||
|
||||
switch ($type) {
|
||||
case IMAGETYPE_GIF :
|
||||
$this->image = imagecreatefromgif($file);
|
||||
break;
|
||||
case IMAGETYPE_JPEG :
|
||||
$this->image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case IMAGETYPE_PNG :
|
||||
$this->image = imagecreatefrompng($file);
|
||||
break;
|
||||
default :
|
||||
throw new InvalidArgumentException("Image type $type not supported");
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image resource from string data
|
||||
*
|
||||
* @param string $data
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function setImageString($data)
|
||||
{
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
|
||||
if (!$this->image = imagecreatefromstring($data)) {
|
||||
throw new RuntimeException('Cannot create image from data string');
|
||||
}
|
||||
$this->width = imagesx($this->image);
|
||||
$this->height = imagesy($this->image);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resamples the current image
|
||||
*
|
||||
* @param int $width New width
|
||||
* @param int $height New height
|
||||
* @param bool $constrainProportions Constrain current image proportions when resizing
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function resample($width, $height, $constrainProportions = true)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
if ($constrainProportions) {
|
||||
if ($this->height >= $this->width) {
|
||||
$width = round($height / $this->height * $this->width);
|
||||
} else {
|
||||
$height = round($width / $this->width * $this->height);
|
||||
}
|
||||
}
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
imagecopyresampled($temp, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlarge canvas
|
||||
*
|
||||
* @param int $width Canvas width
|
||||
* @param int $height Canvas height
|
||||
* @param array $rgb RGB colour values
|
||||
* @param int $xpos X-Position of image in new canvas, null for centre
|
||||
* @param int $ypos Y-Position of image in new canvas, null for centre
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function enlargeCanvas($width, $height, array $rgb = array(), $xpos = null, $ypos = null)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
|
||||
$width = max($width, $this->width);
|
||||
$height = max($height, $this->height);
|
||||
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
if (count($rgb) == 3) {
|
||||
$bg = imagecolorallocate($temp, $rgb[0], $rgb[1], $rgb[2]);
|
||||
imagefill($temp, 0, 0, $bg);
|
||||
}
|
||||
|
||||
if (null === $xpos) {
|
||||
$xpos = round(($width - $this->width) / 2);
|
||||
}
|
||||
if (null === $ypos) {
|
||||
$ypos = round(($height - $this->height) / 2);
|
||||
}
|
||||
|
||||
imagecopy($temp, $this->image, (int) $xpos, (int) $ypos, 0, 0, $this->width, $this->height);
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crop image
|
||||
*
|
||||
* @param int|array $x1 Top left x-coordinate of crop box or array of coordinates
|
||||
* @param int $y1 Top left y-coordinate of crop box
|
||||
* @param int $x2 Bottom right x-coordinate of crop box
|
||||
* @param int $y2 Bottom right y-coordinate of crop box
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function crop($x1, $y1 = 0, $x2 = 0, $y2 = 0)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
if (is_array($x1) && 4 == count($x1)) {
|
||||
list($x1, $y1, $x2, $y2) = $x1;
|
||||
}
|
||||
|
||||
$x1 = max($x1, 0);
|
||||
$y1 = max($y1, 0);
|
||||
|
||||
$x2 = min($x2, $this->width);
|
||||
$y2 = min($y2, $this->height);
|
||||
|
||||
$width = $x2 - $x1;
|
||||
$height = $y2 - $y1;
|
||||
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
imagecopy($temp, $this->image, 0, 0, $x1, $y1, $width, $height);
|
||||
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace current image resource with a new one
|
||||
*
|
||||
* @param resource $res New image resource
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
protected function _replace($res)
|
||||
{
|
||||
if (!is_resource($res)) {
|
||||
throw new UnexpectedValueException('Invalid resource');
|
||||
}
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
$this->image = $res;
|
||||
$this->width = imagesx($res);
|
||||
$this->height = imagesy($res);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save current image to file
|
||||
*
|
||||
* @param string $fileName
|
||||
* @return void
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function save($fileName, $type = IMAGETYPE_JPEG)
|
||||
{
|
||||
$dir = dirname($fileName);
|
||||
if (!is_dir($dir)) {
|
||||
if (!mkdir($dir, 0755, true)) {
|
||||
throw new RuntimeException('Error creating directory ' . $dir);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
switch ($type) {
|
||||
case IMAGETYPE_GIF :
|
||||
if (!imagegif($this->image, $fileName)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
break;
|
||||
case IMAGETYPE_PNG :
|
||||
if (!imagepng($this->image, $fileName)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
break;
|
||||
case IMAGETYPE_JPEG :
|
||||
default :
|
||||
if (!imagejpeg($this->image, $fileName, 95)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
throw new RuntimeException('Error saving image file to ' . $fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GD image resource
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current image resource width
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current image height
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
}
|
||||
196
application/libraries/Jwt.php
Executable file
196
application/libraries/Jwt.php
Executable file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* JSON Web Token implementation, based on this spec:
|
||||
* http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Authentication
|
||||
* @package Authentication_JWT
|
||||
* @author Neuman Vong <neuman@twilio.com>
|
||||
* @author Anant Narayanan <anant@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
|
||||
* @link https://github.com/firebase/php-jwt
|
||||
*/
|
||||
class JWT
|
||||
{
|
||||
/**
|
||||
* Decodes a JWT string into a PHP object.
|
||||
*
|
||||
* @param string $jwt The JWT
|
||||
* @param string|null $key The secret key
|
||||
* @param bool $verify Don't skip verification process
|
||||
*
|
||||
* @return object The JWT's payload as a PHP object
|
||||
* @throws UnexpectedValueException Provided JWT was invalid
|
||||
* @throws DomainException Algorithm was not provided
|
||||
*
|
||||
* @uses jsonDecode
|
||||
* @uses urlsafeB64Decode
|
||||
*/
|
||||
public static function decode($jwt, $key = null, $verify = true)
|
||||
{
|
||||
$tks = explode('.', $jwt);
|
||||
if (count($tks) != 3) {
|
||||
throw new UnexpectedValueException('Wrong number of segments');
|
||||
}
|
||||
list($headb64, $bodyb64, $cryptob64) = $tks;
|
||||
if (null === ($header = JWT::jsonDecode(JWT::urlsafeB64Decode($headb64)))) {
|
||||
throw new UnexpectedValueException('Invalid segment encoding');
|
||||
}
|
||||
if (null === $payload = JWT::jsonDecode(JWT::urlsafeB64Decode($bodyb64))) {
|
||||
throw new UnexpectedValueException('Invalid segment encoding');
|
||||
}
|
||||
$sig = JWT::urlsafeB64Decode($cryptob64);
|
||||
if ($verify) {
|
||||
if (empty($header->alg)) {
|
||||
throw new DomainException('Empty algorithm');
|
||||
}
|
||||
if ($sig != JWT::sign("$headb64.$bodyb64", $key, $header->alg)) {
|
||||
throw new UnexpectedValueException('Signature verification failed');
|
||||
}
|
||||
}
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts and signs a PHP object or array into a JWT string.
|
||||
*
|
||||
* @param object|array $payload PHP object or array
|
||||
* @param string $key The secret key
|
||||
* @param string $algo The signing algorithm. Supported
|
||||
* algorithms are 'HS256', 'HS384' and 'HS512'
|
||||
*
|
||||
* @return string A signed JWT
|
||||
* @uses jsonEncode
|
||||
* @uses urlsafeB64Encode
|
||||
*/
|
||||
public static function encode($payload, $key, $algo = 'HS256')
|
||||
{
|
||||
$header = array('typ' => 'JWT', 'alg' => $algo);
|
||||
|
||||
$segments = array();
|
||||
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
|
||||
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
|
||||
$signing_input = implode('.', $segments);
|
||||
|
||||
$signature = JWT::sign($signing_input, $key, $algo);
|
||||
$segments[] = JWT::urlsafeB64Encode($signature);
|
||||
|
||||
return implode('.', $segments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign a string with a given key and algorithm.
|
||||
*
|
||||
* @param string $msg The message to sign
|
||||
* @param string $key The secret key
|
||||
* @param string $method The signing algorithm. Supported
|
||||
* algorithms are 'HS256', 'HS384' and 'HS512'
|
||||
*
|
||||
* @return string An encrypted message
|
||||
* @throws DomainException Unsupported algorithm was specified
|
||||
*/
|
||||
public static function sign($msg, $key, $method = 'HS256')
|
||||
{
|
||||
$methods = array(
|
||||
'HS256' => 'sha256',
|
||||
'HS384' => 'sha384',
|
||||
'HS512' => 'sha512',
|
||||
);
|
||||
if (empty($methods[$method])) {
|
||||
throw new DomainException('Algorithm not supported');
|
||||
}
|
||||
return hash_hmac($methods[$method], $msg, $key, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a JSON string into a PHP object.
|
||||
*
|
||||
* @param string $input JSON string
|
||||
*
|
||||
* @return object Object representation of JSON string
|
||||
* @throws DomainException Provided string was invalid JSON
|
||||
*/
|
||||
public static function jsonDecode($input)
|
||||
{
|
||||
$obj = json_decode($input);
|
||||
if (function_exists('json_last_error') && $errno = json_last_error()) {
|
||||
JWT::_handleJsonError($errno);
|
||||
} else if ($obj === null && $input !== 'null') {
|
||||
throw new DomainException('Null result with non-null input');
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a PHP object into a JSON string.
|
||||
*
|
||||
* @param object|array $input A PHP object or array
|
||||
*
|
||||
* @return string JSON representation of the PHP object or array
|
||||
* @throws DomainException Provided object could not be encoded to valid JSON
|
||||
*/
|
||||
public static function jsonEncode($input)
|
||||
{
|
||||
$json = json_encode($input);
|
||||
if (function_exists('json_last_error') && $errno = json_last_error()) {
|
||||
JWT::_handleJsonError($errno);
|
||||
} else if ($json === 'null' && $input !== null) {
|
||||
throw new DomainException('Null result with non-null input');
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a string with URL-safe Base64.
|
||||
*
|
||||
* @param string $input A Base64 encoded string
|
||||
*
|
||||
* @return string A decoded string
|
||||
*/
|
||||
public static function urlsafeB64Decode($input)
|
||||
{
|
||||
$remainder = strlen($input) % 4;
|
||||
if ($remainder) {
|
||||
$padlen = 4 - $remainder;
|
||||
$input .= str_repeat('=', $padlen);
|
||||
}
|
||||
return base64_decode(strtr($input, '-_', '+/'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a string with URL-safe Base64.
|
||||
*
|
||||
* @param string $input The string you want encoded
|
||||
*
|
||||
* @return string The base64 encode of what you passed in
|
||||
*/
|
||||
public static function urlsafeB64Encode($input)
|
||||
{
|
||||
return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a JSON error.
|
||||
*
|
||||
* @param int $errno An error number from json_last_error()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function _handleJsonError($errno)
|
||||
{
|
||||
$messages = array(
|
||||
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
|
||||
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
|
||||
JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON'
|
||||
);
|
||||
throw new DomainException(
|
||||
isset($messages[$errno])
|
||||
? $messages[$errno]
|
||||
: 'Unknown JSON error: ' . $errno
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
162
application/libraries/Kapus.php
Normal file
162
application/libraries/Kapus.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class Kapus{
|
||||
|
||||
public function calc($date,$userID = 3)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
//cek if current date is posted
|
||||
$this->db->trans_start();
|
||||
$sql = "select * from sys_f_kapus_sum where sysFKapusSumDate = ?
|
||||
and sysFKapusIsActive = 'Y' ";
|
||||
$qry = $this->db->query($sql , array($date));
|
||||
$sysFKapusSumID = 0;
|
||||
if ($qry ) {
|
||||
$rows = $qry->result_array();
|
||||
if ( count($rows) > 0 ) {
|
||||
$sysFKapusSumID = $rows[0]["sysFKapusSumID"];
|
||||
if ($rows[0]["sysFKapusSumIsPosted"] == "Y" ) {
|
||||
return array("status" => "ERR" , "message" => "Kapus at $date already posted");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = "select * from sys_kapus limit 0,1";
|
||||
$qry = $this->db->query($sql);
|
||||
if (! $qry ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "ERR" , "message" => "Invalid Kapus Setting" . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "ERR" , "message" => "Invalid Kapus Setting");
|
||||
}
|
||||
$companyID = $rows[0]["sysKaPusM_CompanyID"] . "," . $rows[0]["sysKaPusM_CompanyID2"];
|
||||
$paymentTypeID = $rows[0]["sysKaPusM_PaymentTypeID"];
|
||||
$targetPct = $rows[0]["sysKaPusPct"];
|
||||
// get kapus
|
||||
$sql = "select sum(F_PaymentDetailAmount) TotalAmount,
|
||||
sum(F_PaymentDetailAmount - F_PaymentDetailAmount mod 500 ) TotalAmountAfterRounding
|
||||
from t_orderheader
|
||||
join f_payment on T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
||||
and F_PaymentIsActive = 'Y' and T_OrderHeaderIsActive = 'Y'
|
||||
and date(T_OrderHeaderDate) = date(?)
|
||||
and F_PaymentDate = date(?)
|
||||
join f_paymentdetail on F_PaymentID = F_PaymentDetailF_PaymentID
|
||||
and F_PaymentDetailM_PaymentTypeID = ?
|
||||
and F_PaymentDetailIsActive = 'Y' ";
|
||||
$qry = $this->db->query($sql, array($date,$date, $paymentTypeID));
|
||||
if (! $qry ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "ERR" , "message" => "Error get total payment " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "OK" , "message" => "No Payment Type , $paymentTypeID , $date ");
|
||||
}
|
||||
// seluruh kas
|
||||
$totalAmount = $rows[0]["TotalAmount"];
|
||||
$totalAmountAfterRounding = $rows[0]["TotalAmountAfterRounding"];
|
||||
if ($totalAmount == 0 ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "OK" , "message" => "Total Amount Zero ");
|
||||
}
|
||||
|
||||
$sql = "drop table if exists xtmp_kapus";
|
||||
$qry = $this->db->query($sql);
|
||||
if (! $qry ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "ERR" , "message" => "Drop Tmp table " . print_r($this->db->error(),true));
|
||||
}
|
||||
$sql = "
|
||||
create temporary table xtmp_kapus
|
||||
select F_PaymentT_OrderHeaderID,
|
||||
cast(sum(F_PaymentDetailAmount) as decimal(15,0)) Total
|
||||
from f_payment
|
||||
join t_orderheader on F_PaymentT_OrderHeaderID = T_OrderHeaderID and T_OrderHeaderM_CompanyID in ($companyID)
|
||||
join f_paymentdetail on F_PaymentDetailF_PaymentID = F_PaymentID and F_PaymentDetailIsActive = 'Y'
|
||||
and F_PaymentIsActive = 'Y'
|
||||
where F_PaymentDate = ? and F_PaymentDetailM_PaymentTypeID = ?
|
||||
group by F_PaymentT_OrderHeaderID";
|
||||
$qry = $this->db->query($sql, array($date,$paymentTypeID));
|
||||
if (! $qry ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "ERR" , "message" => "Create Tmp table " . print_r($this->db->error(),true));
|
||||
}
|
||||
|
||||
$sql = "
|
||||
select T_OrderHeaderID,
|
||||
cast(T_OrderHeaderTotal as decimal(15,0) ) as T_OrderHeaderTotal ,
|
||||
cast(T_OrderHeaderTotal - T_OrderHeaderTotal mod 500 as decimal(15,0) ) as T_OrderHeaderTotalAfterRounding
|
||||
from t_orderheader
|
||||
join xtmp_kapus on T_OrderHeaderID = F_PaymentT_OrderHeaderID
|
||||
and Total = T_OrderHeaderTotal
|
||||
and date(T_OrderHeaderDate) = ?
|
||||
order by T_OrderHeaderID";
|
||||
$qry = $this->db->query($sql, array($date));
|
||||
if (! $qry ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "ERR" , "message" => "Error get detail payment " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
if ($sysFKapusSumID == 0) {
|
||||
$sql = "insert into sys_f_kapus_sum(sysFKapusSumDate, sysFKapusSumUserID,sysFKapusSumTargetPct,
|
||||
sysFKapusSumTotal, sysFKapusSumTotalAfterRounding) values(?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql,array($date, $userID, $targetPct, $totalAmount, $totalAmountAfterRounding));
|
||||
if (! $qry ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "ERR" , "message" => "Error create sysFKapusSum " . print_r($this->db->error(),true));
|
||||
}
|
||||
$sysFKapusSumID = $this->db->insert_id();
|
||||
}
|
||||
$qry = $this->db->query("update sys_f_kapus set sysFKapusIsActive='N' where sysFKapusSysFKapusSumID=?", array($sysFKapusSumID));
|
||||
if (! $qry ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "ERR" , "message" => "Error reset sysFKapus " . print_r($this->db->error(),true));
|
||||
}
|
||||
|
||||
$sql_i = "insert into sys_f_kapus( sysFKapusT_OrderHeaderID, sysFKapusAmount, sysFKapusRunAmount,
|
||||
sysFKapusAmountAfterRounding,
|
||||
sysFKapusM_UserID, sysFKapusDate, sysFKapusPct, sysFKapusSysFKapusSumID )
|
||||
values(?,?,?, ?, ?,?,?,?)";
|
||||
$curPct = 0;
|
||||
$sum_total = 0;
|
||||
$sum_total_after_rounding = 0;
|
||||
foreach($rows as $r) {
|
||||
$x_id = $r["T_OrderHeaderID"];
|
||||
$x_total = $r["T_OrderHeaderTotal"];
|
||||
$x_total_after_rounding = $r["T_OrderHeaderTotalAfterRounding"];
|
||||
$sum_total += $x_total;
|
||||
$sum_total_after_rounding += $x_total_after_rounding;
|
||||
$curPct = $sum_total / $totalAmount * 100 ;
|
||||
$qry = $this->db->query($sql_i, array($x_id, $x_total, $sum_total,
|
||||
$x_total_after_rounding,
|
||||
$userID,$date, $curPct,$sysFKapusSumID ) );
|
||||
if (! $qry ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "ERR" , "message" => "Error insert sys_f_kapus " . print_r($this->db->error(),true));
|
||||
}
|
||||
if ($curPct >= $targetPct ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$sql = "update sys_f_kapus_sum set sysFKapusSumAmount = ? , sysFKapusSumActualPct = ? ,
|
||||
sysFKapusSumTargetPct = ?, sysFKapusSumAmountAfterRounding = ?
|
||||
where sysFKapusSumID = ?";
|
||||
$qry = $this->db->query($sql, array($sum_total, $curPct, $targetPct, $sum_total_after_rounding, $sysFKapusSumID));
|
||||
if (! $qry ) {
|
||||
$this->db->trans_rollback();
|
||||
return array("status" => "ERR" , "message" => "Error update sysFKapusSum " . print_r($this->db->error(),true));
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
return array("status" => "OK" , "message" => "");
|
||||
}
|
||||
|
||||
}
|
||||
282
application/libraries/KelainanLab.php
Normal file
282
application/libraries/KelainanLab.php
Normal file
@@ -0,0 +1,282 @@
|
||||
<?php
|
||||
defined("BASEPATH") or exit("No direct script access allowed");
|
||||
class KelainanLab
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db_onedev = $CI->load->database("default", true);
|
||||
$this->db_smartone = $CI->load->database("default", true);
|
||||
}
|
||||
|
||||
function clean_mysqli_connection($dbc)
|
||||
{
|
||||
while (mysqli_more_results($dbc)) {
|
||||
if (mysqli_next_result($dbc)) {
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
if (get_class($result) == 'mysqli_stmt') {
|
||||
mysqli_stmt_free_result($result);
|
||||
} else {
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function dynamic_comparison($varleft, $op, $varright)
|
||||
{
|
||||
|
||||
switch ($op) {
|
||||
case "=":
|
||||
return $varleft == $varright;
|
||||
case "!=":
|
||||
return $varleft != $varright;
|
||||
case ">=":
|
||||
return $varleft >= $varright;
|
||||
case "<=":
|
||||
return $varleft <= $varright;
|
||||
case ">":
|
||||
return $varleft > $varright;
|
||||
case "<":
|
||||
return $varleft < $varright;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function generate_kelainan_lab($orderid=0, $orderdetailID=0)
|
||||
{
|
||||
$errors = [];
|
||||
if ($orderid != 0) {
|
||||
$filterOrderID = " AND T_OrderHeaderID = {$orderid}";
|
||||
} else {
|
||||
$filterOrderID = "";
|
||||
}
|
||||
if ($orderdetailID != 0) {
|
||||
$filterDetailID = " AND T_OrderDetailID = {$orderdetailID}";
|
||||
} else {
|
||||
$filterDetailID = "";
|
||||
}
|
||||
$sql = "SELECT
|
||||
T_OrderHeaderID,T_OrderHeaderLabNumber,
|
||||
T_TestName, T_OrderDetailID, T_OrderDetailResult, T_OrderDetailNat_MethodeID,
|
||||
T_OrderDetailNat_MethodeID, T_OrderDetailNat_MethodeName,
|
||||
T_OrderDetailMinValue, T_OrderDetailMaxValue, T_OrderDetailMinValueInclusive,
|
||||
T_OrderDetailMaxValueInclusive,
|
||||
Mcu_SummaryLabID,
|
||||
Mcu_SummaryLabValue,
|
||||
Mcu_SummaryLabNat_MethodeID,
|
||||
Mcu_SummaryLabWithMethode,
|
||||
Mcu_SummaryLabType,
|
||||
Mcu_SummaryLabIsNormalValue,
|
||||
Mcu_SummaryLabIsRange,
|
||||
Mcu_SummaryLabMinInclusive,
|
||||
Mcu_SummaryLabMinValue,
|
||||
Mcu_SummaryLabMaxInclusive,
|
||||
Mcu_SummaryLabMaxValue,
|
||||
Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanClasification,
|
||||
Nat_TestID,
|
||||
Nat_TestCode,
|
||||
mcu_kelainangroup.*
|
||||
from t_orderdetail
|
||||
join t_orderheader on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID {$filterOrderID} {$filterDetailID}
|
||||
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y'
|
||||
JOIN m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
||||
join t_test
|
||||
on T_OrderDetailT_TestID = T_TestID
|
||||
join nat_test ON T_TestNat_TestID = Nat_TestID
|
||||
join mcu_summarylab on T_TestNat_TestID = Mcu_SummaryLabNat_TestID AND Mcu_SummaryLabIsActive = 'Y'
|
||||
AND (Mcu_SummaryLabGender = 'A' OR (Mcu_SummaryLabGender <> 'A' AND Mcu_SummaryLabGender = CASE
|
||||
WHEN LOWER(M_SexNameLang) = 'male' THEN 'M'
|
||||
WHEN LOWER(M_SexNameLang) = 'female' THEN 'F'
|
||||
else ''
|
||||
END))
|
||||
join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
|
||||
join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID";
|
||||
//echo $sql;
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
|
||||
$prm_log = ['SELECT_T_ORDERDETAIL_KELAINAN_LAB_1', 'kelainanlab/generate_kelainan_lab'];
|
||||
$xsql = $this->db_onedev->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,json_encode($errors));
|
||||
$errors[] = "SELECT_T_ORDERDETAIL_KELAINAN_LAB_1";
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
$results = [];
|
||||
|
||||
|
||||
|
||||
foreach ($rows as $r) {
|
||||
$result_value = $r['T_OrderDetailResult'];
|
||||
|
||||
$value_comparison = 0;
|
||||
//echo $r['Mcu_SummaryLabIsNormalValue'];
|
||||
$kelainan = [];
|
||||
$notavailable = [];
|
||||
if (trim($result_value) == 'NA') {
|
||||
$notavailable = $r;
|
||||
} elseif ($r['Mcu_SummaryLabIsNormalValue'] == 'Y') {
|
||||
if ($r['Mcu_SummaryLabType'] == '<' || $r['Mcu_SummaryLabType'] == '<=') {
|
||||
$value_comparison = $r['T_OrderDetailMinValue'];
|
||||
}
|
||||
if ($r['Mcu_SummaryLabType'] == '>' || $r['Mcu_SummaryLabType'] == '>=') {
|
||||
$value_comparison = $r['T_OrderDetailMaxValue'];
|
||||
}
|
||||
//echo "Y";
|
||||
if ($r['Mcu_SummaryLabWithMethode'] == 'N' && $this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
|
||||
//echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
||||
$kelainan = $r;
|
||||
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
|
||||
}
|
||||
} else if ($r['Mcu_SummaryLabIsRange'] == 'Y') {
|
||||
// Mcu_SummaryLabIsNormalValue,
|
||||
// Mcu_SummaryLabIsRange,
|
||||
// Mcu_SummaryLabMinInclusive,
|
||||
// Mcu_SummaryLabMinValue,
|
||||
// Mcu_SummaryLabMaxInclusive,
|
||||
// Mcu_SummaryLabMaxValue,
|
||||
$isWithinMin = $r['Mcu_SummaryLabMinInclusive'] === 'Y' ? floatval($result_value) >= floatval($r['Mcu_SummaryLabMinValue']) : floatval($result_value) > floatval($r['Mcu_SummaryLabMinValue']);
|
||||
$isWithinMax = $r['Mcu_SummaryLabMaxInclusive'] === 'Y' ? floatval($result_value) <= floatval($r['Mcu_SummaryLabMaxValue']) : floatval($result_value) < floatval($r['Mcu_SummaryLabMaxValue']);
|
||||
|
||||
if ($isWithinMax && $isWithinMin) {
|
||||
$kelainan = $r;
|
||||
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
|
||||
}
|
||||
} else {
|
||||
$value_comparison = $r['Mcu_SummaryLabValue'];
|
||||
if ($r['Mcu_SummaryLabType'] == '!=' || $r['Mcu_SummaryLabType'] == '==') {
|
||||
if ($this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
|
||||
//echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
||||
$kelainan = $r;
|
||||
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
|
||||
}
|
||||
} else {
|
||||
if (is_numeric($result_value) && $this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
|
||||
//echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
||||
$kelainan = $r;
|
||||
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName'], 'orderdetailID' => $r['T_OrderDetailID'], 'orderheaderID' => $r['T_OrderHeaderID'], 'nat_testID' => $r['Nat_TestID'], 'mcu_summarylabID' => $r['Mcu_SummaryLabID']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($results) > 0) {
|
||||
$sql_update_kel = "";
|
||||
if ($orderdetailID != 0) {
|
||||
$sql_update_kel = "UPDATE t_kelainan_lab
|
||||
SET T_KelainanLabIsActive = 'N'
|
||||
WHERE
|
||||
T_KelainanLabT_OrderDetailID = {$orderdetailID}";
|
||||
} else {
|
||||
$sql_update_kel = "UPDATE t_kelainan_lab
|
||||
SET T_KelainanLabIsActive = 'N'
|
||||
WHERE
|
||||
T_KelainanLabT_OrderHeaderID = {$orderid}";
|
||||
|
||||
}
|
||||
$qry_update_kel = $this->db_onedev->query($sql_update_kel);
|
||||
if (!$qry_update_kel) {
|
||||
$prm_log = ['UPDATE_T_KELAINAN_LAB_N', 'kelainanlab/generate_kelainan_lab'];
|
||||
$xsql = $this->db_onedev->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,json_encode(['orderid' => $orderid, 'orderdetailID' => $orderdetailID]));
|
||||
$errors[] = "UPDATE_T_KELAINAN_LAB_N";
|
||||
}
|
||||
|
||||
foreach ($results as $v_result) {
|
||||
$sql_kel_lab = "SELECT *
|
||||
FROM t_kelainan_lab
|
||||
WHERE T_KelainanLabT_OrderDetailID = ?
|
||||
GROUP BY T_KelainanLabT_OrderDetailID";
|
||||
$qry_kel_lab = $this->db_onedev->query($sql_kel_lab, array($v_result['orderdetailID']));
|
||||
if ($qry_kel_lab) {
|
||||
$rows_kel = $qry_kel_lab->result_array();
|
||||
} else {
|
||||
$prm_log = ['SELECT_T_KELAINAN_LAB', 'kelainanlab/generate_kelainan_lab'];
|
||||
$xsql = $this->db_onedev->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,json_encode($v_result));
|
||||
$errors[] = "SELECT_T_KELAINAN_LAB";
|
||||
}
|
||||
|
||||
if (count($rows_kel) > 0) {
|
||||
|
||||
// print_r($v_result['orderdetailID']);
|
||||
// exit;
|
||||
|
||||
$sql_update_kel = "UPDATE t_kelainan_lab
|
||||
SET T_KelainanLabT_OrderDetailID = {$v_result['orderdetailID']},
|
||||
T_KelainanLabT_OrderHeaderID = {$v_result['orderheaderID']},
|
||||
T_KelainanLabNat_TestID = {$v_result['nat_testID']},
|
||||
T_KelainanLabMcu_SummaryLabID = {$v_result['mcu_summarylabID']},
|
||||
T_KelainanLabCreatedUserID = 1,
|
||||
T_KelainanLabIsActive = 'Y',
|
||||
T_KelainanLabCreated = NOW()
|
||||
WHERE T_KelainanLabID = {$rows_kel[0]['T_KelainanLabID']}";
|
||||
$qry_update_kel = $this->db_onedev->query($sql_update_kel);
|
||||
if (!$qry_update_kel) {
|
||||
$prm_log = ['UPDATE_T_KELAINAN_LAB', 'kelainanlab/generate_kelainan_lab'];
|
||||
$xsql = $this->db_onedev->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,json_encode($v_result));
|
||||
$errors[] = "UPDATE_T_KELAINAN_LAB";
|
||||
}
|
||||
} else {
|
||||
// print_r('insert');
|
||||
// exit;
|
||||
$sql_insert_lab = "INSERT INTO t_kelainan_lab(
|
||||
T_KelainanLabT_OrderDetailID,
|
||||
T_KelainanLabT_OrderHeaderID,
|
||||
T_KelainanLabNat_TestID,
|
||||
T_KelainanLabMcu_SummaryLabID,
|
||||
T_KelainanLabCreatedUserID,
|
||||
T_KelainanLabCreated)
|
||||
VALUES(
|
||||
'{$v_result['orderdetailID']}',
|
||||
'{$v_result['orderheaderID']}',
|
||||
'{$v_result['nat_testID']}',
|
||||
'{$v_result['mcu_summarylabID']}',
|
||||
1,
|
||||
NOW())";
|
||||
$qry_insert_lab = $this->db_onedev->query($sql_insert_lab);
|
||||
|
||||
if (!$qry_insert_lab) {
|
||||
$prm_log = ['INSERT_T_KELAINAN_LAB', 'kelainanlab/generate_kelainan_lab'];
|
||||
$xsql = $this->db_onedev->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,json_encode($v_result));
|
||||
$errors[] = "INSERT_T_KELAINAN_LAB";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
function insert_log_error($log_sql, $params,$data='')
|
||||
{
|
||||
// Membersihkan SQL dari \r\n dan whitespace berlebih
|
||||
//$clean_log_sql = trim(str_replace(["\r\n", "\r", "\n"], ' ', $log_sql));
|
||||
|
||||
$sql = "INSERT INTO error_log(
|
||||
ErrorLogCode,
|
||||
ErrorLogName,
|
||||
ErrorLogDescription,
|
||||
ErrorLogData,
|
||||
ErrorLogOrderCreated
|
||||
)
|
||||
VALUES(
|
||||
?,?,?,?,NOW()
|
||||
)";
|
||||
|
||||
$query = $this->db_log->query($sql, [$params[0],$params[1],$log_sql,json_encode($data)]);
|
||||
//echo $this->db_log->last_query();
|
||||
if (!$query) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
1945
application/libraries/Kesimpulanfisik.php
Normal file
1945
application/libraries/Kesimpulanfisik.php
Normal file
File diff suppressed because it is too large
Load Diff
14
application/libraries/Mcu.php
Normal file
14
application/libraries/Mcu.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class Mcu{
|
||||
// param
|
||||
// array ( T_OrderHeaderID => Array( T_SampleTypeID
|
||||
//
|
||||
function export($param) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
foreach($param as $orderHeaderID => $samples ) {
|
||||
$s_samples = impode(",",$samples);
|
||||
}
|
||||
}
|
||||
}
|
||||
2020
application/libraries/Mongo_db.php
Normal file
2020
application/libraries/Mongo_db.php
Normal file
File diff suppressed because it is too large
Load Diff
184
application/libraries/NatPatientLib.php
Normal file
184
application/libraries/NatPatientLib.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
defined("BASEPATH") or exit("No direct script access allowed");
|
||||
class NatPatientLib
|
||||
{
|
||||
|
||||
//dev
|
||||
var $NAT_PATIENT_API = "http://10.9.8.249/one-api/nat_patient/r_api/";
|
||||
//prod
|
||||
//var $NAT_PATIENT_API = "http://192.168.50.250/one-api/nat_patient/r_api/";
|
||||
function __construct()
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("default", true);
|
||||
}
|
||||
|
||||
//remote => status : Y|N Y confirm N, not confirm.
|
||||
/*
|
||||
create table m_patient_nat_validation(
|
||||
M_PatientNatValidationID int not null auto_increment primary key,
|
||||
M_PatientNatValidationM_PatientID int,
|
||||
M_PatientNatValidationM_UserID int,
|
||||
M_PatientNatValidationM_UserUsername varchar(100),
|
||||
M_PatientNatValidationIsActive char(1) default 'Y',
|
||||
M_PatientNatValidationCreated datetime default current_timestamp(),
|
||||
M_PatientNatValidationLastUpdated datetime default current_timestamp() on update current_timestamp(),
|
||||
key(M_PatientNatValidationM_PatientID),
|
||||
key(M_PatientNatValidationIsActive),
|
||||
);
|
||||
create table m_patient_nat_log (
|
||||
M_PatientNatLogID int not null auto_increment primary key,
|
||||
M_PatientNatLogDate datetime default current_timestamp(),
|
||||
M_PatientNatLogStatus enum('New','Retry','Sent'),
|
||||
M_PatientNatLogLastUpdated datetime default current_timestamp() on update current_timestamp(),
|
||||
M_PatientNatLogJson text,
|
||||
key(M_PatientNatLogDate),
|
||||
key(M_PatientNatLogStatus)
|
||||
);
|
||||
*/
|
||||
function save_nasional($userName,$patient) {
|
||||
$resp = $this->get_branch();
|
||||
if ($resp["status"] != "OK") {
|
||||
return $resp;
|
||||
}
|
||||
$param = ["M_BranchID" => $resp["branchID"],
|
||||
"M_BranchCode" => $resp["branchCode"],
|
||||
"Username" => $userName,
|
||||
"patient" => $patient ];
|
||||
$z_param = gzcompress(json_encode($param));
|
||||
$url = $this->NAT_PATIENT_API . "/update_from_local";
|
||||
$zresp = $this->post($url, $z_param);
|
||||
$jresp = gzuncompress($zresp);
|
||||
$resp = json_decode($jresp, true);
|
||||
if (!isset($resp["status"])) {
|
||||
$resp["status"] = "ERR";
|
||||
$resp["message"] = $zresp;
|
||||
}
|
||||
return $resp;
|
||||
}
|
||||
|
||||
function confirm($localM_PatientID, $arr_remote, $userID, $userName)
|
||||
{
|
||||
$payload = [
|
||||
"userID" => $userID,
|
||||
"userName" => $userName,
|
||||
"lokalM_PatientID" => $localM_PatientID,
|
||||
"remote" => $arr_remote,
|
||||
];
|
||||
$jsonPayload = json_encode($payload);
|
||||
$sql = "insert into m_patient_nat_log(M_PatientNatLogStatus,M_PatientNatLogJson)
|
||||
values('New',?)";
|
||||
$qry = $this->db->query($sql, [$jsonPayload]);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" => $this->db->error()["message"],
|
||||
];
|
||||
}
|
||||
return ["status" => "OK"];
|
||||
}
|
||||
function check_connection()
|
||||
{
|
||||
$start = date("Y-m-d H:i:s");
|
||||
$url = $this->NAT_PATIENT_API . "/check_connection";
|
||||
$zresp = $this->post($url, json_encode(["dummy" => "load"]));
|
||||
$jresp = gzuncompress($zresp);
|
||||
$resp = json_decode($jresp, true);
|
||||
if (!isset($resp["status"])) {
|
||||
$resp["status"] = "ERR";
|
||||
$resp["message"] = $zresp;
|
||||
}
|
||||
$stop = date("Y-m-d H:i:s");
|
||||
$resp["start"] = $start;
|
||||
$resp["stop"] = $stop;
|
||||
return $resp;
|
||||
}
|
||||
function get_branch()
|
||||
{
|
||||
$sql =
|
||||
"select M_BranchID, M_BranchCode from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault='Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => "ERR",
|
||||
"message" =>
|
||||
$this->db->error()["message"] .
|
||||
"|\n" .
|
||||
$this->db->last_query(),
|
||||
];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return ["status" => "ERR", "message" => "No Default Branch"];
|
||||
}
|
||||
return [
|
||||
"status" => "OK",
|
||||
"branchID" => $rows[0]["M_BranchID"],
|
||||
"branchCode" => $rows[0]["M_BranchCode"],
|
||||
];
|
||||
}
|
||||
function search($query)
|
||||
{
|
||||
$start = date("Y-m-d H:i:s");
|
||||
$url = $this->NAT_PATIENT_API . "/search_bizone";
|
||||
$jparam = json_encode(["search" => $query]);
|
||||
$zresp = $this->post($url, $jparam);
|
||||
$jresp = gzuncompress($zresp);
|
||||
$resp = json_decode($jresp, true);
|
||||
if (!isset($resp["status"])) {
|
||||
$resp["status"] = "ERR";
|
||||
$resp["message"] = $zresp;
|
||||
}
|
||||
$stop = date("Y-m-d H:i:s");
|
||||
$resp["start"] = $start;
|
||||
$resp["stop"] = $stop;
|
||||
return $resp;
|
||||
}
|
||||
// param array ->
|
||||
function search_by_nik($param)
|
||||
{
|
||||
$start = date("Y-m-d H:i:s");
|
||||
$url = $this->NAT_PATIENT_API . "/search_by_nik";
|
||||
$resp = $this->get_branch();
|
||||
|
||||
if ($resp["status"] != "OK") {
|
||||
return $resp;
|
||||
}
|
||||
$jparam = json_encode($param);
|
||||
$zresp = $this->post($url, $jparam);
|
||||
$jresp = gzuncompress($zresp);
|
||||
$resp = json_decode($jresp, true);
|
||||
if (!isset($resp["status"])) {
|
||||
$resp["status"] = "ERR";
|
||||
$resp["message"] = $zresp;
|
||||
}
|
||||
$stop = date("Y-m-d H:i:s");
|
||||
$resp["start"] = $start;
|
||||
$resp["stop"] = $stop;
|
||||
return $resp;
|
||||
}
|
||||
public function post($url, $data)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/text",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_error($ch) != "") {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Http Error : " . curl_error($ch),
|
||||
]);
|
||||
curl_close($ch);
|
||||
exit();
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
947
application/libraries/Nonlabtemplate.php
Normal file
947
application/libraries/Nonlabtemplate.php
Normal file
@@ -0,0 +1,947 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class Nonlabtemplate
|
||||
{
|
||||
|
||||
function generate($T_SamplingSOID)
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("onedev", true);
|
||||
$this->db_log = $CI->load->database("one_lab_log", true);
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$sql = "SELECT NonlabTemplateID as template_id,
|
||||
NonlabTemplateName as template_name,
|
||||
T_SamplingSoT_OrderHeaderID as order_header_id,
|
||||
T_OrderDetailID as order_detail_id
|
||||
FROM t_samplingso
|
||||
JOIN t_orderdetail ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_SamplingSoT_TestID = T_OrderDetailT_TestID AND T_OrderDetailIsActive = 'Y'
|
||||
JOIN t_test ON T_SamplingSoT_TestID = T_TestID
|
||||
JOIN nat_test ON Nat_TestID = T_TestNat_TestID
|
||||
JOIN nonlab_template_mapping ON NonlabTemplateMappingNat_TestID = Nat_TestID AND
|
||||
NonlabTemplateMappingIsActive = 'Y'
|
||||
JOIN nonlab_template ON NonlabTemplateMappingNonlabTemplateID = NonlabTemplateID AND NonlabTemplateIsActive = 'Y'
|
||||
LEFT JOIN so_resultentry ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND
|
||||
So_ResultEntryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
So_ResultEntryIsActive = 'Y'
|
||||
WHERE
|
||||
T_SamplingSoID = ? AND
|
||||
T_SamplingSoIsActive = 'Y' AND
|
||||
So_ResultEntryID IS NULL
|
||||
GROUP BY NonlabTemplateID
|
||||
LIMIT 1";
|
||||
$qry = $this->db->query($sql, array($T_SamplingSOID));
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_NONLAB_TEMPLATE', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$row_arr = $qry->row_array();
|
||||
if ($row_arr) {
|
||||
//print_r($row_arr);
|
||||
$template_name = $row_arr['template_name'];
|
||||
if($row_arr['template_name'] == 'Fisik Umum'){
|
||||
$sql = "SELECT FisikTemplateType as xtype
|
||||
FROM fisik_template
|
||||
JOIN t_orderheader ON T_OrderHeaderID = {$row_arr['order_header_id']}
|
||||
JOIN mgm_mcutemplate ON Mgm_McuTemplateMgm_McuID = T_OrderHeaderMgm_McuID
|
||||
JOIN fisik_template_mapping ON Mgm_McuTemplateFisikTemplateMappingID = FisikTemplateMappingID
|
||||
JOIN fisik_template_mapping_detail ON FisikTemplateMappingDetailFisikTemplateMappingID = FisikTemplateMappingID AND
|
||||
FisikTemplateMappingDetailFisikTemplateID = FisikTemplateID AND
|
||||
FisikTemplateMappingDetailIsActive = 'Y'
|
||||
WHERE
|
||||
FisikTemplateIsActive = 'Y'
|
||||
GROUP BY FisikTemplateType";
|
||||
$qry = $this->db->query($sql);
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_FISIK_TEMPLATE', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
$arr_types = $qry->result_array();
|
||||
$xtypes = [];
|
||||
foreach ($arr_types as $key => $value) {
|
||||
$xtypes[] = $value['xtype'];
|
||||
}
|
||||
|
||||
$template_name = "Fisik Umum";
|
||||
if(in_array("K3", $xtypes)){
|
||||
$template_name = "Fisik Umum K3";
|
||||
}
|
||||
//echo $template_name;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT COUNT(*) as xcount
|
||||
FROM so_resultentry
|
||||
WHERE
|
||||
So_ResultEntryT_OrderHeaderID = ? AND
|
||||
So_ResultEntryT_OrderDetailID = ? AND
|
||||
So_ResultEntryIsActive = 'Y'";
|
||||
|
||||
$query = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id'],
|
||||
$row_arr['order_detail_id']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID, 'arr' => $row_arr],'error' => $this->db->error()];
|
||||
$prm_log = ['CHECK_EXIST_SO_RE', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$check_exist = $query->row()->xcount;
|
||||
|
||||
if($check_exist == 0){
|
||||
$sql = "INSERT INTO so_resultentry(
|
||||
So_ResultEntryT_OrderHeaderID,
|
||||
So_ResultEntryT_OrderDetailID,
|
||||
So_ResultEntryNonlab_TemplateID,
|
||||
So_ResultEntryNonlab_TemplateName,
|
||||
So_ResultEntryCreated
|
||||
)
|
||||
VALUES(?,?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id'],
|
||||
$row_arr['order_detail_id'],
|
||||
$row_arr['template_id'],
|
||||
$template_name
|
||||
));
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['INSERT_SO_RESULTENTRY', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
$soresultentryid = $this->db->insert_id();
|
||||
|
||||
if($template_name == 'TBBB'){
|
||||
$sql = "SELECT COUNT(*) as exist_tbbb
|
||||
FROM t_samplingso_additional_fisik_bbtb
|
||||
WHERE T_SamplingAdditionalFisikBBTBIsActive = 'Y' AND
|
||||
T_SamplingAdditionalFisikBBTBT_OrderHeaderID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $row_arr['order_header_id']],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_ORDER_HEADER_LANG', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$check_exist_tbbbb = $qry->row()->exist_tbbb;
|
||||
if($check_exist_tbbbb == 0){
|
||||
$sql = "INSERT INTO t_samplingso_additional_fisik_bbtb (
|
||||
T_SamplingAdditionalFisikBBTBT_OrderHeaderID,
|
||||
T_SamplingAdditionalFisikBBTBValueBB,
|
||||
T_SamplingAdditionalFisikBBTBValueTB,
|
||||
T_SamplingAdditionalFisikBBTBValueClassification,
|
||||
T_SamplingAdditionalFisikBBTBBodyFat,
|
||||
T_SamplingAdditionalFisikBBTBCreated
|
||||
) VALUES(?,0,0,'',0, NOW())";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $row_arr['order_header_id']],'error' => $this->db->error()];
|
||||
$prm_log = ['INSERT_ADD_TBBB', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($template_name == 'VISUS'){
|
||||
$sql = "SELECT COUNT(*) as exist_visus
|
||||
FROM t_samplingso_additional_fisik_visus
|
||||
WHERE
|
||||
T_SamplingAdditionalFisikVisusT_OrderHeaderID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id']
|
||||
));
|
||||
// echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $row_arr['order_header_id']],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_ORDER_HEADER_LANG', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$check_exist_visus = $qry->row()->exist_visus;
|
||||
//echo $check_exist_visus ;
|
||||
if($check_exist_visus == 0){
|
||||
$sql = "INSERT INTO t_samplingso_additional_fisik_visus (
|
||||
T_SamplingAdditionalFisikVisusT_OrderHeaderID,
|
||||
T_SamplingAdditionalFisikVisusCreated
|
||||
) VALUES(?,NOW())";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $row_arr['order_header_id']],'error' => $this->db->error()];
|
||||
$prm_log = ['INSERT_ADD_VISUS', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($template_name == 'BW'){
|
||||
$sql = "SELECT COUNT(*) as exist_bw
|
||||
FROM t_samplingso_additional_fisik_bw
|
||||
WHERE
|
||||
T_SamplingAdditionalFisikBWT_OrderHeaderID = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $row_arr['order_header_id']],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_ORDER_HEADER_LANG', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$check_exist_visus = $qry->row()->exist_bw;
|
||||
if($check_exist_visus == 0){
|
||||
$sql = "INSERT INTO t_samplingso_additional_fisik_bw (
|
||||
T_SamplingAdditionalFisikBWT_OrderHeaderID,
|
||||
T_SamplingAdditionalFisikBWCreated
|
||||
) VALUES(?,NOW())";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $row_arr['order_header_id']],'error' => $this->db->error()];
|
||||
$prm_log = ['INSERT_ADD_BW', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM t_orderheaderlang
|
||||
WHERE
|
||||
T_OrderHeaderLangT_OrderHeaderID = ? AND T_OrderHeaderLangIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_ORDER_HEADER_LANG', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$order_langs = $qry->result_array();
|
||||
//print_r($order_langs);
|
||||
|
||||
foreach ($order_langs as $k_lang => $val_lang) {
|
||||
$sql = "SELECT *
|
||||
FROM nonlab_template_detail
|
||||
JOIN t_orderheader ON T_OrderHeaderID = ?
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
JOIN m_sex ON M_SexID = M_PatientM_SexID AND M_SexIsActive = 'Y' AND
|
||||
( NonlabTemplateDetailGender = 'all' OR NonlabTemplateDetailGender = M_SexNameLang)
|
||||
WHERE
|
||||
NonlabTemplateDetailNonlabTemplateID = ? AND NonlabTemplateDetailIsActive = 'Y' AND NonlabTemplateDetaiM_LangID = ? ";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id'],
|
||||
$row_arr['template_id'],
|
||||
$val_lang['T_OrderHeaderLangM_LangID']
|
||||
));
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $soresultentryid ,'arr' => $row_arr ],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_NONLAB_TEMPLATE_DETAIL', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$rows_result = $qry->result_array();
|
||||
if($rows_result && count($rows_result) > 0){
|
||||
foreach ($rows_result as $key => $value) {
|
||||
if(intval($val_lang['T_OrderHeaderLangM_LangID']) == 1){
|
||||
$sql = "SELECT COUNT(*) as xcount
|
||||
FROM so_resultentrydetail
|
||||
WHERE
|
||||
So_ResultEntryDetailSo_ResultEntryID = ? AND
|
||||
So_ResultEntryDetailNonlab_TemplateDetailID = ? AND
|
||||
So_ResultEntryDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array(
|
||||
$soresultentryid,
|
||||
$value['NonlabTemplateDetailID']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID, 'arr' => $value],'error' => $this->db->error()];
|
||||
$prm_log = ['CHECK_EXIST_SO_RE', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$check_exist_detail = $query->row()->xcount;
|
||||
|
||||
if($check_exist_detail == 0){
|
||||
$sql = "INSERT INTO so_resultentrydetail (
|
||||
So_ResultEntryDetailSo_ResultEntryID,
|
||||
So_ResultEntryDetailNonlab_TemplateDetailID,
|
||||
So_ResultEntryDetailNonlab_TemplateDetailName,
|
||||
So_ResultEntryDetailCreated
|
||||
)
|
||||
VALUES(?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$soresultentryid,
|
||||
$value['NonlabTemplateDetailID'],
|
||||
$value['NonlabTemplateDetailName']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['INSERT_SO_RESULTENTRY_DETAIL', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
}
|
||||
//echo $this->db->last_query();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM so_resultentry
|
||||
WHERE
|
||||
So_ResultEntryID = ? ";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$soresultentryid
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$rows_return = $qry->row_array();
|
||||
|
||||
return $rows_return;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function insert_log_error($log_sql, $params,$data='')
|
||||
{
|
||||
// Membersihkan SQL dari \r\n dan whitespace berlebih
|
||||
//$clean_log_sql = trim(str_replace(["\r\n", "\r", "\n"], ' ', $log_sql));
|
||||
|
||||
$sql = "INSERT INTO error_log_order(
|
||||
ErrorLogOrderCode,
|
||||
ErrorLogOrderFnName,
|
||||
ErrorLogOrderDescription,
|
||||
ErrorLogOrderData,
|
||||
ErrorLogOrderCreated
|
||||
)
|
||||
VALUES(
|
||||
?,?,?,?,NOW()
|
||||
)";
|
||||
|
||||
$query = $this->db_log->query($sql, [$params[0],$params[1],$log_sql,json_encode($data)]);
|
||||
//echo $this->db_log->last_query();
|
||||
if (!$query) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function create($tPriceHeaderID)
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("onedev", true);
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sql = "select * from t_priceheader where T_PriceHeaderID = ?";
|
||||
$qry = $this->db->query($sql, array($tPriceHeaderID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return array(false, "T PriceHeader ID : $tPriceHeaderID not found");
|
||||
}
|
||||
$sql = "select distinct T_PriceT_PriceHeaderID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $tPriceHeaderID Ss_PriceMouT_PriceHeaderID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceT_PriceHeaderID= ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($tPriceHeaderID));
|
||||
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(), true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
foreach ($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch ($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
if (!$qry) {
|
||||
// HANYA DEBUG
|
||||
// echo $this->db->last_query();
|
||||
// print_r($this->db->error());
|
||||
$this->db->trans_rollback();
|
||||
return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach ($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",", $t_rows) . "]";
|
||||
break;
|
||||
default:
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $tPriceHeaderID T_PriceT_PriceHeaderID, T_TestID,
|
||||
T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp,
|
||||
0 T_PriceSubTotal, 0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell,
|
||||
'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,
|
||||
$tPriceHeaderID Ss_PriceMouT_PriceHeaderID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceT_PriceHeaderID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceT_PriceHeaderID= ? ";
|
||||
$qry = $this->db->query($sql, array($tPriceHeaderID));
|
||||
if (!$qry) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(), true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach ($xrows as $r) {
|
||||
$pCode = $r["parentCode"];
|
||||
if (!isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
//DEBUG
|
||||
// echo $this->db->last_query();
|
||||
// print_r($this->db->error());
|
||||
return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach ($xrows as $r) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
$flag_error = false;
|
||||
foreach ($p_rows as $idx => $r) {
|
||||
$T_TestName = $r["T_TestName"];
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if (isset($arr_child[$sasCode])) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs, true);
|
||||
if (isset($arr_nat[$sasCode])) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $tPriceHeaderID T_PriceT_PriceHeaderID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$tPriceHeaderID Ss_PriceMouT_PriceHeaderID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketT_PriceHeaderID= ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($tPriceHeaderID));
|
||||
if (!$qry) {
|
||||
// echo $this->db->last_query();
|
||||
// print_r($this->db->error());
|
||||
return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach ($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $tPriceHeaderID T_PriceT_PriceHeaderID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, 0 T_PricePriority,
|
||||
T_PacketDetailPrice T_PriceAmount,
|
||||
0 T_PriceDisc,
|
||||
0 T_PriceDiscRp, T_PacketDetailPrice T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
JOIN t_packet ON T_PacketDetailT_PacketID = T_PacketID
|
||||
JOIN t_price ON T_PacketDetailT_TestID = T_PriceT_TestID AND T_PriceIsActive = 'Y' AND T_PriceT_PriceHeaderID = T_PacketT_PriceHeaderID
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($packetID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach ($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach ($nt_rows as $nr) {
|
||||
$t_rows[] = intval($nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[] = intval($nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows, JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0) {
|
||||
$x_arr = array();
|
||||
foreach ($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr, true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test, true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows, $p_rows, $pn_rows);
|
||||
$qry = $this->db->query(
|
||||
"delete from ss_price_mou where Ss_PriceMouT_PriceHeaderID=?",
|
||||
array($tPriceHeaderID)
|
||||
);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
return array(false, "" . print_r($this->db->error(), true) . $this->db->last_query());
|
||||
}
|
||||
$this->db->insert_batch("ss_price_mou", $rows);
|
||||
$err = $this->db->error();
|
||||
if ($err["code"] != 0) {
|
||||
echo "ERR Code : " . $err["code"] . " | " . $err["message"] . " \n";
|
||||
$this->db->trans_rollback();
|
||||
return array(false, "" . print_r($this->db->error(), true) . $this->db->last_query());
|
||||
}
|
||||
|
||||
// $sql_i = "insert into ss_price_mou(
|
||||
// T_TestID, T_TestName,
|
||||
// IsFromPanel, Nat_TestID,T_PriceT_TestID, T_PriceIsCito,
|
||||
// T_PricePriority, T_PriceAmount, T_PriceDisc,
|
||||
// T_PriceDiscRp, T_PriceSubTotal, T_PriceOther, T_PriceTotal,
|
||||
// T_TestForceSell, is_packet, packet_id, px_type,
|
||||
// nat_test, child_test, IsFavourite, Ss_PriceMouT_PriceHeaderID)
|
||||
// values (
|
||||
// ?,?,
|
||||
// ?,?,?,?,
|
||||
// ?,?,?,
|
||||
// ?,?,?,?,
|
||||
// ?,?,?,?,
|
||||
// ?,?,?,?
|
||||
// )";
|
||||
// foreach ($rows as $r) {
|
||||
// $arr = [
|
||||
// $r["T_TestID"],
|
||||
// $r["T_TestName"],
|
||||
// $r["IsFromPanel"],
|
||||
// $r["Nat_TestID"],
|
||||
// $r["T_PriceT_TestID"],
|
||||
// $r["T_PriceIsCito"],
|
||||
// $r["T_PricePriority"],
|
||||
// $r["T_PriceAmount"],
|
||||
// $r["T_PriceDisc"],
|
||||
// $r["T_PriceDiscRp"],
|
||||
// $r["T_PriceSubTotal"],
|
||||
// $r["T_PriceOther"],
|
||||
// $r["T_PriceTotal"],
|
||||
// $r["T_TestForceSell"],
|
||||
// $r["is_packet"],
|
||||
// $r["packet_id"],
|
||||
// $r["px_type"],
|
||||
// $r["nat_test"],
|
||||
// $r["child_test"],
|
||||
// $r["IsFavourite"],
|
||||
// $r["Ss_PriceMouT_PriceHeaderID"],
|
||||
// ];
|
||||
// $qry = $this->db->query($sql_i, $arr);
|
||||
// if (!$qry) {
|
||||
//
|
||||
// header("Content-Type: text/plain");
|
||||
// print_r($r);
|
||||
// echo $this->db->last_query();
|
||||
// return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
// }
|
||||
// }
|
||||
$this->db->trans_commit();
|
||||
return array(true, "OK");
|
||||
}
|
||||
// retrun array status, message
|
||||
public function bisone_create($mouID)
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("one", true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (!$qry) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(), true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach ($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch ($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
if (!$qry) {
|
||||
return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach ($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",", $t_rows) . "]";
|
||||
break;
|
||||
default:
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(), true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach ($xrows as $r) {
|
||||
$pCode = $r["parentCode"];
|
||||
if (!isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach ($xrows as $r) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
$flag_error = false;
|
||||
foreach ($p_rows as $idx => $r) {
|
||||
$T_TestName = $r["T_TestName"];
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if (isset($arr_child[$sasCode])) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs, true);
|
||||
if (isset($arr_nat[$sasCode])) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (!$qry) {
|
||||
return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach ($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($packetID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach ($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach ($nt_rows as $nr) {
|
||||
$t_rows[] = intval($nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[] = intval($nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows, JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0) {
|
||||
$x_arr = array();
|
||||
foreach ($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr, true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test, true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows, $p_rows, $pn_rows);
|
||||
$qry = $this->db->query("delete from ss_price_mou where Ss_PriceMouM_MouID=?", array($mouID));
|
||||
if (!$qry) {
|
||||
return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou", $rows);
|
||||
if (!$qry) {
|
||||
return array(false, "Regional " . print_r($this->db->error(), true));
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
}
|
||||
118
application/libraries/Ocr_alibaba.php
Normal file
118
application/libraries/Ocr_alibaba.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class Ocr_alibaba
|
||||
{
|
||||
const API_KEY = "sk-a7de5339f0fa4cf491ffc37b00dae1cc";
|
||||
const API_URL = "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions";
|
||||
public $modelName = "qwen-vl-plus";
|
||||
public $temperature = 0.2;
|
||||
|
||||
public function extract_ocr($imagePath)
|
||||
{
|
||||
if (!file_exists($imagePath)) {
|
||||
return ["status" => "ERR", "message" => "Error: File not found."];
|
||||
}
|
||||
|
||||
// Load image and convert to black and white
|
||||
$image = imagecreatefromstring(file_get_contents($imagePath));
|
||||
// imagefilter($image, IMG_FILTER_GRAYSCALE);
|
||||
|
||||
// Get original dimensions and resize
|
||||
// $originalWidth = imagesx($image);
|
||||
// $originalHeight = imagesy($image);
|
||||
// $newWidth = intval(640);
|
||||
// $newHeight = intval($originalHeight * ($newWidth / $originalWidth));
|
||||
// $resizedImage = imagecreatetruecolor($newWidth, $newHeight);
|
||||
// imagecopyresampled($resizedImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
|
||||
|
||||
// Convert image to base64
|
||||
ob_start();
|
||||
imagejpeg($image);
|
||||
$imageData = ob_get_clean();
|
||||
$imgStr = base64_encode($imageData);
|
||||
$imgStrNew = "data:image/jpeg;base64," . $imgStr;
|
||||
|
||||
// Prepare request payload
|
||||
$payload = json_encode([
|
||||
"model" => $this->modelName,
|
||||
"messages" => [[
|
||||
"role" => "user",
|
||||
"content" => [
|
||||
[
|
||||
"type" => "text",
|
||||
"text" => "Extract all text from the given image. Return result only, in the pattern label:value as it is, without translation."
|
||||
],
|
||||
[
|
||||
"type" => "image_url",
|
||||
"image_url" => [
|
||||
"url" => $imgStrNew
|
||||
],
|
||||
]
|
||||
],
|
||||
]],
|
||||
"options" => ["temperature" => $this->temperature],
|
||||
"stream" => false
|
||||
]);
|
||||
|
||||
// Initialize cURL
|
||||
$ch = curl_init(self::API_URL);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/json",
|
||||
"Authorization: Bearer " . self::API_KEY
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
|
||||
// Execute request
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return ["status" => "ERR", "message" => curl_error($ch)];
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
$response = strip_tags($response);
|
||||
$responseData = json_decode($response, true);
|
||||
$content = $responseData['choices'][0]['message']['content'];
|
||||
|
||||
if (is_null($responseData) || !isset($content)) {
|
||||
return ["status" => "ERR", "message" => "raw : $response"];
|
||||
}
|
||||
|
||||
$parsedData = [];
|
||||
$lines = explode("\n", $content);
|
||||
foreach ($lines as $line) {
|
||||
$parts = explode(":", $line, 2);
|
||||
if (count($parts) == 2) {
|
||||
$key = trim(str_replace("*", "", $parts[0]));
|
||||
$key = strtolower($key);
|
||||
$key = str_replace(" ", "_", $key);
|
||||
$value = trim(str_replace("*", "", $parts[1]));
|
||||
|
||||
if (strpos($key, "/")) {
|
||||
$a_key = explode("/", $key);
|
||||
$a_val = explode(",", $value);
|
||||
if (strpos($value, "/")) {
|
||||
$a_val = explode("/", $value);
|
||||
}
|
||||
foreach ($a_key as $a_idx => $sub_key) {
|
||||
$sub_val = $a_val[$a_idx];
|
||||
$parsedData[trim($sub_key)] = trim($sub_val);
|
||||
}
|
||||
} else {
|
||||
$parsedData[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$info["prompt_tokens"] = $responseData["usage"]["prompt_tokens"];
|
||||
$info["completion_tokens"] = $responseData["usage"]["completion_tokens"];
|
||||
$info["total_tokens"] = $responseData["usage"]["total_tokens"];
|
||||
$info["estimated_cost"] = $responseData["usage"]["estimated_cost"];
|
||||
$info["model"] = $this->modelName;
|
||||
$info["temperature"] = $this->temperature;
|
||||
return ["status" => "OK", "data" => $parsedData, "info" => $info];
|
||||
}
|
||||
}
|
||||
124
application/libraries/Ocr_deepinfra.php
Normal file
124
application/libraries/Ocr_deepinfra.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class Ocr_deepinfra
|
||||
{
|
||||
const API_KEY = "a6vizxx0GoH3kDonZLnPD9qDeq8jwZyU";
|
||||
const API_URL = "https://api.deepinfra.com/v1/openai/chat/completions";
|
||||
public $modelName = "meta-llama/Llama-3.2-11B-Vision-Instruct";
|
||||
public $temperature = 0.1;
|
||||
|
||||
public function extract_ocr($imagePath)
|
||||
{
|
||||
if (!file_exists($imagePath)) {
|
||||
return ["status" => "ERR", "message" => "Error: File not found."];
|
||||
}
|
||||
|
||||
// Load image and convert to black and white
|
||||
$image = imagecreatefromstring(file_get_contents($imagePath));
|
||||
// imagefilter($image, IMG_FILTER_GRAYSCALE);
|
||||
|
||||
// Get original dimensions and resize
|
||||
// $originalWidth = imagesx($image);
|
||||
// $originalHeight = imagesy($image);
|
||||
// $newWidth = intval(640);
|
||||
// $newHeight = intval($originalHeight * ($newWidth / $originalWidth));
|
||||
// $resizedImage = imagecreatetruecolor($newWidth, $newHeight);
|
||||
// imagecopyresampled($resizedImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
|
||||
|
||||
// Convert image to base64
|
||||
ob_start();
|
||||
// imagejpeg($resizedImage);
|
||||
imagejpeg($image);
|
||||
$imageData = ob_get_clean();
|
||||
$imgStr = base64_encode($imageData);
|
||||
$imgStrNew = "data:image/jpeg;base64," . $imgStr;
|
||||
|
||||
// Prepare request payload
|
||||
$payload = json_encode([
|
||||
"model" => $this->modelName,
|
||||
"messages" => [[
|
||||
"role" => "user",
|
||||
"content" => [
|
||||
[
|
||||
"type" => "text",
|
||||
"text" => "Extract all text from the given image. Return result only, in the pattern label:value as it is, without translation."
|
||||
],
|
||||
[
|
||||
"type" => "image_url",
|
||||
"image_url" => [
|
||||
"url" => $imgStrNew
|
||||
],
|
||||
]
|
||||
],
|
||||
]],
|
||||
"options" => ["temperature" => $this->temperature],
|
||||
"stream" => false
|
||||
]);
|
||||
|
||||
// Initialize cURL
|
||||
$ch = curl_init(self::API_URL);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/json",
|
||||
"Authorization: Bearer " . self::API_KEY
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
|
||||
// Execute request
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return ["status" => "ERR", "message" => curl_error($ch)];
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
$response = strip_tags($response);
|
||||
$responseData = json_decode($response, true);
|
||||
|
||||
$content = $responseData['choices'][0]['message']['content'];
|
||||
|
||||
if (is_null($responseData) || !isset($content)) {
|
||||
return ["status" => "ERR", "message" => "raw : $response"];
|
||||
}
|
||||
|
||||
// echo "content:\n";
|
||||
// echo $content . "\n";
|
||||
// echo "\n";
|
||||
|
||||
$parsedData = [];
|
||||
$lines = explode("\n", $content);
|
||||
foreach ($lines as $line) {
|
||||
$parts = explode(":", $line, 2);
|
||||
if (count($parts) == 2) {
|
||||
$key = trim(str_replace("*", "", $parts[0]));
|
||||
$key = strtolower($key);
|
||||
$key = str_replace(" ", "_", $key);
|
||||
$value = trim(str_replace("*", "", $parts[1]));
|
||||
|
||||
if (strpos($key, "/")) {
|
||||
$a_key = explode("/", $key);
|
||||
$a_val = explode(",", $value);
|
||||
if (strpos($value, "/")) {
|
||||
$a_val = explode("/", $value);
|
||||
}
|
||||
foreach ($a_key as $a_idx => $sub_key) {
|
||||
$sub_val = $a_val[$a_idx];
|
||||
$parsedData[trim($sub_key)] = trim($sub_val);
|
||||
}
|
||||
} else {
|
||||
$parsedData[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$info["prompt_tokens"] = $responseData["usage"]["prompt_tokens"];
|
||||
$info["completion_tokens"] = $responseData["usage"]["completion_tokens"];
|
||||
$info["total_tokens"] = $responseData["usage"]["total_tokens"];
|
||||
$info["estimated_cost"] = $responseData["usage"]["estimated_cost"];
|
||||
$info["model"] = $this->modelName;
|
||||
$info["temperature"] = $this->temperature;
|
||||
return ["status" => "OK", "data" => $parsedData, "info" => $info];
|
||||
}
|
||||
}
|
||||
104
application/libraries/Ocr_llama.php
Normal file
104
application/libraries/Ocr_llama.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class Ocr_llama
|
||||
{
|
||||
private $ollamaUrl = "http://10.9.10.205:11434/api/chat";
|
||||
private $modelName = "llama3.2-vision:11b";
|
||||
private $temperature = 0.1;
|
||||
|
||||
public function extract_ocr($imagePath)
|
||||
{
|
||||
if (!file_exists($imagePath)) {
|
||||
return ["status"=>"ERR", "message"=> "Error: File not found."];
|
||||
}
|
||||
|
||||
// Load image and convert to black and white
|
||||
$image = imagecreatefromstring(file_get_contents($imagePath));
|
||||
imagefilter($image, IMG_FILTER_GRAYSCALE);
|
||||
|
||||
// Get original dimensions and resize
|
||||
// $newWidth = intval(imagesx($image) / 2);
|
||||
// $newHeight = intval(imagesy($image) / );
|
||||
// $resizedImage = imagecreatetruecolor($newWidth, $newHeight);
|
||||
// imagecopyresampled($resizedImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, imagesx($image), imagesy($image));
|
||||
|
||||
// Convert image to base64
|
||||
ob_start();
|
||||
imagejpeg($image);
|
||||
$imageData = ob_get_clean();
|
||||
$imgStr = base64_encode($imageData);
|
||||
|
||||
// Prepare request payload
|
||||
$payload = json_encode([
|
||||
"model" => $this->modelName,
|
||||
"messages" => [[
|
||||
"role" => "user",
|
||||
"content" => "Extract all text from the given image. Return result only, in the pattern label:value as it is, without translation.",
|
||||
"images" => [$imgStr]
|
||||
]],
|
||||
"options" => ["temperature" => $this->temperature],
|
||||
"stream" => false
|
||||
]);
|
||||
|
||||
// Initialize cURL
|
||||
$ch = curl_init($this->ollamaUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
|
||||
// Execute request
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return ["status" => "ERR", "message" => curl_error($ch)];
|
||||
}
|
||||
curl_close($ch);
|
||||
// Decode response
|
||||
// Remove <pre> tags if present
|
||||
$response = strip_tags($response);
|
||||
|
||||
$responseData = json_decode($response, true);
|
||||
if (!$responseData || !isset($responseData['message']['content'])) {
|
||||
return ["status"=>"ERR", "message"=> "raw : $response"];
|
||||
}
|
||||
|
||||
// Parse content into JSON object
|
||||
$content = $responseData["message"]["content"];
|
||||
// echo "content:\n";
|
||||
// echo $content . "\n";
|
||||
// echo "\n";
|
||||
$parsedData = [];
|
||||
$lines = explode("\n", $content);
|
||||
foreach ($lines as $line) {
|
||||
$parts = explode(":", $line, 2);
|
||||
if (count($parts) == 2) {
|
||||
$key = trim(str_replace("*","",$parts[0]));
|
||||
$key = strtolower($key);
|
||||
$key = str_replace(" ","_",$key);
|
||||
$value = trim(str_replace("*","",$parts[1]));
|
||||
|
||||
if (strpos($key, "/")) {
|
||||
$a_key = explode("/", $key);
|
||||
$a_val = explode(",", $value);
|
||||
if (strpos($value, "/")) {
|
||||
$a_val = explode("/", $value);
|
||||
}
|
||||
foreach($a_key as $a_idx => $sub_key) {
|
||||
$sub_val = $a_val[$a_idx];
|
||||
$parsedData[trim($sub_key)] = trim($sub_val);
|
||||
}
|
||||
} else {
|
||||
$parsedData[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$info["total_duration"] = $responseData["total_duration"];
|
||||
$info["prompt_eval_duration"] = $responseData["prompt_eval_duration"];
|
||||
$info["eval_duration"] = $responseData["eval_duration"];
|
||||
$info["model"] = $responseData["model"];
|
||||
return ["status"=>"OK", "data" => $parsedData, "info"=> $info];
|
||||
}
|
||||
}
|
||||
119
application/libraries/Ocr_oroute.php
Normal file
119
application/libraries/Ocr_oroute.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class Ocr_oroute
|
||||
{
|
||||
const API_KEY = "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";
|
||||
const API_URL = "https://openrouter.ai/api/v1/chat/completions";
|
||||
public $modelName;
|
||||
public $temperature = 0.1;
|
||||
|
||||
public function extract_ocr($imagePath)
|
||||
{
|
||||
if (!file_exists($imagePath)) {
|
||||
return ["status" => "ERR", "message" => "Error: File not found."];
|
||||
}
|
||||
|
||||
// Load image and convert to black and white
|
||||
$image = imagecreatefromstring(file_get_contents($imagePath));
|
||||
// imagefilter($image, IMG_FILTER_GRAYSCALE);
|
||||
|
||||
// Get original dimensions and resize
|
||||
// $originalWidth = imagesx($image);
|
||||
// $originalHeight = imagesy($image);
|
||||
// $newWidth = intval(640);
|
||||
// $newHeight = intval($originalHeight * ($newWidth / $originalWidth));
|
||||
// $resizedImage = imagecreatetruecolor($newWidth, $newHeight);
|
||||
// imagecopyresampled($resizedImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
|
||||
|
||||
// Convert image to base64
|
||||
ob_start();
|
||||
// imagejpeg($resizedImage);
|
||||
imagejpeg($image);
|
||||
$imageData = ob_get_clean();
|
||||
$imgStr = base64_encode($imageData);
|
||||
$imgStrNew = "data:image/jpeg;base64," . $imgStr;
|
||||
|
||||
// Prepare request payload
|
||||
$payload = json_encode([
|
||||
"model" => $this->modelName,
|
||||
"messages" => [[
|
||||
"role" => "user",
|
||||
"content" => [
|
||||
[
|
||||
"type" => "text",
|
||||
"text" => "Extract all text from the given image. Return result only, in the pattern label:value as it is, without translation."
|
||||
],
|
||||
[
|
||||
"type" => "image_url",
|
||||
"image_url" => [
|
||||
"url" => $imgStrNew
|
||||
],
|
||||
]
|
||||
],
|
||||
]],
|
||||
"options" => ["temperature" => $this->temperature],
|
||||
"stream" => false
|
||||
]);
|
||||
|
||||
// Initialize cURL
|
||||
$ch = curl_init(self::API_URL);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/json",
|
||||
"Authorization: Bearer " . self::API_KEY
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
|
||||
// Execute request
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return ["status" => "ERR", "message" => "Error CURL ke API " . curl_error($ch)];
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
$response = strip_tags($response);
|
||||
$responseData = json_decode($response, true);
|
||||
$content = $responseData['choices'][0]['message']['content'];
|
||||
|
||||
if (is_null($responseData) || !isset($content)) {
|
||||
return ["status" => "ERR", "message" => "raw : $response"];
|
||||
}
|
||||
|
||||
$parsedData = [];
|
||||
$lines = explode("\n", $content);
|
||||
foreach ($lines as $line) {
|
||||
$parts = explode(":", $line, 2);
|
||||
if (count($parts) == 2) {
|
||||
$key = trim(str_replace("*", "", $parts[0]));
|
||||
$key = strtolower($key);
|
||||
$key = str_replace(" ", "_", $key);
|
||||
$value = trim(str_replace("*", "", $parts[1]));
|
||||
|
||||
if (strpos($key, "/")) {
|
||||
$a_key = explode("/", $key);
|
||||
$a_val = explode(",", $value);
|
||||
if (strpos($value, "/")) {
|
||||
$a_val = explode("/", $value);
|
||||
}
|
||||
foreach ($a_key as $a_idx => $sub_key) {
|
||||
$sub_val = $a_val[$a_idx];
|
||||
$parsedData[trim($sub_key)] = trim($sub_val);
|
||||
}
|
||||
} else {
|
||||
$parsedData[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$info["prompt_tokens"] = $responseData["usage"]["prompt_tokens"];
|
||||
$info["completion_tokens"] = $responseData["usage"]["completion_tokens"];
|
||||
$info["total_tokens"] = $responseData["usage"]["total_tokens"];
|
||||
$info["estimated_cost"] = $responseData["usage"]["estimated_cost"];
|
||||
$info["model"] = $this->modelName;
|
||||
$info["temperature"] = $this->temperature;
|
||||
return ["status" => "OK", "data" => $parsedData, "info" => $info];
|
||||
}
|
||||
}
|
||||
319
application/libraries/Report.php
Normal file
319
application/libraries/Report.php
Normal file
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class ReportUrl
|
||||
{
|
||||
|
||||
function generate($T_SamplingSOID)
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("onedev", true);
|
||||
$this->db_log = $CI->load->database("one_lab_log", true);
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$sql = "SELECT NonlabTemplateID as template_id,
|
||||
NonlabTemplateName as template_name,
|
||||
T_SamplingSoT_OrderHeaderID as order_header_id,
|
||||
T_OrderDetailID as order_detail_id
|
||||
FROM t_samplingso
|
||||
JOIN t_orderdetail ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_SamplingSoT_TestID = T_OrderDetailT_TestID AND T_OrderDetailIsActive = 'Y'
|
||||
JOIN t_test ON T_SamplingSoT_TestID = T_TestID
|
||||
JOIN nat_test ON Nat_TestID = T_TestNat_TestID
|
||||
JOIN nonlab_template_mapping ON NonlabTemplateMappingNat_TestID = Nat_TestID AND
|
||||
NonlabTemplateMappingIsActive = 'Y'
|
||||
JOIN nonlab_template ON NonlabTemplateMappingNonlabTemplateID = NonlabTemplateID AND NonlabTemplateIsActive = 'Y'
|
||||
LEFT JOIN so_resultentry ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND
|
||||
So_ResultEntryT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
||||
So_ResultEntryIsActive = 'Y'
|
||||
WHERE
|
||||
T_SamplingSoID = ? AND
|
||||
T_SamplingSoIsActive = 'Y' AND
|
||||
So_ResultEntryID IS NULL
|
||||
GROUP BY NonlabTemplateID
|
||||
LIMIT 1";
|
||||
$qry = $this->db->query($sql, array($T_SamplingSOID));
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_NONLAB_TEMPLATE', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$row_arr = $qry->row_array();
|
||||
if ($row_arr) {
|
||||
//print_r($row_arr);
|
||||
$template_name = $row_arr['template_name'];
|
||||
if($row_arr['template_name'] == 'Fisik Umum'){
|
||||
$sql = "SELECT FisikTemplateType as xtype
|
||||
FROM fisik_template
|
||||
JOIN t_orderheader ON T_OrderHeaderID = {$row_arr['order_header_id']}
|
||||
JOIN mgm_mcutemplate ON Mgm_McuTemplateMgm_McuID = T_OrderHeaderMgm_McuID
|
||||
JOIN fisik_template_mapping ON Mgm_McuTemplateFisikTemplateMappingID = FisikTemplateMappingID
|
||||
JOIN fisik_template_mapping_detail ON FisikTemplateMappingDetailFisikTemplateMappingID = FisikTemplateMappingID AND
|
||||
FisikTemplateMappingDetailFisikTemplateID = FisikTemplateID AND
|
||||
FisikTemplateMappingDetailIsActive = 'Y'
|
||||
WHERE
|
||||
FisikTemplateIsActive = 'Y'
|
||||
GROUP BY FisikTemplateType";
|
||||
$qry = $this->db->query($sql);
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_FISIK_TEMPLATE', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
$arr_types = $qry->result_array();
|
||||
$xtypes = [];
|
||||
foreach ($arr_types as $key => $value) {
|
||||
$xtypes[] = $value['xtype'];
|
||||
}
|
||||
|
||||
$template_name = "Fisik Umum";
|
||||
if(in_array("K3", $xtypes)){
|
||||
$template_name = "Fisik Umum K3";
|
||||
}
|
||||
//echo $template_name;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO so_resultentry(
|
||||
So_ResultEntryT_OrderHeaderID,
|
||||
So_ResultEntryT_OrderDetailID,
|
||||
So_ResultEntryNonlab_TemplateID,
|
||||
So_ResultEntryNonlab_TemplateName,
|
||||
So_ResultEntryCreated
|
||||
)
|
||||
VALUES(?,?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id'],
|
||||
$row_arr['order_detail_id'],
|
||||
$row_arr['template_id'],
|
||||
$template_name
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['INSERT_SO_RESULTENTRY', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
$soresultentryid = $this->db->insert_id();
|
||||
|
||||
$sql = "SELECT * FROM t_orderheaderlang
|
||||
WHERE
|
||||
T_OrderHeaderLangT_OrderHeaderID = ? AND T_OrderHeaderLangIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_ORDER_HEADER_LANG', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$order_langs = $qry->result_array();
|
||||
//print_r($order_langs);
|
||||
|
||||
foreach ($order_langs as $k_lang => $val_lang) {
|
||||
$sql = "SELECT *
|
||||
FROM nonlab_template_detail
|
||||
JOIN t_orderheader ON T_OrderHeaderID = ?
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
JOIN m_sex ON M_SexID = M_PatientM_SexID AND M_SexIsActive = 'Y' AND
|
||||
( NonlabTemplateDetailGender = 'all' OR NonlabTemplateDetailGender = M_SexNameLang)
|
||||
WHERE
|
||||
NonlabTemplateDetailNonlabTemplateID = ? AND NonlabTemplateDetailIsActive = 'Y' AND NonlabTemplateDetaiM_LangID = ? ";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$row_arr['order_header_id'],
|
||||
$row_arr['template_id'],
|
||||
$val_lang['T_OrderHeaderLangM_LangID']
|
||||
));
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['SELECT_NONLAB_TEMPLATE_DETAIL', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$rows_result = $qry->result_array();
|
||||
if($rows_result && count($rows_result) > 0){
|
||||
foreach ($rows_result as $key => $value) {
|
||||
if(intval($val_lang['T_OrderHeaderLangM_LangID']) == 1){
|
||||
$sql = "INSERT INTO so_resultentrydetail (
|
||||
So_ResultEntryDetailSo_ResultEntryID,
|
||||
So_ResultEntryDetailNonlab_TemplateDetailID,
|
||||
So_ResultEntryDetailNonlab_TemplateDetailName,
|
||||
So_ResultEntryDetailCreated
|
||||
)
|
||||
VALUES(?,?,?,NOW())";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$soresultentryid,
|
||||
$value['NonlabTemplateDetailID'],
|
||||
$value['NonlabTemplateDetailName']
|
||||
));
|
||||
if (!$qry) {
|
||||
$dt_log = ['data' => ['id' => $T_SamplingSOID],'error' => $this->db->error()];
|
||||
$prm_log = ['INSERT_SO_RESULTENTRY_DETAIL', 'nonlabtemplate/generate'];
|
||||
$xsql = $this->db->last_query();
|
||||
$log_error = $this->insert_log_error($xsql, $prm_log,$dt_log);
|
||||
$this->db->trans_rollback();
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
//echo $this->db->last_query();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM so_resultentry
|
||||
WHERE
|
||||
So_ResultEntryID = ? ";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$soresultentryid
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$rows_return = $qry->row_array();
|
||||
|
||||
return $rows_return;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function get_report_by_code($report_code, $params){
|
||||
$sql = "SELECT *
|
||||
FROM print_transaction
|
||||
WHERE
|
||||
Print_TransactionCode = ? ";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$report_code
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$rows_return = $qry->row_array();
|
||||
|
||||
return $rows_return;
|
||||
}
|
||||
|
||||
function get_report_url_by_code($report_code, $params = array()){
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("onedev", true);
|
||||
|
||||
// Get report data by code
|
||||
$report_data = $this->get_report_by_code($report_code, $params);
|
||||
|
||||
if (!$report_data || empty($report_data)) {
|
||||
return array(false, "Report code not found: " . $report_code);
|
||||
}
|
||||
|
||||
// Get URL template
|
||||
$url_template = $report_data['Print_TransactionUrl'];
|
||||
|
||||
if (empty($url_template)) {
|
||||
return array(false, "URL template is empty for report code: " . $report_code);
|
||||
}
|
||||
|
||||
// Replace placeholders with actual parameter values
|
||||
$final_url = $url_template;
|
||||
|
||||
foreach ($params as $param_key => $param_value) {
|
||||
// Determine if value should be quoted (string) or not (numeric)
|
||||
$replacement_value = is_numeric($param_value) ? $param_value : "'" . $param_value . "'";
|
||||
|
||||
// Replace placeholder in URL
|
||||
$final_url = str_replace($param_key, $replacement_value, $final_url);
|
||||
}
|
||||
|
||||
return array(true, $final_url);
|
||||
}
|
||||
/*
|
||||
CREATE TABLE `print_transaction` (
|
||||
`Print_TransactionID` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`Print_TransactionType` char(2) NOT NULL DEFAULT 'P' COMMENT 'P (paper), E (Email)',
|
||||
`Print_TransactionCode` varchar(20) NOT NULL DEFAULT '',
|
||||
`Print_TransactionName` varchar(150) NOT NULL DEFAULT '',
|
||||
`Print_TransactionUrl` varchar(500) NOT NULL DEFAULT '',
|
||||
`Print_TransactionParams` varchar(500) NOT NULL DEFAULT '',
|
||||
`Print_TransactionCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`Print_TransactionCreatedUserID` int(11) NOT NULL DEFAULT 0,
|
||||
`Print_TransactionLastUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`Print_TransactionLastUpdatedUserID` int(11) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`Print_TransactionID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
INSERT INTO `print_transaction` (`Print_TransactionID`, `Print_TransactionType`, `Print_TransactionCode`, `Print_TransactionName`, `Print_TransactionUrl`, `Print_TransactionParams`, `Print_TransactionCreated`, `Print_TransactionCreatedUserID`, `Print_TransactionLastUpdated`, `Print_TransactionLastUpdatedUserID`) VALUES
|
||||
(1, 'P', 'LAB-RESULT-P-01', 'Report hasil test lab untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_test.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 09:26:48', 555, '0000-00-00 00:00:00', 0),
|
||||
(2, 'P', 'LAB-RESULT-P-02', 'Report hasil test lab untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_test_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '0000-00-00 00:00:00', 555, '0000-00-00 00:00:00', 0),
|
||||
(3, 'P', 'LAB-RESULT-P-03', 'Report hasil test lab untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_test_prev.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:32:54', 555, '0000-00-00 00:00:00', 0),
|
||||
(4, 'P', 'LAB-RESULT-NP-01', 'Report hasil test lab tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_test_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:25:02', 555, '0000-00-00 00:00:00', 0),
|
||||
(5, 'E', 'LAB-RESULT-NP-02', 'Report hasil test lab tidak untuk email', '/birt/frameset?__report=report/onelab/lab/rpt_test_email_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:25:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(6, 'P', 'LAB-RESULT-NP-03', 'Report hasil test lab tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_test_prev_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:25:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(7, 'P', 'LABEN-RESULT-P-01', 'Report hasil test lab untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:32:09', 555, '0000-00-00 00:00:00', 0),
|
||||
(8, 'E', 'LABEN-RESULT-P-02', 'Report hasil test lab untuk email versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_email_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(9, 'P', 'LABEN-RESULT-P-03', 'Report hasil test lab untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_eng_prev.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(10, 'P', 'LABEN-RESULT-NP-01', 'Report hasil test lab tidak untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_not_print_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(11, 'P', 'MIKROEN-RESULT-P-01', 'Report hasil test mikro untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(12, 'E', 'MIKROEN-RESULT-P-02', 'Report hasil test mikro untuk email versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_email_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(13, 'P', 'MIKROEN-RESULT-P-03', 'Report hasil test mikro untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_eng_prev.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(14, 'P', 'MIKROEN-RESULT-NP-01', 'Report hasil test mikro tidak untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_not_print_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(45, 'P', 'PS-RESULT-P-01', 'Report hasil test preparasi sperma untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_sperma.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(46, 'E', 'PS-RESULT-P-02', 'Report hasil test preparasi sperma untuk email', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_sperma_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(47, 'P', 'PS-RESULT-NP-01', 'Report hasil test preparasi sperma tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_sperma_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(48, 'P', 'DFI-RESULT-P-01', 'Report hasil test dfi untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_dfi.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(49, 'E', 'DFI-RESULT-P-02', 'Report hasil test dfi untuk email', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_dfi_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(50, 'P', 'DFI-RESULT-NP-01', 'Report hasil test dfi tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_dfi_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(51, 'P', 'FNA-RESULT-P-01', 'Report hasil test fna untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_fna.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(52, 'E', 'FNA-RESULT-P-02', 'Report hasil test fna untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_fna_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(53, 'P', 'FNA-RESULT-NP-01', 'Report hasil test fna tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_fna_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(54, 'P', 'PA-RESULT-P-01', 'Report hasil test patologi anatomi untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_patologi_anatomy.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(55, 'E', 'PA-RESULT-P-02', 'Report hasil test patologi anatomi untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_patologi_anatomy_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(56, 'P', 'PA-RESULT-NP-01', 'Report hasil test patologi anatomi tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_patologi_anatomy_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(57, 'P', 'PAP-RESULT-P-01', 'Report hasil test pap smear untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_papsmear.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(58, 'E', 'PAP-RESULT-P-02', 'Report hasil test pap smear untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_papsmear_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(59, 'P', 'PAP-RESULT-NP-01', 'Report hasil test pap smear tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_papsmear_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(60, 'P', 'PAPLCP-RESULT-P-01', 'Report hasil test pap smear (liquid c prep) untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(61, 'E', 'PAPLCP-RESULT-P-02', 'Report hasil test pap smear (liquid c prep) untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(62, 'P', 'PAPLCP-RESULT-NP-01', 'Report hasil test pap smear (liquid c prep) tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(63, 'P', 'PAPLEN-RESULT-P-01', 'Report hasil test pap smear (liquid c prep) untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(64, 'E', 'PAPLEN-RESULT-P-02', 'Report hasil test pap smear (liquid c prep) untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep_email_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(65, 'P', 'PAPLEN-RESULT-NP-01', 'Report hasil test pap smear (liquid c prep) tidak untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep_not_print_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(66, 'P', 'MIKRO-RESULT-P-01', 'Report hasil test mikro untuk diprint terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test_mikro.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(67, 'E', 'MIKRO-RESULT-P-02', 'Report hasil test mikro untuk email terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test_mikro_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(68, 'P', 'MIKRO-RESULT-NP-01', 'Report hasil test mikro tidak untuk diprint terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test_mikro_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(69, 'P', 'MIKROO-RESULT-P-01', 'Report hasil test mikro untuk diprint tidak terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(70, 'E', 'MIKROO-RESULT-P-02', 'Report hasil test mikro untuk email tidak terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(71, 'P', 'MIKROO-RESULT-NP-01', 'Report hasil test mikro untuk tidak diprint tidak terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(72, 'P', 'CT-RESULT-P-01', 'Report hasil test citology untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_cytologi.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(73, 'E', 'CT-RESULT-P-02', 'Report hasil test citology untuk email', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_cytologi_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(74, 'P', 'CT-RESULT-NP-01', 'Report hasil test citology untuk tidak diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_cytologi_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0);
|
||||
|
||||
-- 2026-02-06 06:35:26
|
||||
*/
|
||||
}
|
||||
138
application/libraries/Reporturl.php
Normal file
138
application/libraries/Reporturl.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class Reporturl
|
||||
{
|
||||
|
||||
function __construct(){
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("onedev", true);
|
||||
}
|
||||
|
||||
function get_report_by_code($report_code, $params){
|
||||
$sql = "SELECT *
|
||||
FROM print_transaction
|
||||
WHERE
|
||||
Print_TransactionCode = ? ";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$report_code
|
||||
));
|
||||
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(), true));
|
||||
}
|
||||
|
||||
$rows_return = $qry->row_array();
|
||||
|
||||
return $rows_return;
|
||||
}
|
||||
|
||||
function get_report_url_by_code($report_code, $params = array(), $show='N'){
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("onedev", true);
|
||||
|
||||
// Get report data by code
|
||||
$report_data = $this->get_report_by_code($report_code, $params);
|
||||
|
||||
if (!$report_data || empty($report_data)) {
|
||||
return array(false, "Report code not found: " . $report_code);
|
||||
}
|
||||
|
||||
// Get URL template
|
||||
$url_template = $report_data['Print_TransactionUrl'];
|
||||
|
||||
if (empty($url_template)) {
|
||||
return array(false, "URL template is empty for report code: " . $report_code);
|
||||
}
|
||||
|
||||
// Replace placeholders with actual parameter values
|
||||
$final_url = $url_template;
|
||||
|
||||
foreach ($params as $param_key => $param_value) {
|
||||
// Determine if value should be quoted (string) or not (numeric)
|
||||
$replacement_value = is_numeric($param_value) ? $param_value : "'" . $param_value . "'";
|
||||
|
||||
// Replace placeholder in URL
|
||||
$final_url = str_replace($param_key, $replacement_value, $final_url);
|
||||
}
|
||||
|
||||
if($show == 'N'){
|
||||
return array(true, $final_url);
|
||||
}
|
||||
else{
|
||||
$final_url = 'http'.($_SERVER['HTTPS'] == 'on' ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$final_url;
|
||||
|
||||
$response = file_get_contents($final_url);
|
||||
header("Content-type: application/pdf");
|
||||
header(
|
||||
'Content-Disposition: inline; filename="' .
|
||||
$output_file_name .
|
||||
'"'
|
||||
);
|
||||
echo ($response);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
CREATE TABLE `print_transaction` (
|
||||
`Print_TransactionID` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`Print_TransactionType` char(2) NOT NULL DEFAULT 'P' COMMENT 'P (paper), E (Email)',
|
||||
`Print_TransactionCode` varchar(20) NOT NULL DEFAULT '',
|
||||
`Print_TransactionName` varchar(150) NOT NULL DEFAULT '',
|
||||
`Print_TransactionUrl` varchar(500) NOT NULL DEFAULT '',
|
||||
`Print_TransactionParams` varchar(500) NOT NULL DEFAULT '',
|
||||
`Print_TransactionCreated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`Print_TransactionCreatedUserID` int(11) NOT NULL DEFAULT 0,
|
||||
`Print_TransactionLastUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`Print_TransactionLastUpdatedUserID` int(11) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`Print_TransactionID`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
INSERT INTO `print_transaction` (`Print_TransactionID`, `Print_TransactionType`, `Print_TransactionCode`, `Print_TransactionName`, `Print_TransactionUrl`, `Print_TransactionParams`, `Print_TransactionCreated`, `Print_TransactionCreatedUserID`, `Print_TransactionLastUpdated`, `Print_TransactionLastUpdatedUserID`) VALUES
|
||||
(1, 'P', 'LAB-RESULT-P-01', 'Report hasil test lab untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_test.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 09:26:48', 555, '0000-00-00 00:00:00', 0),
|
||||
(2, 'P', 'LAB-RESULT-P-02', 'Report hasil test lab untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_test_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '0000-00-00 00:00:00', 555, '0000-00-00 00:00:00', 0),
|
||||
(3, 'P', 'LAB-RESULT-P-03', 'Report hasil test lab untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_test_prev.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:32:54', 555, '0000-00-00 00:00:00', 0),
|
||||
(4, 'P', 'LAB-RESULT-NP-01', 'Report hasil test lab tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_test_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:25:02', 555, '0000-00-00 00:00:00', 0),
|
||||
(5, 'E', 'LAB-RESULT-NP-02', 'Report hasil test lab tidak untuk email', '/birt/frameset?__report=report/onelab/lab/rpt_test_email_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:25:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(6, 'P', 'LAB-RESULT-NP-03', 'Report hasil test lab tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_test_prev_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:25:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(7, 'P', 'LABEN-RESULT-P-01', 'Report hasil test lab untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:32:09', 555, '0000-00-00 00:00:00', 0),
|
||||
(8, 'E', 'LABEN-RESULT-P-02', 'Report hasil test lab untuk email versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_email_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(9, 'P', 'LABEN-RESULT-P-03', 'Report hasil test lab untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_eng_prev.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(10, 'P', 'LABEN-RESULT-NP-01', 'Report hasil test lab tidak untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_not_print_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(11, 'P', 'MIKROEN-RESULT-P-01', 'Report hasil test mikro untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(12, 'E', 'MIKROEN-RESULT-P-02', 'Report hasil test mikro untuk email versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_email_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(13, 'P', 'MIKROEN-RESULT-P-03', 'Report hasil test mikro untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_eng_prev.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(14, 'P', 'MIKROEN-RESULT-NP-01', 'Report hasil test mikro tidak untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_test_not_print_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 10:34:57', 555, '0000-00-00 00:00:00', 0),
|
||||
(45, 'P', 'PS-RESULT-P-01', 'Report hasil test preparasi sperma untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_sperma.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(46, 'E', 'PS-RESULT-P-02', 'Report hasil test preparasi sperma untuk email', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_sperma_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(47, 'P', 'PS-RESULT-NP-01', 'Report hasil test preparasi sperma tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_sperma_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(48, 'P', 'DFI-RESULT-P-01', 'Report hasil test dfi untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_dfi.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(49, 'E', 'DFI-RESULT-P-02', 'Report hasil test dfi untuk email', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_dfi_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(50, 'P', 'DFI-RESULT-NP-01', 'Report hasil test dfi tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_dfi_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(51, 'P', 'FNA-RESULT-P-01', 'Report hasil test fna untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_fna.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(52, 'E', 'FNA-RESULT-P-02', 'Report hasil test fna untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_fna_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(53, 'P', 'FNA-RESULT-NP-01', 'Report hasil test fna tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_fna_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(54, 'P', 'PA-RESULT-P-01', 'Report hasil test patologi anatomi untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_patologi_anatomy.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(55, 'E', 'PA-RESULT-P-02', 'Report hasil test patologi anatomi untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_patologi_anatomy_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(56, 'P', 'PA-RESULT-NP-01', 'Report hasil test patologi anatomi tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_patologi_anatomy_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(57, 'P', 'PAP-RESULT-P-01', 'Report hasil test pap smear untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_papsmear.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(58, 'E', 'PAP-RESULT-P-02', 'Report hasil test pap smear untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_papsmear_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(59, 'P', 'PAP-RESULT-NP-01', 'Report hasil test pap smear tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_papsmear_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(60, 'P', 'PAPLCP-RESULT-P-01', 'Report hasil test pap smear (liquid c prep) untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(61, 'E', 'PAPLCP-RESULT-P-02', 'Report hasil test pap smear (liquid c prep) untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(62, 'P', 'PAPLCP-RESULT-NP-01', 'Report hasil test pap smear (liquid c prep) tidak untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(63, 'P', 'PAPLEN-RESULT-P-01', 'Report hasil test pap smear (liquid c prep) untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(64, 'E', 'PAPLEN-RESULT-P-02', 'Report hasil test pap smear (liquid c prep) untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep_email_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(65, 'P', 'PAPLEN-RESULT-NP-01', 'Report hasil test pap smear (liquid c prep) tidak untuk diprint versi inggris', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_lcprep_not_print_eng.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(66, 'P', 'MIKRO-RESULT-P-01', 'Report hasil test mikro untuk diprint terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test_mikro.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(67, 'E', 'MIKRO-RESULT-P-02', 'Report hasil test mikro untuk email terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test_mikro_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(68, 'P', 'MIKRO-RESULT-NP-01', 'Report hasil test mikro tidak untuk diprint terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test_mikro_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(69, 'P', 'MIKROO-RESULT-P-01', 'Report hasil test mikro untuk diprint tidak terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(70, 'E', 'MIKROO-RESULT-P-02', 'Report hasil test mikro untuk email tidak terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(71, 'P', 'MIKROO-RESULT-NP-01', 'Report hasil test mikro untuk tidak diprint tidak terlampir', '/birt/frameset?__report=report/onelab/lab/rpt_test_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(72, 'P', 'CT-RESULT-P-01', 'Report hasil test citology untuk diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_cytologi.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(73, 'E', 'CT-RESULT-P-02', 'Report hasil test citology untuk email', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_cytologi_email.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0),
|
||||
(74, 'P', 'CT-RESULT-NP-01', 'Report hasil test citology untuk tidak diprint', '/birt/frameset?__report=report/onelab/lab/rpt_hasil_cytologi_not_print.rptdesign&__format=pdf&username=PUsername&PID=PT_OrderHeaderID&tm=TS', 'PUsername,PT_OrderHeaderID,TS', '2026-02-06 11:24:51', 555, '0000-00-00 00:00:00', 0);
|
||||
|
||||
-- 2026-02-06 06:35:26
|
||||
*/
|
||||
}
|
||||
113
application/libraries/Resultcalc-bkp.php
Normal file
113
application/libraries/Resultcalc-bkp.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class ResultCalc{
|
||||
public function auto($id)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select
|
||||
T_TestCalculationID,T_TestCalculationFormula,
|
||||
T_OrderDetailID, T_OrderDetailT_TestID, T_TestNat_TestID Nat_TestID,
|
||||
T_TestCalculationID,T_OrderDetailResult,
|
||||
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) / 365 AgeInYear,
|
||||
T_TestCalculationNat_SexID
|
||||
from t_orderdetail
|
||||
join t_orderheader on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderID = ?
|
||||
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
join t_testcalculation on T_TestNat_TestID = T_TestCalculationNat_TestID
|
||||
and T_TestCalculationIsActive = 'Y'
|
||||
and (
|
||||
T_TestCalculationNat_SexID = M_PatientM_SexID
|
||||
or
|
||||
T_TestCalculationNat_SexID = 0
|
||||
)
|
||||
";
|
||||
|
||||
$sql_det = "select T_TestCalculationDetailCode, T_OrderDetailResult
|
||||
from
|
||||
t_testcalculation_detail td
|
||||
join t_testcalculation on T_TestCalculationID = T_TestCalculationDetailT_TestCalculationID
|
||||
and T_TestCalculationID = ?
|
||||
join t_test t on td.T_TestCalculationDetailNat_TestID = T_TestNat_TestID
|
||||
left join t_orderdetail on T_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y'
|
||||
and T_OrderDetailT_OrderHeaderID = ?
|
||||
where T_OrderDetailID is not null";
|
||||
|
||||
|
||||
$qry = $this->db->query($sql, array($id));
|
||||
$rows = $qry->result_array();
|
||||
|
||||
if ( count($rows) > 0 ) {
|
||||
foreach($rows as $r) {
|
||||
$tc_id = $r["T_TestCalculationID"];
|
||||
$formula = $r["T_TestCalculationFormula"];
|
||||
$qry_det = $this->db->query($sql_det, array($tc_id, $id));
|
||||
$drows = $qry_det->result_array();
|
||||
$have_all = true;
|
||||
$have_one = false;
|
||||
$formula = str_replace("AGE",$r["AgeInYear"], $formula);
|
||||
$flag_recursive = false;
|
||||
if (strpos($formula,"[REC]") > -1 ) {
|
||||
$flag_recursive = true;
|
||||
}
|
||||
if ( ! $flag_recursive ) {
|
||||
if( trim($r["T_OrderDetailResult"]) != "") continue;
|
||||
}
|
||||
|
||||
$formula = str_replace("[REC]","", $formula);
|
||||
foreach($drows as $dr) {
|
||||
$code = $dr["T_TestCalculationDetailCode"];
|
||||
$value = $dr["T_OrderDetailResult"];
|
||||
if($dr["T_OrderDetailResult"] == "" ) {
|
||||
$have_all = false;
|
||||
break;
|
||||
}
|
||||
$have_one = true;
|
||||
$formula = str_replace($code, $value,$formula);
|
||||
}
|
||||
if ($have_all && $have_one) {
|
||||
|
||||
eval("\$f_value = $formula;");
|
||||
//formating
|
||||
//echo "\n$f_value ..";
|
||||
//file_put_contents("/xtmp/formula",$f_value. "\n",FILE_APPEND);
|
||||
if (is_numeric($f_value)) {
|
||||
$f_value = $this->format_value($f_value,$r["Nat_TestID"]);
|
||||
}
|
||||
//file_put_contents("/xtmp/formula",$f_value. "\n",FILE_APPEND);
|
||||
$od_id = $r["T_OrderDetailID"];
|
||||
$sql = "update t_orderdetail set T_OrderDetailResult = ?
|
||||
where T_OrderDetailID = ?";
|
||||
$this->db->query($sql, array($f_value,$od_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function format_value($f_value, $nat_test_id){
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select * from m_instrumentmethode
|
||||
where M_InstrumentMethodeIsActive = 'Y'
|
||||
and M_InstrumentMethodeNat_TestID = ?
|
||||
limit 0,1";
|
||||
$qry = $this->db->query($sql, array($nat_test_id) );
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
if ($f_value > 0 ) {
|
||||
$fmt = $rows[0]["M_InstrumentMethodeResultFormatAboveSF"];
|
||||
} else {
|
||||
$fmt = $rows[0]["M_InstrumentMethodeResultFormatSF"];
|
||||
}
|
||||
$idx = strpos($fmt,".");
|
||||
$dec = strlen($fmt) - $idx;
|
||||
if ($dec > 0 ) $dec = $dec -1;
|
||||
return number_format($f_value,$dec);
|
||||
}
|
||||
}
|
||||
return number_format($f_value,0,".",",");
|
||||
}
|
||||
}
|
||||
107
application/libraries/Resultcalc-new.php
Normal file
107
application/libraries/Resultcalc-new.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class ResultCalc{
|
||||
public function auto($id)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select
|
||||
T_TestCalculationID,T_TestCalculationFormula,
|
||||
T_OrderDetailID, T_OrderDetailT_TestID, T_TestNat_TestID Nat_TestID,
|
||||
T_TestCalculationID,T_OrderDetailResult,
|
||||
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) / 365 AgeInYear,
|
||||
T_TestCalculationNat_SexID
|
||||
from t_orderdetail
|
||||
join t_orderheader on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderID = ?
|
||||
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
join t_testcalculation on T_TestNat_TestID = T_TestCalculationNat_TestID
|
||||
and T_TestCalculationIsActive = 'Y'
|
||||
and (
|
||||
T_TestCalculationNat_SexID = M_PatientM_SexID
|
||||
or
|
||||
T_TestCalculationNat_SexID = 0
|
||||
)
|
||||
";
|
||||
|
||||
$sql_det = "select T_TestCalculationDetailCode, T_OrderDetailResult
|
||||
from
|
||||
t_testcalculation_detail td
|
||||
join t_testcalculation on T_TestCalculationID = T_TestCalculationDetailT_TestCalculationID
|
||||
and T_TestCalculationID = ?
|
||||
join t_test t on td.T_TestCalculationDetailNat_TestID = T_TestNat_TestID
|
||||
left join t_orderdetail on T_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y'
|
||||
and T_OrderDetailT_OrderHeaderID = ?
|
||||
where T_OrderDetailID is not null";
|
||||
|
||||
|
||||
$qry = $this->db->query($sql, array($id));
|
||||
$rows = $qry->result_array();
|
||||
if ( count($rows) > 0 ) {
|
||||
foreach($rows as $r) {
|
||||
$tc_id = $r["T_TestCalculationID"];
|
||||
$qry_det = $this->db->query($sql_det, array($tc_id, $id));
|
||||
$drows = $qry_det->result_array();
|
||||
$formula = $r["T_TestCalculationFormula"];
|
||||
$have_all = true;
|
||||
$have_one = false;
|
||||
$formula = str_replace("AGE",$r["AgeInYear"], $formula);
|
||||
$flag_recursive = false;
|
||||
if (strpos($formula,"[REC]") > -1 ) {
|
||||
$flag_recursive = true;
|
||||
}
|
||||
if ( ! $flag_recursive ) {
|
||||
if( $r["T_OrderDetailResult"] != "") continue;
|
||||
}
|
||||
$formula = str_replace("[REC]","", $formula);
|
||||
foreach($drows as $dr) {
|
||||
if($dr["T_OrderDetailResult"] == "" ) {
|
||||
$have_all = false;
|
||||
break;
|
||||
}
|
||||
$have_one = true;
|
||||
$code = $dr["T_TestCalculationDetailCode"];
|
||||
$value = $dr["T_OrderDetailResult"];
|
||||
$formula = str_replace($code, $value,$formula);
|
||||
}
|
||||
if ($have_all && $have_one) {
|
||||
|
||||
eval("\$f_value = $formula;");
|
||||
file_put_contents("/xtmp/formula",$formula . "\n",FILE_APPEND);
|
||||
//formating
|
||||
$f_value = $this->format_value($f_value,$r["Nat_TestID"]);
|
||||
$od_id = $r["T_OrderDetailID"];
|
||||
$sql = "update t_orderdetail set T_OrderDetailResult = ?
|
||||
where T_OrderDetailID = ?";
|
||||
$this->db->query($sql, array($f_value,$od_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function format_value($f_value, $nat_test_id){
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select * from m_instrumentmethode
|
||||
where M_InstrumentMethodeIsActive = 'Y'
|
||||
and M_InstrumentMethodeNat_TestID = ?
|
||||
limit 0,1";
|
||||
$qry = $this->db->query($sql, array($nat_test_id) );
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
if ($f_value > 0 ) {
|
||||
$fmt = $rows[0]["M_InstrumentMethodeResultFormatAboveSF"];
|
||||
} else {
|
||||
$fmt = $rows[0]["M_InstrumentMethodeResultFormatSF"];
|
||||
}
|
||||
$idx = strpos($fmt,".");
|
||||
$dec = strlen($fmt) - $idx;
|
||||
if ($dec > 0 ) $dec = $dec -1;
|
||||
return number_format($f_value,$dec);
|
||||
}
|
||||
}
|
||||
return number_format($f_value,0,".",",");
|
||||
}
|
||||
}
|
||||
110
application/libraries/Resultcalc-riau.php
Normal file
110
application/libraries/Resultcalc-riau.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class ResultCalc{
|
||||
public function auto($id)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select
|
||||
T_TestCalculationID,T_TestCalculationFormula,
|
||||
T_OrderDetailID, T_OrderDetailT_TestID, T_TestNat_TestID Nat_TestID,
|
||||
T_TestCalculationID,T_OrderDetailResult,
|
||||
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) / 365 AgeInYear,
|
||||
T_TestCalculationNat_SexID
|
||||
from t_orderdetail
|
||||
join t_orderheader on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderID = ?
|
||||
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
join t_testcalculation on T_TestNat_TestID = T_TestCalculationNat_TestID
|
||||
and T_TestCalculationIsActive = 'Y'
|
||||
and (
|
||||
T_TestCalculationNat_SexID = M_PatientM_SexID
|
||||
or
|
||||
T_TestCalculationNat_SexID = 0
|
||||
)
|
||||
";
|
||||
|
||||
$sql_det = "select T_TestCalculationDetailCode, T_OrderDetailResult
|
||||
from
|
||||
t_testcalculation_detail td
|
||||
join t_testcalculation on T_TestCalculationID = T_TestCalculationDetailT_TestCalculationID
|
||||
and T_TestCalculationID = ?
|
||||
join t_test t on td.T_TestCalculationDetailNat_TestID = T_TestNat_TestID
|
||||
left join t_orderdetail on T_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y'
|
||||
and T_OrderDetailT_OrderHeaderID = ?
|
||||
where T_OrderDetailID is not null";
|
||||
|
||||
|
||||
$qry = $this->db->query($sql, array($id));
|
||||
$rows = $qry->result_array();
|
||||
if ( count($rows) > 0 ) {
|
||||
foreach($rows as $r) {
|
||||
$tc_id = $r["T_TestCalculationID"];
|
||||
$qry_det = $this->db->query($sql_det, array($tc_id, $id));
|
||||
$drows = $qry_det->result_array();
|
||||
$formula = $r["T_TestCalculationFormula"];
|
||||
$have_all = true;
|
||||
$have_one = false;
|
||||
$formula = str_replace("AGE",$r["AgeInYear"], $formula);
|
||||
$flag_recursive = false;
|
||||
if (strpos($formula,"[REC]") > -1 ) {
|
||||
$flag_recursive = true;
|
||||
}
|
||||
//echo "$formula " . $r["T_OrderDetailResult"] . "\n";
|
||||
if ( ! $flag_recursive ) {
|
||||
if( trim($r["T_OrderDetailResult"]) != "") continue;
|
||||
}
|
||||
|
||||
$formula = str_replace("[REC]","", $formula);
|
||||
foreach($drows as $dr) {
|
||||
$code = $dr["T_TestCalculationDetailCode"];
|
||||
$value = $dr["T_OrderDetailResult"];
|
||||
//echo "$code , $value , $formula \n";
|
||||
if($dr["T_OrderDetailResult"] == "" ) {
|
||||
$have_all = false;
|
||||
break;
|
||||
}
|
||||
$have_one = true;
|
||||
$formula = str_replace($code, $value,$formula);
|
||||
}
|
||||
if ($have_all && $have_one) {
|
||||
|
||||
eval("\$f_value = $formula;");
|
||||
//formating
|
||||
//echo "\n$f_value ..";
|
||||
$f_value = $this->format_value($f_value,$r["Nat_TestID"]);
|
||||
$od_id = $r["T_OrderDetailID"];
|
||||
$sql = "update t_orderdetail set T_OrderDetailResult = ?
|
||||
where T_OrderDetailID = ?";
|
||||
$this->db->query($sql, array($f_value,$od_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function format_value($f_value, $nat_test_id){
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select * from m_instrumentmethode
|
||||
where M_InstrumentMethodeIsActive = 'Y'
|
||||
and M_InstrumentMethodeNat_TestID = ?
|
||||
limit 0,1";
|
||||
$qry = $this->db->query($sql, array($nat_test_id) );
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
if ($f_value > 0 ) {
|
||||
$fmt = $rows[0]["M_InstrumentMethodeResultFormatAboveSF"];
|
||||
} else {
|
||||
$fmt = $rows[0]["M_InstrumentMethodeResultFormatSF"];
|
||||
}
|
||||
$idx = strpos($fmt,".");
|
||||
$dec = strlen($fmt) - $idx;
|
||||
if ($dec > 0 ) $dec = $dec -1;
|
||||
return number_format($f_value,$dec);
|
||||
}
|
||||
}
|
||||
return number_format($f_value,0,".",",");
|
||||
}
|
||||
}
|
||||
175
application/libraries/Resultcalc.php
Normal file
175
application/libraries/Resultcalc.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class ResultCalc
|
||||
{
|
||||
public function auto($id, $debug = "")
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("onedev", true);
|
||||
$sql = "select
|
||||
T_TestCalculationID,T_TestCalculationFormula,
|
||||
T_OrderDetailID, T_OrderDetailT_TestID, T_TestNat_TestID Nat_TestID,
|
||||
T_TestCalculationID,T_OrderDetailResult,
|
||||
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) / 365 AgeInYear,
|
||||
T_TestCalculationNat_SexID,
|
||||
T_OrderDetailT_TestName
|
||||
from t_orderdetail
|
||||
join t_orderheader on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderID = ?
|
||||
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
join t_testcalculation on T_TestNat_TestID = T_TestCalculationNat_TestID
|
||||
and T_TestCalculationIsActive = 'Y'
|
||||
and (
|
||||
T_TestCalculationNat_SexID = M_PatientM_SexID
|
||||
or
|
||||
T_TestCalculationNat_SexID = 0
|
||||
)
|
||||
";
|
||||
|
||||
$sql_det = "select T_OrderDetailT_TestName, T_TestCalculationDetailCode, T_OrderDetailResult
|
||||
from
|
||||
t_testcalculation_detail td
|
||||
join t_testcalculation on T_TestCalculationID = T_TestCalculationDetailT_TestCalculationID
|
||||
and T_TestCalculationID = ? and T_TestCalculationDetailIsActive = 'Y'
|
||||
join t_test t on td.T_TestCalculationDetailNat_TestID = T_TestNat_TestID
|
||||
left join t_orderdetail on T_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y'
|
||||
and T_OrderDetailT_OrderHeaderID = ?
|
||||
Order by T_TestCalculationDetailCode,T_OrderDetailResult desc";
|
||||
//where T_OrderDetailID is not null";
|
||||
|
||||
|
||||
$qry = $this->db->query($sql, array($id));
|
||||
$date = date("Y-m-d H:i:s");
|
||||
//file_put_contents("/xtmp/debug-calc.log", "$date : {$this->db->last_query()} \n");
|
||||
$rows = $qry->result_array();
|
||||
if ($debug != "") {
|
||||
print_r($rows);
|
||||
}
|
||||
|
||||
if (count($rows) > 0) {
|
||||
foreach ($rows as $r) {
|
||||
$tc_id = $r["T_TestCalculationID"];
|
||||
$qry_det = $this->db->query($sql_det, array($tc_id, $id));
|
||||
$drows = $qry_det->result_array();
|
||||
$formula = $r["T_TestCalculationFormula"];
|
||||
$have_all = true;
|
||||
$have_one = false;
|
||||
$formula = str_replace("AGE", $r["AgeInYear"], $formula);
|
||||
$flag_recursive = false;
|
||||
if (strpos($formula, "[REC]") > -1) {
|
||||
$flag_recursive = true;
|
||||
}
|
||||
if (!$flag_recursive) {
|
||||
if (trim($r["T_OrderDetailResult"]) != "") continue;
|
||||
}
|
||||
|
||||
$formula = str_replace("[REC]", "", $formula);
|
||||
$org_formula = $formula;
|
||||
$s_code_value = "";
|
||||
$tc_name = $r["T_OrderDetailT_TestName"];
|
||||
|
||||
$arr_code = array();
|
||||
|
||||
$arr_param = [];
|
||||
foreach ($drows as $dr) {
|
||||
$code = $dr["T_TestCalculationDetailCode"];
|
||||
$value = $dr["T_OrderDetailResult"];
|
||||
$s_code_value .= "^$code=$value";
|
||||
$arr_param[] = $code;
|
||||
if (isset($arr_code[$code])) continue;
|
||||
$arr_code[$code] = "exist";
|
||||
if ($dr["T_OrderDetailResult"] == "" || $dr["T_OrderDetailResult"] == "-") {
|
||||
$have_all = false;
|
||||
break;
|
||||
}
|
||||
$arr_code[$code] = $value;
|
||||
$have_one = true;
|
||||
$formula = str_replace($code, $value, $formula);
|
||||
}
|
||||
$have_all = true;
|
||||
if (count($arr_param) == 0) $have_all = false;
|
||||
foreach($arr_param as $p) {
|
||||
if ($debug != "") {
|
||||
echo "code $p : ";
|
||||
}
|
||||
if (!isset($arr_code[$p])) {
|
||||
if ($debug != "") {
|
||||
echo "not exists \n";
|
||||
}
|
||||
$have_all = false;
|
||||
break;
|
||||
} else {
|
||||
if ($arr_code[$p] == "exist") {
|
||||
$have_all = false;
|
||||
}
|
||||
if ($debug != "") {
|
||||
echo "exists : {$arr_code[$p]} \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($debug != "") {
|
||||
echo "$formula " . $r["T_OrderDetailResult"] . "\n";
|
||||
echo "-- have one : " . $have_one ? "Y" : "N";
|
||||
echo "\n";
|
||||
echo "-- have all : " . $have_all ? "Y" : "N";
|
||||
echo "\n";
|
||||
}
|
||||
if ($have_all && $have_one) {
|
||||
|
||||
$date = date("Y-m-d H:i:s");
|
||||
try {
|
||||
// file_put_contents("/xtmp/debug-calc.log", "$date : $tc_name => \$f_value = $formula; \n");
|
||||
// file_put_contents("/xtmp/debug-calc.log", "$date : Formula : $org_formula\n",FILE_APPEND);
|
||||
// file_put_contents("/xtmp/debug-calc.log", print_r($drows,true),FILE_APPEND);
|
||||
|
||||
eval("\$f_value = $formula;");
|
||||
//formating
|
||||
$f_value = $this->format_value($f_value, $r["Nat_TestID"]);
|
||||
if (is_numeric($f_value)) {
|
||||
$f_value = $this->format_value($f_value, $r["Nat_TestID"]);
|
||||
}
|
||||
$od_id = $r["T_OrderDetailID"];
|
||||
$sql = "update t_orderdetail set T_OrderDetailResult = ?
|
||||
where T_OrderDetailID = ?";
|
||||
$this->db->query($sql, array($f_value, $od_id));
|
||||
|
||||
if ($tc_id == 2) {
|
||||
$sql = "insert into t_order_calc(T_OrderCalcT_OrderDetailID,
|
||||
T_OrderCalcFormula,T_OrderCalcResult) values(?,?,?)";
|
||||
$this->db->query($sql, array($od_id, $formula . " | " . $s_code_value, $f_value));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
//print_r($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function format_value($f_value, $nat_test_id)
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("onedev", true);
|
||||
$sql = "select * from m_instrumentmethode
|
||||
where M_InstrumentMethodeIsActive = 'Y'
|
||||
and M_InstrumentMethodeNat_TestID = ?
|
||||
limit 0,1";
|
||||
$qry = $this->db->query($sql, array($nat_test_id));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
if ($f_value > 0) {
|
||||
$fmt = $rows[0]["M_InstrumentMethodeResultFormatAboveSF"];
|
||||
} else {
|
||||
$fmt = $rows[0]["M_InstrumentMethodeResultFormatSF"];
|
||||
}
|
||||
$idx = strpos($fmt, ".");
|
||||
$dec = strlen($fmt) - $idx;
|
||||
if ($dec > 0) $dec = $dec - 1;
|
||||
return number_format($f_value, $dec);
|
||||
}
|
||||
}
|
||||
return number_format($f_value, 0, ".", ",");
|
||||
}
|
||||
}
|
||||
116
application/libraries/Resultcalcv2.php
Normal file
116
application/libraries/Resultcalcv2.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class ResultCalcv2 {
|
||||
public function auto($id)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select
|
||||
T_TestCalculationID,T_TestCalculationFormula,
|
||||
T_OrderDetailID, T_OrderDetailT_TestID, T_TestNat_TestID Nat_TestID,
|
||||
T_TestCalculationID,T_OrderDetailResult,
|
||||
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) / 365 AgeInYear,
|
||||
T_TestCalculationNat_SexID
|
||||
from t_orderdetail
|
||||
join t_orderheader on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
||||
and T_OrderHeaderID = ?
|
||||
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
||||
join t_test on T_OrderDetailT_TestID = T_TestID
|
||||
and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
join t_testcalculation on T_TestNat_TestID = T_TestCalculationNat_TestID
|
||||
and T_TestCalculationIsActive = 'Y'
|
||||
and (
|
||||
T_TestCalculationNat_SexID = M_PatientM_SexID
|
||||
or
|
||||
T_TestCalculationNat_SexID = 0
|
||||
)
|
||||
";
|
||||
|
||||
$sql_det = "select T_TestCalculationDetailCode, T_OrderDetailResult
|
||||
from
|
||||
t_testcalculation_detail td
|
||||
join t_testcalculation on T_TestCalculationID = T_TestCalculationDetailT_TestCalculationID
|
||||
and T_TestCalculationID = ?
|
||||
join t_test t on td.T_TestCalculationDetailNat_TestID = T_TestNat_TestID
|
||||
left join t_orderdetail on T_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y'
|
||||
and T_OrderDetailT_OrderHeaderID = ?
|
||||
where T_OrderDetailID is not null";
|
||||
|
||||
|
||||
$qry = $this->db->query($sql, array($id));
|
||||
$rows = $qry->result_array();
|
||||
if ( count($rows) > 0 ) {
|
||||
foreach($rows as $r) {
|
||||
$tc_id = $r["T_TestCalculationID"];
|
||||
$qry_det = $this->db->query($sql_det, array($tc_id, $id));
|
||||
$drows = $qry_det->result_array();
|
||||
$formula = $r["T_TestCalculationFormula"];
|
||||
$have_all = true;
|
||||
$have_one = false;
|
||||
$formula = str_replace("AGE",$r["AgeInYear"], $formula);
|
||||
$flag_recursive = false;
|
||||
if (strpos($formula,"[REC]") > -1 ) {
|
||||
$flag_recursive = true;
|
||||
}
|
||||
echo "$formula " . $r["T_OrderDetailResult"] . "\n";
|
||||
if ( ! $flag_recursive ) {
|
||||
if( trim($r["T_OrderDetailResult"]) != "") continue;
|
||||
}
|
||||
|
||||
$formula = str_replace("[REC]","", $formula);
|
||||
foreach($drows as $dr) {
|
||||
$code = $dr["T_TestCalculationDetailCode"];
|
||||
$value = $dr["T_OrderDetailResult"];
|
||||
echo "$code , $value , $formula \n";
|
||||
if($dr["T_OrderDetailResult"] == "" ) {
|
||||
$have_all = false;
|
||||
break;
|
||||
}
|
||||
$have_one = true;
|
||||
$formula = str_replace($code, $value,$formula);
|
||||
}
|
||||
if ($have_all && $have_one) {
|
||||
|
||||
eval("\$f_value = $formula;");
|
||||
//formating
|
||||
echo "\n$f_value ..";
|
||||
$f_value = $this->format_value($f_value,$r["Nat_TestID"]);
|
||||
if (is_numeric($f_value)) {
|
||||
$f_value = $this->format_value($f_value,$r["Nat_TestID"]);
|
||||
}
|
||||
$od_id = $r["T_OrderDetailID"];
|
||||
$sql = "update t_orderdetail set T_OrderDetailResult = ?
|
||||
where T_OrderDetailID = ?";
|
||||
$this->db->query($sql, array($f_value,$od_id));
|
||||
$sql = "insert into t_order_calc(T_OrderCalcT_OrderDetailID,
|
||||
T_OrderCalcFormula,T_OrderCalcResult) values(?,?,?)";
|
||||
$this->db->query($sql, array($od_id,$formula,$f_value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function format_value($f_value, $nat_test_id){
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select * from m_instrumentmethode
|
||||
where M_InstrumentMethodeIsActive = 'Y'
|
||||
and M_InstrumentMethodeNat_TestID = ?
|
||||
limit 0,1";
|
||||
$qry = $this->db->query($sql, array($nat_test_id) );
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
if ($f_value > 0 ) {
|
||||
$fmt = $rows[0]["M_InstrumentMethodeResultFormatAboveSF"];
|
||||
} else {
|
||||
$fmt = $rows[0]["M_InstrumentMethodeResultFormatSF"];
|
||||
}
|
||||
$idx = strpos($fmt,".");
|
||||
$dec = strlen($fmt) - $idx;
|
||||
if ($dec > 0 ) $dec = $dec -1;
|
||||
return number_format($f_value,$dec);
|
||||
}
|
||||
}
|
||||
return number_format($f_value,0,".",",");
|
||||
}
|
||||
}
|
||||
49
application/libraries/Sas_s3.php
Normal file
49
application/libraries/Sas_s3.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
require FCPATH . "vendor/aws_v3/aws-autoloader.php";
|
||||
|
||||
date_default_timezone_set("Asia/Jakarta");
|
||||
|
||||
class Sas_s3
|
||||
{
|
||||
var $bucket;
|
||||
var $s3;
|
||||
var $endpoint = "https://is3.cloudhost.id";
|
||||
function __construct()
|
||||
{
|
||||
$this->bucket = "audio-sample";
|
||||
$this->s3 = new Aws\S3\S3Client([
|
||||
"region" => "us-east-1",
|
||||
"endpoint" => $this->endpoint,
|
||||
"use_path_style_endpoint" => true,
|
||||
"credentials" => [
|
||||
"key" => "DLBFBBB8R22W4B5IE7PC",
|
||||
"secret" => "byCv726DN1TCQvLVHdSLMJg3K0i3Ajhm4rXPAVCu"
|
||||
]
|
||||
]);
|
||||
}
|
||||
function create_bucket($bucket)
|
||||
{
|
||||
$result = $this->s3->createBucket(["Bucket" => $bucket]);
|
||||
return $result;
|
||||
}
|
||||
function upload($bucket, $key, $contentType, $body)
|
||||
{
|
||||
$result = $this->s3->putObject(
|
||||
[
|
||||
"Bucket" => $bucket,
|
||||
"Key" => $key,
|
||||
"Body" => $body,
|
||||
"ContentType" => $contentType
|
||||
]
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
// avail : 10 minutes
|
||||
function show_url($bucket, $key, $avail)
|
||||
{
|
||||
$cmd = $this->s3->getCommand("GetObject", ['Bucket' => $bucket, 'Key' => $key]);
|
||||
$request = $this->s3->createPresignedRequest($cmd, '+20 minutes');
|
||||
$presignedUrl = $request->getUri();
|
||||
return $presignedUrl;
|
||||
}
|
||||
}
|
||||
584
application/libraries/Satu_sehat.php
Normal file
584
application/libraries/Satu_sehat.php
Normal file
@@ -0,0 +1,584 @@
|
||||
<?php
|
||||
class Satu_sehat
|
||||
{
|
||||
var $base_url, $base_consent_url, $base_oauth_url;
|
||||
var $is_staging, $organizationID;
|
||||
var $key, $secret;
|
||||
var $tz;
|
||||
var $db, $dbname;
|
||||
function __construct()
|
||||
{
|
||||
$this->tz = "+07:00";
|
||||
$this->is_staging = false;
|
||||
$this->base_url = "https://api-satusehat.kemkes.go.id/fhir-r4/v1";
|
||||
$this->base_oauth_url = "https://api-satusehat.kemkes.go.id/oauth2/v1";
|
||||
$this->base_consent_url = "https://api-satusehat.dto.kemkes.go.id/consent/v1";
|
||||
$CI = &get_instance();
|
||||
$this->db = $CI->load->database("default", true);
|
||||
|
||||
$this->dbname = "one_health";
|
||||
if ($this->is_staging) {
|
||||
$this->base_url = "https://api-satusehat-stg.kemkes.go.id/fhir-r4/v1";
|
||||
$this->base_oauth_url = "https://api-satusehat-stg.kemkes.go.id/oauth2/v1";
|
||||
$this->base_consent_url = "https://api-satusehat-stg.dto.kemkes.go.id/consent/v1";
|
||||
$this->dbname = "one_health_dev";
|
||||
}
|
||||
$this->get_organization_id();
|
||||
}
|
||||
function load_clinic()
|
||||
{
|
||||
$this->dbname = "one_health_clinic";
|
||||
}
|
||||
function ss_organization()
|
||||
{
|
||||
$this->get_organization_id();
|
||||
$o_resp = $this->ss_get("/Organization/{$this->organizationID}");
|
||||
$resp = $this->objToArray($o_resp);
|
||||
$id = $resp["id"];
|
||||
$name = $resp["name"];
|
||||
$x_type = $resp["type"][0]["coding"][0];
|
||||
$type = $x_type["display"];
|
||||
$code = $x_type["code"];
|
||||
$system = $x_type["system"];
|
||||
return json_encode([
|
||||
"ID" => $id,
|
||||
"Name" => $name,
|
||||
"Type" => $type,
|
||||
"CodeSystem" => $code . " | " . $system,
|
||||
]);
|
||||
}
|
||||
|
||||
function search_practicioner_by_nik($nik, $debug = "")
|
||||
{
|
||||
$service = "/Practitioner?identifier=https://fhir.kemkes.go.id/id/nik|" . $nik;
|
||||
$o_resp = $this->ss_get($service, $debug);
|
||||
$resp = $this->objToArray($o_resp);
|
||||
if (count($resp["entry"]) > 0) {
|
||||
$rs = $resp["entry"][0]["resource"];
|
||||
return json_encode([
|
||||
"status" => "OK",
|
||||
"ihsID" => $rs["id"],
|
||||
"name" => $rs["name"][0]["text"]
|
||||
]);
|
||||
}
|
||||
return json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Practitioner not found [$nik]"
|
||||
]);
|
||||
}
|
||||
|
||||
function search_patient_by_nik($nik, $debug = "")
|
||||
{
|
||||
$service = "/Patient?identifier=https://fhir.kemkes.go.id/id/nik|" . $nik;
|
||||
$resp = $this->ss_get($service);
|
||||
if ($debug != "") {
|
||||
echo "resp : ";
|
||||
print_r($resp);
|
||||
}
|
||||
$a_resp = $this->objToArray($resp);
|
||||
if (isset($a_resp["entry"][0]["resource"]["id"])) {
|
||||
return $a_resp["entry"][0]["resource"]["id"];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function location_by_organization($organizationIhsID, $debug = "")
|
||||
{
|
||||
$service = "/Location?organization=" . $organizationIhsID;
|
||||
$resp = $this->ss_get($service);
|
||||
if ($debug != "") {
|
||||
echo "resp : ";
|
||||
print_r($resp);
|
||||
}
|
||||
$a_resp = $this->objToArray($resp);
|
||||
return $a_resp;
|
||||
}
|
||||
|
||||
function location_create(
|
||||
$code,
|
||||
$name,
|
||||
$description,
|
||||
$address,
|
||||
$city,
|
||||
$kodePos,
|
||||
$administrativeCode,
|
||||
$rt,
|
||||
$rw,
|
||||
$phone,
|
||||
$type,
|
||||
$partOf = "",
|
||||
$email = "",
|
||||
$fax = "",
|
||||
$url = "",
|
||||
$long = "",
|
||||
$lat = ""
|
||||
) {
|
||||
$this->get_organization_id();
|
||||
$organizationID = $this->organizationID;
|
||||
list($type_code, $type_display) = explode("^", $type);
|
||||
$telecom = [];
|
||||
$telecom[] = ["system" => "phone", "value" => "$phone", "use" => "work"];
|
||||
if ($fax != "") $telecom[] = ["system" => "fax", "value" => "$fax", "use" => "work"];
|
||||
if ($email != "") $telecom[] = ["system" => "email", "value" => "$email"];
|
||||
if ($url != "") $telecom[] = ["system" => "url", "value" => "$url"];
|
||||
$provCode = substr($administrativeCode, 0, 2);
|
||||
$cityCode = substr($administrativeCode, 0, 4);
|
||||
$districtCode = substr($administrativeCode, 0, 7);
|
||||
$villageCode = substr($administrativeCode, 0, 10);
|
||||
|
||||
$data = [
|
||||
"resourceType" => "Location",
|
||||
"identifier" => [
|
||||
[
|
||||
"system" => "http://sys-ids.kemkes.go.id/location/{$organizationID}",
|
||||
"value" => "$code",
|
||||
],
|
||||
],
|
||||
"status" => "active",
|
||||
"name" => "$name",
|
||||
"description" => "$description",
|
||||
"mode" => "instance",
|
||||
"telecom" => $telecom,
|
||||
"address" => [
|
||||
"use" => "work",
|
||||
"line" => [
|
||||
$address,
|
||||
],
|
||||
"city" => "$city",
|
||||
"postalCode" => "$kodePos",
|
||||
"country" => "ID",
|
||||
"extension" => [
|
||||
[
|
||||
"url" =>
|
||||
"https://fhir.kemkes.go.id/r4/StructureDefinition/administrativeCode",
|
||||
"extension" => [
|
||||
["url" => "province", "valueCode" => $provCode],
|
||||
["url" => "city", "valueCode" => $cityCode],
|
||||
["url" => "district", "valueCode" => "$districtCode"],
|
||||
["url" => "village", "valueCode" => "$villageCode"],
|
||||
["url" => "rt", "valueCode" => "$rt"],
|
||||
["url" => "rw", "valueCode" => "$rw"],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
"physicalType" => [
|
||||
"coding" => [
|
||||
[
|
||||
"system" =>
|
||||
"http://terminology.hl7.org/CodeSystem/location-physical-type",
|
||||
"code" => "$type_code",
|
||||
"display" => "$type_display",
|
||||
],
|
||||
],
|
||||
],
|
||||
"position" => [
|
||||
"longitude" => intval($long),
|
||||
"latitude" => intval($lat),
|
||||
"altitude" => 0,
|
||||
],
|
||||
"managingOrganization" => ["reference" => "Organization/{$organizationID}"],
|
||||
];
|
||||
if ($partOf != "") {
|
||||
$data["partOf"] = [
|
||||
"reference" => "Location/$partOf"
|
||||
];
|
||||
}
|
||||
$service = "/Location";
|
||||
$resp = $this->ss_post($service, $data);
|
||||
$oresp = $this->objToArray($resp);
|
||||
if (!isset($oresp["id"])) {
|
||||
header("Content-Type: text/plain");
|
||||
print_r($data);
|
||||
print_r($resp);
|
||||
}
|
||||
return $oresp;
|
||||
}
|
||||
|
||||
function location_nonactive(
|
||||
$ihsID
|
||||
) {
|
||||
$this->get_organization_id();
|
||||
$data = [
|
||||
[
|
||||
"op" => "replace",
|
||||
"path" => "/status",
|
||||
"value" => "inactive"
|
||||
]
|
||||
];
|
||||
|
||||
$service = "/Location/$ihsID";
|
||||
$resp = $this->ss_patch($service, $data);
|
||||
return $this->objToArray($resp);
|
||||
}
|
||||
function get_location($locationID)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function encounter_by_id($encounterID)
|
||||
{
|
||||
$this->get_organization_id();
|
||||
$service = "/Encounter/$";
|
||||
$resp = $this->ss_get($service);
|
||||
return $this->objToArray($resp);
|
||||
}
|
||||
function encounter_by_subject($patientIhsID)
|
||||
{
|
||||
$this->get_organization_id();
|
||||
$service = "/Encounter?subject=$patientIhsID";
|
||||
$resp = $this->ss_get($service);
|
||||
return $this->objToArray($resp);
|
||||
}
|
||||
function encounter(
|
||||
$orderDate,
|
||||
$patientIhsID,
|
||||
$patientName,
|
||||
$doctorIhsID,
|
||||
$doctorName,
|
||||
$locationID,
|
||||
$locationName,
|
||||
$labNumber,
|
||||
$tz = "+07:00",
|
||||
$payload_only = false
|
||||
) {
|
||||
$service = "/Encounter";
|
||||
$xdate = substr($orderDate, 0, 10) . "T" . substr($orderDate, 11) . $tz;
|
||||
$this->get_organization_id();
|
||||
$param = $this->encounter_param(
|
||||
$patientIhsID,
|
||||
$patientName,
|
||||
$doctorIhsID,
|
||||
$doctorName,
|
||||
$locationID,
|
||||
$locationName,
|
||||
$this->organizationID,
|
||||
$labNumber,
|
||||
$xdate
|
||||
);
|
||||
$payload = json_encode($param);
|
||||
if ($payload_only) {
|
||||
return ["", "", $payload, ""];
|
||||
}
|
||||
$jresp = $this->ss_post($service, $param);
|
||||
$resp = $this->objToArray($jresp);
|
||||
$response = json_encode($resp);
|
||||
if (is_array($resp) && isset($resp["id"])) {
|
||||
$encounterResponseID = $resp["id"];
|
||||
return [$encounterResponseID, "", $payload, $response];
|
||||
} else {
|
||||
return ["", $response, $payload, $response];
|
||||
}
|
||||
}
|
||||
function encounter_param(
|
||||
$patientIhs,
|
||||
$patientName,
|
||||
$dpjpIhs,
|
||||
$dpjpName,
|
||||
$locationIhs,
|
||||
$locationName,
|
||||
$organizationID,
|
||||
$orderHeaderNumber,
|
||||
$dateTime // 2022-06-14T07:00:00+07:00
|
||||
) {
|
||||
if ($this->is_staging) {
|
||||
$dpjpIhs = "N10000001";
|
||||
$dpjpName = "Dokter Bronsig";
|
||||
}
|
||||
$encounterParam = [
|
||||
"resourceType" => "Encounter",
|
||||
"status" => "arrived",
|
||||
"class" => [
|
||||
"system" => "http://terminology.hl7.org/CodeSystem/v3-ActCode",
|
||||
"code" => "AMB",
|
||||
"display" => "ambulatory"
|
||||
],
|
||||
"subject" => [
|
||||
"reference" => "Patient/{$patientIhs}",
|
||||
"display" => "$patientName"
|
||||
],
|
||||
"participant" => [
|
||||
[
|
||||
"type" => [
|
||||
[
|
||||
"coding" => [
|
||||
[
|
||||
"system" => "http://terminology.hl7.org/CodeSystem/v3-ParticipationType",
|
||||
"code" => "ATND",
|
||||
"display" => "attender"
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
"individual" => [
|
||||
"reference" => "Practitioner/{$dpjpIhs}",
|
||||
"display" => "$dpjpName"
|
||||
]
|
||||
]
|
||||
],
|
||||
"period" => [
|
||||
"start" => "$dateTime",
|
||||
],
|
||||
"location" => [
|
||||
[
|
||||
"location" => [
|
||||
"reference" => "Location/$locationIhs",
|
||||
"display" => "$locationName"
|
||||
]
|
||||
]
|
||||
],
|
||||
"statusHistory" => [
|
||||
[
|
||||
"status" => "arrived",
|
||||
"period" => [
|
||||
"start" => $dateTime
|
||||
]
|
||||
]
|
||||
],
|
||||
"serviceProvider" => [
|
||||
"reference" => "Organization/{$organizationID}"
|
||||
],
|
||||
"identifier" => [
|
||||
[
|
||||
"system" => "http://sys-ids.kemkes.go.id/encounter/{$organizationID}",
|
||||
"value" => "$orderHeaderNumber"
|
||||
]
|
||||
]
|
||||
];
|
||||
return $encounterParam;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// helper
|
||||
function get_organization_id()
|
||||
{
|
||||
|
||||
$sql = "SELECT organizationID
|
||||
FROM {$this->dbname}.organization
|
||||
JOIN m_branch ON organizationM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'
|
||||
WHERE organizationIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0) {
|
||||
$this->organizationID = $rows[0]["organizationID"];
|
||||
}
|
||||
}
|
||||
|
||||
function ss_patch($service, $data)
|
||||
{
|
||||
$token = $this->get_token();
|
||||
$authorization = "Authorization: Bearer " . $token;
|
||||
$xbase_url = $this->base_url;
|
||||
$url = $xbase_url . "$service";
|
||||
$ch = curl_init($url);
|
||||
# Setup request to send json via POST.
|
||||
$payload = json_encode($data);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json-patch+json', $authorization));
|
||||
# Return response instead of printing.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
# Send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# Print response.
|
||||
$data_rst = json_decode($result);
|
||||
return $data_rst;
|
||||
}
|
||||
|
||||
function get_client_key($debug = "")
|
||||
{
|
||||
$sql = "select * from {$this->dbname}.client where clientIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
return [false, "", ""];
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
if ($debug != "") {
|
||||
print_r([false, "", ""]);
|
||||
}
|
||||
return [false, "", ""];
|
||||
}
|
||||
if ($debug != "") {
|
||||
print_r([true, $rows[0]["clientKey"], $rows[0]["clientSecret"]]);
|
||||
}
|
||||
|
||||
return [true, $rows[0]["clientKey"], $rows[0]["clientSecret"]];
|
||||
}
|
||||
|
||||
function reset_token()
|
||||
{
|
||||
$sql = "delete from {$this->dbname}.token ";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "ERR : " . $this->db->error()["message"];
|
||||
echo " " . $this->db->last_query();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function put_token()
|
||||
{
|
||||
$auth_url = $this->base_oauth_url;
|
||||
$url = $auth_url . "/accesstoken?grant_type=client_credentials";
|
||||
list($status, $key, $secret) = $this->get_client_key();
|
||||
$data = [
|
||||
"client_id" => $key,
|
||||
"client_secret" => $secret
|
||||
];
|
||||
$ch = curl_init($url);
|
||||
$post_data = http_build_query($data);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
if ($result) {
|
||||
$token_rst = json_decode($result);
|
||||
$sql = "select count(*) as xcount, tokenID
|
||||
from {$this->dbname}.token
|
||||
where
|
||||
tokenIsActive = 'y'
|
||||
";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "get count token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst_count = $qry->row_array();
|
||||
// print_r($token_rst);
|
||||
if ($rst_count['xcount'] > 0) {
|
||||
$sql = "update {$this->dbname}.token set tokenValue = ?, tokenExpired = date_add(now(), interval 50 minute)
|
||||
where tokenID = ?";
|
||||
$qry = $this->db->query($sql, [$token_rst->access_token, $rst_count['tokenID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("refresh token error", $this->db->last_query());
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$sql = "update {$this->dbname}.token set tokenIsActive = 'N' where tokenIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "nonactive token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "insert into {$this->dbname}.token(tokenValue,tokenExpired) values(?,date_add(now(), interval 50 minute))";
|
||||
$qry = $this->db->query($sql, [$token_rst->access_token]);
|
||||
if (!$qry) {
|
||||
echo "insert token error";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "select tokenValue
|
||||
from {$this->dbname}.token
|
||||
where
|
||||
tokenIsActive = 'Y' limit 1
|
||||
";
|
||||
$qry = $this->db->query($sql);
|
||||
if (!$qry) {
|
||||
echo "get token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
return $qry->row()->tokenValue;
|
||||
}
|
||||
}
|
||||
|
||||
function get_token()
|
||||
{
|
||||
$sql = "SELECT COUNT(*) as xcount, tokenValue
|
||||
FROM {$this->dbname}.token
|
||||
WHERE tokenIsActive = 'Y' AND NOW() < tokenExpired AND tokenValue IS NOT NULL ";
|
||||
$qry = $this->db->query($sql);
|
||||
$this->check_error($qry, "select token");
|
||||
|
||||
$data_token = $qry->row_array();
|
||||
//print_r($data_token);
|
||||
if ($data_token['xcount'] > 0) {
|
||||
return $data_token['tokenValue'];
|
||||
} else {
|
||||
return $this->put_token();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function ss_post($service, $data)
|
||||
{
|
||||
$token = $this->get_token();
|
||||
$authorization = "Authorization: Bearer " . $token;
|
||||
$xbase_url = $this->base_url;
|
||||
$url = $xbase_url . "$service";
|
||||
$ch = curl_init($url);
|
||||
# Setup request to send json via POST.
|
||||
$payload = json_encode($data);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization));
|
||||
# Return response instead of printing.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
# Send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# Print response.
|
||||
$data_rst = json_decode($result);
|
||||
return $data_rst;
|
||||
}
|
||||
function ss_get($service, $debug = "")
|
||||
{
|
||||
$token = $this->get_token();
|
||||
$authorization = "Authorization: Bearer " . $token;
|
||||
$xbase_url = $this->base_url;
|
||||
$url = $xbase_url . "$service";
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization));
|
||||
# Return response instead of printing.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
# Send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# Print response.
|
||||
if ($debug != "") {
|
||||
echo "url : $url \n";
|
||||
print_r($result);
|
||||
}
|
||||
$data_rst = json_decode($result);
|
||||
return $data_rst;
|
||||
}
|
||||
protected function objToArray($obj)
|
||||
{
|
||||
if (!is_object($obj) && !is_array($obj)) {
|
||||
return $obj;
|
||||
}
|
||||
foreach ($obj as $key => $value) {
|
||||
$arr[$key] = $this->objToArray($value);
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
function check_error($qry, $stage)
|
||||
{
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => $this->db->error(),
|
||||
"sql" => $this->db->last_query()
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
244
application/libraries/Satusehat.php
Normal file
244
application/libraries/Satusehat.php
Normal file
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
defined("BASEPATH") or exit("No direct script access allowed");
|
||||
class Satusehat
|
||||
{
|
||||
//var $xbase_url = "https://api-satusehat-dev.dto.kemkes.go.id/fhir-r4/v1";
|
||||
function __construct()
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db_onedev = $CI->load->database("default", true);
|
||||
|
||||
}
|
||||
|
||||
function clean_mysqli_connection( $dbc )
|
||||
{
|
||||
while( mysqli_more_results($dbc) )
|
||||
{
|
||||
if(mysqli_next_result($dbc))
|
||||
{
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
if( get_class($result) == 'mysqli_stmt' )
|
||||
{
|
||||
mysqli_stmt_free_result($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*function get_token(){
|
||||
$sql = "SELECT COUNT(*) as xcount, tokenValue
|
||||
FROM one_health.token
|
||||
WHERE tokenIsActive = 'Y' AND NOW() < tokenExpired AND tokenValue IS NOT NULL
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "select token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_token = $qry->row_array();
|
||||
//print_r($data_token);
|
||||
if($data_token['xcount'] > 0){
|
||||
return $data_token['tokenValue'];
|
||||
}else{
|
||||
return $this->putx_token();
|
||||
}
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
function get_new_token(){
|
||||
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => 'https://api-satusehat-dev.dto.kemkes.go.id/oauth2/v1/accesstoken?grant_type=client_credentials',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||
CURLOPT_POSTFIELDS => 'client_id=6PukKqO0RQqu0cKBOC8EKGcXQySfPR4aVkiVmuTgkx5xvva4&client_secret=89ZqsmY3z5W7rVscHTp9gJoAWWiAZG4A2unS3maTw3DxBFxTdaRsSeTUbD8mRN3p',
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
echo $response;
|
||||
|
||||
}
|
||||
|
||||
function put_token(){
|
||||
$auth_url = "https://api-satusehat-dev.dto.kemkes.go.id/oauth2/v1";
|
||||
//API URL
|
||||
$url = $auth_url."/accesstoken?grant_type=client_credentials";
|
||||
//echo $url;
|
||||
|
||||
$data = [
|
||||
"client_id" => "6PukKqO0RQqu0cKBOC8EKGcXQySfPR4aVkiVmuTgkx5xvva4",
|
||||
"client_secret" => "89ZqsmY3z5W7rVscHTp9gJoAWWiAZG4A2unS3maTw3DxBFxTdaRsSeTUbD8mRN3p"
|
||||
];
|
||||
|
||||
|
||||
$ch = curl_init($url);
|
||||
# Setup request to send json via POST.
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch,CURLOPT_HTTPHEADER,
|
||||
array(
|
||||
'Content-Type: application/x-www-form-urlencoded'
|
||||
)
|
||||
);
|
||||
# Return response instead of printing.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
# Send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# Print response.
|
||||
print_r($result);
|
||||
//echo $token_rst->access_token;
|
||||
if($result){
|
||||
$token_rst = json_decode($result);
|
||||
|
||||
$sql = "SELECT COUNT(*) as xcount, tokenID
|
||||
FROM one_health.token
|
||||
WHERE
|
||||
tokenIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "get count token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$rst_count = $qry->row_array();
|
||||
|
||||
if($rst_count['xcount'] > 0){
|
||||
$sql = "UPDATE one_health.token SET tokenValue = ?, tokenExpired = DATE_ADD(NOW(), INTERVAL 50 MINUTE)
|
||||
WHERE tokenID = ?";
|
||||
$qry = $this->db_onedev->query($sql, [$token_rst->access_token,$rst_count['tokenID']]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("refresh token error", $this->db_onedev->last_query());
|
||||
exit;
|
||||
}
|
||||
}else{
|
||||
$sql = "UPDATE one_health.token SET tokenIsActive = 'N' WHERE tokenIsActive = 'Y'";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "nonactive token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO one_health.token(tokenValue,tokenExpired) VALUES(?,DATE_ADD(NOW(), INTERVAL 50 MINUTE))";
|
||||
$qry = $this->db_onedev->query($sql, [$token_rst->access_token]);
|
||||
if (!$qry) {
|
||||
echo "insert token error";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT tokenValue
|
||||
FROM one_health.token
|
||||
WHERE
|
||||
tokenIsActive = 'Y' LIMIT 1
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "get token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
return $qry->row()->tokenValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*function search_practicioner_by_nik($nik){
|
||||
$sql = "SELECT tokenValue
|
||||
FROM one_health.token
|
||||
WHERE
|
||||
tokenIsActive = 'Y' LIMIT 1
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if (!$qry) {
|
||||
echo "get token error";
|
||||
exit;
|
||||
}
|
||||
|
||||
$token = $qry->row()->tokenValue;
|
||||
|
||||
$authorization = "Authorization: Bearer ".$token;
|
||||
//API URL
|
||||
$url = $this->xbase_url."/Practitioner?identifier=https://fhir.kemkes.go.id/id/nik|".$nik;
|
||||
//echo $url;
|
||||
|
||||
|
||||
$ch = curl_init($url);
|
||||
# Setup request to send json via POST.
|
||||
//$payload = json_encode($data);
|
||||
|
||||
//curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
|
||||
# Return response instead of printing.
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
# Send request.
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
# Print response.
|
||||
$data_rst = json_decode($result);
|
||||
print_r($result);
|
||||
|
||||
return $data_rst;
|
||||
}*/
|
||||
|
||||
function gen_uuid() {
|
||||
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||
// 32 bits for "time_low"
|
||||
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
|
||||
|
||||
// 16 bits for "time_mid"
|
||||
mt_rand( 0, 0xffff ),
|
||||
|
||||
// 16 bits for "time_hi_and_version",
|
||||
// four most significant bits holds version number 4
|
||||
mt_rand( 0, 0x0fff ) | 0x4000,
|
||||
|
||||
// 16 bits, 8 bits for "clk_seq_hi_res",
|
||||
// 8 bits for "clk_seq_low",
|
||||
// two most significant bits holds zero and one for variant DCE1.1
|
||||
mt_rand( 0, 0x3fff ) | 0x8000,
|
||||
|
||||
// 48 bits for "node"
|
||||
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
|
||||
);
|
||||
}
|
||||
|
||||
protected function objToArray($obj)
|
||||
{
|
||||
// Not an object or array
|
||||
if (!is_object($obj) && !is_array($obj)) {
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// Parse array
|
||||
foreach ($obj as $key => $value) {
|
||||
$arr[$key] = $this->objToArray($value);
|
||||
}
|
||||
|
||||
// Return parsed array
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
69
application/libraries/Soresultlog.php
Normal file
69
application/libraries/Soresultlog.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class Soresultlog
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$CI = &get_instance();
|
||||
$this->db_onedev = $CI->load->database("default", true);
|
||||
$this->db_smartone = $CI->load->database("default", true);
|
||||
}
|
||||
|
||||
function clean_mysqli_connection($dbc)
|
||||
{
|
||||
while (mysqli_more_results($dbc)) {
|
||||
if (mysqli_next_result($dbc)) {
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
if (get_class($result) == 'mysqli_stmt') {
|
||||
mysqli_stmt_free_result($result);
|
||||
} else {
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function step_action($act,$re_id,$userid)
|
||||
{
|
||||
//$CI = &get_instance();
|
||||
//$this->db = $CI->load->database("one", true);
|
||||
|
||||
$sql = "INSERT INTO so_reactionlog(
|
||||
So_REActionLogDate,
|
||||
So_REActionLogSo_ResultEntryID,
|
||||
So_REActionLogAction,
|
||||
So_REActionLogUserID
|
||||
)
|
||||
VALUES(
|
||||
NOW(),?,?,?
|
||||
)";
|
||||
$qry = $this->db_onedev->query($sql, array($re_id,$act,$userid));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db_onedev->error(), true));
|
||||
}else
|
||||
return array(true);
|
||||
}
|
||||
|
||||
public function log_result($data_json,$re_id,$userid)
|
||||
{
|
||||
//$CI = &get_instance();
|
||||
//$this->db = $CI->load->database("one", true);
|
||||
//echo $re_id;
|
||||
$sql = "INSERT INTO cpone_log.log_resultentry_so(
|
||||
Log_ResultEntrySoDate,
|
||||
Log_ResultEntrySoReID,
|
||||
Log_ResultEntrySoJSON,
|
||||
Log_ResultEntrySoUserID
|
||||
)
|
||||
VALUES(
|
||||
NOW(),?,?,?
|
||||
)";
|
||||
$qry = $this->db_onedev->query($sql, array($re_id,$data_json,$userid));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db_onedev->error(), true));
|
||||
}else
|
||||
return array(true);
|
||||
}
|
||||
}
|
||||
547
application/libraries/SsPriceMou.php
Normal file
547
application/libraries/SsPriceMou.php
Normal file
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMou{
|
||||
|
||||
// retrun array status, message
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows,$p_rows, $pn_rows);
|
||||
$qry = $this->db->query("delete from ss_price_mou where Ss_PriceMouM_MouID=?", array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou", $rows);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
public function edit($mouID,$testID,$cito) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
|
||||
$sql = "select * from t_test where T_TestID = ? ";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Test $testID found");
|
||||
}
|
||||
$sasCode = $rows[0]["T_TestSasCode"];
|
||||
if ( strlen($sasCode) == 8 ) {
|
||||
$flagProfile = false;
|
||||
} else {
|
||||
$flagProfile = true;
|
||||
}
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No MOU $mouID found");
|
||||
}
|
||||
$mouName = $rows[0]["M_MouName"];
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
}
|
||||
if ( count($rows) > 0 ) {
|
||||
$r = $rows[0];
|
||||
unset($r["T_TestSasCode"]);
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$sasCode = substr($sasCode,0,8);
|
||||
foreach($rows as $idx => $r ) {
|
||||
if ( strlen($r["T_TestSasCode"]) > 8 ) {
|
||||
unset($rows[$idx]);
|
||||
} else {
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
}
|
||||
if ($cito == 'Y' ) {
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
// for non cito
|
||||
if($flagProfile ) {
|
||||
//wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sasCodeLike = $sasCode . "%";
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
||||
and T_TestSasCode like ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($p_rows as $r) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$p_rows);
|
||||
}
|
||||
//Update Panel yang mengandung Test
|
||||
$sql = "select
|
||||
distinct T_PacketDetailT_PacketID
|
||||
from
|
||||
t_packetdetail
|
||||
where T_PacketDetailIsActive = 'Y'
|
||||
and T_PacketDetailT_TestID = ?";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$packet_ids = "0";
|
||||
foreach($xrows as $r ) {
|
||||
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
||||
}
|
||||
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
foreach($pn_rows as $r ) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$pn_rows);
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
}
|
||||
52
application/libraries/SsPriceMouPx.php
Normal file
52
application/libraries/SsPriceMouPx.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMouPx {
|
||||
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
|
||||
$sql = "select * from ss_price_mou where Ss_PriceMouM_MouID = ? and px_type in ('PR','PXR')";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Ss Price Mou " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$sql ="delete from ss_price_mou_px where Ss_PriceMouPxSs_PriceMouID in ( select Ss_PriceMouID from ss_price_mou
|
||||
where Ss_PriceMouM_MouID = ? )";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Clear Ss Price Mou Px" . print_r($this->db->error(),true));
|
||||
}
|
||||
$a_data = array();
|
||||
foreach($rows as $r) {
|
||||
$j_ct = $r["child_test"];
|
||||
$ct = json_decode($j_ct,true);
|
||||
foreach($ct as $c) {
|
||||
$a_data[] = array(
|
||||
"Ss_PriceMouPxM_MouID" => $r["Ss_PriceMouM_MouID"],
|
||||
"Ss_PriceMouPxSs_PriceMouID" => $r["Ss_PriceMouID"],
|
||||
"Ss_PriceMouPxT_TestID" => $c["T_TestID"],
|
||||
"Ss_PriceMouPxT_TestName" => $c["T_TestName"],
|
||||
"Ss_PriceMouPxT_PriceIsCito" => $c["T_PriceIsCito"],
|
||||
"Ss_PriceMouPxT_PriceM_CompanyID" => $c["T_PriceM_CompanyID"],
|
||||
"Ss_PriceMouPxT_PricePriority" => $c["T_PricePriority"],
|
||||
"Ss_PriceMouPxT_PriceAmount" => $c["T_PriceAmount"],
|
||||
"Ss_PriceMouPxT_PriceDisc" => $c["T_PriceDisc"],
|
||||
"Ss_PriceMouPxT_PriceDiscRp" => $c["T_PriceDiscRp"],
|
||||
"Ss_PriceMouPxT_PriceSubTotal" => $c["T_PriceSubTotal"],
|
||||
"Ss_PriceMouPxT_PriceOther" => $c["T_PriceOther"],
|
||||
"Ss_PriceMouPxT_PriceTotal" => $c["T_PriceTotal"],
|
||||
"Ss_PriceMouPxT_TestForceSell" => $c["T_TestForSell"],
|
||||
"nat_test" => $c["nat_test"]
|
||||
);
|
||||
}
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou_px",$a_data);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Batch Ss Price Mou Px" . print_r($this->db->error(),true));
|
||||
}
|
||||
|
||||
return array(true, "");
|
||||
}
|
||||
}
|
||||
249
application/libraries/Txbranchstatus-cabang.php
Normal file
249
application/libraries/Txbranchstatus-cabang.php
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class TxBranchStatus{
|
||||
|
||||
public function update_multi($stage,$ids ,$username)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$s_ids = join(",",$ids);
|
||||
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
|
||||
from
|
||||
t_orderdetail
|
||||
where T_OrderDetailID in ($s_ids) ";
|
||||
$qry = $this->db->query($sql);
|
||||
$incomingRefID = 0;
|
||||
$s_detail_ids = "0";
|
||||
$s_child_ids = "0";
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows) > 0 ) {
|
||||
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
|
||||
$s_test = "0";
|
||||
foreach($rows as $r) {
|
||||
$s_test .= "," . $r["T_OrderDetailT_TestID"];
|
||||
}
|
||||
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
|
||||
from incoming_ref_detail
|
||||
where incomingRefDetailNewT_OrderHeaderID = ?
|
||||
and incomingRefDetailT_TestID in ($s_test) ";
|
||||
$qryd = $this->db->query($sql, array($headerID));
|
||||
$flag_found = false;
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
|
||||
foreach($rowsd as $r) {
|
||||
$s_detail_ids .= "," . $r["incomingRefDetailID"];
|
||||
}
|
||||
}
|
||||
}
|
||||
//check child
|
||||
if(! $flag_found ) {
|
||||
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
|
||||
from incoming_ref_child
|
||||
where incomingRefChildNewT_OrderHeaderID = ?
|
||||
and incomingRefChildT_TestID in ($s_test) ";
|
||||
$qryd = $this->db->query($sql, array($headerID));
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
|
||||
foreach($rowsd as $r) {
|
||||
$s_child_ids .= "," . $r["incomingRefChildID"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($s_detail_ids == "0" && $s_child_ids == "0" ) {
|
||||
return false;
|
||||
}
|
||||
$sql = "select M_BranchID, M_BranchIPAddress
|
||||
from m_branch
|
||||
join incoming_ref
|
||||
on M_BranchID = incomingRefM_BranchID
|
||||
where incomingRefID = ?";
|
||||
$qry = $this->db->query($sql, array($incomingRefID));
|
||||
$branchID = 0;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows)>0) {
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
|
||||
}
|
||||
}
|
||||
if ($branchID == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$note = "$stage by $username";
|
||||
if ($s_detail_ids!= "0" ) {
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefDetailT_OrderDetailID,
|
||||
incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
? note
|
||||
from incoming_ref_detail
|
||||
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
|
||||
and incomingRefDetailID in ($s_detail_ids)
|
||||
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
|
||||
$qry = $this->db->query($sql, array($note));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$param = json_encode($rows);
|
||||
//insert to
|
||||
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
|
||||
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
|
||||
values (?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
|
||||
}
|
||||
}
|
||||
if ($s_child_ids!= "0" ) {
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
|
||||
'' incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
? note
|
||||
from incoming_ref_child
|
||||
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
|
||||
and incomingRefChildID in ($s_child_ids)
|
||||
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
|
||||
$qry = $this->db->query($sql, array($note));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$param = json_encode($rows);
|
||||
//insert to
|
||||
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
|
||||
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
|
||||
values (?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function update($stage,$orderDetailID,$username)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
|
||||
from
|
||||
t_orderdetail
|
||||
where T_OrderDetailID = ? ";
|
||||
$qry = $this->db->query($sql, array($orderDetailID));
|
||||
$incomingRefID = 0;
|
||||
$incomingRefDetailID = 0;
|
||||
$flag_child = false;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$flag_found = false;
|
||||
if(count($rows) > 0 ) {
|
||||
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
|
||||
$testID = $rows[0]["T_OrderDetailT_TestID"];
|
||||
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
|
||||
from incoming_ref_detail
|
||||
where incomingRefDetailNewT_OrderHeaderID = ?
|
||||
and incomingRefDetailT_TestID = ?";
|
||||
$qryd = $this->db->query($sql, array($headerID,$testID));
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
|
||||
$incomingRefDetailID = $rowsd[0]["incomingRefDetailID"];
|
||||
$flag_found = true;
|
||||
}
|
||||
}
|
||||
//check child
|
||||
if(! $flag_found ) {
|
||||
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
|
||||
from incoming_ref_child
|
||||
where incomingRefChildNewT_OrderHeaderID = ?
|
||||
and incomingRefChildT_TestID = ?";
|
||||
$qryd = $this->db->query($sql, array($headerID,$testID));
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
|
||||
$incomingRefDetailID = $rowsd[0]["incomingRefChildID"];
|
||||
$flag_found = true;
|
||||
$flag_child = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($incomingRefDetailID == 0 || $incomingRefDetailID == "") {
|
||||
return false;
|
||||
}
|
||||
$sql = "select M_BranchID, M_BranchIPAddress
|
||||
from m_branch
|
||||
join incoming_ref
|
||||
on M_BranchID = incomingRefM_BranchID
|
||||
where incomingRefID = ?";
|
||||
$qry = $this->db->query($sql, array($incomingRefID));
|
||||
$branchID = 0;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows)>0) {
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
|
||||
}
|
||||
}
|
||||
if ($branchID == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$note = "$stage by $username";
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefDetailT_OrderDetailID,
|
||||
incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
? note
|
||||
from incoming_ref_detail
|
||||
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
|
||||
and incomingRefDetailID = ?
|
||||
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
|
||||
if ($flag_child ) {
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
|
||||
'' incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
? note
|
||||
from incoming_ref_child
|
||||
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
|
||||
and incomingRefChildID = ?
|
||||
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
|
||||
}
|
||||
$qry = $this->db->query($sql, array($note, $incomingRefDetailID));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$param = json_encode($rows);
|
||||
//insert to
|
||||
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
|
||||
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
|
||||
values (?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
|
||||
}
|
||||
}
|
||||
}
|
||||
300
application/libraries/Txbranchstatus.php
Normal file
300
application/libraries/Txbranchstatus.php
Normal file
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class TxBranchStatus{
|
||||
|
||||
public function update_multi($stage,$ids ,$username)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$s_ids = join(",",$ids);
|
||||
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
|
||||
from
|
||||
t_orderdetail
|
||||
where T_OrderDetailID in ($s_ids) ";
|
||||
$qry = $this->db->query($sql);
|
||||
$incomingRefID = 0;
|
||||
$s_detail_ids = "0";
|
||||
$s_child_ids = "0";
|
||||
$headerID = 0;
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows) > 0 ) {
|
||||
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
|
||||
$s_test = "0";
|
||||
foreach($rows as $r) {
|
||||
$s_test .= "," . $r["T_OrderDetailT_TestID"];
|
||||
}
|
||||
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
|
||||
from incoming_ref_detail
|
||||
where incomingRefDetailNewT_OrderHeaderID = ?
|
||||
and incomingRefDetailT_TestID in ($s_test) ";
|
||||
$qryd = $this->db->query($sql, array($headerID));
|
||||
$flag_found = false;
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
|
||||
foreach($rowsd as $r) {
|
||||
$s_detail_ids .= "," . $r["incomingRefDetailID"];
|
||||
}
|
||||
}
|
||||
}
|
||||
//check child
|
||||
if(! $flag_found ) {
|
||||
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
|
||||
from incoming_ref_child
|
||||
where incomingRefChildNewT_OrderHeaderID = ?
|
||||
and incomingRefChildT_TestID in ($s_test) ";
|
||||
$qryd = $this->db->query($sql, array($headerID));
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
|
||||
foreach($rowsd as $r) {
|
||||
$s_child_ids .= "," . $r["incomingRefChildID"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($s_detail_ids == "0" && $s_child_ids == "0" ) {
|
||||
return false;
|
||||
}
|
||||
$sql = "select M_BranchID, M_BranchIPAddress
|
||||
from m_branch
|
||||
join incoming_ref
|
||||
on M_BranchID = incomingRefM_BranchID
|
||||
where incomingRefID = ?";
|
||||
$qry = $this->db->query($sql, array($incomingRefID));
|
||||
$branchID = 0;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows)>0) {
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
|
||||
}
|
||||
}
|
||||
if ($branchID == 0 ) {
|
||||
return false;
|
||||
}
|
||||
$val_note = "";
|
||||
$val_note_int = "";
|
||||
if ($headerID > 0 ) {
|
||||
$sql = "select T_OrderHeaderAddOnValidationNote, T_OrderHeaderAddOnValidationInternal
|
||||
from t_orderheaderaddon
|
||||
where T_orderHeaderAddOnT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql,array($headerID));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$val_note = $rows[0]["T_OrderHeaderAddOnValidationNote"];
|
||||
$val_note_int = $rows[0]["T_OrderHeaderAddOnValidationInternal"];
|
||||
if ( $val_note == null ) $val_note = "";
|
||||
if ( $val_note_int == null ) $val_note_int = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
$note = "$stage by $username";
|
||||
if ($s_detail_ids!= "0" ) {
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefDetailID,
|
||||
incomingRefDetailT_OrderDetailID,
|
||||
incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
T_OrderDetailNote,
|
||||
? note,
|
||||
? validation_note,
|
||||
? validation_note_internal
|
||||
from incoming_ref_detail
|
||||
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
|
||||
and incomingRefDetailID in ($s_detail_ids)
|
||||
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
|
||||
$qry = $this->db->query($sql, array($note,$val_note,$val_note_int));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$param = json_encode($rows);
|
||||
//insert to
|
||||
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
|
||||
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
|
||||
values (?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
|
||||
}
|
||||
}
|
||||
if ($s_child_ids!= "0" ) {
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefChildID,
|
||||
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
|
||||
'' incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
T_OrderDetailNote,
|
||||
? note,
|
||||
? validation_note,
|
||||
? validation_note_internal
|
||||
from incoming_ref_child
|
||||
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
|
||||
and incomingRefChildID in ($s_child_ids)
|
||||
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
|
||||
$qry = $this->db->query($sql, array($note,$val_note,$val_note_int));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$param = json_encode($rows);
|
||||
//insert to
|
||||
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
|
||||
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
|
||||
values (?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function update($stage,$orderDetailID,$username)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
|
||||
from
|
||||
t_orderdetail
|
||||
where T_OrderDetailID = ? ";
|
||||
$qry = $this->db->query($sql, array($orderDetailID));
|
||||
$incomingRefID = 0;
|
||||
$incomingRefDetailID = 0;
|
||||
$flag_child = false;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$flag_found = false;
|
||||
if(count($rows) > 0 ) {
|
||||
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
|
||||
$testID = $rows[0]["T_OrderDetailT_TestID"];
|
||||
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
|
||||
from incoming_ref_detail
|
||||
where incomingRefDetailNewT_OrderHeaderID = ?
|
||||
and incomingRefDetailT_TestID = ?";
|
||||
$qryd = $this->db->query($sql, array($headerID,$testID));
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
|
||||
$incomingRefDetailID = $rowsd[0]["incomingRefDetailID"];
|
||||
$flag_found = true;
|
||||
}
|
||||
}
|
||||
//check child
|
||||
if(! $flag_found ) {
|
||||
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
|
||||
from incoming_ref_child
|
||||
where incomingRefChildNewT_OrderHeaderID = ?
|
||||
and incomingRefChildT_TestID = ?";
|
||||
$qryd = $this->db->query($sql, array($headerID,$testID));
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
|
||||
$incomingRefDetailID = $rowsd[0]["incomingRefChildID"];
|
||||
$flag_found = true;
|
||||
$flag_child = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($incomingRefDetailID == 0 || $incomingRefDetailID == "") {
|
||||
return false;
|
||||
}
|
||||
$sql = "select M_BranchID, M_BranchIPAddress
|
||||
from m_branch
|
||||
join incoming_ref
|
||||
on M_BranchID = incomingRefM_BranchID
|
||||
where incomingRefID = ?";
|
||||
$qry = $this->db->query($sql, array($incomingRefID));
|
||||
$branchID = 0;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows)>0) {
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
|
||||
}
|
||||
}
|
||||
if ($branchID == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$val_note = "";
|
||||
$val_note_int = "";
|
||||
if ($headerID > 0 ) {
|
||||
$sql = "select T_OrderHeaderAddOnValidationNote, T_OrderHeaderAddOnValidationInternal
|
||||
from t_orderheaderaddon
|
||||
where T_orderHeaderAddOnT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql,array($headerID));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$val_note = $rows[0]["T_OrderHeaderAddOnValidationNote"];
|
||||
$val_note_int = $rows[0]["T_OrderHeaderAddOnValidationInternal"];
|
||||
if ( $val_note == null ) $val_note = "";
|
||||
if ( $val_note_int == null ) $val_note_int = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
$note = "$stage by $username";
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefDetailID,
|
||||
incomingRefDetailT_OrderDetailID,
|
||||
incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
T_OrderDetailNote,
|
||||
? note,
|
||||
? validation_note,
|
||||
? validation_note_internal
|
||||
from incoming_ref_detail
|
||||
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
|
||||
and incomingRefDetailID = ?
|
||||
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
|
||||
if ($flag_child ) {
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefChildID,
|
||||
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
|
||||
'' incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
T_OrderDetailNote,
|
||||
? note,
|
||||
? validation_note,
|
||||
? validation_note_internal
|
||||
from incoming_ref_child
|
||||
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
|
||||
and incomingRefChildID = ?
|
||||
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
|
||||
}
|
||||
$qry = $this->db->query($sql, array($note, $val_note, $val_note_int, $incomingRefDetailID));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$param = json_encode($rows);
|
||||
//insert to
|
||||
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
|
||||
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
|
||||
values (?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
|
||||
}
|
||||
}
|
||||
}
|
||||
296
application/libraries/Txbranchstatus_updated.php
Normal file
296
application/libraries/Txbranchstatus_updated.php
Normal file
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class TxBranchStatus{
|
||||
|
||||
public function update_multi($stage,$ids ,$username)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$s_ids = join(",",$ids);
|
||||
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
|
||||
from
|
||||
t_orderdetail
|
||||
where T_OrderDetailID in ($s_ids) ";
|
||||
$qry = $this->db->query($sql);
|
||||
$incomingRefID = 0;
|
||||
$s_detail_ids = "0";
|
||||
$s_child_ids = "0";
|
||||
$headerID = 0;
|
||||
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows) > 0 ) {
|
||||
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
|
||||
$s_test = "0";
|
||||
foreach($rows as $r) {
|
||||
$s_test .= "," . $r["T_OrderDetailT_TestID"];
|
||||
}
|
||||
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
|
||||
from incoming_ref_detail
|
||||
where incomingRefDetailNewT_OrderHeaderID = ?
|
||||
and incomingRefDetailT_TestID in ($s_test) ";
|
||||
$qryd = $this->db->query($sql, array($headerID));
|
||||
$flag_found = false;
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
|
||||
foreach($rowsd as $r) {
|
||||
$s_detail_ids .= "," . $r["incomingRefDetailID"];
|
||||
}
|
||||
}
|
||||
}
|
||||
//check child
|
||||
if(! $flag_found ) {
|
||||
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
|
||||
from incoming_ref_child
|
||||
where incomingRefChildNewT_OrderHeaderID = ?
|
||||
and incomingRefChildT_TestID in ($s_test) ";
|
||||
$qryd = $this->db->query($sql, array($headerID));
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
|
||||
foreach($rowsd as $r) {
|
||||
$s_child_ids .= "," . $r["incomingRefChildID"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($s_detail_ids == "0" && $s_child_ids == "0" ) {
|
||||
return false;
|
||||
}
|
||||
$sql = "select M_BranchID, M_BranchIPAddress
|
||||
from m_branch
|
||||
join incoming_ref
|
||||
on M_BranchID = incomingRefM_BranchID
|
||||
where incomingRefID = ?";
|
||||
$qry = $this->db->query($sql, array($incomingRefID));
|
||||
$branchID = 0;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows)>0) {
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
|
||||
}
|
||||
}
|
||||
if ($branchID == 0 ) {
|
||||
return false;
|
||||
}
|
||||
$val_note = "";
|
||||
$val_note_int = "";
|
||||
if ($headerID > 0 ) {
|
||||
$sql = "select T_OrderHeaderAddOnValidationNote, T_OrderHeaderAddOnValidationInternal
|
||||
from t_orderheaderaddon
|
||||
where T_orderHeaderAddOnT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql,array($headerID));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$val_note = $rows[0]["T_OrderHeaderAddOnValidationNote"];
|
||||
$val_note_int = $rows[0]["T_OrderHeaderAddOnValidationInternal"];
|
||||
if ( $val_note == null ) $val_note = "";
|
||||
if ( $val_note_int == null ) $val_note_int = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
$note = "$stage by $username";
|
||||
if ($s_detail_ids!= "0" ) {
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefDetailT_OrderDetailID,
|
||||
incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
T_OrderDetailNote,
|
||||
? note,
|
||||
? validation_note,
|
||||
? validation_note_internal
|
||||
from incoming_ref_detail
|
||||
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
|
||||
and incomingRefDetailID in ($s_detail_ids)
|
||||
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
|
||||
$qry = $this->db->query($sql, array($note,$val_note,$val_note_int));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$param = json_encode($rows);
|
||||
//insert to
|
||||
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
|
||||
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
|
||||
values (?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
|
||||
}
|
||||
}
|
||||
if ($s_child_ids!= "0" ) {
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
|
||||
'' incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
T_OrderDetailNote,
|
||||
? note,
|
||||
? validation_note,
|
||||
? validation_note_internal
|
||||
from incoming_ref_child
|
||||
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
|
||||
and incomingRefChildID in ($s_child_ids)
|
||||
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
|
||||
$qry = $this->db->query($sql, array($note,$val_note,$val_note_int));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$param = json_encode($rows);
|
||||
//insert to
|
||||
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
|
||||
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
|
||||
values (?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function update($stage,$orderDetailID,$username)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
|
||||
from
|
||||
t_orderdetail
|
||||
where T_OrderDetailID = ? ";
|
||||
$qry = $this->db->query($sql, array($orderDetailID));
|
||||
$incomingRefID = 0;
|
||||
$incomingRefDetailID = 0;
|
||||
$flag_child = false;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$flag_found = false;
|
||||
if(count($rows) > 0 ) {
|
||||
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
|
||||
$testID = $rows[0]["T_OrderDetailT_TestID"];
|
||||
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
|
||||
from incoming_ref_detail
|
||||
where incomingRefDetailNewT_OrderHeaderID = ?
|
||||
and incomingRefDetailT_TestID = ?";
|
||||
$qryd = $this->db->query($sql, array($headerID,$testID));
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
|
||||
$incomingRefDetailID = $rowsd[0]["incomingRefDetailID"];
|
||||
$flag_found = true;
|
||||
}
|
||||
}
|
||||
//check child
|
||||
if(! $flag_found ) {
|
||||
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
|
||||
from incoming_ref_child
|
||||
where incomingRefChildNewT_OrderHeaderID = ?
|
||||
and incomingRefChildT_TestID = ?";
|
||||
$qryd = $this->db->query($sql, array($headerID,$testID));
|
||||
if($qryd) {
|
||||
$rowsd = $qryd->result_array();
|
||||
if ( count($rowsd) > 0 ) {
|
||||
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
|
||||
$incomingRefDetailID = $rowsd[0]["incomingRefChildID"];
|
||||
$flag_found = true;
|
||||
$flag_child = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($incomingRefDetailID == 0 || $incomingRefDetailID == "") {
|
||||
return false;
|
||||
}
|
||||
$sql = "select M_BranchID, M_BranchIPAddress
|
||||
from m_branch
|
||||
join incoming_ref
|
||||
on M_BranchID = incomingRefM_BranchID
|
||||
where incomingRefID = ?";
|
||||
$qry = $this->db->query($sql, array($incomingRefID));
|
||||
$branchID = 0;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows)>0) {
|
||||
$branchID = $rows[0]["M_BranchID"];
|
||||
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
|
||||
}
|
||||
}
|
||||
if ($branchID == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$val_note = "";
|
||||
$val_note_int = "";
|
||||
if ($headerID > 0 ) {
|
||||
$sql = "select T_OrderHeaderAddOnValidationNote, T_OrderHeaderAddOnValidationInternal
|
||||
from t_orderheaderaddon
|
||||
where T_orderHeaderAddOnT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql,array($headerID));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$val_note = $rows[0]["T_OrderHeaderAddOnValidationNote"];
|
||||
$val_note_int = $rows[0]["T_OrderHeaderAddOnValidationInternal"];
|
||||
if ( $val_note == null ) $val_note = "";
|
||||
if ( $val_note_int == null ) $val_note_int = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
$note = "$stage by $username";
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefDetailT_OrderDetailID,
|
||||
incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
T_OrderDetailNote,
|
||||
? note,
|
||||
? validation_note,
|
||||
? validation_note_internal
|
||||
from incoming_ref_detail
|
||||
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
|
||||
and incomingRefDetailID = ?
|
||||
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
|
||||
if ($flag_child ) {
|
||||
$sql = "select
|
||||
incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
|
||||
'' incomingRefDetailStatus,
|
||||
T_OrderDetailResult,
|
||||
T_OrderDetailNat_NormalValueID,
|
||||
T_OrderDetailVerification,
|
||||
T_OrderDetailValidation,
|
||||
T_OrderDetailNote,
|
||||
? note,
|
||||
? validation_note,
|
||||
? validation_note_internal
|
||||
from incoming_ref_child
|
||||
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
|
||||
and incomingRefChildID = ?
|
||||
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
|
||||
}
|
||||
$qry = $this->db->query($sql, array($note, $val_note, $val_note_int, $incomingRefDetailID));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$param = json_encode($rows);
|
||||
//insert to
|
||||
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
|
||||
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
|
||||
values (?,?,?,?,?)";
|
||||
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
|
||||
}
|
||||
}
|
||||
}
|
||||
63
application/libraries/Wa_krmv3.php
Normal file
63
application/libraries/Wa_krmv3.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
include_once BASEPATH . "../vendor/kirim_pesan/ClientV3.php";
|
||||
|
||||
use KrmPesan\ClientV3;
|
||||
|
||||
class Wa_krmv3
|
||||
{
|
||||
var $id_token = "eyJraWQiOiJnUFdURUFqekZLTmFnTGhSa28rbGszeEhRMCtEWm42Z29XcDR1ZEhvV0RZPSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiIyNTJjNGZiYS0xMGFhLTQ1NzUtOTZjYy01ZDBiZjdmMzE0MDQiLCJjb2duaXRvOmdyb3VwcyI6WyJ1c2VyIiwiREVWIzYyODUyMzY4MTEzMzAiXSwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC5hcC1zb3V0aGVhc3QtMS5hbWF6b25hd3MuY29tXC9hcC1zb3V0aGVhc3QtMV9Fa0M0emJUVXUiLCJjb2duaXRvOnVzZXJuYW1lIjoiMjUyYzRmYmEtMTBhYS00NTc1LTk2Y2MtNWQwYmY3ZjMxNDA0Iiwib3JpZ2luX2p0aSI6ImJjZTcxZTY4LWVhZTYtNGE3MC05ZjA5LTE5MjEyNjFmMWYxNyIsImF1ZCI6IjIybXZnMnNhc2Y5aDZsbTVhdWk4YjByN2pqIiwiZXZlbnRfaWQiOiI3MDMxYjQ0Ni00MjBjLTQ4ZjktOGIzMi1mMGZiMzFlYjUzNzgiLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTY5ODkxMjk1MiwibmFtZSI6IlByYW1pdGEgTGFiIiwiZXhwIjoxNjk4OTk5MzUyLCJpYXQiOjE2OTg5MTI5NTIsImp0aSI6IjU5NjZhZTVjLTkyZDAtNGYxYS05NzVhLTVhMjFjZjlhNjAxZCIsImVtYWlsIjoiaW5mb0BwcmFtaXRhLmNvLmlkIn0.FrIVco9oW4QSwPWWSpUc-CyNGm3hjoDXtrKECBLdKdbyJsX0Qws48S2AXbQ7gqb8dSLpH4tFUyM5boTOxYR55bc8QuN6hF9n9-1QOFfKGyLA37tSdVE-9bziycIUQ5g0cqBH_3eFebAaeDIIYKr6Tu_bs0ZAuRqvjLqj8mSoDNrDaeOhVLKMfFUwXtesjxkOV0TvV_OFQ4_96Q4Kk3wul7R2mJTuONsDa8u1UgWFVrcmRKYzq_qSs6K5eFD_kekRpZrMkNeC4ch3fvP1ZQ3z2SsNVwvLtpRYdFiEYuV91jYtZC33WR6dOL1d-wUdowNXfdGrQlAHOah2NyDbDuF96Q";
|
||||
var $refresh_token = "eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.bTjo6WiUaTZjjUohwGi0M52we5pG-yrqauLHRrFrHD5CTItWuFnceFCtt8l-rxwST9jvBC3VqkOvRkP2sA1M-U4jt0LSP1aJl5dTNo2ejxvCRGyvw7Un5ykM1XqvxYWzVrWC5hi-Jf87sJco2myJqjlHAiPiHmH-vvrcdSiMjEnu83jatHmGimQQzZUq6xKjn6UW5Ok0bEKqOJMh3Lo_32WHpH01G1i26Iz35Dn9yKbzL3wam52tuD3pbTA98fYXeMZGOf0jjJAt-Xk2DAOYiKrkqY6nWW8nuqKqT71PUxKDTooB77qd9F1pqmMG_r97pWXMzpIzO5O1w34jb2cymQ.fLP07rW7cC79w1rm.oMv0SEleK1pi4p-FbjmABIc39N8KRRp6l3cTSi1ndmM4wnnjwLbV9XLYpVPZZ9oz2zhZH9p7h3POgUKzazm4raP_pRA-SeyrqKQZa6U5cACeRmRbIdPMXInjACxiyaSD09rwP3_htgIpz0urTzWt9d0zMXdaczORdSPcC-GHtanHPfDVkr-u9dYG2ZYeJmx-u0NIi2OmgnqUiBJmD5gx1LdzFnrmTizrVeAnxA_fB8FF0isHTLUo3imAgGGG9dgYa_dSodqdWpK9rgX5AtVe5NVAzqudACx5KwOfM7EpwLhaLFI-RA4KXB2OQlMAU3TqBvBjt89Gs6AMtBaFxKg3HWxkOiynLX4hV8I4WnEWhYoAN6sOBcuW6h2Dhqxpd9fDYQdS1VqmgZkBrNzMnmcb91F6QmPs5jMqMK2aL7S_T9I9L6y-ci6OCdDmpwlwM5wsiIK7PBdI367sgWE9-oXGvGopiV_e17FJRqLWItnEjPJoel3hr5jcil5LAie4VGBjUOCY50PjP_gRdxdtwrWgBZu48AuNekHGXlQKy_QyOgLK0WAtXBms0_-VvpUyOKVWOt27ExxweayKfDeLpkX8uh-Iy7VXK2tDUVky7EHCZirQccb93Y0hNaxpEqto0fm12RzycHGye0ScbPh1NoeAcqc77lI6-TmtfcBiweDALrUVriQIMRcbnOrQNSBazYMVVQiNsXrsrBs36yqKV60Y5cScG9d7sq83N9ENLM90Q2XYATnLlE_wOMa9WpYNkNo62fMZQZDNCdzRXcnZNjJvAXhxmlqdCpceg_TbbYmOSge6iq2Qz5gprdbsf89cD-EbgqHUfhZlbQ1wZtTcO0DepY4K3jwseF3CXJbksbfNMGLYVjrIRSeCbOoKJ1EcQqVfP56F9kSAvohOQBTrWQU74pJI9S_m_Gzx21y9eJXbM9XNHhguU2ZcmXFOZSZ65-JApQqdao2gNjkfq-WZQwrW-RctUv2XRUV6MJjkIysx3zpnS8r5zmSYqqcj929aAI7LiL7c2VtMgQLJNiw0023LovrgU2QzMGu8dNw790wAwNv7X8C_oMTEk44aKFMaG2MRvjuO6jPv7qRqDIi6igzhk4lJuGA1gYPGFLBu68CdBgpA3FxVtmxJhXDCr4rfgtJ7XY1TWBe_gjqHw3c_FMhLOjBzD25mGC-vWwSdLpwaCrkvz3B73yl0PJXvfl_PQdiW8UzrIRZ-J1KKnBv0n5lEj3W4Ahy6v0IwcYxRdkkUHKu87r_MFNJQlRJiiXeFuHpxb5IVF-Xb6IGj0wxhbCzQKaMX1N91xogecORoUncx1mGl8HuHyflQphtp2fj9mkWf6tEyJcLX5rVD09sbG5QIc2aWZGK7WrVPx7iezEwmVOSGYs6Bb8KJfb33KlsFo0hHMm00VRhGwV2PxgCw1GJX7GzCuWeInkCOL4_7Z3CSwKceu0-FlSFcfFr4OdALzSVMthRg_Jle.tSoFTKWQVTvUfZgSkaTyuQ";
|
||||
|
||||
var $device_id = "ap-southeast-1_60ed15bd-eb92-4d89-a5e0-85595ac26530";
|
||||
var $template = "qrorder";
|
||||
var $client;
|
||||
function __construct()
|
||||
{
|
||||
$this->client = new ClientV3([
|
||||
"deviceId" => $this->device_id,
|
||||
"refreshToken" => $this->refresh_token,
|
||||
"idToken" => $this->id_token
|
||||
]);
|
||||
}
|
||||
function upload($url)
|
||||
{
|
||||
//create tmp file
|
||||
$fname = tempnam("/tmp", "rpt") . "-rpt.pdf";
|
||||
file_put_contents($fname, file_get_contents($url));
|
||||
$resp = $this->client->upload($fname);
|
||||
unlink($fname);
|
||||
return $resp;
|
||||
}
|
||||
function send_qrcode($phone, $url, $name, $date)
|
||||
{
|
||||
$urlImg = $this->upload($url);
|
||||
$message = [$name, $date];
|
||||
$resp = $this->client->sendMessageTemplateImage($phone, $this->template, "id", $message, $urlImg);
|
||||
return json_decode($resp, true);
|
||||
}
|
||||
function send_otp($phone, $otp)
|
||||
{
|
||||
$resp = $this->client->sendMessageTemplateAuthentication($phone, "pramitamobileotp", "id", $otp);
|
||||
return json_decode($resp, true);
|
||||
}
|
||||
function send_rujukan_external_process($phone, $phone_cabang)
|
||||
{
|
||||
|
||||
$message = [$phone_cabang];
|
||||
$resp = $this->client->sendMessageTemplateText($phone, "rujukan01", "id", $message);
|
||||
return json_decode($resp, true);
|
||||
}
|
||||
function send_eform($phone, $kode_cabang, $nolab, $type = "")
|
||||
{
|
||||
|
||||
$message = [$kode_cabang, $nolab];
|
||||
$resp = $this->client->sendMessageTemplateText($phone, "eform_fisik", "id", $message);
|
||||
return json_decode($resp, true);
|
||||
}
|
||||
function send_msg_button($phone, $url)
|
||||
{
|
||||
$body = ["hello", "world", "there"];
|
||||
$resp = $this->client->sendMessageTemplateButton($phone, "sample-message-button", "id", $body, $url);
|
||||
return json_decode($resp, true);
|
||||
}
|
||||
}
|
||||
159
application/libraries/Wa_sas.php
Normal file
159
application/libraries/Wa_sas.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
class Wa_sas
|
||||
{
|
||||
var $username, $host, $password;
|
||||
function __construct()
|
||||
{
|
||||
// $this->host = "http://sasdev.jala.my.id:3000/send/";
|
||||
//$this->host = "http://139.59.235.205:3000/send/";
|
||||
$this->host = "http://devkedungdoro.aplikasi.web.id:7001/send/";
|
||||
$this->username = "sasdev";
|
||||
$this->password = "sasdev!#102938";
|
||||
}
|
||||
function fix_phone($phone)
|
||||
{
|
||||
//remove - and space
|
||||
$phone = str_replace("-", "", $phone);
|
||||
$phone = str_replace(" ", "", $phone);
|
||||
//remove 1st +
|
||||
if (substr($phone, 0, 1) == "+") {
|
||||
$phone = substr($phone, 1);
|
||||
}
|
||||
if (substr($phone, 0, 1) == "0") {
|
||||
$phone = "62" . substr($phone, 1);
|
||||
}
|
||||
if (substr($phone, 0, 2) != "62") {
|
||||
$phone = "62" . $phone;
|
||||
}
|
||||
return $phone;
|
||||
}
|
||||
|
||||
function send_image_group(
|
||||
$phone,
|
||||
$caption,
|
||||
$url_image,
|
||||
$contentType,
|
||||
$file_name,
|
||||
$extension,
|
||||
$view_once = false,
|
||||
$compress = false
|
||||
) {
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'sasdev') . ".$extension";
|
||||
file_put_contents($tmpFile, file_get_contents($url_image));
|
||||
$data = [
|
||||
"phone" => $phone,
|
||||
"caption" => $caption,
|
||||
"view_once" => $view_once,
|
||||
"compress" => $compress,
|
||||
"image" => curl_file_create($tmpFile, $contentType, $file_name)
|
||||
];
|
||||
$ch = curl_init($this->host . "image");
|
||||
//curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
|
||||
$return = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
unlink($tmpFile);
|
||||
$j_return = json_decode($return, true);
|
||||
if (json_last_error() != 0) {
|
||||
return ["code" => "ERROR", "message" => "Error Json Decode : $return"];
|
||||
}
|
||||
return $j_return;
|
||||
}
|
||||
function send_message($phone, $message, $is_group = false)
|
||||
{
|
||||
$data = [
|
||||
"phone" => $is_group ? $phone : $this->fix_phone($phone),
|
||||
"message" => $message
|
||||
];
|
||||
$ch = curl_init($this->host . "message");
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
$return = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$j_return = json_decode($return, true);
|
||||
|
||||
if (json_last_error() != 0) {
|
||||
return ["code" => "ERROR", "message" => "Error Json Decode : $return"];
|
||||
}
|
||||
return $j_return;
|
||||
}
|
||||
function send_image(
|
||||
$phone,
|
||||
$caption,
|
||||
$url_image,
|
||||
$contentType,
|
||||
$file_name,
|
||||
$extension,
|
||||
$view_once = false,
|
||||
$compress = false
|
||||
) {
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'sasdev') . ".$extension";
|
||||
file_put_contents($tmpFile, file_get_contents($url_image));
|
||||
$data = [
|
||||
"phone" => $this->fix_phone($phone),
|
||||
"caption" => $caption,
|
||||
"view_once" => $view_once,
|
||||
"compress" => $compress,
|
||||
"image" => curl_file_create($tmpFile, $contentType, $file_name)
|
||||
];
|
||||
$ch = curl_init($this->host . "image");
|
||||
//curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
|
||||
$return = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
unlink($tmpFile);
|
||||
$j_return = json_decode($return, true);
|
||||
if (json_last_error() != 0) {
|
||||
return ["code" => "ERROR", "message" => "Error Json Decode : $return"];
|
||||
}
|
||||
return $j_return;
|
||||
}
|
||||
function send_file(
|
||||
$phone,
|
||||
$caption,
|
||||
$url_file,
|
||||
$contentType,
|
||||
$file_name,
|
||||
$extension,
|
||||
$compress = false
|
||||
) {
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'sasdev') . ".$extension";
|
||||
file_put_contents($tmpFile, file_get_contents($url_file));
|
||||
$data = [
|
||||
"phone" => $this->fix_phone($phone),
|
||||
"caption" => $caption,
|
||||
"compress" => $compress,
|
||||
"file" => curl_file_create($tmpFile, $contentType, $file_name)
|
||||
];
|
||||
$ch = curl_init($this->host . "file");
|
||||
//curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
|
||||
$return = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
unlink($tmpFile);
|
||||
$j_return = json_decode($return, true);
|
||||
if (json_last_error() != 0) {
|
||||
return ["code" => "ERROR", "message" => "Error Json Decode : $return"];
|
||||
}
|
||||
return $j_return;
|
||||
}
|
||||
}
|
||||
127
application/libraries/his/Simrs.php
Normal file
127
application/libraries/his/Simrs.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class Simrs {
|
||||
function __construct()
|
||||
{
|
||||
$this->HisEndPoint = "http://34.101.132.130:8080/query";
|
||||
$this->Timeout = 10;
|
||||
$this->token = "";
|
||||
$this->userName = "adiet";
|
||||
$this->password = "qwerty";
|
||||
}
|
||||
|
||||
function get_token() {
|
||||
if (! file_exists("/tmp/his-token.json")) {
|
||||
$this->login($this->userName,$this->password);
|
||||
} else {
|
||||
$jtoken = file_get_contents("/tmp/his-token.json");
|
||||
$token = json_decode($jtoken,true);
|
||||
$expired = $token["expired"];
|
||||
if ($expired - time() > 180 ) {
|
||||
return "{$token["token"]}";
|
||||
} else {
|
||||
$new_token = $this->login("x");
|
||||
return $new_token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function login($debug = "") {
|
||||
list($is_ok,$enc_password)= $this->gql(
|
||||
"mutation",
|
||||
"passwordEncrypt",
|
||||
["password" => "String!"],
|
||||
["password" => $this->password],
|
||||
"",
|
||||
"",
|
||||
$debug
|
||||
);
|
||||
if(! $is_ok) {
|
||||
if ($debug != "") echo "Error : {$this->password} => $enc_password\n";
|
||||
return false;
|
||||
}
|
||||
list($is_ok,$tokenResponse)= $this->gql(
|
||||
"mutation",
|
||||
"userLogin",
|
||||
["userName" => "String!", "password" => "String!"],
|
||||
["userName" => $this->userName, "password" => $enc_password],
|
||||
"userID token expired",
|
||||
"",
|
||||
$debug
|
||||
);
|
||||
if(!$is_ok) return false;
|
||||
|
||||
file_put_contents("/tmp/his-token.json",json_encode($tokenResponse));
|
||||
return $tokenResponse["token"];
|
||||
}
|
||||
|
||||
function gql($type, $name, $param, $variable, $return = "",
|
||||
$token = "",
|
||||
$debug = "")
|
||||
{
|
||||
$prm_gql= "";
|
||||
$prm_body = "";
|
||||
foreach($param as $k => $v) {
|
||||
if ($prm_gql!= "") $prm_gql .= ",";
|
||||
$prm_gql.= '$' . $k . ":" . $v;
|
||||
if ($prm_body != "") $prm_body .= ",";
|
||||
$prm_body .= $k . ":$" . $k;
|
||||
}
|
||||
$body = [];
|
||||
if ($return == "") {
|
||||
$body["query"] = "{$type}($prm_gql){{$name}($prm_body)}";
|
||||
} else {
|
||||
$body["query"] = "{$type}($prm_gql){ {$name}($prm_body){ $return } }";
|
||||
}
|
||||
$body["variables"] = $variable;
|
||||
$gql_body = json_encode($body);
|
||||
if($debug != "") {
|
||||
echo "Debug GQL: $gql_body \n";
|
||||
}
|
||||
$resp =$this->post($gql_body,$token);
|
||||
if($debug != "") {
|
||||
echo "Response GQL: $resp \n";
|
||||
}
|
||||
$j_resp = json_decode($resp,true);
|
||||
if ($j_resp !== false) {
|
||||
if ($j_resp["data"] != null) {
|
||||
$result = $j_resp["data"][$name];
|
||||
if ($debug != "") {
|
||||
print_r($result);
|
||||
}
|
||||
return [true,$result];
|
||||
} else {
|
||||
return [false,json_encode($j_resp["error"])];
|
||||
}
|
||||
}
|
||||
return [false,$resp];
|
||||
}
|
||||
|
||||
function post($data,$token = "")
|
||||
{
|
||||
$ch = curl_init($this->HisEndPoint);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->Timeout / 2);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $this->Timeout);
|
||||
if ($token == "") {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/json",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer $token",
|
||||
"Content-Type: application/json",
|
||||
"Content-Length: " . strlen($data),
|
||||
]);
|
||||
}
|
||||
$result = curl_exec($ch);
|
||||
if (curl_error($ch) != "") {
|
||||
return "ERROR SIMRS HIS API {$this->HisEndPoint} : " . curl_error($ch) . "\n";
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}}
|
||||
|
||||
11
application/libraries/index.html
Executable file
11
application/libraries/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
3312
application/libraries/qrcode/phpqrcode.php
Normal file
3312
application/libraries/qrcode/phpqrcode.php
Normal file
File diff suppressed because it is too large
Load Diff
180
application/libraries/qrcode/qrbitstream.php
Normal file
180
application/libraries/qrcode/qrbitstream.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?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 <fukuchi@megaui.net>
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
17
application/libraries/qrcode/qrconfig.php
Normal file
17
application/libraries/qrcode/qrconfig.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/*
|
||||
* PHP QR Code encoder
|
||||
*
|
||||
* Config file, feel free to modify
|
||||
*/
|
||||
|
||||
define('QR_CACHEABLE', true); // use cache - more disk reads but less CPU power, masks and format templates are stored there
|
||||
define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR); // used when QR_CACHEABLE === true
|
||||
define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR); // 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', false); // 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
|
||||
|
||||
54
application/libraries/qrcode/qrconst.php
Normal file
54
application/libraries/qrcode/qrconst.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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 <fukuchi@megaui.net>
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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));
|
||||
}
|
||||
}
|
||||
502
application/libraries/qrcode/qrencode.php
Normal file
502
application/libraries/qrcode/qrencode.php
Normal file
@@ -0,0 +1,502 @@
|
||||
<?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 <fukuchi@megaui.net>
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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; $i<QRspec::rsBlockNum1($spec); $i++) {
|
||||
$ecc = array_slice($this->ecccode,$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; $i<QRspec::rsBlockNum2($spec); $i++) {
|
||||
$ecc = array_slice($this->ecccode,$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());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
98
application/libraries/qrcode/qrimage.php
Normal file
98
application/libraries/qrcode/qrimage.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/*
|
||||
* PHP QR Code encoder
|
||||
*
|
||||
* Image output of code using GD2
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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 $black = array(255,255,255);
|
||||
public static $white = array(0,0,0);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
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,QRImage::$black[0],QRImage::$black[1],QRImage::$black[2]);
|
||||
$col[1] = ImageColorAllocate($base_image,QRImage::$white[0],QRImage::$white[1],QRImage::$white[2]);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
729
application/libraries/qrcode/qrinput.php
Normal file
729
application/libraries/qrcode/qrinput.php
Normal file
@@ -0,0 +1,729 @@
|
||||
<?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 <fukuchi@megaui.net>
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
43
application/libraries/qrcode/qrlib.php
Normal file
43
application/libraries/qrcode/qrlib.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*
|
||||
* PHP QR Code encoder
|
||||
*
|
||||
* Root library file, prepares environment and includes dependencies
|
||||
*
|
||||
* Based on libqrencode C library distributed under LGPL 2.1
|
||||
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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";
|
||||
|
||||
328
application/libraries/qrcode/qrmask.php
Normal file
328
application/libraries/qrcode/qrmask.php
Normal file
@@ -0,0 +1,328 @@
|
||||
<?php
|
||||
/*
|
||||
* PHP QR Code encoder
|
||||
*
|
||||
* Masking
|
||||
*
|
||||
* Based on libqrencode C library distributed under LGPL 2.1
|
||||
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
}
|
||||
210
application/libraries/qrcode/qrrscode.php
Normal file
210
application/libraries/qrcode/qrrscode.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?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 <fukuchi@megaui.net>
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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<<mm)-1)
|
||||
public $alpha_to = array(); // log lookup table
|
||||
public $index_of = array(); // Antilog lookup table
|
||||
public $genpoly = array(); // Generator polynomial
|
||||
public $nroots; // Number of generator roots = number of parity symbols
|
||||
public $fcr; // First consecutive root, index form
|
||||
public $prim; // Primitive element, index form
|
||||
public $iprim; // prim-th root of 1, index form
|
||||
public $pad; // Padding bytes in shortened block
|
||||
public $gfpoly;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
public function modnn($x)
|
||||
{
|
||||
while ($x >= $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;
|
||||
}
|
||||
}
|
||||
592
application/libraries/qrcode/qrspec.php
Normal file
592
application/libraries/qrcode/qrspec.php
Normal file
@@ -0,0 +1,592 @@
|
||||
<?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 <fukuchi@megaui.net>
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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('<span class="m"> </span>', explode('0', $frameLine));
|
||||
$frameLine = join('██', explode('1', $frameLine));
|
||||
}
|
||||
|
||||
?>
|
||||
<style>
|
||||
.m { background-color: white; }
|
||||
</style>
|
||||
<?php
|
||||
echo '<pre><tt><br/ ><br/ ><br/ > ';
|
||||
echo join("<br/ > ", $frame);
|
||||
echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';
|
||||
|
||||
} else {
|
||||
|
||||
foreach ($frame as &$frameLine) {
|
||||
$frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine));
|
||||
$frameLine = join('<span class="m">▒</span>', explode("\xc1", $frameLine));
|
||||
$frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine));
|
||||
$frameLine = join('<span class="p">▒</span>', explode("\xa1", $frameLine));
|
||||
$frameLine = join('<span class="s">◇</span>', explode("\x84", $frameLine)); //format 0
|
||||
$frameLine = join('<span class="s">◆</span>', explode("\x85", $frameLine)); //format 1
|
||||
$frameLine = join('<span class="x">☢</span>', explode("\x81", $frameLine)); //special bit
|
||||
$frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0
|
||||
$frameLine = join('<span class="c">◷</span>', explode("\x91", $frameLine)); //clock 1
|
||||
$frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version
|
||||
$frameLine = join('<span class="f">▒</span>', explode("\x89", $frameLine)); //version
|
||||
$frameLine = join('♦', explode("\x01", $frameLine));
|
||||
$frameLine = join('⋅', explode("\0", $frameLine));
|
||||
}
|
||||
|
||||
?>
|
||||
<style>
|
||||
.p { background-color: yellow; }
|
||||
.m { background-color: #00FF00; }
|
||||
.s { background-color: #FF0000; }
|
||||
.c { background-color: aqua; }
|
||||
.x { background-color: pink; }
|
||||
.f { background-color: gold; }
|
||||
</style>
|
||||
<?php
|
||||
echo "<pre><tt>";
|
||||
echo join("<br/ >", $frame);
|
||||
echo "</tt></pre>";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
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]; }
|
||||
|
||||
}
|
||||
311
application/libraries/qrcode/qrsplit.php
Normal file
311
application/libraries/qrcode/qrsplit.php
Normal file
@@ -0,0 +1,311 @@
|
||||
<?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 <fukuchi@megaui.net>
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
172
application/libraries/qrcode/qrtools.php
Normal file
172
application/libraries/qrcode/qrtools.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/*
|
||||
* PHP QR Code encoder
|
||||
*
|
||||
* Toolset, handy and debug utilites.
|
||||
*
|
||||
* PHP QR Code is distributed under LGPL 3
|
||||
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||||
*
|
||||
* 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 '<table cellpadding="3" cellspacing="1">
|
||||
<thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
|
||||
<tbody>';
|
||||
|
||||
foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
|
||||
if ($p > 0) {
|
||||
echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
|
||||
} else {
|
||||
$startTime = $thisTime;
|
||||
}
|
||||
|
||||
$p++;
|
||||
$lastTime = $thisTime;
|
||||
}
|
||||
|
||||
echo '</tbody><tfoot>
|
||||
<tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
|
||||
</tfoot>
|
||||
</table>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//##########################################################################
|
||||
|
||||
QRtools::markTime('start');
|
||||
|
||||
11
application/logs/index.html
Executable file
11
application/logs/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/models/index.html
Executable file
11
application/models/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
8
application/views/errors/cli/error_404.php
Executable file
8
application/views/errors/cli/error_404.php
Executable file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
echo "\nERROR: ",
|
||||
$heading,
|
||||
"\n\n",
|
||||
$message,
|
||||
"\n\n";
|
||||
8
application/views/errors/cli/error_db.php
Executable file
8
application/views/errors/cli/error_db.php
Executable file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
echo "\nDatabase error: ",
|
||||
$heading,
|
||||
"\n\n",
|
||||
$message,
|
||||
"\n\n";
|
||||
21
application/views/errors/cli/error_exception.php
Executable file
21
application/views/errors/cli/error_exception.php
Executable file
@@ -0,0 +1,21 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
|
||||
|
||||
An uncaught Exception was encountered
|
||||
|
||||
Type: <?php echo get_class($exception), "\n"; ?>
|
||||
Message: <?php echo $message, "\n"; ?>
|
||||
Filename: <?php echo $exception->getFile(), "\n"; ?>
|
||||
Line Number: <?php echo $exception->getLine(); ?>
|
||||
|
||||
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
|
||||
|
||||
Backtrace:
|
||||
<?php foreach ($exception->getTrace() as $error): ?>
|
||||
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
|
||||
File: <?php echo $error['file'], "\n"; ?>
|
||||
Line: <?php echo $error['line'], "\n"; ?>
|
||||
Function: <?php echo $error['function'], "\n\n"; ?>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<?php endif ?>
|
||||
8
application/views/errors/cli/error_general.php
Executable file
8
application/views/errors/cli/error_general.php
Executable file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
echo "\nERROR: ",
|
||||
$heading,
|
||||
"\n\n",
|
||||
$message,
|
||||
"\n\n";
|
||||
21
application/views/errors/cli/error_php.php
Executable file
21
application/views/errors/cli/error_php.php
Executable file
@@ -0,0 +1,21 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
|
||||
|
||||
A PHP Error was encountered
|
||||
|
||||
Severity: <?php echo $severity, "\n"; ?>
|
||||
Message: <?php echo $message, "\n"; ?>
|
||||
Filename: <?php echo $filepath, "\n"; ?>
|
||||
Line Number: <?php echo $line; ?>
|
||||
|
||||
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
|
||||
|
||||
Backtrace:
|
||||
<?php foreach (debug_backtrace() as $error): ?>
|
||||
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
|
||||
File: <?php echo $error['file'], "\n"; ?>
|
||||
Line: <?php echo $error['line'], "\n"; ?>
|
||||
Function: <?php echo $error['function'], "\n\n"; ?>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<?php endif ?>
|
||||
11
application/views/errors/cli/index.html
Executable file
11
application/views/errors/cli/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
64
application/views/errors/html/error_404.php
Executable file
64
application/views/errors/html/error_404.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>404 Page Not Found</title>
|
||||
<style type="text/css">
|
||||
|
||||
::selection { background-color: #E13300; color: white; }
|
||||
::-moz-selection { background-color: #E13300; color: white; }
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font: 13px/20px normal Helvetica, Arial, sans-serif;
|
||||
color: #4F5155;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #003399;
|
||||
background-color: transparent;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #444;
|
||||
background-color: transparent;
|
||||
border-bottom: 1px solid #D0D0D0;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
margin: 0 0 14px 0;
|
||||
padding: 14px 15px 10px 15px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Consolas, Monaco, Courier New, Courier, monospace;
|
||||
font-size: 12px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #D0D0D0;
|
||||
color: #002166;
|
||||
display: block;
|
||||
margin: 14px 0 14px 0;
|
||||
padding: 12px 10px 12px 10px;
|
||||
}
|
||||
|
||||
#container {
|
||||
margin: 10px;
|
||||
border: 1px solid #D0D0D0;
|
||||
box-shadow: 0 0 8px #D0D0D0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 12px 15px 12px 15px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<h1><?php echo $heading; ?></h1>
|
||||
<?php echo $message; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
64
application/views/errors/html/error_db.php
Executable file
64
application/views/errors/html/error_db.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Database Error</title>
|
||||
<style type="text/css">
|
||||
|
||||
::selection { background-color: #E13300; color: white; }
|
||||
::-moz-selection { background-color: #E13300; color: white; }
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font: 13px/20px normal Helvetica, Arial, sans-serif;
|
||||
color: #4F5155;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #003399;
|
||||
background-color: transparent;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #444;
|
||||
background-color: transparent;
|
||||
border-bottom: 1px solid #D0D0D0;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
margin: 0 0 14px 0;
|
||||
padding: 14px 15px 10px 15px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Consolas, Monaco, Courier New, Courier, monospace;
|
||||
font-size: 12px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #D0D0D0;
|
||||
color: #002166;
|
||||
display: block;
|
||||
margin: 14px 0 14px 0;
|
||||
padding: 12px 10px 12px 10px;
|
||||
}
|
||||
|
||||
#container {
|
||||
margin: 10px;
|
||||
border: 1px solid #D0D0D0;
|
||||
box-shadow: 0 0 8px #D0D0D0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 12px 15px 12px 15px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<h1><?php echo $heading; ?></h1>
|
||||
<?php echo $message; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
32
application/views/errors/html/error_exception.php
Executable file
32
application/views/errors/html/error_exception.php
Executable file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?>
|
||||
|
||||
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
|
||||
|
||||
<h4>An uncaught Exception was encountered</h4>
|
||||
|
||||
<p>Type: <?php echo get_class($exception); ?></p>
|
||||
<p>Message: <?php echo $message; ?></p>
|
||||
<p>Filename: <?php echo $exception->getFile(); ?></p>
|
||||
<p>Line Number: <?php echo $exception->getLine(); ?></p>
|
||||
|
||||
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
|
||||
|
||||
<p>Backtrace:</p>
|
||||
<?php foreach ($exception->getTrace() as $error): ?>
|
||||
|
||||
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
|
||||
|
||||
<p style="margin-left:10px">
|
||||
File: <?php echo $error['file']; ?><br />
|
||||
Line: <?php echo $error['line']; ?><br />
|
||||
Function: <?php echo $error['function']; ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
|
||||
<?php endforeach ?>
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
</div>
|
||||
64
application/views/errors/html/error_general.php
Executable file
64
application/views/errors/html/error_general.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Error</title>
|
||||
<style type="text/css">
|
||||
|
||||
::selection { background-color: #E13300; color: white; }
|
||||
::-moz-selection { background-color: #E13300; color: white; }
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font: 13px/20px normal Helvetica, Arial, sans-serif;
|
||||
color: #4F5155;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #003399;
|
||||
background-color: transparent;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #444;
|
||||
background-color: transparent;
|
||||
border-bottom: 1px solid #D0D0D0;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
margin: 0 0 14px 0;
|
||||
padding: 14px 15px 10px 15px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Consolas, Monaco, Courier New, Courier, monospace;
|
||||
font-size: 12px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #D0D0D0;
|
||||
color: #002166;
|
||||
display: block;
|
||||
margin: 14px 0 14px 0;
|
||||
padding: 12px 10px 12px 10px;
|
||||
}
|
||||
|
||||
#container {
|
||||
margin: 10px;
|
||||
border: 1px solid #D0D0D0;
|
||||
box-shadow: 0 0 8px #D0D0D0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 12px 15px 12px 15px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<h1><?php echo $heading; ?></h1>
|
||||
<?php echo $message; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
33
application/views/errors/html/error_php.php
Executable file
33
application/views/errors/html/error_php.php
Executable file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?>
|
||||
|
||||
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
|
||||
|
||||
<h4>A PHP Error was encountered</h4>
|
||||
|
||||
<p>Severity: <?php echo $severity; ?></p>
|
||||
<p>Message: <?php echo $message; ?></p>
|
||||
<p>Filename: <?php echo $filepath; ?></p>
|
||||
<p>Line Number: <?php echo $line; ?></p>
|
||||
|
||||
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
|
||||
|
||||
<p>Backtrace:</p>
|
||||
<?php foreach (debug_backtrace() as $error): ?>
|
||||
|
||||
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
|
||||
|
||||
<p style="margin-left:10px">
|
||||
File: <?php echo $error['file'] ?><br />
|
||||
Line: <?php echo $error['line'] ?><br />
|
||||
Function: <?php echo $error['function'] ?>
|
||||
</p>
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
<?php endforeach ?>
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
</div>
|
||||
11
application/views/errors/html/index.html
Executable file
11
application/views/errors/html/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/views/errors/index.html
Executable file
11
application/views/errors/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/views/index.html
Executable file
11
application/views/index.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user