diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..342aa43 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/application/cache/* +/application/logs \ No newline at end of file diff --git a/application/.htaccess b/application/.htaccess new file mode 100644 index 0000000..83097d2 --- /dev/null +++ b/application/.htaccess @@ -0,0 +1,6 @@ + + Require all denied + + + Deny from all + \ No newline at end of file diff --git a/application/cache/.htaccess b/application/cache/.htaccess new file mode 100644 index 0000000..83097d2 --- /dev/null +++ b/application/cache/.htaccess @@ -0,0 +1,6 @@ + + Require all denied + + + Deny from all + \ No newline at end of file diff --git a/application/cache/index.html b/application/cache/index.html new file mode 100644 index 0000000..b48b490 --- /dev/null +++ b/application/cache/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/application/config/app.php b/application/config/app.php new file mode 100644 index 0000000..ec6c9bc --- /dev/null +++ b/application/config/app.php @@ -0,0 +1,20 @@ + '', + 'thead_open' => '', + ]; +$config['status'] = [ + 'active' => 'A', + 'inactive' => 'I', + 'void' => 'V', + 'rejected' => 'R' +]; + +$config['jenisKelamin'] = [ + 'pria' => 'M', + 'laki-laki' => 'M', + 'wanita' => 'F', + 'perempuan' => 'F', +]; diff --git a/bmt-system/application/config/autoload.php b/application/config/autoload.php old mode 100755 new mode 100644 similarity index 61% rename from bmt-system/application/config/autoload.php rename to application/config/autoload.php index 71e882c..f4c6daf --- a/bmt-system/application/config/autoload.php +++ b/application/config/autoload.php @@ -1,4 +1,7 @@ - 'ua'); */ - -$autoload['libraries'] = array('database','session','authlib','allfunct','message'); - +//$autoload['libraries'] = array('database','table','form_builder','pagination'); +$autoload['libraries'] = array('database','session','authlib','allfunct','message','encryption'); /* | ------------------------------------------------------------------- -| Auto-load Helper Files +| 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['helper'] = array('url', 'file'); +| $autoload['drivers'] = array('cache'); */ - -$autoload['helper'] = array('url','jsonwrapper/jsonwrapper'); - +$autoload['drivers'] = array(); /* | ------------------------------------------------------------------- -| Auto-load Plugins +| Auto-load Helper Files | ------------------------------------------------------------------- | Prototype: | -| $autoload['plugin'] = array('captcha', 'js_calendar'); +| $autoload['helper'] = array('url', 'file'); */ - -$autoload['plugin'] = array(); - +$autoload['helper'] = array('url','jsonwrapper/jsonwrapper'); /* | ------------------------------------------------------------------- @@ -78,10 +99,9 @@ | config files. Otherwise, leave it blank. | */ - +//$autoload['config'] = array('app','pagination'); $autoload['config'] = array(); - /* | ------------------------------------------------------------------- | Auto-load Language files @@ -90,28 +110,23 @@ | | $autoload['language'] = array('lang1', 'lang2'); | -| NOTE: Do not include the "_lang" part of your file. For example +| 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('model1', 'model2'); +| $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(); - - - -/* End of file autoload.php */ -/* Location: ./system/application/config/autoload.php */ -?> diff --git a/application/config/config.php b/application/config/config.php new file mode 100644 index 0000000..5c73377 --- /dev/null +++ b/application/config/config.php @@ -0,0 +1,515 @@ +]+$/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/ +| +| 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. +| +| 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['allow_get_array'] = true; +$config['enable_query_strings'] = false; +$config['controller_trigger'] = 'c'; +$config['function_trigger'] = 'm'; +$config['directory_trigger'] = 'd'; + +/* +|-------------------------------------------------------------------------- +| 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'] = 1; + +/* +|-------------------------------------------------------------------------- +| 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. +| +| http://codeigniter.com/user_guide/libraries/encryption.html +| +*/ +$config['encryption_key'] = 't2p3k3tan'; + +/* +|-------------------------------------------------------------------------- +| 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_eabsensi_unit'; +$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. +| +| This is particularly useful for portability between UNIX-based OSes, +| (usually \n) and Windows (\r\n). +| +*/ +$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; + +/* +|-------------------------------------------------------------------------- +| 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'] = ''; diff --git a/application/config/constants.php b/application/config/constants.php new file mode 100644 index 0000000..9e2c2ea --- /dev/null +++ b/application/config/constants.php @@ -0,0 +1,85 @@ +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( + 'hostname' => '127.0.0.1', + 'username' => 'ahmad', + 'password' => 'ahmad', + 'database' => 'bmt_v1', + 'dbdriver' => 'mysqli', + 'dbprefix' => '', + 'pconnect' => false, + 'db_debug' => true, + 'cache_on' => false, + 'cachedir' => '', + 'char_set' => 'utf8', + 'dbcollat' => 'utf8_general_ci', + 'swap_pre' => '', + 'encrypt' => false, + 'compress' => false, + 'stricton' => false, + 'failover' => array(), + 'save_queries' => true, +); diff --git a/application/config/doctypes.php b/application/config/doctypes.php new file mode 100644 index 0000000..f95451b --- /dev/null +++ b/application/config/doctypes.php @@ -0,0 +1,24 @@ + '', + 'xhtml1-strict' => '', + 'xhtml1-trans' => '', + 'xhtml1-frame' => '', + 'xhtml-basic11' => '', + 'html5' => '', + 'html4-strict' => '', + 'html4-trans' => '', + 'html4-frame' => '', + 'mathml1' => '', + 'mathml2' => '', + 'svg10' => '', + 'svg11' => '', + 'svg11-basic' => '', + 'svg11-tiny' => '', + 'xhtml-math-svg-xh' => '', + 'xhtml-math-svg-sh' => '', + 'xhtml-rdfa-1' => '', + 'xhtml-rdfa-2' => '' +); diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php new file mode 100644 index 0000000..faa66d6 --- /dev/null +++ b/application/config/foreign_chars.php @@ -0,0 +1,103 @@ + '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' +); diff --git a/application/config/hooks.php b/application/config/hooks.php new file mode 100644 index 0000000..5d5f1b9 --- /dev/null +++ b/application/config/hooks.php @@ -0,0 +1,19 @@ + 'Db_log', // Name of Class + 'function' => 'logQueries', // Name of function to be executed in from Class + 'filename' => 'db_log.php', // Name of the Hook file + 'filepath' => 'hooks' // Name of folder where Hook file is stored +); \ No newline at end of file diff --git a/application/config/index.html b/application/config/index.html new file mode 100644 index 0000000..b48b490 --- /dev/null +++ b/application/config/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/application/config/jwt.php b/application/config/jwt.php new file mode 100644 index 0000000..24bc104 --- /dev/null +++ b/application/config/jwt.php @@ -0,0 +1,11 @@ + array( + 'hostname' => '127.0.0.1', + 'port' => '11211', + 'weight' => '1', + ), +); diff --git a/application/config/migration.php b/application/config/migration.php new file mode 100644 index 0000000..e26f361 --- /dev/null +++ b/application/config/migration.php @@ -0,0 +1,84 @@ +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/'; diff --git a/application/config/mimes.php b/application/config/mimes.php new file mode 100644 index 0000000..1153389 --- /dev/null +++ b/application/config/mimes.php @@ -0,0 +1,158 @@ + 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'), + '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' => 'video/mp4', + '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' => 'audio/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', + '7zip' => array('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') +); diff --git a/application/config/pagination.php b/application/config/pagination.php new file mode 100644 index 0000000..69d46e9 --- /dev/null +++ b/application/config/pagination.php @@ -0,0 +1,19 @@ + '', + 'uri_segment'=> 4, + 'full_tag_open'=> "", + 'num_tag_open'=> '
  • ', + 'num_tag_close'=> '
  • ', + 'cur_tag_open'=> "
  • ", + 'cur_tag_close'=> "
  • ", + 'next_tag_open'=> "
  • ", + 'next_tagl_close'=> "
  • ", + 'prev_tag_open'=> "
  • ", + 'prev_tagl_close'=> "
  • ", + 'first_tag_open'=> "
  • ", + 'first_tagl_close'=> "
  • ", + 'last_tag_open'=> "
  • ", + 'last_tagl_close'=> "
  • " +); \ No newline at end of file diff --git a/application/config/profiler.php b/application/config/profiler.php new file mode 100644 index 0000000..7eb227f --- /dev/null +++ b/application/config/profiler.php @@ -0,0 +1,14 @@ +function($username, $password) +| In other cases override the function _perform_library_auth in your controller +| +| For digest authentication the library function should return already stored md5(username:restrealm:password) for that username +| E.g: md5('admin:REST API:1234') = '1e957ebc35631ab22d5bd6526bd14ea2' +| +*/ +$config['auth_library_class'] = ''; +$config['auth_library_function'] = ''; + +/* +|-------------------------------------------------------------------------- +| Override auth types for specific class/method +|-------------------------------------------------------------------------- +| +| Set specific authentication types for methods within a class (controller) +| +| Set as many config entries as needed. Any methods not set will use the default 'rest_auth' config value. +| +| example: +| +| $config['auth_override_class_method']['deals']['view'] = 'none'; +| $config['auth_override_class_method']['deals']['insert'] = 'digest'; +| $config['auth_override_class_method']['accounts']['user'] = 'basic'; +| $config['auth_override_class_method']['dashboard']['*'] = 'none|digest|basic'; +| +| Here 'deals', 'accounts' and 'dashboard' are controller names, 'view', 'insert' and 'user' are methods within. An asterisk may also be used to specify an authentication method for an entire classes methods. Ex: $config['auth_override_class_method']['dashboard']['*'] = 'basic'; (NOTE: leave off the '_get' or '_post' from the end of the method name) +| Acceptable values are; 'none', 'digest' and 'basic'. +| +*/ +// $config['auth_override_class_method']['deals']['view'] = 'none'; +// $config['auth_override_class_method']['deals']['insert'] = 'digest'; +// $config['auth_override_class_method']['accounts']['user'] = 'basic'; +// $config['auth_override_class_method']['dashboard']['*'] = 'basic'; + + +//---Uncomment list line for the wildard unit test +//$config['auth_override_class_method']['wildcard_test_cases']['*'] = 'basic'; +/* +|-------------------------------------------------------------------------- +| REST Login usernames +|-------------------------------------------------------------------------- +| +| Array of usernames and passwords for login, if ldap is configured this is ignored +| +| array('admin' => '1234') +| +*/ +$config['rest_valid_logins'] = array('admin' => '1234'); + +/* +|-------------------------------------------------------------------------- +| Global IP Whitelisting +|-------------------------------------------------------------------------- +| +| Limit connections to your REST server to whitelisted IP addresses. +| +| Usage: +| 1. Set to true *and* select an auth option for extreme security (client's IP +| address must be in whitelist and they must also log in) +| 2. Set to true with auth set to false to allow whitelisted IPs access with no login. +| 3. Set to false here but set 'auth_override_class_method' to 'whitelist' to +| restrict certain methods to IPs in your whitelist +| +*/ +$config['rest_ip_whitelist_enabled'] = false; + +/* +|-------------------------------------------------------------------------- +| REST IP Whitelist +|-------------------------------------------------------------------------- +| +| Limit connections to your REST server to a comma separated +| list of IP addresses +| +| Example: $config['rest_ip_whitelist'] = '123.456.789.0, 987.654.32.1'; +| +| 127.0.0.1 and 0.0.0.0 are allowed by default. +| +*/ +$config['rest_ip_whitelist'] = ''; + +/* +|-------------------------------------------------------------------------- +| Global IP Blacklisting +|-------------------------------------------------------------------------- +| +| Prevent connections to your REST server from blacklisted IP addresses. +| +| Usage: +| 1. Set to true *and* add any IP address to "rest_ip_blacklist" option +| +*/ +$config['rest_ip_blacklist_enabled'] = false; + +/* +|-------------------------------------------------------------------------- +| REST IP Blacklist +|-------------------------------------------------------------------------- +| +| Block connections from these IP addresses. +| +| Example: $config['rest_ip_blacklist'] = '123.456.789.0, 987.654.32.1'; +| +| +*/ +$config['rest_ip_blacklist'] = ''; + +/* +|-------------------------------------------------------------------------- +| REST Database Group +|-------------------------------------------------------------------------- +| +| Connect to a database group for keys, logging, etc. It will only connect +| if you have any of these features enabled. +| +| 'default' +| +*/ +$config['rest_database_group'] = 'default'; + +/* +|-------------------------------------------------------------------------- +| REST API Keys Table Name +|-------------------------------------------------------------------------- +| +| The table name in your database that stores API Keys. +| +| 'keys' +| +*/ +$config['rest_keys_table'] = 'keys'; + +/* +|-------------------------------------------------------------------------- +| REST Enable Keys +|-------------------------------------------------------------------------- +| +| When set to true REST_Controller will look for a key and match it to the DB. +| If no key is provided, the request will return an error. +| +| FALSE + + CREATE TABLE `keys` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `key` varchar(40) NOT NULL, + `level` int(2) NOT NULL, + `ignore_limits` tinyint(1) NOT NULL DEFAULT '0', + `is_private_key` tinyint(1) NOT NULL DEFAULT '0', + `ip_addresses` TEXT NULL DEFAULT NULL, + `date_created` int(11) NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +| +*/ +$config['rest_enable_keys'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| REST Table Key Column Name +|-------------------------------------------------------------------------- +| +| If you are not using the default table schema as shown above, what is the +| name of the db column that holds the api key value? +| +*/ +$config['rest_key_column'] = 'key'; + +/* +|-------------------------------------------------------------------------- +| REST Key Length +|-------------------------------------------------------------------------- +| +| How long should created keys be? Double check this in your db schema. +| +| Default: 32 +| Max: 40 +| +*/ +$config['rest_key_length'] = 40; + +/* +|-------------------------------------------------------------------------- +| REST API Key Variable +|-------------------------------------------------------------------------- +| +| Which variable will provide us the API Key +| +| Default: X-API-KEY +| +*/ +$config['rest_key_name'] = 'X-API-KEY'; + +/* +|-------------------------------------------------------------------------- +| REST API Logs Table Name +|-------------------------------------------------------------------------- +| +| The table name in your database that stores logs. +| +| 'logs' +| +*/ +$config['rest_logs_table'] = 'logs'; + +/* +|-------------------------------------------------------------------------- +| REST Enable Logging +|-------------------------------------------------------------------------- +| +| When set to true REST_Controller will log actions based on key, date, +| time and IP address. This is a general rule that can be overridden in the +| $this->method array in each controller. +| +| FALSE +| + CREATE TABLE `logs` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `uri` varchar(255) NOT NULL, + `method` varchar(6) NOT NULL, + `params` text DEFAULT NULL, + `api_key` varchar(40) NOT NULL, + `ip_address` varchar(45) NOT NULL, + `time` int(11) NOT NULL, + `rtime` float DEFAULT NULL, + `authorized` tinyint(1) NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +| +*/ +$config['rest_enable_logging'] = FALSE; + + +/* +|-------------------------------------------------------------------------- +| REST API Access Table Name +|-------------------------------------------------------------------------- +| +| The table name in your database that stores the access controls. +| +| 'access' +| +*/ +$config['rest_access_table'] = 'access'; + +/* +|-------------------------------------------------------------------------- +| REST Method Access Control +|-------------------------------------------------------------------------- +| +| When set to true REST_Controller will check the access table to see if +| the API KEY can access that controller. rest_enable_keys *must* be enabled +| to use this. +| +| FALSE +| +CREATE TABLE `access` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(40) NOT NULL DEFAULT '', + `controller` varchar(50) NOT NULL DEFAULT '', + `date_created` datetime DEFAULT NULL, + `date_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +| +*/ +$config['rest_enable_access'] = FALSE; + + +/* +|-------------------------------------------------------------------------- +| REST API Param Log Format +|-------------------------------------------------------------------------- +| +| When set to true API log params will be stored in the database as JSON, +| when false they will be php serialized. +| +*/ +$config['rest_logs_json_params'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| REST API Limits Table Name +|-------------------------------------------------------------------------- +| +| The table name in your database that stores limits. +| +| 'limits' +| +*/ +$config['rest_limits_table'] = 'limits'; + +/* +|-------------------------------------------------------------------------- +| REST Enable Limits +|-------------------------------------------------------------------------- +| +| When set to true REST_Controller will count the number of uses of each method +| by an API key each hour. This is a general rule that can be overridden in the +| $this->method array in each controller. +| +| FALSE +| + CREATE TABLE `limits` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `uri` varchar(255) NOT NULL, + `count` int(10) NOT NULL, + `hour_started` int(11) NOT NULL, + `api_key` varchar(40) NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +| +| To specify limits, within your Controller __construct() method add per-method +| limits with: + + $this->method['METHOD_NAME']['limit'] = [NUM_REQUESTS_PER_HOUR]; + +| See application/controllers/api/example.php for examples. +*/ +$config['rest_enable_limits'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| REST Ignore HTTP Accept +|-------------------------------------------------------------------------- +| +| Set to TRUE to ignore the HTTP Accept and speed up each request a little. +| Only do this if you are using the $this->rest_format or /format/xml in URLs +| +| FALSE +| +*/ +$config['rest_ignore_http_accept'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| REST AJAX Only +|-------------------------------------------------------------------------- +| +| Set to TRUE to only allow AJAX requests. If TRUE and the request is not +| coming from AJAX, a 505 response with the error message "Only AJAX +| requests are accepted." will be returned. This is good for production +| environments. Set to FALSE to also accept HTTP requests. +| +| FALSE +| +*/ +$config['rest_ajax_only'] = FALSE; + +/* End of file config.php */ +/* Location: ./system/application/config/rest.php */ diff --git a/bmt-system/application/config/routes.php b/application/config/routes.php old mode 100755 new mode 100644 similarity index 53% rename from bmt-system/application/config/routes.php rename to application/config/routes.php index 8915406..99ad7d1 --- a/bmt-system/application/config/routes.php +++ b/application/config/routes.php @@ -1,48 +1,52 @@ - my_controller/index +| my-controller/my-method -> my_controller/my_method +*/ +$route['default_controller'] = 'welcome'; +$route['404_override'] = ''; +$route['translate_uri_dashes'] = FALSE; diff --git a/bmt-system/application/config/smileys.php b/application/config/smileys.php old mode 100755 new mode 100644 similarity index 86% rename from bmt-system/application/config/smileys.php rename to application/config/smileys.php index 7f3aba5..cc25757 --- a/bmt-system/application/config/smileys.php +++ b/application/config/smileys.php @@ -1,66 +1,64 @@ - 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', 'excaim'), - ':question:' => array('question.gif', '19', '19', 'question') // no comma after last item - - ); - -/* End of file smileys.php */ -/* Location: ./system/application/config/smileys.php */ \ No newline at end of file + 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') + +); diff --git a/application/config/user_agents.php b/application/config/user_agents.php new file mode 100644 index 0000000..df1c666 --- /dev/null +++ b/application/config/user_agents.php @@ -0,0 +1,211 @@ + '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' => 'Spartan', + 'Chrome' => 'Chrome', + // Opera 10+ always reports Opera/9.80 and appends 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' +); diff --git a/bmt-system/application/controllers/angsuran.php b/application/controllers/Angsuran.php similarity index 97% rename from bmt-system/application/controllers/angsuran.php rename to application/controllers/Angsuran.php index cba0d24..1280f34 100755 --- a/bmt-system/application/controllers/angsuran.php +++ b/application/controllers/Angsuran.php @@ -1,34 +1,34 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "transaksiumum"; - $this->menuactsub = "angsuran"; - } - - //---- Admin - function index() - { + $this->menuactsub = "angsuran"; + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('angsuran',$data); + $this->load->view('angsuran',$data); } function _loadMenu($parent) { @@ -68,7 +68,7 @@ function _loadMenu($parent) } else { $this->isi[] = ""; } - } + } //---- Fungsi mengisi option Wilayah function isi_wilayah() { @@ -82,7 +82,7 @@ function isi_wilayah() } } function savetunai(){ - $data = $this->allfunct->securePost(); + $data = $this->allfunct->securePost(); $realangsuran = $data['pokok'] + $data['margin']; $pokok = $data['pokokinfo']; $margin = $data['margininfo']; @@ -94,7 +94,7 @@ function savetunai(){ $data1['create_date'] = date("Y-m-d H:i:s"); $data1['create_by'] = $this->session->userdata('username'); $data1['update_by'] = $this->session->userdata('username'); - //$data1['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data1['accounttrans_curency'] = $this->session->userdata('cbg'); $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); $data2['accounttrans_code'] = $data['nomor_ref']." - ".$data['nomor_jurnal']; @@ -103,7 +103,7 @@ function savetunai(){ $data2['create_date'] = date("Y-m-d H:i:s"); $data2['create_by'] = $this->session->userdata('username'); $data2['update_by'] = $this->session->userdata('username'); - //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); $data3['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); $data3['accounttrans_code'] = $data['nomor_ref']." - ".$data['nomor_jurnal']; @@ -112,7 +112,7 @@ function savetunai(){ $data3['create_date'] = date("Y-m-d H:i:s"); $data3['create_by'] = $this->session->userdata('username'); $data3['update_by'] = $this->session->userdata('username'); - //$data3['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data3['accounttrans_curency'] = $this->session->userdata('cbg'); $data4['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); $data4['accounttrans_code'] = $data['nomor_ref']." - ".$data['nomor_jurnal']; @@ -121,7 +121,7 @@ function savetunai(){ $data4['create_date'] = date("Y-m-d H:i:s"); $data4['create_by'] = $this->session->userdata('username'); $data4['update_by'] = $this->session->userdata('username'); - //$data4['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data4['accounttrans_curency'] = $this->session->userdata('cbg'); if($data['jenis_pembiayaan'] == "MURABAHAH"){ $data1['accounttrans_listid'] = "19"; @@ -139,11 +139,11 @@ function savetunai(){ $data4['accounttrans_listid'] = $data['gl_pendapatanmargin']; $data4['accounttrans_type'] = '01'; $data4['accounttrans_value'] = $margin; - - $this->master->simpan('tb_accounttrans',$data1); - $this->master->simpan('tb_accounttrans',$data2); - $this->master->simpan('tb_accounttrans',$data3); - $this->master->simpan('tb_accounttrans',$data4); + + $this->master->simpan('tb_accounttrans',$data1); + $this->master->simpan('tb_accounttrans',$data2); + $this->master->simpan('tb_accounttrans',$data3); + $this->master->simpan('tb_accounttrans',$data4); }elseif(($data['jenis_pembiayaan'] == "MUDHARABAH")||($data['jenis_pembiayaan'] == "MUSYARAKAH")){ $data1['accounttrans_listid'] = "19"; @@ -157,14 +157,14 @@ function savetunai(){ $data3['accounttrans_listid'] = $data['gl_pendapatanbagihasil']; $data3['accounttrans_type'] = '01'; $data3['accounttrans_value'] = $margin; - /* - $data4['accounttrans_listid'] = '19'; - $data4['accounttrans_type'] = '02'; - $data4['accounttrans_value'] = $margin; - */ - $this->master->simpan('tb_accounttrans',$data1); - $this->master->simpan('tb_accounttrans',$data2); - $this->master->simpan('tb_accounttrans',$data3); + /* + $data4['accounttrans_listid'] = '19'; + $data4['accounttrans_type'] = '02'; + $data4['accounttrans_value'] = $margin; + */ + $this->master->simpan('tb_accounttrans',$data1); + $this->master->simpan('tb_accounttrans',$data2); + $this->master->simpan('tb_accounttrans',$data3); //$this->master->simpan('tb_accounttrans',$data4); }elseif($data['jenis_pembiayaan'] == "AL-QARDH"){ $data1['accounttrans_listid'] = "19"; @@ -173,9 +173,9 @@ function savetunai(){ $data2['accounttrans_listid'] = $data['id_jurnal']; $data2['accounttrans_type'] = '01'; - $data2['accounttrans_value'] = $data['jumlah']; - - $this->master->simpan('tb_accounttrans',$data1); + $data2['accounttrans_value'] = $data['jumlah']; + + $this->master->simpan('tb_accounttrans',$data1); $this->master->simpan('tb_accounttrans',$data2); } @@ -190,9 +190,9 @@ function savetunai(){ $id = $data['nomor_jurnal']; $data5['status'] = '1'; - $where = array('pembiayaandetail_id' => $id); - if($data['jumlah'] >= $realangsuran){ - $this->master->update("tb_pembiayaandetail",$data5,$where); + $where = array('pembiayaandetail_id' => $id); + if($data['jumlah'] >= $realangsuran){ + $this->master->update("tb_pembiayaandetail",$data5,$where); } echo $this->master->simpan('tb_accounttemp',$data4)."#".$id; } @@ -228,14 +228,14 @@ function jurnalall() $data = $query->result_array(); $hasil['alldata'] = $data; echo json_encode($hasil); - } - function cetak() - { - $query = $this->db->query("SELECT wilayah_kerja FROM bmt WHERE bmt_id =1"); - $data = $query->result_array(); - $data1['code_cabang'] = $data[0]["wilayah_kerja"]; - $data1['teller'] = $this->session->userdata('username'); - $this->load->view('cetak/validasi',$data1); + } + function cetak() + { + $query = $this->db->query("SELECT wilayah_kerja FROM bmt WHERE bmt_id =1"); + $data = $query->result_array(); + $data1['code_cabang'] = $data[0]["wilayah_kerja"]; + $data1['teller'] = $this->session->userdata('username'); + $this->load->view('cetak/validasi',$data1); } function login() { @@ -244,7 +244,7 @@ function login() $resp = $this->authlib->login1($login); echo $resp; } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/auth.php b/application/controllers/Auth.php similarity index 95% rename from bmt-system/application/controllers/auth.php rename to application/controllers/Auth.php index 7891084..d881571 100755 --- a/bmt-system/application/controllers/auth.php +++ b/application/controllers/Auth.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Auth extends Controller { +class Auth extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); } function index(){ diff --git a/bmt-system/application/controllers/basil.php b/application/controllers/Basil.php similarity index 95% rename from bmt-system/application/controllers/basil.php rename to application/controllers/Basil.php index 3af0561..f8a0859 100755 --- a/bmt-system/application/controllers/basil.php +++ b/application/controllers/Basil.php @@ -1,24 +1,24 @@ -load->model('master_model','master'); $this->load->model('admin_model','modelku'); - - } - - function index() + + } + + function index() { $tglawal = "2014-10-01"; $tglakhir = "2014-10-07"; @@ -64,9 +64,9 @@ function index() } } - echo $saldo_rata; + echo $saldo_rata; } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/hapustransaksi.php b/application/controllers/Hapustransaksi.php similarity index 94% rename from bmt-system/application/controllers/hapustransaksi.php rename to application/controllers/Hapustransaksi.php index 3778f30..320b97e 100755 --- a/bmt-system/application/controllers/hapustransaksi.php +++ b/application/controllers/Hapustransaksi.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Hapustransaksi extends Controller { +class Hapustransaksi extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); diff --git a/bmt-system/application/controllers/help.php b/application/controllers/Help.php similarity index 89% rename from bmt-system/application/controllers/help.php rename to application/controllers/Help.php index 4728a68..ac5d422 100644 --- a/bmt-system/application/controllers/help.php +++ b/application/controllers/Help.php @@ -4,32 +4,31 @@ * Copyright (c) 2014 * * file : help.php - * author : Edi Suwoto S.Komp + * author : Edi Suwoto S.Komp * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Help extends Controller { +class Help extends CI_Controller { function __construct() { - parent::Controller(); - //$this->authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); - $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "help"; + parent::__construct(); + //$this->authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); + $this->load->model('master_model','master'); + $this->load->model('admin_model','modelku'); + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "help"; $this->menuactsub = "help"; } function index() { - $this->authlib->cekmain(); + $this->authlib->cekmain(); $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = 'vader'; - $this->load->view('help',$data); - - } + $this->load->view('help',$data); + } } diff --git a/bmt-system/application/controllers/lapmutasi.php b/application/controllers/Lapmutasi.php similarity index 97% rename from bmt-system/application/controllers/lapmutasi.php rename to application/controllers/Lapmutasi.php index 3fffd61..a81f437 100755 --- a/bmt-system/application/controllers/lapmutasi.php +++ b/application/controllers/Lapmutasi.php @@ -1,35 +1,35 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "transaksiumum"; - $this->menuactsub = "lapmutasi"; - } - - //---- Admin - function index() - { + $this->menuactsub = "lapmutasi"; + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('lapmutasi',$data); - } + $this->load->view('lapmutasi',$data); + } function get_transaksitabungan() { $tglawal = $this->allfunct->revDate($this->input->post('tglawal')); @@ -39,7 +39,7 @@ function get_transaksitabungan() FROM tb_accounttrans AS t1 INNER JOIN tb_tabungan AS t2 ON t2.nomor_rekening=t1.accounttrans_user INNER JOIN master_grouptabungan AS t3 ON t3.kode_produk=t2.jenis_simpanan - INNER JOIN tb_nasabah AS t4 ON t4.nomor_nasabah=t2.nomor_nasabah + INNER JOIN tb_nasabah AS t4 ON t4.nomor_nasabah=t2.nomor_nasabah WHERE accounttrans_listid !=19 and accounttrans_listid!=349 AND accounttrans_date BETWEEN '$tglawal' AND '$tglakhir' GROUP BY t1.accounttrans_user"); $data = $query->result_array(); @@ -56,7 +56,7 @@ function get_transaksideposito() FROM tb_accounttrans AS t1 INNER JOIN tb_deposito AS t2 ON t2.nomor_rekening=t1.accounttrans_user INNER JOIN master_groupdeposito AS t3 ON t3.kode_produk=t2.nama_produk - INNER JOIN tb_nasabah AS t4 ON t4.nomor_nasabah=t2.nomor_nasabah + INNER JOIN tb_nasabah AS t4 ON t4.nomor_nasabah=t2.nomor_nasabah WHERE accounttrans_listid !=19 AND accounttrans_date BETWEEN '$tglawal' AND '$tglakhir' GROUP BY t1.accounttrans_user"); $data = $query->result_array(); @@ -72,9 +72,9 @@ function get_transaksipembiayaan() SUM(CASE WHEN accounttrans_type = '02' THEN accounttrans_value END) AS mutasi_debet FROM tb_accounttrans AS t1 INNER JOIN tb_pembiayaan AS t2 ON t2.nomor_rekening=t1.accounttrans_user - INNER JOIN master_grouppembiayaan AS t3 ON t3.kode_produk=t2.jenis_pembiayaan + INNER JOIN master_grouppembiayaan AS t3 ON t3.kode_produk=t2.jenis_pembiayaan INNER JOIN tb_nasabah AS t4 ON t4.nomor_nasabah=t2.nomor_nasabah - WHERE accounttrans_listid!=19 and accounttrans_listid!=44 and accounttrans_listid!=118 and + WHERE accounttrans_listid!=19 and accounttrans_listid!=44 and accounttrans_listid!=118 and accounttrans_listid!=288 and accounttrans_date BETWEEN '$tglawal' AND '$tglakhir' GROUP BY t1.accounttrans_user"); $data = $query->result_array(); @@ -103,7 +103,7 @@ function login() $resp = $this->authlib->login1($login); echo $resp; } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/pegadaian.php b/application/controllers/Pegadaian.php similarity index 93% rename from bmt-system/application/controllers/pegadaian.php rename to application/controllers/Pegadaian.php index aeb0889..589edc6 100644 --- a/bmt-system/application/controllers/pegadaian.php +++ b/application/controllers/Pegadaian.php @@ -4,32 +4,32 @@ * Copyright (c) 2014 * * file : pegadaian.php - * author : Edi Suwoto S.Komp + * author : Edi Suwoto S.Komp * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Pegadaian extends Controller { +class Pegadaian extends CI_Controller { function __construct() { - parent::Controller(); - //$this->authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); - $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "help"; + parent::__construct(); + //$this->authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); + $this->load->model('master_model','master'); + $this->load->model('admin_model','modelku'); + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "help"; $this->menuactsub = "pegadaian"; } function index() { - $this->authlib->cekmain(); + $this->authlib->cekmain(); $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = 'vader'; - $this->load->view('pegadaian',$data); + $this->load->view('pegadaian',$data); - } + } } diff --git a/bmt-system/application/controllers/pencairandeposito.php b/application/controllers/Pencairandeposito.php similarity index 96% rename from bmt-system/application/controllers/pencairandeposito.php rename to application/controllers/Pencairandeposito.php index 8c477b8..0ff3642 100755 --- a/bmt-system/application/controllers/pencairandeposito.php +++ b/application/controllers/Pencairandeposito.php @@ -1,36 +1,36 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "transaksiumum"; - $this->menuactsub = "pencairandeposito"; - } - - //---- Admin - function index() - { + $this->menuactsub = "pencairandeposito"; + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('pencairandeposito',$data); + $this->load->view('pencairandeposito',$data); } - + //---- Fungsi mengisi option Wilayah function isi_wilayah() { @@ -71,7 +71,7 @@ function savetunai(){ $data1['create_date'] = date("Y-m-d H:i:s"); $data1['create_by'] = $this->session->userdata('username'); $data1['update_by'] = $data['otorisasi']; - //$data1['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data1['accounttrans_curency'] = $this->session->userdata('cbg'); $data2['accounttrans_listid'] = $data['id_jurnal']; $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); @@ -83,19 +83,19 @@ function savetunai(){ $data2['accounttrans_direct'] = $data['wilayah_id']; $data2['create_date'] = date("Y-m-d H:i:s"); $data2['create_by'] = $this->session->userdata('username'); - $data2['update_by'] = $data['otorisasi']; - //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); + $data2['update_by'] = $data['otorisasi']; + //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); $this->master->simpan('tb_accounttrans',$data1); $this->master->simpan('tb_accounttrans',$data2); $data2['accounttrans_posted'] = '1'; $data1['accounttrans_posted'] = '1'; - $this->master->simpan('tb_accounttemp',$data1); - - $id_jurnal= $data['nomor_jurnal']; - $nomor_ref= $data['nomor_ref']; - $nomor_rekening= $data['nomor_rekening']; - $nama= $data['nama']; + $this->master->simpan('tb_accounttemp',$data1); + + $id_jurnal= $data['nomor_jurnal']; + $nomor_ref= $data['nomor_ref']; + $nomor_rekening= $data['nomor_rekening']; + $nama= $data['nama']; echo $this->master->simpan('tb_accounttemp',$data2)."#".$id_jurnal."#".$nomor_ref."#".$nomor_rekening." ".$nama; @@ -120,7 +120,7 @@ function login() $resp = $this->authlib->login1($login); echo $resp; } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/pencairanpembiayaan.php b/application/controllers/Pencairanpembiayaan.php similarity index 96% rename from bmt-system/application/controllers/pencairanpembiayaan.php rename to application/controllers/Pencairanpembiayaan.php index 994e90d..7399e5c 100755 --- a/bmt-system/application/controllers/pencairanpembiayaan.php +++ b/application/controllers/Pencairanpembiayaan.php @@ -1,36 +1,36 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "transaksiumum"; - $this->menuactsub = "pencairanpembiayaan"; - } - - //---- Admin - function index() - { + $this->menuactsub = "pencairanpembiayaan"; + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('pencairanpembiayaan',$data); + $this->load->view('pencairanpembiayaan',$data); } - + //---- Fungsi mengisi option Wilayah function isi_wilayah() { @@ -94,7 +94,7 @@ function savetunai(){ $data1['create_date'] = date("Y-m-d H:i:s"); $data1['create_by'] = $this->session->userdata('username'); $data1['update_by'] = $this->session->userdata('username'); - //$data1['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data1['accounttrans_curency'] = $this->session->userdata('cbg'); $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); $data2['accounttrans_code'] = $data['nomor_ref']." - ".$data['nomor_jurnal']; @@ -103,7 +103,7 @@ function savetunai(){ $data2['create_date'] = date("Y-m-d H:i:s"); $data2['create_by'] = $this->session->userdata('username'); $data2['update_by'] = $this->session->userdata('username'); - //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); $data3['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); $data3['accounttrans_code'] = $data['nomor_ref']." - ".$data['nomor_jurnal']; @@ -112,10 +112,10 @@ function savetunai(){ $data3['create_date'] = date("Y-m-d H:i:s"); $data3['create_by'] = $this->session->userdata('username'); $data3['update_by'] = $this->session->userdata('username'); - //$data3['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data3['accounttrans_curency'] = $this->session->userdata('cbg'); if($data['jenis_pembiayaan'] == "MURABAHAH"){ - //$data1['accounttrans_type'] = '01'; + //$data1['accounttrans_type'] = '01'; $data1['accounttrans_type'] = '02'; $data1['accounttrans_value'] = $pokokmargin; $data1['accounttrans_ref'] = '1'; @@ -127,7 +127,7 @@ function savetunai(){ $data3['accounttrans_listid'] = "44"; $data3['accounttrans_type'] = '01'; $data3['accounttrans_value'] = $margin; - $this->master->simpan('tb_accounttrans',$data3); + $this->master->simpan('tb_accounttrans',$data3); }elseif(($data['jenis_pembiayaan'] == "MUDHARABAH")||($data['jenis_pembiayaan'] == "MUSYARAKAH")){ $data1['accounttrans_type'] = '01'; @@ -135,7 +135,7 @@ function savetunai(){ $data2['accounttrans_listid'] = "19"; $data2['accounttrans_type'] = '02'; - $data2['accounttrans_value'] = $pokokmargin; + $data2['accounttrans_value'] = $pokokmargin; }elseif($data['jenis_pembiayaan'] == "AL-QARDH"){ $data1['accounttrans_type'] = '02'; @@ -146,20 +146,20 @@ function savetunai(){ $data2['accounttrans_value'] = $pokokmargin; } - $this->master->simpan('tb_accounttrans',$data1); - $this->master->simpan('tb_accounttrans',$data2); + $this->master->simpan('tb_accounttrans',$data1); + $this->master->simpan('tb_accounttrans',$data2); $data1['accounttrans_posted'] = '1'; $data2['accounttrans_posted'] = '1'; - $data3['accounttrans_posted'] = '1'; + $data3['accounttrans_posted'] = '1'; //$this->master->simpan('tb_accounttemp',$data2); - //$this->master->simpan('tb_accounttemp',$data3); - - $id_jurnal= $data['nomor_jurnal']; - $nomor_ref= $data['nomor_ref']; - $nomor_rekening= $data['nomor_rekening']; - $nama= $data['nama']; + //$this->master->simpan('tb_accounttemp',$data3); + + $id_jurnal= $data['nomor_jurnal']; + $nomor_ref= $data['nomor_ref']; + $nomor_rekening= $data['nomor_rekening']; + $nama= $data['nama']; echo $this->master->simpan('tb_accounttemp',$data1)."#".$id_jurnal."#".$nomor_ref."#".$nomor_rekening." ".$nama; } @@ -213,7 +213,7 @@ function login() $resp = $this->authlib->login1($login); echo $resp; } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/profile.php b/application/controllers/Profile.php similarity index 97% rename from bmt-system/application/controllers/profile.php rename to application/controllers/Profile.php index 08d34b2..92eb97c 100755 --- a/bmt-system/application/controllers/profile.php +++ b/application/controllers/Profile.php @@ -8,24 +8,24 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Profile extends Controller { +class Profile extends CI_Controller { function __construct() { - parent::Controller(); - $this->authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); + parent::__construct(); + $this->authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->load->library('encrypt'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "index"; + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "index"; $this->menuactsub = ""; } function index() { - $this->authlib->cekmain(); + $this->authlib->cekmain(); $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = 'vader'; $this->load->view('profile',$data); diff --git a/bmt-system/application/controllers/setordeposito.php b/application/controllers/Setordeposito.php similarity index 96% rename from bmt-system/application/controllers/setordeposito.php rename to application/controllers/Setordeposito.php index 0a3290f..0211442 100755 --- a/bmt-system/application/controllers/setordeposito.php +++ b/application/controllers/Setordeposito.php @@ -1,36 +1,36 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "transaksiumum"; - $this->menuactsub = "setordeposito"; - } - - //---- Admin - function index() - { + $this->menuactsub = "setordeposito"; + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('setordeposito',$data); + $this->load->view('setordeposito',$data); } - + //---- Fungsi mengisi option Wilayah function isi_wilayah() { @@ -72,7 +72,7 @@ function savetunai(){ $data1['create_date'] = date("Y-m-d H:i:s"); $data1['create_by'] = $this->session->userdata('username'); $data1['update_by'] = $this->session->userdata('username'); - //$data1['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data1['accounttrans_curency'] = $this->session->userdata('cbg'); $data2['accounttrans_listid'] = $data['id_jurnal']; $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); @@ -86,12 +86,12 @@ function savetunai(){ $data2['create_date'] = date("Y-m-d H:i:s"); $data2['create_by'] = $this->session->userdata('username'); $data2['update_by'] = $this->session->userdata('username'); - //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); - $id_jurnal= $data['id_jurnal']; - $nomor_ref= $data['nomor_ref']; - $nomor_rekening= $data['nomor_rekening']; - $nama= $data['nama']; + $id_jurnal= $data['id_jurnal']; + $nomor_ref= $data['nomor_ref']; + $nomor_rekening= $data['nomor_rekening']; + $nama= $data['nama']; unset($data['id_jurnal']); unset($data['biaya_jurnal']); unset($data['tgl_transaksi']); @@ -134,7 +134,7 @@ function login() $resp = $this->authlib->login1($login); echo $resp; } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/setortunai.php b/application/controllers/Setortunai.php similarity index 97% rename from bmt-system/application/controllers/setortunai.php rename to application/controllers/Setortunai.php index 7640531..3e0a231 100755 --- a/bmt-system/application/controllers/setortunai.php +++ b/application/controllers/Setortunai.php @@ -1,36 +1,36 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "transaksiumum"; - $this->menuactsub = "setortunai"; - } - - //---- Admin - function index() - { + $this->menuactsub = "setortunai"; + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('setortunai',$data); + $this->load->view('setortunai',$data); } - + //---- Fungsi mengisi option Wilayah function isi_wilayah() { @@ -86,59 +86,59 @@ function saldorata() $no_rekening = $data['id']; $jurnal = $data['jurnal']; $query1 = $this->db->query("SELECT accounttrans_date FROM tb_accounttrans WHERE accounttrans_listid=$jurnal AND accounttrans_user='".$no_rekening."'"); - $data1 = $query1->result_array(); - - $startdate = $data1[0]['accounttrans_date']; - $enddate = date("Y-m-d"); - $jhhari = $this->allfunct->dateRange($startdate,$enddate); - $xdate = $this->allfunct->frmDate($startdate,4); - $ydate = $this->allfunct->frmDate($enddate,4); - $xmonth = $this->allfunct->frmDate($startdate,5); - $ymonth = $this->allfunct->frmDate($enddate,5); - $xyear = $this->allfunct->frmDate($startdate,6); - $yyear = $this->allfunct->frmDate($enddate,6); - $saldo = 0; - $saldor = 0; - $saldorr = 0; - $saldo_rata = 0; - $ptitle =""; - $i = 1; - for($a=0;$a< $jhhari;$a++){ - $datenext = $this->allfunct->tenggang($a,$startdate); - $query1 = $this->db->query("SELECT accounttrans_user,`accounttrans_date`,SUM(CASE WHEN accounttrans_type like '01' THEN accounttrans_value END) AS jlh1, - SUM(CASE WHEN accounttrans_type like '02' THEN accounttrans_value END) AS jlh2 - FROM tb_accounttrans - WHERE accounttrans_listid=203 AND accounttrans_user='".$no_rekening."' - AND accounttrans_date ='$datenext' - GROUP BY accounttrans_user,`accounttrans_date`"); - $data1 = $query1->result_array(); - if($query1->num_rows() > 0) { - $saldo += ($data1[0]["jlh1"] - $data1[0]["jlh2"]) * 1; - $saldor += $saldo; - $saldorr = floor($saldor / $i); - $ptitle .= $no_rekening." = ".number_format($saldo,0)." = ".number_format($saldor,0)." / ".$a." ".$i." : ".number_format($saldorr,0)."
    "; - $saldo_rata = $saldorr; - $i++; - }else{ - $saldor += $saldo; - $saldorr = floor($saldor / $i); - $ptitle .= $no_rekening." = ".number_format($saldo,0)." = ".number_format($saldor,0)." / ".$a." ".$i." : ".number_format($saldorr,0)."
    "; - $saldo_rata = $saldorr; - if($saldo !=0){ - $i++; - } - } - } + $data1 = $query1->result_array(); + + $startdate = $data1[0]['accounttrans_date']; + $enddate = date("Y-m-d"); + $jhhari = $this->allfunct->dateRange($startdate,$enddate); + $xdate = $this->allfunct->frmDate($startdate,4); + $ydate = $this->allfunct->frmDate($enddate,4); + $xmonth = $this->allfunct->frmDate($startdate,5); + $ymonth = $this->allfunct->frmDate($enddate,5); + $xyear = $this->allfunct->frmDate($startdate,6); + $yyear = $this->allfunct->frmDate($enddate,6); + $saldo = 0; + $saldor = 0; + $saldorr = 0; + $saldo_rata = 0; + $ptitle =""; + $i = 1; + for($a=0;$a< $jhhari;$a++){ + $datenext = $this->allfunct->tenggang($a,$startdate); + $query1 = $this->db->query("SELECT accounttrans_user,`accounttrans_date`,SUM(CASE WHEN accounttrans_type like '01' THEN accounttrans_value END) AS jlh1, + SUM(CASE WHEN accounttrans_type like '02' THEN accounttrans_value END) AS jlh2 + FROM tb_accounttrans + WHERE accounttrans_listid=203 AND accounttrans_user='".$no_rekening."' + AND accounttrans_date ='$datenext' + GROUP BY accounttrans_user,`accounttrans_date`"); + $data1 = $query1->result_array(); + if($query1->num_rows() > 0) { + $saldo += ($data1[0]["jlh1"] - $data1[0]["jlh2"]) * 1; + $saldor += $saldo; + $saldorr = floor($saldor / $i); + $ptitle .= $no_rekening." = ".number_format($saldo,0)." = ".number_format($saldor,0)." / ".$a." ".$i." : ".number_format($saldorr,0)."
    "; + $saldo_rata = $saldorr; + $i++; + }else{ + $saldor += $saldo; + $saldorr = floor($saldor / $i); + $ptitle .= $no_rekening." = ".number_format($saldo,0)." = ".number_format($saldor,0)." / ".$a." ".$i." : ".number_format($saldorr,0)."
    "; + $saldo_rata = $saldorr; + if($saldo !=0){ + $i++; + } + } + } echo $saldo_rata; } function savetunai(){ $data = $this->allfunct->securePost(); - // - $query = $this->db->query("SELECT blockir FROM tb_tabungan WHERE nomor_rekening='".$data['nomor_rekening']."'"); - $datar = $query->result_array(); - $blockir = $datar[0]["blockir"]; - if(($blockir == "Block Kredit")||($blockir == "Block Debet-Kredit")){ - echo "Maaf Tabungan anda di blokir silahkan hubungi administrator"; + // + $query = $this->db->query("SELECT blockir FROM tb_tabungan WHERE nomor_rekening='".$data['nomor_rekening']."'"); + $datar = $query->result_array(); + $blockir = $datar[0]["blockir"]; + if(($blockir == "Block Kredit")||($blockir == "Block Debet-Kredit")){ + echo "Maaf Tabungan anda di blokir silahkan hubungi administrator"; }else{ $data3['accounttrans_listid'] = "19"; $data3['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); @@ -149,7 +149,7 @@ function savetunai(){ $data3['accounttrans_user'] = $data['nomor_rekening']; $data3['create_date'] = date("Y-m-d H:i:s"); $data3['create_by'] = $this->session->userdata('username'); - $data3['update_by'] = $this->session->userdata('username'); + $data3['update_by'] = $this->session->userdata('username'); // $data2['accounttrans_listid'] = $data['id_jurnal']; @@ -161,13 +161,13 @@ function savetunai(){ $data2['accounttrans_user'] = $data['nomor_rekening']; $data2['create_date'] = date("Y-m-d H:i:s"); $data2['create_by'] = $this->session->userdata('username'); - $data2['update_by'] = $this->session->userdata('username'); - //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); - + $data2['update_by'] = $this->session->userdata('username'); + //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); + $nomor_jurnal= $data['nomor_jurnal']; - $nomor_ref= $data['nomor_ref']; - $nomor_rekening= $data['nomor_rekening']; - $nama= $data['nama']; + $nomor_ref= $data['nomor_ref']; + $nomor_rekening= $data['nomor_rekening']; + $nama= $data['nama']; unset($data['id_jurnal']); unset($data['biaya_jurnal']); unset($data['tgl_transaksi']); @@ -188,7 +188,7 @@ function savetunai(){ $data2['accounttrans_posted'] = '1'; $data3['accounttrans_posted'] = '1'; $this->master->simpan('tb_accounttemp',$data2); - $this->master->simpan('tb_accounttemp',$data3); + $this->master->simpan('tb_accounttemp',$data3); } } function single_pegawai() @@ -203,14 +203,14 @@ function single_pegawai() }else{ echo ""; } - } - function cetakValidasi() - { - $query = $this->db->query("SELECT wilayah_kerja FROM bmt WHERE bmt_id =1"); - $data = $query->result_array(); - $data1['code_cabang'] = $data[0]["wilayah_kerja"]; - $data1['teller'] = $this->session->userdata('username'); - $this->load->view('cetak/validasi',$data1); + } + function cetakValidasi() + { + $query = $this->db->query("SELECT wilayah_kerja FROM bmt WHERE bmt_id =1"); + $data = $query->result_array(); + $data1['code_cabang'] = $data[0]["wilayah_kerja"]; + $data1['teller'] = $this->session->userdata('username'); + $this->load->view('cetak/validasi',$data1); } function login() { @@ -219,7 +219,7 @@ function login() $resp = $this->authlib->login1($login); echo $resp; } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/sync.php b/application/controllers/Sync.php similarity index 95% rename from bmt-system/application/controllers/sync.php rename to application/controllers/Sync.php index 5bbce9e..864972a 100644 --- a/bmt-system/application/controllers/sync.php +++ b/application/controllers/Sync.php @@ -4,24 +4,24 @@ * Copyright (c) 2014 * * file : sync.php - * author : Edi Suwoto S.Komp + * author : Edi Suwoto S.Komp * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Sync extends Controller { +class Sync extends CI_Controller { function __construct() { - parent::Controller(); - //$this->authlib->cekcontr(); - $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + parent::__construct(); + //$this->authlib->cekcontr(); + $this->load->model('master_model','master'); + $this->load->model('admin_model','modelku'); + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); } function index() { - } + } function login(){ $data = $this->allfunct->securePost(); $id = $data['id']; diff --git a/bmt-system/application/controllers/tariktunai.php b/application/controllers/Tariktunai.php similarity index 96% rename from bmt-system/application/controllers/tariktunai.php rename to application/controllers/Tariktunai.php index 8385c5b..7844bbd 100755 --- a/bmt-system/application/controllers/tariktunai.php +++ b/application/controllers/Tariktunai.php @@ -1,36 +1,36 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "transaksiumum"; - $this->menuactsub = "tariktunai"; - } - - //---- Admin - function index() - { + $this->menuactsub = "tariktunai"; + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('tariktunai',$data); + $this->load->view('tariktunai',$data); } - + //---- Fungsi mengisi option Wilayah function isi_wilayah() { @@ -68,7 +68,7 @@ function saldo() function saldoval() { $data = $this->allfunct->securePost(); - $no_rekening = $data['id']; + $no_rekening = $data['id']; $id_jurnal = $data['id_jurnal']; $query = $this->db->query("SELECT sum(accounttrans_value) as jlh FROM tb_accounttrans WHERE accounttrans_listid='".$id_jurnal."' AND accounttrans_user='".$no_rekening."' and accounttrans_type='01'"); $data = $query->result_array(); @@ -82,13 +82,13 @@ function saldoval() } } function savetunai(){ - $data = $this->allfunct->securePost(); - //cek status tabungan - $query = $this->db->query("SELECT blockir FROM tb_tabungan WHERE nomor_rekening='".$data['nomor_rekening']."'"); - $datar = $query->result_array(); - $blockir = $datar[0]["blockir"]; - if(($blockir == "Block Debet")||($blockir == "Block Debet-Kredit")){ - echo "Maaf Tabungan anda di blokir silahkan hubungi administrator"; + $data = $this->allfunct->securePost(); + //cek status tabungan + $query = $this->db->query("SELECT blockir FROM tb_tabungan WHERE nomor_rekening='".$data['nomor_rekening']."'"); + $datar = $query->result_array(); + $blockir = $datar[0]["blockir"]; + if(($blockir == "Block Debet")||($blockir == "Block Debet-Kredit")){ + echo "Maaf Tabungan anda di blokir silahkan hubungi administrator"; }else{ $data1['accounttrans_listid'] = "19"; $data1['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); @@ -100,7 +100,7 @@ function savetunai(){ $data1['create_date'] = date("Y-m-d H:i:s"); $data1['create_by'] = $this->session->userdata('username'); $data1['update_by'] = $this->session->userdata('username'); - //$data1['accounttrans_curency'] = $this->session->userdata('cbg'); + //$data1['accounttrans_curency'] = $this->session->userdata('cbg'); $data2['accounttrans_listid'] = $data['id_jurnal']; $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); @@ -112,11 +112,11 @@ function savetunai(){ $data2['create_date'] = date("Y-m-d H:i:s"); $data2['create_by'] = $this->session->userdata('username'); $data2['update_by'] = $this->session->userdata('username'); - //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); - - $nomor_jurnal= $data['nomor_jurnal']; - $nomor_ref= $data['nomor_ref']; - $nomor_rekening= $data['nomor_rekening']; + //$data2['accounttrans_curency'] = $this->session->userdata('cbg'); + + $nomor_jurnal= $data['nomor_jurnal']; + $nomor_ref= $data['nomor_ref']; + $nomor_rekening= $data['nomor_rekening']; $nama= $data['nama']; unset($data['id_jurnal']); unset($data['biaya_jurnal']); @@ -130,12 +130,12 @@ function savetunai(){ $data1['accounttrans_posted'] = '1'; $this->master->simpan('tb_accounttemp',$data1); echo $this->master->simpan('tb_accounttemp',$data2)."#".$nomor_jurnal."#".$nomor_ref."#".$nomor_rekening." ".$nama; - } + } } function limittarik(){ $data = $this->allfunct->securePost(); $nilai = $data['nilai']; - $userlevel = $this->authlib->levellogin($this->session->userdata('username')); + $userlevel = $this->authlib->levellogin($this->session->userdata('username')); if($userlevel != 1){ $query = $this->db->query("SELECT kode FROM master_otoritas WHERE level='".$userlevel."'"); $data = $query->result_array(); @@ -173,7 +173,7 @@ function login() $resp = $this->authlib->login1($login); echo $resp; } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/application/controllers/Tes.php b/application/controllers/Tes.php new file mode 100644 index 0000000..de556bd --- /dev/null +++ b/application/controllers/Tes.php @@ -0,0 +1,26 @@ + + * @see http://codeigniter.com/user_guide/general/urls.html + */ + public function index() + { + echo $this->encrypt->encode('123456'); + $this->load->view('welcome_message'); + } +} diff --git a/bmt-system/application/controllers/welcome.php b/application/controllers/Welcome.php similarity index 91% rename from bmt-system/application/controllers/welcome.php rename to application/controllers/Welcome.php index 0f396ca..f9bc592 100755 --- a/bmt-system/application/controllers/welcome.php +++ b/application/controllers/Welcome.php @@ -1,33 +1,34 @@ -authlib->cekcontr(); +load->library('allfunct'); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "index"; - $this->menuactsub = ""; - } - - function index() - { + $this->menuactsub = ""; + } + + function index() + { $this->authlib->cekmain(); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); - $data['tema'] = 'vader'; - $this->load->view('welcome',$data); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['tema'] = 'vader'; + $this->load->view('welcome',$data); } function get_session() { @@ -47,7 +48,7 @@ function get_session() $hasil['alldata'] = $alldata['result']; echo json_encode($hasil); } - } -} - + } +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/akunting/jurnal.php b/application/controllers/akunting/Jurnal.php similarity index 97% rename from bmt-system/application/controllers/akunting/jurnal.php rename to application/controllers/akunting/Jurnal.php index 0191101..b990d4b 100755 --- a/bmt-system/application/controllers/akunting/jurnal.php +++ b/application/controllers/akunting/Jurnal.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Jurnal extends Controller { +class Jurnal extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); error_reporting(E_ALL & ~E_NOTICE); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); diff --git a/bmt-system/application/controllers/akunting/labarugi.php b/application/controllers/akunting/Labarugi.php similarity index 97% rename from bmt-system/application/controllers/akunting/labarugi.php rename to application/controllers/akunting/Labarugi.php index 4b20da2..2bbba12 100755 --- a/bmt-system/application/controllers/akunting/labarugi.php +++ b/application/controllers/akunting/Labarugi.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Labarugi extends Controller { +class Labarugi extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -109,11 +109,11 @@ function getCOAjurnaldetail() } $isi .= "
    "; $isi .= ""; - $item = substr($val->listakun_pattern,0,2); - if(($item == "5*")||($item == "6*")){ - $totalLaba += $totaln; - }else{ - $totalLaba -= $totaln; + $item = substr($val->listakun_pattern,0,2); + if(($item == "5*")||($item == "6*")){ + $totalLaba += $totaln; + }else{ + $totalLaba -= $totaln; } } } @@ -131,7 +131,7 @@ function nilaivalue($id,$tglawal,$tglakhir){ $query1 = $this->db->query("SELECT SUM(CASE WHEN accounttrans_type like '01' THEN accounttrans_value END) AS jlh1 FROM tb_accounttrans WHERE accounttrans_listid=$id AND accounttrans_date BETWEEN '$tglawal' AND '$tglakhir'"); } $query2 = $this->db->query("SELECT SUM(CASE WHEN accounttrans_type like '02' THEN accounttrans_value END) AS jlh2 FROM tb_accounttrans WHERE accounttrans_listid=$id AND accounttrans_date BETWEEN '$tglawal' AND '$tglakhir'"); - $query3 = $this->db->query("SELECT listakun_pattern FROM coa_listakun WHERE listakun_id=$id"); + $query3 = $this->db->query("SELECT listakun_pattern FROM coa_listakun WHERE listakun_id=$id"); $data1 = $query1->result_array(); $data2 = $query2->result_array(); @@ -143,15 +143,15 @@ function nilaivalue($id,$tglawal,$tglakhir){ ///525.52 if(($id =="349")||($id =="348")||($id =="350")||($id =="352")||($id =="353") ||($id =="342")||($id =="343") ||($id == "325")||($id == "326")||($id == "327")||($id == "328")||($id == "329")||($id == "330") || ($id == "334")||($id == "335")||($id == "336")||($id == "337")||($id == "338")||($id == "339")){ $trans = $data1[0]["jlh1"] * -1; - }else{ + }else{ $trans = $data1[0]["jlh1"] * 1; - } + } }elseif($item == "6*"){ $trans = $data1[0]["jlh1"] * -1; }elseif($item == "7*"){ $trans = $data2[0]["jlh2"] * 1; - }else{ - $trans = ($data2[0]["jlh2"] - $data1[0]["jlh1"]) * 1; + }else{ + $trans = ($data2[0]["jlh2"] - $data1[0]["jlh1"]) * 1; } return $trans; } diff --git a/bmt-system/application/controllers/akunting/neraca.php b/application/controllers/akunting/Neraca.php similarity index 97% rename from bmt-system/application/controllers/akunting/neraca.php rename to application/controllers/akunting/Neraca.php index b5a838e..19072dd 100755 --- a/bmt-system/application/controllers/akunting/neraca.php +++ b/application/controllers/akunting/Neraca.php @@ -1,18 +1,18 @@ authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -149,15 +149,15 @@ function nilaivalue($id,$tglawal){ $query2 = $this->db->query("SELECT SUM(CASE WHEN accounttrans_type like '02' THEN accounttrans_value END) AS jlh2 FROM tb_accounttrans WHERE accounttrans_listid=$id AND accounttrans_date <='$tglawal'"); $data1 = $query1->result_array(); $data2 = $query2->result_array(); - $query3 = $this->db->query("SELECT listakun_pattern FROM coa_listakun WHERE listakun_id=$id"); - $data1 = $query1->result_array(); - $data2 = $query2->result_array(); - $data3 = $query3->result_array(); + $query3 = $this->db->query("SELECT listakun_pattern FROM coa_listakun WHERE listakun_id=$id"); + $data1 = $query1->result_array(); + $data2 = $query2->result_array(); + $data3 = $query3->result_array(); $item = substr($data3[0]["listakun_pattern"],0,2); $item1 = substr($data3[0]["listakun_pattern"],0,3); - if($id =="285"){ - $trans = $this->Labarugi($tglawal); - }else{ + if($id =="285"){ + $trans = $this->Labarugi($tglawal); + }else{ if($item == "2*"){ $trans = ($data1[0]["jlh1"] - $data2[0]["jlh2"]) * 1; }elseif($item == "3*"){ @@ -166,8 +166,8 @@ function nilaivalue($id,$tglawal){ $trans = ($data1[0]["jlh1"] - $data2[0]["jlh2"]) * 1; }else{ $trans = ($data2[0]["jlh2"] - $data1[0]["jlh1"]) * 1; - } - } + } + } return $trans; } function Labarugi($tglakhir){ @@ -200,19 +200,19 @@ function Labarugi($tglakhir){ function nilaivalueLaba($id,$tglakhir){ $query1 = $this->db->query("SELECT SUM(CASE WHEN accounttrans_type like '01' THEN accounttrans_value END) AS jlh1 FROM tb_accounttrans WHERE accounttrans_listid=$id AND accounttrans_date <='$tglakhir'"); $query2 = $this->db->query("SELECT SUM(CASE WHEN accounttrans_type like '02' THEN accounttrans_value END) AS jlh2 FROM tb_accounttrans WHERE accounttrans_listid=$id AND accounttrans_date <='$tglakhir'"); - $query3 = $this->db->query("SELECT listakun_pattern FROM coa_listakun WHERE listakun_id=$id"); - $data1 = $query1->result_array(); - $data2 = $query2->result_array(); - $data3 = $query3->result_array(); - $item = substr($data3[0]["listakun_pattern"],0,2); - if($item == "5*"){ - $trans = ($data1[0]["jlh1"] - $data2[0]["jlh2"]) * 1; - }elseif($item == "6*"){ - $trans = ($data1[0]["jlh1"] - $data2[0]["jlh2"]) * 1; + $query3 = $this->db->query("SELECT listakun_pattern FROM coa_listakun WHERE listakun_id=$id"); + $data1 = $query1->result_array(); + $data2 = $query2->result_array(); + $data3 = $query3->result_array(); + $item = substr($data3[0]["listakun_pattern"],0,2); + if($item == "5*"){ + $trans = ($data1[0]["jlh1"] - $data2[0]["jlh2"]) * 1; + }elseif($item == "6*"){ + $trans = ($data1[0]["jlh1"] - $data2[0]["jlh2"]) * 1; }elseif($item == "7*"){ $trans = ($data1[0]["jlh1"] - $data2[0]["jlh2"]) * 1; - }else{ - $trans = ($data2[0]["jlh2"] - $data1[0]["jlh1"]) * 1; + }else{ + $trans = ($data2[0]["jlh2"] - $data1[0]["jlh1"]) * 1; } return $trans; } diff --git a/bmt-system/application/controllers/akunting/posting.php b/application/controllers/akunting/Posting.php similarity index 96% rename from bmt-system/application/controllers/akunting/posting.php rename to application/controllers/akunting/Posting.php index 7146c49..787849c 100755 --- a/bmt-system/application/controllers/akunting/posting.php +++ b/application/controllers/akunting/Posting.php @@ -1,18 +1,18 @@ authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -31,32 +31,32 @@ function index() $this->load->view('akunting/posting',$data); } - function get_koreksiview() - { - $tgl1 = $this->allfunct->revDate($this->input->post('tgl1')); - $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); - $where = " WHERE 1 "; - if(($tgl1 != "")&&($tgl2 != "")){ - $where .= " AND accounttrans_date BETWEEN '$tgl1' AND '$tgl2'"; - } - $query = $this->db->query("SELECT * FROM tb_accounttrans ".$where." ORDER BY accounttrans_id ASC"); - $data = $query->result_array(); - //echo $data; - $hasil['alldata'] = $data; - echo json_encode($hasil); + function get_koreksiview() + { + $tgl1 = $this->allfunct->revDate($this->input->post('tgl1')); + $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); + $where = " WHERE 1 "; + if(($tgl1 != "")&&($tgl2 != "")){ + $where .= " AND accounttrans_date BETWEEN '$tgl1' AND '$tgl2'"; + } + $query = $this->db->query("SELECT * FROM tb_accounttrans ".$where." ORDER BY accounttrans_id ASC"); + $data = $query->result_array(); + //echo $data; + $hasil['alldata'] = $data; + echo json_encode($hasil); } - function delkoreksi(){ - $data = $this->allfunct->securePost(); - $val = $data['val']; - $x = substr($val,0,+3); - if($x == "on,"){ - $val = str_replace('on,','',$val); - } - $val = explode(",", $val); - for($i=0;$i $val[$i]); - echo $this->master->delete("tb_accounttrans",$where); - } + function delkoreksi(){ + $data = $this->allfunct->securePost(); + $val = $data['val']; + $x = substr($val,0,+3); + if($x == "on,"){ + $val = str_replace('on,','',$val); + } + $val = explode(",", $val); + for($i=0;$i $val[$i]); + echo $this->master->delete("tb_accounttrans",$where); + } } function get_transaksiview() { @@ -96,7 +96,7 @@ function updatepost(){ $resp['create_date'] = date("Y-m-d H:i:s"); $resp['create_by'] = $this->session->userdata('username'); $resp['update_by'] = $this->session->userdata('username'); - $resp['accounttrans_curency'] = $this->session->userdata('cbg'); + $resp['accounttrans_curency'] = $this->session->userdata('cbg'); $this->master->simpan('tb_accounttrans',$resp); diff --git a/bmt-system/application/controllers/base/deposito.php b/application/controllers/base/Deposito.php similarity index 96% rename from bmt-system/application/controllers/base/deposito.php rename to application/controllers/base/Deposito.php index fea14fe..3897a24 100755 --- a/bmt-system/application/controllers/base/deposito.php +++ b/application/controllers/base/Deposito.php @@ -1,35 +1,35 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "base"; $this->menuactsub = "deposito"; - } - - //---- Admin - function index() - { + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('base/deposito',$data); - } + $this->load->view('base/deposito',$data); + } function run_code() { @@ -88,28 +88,28 @@ function editdata(){ $data['update_by'] = $this->session->userdata('username'); $where = array('deposito_id' => $id); echo $this->master->update("tb_deposito",$data,$where); - } - function get_data() - { - $ff = $this->input->post('ff'); // Jenis Filter - $if = $this->input->post('if'); // Value Filter - $fd = $this->input->post('fd'); // Field Sorting - $adsc = $this->input->post('adsc'); // Asc or Desc - $hal = $this->input->post('hal'); // Offset Limit - $juml = $this->input->post('juml'); // Jumlah Limit - $awal = $juml * ($hal - 1); - $alldata = $this->modelku->getAllDeposito($ff,$if,$fd,$adsc,$awal,$juml); - $records = $alldata['numrow']; - $page_num = ceil($records / $juml); - if ($records > 0) + } + function get_data() + { + $ff = $this->input->post('ff'); // Jenis Filter + $if = $this->input->post('if'); // Value Filter + $fd = $this->input->post('fd'); // Field Sorting + $adsc = $this->input->post('adsc'); // Asc or Desc + $hal = $this->input->post('hal'); // Offset Limit + $juml = $this->input->post('juml'); // Jumlah Limit + $awal = $juml * ($hal - 1); + $alldata = $this->modelku->getAllDeposito($ff,$if,$fd,$adsc,$awal,$juml); + $records = $alldata['numrow']; + $page_num = ceil($records / $juml); + if ($records > 0) { - $hasil['total'] = $page_num; - $hasil['alldata'] = $alldata['result']; - echo json_encode($hasil); + $hasil['total'] = $page_num; + $hasil['alldata'] = $alldata['result']; + echo json_encode($hasil); }else{ $hasil['alldata'] = 0; echo $hasil; - } + } } //---- Fungsi mengisi option function isi_deposito() @@ -160,7 +160,7 @@ function tabungan() }else{ echo ""; } - } -} - + } +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/base/jaminan.php b/application/controllers/base/Jaminan.php similarity index 95% rename from bmt-system/application/controllers/base/jaminan.php rename to application/controllers/base/Jaminan.php index efc66d6..5434f46 100755 --- a/bmt-system/application/controllers/base/jaminan.php +++ b/application/controllers/base/Jaminan.php @@ -1,35 +1,35 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "base"; $this->menuactsub = "jaminan"; - } - - //---- Admin - function index() - { + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('base/jaminan',$data); - } + $this->load->view('base/jaminan',$data); + } function run_code() { @@ -78,45 +78,45 @@ function editjaminan(){ $data['update_by'] = $this->session->userdata('username'); $where = array('nomor_jaminan' => $id); echo $this->master->update("tb_jaminan",$data,$where); - } - function get_jaminan() - { - $ff = $this->input->post('ff'); // Jenis Filter - $if = $this->input->post('if'); // Value Filter - $fd = $this->input->post('fd'); // Field Sorting - $adsc = $this->input->post('adsc'); // Asc or Desc - $hal = $this->input->post('hal'); // Offset Limit - $juml = $this->input->post('juml'); // Jumlah Limit - $awal = $juml * ($hal - 1); - $alldata = $this->modelku->getAllJaminan($ff,$if,$fd,$adsc,$awal,$juml); - $records = $alldata['numrow']; - $page_num = ceil($records / $juml); - if ($records > 0) - { + } + function get_jaminan() + { + $ff = $this->input->post('ff'); // Jenis Filter + $if = $this->input->post('if'); // Value Filter + $fd = $this->input->post('fd'); // Field Sorting + $adsc = $this->input->post('adsc'); // Asc or Desc + $hal = $this->input->post('hal'); // Offset Limit + $juml = $this->input->post('juml'); // Jumlah Limit + $awal = $juml * ($hal - 1); + $alldata = $this->modelku->getAllJaminan($ff,$if,$fd,$adsc,$awal,$juml); + $records = $alldata['numrow']; + $page_num = ceil($records / $juml); + if ($records > 0) + { - $hasil['total'] = $page_num; - $hasil['alldata'] = $alldata['result']; - echo json_encode($hasil); - } + $hasil['total'] = $page_num; + $hasil['alldata'] = $alldata['result']; + echo json_encode($hasil); + } } - function get_pembiayaan(){ - $ff = $this->input->post('ff'); // Jenis Filter - $if = $this->input->post('if'); // Value Filter - $fd = $this->input->post('fd'); // Field Sorting - $adsc = $this->input->post('adsc'); // Asc or Desc - $hal = $this->input->post('hal'); // Offset Limit - $juml = $this->input->post('juml'); // Jumlah Limit - $awal = $juml * ($hal - 1); - $alldata = $this->modelku->getAllJaminanPembiayaan($ff,$if,$fd,$adsc,$awal,$juml); - $records = $alldata['numrow']; - $page_num = ceil($records / $juml); - if ($records > 0) - { - - $hasil['total'] = $page_num; - $hasil['alldata'] = $alldata['result']; - echo json_encode($hasil); - } + function get_pembiayaan(){ + $ff = $this->input->post('ff'); // Jenis Filter + $if = $this->input->post('if'); // Value Filter + $fd = $this->input->post('fd'); // Field Sorting + $adsc = $this->input->post('adsc'); // Asc or Desc + $hal = $this->input->post('hal'); // Offset Limit + $juml = $this->input->post('juml'); // Jumlah Limit + $awal = $juml * ($hal - 1); + $alldata = $this->modelku->getAllJaminanPembiayaan($ff,$if,$fd,$adsc,$awal,$juml); + $records = $alldata['numrow']; + $page_num = ceil($records / $juml); + if ($records > 0) + { + + $hasil['total'] = $page_num; + $hasil['alldata'] = $alldata['result']; + echo json_encode($hasil); + } } function single_pegawai() { @@ -130,7 +130,7 @@ function single_pegawai() }else{ echo ""; } - } -} - + } +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/base/nasabah.php b/application/controllers/base/Nasabah.php similarity index 96% rename from bmt-system/application/controllers/base/nasabah.php rename to application/controllers/base/Nasabah.php index e61ba5c..65764d6 100755 --- a/bmt-system/application/controllers/base/nasabah.php +++ b/application/controllers/base/Nasabah.php @@ -1,44 +1,44 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "base"; $this->menuactsub = "nasabah"; - } - - //---- Admin - function index() - { + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); - $data['tema'] = $this->tema; - $data['excel'] = true; + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['tema'] = $this->tema; + $data['excel'] = true; $data['excelclass'] = "excel_nasabah"; - $this->load->view('base/nasabah',$data); - } - function cetak_excel(){ - $alldata = $this->modelku->getAllNasabah($ff,$if,$fd,$adsc,$awal,$juml); - - $data['hasi'] = $alldata; - $data['filename'] = "data_nasabah"; - $this->load->view('spreadsheet_view',$data); - } + $this->load->view('base/nasabah',$data); + } + function cetak_excel(){ + $alldata = $this->modelku->getAllNasabah($ff,$if,$fd,$adsc,$awal,$juml); + + $data['hasi'] = $alldata; + $data['filename'] = "data_nasabah"; + $this->load->view('spreadsheet_view',$data); + } function run_code() { @@ -47,7 +47,7 @@ function run_code() $cabang = $data[0]["kode"]; $num = $this->db->count_all_results('tb_nasabah') + 1; - $paddedNum = sprintf("%03d", $num); + $paddedNum = sprintf("%03d", $num); echo $cabang."".date('m')."".date('y')."".$paddedNum; } @@ -65,12 +65,12 @@ function saveNasabah(){ } if($data['tanggal_lahir'] !=""){ $data['tanggal_lahir'] = $this->allfunct->revDate($data['tanggal_lahir']); - } - if($data['berlaku_identitas_waris'] !=""){ - $data['berlaku_identitas_waris'] = $this->allfunct->revDate($data['berlaku_identitas_waris']); - } - if($data['berlaku_identitas'] !=""){ - $data['berlaku_identitas'] = $this->allfunct->revDate($data['berlaku_identitas']); + } + if($data['berlaku_identitas_waris'] !=""){ + $data['berlaku_identitas_waris'] = $this->allfunct->revDate($data['berlaku_identitas_waris']); + } + if($data['berlaku_identitas'] !=""){ + $data['berlaku_identitas'] = $this->allfunct->revDate($data['berlaku_identitas']); } $data['create_by'] = $this->session->userdata('username'); $data['update_by'] = $this->session->userdata('username'); @@ -89,28 +89,28 @@ function editNasabah(){ $data['update_by'] = $this->session->userdata('username'); $where = array('nomor_nasabah' => $id); echo $this->master->update("tb_nasabah",$data,$where); - } - function get_nasabah() - { - $ff = $this->input->post('ff'); // Jenis Filter - $if = $this->input->post('if'); // Value Filter - $fd = $this->input->post('fd'); // Field Sorting - $adsc = $this->input->post('adsc'); // Asc or Desc - $hal = $this->input->post('hal'); // Offset Limit - $juml = $this->input->post('juml'); // Jumlah Limit - $awal = $juml * ($hal - 1); - $alldata = $this->modelku->getAllNasabah($ff,$if,$fd,$adsc,$awal,$juml); - $records = $alldata['numrow']; - $page_num = ceil($records / $juml); - if ($records > 0) - { + } + function get_nasabah() + { + $ff = $this->input->post('ff'); // Jenis Filter + $if = $this->input->post('if'); // Value Filter + $fd = $this->input->post('fd'); // Field Sorting + $adsc = $this->input->post('adsc'); // Asc or Desc + $hal = $this->input->post('hal'); // Offset Limit + $juml = $this->input->post('juml'); // Jumlah Limit + $awal = $juml * ($hal - 1); + $alldata = $this->modelku->getAllNasabah($ff,$if,$fd,$adsc,$awal,$juml); + $records = $alldata['numrow']; + $page_num = ceil($records / $juml); + if ($records > 0) + { - $hasil['total'] = $page_num; - $hasil['alldata'] = $alldata['result']; - echo json_encode($hasil); - } + $hasil['total'] = $page_num; + $hasil['alldata'] = $alldata['result']; + echo json_encode($hasil); + } } - + function isi_propinsi() { $hasil = $this->db->select('kodeBPS,namaProvinsi')->get('provinsi')->result(); @@ -192,7 +192,7 @@ function single_kecamatan() echo ""; } } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/base/pembiayaan.php b/application/controllers/base/Pembiayaan.php similarity index 97% rename from bmt-system/application/controllers/base/pembiayaan.php rename to application/controllers/base/Pembiayaan.php index 3f49509..1d766dc 100755 --- a/bmt-system/application/controllers/base/pembiayaan.php +++ b/application/controllers/base/Pembiayaan.php @@ -1,35 +1,35 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "base"; $this->menuactsub = "pembiayaan"; - } - - //---- Admin - function index() - { + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('base/pembiayaan',$data); - } + $this->load->view('base/pembiayaan',$data); + } function run_code() { @@ -170,58 +170,58 @@ function dataangsuran($id_pembiayaan){ $data1['update_by'] = $this->session->userdata('username'); $this->master->simpan('tb_pembiayaandetail',$data1); } - }elseif(($data[0]['modal'] != 0)){ - $nisbah_bank = $data[0]['nisbah_bank']; - $nisbah_nasabah = $data[0]['nisbah_nasabah']; - $modal = $data[0]['modal']; - - $pokok = $modal / $data[0]['lama_angsuran']; - $margin = 0; - $jumlah = $pokok + $margin; - for($i=0;$i < $data[0]['lama_angsuran'];$i++){ - if($data[0]['type_angsuran'] == "HARI"){ - $dateangs = $this->authlib->getNextBillDay($data[0]['mulai_angsuran'],$i); - }elseif($data[0]['type_angsuran'] == "MINGGU"){ - $dateangs = $this->authlib->getNextBillMinggu($data[0]['mulai_angsuran'],$minggu); - $minggu += 7; - }elseif($data[0]['type_angsuran'] == "BULAN"){ - $dateangs = $this->authlib->getNextBillDate($data[0]['mulai_angsuran'],$i); - } - $data1['id_pembiayaan'] = $id_pembiayaan; - $data1['tgl_angsuran'] = $dateangs; - $data1['pokok'] = $pokok; - $data1['margin'] = $margin; - $data1['jumlah'] = $jumlah; - $data1['create_by'] = $this->session->userdata('username'); - $data1['update_by'] = $this->session->userdata('username'); - $this->master->simpan('tb_pembiayaandetail',$data1); - } - } + }elseif(($data[0]['modal'] != 0)){ + $nisbah_bank = $data[0]['nisbah_bank']; + $nisbah_nasabah = $data[0]['nisbah_nasabah']; + $modal = $data[0]['modal']; + + $pokok = $modal / $data[0]['lama_angsuran']; + $margin = 0; + $jumlah = $pokok + $margin; + for($i=0;$i < $data[0]['lama_angsuran'];$i++){ + if($data[0]['type_angsuran'] == "HARI"){ + $dateangs = $this->authlib->getNextBillDay($data[0]['mulai_angsuran'],$i); + }elseif($data[0]['type_angsuran'] == "MINGGU"){ + $dateangs = $this->authlib->getNextBillMinggu($data[0]['mulai_angsuran'],$minggu); + $minggu += 7; + }elseif($data[0]['type_angsuran'] == "BULAN"){ + $dateangs = $this->authlib->getNextBillDate($data[0]['mulai_angsuran'],$i); + } + $data1['id_pembiayaan'] = $id_pembiayaan; + $data1['tgl_angsuran'] = $dateangs; + $data1['pokok'] = $pokok; + $data1['margin'] = $margin; + $data1['jumlah'] = $jumlah; + $data1['create_by'] = $this->session->userdata('username'); + $data1['update_by'] = $this->session->userdata('username'); + $this->master->simpan('tb_pembiayaandetail',$data1); + } + } } - } - function get_pembiayaan() - { - $ff = $this->input->post('ff'); // Jenis Filter - $if = $this->input->post('if'); // Value Filter - $fd = $this->input->post('fd'); // Field Sorting - $adsc = $this->input->post('adsc'); // Asc or Desc - $hal = $this->input->post('hal'); // Offset Limit - $juml = $this->input->post('juml'); // Jumlah Limit - $awal = $juml * ($hal - 1); - $alldata = $this->modelku->getAllPembiayaan($ff,$if,$fd,$adsc,$awal,$juml); - $records = $alldata['numrow']; - $page_num = ceil($records / $juml); - if ($records > 0) + } + function get_pembiayaan() + { + $ff = $this->input->post('ff'); // Jenis Filter + $if = $this->input->post('if'); // Value Filter + $fd = $this->input->post('fd'); // Field Sorting + $adsc = $this->input->post('adsc'); // Asc or Desc + $hal = $this->input->post('hal'); // Offset Limit + $juml = $this->input->post('juml'); // Jumlah Limit + $awal = $juml * ($hal - 1); + $alldata = $this->modelku->getAllPembiayaan($ff,$if,$fd,$adsc,$awal,$juml); + $records = $alldata['numrow']; + $page_num = ceil($records / $juml); + if ($records > 0) { - $hasil['total'] = $page_num; - $hasil['alldata'] = $alldata['result']; - echo json_encode($hasil); + $hasil['total'] = $page_num; + $hasil['alldata'] = $alldata['result']; + echo json_encode($hasil); }else{ $hasil['alldata'] = 0; echo $hasil; - } + } } function get_jadwalview() { @@ -281,7 +281,7 @@ function single_jaminan() }else{ echo ""; } - } -} - + } +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/base/tabungan.php b/application/controllers/base/Tabungan.php similarity index 96% rename from bmt-system/application/controllers/base/tabungan.php rename to application/controllers/base/Tabungan.php index 0bb0f53..ff284f9 100755 --- a/bmt-system/application/controllers/base/tabungan.php +++ b/application/controllers/base/Tabungan.php @@ -1,65 +1,65 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "base"; $this->menuactsub = "tabungan"; - } - - //---- Admin - function index() - { + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('base/tabungan',$data); - } + $this->load->view('base/tabungan',$data); + } function run_code() { $id = $this->input->post('id'); - $cab = $this->input->post('cab'); + $cab = $this->input->post('cab'); //$query = $this->db->query("SELECT count(*) AS jlh FROM tb_tabungan WHERE nomor_rekening LIKE '$id%'"); - $query = $this->db->query("SELECT nomor_rekening AS jlh FROM tb_tabungan WHERE nomor_rekening LIKE '$id%' order by nomor_rekening desc"); + $query = $this->db->query("SELECT nomor_rekening AS jlh FROM tb_tabungan WHERE nomor_rekening LIKE '$id%' order by nomor_rekening desc"); $data = $query->result_array(); - - if($query->num_rows() > 0){ - $num = $data[0]["jlh"] + 1; - $paddedNum = $num; - }else{ - $paddedNum = $id."".$cab."".sprintf("%05d", 1); + + if($query->num_rows() > 0){ + $num = $data[0]["jlh"] + 1; + $paddedNum = $num; + }else{ + $paddedNum = $id."".$cab."".sprintf("%05d", 1); } echo $paddedNum; - } - function isi_propinsi() - { - $hasil = $this->db->select('kodeBPS,namaProvinsi')->get('provinsi')->result(); - $i=0; - $pTitle = ""; - foreach ($hasil as $row) - { - $clr = (($i%2) == 0) ? '#fff' : '#EFF1F1'; - $pTitle .= ""; - $i++; - } - echo $pTitle; + } + function isi_propinsi() + { + $hasil = $this->db->select('kodeBPS,namaProvinsi')->get('provinsi')->result(); + $i=0; + $pTitle = ""; + foreach ($hasil as $row) + { + $clr = (($i%2) == 0) ? '#fff' : '#EFF1F1'; + $pTitle .= ""; + $i++; + } + echo $pTitle; } function cab_code() { @@ -118,25 +118,25 @@ function hapus() { $where = array('tabungan_id' => $this->input->post('id')); echo $this->master->delete("tb_tabungan",$where); - } - function get_tabungan() - { - $ff = $this->input->post('ff'); // Jenis Filter - $if = $this->input->post('if'); // Value Filter - $fd = $this->input->post('fd'); // Field Sorting - $adsc = $this->input->post('adsc'); // Asc or Desc - $hal = $this->input->post('hal'); // Offset Limit - $juml = $this->input->post('juml'); // Jumlah Limit - $awal = $juml * ($hal - 1); - $alldata = $this->modelku->getAllTabungan($ff,$if,$fd,$adsc,$awal,$juml); - $records = $alldata['numrow']; - $page_num = ceil($records / $juml); - if ($records > 0) + } + function get_tabungan() + { + $ff = $this->input->post('ff'); // Jenis Filter + $if = $this->input->post('if'); // Value Filter + $fd = $this->input->post('fd'); // Field Sorting + $adsc = $this->input->post('adsc'); // Asc or Desc + $hal = $this->input->post('hal'); // Offset Limit + $juml = $this->input->post('juml'); // Jumlah Limit + $awal = $juml * ($hal - 1); + $alldata = $this->modelku->getAllTabungan($ff,$if,$fd,$adsc,$awal,$juml); + $records = $alldata['numrow']; + $page_num = ceil($records / $juml); + if ($records > 0) { - $hasil['total'] = $page_num; - $hasil['alldata'] = $alldata['result']; - echo json_encode($hasil); - } + $hasil['total'] = $page_num; + $hasil['alldata'] = $alldata['result']; + echo json_encode($hasil); + } } function isi_tabungan() { @@ -169,7 +169,7 @@ function login() $resp = $this->authlib->login1($login); echo $resp; } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/application/controllers/index.html b/application/controllers/index.html new file mode 100644 index 0000000..b48b490 --- /dev/null +++ b/application/controllers/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/bmt-system/application/controllers/monitor/aktivasitabungan.php b/application/controllers/monitor/Aktivasitabungan.php similarity index 94% rename from bmt-system/application/controllers/monitor/aktivasitabungan.php rename to application/controllers/monitor/Aktivasitabungan.php index 3a91c20..023af5d 100755 --- a/bmt-system/application/controllers/monitor/aktivasitabungan.php +++ b/application/controllers/monitor/Aktivasitabungan.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Aktivasitabungan extends Controller { +class Aktivasitabungan extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); diff --git a/bmt-system/application/controllers/monitor/cetaktabungan.php b/application/controllers/monitor/Cetaktabungan.php similarity index 97% rename from bmt-system/application/controllers/monitor/cetaktabungan.php rename to application/controllers/monitor/Cetaktabungan.php index 4375686..fdea205 100755 --- a/bmt-system/application/controllers/monitor/cetaktabungan.php +++ b/application/controllers/monitor/Cetaktabungan.php @@ -8,42 +8,42 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Cetaktabungan extends Controller { +class Cetaktabungan extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); - $this->load->model('master_model','master'); + $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "transaksiumum"; - $this->menuactsub = "cetaktabungan"; + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "transaksiumum"; + $this->menuactsub = "cetaktabungan"; } //---- Admin function index() { - $data['idpeg'] = $this->session->userdata('username'); + $data['idpeg'] = $this->session->userdata('username'); $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); - $data['tema'] = $this->tema; + $data['tema'] = $this->tema; $this->load->view('monitor/cetaktabungan',$data); } - - function get_cetaktrans() - { - $tglawal = $this->allfunct->revDate($this->input->post('tglawal')); - $tglakhir = $this->allfunct->revDate($this->input->post('tglakhir')); - $id = $this->input->post('id'); - - $query = $this->db->query("SELECT accounttrans_date,accounttrans_type,accounttrans_value,create_by - FROM tb_accounttrans - WHERE accounttrans_listid !=19 and accounttrans_listid!=349 AND accounttrans_user='$id' AND accounttrans_date BETWEEN '$tglawal' AND '$tglakhir'"); - $data = $query->result_array(); - //echo $data; - $hasil['alldata'] = $data; - echo json_encode($hasil); + + function get_cetaktrans() + { + $tglawal = $this->allfunct->revDate($this->input->post('tglawal')); + $tglakhir = $this->allfunct->revDate($this->input->post('tglakhir')); + $id = $this->input->post('id'); + + $query = $this->db->query("SELECT accounttrans_date,accounttrans_type,accounttrans_value,create_by + FROM tb_accounttrans + WHERE accounttrans_listid !=19 and accounttrans_listid!=349 AND accounttrans_user='$id' AND accounttrans_date BETWEEN '$tglawal' AND '$tglakhir'"); + $data = $query->result_array(); + //echo $data; + $hasil['alldata'] = $data; + echo json_encode($hasil); } function saldonow(){ $tglawal = $this->allfunct->revDate($this->input->post('tglawal')); @@ -52,9 +52,9 @@ function saldonow(){ FROM tb_accounttrans WHERE accounttrans_listid !=19 AND accounttrans_date < '$tglawal' AND accounttrans_user='$id'"); $data = $query->result_array(); echo floor($data[0]["mutasi_kredit"] - $data[0]["mutasi_debet"]) ; - } - function cetak() - { + } + function cetak() + { $query = $this->db->query("SELECT set4,set5,set6,set7,set8,set9,set10,set11,set12 FROM setting"); $data = $query->result_array(); if($query->num_rows() > 0) { @@ -76,7 +76,7 @@ function cetak() $data['wth'] = $wth."%"; $data['sizetop'] = "
    "; $data['margin'] = "margin-left : 0.1cm; margin-top : ".$set10.";"; - $this->load->view('cetak/laporantabungan',$data); + $this->load->view('cetak/laporantabungan',$data); } function cetakkop() { @@ -96,27 +96,27 @@ function get_paramlayout(){ $query = $this->db->query("SELECT set4,set5,set6,set7,set8,set9,set10,set11 FROM setting"); $data = $query->result_array(); echo json_encode($data); - } - function single_pegawai() - { - $data = $this->allfunct->securePost(); - $peg = $data['peg']; - $query = $this->db->query("SELECT nama_pegawai FROM pegawai WHERE nip='".$peg."'"); - $data = $query->result_array(); - if($query->num_rows() > 0) { - $ppeg = $data[0]["nama_pegawai"]; - echo $ppeg; - }else{ - echo ""; - } - } - function login() - { - $data = $this->allfunct->securePost(); - $login = array($data['username'], $data['password']); - $resp = $this->authlib->login1($login); - echo $resp; - } + } + function single_pegawai() + { + $data = $this->allfunct->securePost(); + $peg = $data['peg']; + $query = $this->db->query("SELECT nama_pegawai FROM pegawai WHERE nip='".$peg."'"); + $data = $query->result_array(); + if($query->num_rows() > 0) { + $ppeg = $data[0]["nama_pegawai"]; + echo $ppeg; + }else{ + echo ""; + } + } + function login() + { + $data = $this->allfunct->securePost(); + $login = array($data['username'], $data['password']); + $resp = $this->authlib->login1($login); + echo $resp; + } } diff --git a/bmt-system/application/controllers/monitor/deposito.php b/application/controllers/monitor/Deposito.php similarity index 95% rename from bmt-system/application/controllers/monitor/deposito.php rename to application/controllers/monitor/Deposito.php index aaed8b7..d0e72f1 100644 --- a/bmt-system/application/controllers/monitor/deposito.php +++ b/application/controllers/monitor/Deposito.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Deposito extends Controller { +class Deposito extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -30,34 +30,34 @@ function index() $data['tema'] = $this->tema; $this->load->view('monitor/deposito',$data); } - function get_dataview(){ - $tgl1 = $this->allfunct->revDate($this->input->post('tgl1')); - $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); - $fv = $this->input->post('fv'); - $ifv = $this->input->post('ifv'); - $where = " WHERE accounttrans_listid !='19' "; - if(($tgl1 != "")&&($tgl2 != "")){ - $where .= " AND accounttrans_date BETWEEN '$tgl1' AND '$tgl2'"; - } - if(($fv != "")){ - $where .= " AND `$fv` LIKE '%".$ifv."%'"; - } - $query = $this->db->query("SELECT SUM(accounttrans_value) AS nominal,t1.*,t2.nama,t2.alamat,t2.kabupaten,t5.groupdeposito_nama FROM tb_deposito AS t1 - INNER JOIN tb_nasabah AS t2 ON t2.nomor_nasabah=t1.nomor_nasabah + function get_dataview(){ + $tgl1 = $this->allfunct->revDate($this->input->post('tgl1')); + $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); + $fv = $this->input->post('fv'); + $ifv = $this->input->post('ifv'); + $where = " WHERE accounttrans_listid !='19' "; + if(($tgl1 != "")&&($tgl2 != "")){ + $where .= " AND accounttrans_date BETWEEN '$tgl1' AND '$tgl2'"; + } + if(($fv != "")){ + $where .= " AND `$fv` LIKE '%".$ifv."%'"; + } + $query = $this->db->query("SELECT SUM(accounttrans_value) AS nominal,t1.*,t2.nama,t2.alamat,t2.kabupaten,t5.groupdeposito_nama FROM tb_deposito AS t1 + INNER JOIN tb_nasabah AS t2 ON t2.nomor_nasabah=t1.nomor_nasabah INNER JOIN tb_accounttrans AS t4 ON t4.accounttrans_user=t1.nomor_rekening INNER JOIN master_groupdeposito AS t5 ON t5.kode_produk=t1.nama_produk - ".$where." GROUP BY t1.nomor_rekening"); - $data = $query->result_array(); - $hasil['alldata'] = $data; - echo json_encode($hasil); + ".$where." GROUP BY t1.nomor_rekening"); + $data = $query->result_array(); + $hasil['alldata'] = $data; + echo json_encode($hasil); } - function get_transview(){ - $rek = $this->input->post('id'); - $query = $this->db->query("SELECT * FROM tb_accounttrans WHERE accounttrans_user='$rek' AND accounttrans_listid !='19'"); - $data = $query->result_array(); - //echo $data; - $hasil['alldata'] = $data; - echo json_encode($hasil); + function get_transview(){ + $rek = $this->input->post('id'); + $query = $this->db->query("SELECT * FROM tb_accounttrans WHERE accounttrans_user='$rek' AND accounttrans_listid !='19'"); + $data = $query->result_array(); + //echo $data; + $hasil['alldata'] = $data; + echo json_encode($hasil); } function single_pegawai() diff --git a/bmt-system/application/controllers/monitor/listtabungan.php b/application/controllers/monitor/Listtabungan.php similarity index 95% rename from bmt-system/application/controllers/monitor/listtabungan.php rename to application/controllers/monitor/Listtabungan.php index 77aceca..70831a2 100755 --- a/bmt-system/application/controllers/monitor/listtabungan.php +++ b/application/controllers/monitor/Listtabungan.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Listtabungan extends Controller { +class Listtabungan extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -30,36 +30,36 @@ function index() $data['tema'] = $this->tema; $this->load->view('monitor/listtabungan',$data); } - function get_dataview(){ - $tgl1 = $this->allfunct->revDate($this->input->post('tgl1')); - $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); - $fv = $this->input->post('fv'); - $ifv = $this->input->post('ifv'); - $where = " WHERE accounttrans_listid !='19'"; - if(($tgl1 != "")&&($tgl2 != "")){ - $where .= " AND accounttrans_date BETWEEN '$tgl1' AND '$tgl2'"; - } - if(($fv != "")){ - $where .= " AND `$fv` LIKE '%".$ifv."%'"; - } + function get_dataview(){ + $tgl1 = $this->allfunct->revDate($this->input->post('tgl1')); + $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); + $fv = $this->input->post('fv'); + $ifv = $this->input->post('ifv'); + $where = " WHERE accounttrans_listid !='19'"; + if(($tgl1 != "")&&($tgl2 != "")){ + $where .= " AND accounttrans_date BETWEEN '$tgl1' AND '$tgl2'"; + } + if(($fv != "")){ + $where .= " AND `$fv` LIKE '%".$ifv."%'"; + } $query = $this->db->query("SELECT SUM(CASE WHEN accounttrans_type like '01' THEN accounttrans_value END) AS kredit,SUM(CASE WHEN accounttrans_type like '02' THEN accounttrans_value END) AS debet,t1.*,t2.nama,t2.rtrw,t2.alamat,t2.kabupaten,t3.nama_pegawai,t5.grouptabungan_nama - FROM tb_tabungan AS t1 - INNER JOIN tb_nasabah AS t2 ON t2.nomor_nasabah=t1.nomor_nasabah + FROM tb_tabungan AS t1 + INNER JOIN tb_nasabah AS t2 ON t2.nomor_nasabah=t1.nomor_nasabah INNER JOIN pegawai AS t3 ON t1.nomor_fo=t3.nip INNER JOIN tb_accounttrans AS t4 ON t4.accounttrans_user=t1.nomor_rekening INNER JOIN master_grouptabungan AS t5 ON t5.kode_produk=t1.jenis_simpanan - ".$where." GROUP BY t1.nomor_rekening"); - $data = $query->result_array(); - $hasil['alldata'] = $data; - echo json_encode($hasil); + ".$where." GROUP BY t1.nomor_rekening"); + $data = $query->result_array(); + $hasil['alldata'] = $data; + echo json_encode($hasil); } - function get_transview(){ - $rek = $this->input->post('id'); - $query = $this->db->query("SELECT * FROM tb_accounttrans WHERE accounttrans_user='$rek' AND accounttrans_listid !='19' AND accounttrans_listid !='577' AND accounttrans_listid !='244' AND accounttrans_listid !='416' AND accounttrans_listid !='349' AND accounttrans_listid !='440'"); - $data = $query->result_array(); - //echo $data; - $hasil['alldata'] = $data; - echo json_encode($hasil); + function get_transview(){ + $rek = $this->input->post('id'); + $query = $this->db->query("SELECT * FROM tb_accounttrans WHERE accounttrans_user='$rek' AND accounttrans_listid !='19' AND accounttrans_listid !='577' AND accounttrans_listid !='244' AND accounttrans_listid !='416' AND accounttrans_listid !='349' AND accounttrans_listid !='440'"); + $data = $query->result_array(); + //echo $data; + $hasil['alldata'] = $data; + echo json_encode($hasil); } function single_pegawai() diff --git a/bmt-system/application/controllers/monitor/npf.php b/application/controllers/monitor/Npf.php similarity index 96% rename from bmt-system/application/controllers/monitor/npf.php rename to application/controllers/monitor/Npf.php index 6bf70ff..0bed04d 100644 --- a/bmt-system/application/controllers/monitor/npf.php +++ b/application/controllers/monitor/Npf.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Npf extends Controller { +class Npf extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -30,27 +30,27 @@ function index() $data['tema'] = $this->tema; $this->load->view('monitor/npf',$data); } - function get_dataangsuran(){ + function get_dataangsuran(){ $data = $this->allfunct->securePost(); - $id = $data['id']; - $query = $this->db->query("SELECT pokok,margin FROM tb_pembiayaandetail WHERE id_pembiayaan='$id'"); + $id = $data['id']; + $query = $this->db->query("SELECT pokok,margin FROM tb_pembiayaandetail WHERE id_pembiayaan='$id'"); $data = $query->result_array(); - if($query->num_rows() > 0) { - echo $data[0]["pokok"]."#".$data[0]["margin"]; - }else{ - echo "0#0"; - } + if($query->num_rows() > 0) { + echo $data[0]["pokok"]."#".$data[0]["margin"]; + }else{ + echo "0#0"; + } } - function get_totalangsuran(){ - $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); - $rek = $this->input->post('id'); - $hasil = $this->db->query("SELECT t1.*,sum(accounttrans_value) AS jlh,t1.accounttrans_id FROM tb_accounttrans AS t1 - WHERE accounttrans_user='$rek' AND `accounttrans_desc` LIKE 'ANGSURAN%' AND `accounttrans_listid` !=19 AND - `accounttrans_type`='01' AND `accounttrans_date` <='$tgl2' GROUP BY `accounttrans_code`,accounttrans_listid ORDER BY `accounttrans_value` ASC")->result(); + function get_totalangsuran(){ + $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); + $rek = $this->input->post('id'); + $hasil = $this->db->query("SELECT t1.*,sum(accounttrans_value) AS jlh,t1.accounttrans_id FROM tb_accounttrans AS t1 + WHERE accounttrans_user='$rek' AND `accounttrans_desc` LIKE 'ANGSURAN%' AND `accounttrans_listid` !=19 AND + `accounttrans_type`='01' AND `accounttrans_date` <='$tgl2' GROUP BY `accounttrans_code`,accounttrans_listid ORDER BY `accounttrans_value` ASC")->result(); $pokok = 0; $margin = 0; $i=0; - foreach ($hasil as $row) + foreach ($hasil as $row) { if($i==0){ $margin = $row->jlh; @@ -58,13 +58,13 @@ function get_totalangsuran(){ $pokok = $row->jlh; } $i++; - } - echo $pokok."#".$margin; + } + echo $pokok."#".$margin; } - function get_dataview(){ + function get_dataview(){ //$tgl1 = $this->allfunct->revDate($this->input->post('tgl1')); - $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); + $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); $fv = $this->input->post('fv'); $ifv = $this->input->post('ifv'); @@ -82,7 +82,7 @@ function get_dataview(){ ".$where.""); $data1 = $query->result_array(); $hasil['alldata'] = $data1; - echo json_encode($hasil); + echo json_encode($hasil); } function get_angsuranview(){ @@ -106,27 +106,27 @@ function get_setoranview() $hasil['alldata'] = $data; echo json_encode($hasil); } - function get_outstanding(){ - $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); - $rek = $this->input->post('id'); - $id_pembiayaan = $this->input->post('id1'); - $query = $this->db->query("SELECT sum(pokok + margin) AS jlh FROM tb_pembiayaandetail AS t1 - INNER JOIN tb_pembiayaan AS t2 ON t2.pembiayaan_id=t1.id_pembiayaan - WHERE nomor_rekening='$rek'"); - $data = $query->result_array(); - if($query->num_rows() > 0) { - $jlh = $data[0]["jlh"]; - }else{ - $jlh = 0; - } - $query1 = $this->db->query("SELECT t1.*,sum(accounttrans_value) AS jlh1 FROM tb_accounttrans AS t1 - WHERE accounttrans_user='$rek' AND `accounttrans_desc` LIKE 'ANGSURAN%' AND `accounttrans_listid` !=19 AND - `accounttrans_type`='01' GROUP BY `accounttrans_code` ORDER BY `accounttrans_id`,accounttrans_date"); - $data1 = $query1->result_array(); - $trans = $data1[0]["jlh1"]; - echo $trans; + function get_outstanding(){ + $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); + $rek = $this->input->post('id'); + $id_pembiayaan = $this->input->post('id1'); + $query = $this->db->query("SELECT sum(pokok + margin) AS jlh FROM tb_pembiayaandetail AS t1 + INNER JOIN tb_pembiayaan AS t2 ON t2.pembiayaan_id=t1.id_pembiayaan + WHERE nomor_rekening='$rek'"); + $data = $query->result_array(); + if($query->num_rows() > 0) { + $jlh = $data[0]["jlh"]; + }else{ + $jlh = 0; + } + $query1 = $this->db->query("SELECT t1.*,sum(accounttrans_value) AS jlh1 FROM tb_accounttrans AS t1 + WHERE accounttrans_user='$rek' AND `accounttrans_desc` LIKE 'ANGSURAN%' AND `accounttrans_listid` !=19 AND + `accounttrans_type`='01' GROUP BY `accounttrans_code` ORDER BY `accounttrans_id`,accounttrans_date"); + $data1 = $query1->result_array(); + $trans = $data1[0]["jlh1"]; + echo $trans; } - + function get_coltrans() { //$tgl1 = $this->allfunct->revDate($this->input->post('tgl1')); @@ -170,9 +170,9 @@ function get_paramcol2(){ $data = $query->result_array(); echo json_encode($data); } - function cetak() - { - $this->load->view('cetak/laporan'); + function cetak() + { + $this->load->view('cetak/laporan'); } } diff --git a/bmt-system/application/controllers/monitor/pembiayaan.php b/application/controllers/monitor/Pembiayaan.php similarity index 96% rename from bmt-system/application/controllers/monitor/pembiayaan.php rename to application/controllers/monitor/Pembiayaan.php index 45708a3..c6ee1bc 100755 --- a/bmt-system/application/controllers/monitor/pembiayaan.php +++ b/application/controllers/monitor/Pembiayaan.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Pembiayaan extends Controller { +class Pembiayaan extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -30,43 +30,43 @@ function index() $data['tema'] = $this->tema; $this->load->view('monitor/pembiayaan',$data); } - function get_dataangsuran(){ + function get_dataangsuran(){ $data = $this->allfunct->securePost(); - $id = $data['id']; - $query = $this->db->query("SELECT pokok,margin FROM tb_pembiayaandetail WHERE id_pembiayaan='$id'"); + $id = $data['id']; + $query = $this->db->query("SELECT pokok,margin FROM tb_pembiayaandetail WHERE id_pembiayaan='$id'"); $data = $query->result_array(); - if($query->num_rows() > 0) { - echo $data[0]["pokok"]."#".$data[0]["margin"]; - }else{ - echo "0#0"; - } - } - function get_transview() - { - $objord = $this->input->post('id'); - $query = $this->db->query("SELECT accounttrans_code,accounttrans_date,accounttrans_value FROM tb_accounttrans WHERE accounttrans_user='".$objord."' AND accounttrans_type='02' AND accounttrans_ref=1 order by accounttrans_date"); - $data = $query->result_array(); - //echo $data; - $hasil['alldata'] = $data; - echo json_encode($hasil); - } - function get_outstanding(){ - $data = $this->allfunct->securePost(); - $id = $data['id']; - $query = $this->db->query("SELECT sum(pokok + margin) AS jlh FROM tb_pembiayaandetail AS t1 - INNER JOIN tb_pembiayaan AS t2 ON t2.pembiayaan_id=t1.id_pembiayaan - WHERE nomor_rekening='$id'"); - $data = $query->result_array(); - if($query->num_rows() > 0) { - echo $data[0]["jlh"]; - }else{ - echo "0"; - } + if($query->num_rows() > 0) { + echo $data[0]["pokok"]."#".$data[0]["margin"]; + }else{ + echo "0#0"; + } + } + function get_transview() + { + $objord = $this->input->post('id'); + $query = $this->db->query("SELECT accounttrans_code,accounttrans_date,accounttrans_value FROM tb_accounttrans WHERE accounttrans_user='".$objord."' AND accounttrans_type='02' AND accounttrans_ref=1 order by accounttrans_date"); + $data = $query->result_array(); + //echo $data; + $hasil['alldata'] = $data; + echo json_encode($hasil); + } + function get_outstanding(){ + $data = $this->allfunct->securePost(); + $id = $data['id']; + $query = $this->db->query("SELECT sum(pokok + margin) AS jlh FROM tb_pembiayaandetail AS t1 + INNER JOIN tb_pembiayaan AS t2 ON t2.pembiayaan_id=t1.id_pembiayaan + WHERE nomor_rekening='$id'"); + $data = $query->result_array(); + if($query->num_rows() > 0) { + echo $data[0]["jlh"]; + }else{ + echo "0"; + } } - function get_dataview(){ + function get_dataview(){ $tgl1 = $this->allfunct->revDate($this->input->post('tgl1')); - $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); + $tgl2 = $this->allfunct->revDate($this->input->post('tgl2')); $fv = $this->input->post('fv'); $ifv = $this->input->post('ifv'); $where = " WHERE t1.status=0 "; @@ -82,7 +82,7 @@ function get_dataview(){ ".$where.""); $data = $query->result_array(); $hasil['alldata'] = $data; - echo json_encode($hasil); + echo json_encode($hasil); } function get_angsuranview(){ @@ -108,9 +108,9 @@ function get_setoranview() } - function cetak() - { - $this->load->view('cetak/laporan'); + function cetak() + { + $this->load->view('cetak/laporan'); } function single_pegawai() { diff --git a/bmt-system/application/controllers/param/bmt.php b/application/controllers/param/Bmt.php similarity index 98% rename from bmt-system/application/controllers/param/bmt.php rename to application/controllers/param/Bmt.php index 0422518..b709cd3 100755 --- a/bmt-system/application/controllers/param/bmt.php +++ b/application/controllers/param/Bmt.php @@ -8,41 +8,41 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Bmt extends Controller { +class Bmt extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); // $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); - $this->load->model('master_model','master'); + $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "param"; - $this->menuactsub = "bmt"; + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "param"; + $this->menuactsub = "bmt"; } //---- Pameter BMT function index() { - $data['idpeg'] = $this->session->userdata('username'); + $data['idpeg'] = $this->session->userdata('username'); $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); - $data['tema'] = $this->tema; + $data['tema'] = $this->tema; $this->load->view('param/bmt',$data); } /* * --------------------- BMT ----------------------------------------- - */ - //---- Edit BMT Info - function editBMTInfo() - { - $data = $this->allfunct->securePost(); - $id = 1; - //unset($data['bmt_id']); - $where = array('bmt_id' => $id); - echo $this->master->update("bmt",$data,$where); - } + */ + //---- Edit BMT Info + function editBMTInfo() + { + $data = $this->allfunct->securePost(); + $id = 1; + //unset($data['bmt_id']); + $where = array('bmt_id' => $id); + echo $this->master->update("bmt",$data,$where); + } //---- Simpan BMT function saveBMT() @@ -85,16 +85,16 @@ function get_bmt() $hasil['alldata'] = $alldata['result']; echo json_encode($hasil); } - } - - function get_bmtinfo() - { - $objord = $this->input->post('id'); - $where = ""; - $query = $this->db->query("SELECT t1.*,namaProvinsi FROM bmt AS t1 INNER JOIN provinsi AS t2 ON t2.kodeBPS=t1.propinsi"); - $data = $query->result_array(); - $hasil['alldata'] = $data; - echo json_encode($hasil); + } + + function get_bmtinfo() + { + $objord = $this->input->post('id'); + $where = ""; + $query = $this->db->query("SELECT t1.*,namaProvinsi FROM bmt AS t1 INNER JOIN provinsi AS t2 ON t2.kodeBPS=t1.propinsi"); + $data = $query->result_array(); + $hasil['alldata'] = $data; + echo json_encode($hasil); } function get_info() { @@ -102,30 +102,30 @@ function get_info() $query = $this->db->query("SELECT t1.*,namaProvinsi FROM bmt AS t1 INNER JOIN provinsi AS t2 ON t2.kodeBPS=t1.propinsi WHERE kode_cabang='$id'"); $data = $query->result_array(); echo $data[0]["nama"]; - } - //---- propinsi - function isi_provinsi() - { - $hasil = $this->db->select('kodeBPS,namaProvinsi')->get('provinsi')->result(); - $i=0; - foreach ($hasil as $row) - { - $clr = (($i%2) == 0) ? '#fff' : '#EFF1F1'; - echo ""; - $i++; - } } - //---- group kerja - function isi_wilayah() - { - $hasil = $this->db->select('kode,wilayah_kerja')->get('bmt_wilayah')->result(); - $i=0; - foreach ($hasil as $row) - { - $clr = (($i%2) == 0) ? '#fff' : '#EFF1F1'; - echo ""; - $i++; - } + //---- propinsi + function isi_provinsi() + { + $hasil = $this->db->select('kodeBPS,namaProvinsi')->get('provinsi')->result(); + $i=0; + foreach ($hasil as $row) + { + $clr = (($i%2) == 0) ? '#fff' : '#EFF1F1'; + echo ""; + $i++; + } + } + //---- group kerja + function isi_wilayah() + { + $hasil = $this->db->select('kode,wilayah_kerja')->get('bmt_wilayah')->result(); + $i=0; + foreach ($hasil as $row) + { + $clr = (($i%2) == 0) ? '#fff' : '#EFF1F1'; + echo ""; + $i++; + } } ///tahun buku //---- Simpan tahun buku diff --git a/bmt-system/application/controllers/param/deposito.php b/application/controllers/param/Deposito.php similarity index 95% rename from bmt-system/application/controllers/param/deposito.php rename to application/controllers/param/Deposito.php index 1df7766..2fb6ba1 100755 --- a/bmt-system/application/controllers/param/deposito.php +++ b/application/controllers/param/Deposito.php @@ -1,34 +1,34 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "param"; $this->menuactsub = "deposito"; - } - - //---- Pameter deposito - function index() - { + } + + //---- Pameter deposito + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('param/deposito',$data); + $this->load->view('param/deposito',$data); } //---- Fungsi level otorisasi @@ -96,7 +96,7 @@ function editdeposito() unset($data['kode_produk']); $where = array('kode_produk' => $id); echo $this->master->update("master_deposito",$data,$where); - } -} - + } +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/param/distribusiprofit.php b/application/controllers/param/Distribusiprofit.php similarity index 95% rename from bmt-system/application/controllers/param/distribusiprofit.php rename to application/controllers/param/Distribusiprofit.php index be9942a..961db35 100755 --- a/bmt-system/application/controllers/param/distribusiprofit.php +++ b/application/controllers/param/Distribusiprofit.php @@ -1,34 +1,34 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "param"; $this->menuactsub = "distribusiprofit"; - } - - //---- Pameter Nasabah - function index() - { + } + + //---- Pameter Nasabah + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('param/distribusiprofit',$data); + $this->load->view('param/distribusiprofit',$data); } /* @@ -112,7 +112,7 @@ function get_pendapatan() $hasil['alldata'] = $alldata['result']; echo json_encode($hasil); } - } -} - + } +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/param/kolektibilitas.php b/application/controllers/param/Kolektibilitas.php similarity index 98% rename from bmt-system/application/controllers/param/kolektibilitas.php rename to application/controllers/param/Kolektibilitas.php index 7b4fe87..7071790 100755 --- a/bmt-system/application/controllers/param/kolektibilitas.php +++ b/application/controllers/param/Kolektibilitas.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Kolektibilitas extends Controller { +class Kolektibilitas extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); diff --git a/bmt-system/application/controllers/param/listakun.php b/application/controllers/param/Listakun.php similarity index 96% rename from bmt-system/application/controllers/param/listakun.php rename to application/controllers/param/Listakun.php index e8f287d..4ff1d64 100755 --- a/bmt-system/application/controllers/param/listakun.php +++ b/application/controllers/param/Listakun.php @@ -1,34 +1,34 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "param"; $this->menuactsub = "listakun"; - } - - //---- Admin jabatan - function index() - { + } + + //---- Admin jabatan + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('param/listakun',$data); + $this->load->view('param/listakun',$data); } function get_akun() @@ -101,11 +101,11 @@ function editTahunbuku() } function saveakun() { - $data = $this->allfunct->securePost(); - $query = $this->db->query("SELECT listakun_pattern FROM coa_listakun WHERE listakun_id ='".$data['listakun_parent']."'"); - $data1 = $query->result_array(); - $data['listakun_pattern'] = $data1[0]["listakun_pattern"]."*".$data['listakun_parent']; - $data['listakun_active'] = "1"; + $data = $this->allfunct->securePost(); + $query = $this->db->query("SELECT listakun_pattern FROM coa_listakun WHERE listakun_id ='".$data['listakun_parent']."'"); + $data1 = $query->result_array(); + $data['listakun_pattern'] = $data1[0]["listakun_pattern"]."*".$data['listakun_parent']; + $data['listakun_active'] = "1"; $data['listakun_sign'] = "-1"; echo $this->master->simpan('coa_listakun',$data); } @@ -142,7 +142,7 @@ function isi_akun() echo ""; $i++; } - } + } //--- Fungsi di Tree View function getTreeCOA() { @@ -177,8 +177,8 @@ function getTreeCOA() $isi .= ""; } echo $isi.""; - } - -} - + } + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/param/nasabah.php b/application/controllers/param/Nasabah.php similarity index 95% rename from bmt-system/application/controllers/param/nasabah.php rename to application/controllers/param/Nasabah.php index 34b3028..6462273 100755 --- a/bmt-system/application/controllers/param/nasabah.php +++ b/application/controllers/param/Nasabah.php @@ -1,35 +1,35 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "param"; $this->menuactsub = "nasabah"; - } - - //---- Pameter Nasabah - function index() - { + } + + //---- Pameter Nasabah + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('param/nasabah',$data); - } + $this->load->view('param/nasabah',$data); + } /* * --------------------- pendapatan ----------------------------------------- @@ -122,53 +122,53 @@ function get_status() echo json_encode($hasil); } } - -/* - * --------------------- Pekerjaan ----------------------------------------- - */ - //---- Simpan pekerjaan - function savepekerjaan() - { - echo $this->master->simpan('sektor_pekerjaan',$this->allfunct->securePost()); - } - - //---- Edit pekerjaan - function editpekerjaan() - { - $data = $this->allfunct->securePost(); - $id = $data['id']; - unset($data['id']); - $where = array('pekerjaan_id' => $id); - echo $this->master->update("sektor_pekerjaan",$data,$where); - } - - //---- Hapus pekerjaan - function delpekerjaan() - { - $where = array('pekerjaan_id' => $this->input->post('id')); - echo $this->master->delete("sektor_pekerjaan",$where); - } - - function get_pekerjaan() - { - $ff = $this->input->post('ff'); // Jenis Filter - $if = $this->input->post('if'); // Value Filter - $fd = $this->input->post('fd'); // Field Sorting - $adsc = $this->input->post('adsc'); // Asc or Desc - $hal = $this->input->post('hal'); // Offset Limit - $juml = $this->input->post('juml'); // Jumlah Limit - $awal = $juml * ($hal - 1); - $alldata = $this->modelku->getAllSektorPekerjaan($ff,$if,$fd,$adsc,$awal,$juml); - $records = $alldata['numrow']; - $page_num = ceil($records / $juml); - if ($records > 0) - { - $hasil['total'] = $page_num; - $hasil['alldata'] = $alldata['result']; - echo json_encode($hasil); - } + +/* + * --------------------- Pekerjaan ----------------------------------------- + */ + //---- Simpan pekerjaan + function savepekerjaan() + { + echo $this->master->simpan('sektor_pekerjaan',$this->allfunct->securePost()); } - -} - + + //---- Edit pekerjaan + function editpekerjaan() + { + $data = $this->allfunct->securePost(); + $id = $data['id']; + unset($data['id']); + $where = array('pekerjaan_id' => $id); + echo $this->master->update("sektor_pekerjaan",$data,$where); + } + + //---- Hapus pekerjaan + function delpekerjaan() + { + $where = array('pekerjaan_id' => $this->input->post('id')); + echo $this->master->delete("sektor_pekerjaan",$where); + } + + function get_pekerjaan() + { + $ff = $this->input->post('ff'); // Jenis Filter + $if = $this->input->post('if'); // Value Filter + $fd = $this->input->post('fd'); // Field Sorting + $adsc = $this->input->post('adsc'); // Asc or Desc + $hal = $this->input->post('hal'); // Offset Limit + $juml = $this->input->post('juml'); // Jumlah Limit + $awal = $juml * ($hal - 1); + $alldata = $this->modelku->getAllSektorPekerjaan($ff,$if,$fd,$adsc,$awal,$juml); + $records = $alldata['numrow']; + $page_num = ceil($records / $juml); + if ($records > 0) + { + $hasil['total'] = $page_num; + $hasil['alldata'] = $alldata['result']; + echo json_encode($hasil); + } + } + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/param/pegawai.php b/application/controllers/param/Pegawai.php similarity index 99% rename from bmt-system/application/controllers/param/pegawai.php rename to application/controllers/param/Pegawai.php index 2171c3d..f29e627 100755 --- a/bmt-system/application/controllers/param/pegawai.php +++ b/application/controllers/param/Pegawai.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Pegawai extends Controller { +class Pegawai extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); //$this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); diff --git a/bmt-system/application/controllers/param/pembiayaan.php b/application/controllers/param/Pembiayaan.php similarity index 95% rename from bmt-system/application/controllers/param/pembiayaan.php rename to application/controllers/param/Pembiayaan.php index 0691bea..9321e14 100755 --- a/bmt-system/application/controllers/param/pembiayaan.php +++ b/application/controllers/param/Pembiayaan.php @@ -1,34 +1,34 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "param"; $this->menuactsub = "pembiayaan"; - } - - //---- Pameter Pembiayaan - function index() - { + } + + //---- Pameter Pembiayaan + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('param/pembiayaan',$data); + $this->load->view('param/pembiayaan',$data); } //---- Fungsi level otorisasi @@ -89,14 +89,14 @@ function get_pembiayaaninfo() //---- Edit pembiayaan info function editPembiayaan() { - $data = $this->allfunct->securePost(); - $data1 = $data['kode_produk']; + $data = $this->allfunct->securePost(); + $data1 = $data['kode_produk']; $data['biaya_administrasi'] = $data['biaya_administrasi']; $id = $data['kode_produk']; unset($data['kode_produk']); $where = array('kode_produk' => $id); echo $this->master->update("master_pembiayaan",$data,$where); - } -} - + } +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/param/setupmenu.php b/application/controllers/param/Setupmenu.php similarity index 98% rename from bmt-system/application/controllers/param/setupmenu.php rename to application/controllers/param/Setupmenu.php index 1e89620..39cd918 100755 --- a/bmt-system/application/controllers/param/setupmenu.php +++ b/application/controllers/param/Setupmenu.php @@ -8,26 +8,26 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Setupmenu extends Controller { +class Setupmenu extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); - $this->load->model('master_model','master'); + $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "param"; - $this->menuactsub = "setupmenu"; + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "param"; + $this->menuactsub = "setupmenu"; } //---- Admin Tema function index() { - $data['idpeg'] = $this->session->userdata('username'); + $data['idpeg'] = $this->session->userdata('username'); $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); - $data['tema'] = $this->tema; + $data['tema'] = $this->tema; $this->load->view('param/setupmenu',$data); } @@ -88,41 +88,41 @@ function getMenu() echo $item; } } - function getMenuapp() - { - $data = $this->allfunct->securePost(); - $menuact = $data['menuact']; - $menuactsub = $data['menuactsub']; - $hasil = $this->db->query("SELECT `menu_id`,`nama`,`href`,`icon`,`css`,`sub`,`urutan`,`parent`,`groups` - FROM `menuapp` - WHERE parent='0' AND `active` = '1' - ORDER BY `urutan`")->result(); - $items = ""; - foreach ($hasil as $row) - { - if ($menuact == $row->css){$status ='active';} - else{$status ='';} - if($row->menu_id == "1"){ - $items .= "
  • ".$row->icon." ".$row->nama."
  • "; - }else{ - $items .= "
  • - ".$row->icon." ".$row->nama.""; - $submenu = $this->db->query("SELECT `menu_id`,`nama`,`href`,`icon`,`css`,`parent`,`groups` - FROM `menuapp` - WHERE parent='".$row->menu_id."' AND `active` = '1' - ORDER BY `urutan`")->result(); - $itemsc = ""; - $items .= $itemsc; - $items .= "
  • "; - } - } - echo $items; + function getMenuapp() + { + $data = $this->allfunct->securePost(); + $menuact = $data['menuact']; + $menuactsub = $data['menuactsub']; + $hasil = $this->db->query("SELECT `menu_id`,`nama`,`href`,`icon`,`css`,`sub`,`urutan`,`parent`,`groups` + FROM `menuapp` + WHERE parent='0' AND `active` = '1' + ORDER BY `urutan`")->result(); + $items = ""; + foreach ($hasil as $row) + { + if ($menuact == $row->css){$status ='active';} + else{$status ='';} + if($row->menu_id == "1"){ + $items .= "
  • ".$row->icon." ".$row->nama."
  • "; + }else{ + $items .= "
  • + ".$row->icon." ".$row->nama.""; + $submenu = $this->db->query("SELECT `menu_id`,`nama`,`href`,`icon`,`css`,`parent`,`groups` + FROM `menuapp` + WHERE parent='".$row->menu_id."' AND `active` = '1' + ORDER BY `urutan`")->result(); + $itemsc = ""; + $items .= $itemsc; + $items .= "
  • "; + } + } + echo $items; } //---- Mengambil Menu sesuai ID function getMenuById() diff --git a/bmt-system/application/controllers/param/tabungan.php b/application/controllers/param/Tabungan.php similarity index 96% rename from bmt-system/application/controllers/param/tabungan.php rename to application/controllers/param/Tabungan.php index 7cfc49c..558633d 100755 --- a/bmt-system/application/controllers/param/tabungan.php +++ b/application/controllers/param/Tabungan.php @@ -1,46 +1,46 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "param"; $this->menuactsub = "tabungan"; - } - - //---- Pameter Nasabah - function index() - { + } + + //---- Pameter Nasabah + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('param/tabungan',$data); - } + $this->load->view('param/tabungan',$data); + } //---- Edit Tabungan info function editMTabungan() { - $data = $this->allfunct->securePost(); - $data1['kode_produk'] = $data['kode_produk']; + $data = $this->allfunct->securePost(); + $data1['kode_produk'] = $data['kode_produk']; $this->master->simpan("master_tabungan",$data1); $id = $data['kode_produk']; unset($data['kode_produk']); $where = array('kode_produk' => $id); - echo $this->master->update("master_tabungan",$data,$where); + echo $this->master->update("master_tabungan",$data,$where); } function get_tabunganinfo() @@ -103,54 +103,54 @@ function get_biaya() echo json_encode($hasil); } } - -/* - * --------------------- Kode Mutasi ----------------------------------------- - */ - //---- Simpan mutasi - function savemutasi() - { - $this->master->simpan('master_kodemutasi',$this->allfunct->securePost()); - $resp = $this->allfunct->securePost(); - $data1['kode_produk'] = $resp['kode_produk']; - echo $this->master->simpan('master_tabungan',$data1); - } - - //---- Edit mutasi - function editmutasi() - { - $data = $this->allfunct->securePost(); - $id = $data['id']; - unset($data['id']); - $where = array('mutasi_id' => $id); - echo $this->master->update("master_kodemutasi",$data,$where); - } - - //---- Hapus mutasi - function delmutasi() - { - $where = array('mutasi_id' => $this->input->post('id')); - echo $this->master->delete("master_kodemutasi",$where); - } - - function get_mutasi() - { - $ff = $this->input->post('ff'); // Jenis Filter - $if = $this->input->post('if'); // Value Filter - $fd = $this->input->post('fd'); // Field Sorting - $adsc = $this->input->post('adsc'); // Asc or Desc - $hal = $this->input->post('hal'); // Offset Limit - $juml = $this->input->post('juml'); // Jumlah Limit - $awal = $juml * ($hal - 1); - $alldata = $this->modelku->getAllKodeMutasi($ff,$if,$fd,$adsc,$awal,$juml); - $records = $alldata['numrow']; - $page_num = ceil($records / $juml); - if ($records > 0) - { - $hasil['total'] = $page_num; - $hasil['alldata'] = $alldata['result']; - echo json_encode($hasil); - } + +/* + * --------------------- Kode Mutasi ----------------------------------------- + */ + //---- Simpan mutasi + function savemutasi() + { + $this->master->simpan('master_kodemutasi',$this->allfunct->securePost()); + $resp = $this->allfunct->securePost(); + $data1['kode_produk'] = $resp['kode_produk']; + echo $this->master->simpan('master_tabungan',$data1); + } + + //---- Edit mutasi + function editmutasi() + { + $data = $this->allfunct->securePost(); + $id = $data['id']; + unset($data['id']); + $where = array('mutasi_id' => $id); + echo $this->master->update("master_kodemutasi",$data,$where); + } + + //---- Hapus mutasi + function delmutasi() + { + $where = array('mutasi_id' => $this->input->post('id')); + echo $this->master->delete("master_kodemutasi",$where); + } + + function get_mutasi() + { + $ff = $this->input->post('ff'); // Jenis Filter + $if = $this->input->post('if'); // Value Filter + $fd = $this->input->post('fd'); // Field Sorting + $adsc = $this->input->post('adsc'); // Asc or Desc + $hal = $this->input->post('hal'); // Offset Limit + $juml = $this->input->post('juml'); // Jumlah Limit + $awal = $juml * ($hal - 1); + $alldata = $this->modelku->getAllKodeMutasi($ff,$if,$fd,$adsc,$awal,$juml); + $records = $alldata['numrow']; + $page_num = ceil($records / $juml); + if ($records > 0) + { + $hasil['total'] = $page_num; + $hasil['alldata'] = $alldata['result']; + echo json_encode($hasil); + } } //---- Fungsi level otorisasi function isi_level() @@ -168,7 +168,7 @@ function isi_level() //---- Simpan produk function saveproduk() { - echo $this->master->simpan('master_grouptabungan',$this->allfunct->securePost()); + echo $this->master->simpan('master_grouptabungan',$this->allfunct->securePost()); } @@ -199,7 +199,7 @@ function get_produk() $hasil['alldata'] = $alldata['result']; echo json_encode($hasil); } - } -} - + } +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/param/umum.php b/application/controllers/param/Umum.php similarity index 97% rename from bmt-system/application/controllers/param/umum.php rename to application/controllers/param/Umum.php index 6d087ab..13e71ae 100755 --- a/bmt-system/application/controllers/param/umum.php +++ b/application/controllers/param/Umum.php @@ -8,25 +8,25 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Umum extends Controller { +class Umum extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "param"; - $this->menuactsub = "umum"; + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "param"; + $this->menuactsub = "umum"; } //---- Admin jabatan function index() { - $data['idpeg'] = $this->session->userdata('username'); + $data['idpeg'] = $this->session->userdata('username'); $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); - $data['tema'] = $this->tema; + $data['tema'] = $this->tema; $this->load->view('param/umum',$data); } diff --git a/bmt-system/application/controllers/param/user.php b/application/controllers/param/User.php similarity index 92% rename from bmt-system/application/controllers/param/user.php rename to application/controllers/param/User.php index 878996a..ba3fdd3 100755 --- a/bmt-system/application/controllers/param/user.php +++ b/application/controllers/param/User.php @@ -8,120 +8,121 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class User extends Controller { - +class User extends CI_Controller { + private $rootControllerPath = APPPATH.'/controllers/'; function __construct() { - parent::Controller(); + parent::__construct(); //$this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); - $this->load->model('master_model','master'); + $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->load->library('encrypt'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "param"; - $this->menuactsub = "user"; + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "param"; + $this->menuactsub = "user"; } //---- Halaman Setup User function index() { - $data['idpeg'] = $this->session->userdata('username'); + $data['idpeg'] = $this->session->userdata('username'); $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; $data['layanancontr'] = array('' => 'Welcome','setortunai' => 'Setor Tunai','tariktunai' => 'Tarik Tunai','setordeposito' => 'Setor Deposito','pencairandeposito' => 'Pencairan Deposito','pencairanpembiayaan' => 'Pencairan Pembiayaan','angsuran' => 'Setor angsuran','lapmutasi' => 'Laporan mutasi','hapustransaksi' => 'Hapus Transaksi','help' => 'Help','profile' => 'Profile'); - $data['paramcontr'] = $this->_scanControllerParam(); - $data['basecontr'] = $this->_scanControllerBase(); - $data['accountingcontr'] = $this->_scanControllerAccounting(); - $data['transaksicontr'] = $this->_scanControllerTransaksi(); + $data['paramcontr'] = $this->_scanControllerParam(); + $data['basecontr'] = $this->_scanControllerBase(); + $data['accountingcontr'] = $this->_scanControllerAccounting(); + $data['transaksicontr'] = $this->_scanControllerTransaksi(); $data['monitorcontr'] = $this->_scanControllerMonitor(); - $data['setting'] = $this->_scanControllerSetting(); - $data['toolcontr'] = $this->_scanControllerTool(); + $data['setting'] = $this->_scanControllerSetting(); + $data['toolcontr'] = $this->_scanControllerTool(); $this->load->view('param/user',$data); - } - function _loadMenuset($parent) - { - $hasil = $this->master->getSetupMenu($parent); - if ($hasil) - { - $this->isi[] = ""; - } else { - $this->isi[] = ""; - } - } - //---- Mengambil Menu sesuai ID - function getMenuById() - { - $hasil = $this->db->get_where('menuapp', array('menu_id' => $this->input->post('id')))->row_array(); - $hasil['groups'] = unserialize($hasil['groups']); - echo json_encode($hasil); - } - function getMenu() - { - $this-> _loadMenuset('0'); - foreach($this->isi as $item) - { - echo $item; - } + } + function _loadMenuset($parent) + { + $hasil = $this->master->getSetupMenu($parent); + if ($hasil) + { + $this->isi[] = ""; + } else { + $this->isi[] = ""; + } + } + //---- Mengambil Menu sesuai ID + function getMenuById() + { + $hasil = $this->db->get_where('menuapp', array('menu_id' => $this->input->post('id')))->row_array(); + $hasil['groups'] = unserialize($hasil['groups']); + echo json_encode($hasil); + } + function getMenu() + { + $this-> _loadMenuset('0'); + foreach($this->isi as $item) + { + echo $item; + } } - - /* - * --------------------- otoritas ----------------------------------------- - */ - //---- Simpan otoritas - function saveotoritas() - { - echo $this->master->simpan('master_otoritas',$this->allfunct->securePost()); - } - - //---- Edit otoritas - function editotoritas() - { - $data = $this->allfunct->securePost(); - $id = $data['id']; - unset($data['id']); - $where = array('otoritas_id' => $id); - echo $this->master->update("master_otoritas",$data,$where); - } - - //---- Hapus otoritas - function delotoritas() - { - $where = array('otoritas_id' => $this->input->post('id')); - echo $this->master->delete("master_otoritas",$where); - } - - function get_otoritas() - { - $ff = $this->input->post('ff'); - $if = $this->input->post('if'); - $fd = $this->input->post('fd'); - $adsc = $this->input->post('adsc'); - $hal = $this->input->post('hal'); - $juml = $this->input->post('juml'); - $awal = $juml * ($hal - 1); - $alldata = $this->modelku->getAllOtoritas($ff,$if,$fd,$adsc,$awal,$juml); - $records = $alldata['numrow']; - $page_num = ceil($records / $juml); - if ($records > 0) - { - $hasil['total'] = $page_num; - $hasil['alldata'] = $alldata['result']; - echo json_encode($hasil); - } + + /* + * --------------------- otoritas ----------------------------------------- + */ + //---- Simpan otoritas + function saveotoritas() + { + echo $this->master->simpan('master_otoritas',$this->allfunct->securePost()); + } + + //---- Edit otoritas + function editotoritas() + { + $data = $this->allfunct->securePost(); + $id = $data['id']; + unset($data['id']); + $where = array('otoritas_id' => $id); + echo $this->master->update("master_otoritas",$data,$where); + } + + //---- Hapus otoritas + function delotoritas() + { + $where = array('otoritas_id' => $this->input->post('id')); + echo $this->master->delete("master_otoritas",$where); + } + + function get_otoritas() + { + $ff = $this->input->post('ff'); + $if = $this->input->post('if'); + $fd = $this->input->post('fd'); + $adsc = $this->input->post('adsc'); + $hal = $this->input->post('hal'); + $juml = $this->input->post('juml'); + $awal = $juml * ($hal - 1); + $alldata = $this->modelku->getAllOtoritas($ff,$if,$fd,$adsc,$awal,$juml); + $records = $alldata['numrow']; + $page_num = ceil($records / $juml); + if ($records > 0) + { + $hasil['total'] = $page_num; + $hasil['alldata'] = $alldata['result']; + echo json_encode($hasil); + } } // ---- Fungsi mendapatkan nama controller di param function _scanControllerParam() { - $root = ('./bmt-system/application/controllers/param/'); + //$root = (APPPATH.'/controllers/param/'); + $root = $this->rootControllerPath.'param/'; $hasil = scandir($root); foreach($hasil as $val) { @@ -133,85 +134,91 @@ function _scanControllerParam() } return $contr; } - // ---- Fungsi mendapatkan nama controller di base - function _scanControllerBase() - { - $root = ('./bmt-system/application/controllers/base/'); - $hasil = scandir($root); - foreach($hasil as $val) - { - if((is_file($root.$val) == TRUE) AND (!preg_match('/^\.|html$/',$val))) - { - $ky = preg_replace('/.php$/', '', $val); - $contr['base/'.$ky] = ucfirst($ky); - } - } - return $contr; - } - // ---- Fungsi mendapatkan nama controller di akunting - function _scanControllerAccounting() - { - $root = ('./bmt-system/application/controllers/akunting/'); - $hasil = scandir($root); - foreach($hasil as $val) - { - if((is_file($root.$val) == TRUE) AND (!preg_match('/^\.|html$/',$val))) - { - $ky = preg_replace('/.php$/', '', $val); - $contr['akunting/'.$ky] = ucfirst($ky); - } - } - return $contr; - } - // ---- Fungsi mendapatkan nama controller di trans - function _scanControllerTransaksi() - { - $root = ('./bmt-system/application/controllers/trans/'); - $hasil = scandir($root); - foreach($hasil as $val) - { - if((is_file($root.$val) == TRUE) AND (!preg_match('/^\.|html$/',$val))) - { - $ky = preg_replace('/.php$/', '', $val); - $contr['trans/'.$ky] = ucfirst($ky); - } - } - return $contr; - } - // ---- Fungsi mendapatkan nama controller di Monitor - function _scanControllerMonitor() - { - $root = ('./bmt-system/application/controllers/monitor/'); - $hasil = scandir($root); - foreach($hasil as $val) - { - if((is_file($root.$val) == TRUE) AND (!preg_match('/^\.|html$/',$val))) - { - $ky = preg_replace('/.php$/', '', $val); - $contr['monitor/'.$ky] = ucfirst($ky); - } - } - return $contr; - } - // ---- Fungsi mendapatkan nama controller di Tool - function _scanControllerTool() - { - $root = ('./bmt-system/application/controllers/tool/'); - $hasil = scandir($root); - foreach($hasil as $val) - { - if((is_file($root.$val) == TRUE) AND (!preg_match('/^\.|html$/',$val))) - { - $ky = preg_replace('/.php$/', '', $val); - $contr['tool/'.$ky] = ucfirst($ky); - } - } - return $contr; - } + // ---- Fungsi mendapatkan nama controller di base + function _scanControllerBase() + { + //$root = ('./bmt-system/application/controllers/base/'); + $root = $this->rootControllerPath.'base/'; + $hasil = scandir($root); + foreach($hasil as $val) + { + if((is_file($root.$val) == TRUE) AND (!preg_match('/^\.|html$/',$val))) + { + $ky = preg_replace('/.php$/', '', $val); + $contr['base/'.$ky] = ucfirst($ky); + } + } + return $contr; + } + // ---- Fungsi mendapatkan nama controller di akunting + function _scanControllerAccounting() + { + //$root = ('./bmt-system/application/controllers/akunting/'); + $root = $this->rootControllerPath.'akunting/'; + $hasil = scandir($root); + foreach($hasil as $val) + { + if((is_file($root.$val) == TRUE) AND (!preg_match('/^\.|html$/',$val))) + { + $ky = preg_replace('/.php$/', '', $val); + $contr['akunting/'.$ky] = ucfirst($ky); + } + } + return $contr; + } + // ---- Fungsi mendapatkan nama controller di trans + function _scanControllerTransaksi() + { + //$root = ('./bmt-system/application/controllers/trans/'); + $root = $this->rootControllerPath.'trans/'; + $hasil = scandir($root); + foreach($hasil as $val) + { + if((is_file($root.$val) == TRUE) AND (!preg_match('/^\.|html$/',$val))) + { + $ky = preg_replace('/.php$/', '', $val); + $contr['trans/'.$ky] = ucfirst($ky); + } + } + return $contr; + } + // ---- Fungsi mendapatkan nama controller di Monitor + function _scanControllerMonitor() + { + //$root = ('./bmt-system/application/controllers/monitor/'); + $root = $this->rootControllerPath.'monitor/'; + $hasil = scandir($root); + foreach($hasil as $val) + { + if((is_file($root.$val) == TRUE) AND (!preg_match('/^\.|html$/',$val))) + { + $ky = preg_replace('/.php$/', '', $val); + $contr['monitor/'.$ky] = ucfirst($ky); + } + } + return $contr; + } + // ---- Fungsi mendapatkan nama controller di Tool + function _scanControllerTool() + { + //$root = ('./bmt-system/application/controllers/tool/'); + $root = $this->rootControllerPath.'tool/'; + $hasil = scandir($root); + foreach($hasil as $val) + { + if((is_file($root.$val) == TRUE) AND (!preg_match('/^\.|html$/',$val))) + { + $ky = preg_replace('/.php$/', '', $val); + $contr['tool/'.$ky] = ucfirst($ky); + } + } + return $contr; + } // ---- Fungsi mendapatkan nama controller di setting function _scanControllerSetting() { - $root = ('./bmt-system/application/controllers/setting/'); + //$root = ('./bmt-system/application/controllers/setting/'); + $root = $this->rootControllerPath.'setting/'; $hasil = scandir($root); foreach($hasil as $val) { diff --git a/bmt-system/application/controllers/plugin/install.php b/application/controllers/plugin/Install.php similarity index 97% rename from bmt-system/application/controllers/plugin/install.php rename to application/controllers/plugin/Install.php index 86830ca..e93c984 100644 --- a/bmt-system/application/controllers/plugin/install.php +++ b/application/controllers/plugin/Install.php @@ -1,65 +1,65 @@ -tema = $this->allfunct->getSetupapp('tema'); - $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "plugin"; - $this->menuactsub = "install"; - } - - //---- Admin - function index() - { - $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); - $data['tema'] = $this->tema; - $data['logo'] = $this->authlib->getLogo(); - $data['imgsrc'] = $this->authlib->getLogo(); - $this->load->view('plugin/install',$data); - } +tema = $this->allfunct->getSetupapp('tema'); + $this->load->model('master_model','master'); + $this->load->model('admin_model','modelku'); + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "plugin"; + $this->menuactsub = "install"; + } + + //---- Admin + function index() + { + $data['idpeg'] = $this->session->userdata('username'); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['tema'] = $this->tema; + $data['logo'] = $this->authlib->getLogo(); + $data['imgsrc'] = $this->authlib->getLogo(); + $this->load->view('plugin/install',$data); + } function uploadplugin() { $config['upload_path'] = 'assets/plugin/'; - $config['allowed_types'] = 'zip|rar'; + $config['allowed_types'] = 'zip|rar'; $this->load->library('upload', $config); if (!$this->upload->do_upload()){ echo strip_tags($this->upload->display_errors()); } else { $hasil = $this->upload->data(); - $fileasli = $hasil['full_path']; - $this->load->library('unzip'); + $fileasli = $hasil['full_path']; + $this->load->library('unzip'); // Optional: Only take out these files, anything else is ignored $this->unzip->allow(array('css', 'js', 'png', 'gif', 'jpeg', 'jpg', 'tpl', 'html', 'swf')); // Give it one parameter and it will extract to the same folder $this->unzip->extract($fileasli); // or specify a destination directory - $this->unzip->extract($fileasli, 'assets/plugin/'); + $this->unzip->extract($fileasli, 'assets/plugin/'); if (file_exists($fileasli)){ unlink($fileasli); - } - $data['name_plugin'] = $hasil['raw_name']; - $data['desc'] = $hasil['raw_name']; - $data['path'] = $hasil['file_path']."".$hasil['raw_name']."/"; + } + $data['name_plugin'] = $hasil['raw_name']; + $data['desc'] = $hasil['raw_name']; + $data['path'] = $hasil['file_path']."".$hasil['raw_name']."/"; $data['status'] = 1; echo $this->master->simpan('plugin',$data); } - } + } function get_plugin() { $ff = $this->input->post('ff'); // Jenis Filter @@ -77,26 +77,26 @@ function get_plugin() $hasil['total'] = $page_num; $hasil['alldata'] = $alldata['result']; echo json_encode($hasil); - }else{ - $hasil['total'] = 0; - echo json_encode($hasil); + }else{ + $hasil['total'] = 0; + echo json_encode($hasil); } - } + } function toogleActive() { $data = array('status' => $this->input->post('val')); $where = array('plugin_id' => $this->input->post('id')); echo $this->master->update("plugin",$data,$where); - } + } function delplugin() { - $this->load->helper("file"); + $this->load->helper("file"); $data = $this->allfunct->securePost(); - $id = $data['id']; - $this->delete_directory($data['path']); - $where = array('plugin_id' => $id); + $id = $data['id']; + $this->delete_directory($data['path']); + $where = array('plugin_id' => $id); echo $this->master->delete("plugin",$where); - } + } function delete_directory($path) { $this->load->helper("file"); // load the helper @@ -105,8 +105,8 @@ function delete_directory($path) if(rmdir($path)){} else{} return true; - } - /// menu plugin + } + /// menu plugin function getMenu() { $this-> _loadMenuset('58'); @@ -114,7 +114,7 @@ function getMenu() { echo $item; } - } + } //---- Fungsi mengisi option menu plugin function isi_menuplugin() { @@ -126,7 +126,7 @@ function isi_menuplugin() echo ""; $i++; } - } + } //---- Fungsi mengisi option Parent pada form Menu function isi_parent() { @@ -138,7 +138,7 @@ function isi_parent() echo ""; $i++; } - } + } function _loadMenuset($parent) { $hasil = $this->master->getSetupMenu($parent); @@ -148,20 +148,20 @@ function _loadMenuset($parent) foreach($hasil as $item) { $icon = ($item['icon'] != "") ? " " : ""; - $act = ($item['active'] == '1') ? "starsmall" : "starblacksmall"; - if($item['menu_id'] == 59){ - $this->isi[] = "
  • [ ".$item['menu_id']."] ".$item['nama']." (Href :".$item['href']." Urutan : ".$item['urutan'].") "; + $act = ($item['active'] == '1') ? "starsmall" : "starblacksmall"; + if($item['menu_id'] == 59){ + $this->isi[] = "
  • [ ".$item['menu_id']."] ".$item['nama']." (Href :".$item['href']." Urutan : ".$item['urutan'].") "; }else{ $this->isi[] = "
  • [ ".$item['menu_id']."] ".$item['nama']." (Href :".$item['href']." Urutan : ".$item['urutan'].")   "; - } + } $this->_loadMenuset($item['menu_id']); } $this->isi[] = ""; } else { $this->isi[] = "
  • "; } - } - -} - + } + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/plugin/migrasidata.php b/application/controllers/plugin/Migrasidata.php similarity index 91% rename from bmt-system/application/controllers/plugin/migrasidata.php rename to application/controllers/plugin/Migrasidata.php index 8c30403..8e1c382 100644 --- a/bmt-system/application/controllers/plugin/migrasidata.php +++ b/application/controllers/plugin/Migrasidata.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Migrasidata extends Controller { +class Migrasidata extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); diff --git a/bmt-system/application/controllers/plugin/simulasiemas.php b/application/controllers/plugin/Simulasiemas.php similarity index 91% rename from bmt-system/application/controllers/plugin/simulasiemas.php rename to application/controllers/plugin/Simulasiemas.php index e6008a5..166e52e 100755 --- a/bmt-system/application/controllers/plugin/simulasiemas.php +++ b/application/controllers/plugin/Simulasiemas.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Simulasiemas extends Controller { +class Simulasiemas extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); diff --git a/bmt-system/application/controllers/plugin/view.php b/application/controllers/plugin/View.php similarity index 92% rename from bmt-system/application/controllers/plugin/view.php rename to application/controllers/plugin/View.php index 62e6061..f2452db 100644 --- a/bmt-system/application/controllers/plugin/view.php +++ b/application/controllers/plugin/View.php @@ -8,17 +8,17 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class View extends Controller { +class View extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->plugin = $this->uri->segment(4); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "plugin"; + $this->menuact = "plugin"; $this->menuactsub = $this->plugin; } @@ -34,7 +34,7 @@ function main(){ $data['logo'] = $this->authlib->getLogo(); $data['imgsrc'] = $this->authlib->getLogo(); ///plugin - $data['plugin'] = $this->plugin; + $data['plugin'] = $this->plugin; $iframplugin = "assets/plugin/hello/hello.php"; $data['iframplugin'] = $iframplugin; $this->load->view('plugin/view',$data); diff --git a/bmt-system/application/controllers/setting/cetaktabungan.php b/application/controllers/setting/Cetaktabungan.php similarity index 93% rename from bmt-system/application/controllers/setting/cetaktabungan.php rename to application/controllers/setting/Cetaktabungan.php index a46c151..8de5f7a 100644 --- a/bmt-system/application/controllers/setting/cetaktabungan.php +++ b/application/controllers/setting/Cetaktabungan.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Cetaktabungan extends Controller { +class Cetaktabungan extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -34,21 +34,21 @@ function index() } // conversi cm ke pixel 1 cm = 37.8 px => 1 cm = 10 mm // font size ke pt - function editInfo() - { - $data = $this->allfunct->securePost(); - $id = 1; - $where = array('id' => $id); - echo $this->master->update("setting",$data,$where); + function editInfo() + { + $data = $this->allfunct->securePost(); + $id = 1; + $where = array('id' => $id); + echo $this->master->update("setting",$data,$where); } - function get_info() - { - $objord = $this->input->post('id'); - $where = ""; - $query = $this->db->query("SELECT set4,set5,set6,set7,set8,set9,set10,set11,set12 FROM setting"); - $data = $query->result_array(); - $hasil['alldata'] = $data; - echo json_encode($hasil); + function get_info() + { + $objord = $this->input->post('id'); + $where = ""; + $query = $this->db->query("SELECT set4,set5,set6,set7,set8,set9,set10,set11,set12 FROM setting"); + $data = $query->result_array(); + $hasil['alldata'] = $data; + echo json_encode($hasil); } diff --git a/bmt-system/application/controllers/setting/logo.php b/application/controllers/setting/Logo.php similarity index 94% rename from bmt-system/application/controllers/setting/logo.php rename to application/controllers/setting/Logo.php index 17a8e75..e5b75ef 100755 --- a/bmt-system/application/controllers/setting/logo.php +++ b/application/controllers/setting/Logo.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Logo extends Controller { +class Logo extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); diff --git a/bmt-system/application/controllers/setting/sampultab.php b/application/controllers/setting/Sampultab.php similarity index 93% rename from bmt-system/application/controllers/setting/sampultab.php rename to application/controllers/setting/Sampultab.php index 6b2dde7..7572d61 100644 --- a/bmt-system/application/controllers/setting/sampultab.php +++ b/application/controllers/setting/Sampultab.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Sampultab extends Controller { +class Sampultab extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -33,21 +33,21 @@ function index() $this->load->view('setting/sampultab',$data); } // conversi cm ke pixel 1 cm = 37.8 px => 1 cm = 10 mm - function editSampulInfo() - { - $data = $this->allfunct->securePost(); - $id = 1; - $where = array('id' => $id); - echo $this->master->update("setting",$data,$where); + function editSampulInfo() + { + $data = $this->allfunct->securePost(); + $id = 1; + $where = array('id' => $id); + echo $this->master->update("setting",$data,$where); } - function get_info() - { - $objord = $this->input->post('id'); - $where = ""; - $query = $this->db->query("SELECT set1,set2,set3 FROM setting"); - $data = $query->result_array(); - $hasil['alldata'] = $data; - echo json_encode($hasil); + function get_info() + { + $objord = $this->input->post('id'); + $where = ""; + $query = $this->db->query("SELECT set1,set2,set3 FROM setting"); + $data = $query->result_array(); + $hasil['alldata'] = $data; + echo json_encode($hasil); } function single_pegawai() diff --git a/bmt-system/application/controllers/setting/theme.php b/application/controllers/setting/Theme.php similarity index 93% rename from bmt-system/application/controllers/setting/theme.php rename to application/controllers/setting/Theme.php index 2c76784..42e2bf7 100644 --- a/bmt-system/application/controllers/setting/theme.php +++ b/application/controllers/setting/Theme.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Theme extends Controller { +class Theme extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); diff --git a/bmt-system/application/controllers/tool/backupdata.php b/application/controllers/tool/Backupdata.php similarity index 94% rename from bmt-system/application/controllers/tool/backupdata.php rename to application/controllers/tool/Backupdata.php index a65091e..1ec95e3 100755 --- a/bmt-system/application/controllers/tool/backupdata.php +++ b/application/controllers/tool/Backupdata.php @@ -1,37 +1,37 @@ -authlib->cekcontr(); - $this->load->dbutil(); - $this->tema = $this->allfunct->getSetupapp('tema'); + $this->load->dbutil(); + $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); + $this->load->model('admin_model','modelku'); $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); $this->menuact = "tools"; $this->menuactsub = "backupdata"; - } - - //---- Admin - function index() - { + } + + //---- Admin + function index() + { $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); $data['tema'] = $this->tema; - $this->load->view('tool/backupdata',$data); + $this->load->view('tool/backupdata',$data); } - + function dobackup() { $tgl = date("d-m-Y"); @@ -76,7 +76,7 @@ function login() $resp = $this->authlib->login1($login); echo $resp; } - -} - + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/tool/cronjob.php b/application/controllers/tool/Cronjob.php similarity index 98% rename from bmt-system/application/controllers/tool/cronjob.php rename to application/controllers/tool/Cronjob.php index 8ef12ab..31564e1 100644 --- a/bmt-system/application/controllers/tool/cronjob.php +++ b/application/controllers/tool/Cronjob.php @@ -1,111 +1,111 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); - $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "tools"; - $this->menuactsub = "cronjob"; - } - function index() - { - $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); - $data['tema'] = $this->tema; - $this->load->view('tool/cronjob',$data); - } - function pembiayaan(){ - $tgl2 = date('Y-m-d'); - $hasil1 = $this->db->query("SELECT t1.*,t2.nama,t3.nama_pegawai FROM tb_pembiayaan AS t1 - INNER JOIN tb_nasabah AS t2 ON t2.nomor_nasabah=t1.nomor_nasabah +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); + $this->load->model('master_model','master'); + $this->load->model('admin_model','modelku'); + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "tools"; + $this->menuactsub = "cronjob"; + } + function index() + { + $data['idpeg'] = $this->session->userdata('username'); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['tema'] = $this->tema; + $this->load->view('tool/cronjob',$data); + } + function pembiayaan(){ + $tgl2 = date('Y-m-d'); + $hasil1 = $this->db->query("SELECT t1.*,t2.nama,t3.nama_pegawai FROM tb_pembiayaan AS t1 + INNER JOIN tb_nasabah AS t2 ON t2.nomor_nasabah=t1.nomor_nasabah INNER JOIN pegawai AS t3 ON t1.nomor_ao=t3.nip WHERE t1.status=0")->result(); foreach ($hasil1 as $row1) - { - $id = $row1->pembiayaan_id; - $rek = $row1->nomor_rekening; - $hasil = $this->db->query("SELECT t1.*,sum(accounttrans_value) AS jlh FROM tb_accounttrans AS t1 - WHERE accounttrans_user='$rek' AND `accounttrans_desc` LIKE 'ANGSURAN%' AND `accounttrans_listid` !=19 AND - `accounttrans_type`='01' AND `accounttrans_date` <='$tgl2' GROUP BY accounttrans_listid ORDER BY `accounttrans_value` ASC")->result(); - $pokok = 0; - $margin = 0; - $i=0; - foreach ($hasil as $row) - { - if($i==0){ - $margin += $row->jlh; - }else{ - $pokok += $row->jlh; - } - $i++; - } + { + $id = $row1->pembiayaan_id; + $rek = $row1->nomor_rekening; + $hasil = $this->db->query("SELECT t1.*,sum(accounttrans_value) AS jlh FROM tb_accounttrans AS t1 + WHERE accounttrans_user='$rek' AND `accounttrans_desc` LIKE 'ANGSURAN%' AND `accounttrans_listid` !=19 AND + `accounttrans_type`='01' AND `accounttrans_date` <='$tgl2' GROUP BY accounttrans_listid ORDER BY `accounttrans_value` ASC")->result(); + $pokok = 0; + $margin = 0; + $i=0; + foreach ($hasil as $row) + { + if($i==0){ + $margin += $row->jlh; + }else{ + $pokok += $row->jlh; + } + $i++; + } $query = $this->db->query("SELECT pokok,margin FROM tb_pembiayaandetail WHERE id_pembiayaan='$id'"); $data = $query->result_array(); if($query->num_rows() > 0) { $pokokdetail = $data[0]["pokok"]; - } - $pCount = floor($pokok / $pokokdetail); - //update pembiayaan detail menjadi o + } + $pCount = floor($pokok / $pokokdetail); + //update pembiayaan detail menjadi o $data1['status'] = '0'; $where1 = array('id_pembiayaan' => $id); - $this->master->update("tb_pembiayaandetail",$data1,$where1); - //update pembiayaan real - for($i=1;$i<=$pCount;$i++){ + $this->master->update("tb_pembiayaandetail",$data1,$where1); + //update pembiayaan real + for($i=1;$i<=$pCount;$i++){ $query = $this->db->query("SELECT pembiayaandetail_id FROM tb_pembiayaandetail WHERE id_pembiayaan='$id' AND status=0"); $data = $query->result_array(); if($query->num_rows() > 0) { $data5['status'] = '1'; - $where = array('pembiayaandetail_id' => $data[0]["pembiayaandetail_id"]); + $where = array('pembiayaandetail_id' => $data[0]["pembiayaandetail_id"]); $this->master->update("tb_pembiayaandetail",$data5,$where); - } - } - //update status pembiayan menjadi lunas - $query1 = $this->db->query("SELECT count(*) AS tot FROM tb_pembiayaandetail WHERE id_pembiayaan='$id' AND status=0"); + } + } + //update status pembiayan menjadi lunas + $query1 = $this->db->query("SELECT count(*) AS tot FROM tb_pembiayaandetail WHERE id_pembiayaan='$id' AND status=0"); $datar = $query1->result_array(); - if($datar[0]["tot"] > 0) { - - }else{ + if($datar[0]["tot"] > 0) { + + }else{ $dataa['status'] = '1'; $wherea = array('pembiayaan_id' => $id); - $this->master->update("tb_pembiayaan",$dataa,$wherea); - } - $total = $pokok + $margin; - //echo $rek." => ".$pokok."#".$margin.":".$total."== ".$pCount."
    "; - } - echo "1"; - } - function zakat(){ + $this->master->update("tb_pembiayaan",$dataa,$wherea); + } + $total = $pokok + $margin; + //echo $rek." => ".$pokok."#".$margin.":".$total."== ".$pCount."
    "; + } + echo "1"; + } + function zakat(){ //$tglawal = $this->allfunct->revDate($this->input->post('tgl1')); - //$tglakhir = $this->allfunct->revDate($this->input->post('tgl2')); + //$tglakhir = $this->allfunct->revDate($this->input->post('tgl2')); $this->db->query("TRUNCATE TABLE `tb_zakat`"); - $hasil = $this->db->query("SELECT basilwadiah_value,basilwadiah_code,basilwadiah_rek FROM tb_basilwadiah")->result(); + $hasil = $this->db->query("SELECT basilwadiah_value,basilwadiah_code,basilwadiah_rek FROM tb_basilwadiah")->result(); foreach ($hasil as $row) - { - $nomor_rek = $row->basilwadiah_rek; - $nilai = $row->basilwadiah_value; - //cari yg zakat ya + { + $nomor_rek = $row->basilwadiah_rek; + $nilai = $row->basilwadiah_value; + //cari yg zakat ya $query1 = $this->db->query("SELECT count(*) AS tot,jenis_simpanan FROM tb_tabungan WHERE nomor_rekening ='$nomor_rek' AND zakat='YA'"); - $data = $query1->result_array(); - if($data[0]["tot"] > 0) { + $data = $query1->result_array(); + if($data[0]["tot"] > 0) { $query = $this->db->query("SELECT tab_zakat FROM master_tabungan WHERE kode_produk='".$data[0]["jenis_simpanan"]."'"); - if($query->num_rows() > 0){ + if($query->num_rows() > 0){ $rsl = $query->result_array(); $zakat = $rsl[0]["tab_zakat"] / 100; - $nilaizakat = $nilai * $zakat; + $nilaizakat = $nilai * $zakat; //masukkan ke tb_zakat $datenow = date("Y-m-d"); $zakata['zakat_rek'] = $nomor_rek; @@ -114,42 +114,42 @@ function zakat(){ //$zakata['end_date'] = $tglakhir; $zakata['zakat_value'] = $nilaizakat; $zakata['create_by'] = $this->session->userdata('username'); - $this->master->simpan('tb_zakat',$zakata); + $this->master->simpan('tb_zakat',$zakata); } - } - } - + } + } + $hasil1 = $this->db->query("SELECT basiltrans_value,kode_produk,basiltrans_rek FROM tb_basiltrans WHERE basiltrans_type=0")->result(); foreach ($hasil1 as $row) { $nomor_rek = $row->basiltrans_rek; - $nilai = $row->basiltrans_value; + $nilai = $row->basiltrans_value; $query1 = $this->db->query("SELECT count(*) AS tot,t1.jenis_simpanan FROM tb_tabungan AS t1 INNER JOIN tb_pembiayaan AS t2 ON t2.nomor_nasabah=t1.nomor_nasabah WHERE t2.nomor_rekening ='$nomor_rek' AND zakat='YA'"); $data = $query1->result_array(); - if($data[0]["tot"] > 0) { + if($data[0]["tot"] > 0) { $query = $this->db->query("SELECT tab_zakat FROM master_tabungan WHERE kode_produk='".$data[0]["jenis_simpanan"]."'"); - if($query->num_rows() > 0){ + if($query->num_rows() > 0){ $rsl = $query->result_array(); $zakat = $rsl[0]["tab_zakat"] / 100; $nilaizakat = $nilai * $zakat; //masukkan ke tb_zakat - $datenow = date("Y-m-d"); + $datenow = date("Y-m-d"); $zakat1['zakat_rek'] = $nomor_rek; $zakat1['tanggal'] = $datenow; //$zakat1['start_date'] = $tglawal; //$zakat1['end_date'] = $tglakhir; $zakat1['zakat_value'] = $nilaizakat; $zakat1['create_by'] = $this->session->userdata('username'); - $this->master->simpan('tb_zakat',$zakat1); + $this->master->simpan('tb_zakat',$zakat1); } - } - } - // masukan ke transaksi - $hasil = $this->db->query("SELECT zakat_rek,zakat_value FROM tb_zakat")->result(); - $query = $this->db->query("SELECT zakat_rek,zakat_value FROM tb_zakat"); + } + } + // masukan ke transaksi + $hasil = $this->db->query("SELECT zakat_rek,zakat_value FROM tb_zakat")->result(); + $query = $this->db->query("SELECT zakat_rek,zakat_value FROM tb_zakat"); if($query->num_rows() > 0){ - foreach ($hasil as $row){ - + foreach ($hasil as $row){ + $data1['accounttrans_listid'] = "577"; $data1['accounttrans_date'] = date('Y-m-d'); $data1['accounttrans_code'] = "577 - 08"; @@ -160,8 +160,8 @@ function zakat(){ $data1['create_date'] = date("Y-m-d H:i:s"); $data1['create_by'] = $this->session->userdata('username'); $data1['update_by'] = $this->session->userdata('username'); - $this->master->simpan('tb_accounttrans',$data1); - + $this->master->simpan('tb_accounttrans',$data1); + $data2['accounttrans_listid'] = "203"; $data2['accounttrans_date'] = date('Y-m-d'); $data2['accounttrans_code'] = "08"; @@ -172,16 +172,16 @@ function zakat(){ $data2['create_date'] = date("Y-m-d H:i:s"); $data2['create_by'] = $this->session->userdata('username'); $data2['update_by'] = $this->session->userdata('username'); - $this->master->simpan('tb_accounttrans',$data2); - } - - } - echo "1"; - } - function adm(){ + $this->master->simpan('tb_accounttrans',$data2); + } + + } + echo "1"; + } + function adm(){ //$tglawal = $this->allfunct->revDate($this->input->post('tgl1')); - //$tglakhir = $this->allfunct->revDate($this->input->post('tgl2')); - $hasil = $this->db->query("SELECT nomor_rekening,jenis_simpanan FROM tb_tabungan WHERE administrasi='YA'")->result(); + //$tglakhir = $this->allfunct->revDate($this->input->post('tgl2')); + $hasil = $this->db->query("SELECT nomor_rekening,jenis_simpanan FROM tb_tabungan WHERE administrasi='YA'")->result(); foreach ($hasil as $row){ $query = $this->db->query("SELECT adm_lain_lain FROM master_tabungan WHERE kode_produk='".$row->jenis_simpanan."'"); if($query->num_rows() > 0){ @@ -211,12 +211,12 @@ function adm(){ $data2['create_by'] = $this->session->userdata('username'); $data2['update_by'] = $this->session->userdata('username'); $this->master->simpan('tb_accounttrans',$data2); - } - } + } + } echo "1"; - - } - function pph(){ + + } + function pph(){ //$tglawal = $this->allfunct->revDate($this->input->post('tgl1')); //$tglakhir = $this->allfunct->revDate($this->input->post('tgl2')); $this->db->query("TRUNCATE TABLE `tb_pph`"); @@ -254,23 +254,23 @@ function pph(){ $query1 = $this->db->query("SELECT count(*) AS tot,t1.jenis_simpanan FROM tb_tabungan AS t1 INNER JOIN tb_pembiayaan AS t2 ON t2.nomor_nasabah=t1.nomor_nasabah WHERE t2.nomor_rekening ='$nomor_rek' AND pph='YA'"); $data = $query1->result_array(); if($data[0]["tot"] > 0) { - $query = $this->db->query("SELECT tab_pph FROM master_tabungan WHERE kode_produk='".$data[0]["jenis_simpanan"]."'"); - if($query->num_rows() > 0){ - $rsl = $query->result_array(); - $pph = $rsl[0]["tab_pph"] / 100; - $nilaipph = $nilai * $pph; - //masukkan ke tb_pph - $datenow = date("Y-m-d"); - $ipph['pph_rek'] = $nomor_rek; - $ipph['tanggal'] = $datenow; - $ipph['pph_value'] = $nilaipph; - $ipph['create_by'] = $this->session->userdata('username'); - $this->master->simpan('tb_pph',$ipph); + $query = $this->db->query("SELECT tab_pph FROM master_tabungan WHERE kode_produk='".$data[0]["jenis_simpanan"]."'"); + if($query->num_rows() > 0){ + $rsl = $query->result_array(); + $pph = $rsl[0]["tab_pph"] / 100; + $nilaipph = $nilai * $pph; + //masukkan ke tb_pph + $datenow = date("Y-m-d"); + $ipph['pph_rek'] = $nomor_rek; + $ipph['tanggal'] = $datenow; + $ipph['pph_value'] = $nilaipph; + $ipph['create_by'] = $this->session->userdata('username'); + $this->master->simpan('tb_pph',$ipph); } } } // masukan ke transaksi - $hasil = $this->db->query("SELECT pph_rek,pph_value FROM tb_pph")->result(); + $hasil = $this->db->query("SELECT pph_rek,pph_value FROM tb_pph")->result(); $query = $this->db->query("SELECT pph_rek,pph_value FROM tb_pph"); if($query->num_rows() > 0){ foreach ($hasil as $row){ @@ -301,16 +301,16 @@ function pph(){ } } - echo "1"; - } - function proses() - { - echo "proses cronjob data otomatis"; - - exit; - } - - -} - + echo "1"; + } + function proses() + { + echo "proses cronjob data otomatis"; + + exit; + } + + +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/tool/eoy.php b/application/controllers/tool/Eoy.php similarity index 98% rename from bmt-system/application/controllers/tool/eoy.php rename to application/controllers/tool/Eoy.php index 3b03981..d6f3c48 100755 --- a/bmt-system/application/controllers/tool/eoy.php +++ b/application/controllers/tool/Eoy.php @@ -1,79 +1,79 @@ -authlib->cekcontr(); - $this->tema = $this->allfunct->getSetupapp('tema'); - $this->load->model('master_model','master'); - $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "tools"; - $this->menuactsub = "eoy"; - } - - //---- Admin - function index() - { - $data['idpeg'] = $this->session->userdata('username'); - $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); - $data['tema'] = $this->tema; - $data['tahunbuku'] = $this->authlib->TahunBuku(); - $this->load->view('tool/eoy',$data); - } - function prosesEOY(){ - //$thnbukunext = $this->authlib->TahunBuku() + 1; - $thnbukunext = $this->authlib->TahunBuku(); - $thnbukunextn = $thnbukunext."-12-31 00:00:01"; - $this->db->query("DELETE FROM `tb_accounttrans` WHERE YEAR(accounttrans_date)='".$thnbukunext."' AND accounttrans_code LIKE 'EOY%'"); - /// ====== - // Pendapatan (d) (semua code account pendapatan yg ada nilainya kecuali nomor account 525.02 , 525.32 , 525.52 di kredit) - // SHU tahun lulu (k) (430.01.01 LABA/RUGI TAHUN LALU) +authlib->cekcontr(); + $this->tema = $this->allfunct->getSetupapp('tema'); + $this->load->model('master_model','master'); + $this->load->model('admin_model','modelku'); + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "tools"; + $this->menuactsub = "eoy"; + } + + //---- Admin + function index() + { + $data['idpeg'] = $this->session->userdata('username'); + $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); + $data['tema'] = $this->tema; + $data['tahunbuku'] = $this->authlib->TahunBuku(); + $this->load->view('tool/eoy',$data); + } + function prosesEOY(){ + //$thnbukunext = $this->authlib->TahunBuku() + 1; + $thnbukunext = $this->authlib->TahunBuku(); + $thnbukunextn = $thnbukunext."-12-31 00:00:01"; + $this->db->query("DELETE FROM `tb_accounttrans` WHERE YEAR(accounttrans_date)='".$thnbukunext."' AND accounttrans_code LIKE 'EOY%'"); + /// ====== + // Pendapatan (d) (semua code account pendapatan yg ada nilainya kecuali nomor account 525.02 , 525.32 , 525.52 di kredit) + // SHU tahun lulu (k) (430.01.01 LABA/RUGI TAHUN LALU) // ======= - $hasil = $this->db->query("SELECT listakun_id,t2.listakun_code AS listakun_code,t1.* FROM `tb_accounttrans` AS t1 - INNER JOIN coa_listakun AS t2 ON t2.listakun_id=t1.`accounttrans_listid` - WHERE listakun_code LIKE '5%' AND listakun_code NOT LIKE '525%' AND YEAR(accounttrans_date)='".$this->authlib->TahunBuku()."'")->result(); - $shuP = 0; - foreach ($hasil as $row){ - /// data pendapatan - $shuP += $row->accounttrans_value; - $listakun_code = $row->listakun_code; - $listakun_id = $row->listakun_id; + $hasil = $this->db->query("SELECT listakun_id,t2.listakun_code AS listakun_code,t1.* FROM `tb_accounttrans` AS t1 + INNER JOIN coa_listakun AS t2 ON t2.listakun_id=t1.`accounttrans_listid` + WHERE listakun_code LIKE '5%' AND listakun_code NOT LIKE '525%' AND YEAR(accounttrans_date)='".$this->authlib->TahunBuku()."'")->result(); + $shuP = 0; + foreach ($hasil as $row){ + /// data pendapatan + $shuP += $row->accounttrans_value; + $listakun_code = $row->listakun_code; + $listakun_id = $row->listakun_id; $data['accounttrans_type'] = "02"; $data['accounttrans_listid'] = $listakun_id; $data['accounttrans_code'] = "EOY ".$row->accounttrans_code; - $data['accounttrans_user'] = $row->accounttrans_user; + $data['accounttrans_user'] = $row->accounttrans_user; $data['accounttrans_desc'] = 'EOY '.$row->accounttrans_desc; - $data['accounttrans_value'] = $row->accounttrans_value; - $data['accounttrans_date'] = $thnbukunextn; + $data['accounttrans_value'] = $row->accounttrans_value; + $data['accounttrans_date'] = $thnbukunextn; $data['create_date'] = $thnbukunextn; $data['create_by'] = $this->session->userdata('username'); $data['update_by'] = $this->session->userdata('username'); - $this->master->simpan("tb_accounttrans",$data); - } - /// data pendapatan LABA/RUGI TAHUN LALU + $this->master->simpan("tb_accounttrans",$data); + } + /// data pendapatan LABA/RUGI TAHUN LALU $data1['accounttrans_type'] = "01"; $data1['accounttrans_listid'] = "283"; $data1['accounttrans_code'] = "EOY-430.01.01"; $data1['accounttrans_user'] = "EOY"; $data1['accounttrans_desc'] = 'EOY LABA/RUGI TAHUN LALU'; $data1['accounttrans_value'] = $shuP; - $data1['accounttrans_date'] = $thnbukunextn; + $data1['accounttrans_date'] = $thnbukunextn; $data1['create_date'] = $thnbukunextn; $data1['create_by'] = $this->session->userdata('username'); $data1['update_by'] = $this->session->userdata('username'); - $this->master->simpan("tb_accounttrans",$data1); - ///===================== + $this->master->simpan("tb_accounttrans",$data1); + ///===================== $hasil = $this->db->query("SELECT listakun_id,t2.listakun_code AS listakun_code,t1.* FROM `tb_accounttrans` AS t1 INNER JOIN coa_listakun AS t2 ON t2.listakun_id=t1.`accounttrans_listid` WHERE listakun_code LIKE '525%' AND YEAR(accounttrans_date)='".$this->authlib->TahunBuku()."'")->result(); @@ -106,32 +106,32 @@ function prosesEOY(){ $data3['create_date'] = $thnbukunextn; $data3['create_by'] = $this->session->userdata('username'); $data3['update_by'] = $this->session->userdata('username'); - $this->master->simpan("tb_accounttrans",$data3); - // ========= + $this->master->simpan("tb_accounttrans",$data3); + // ========= // SHU tahun lulu (d) (430.01.01 LABA/RUGI TAHUN LALU) - // Beban (k) (semua code beban yg ada nilainya dan semua hak bagi hasil 605.) - // ========= + // Beban (k) (semua code beban yg ada nilainya dan semua hak bagi hasil 605.) + // ========= $hasil = $this->db->query("SELECT listakun_id,t2.listakun_code AS listakun_code,t1.* FROM `tb_accounttrans` AS t1 INNER JOIN coa_listakun AS t2 ON t2.listakun_id=t1.`accounttrans_listid` WHERE listakun_code LIKE '6%' AND YEAR(accounttrans_date)='".$this->authlib->TahunBuku()."'")->result(); - $shuB = 0; + $shuB = 0; foreach ($hasil as $row){ /// data beban dan bagi hasil - $shuB += $row->accounttrans_value; + $shuB += $row->accounttrans_value; $listakun_code = $row->listakun_code; - $listakun_id = $row->listakun_id; - $data4['accounttrans_type'] = "01"; - $data4['accounttrans_listid'] = $listakun_id; - $data4['accounttrans_code'] = "EOY ".$row->accounttrans_code; - $data4['accounttrans_user'] = $row->accounttrans_user; - $data4['accounttrans_desc'] = 'EOY '.$row->accounttrans_desc; - $data4['accounttrans_value'] = $row->accounttrans_value; - $data4['accounttrans_date'] = $thnbukunextn; - $data4['create_date'] = $thnbukunextn; - $data4['create_by'] = $this->session->userdata('username'); - $data4['update_by'] = $this->session->userdata('username'); + $listakun_id = $row->listakun_id; + $data4['accounttrans_type'] = "01"; + $data4['accounttrans_listid'] = $listakun_id; + $data4['accounttrans_code'] = "EOY ".$row->accounttrans_code; + $data4['accounttrans_user'] = $row->accounttrans_user; + $data4['accounttrans_desc'] = 'EOY '.$row->accounttrans_desc; + $data4['accounttrans_value'] = $row->accounttrans_value; + $data4['accounttrans_date'] = $thnbukunextn; + $data4['create_date'] = $thnbukunextn; + $data4['create_by'] = $this->session->userdata('username'); + $data4['update_by'] = $this->session->userdata('username'); $this->master->simpan("tb_accounttrans",$data4); - } + } /// data pendapatan LABA/RUGI TAHUN LALU $data5['accounttrans_type'] = "02"; $data5['accounttrans_listid'] = "283"; @@ -143,9 +143,9 @@ function prosesEOY(){ $data5['create_date'] = $thnbukunextn; $data5['create_by'] = $this->session->userdata('username'); $data5['update_by'] = $this->session->userdata('username'); - $resp = $this->master->simpan("tb_accounttrans",$data5); - - ////=== + $resp = $this->master->simpan("tb_accounttrans",$data5); + + ////=== $hasil = $this->db->query("SELECT listakun_id,t2.listakun_code AS listakun_code,t1.* FROM `tb_accounttrans` AS t1 INNER JOIN coa_listakun AS t2 ON t2.listakun_id=t1.`accounttrans_listid` WHERE listakun_code LIKE '7%' AND YEAR(accounttrans_date)='".$this->authlib->TahunBuku()."'")->result(); @@ -178,9 +178,9 @@ function prosesEOY(){ $data5['create_date'] = $thnbukunextn; $data5['create_by'] = $this->session->userdata('username'); $data5['update_by'] = $this->session->userdata('username'); - $resp = $this->master->simpan("tb_accounttrans",$data5); - echo $resp; - } -} - + $resp = $this->master->simpan("tb_accounttrans",$data5); + echo $resp; + } +} + /* End of file */ \ No newline at end of file diff --git a/bmt-system/application/controllers/tool/hitungbasil.php b/application/controllers/tool/Hitungbasil.php similarity index 97% rename from bmt-system/application/controllers/tool/hitungbasil.php rename to application/controllers/tool/Hitungbasil.php index 0ebb5cc..8a0353a 100755 --- a/bmt-system/application/controllers/tool/hitungbasil.php +++ b/application/controllers/tool/Hitungbasil.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Hitungbasil extends Controller { +class Hitungbasil extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -34,8 +34,8 @@ function distribusiprofit(){ $tglawal = $this->allfunct->revDate($this->input->post('tgl1')); $tglakhir = $this->allfunct->revDate($this->input->post('tgl2')); //distribusi bonus - $query = $this->db->query("SELECT gl_produk,gl_bagihasil FROM master_tabungan"); - $data = $query->result_array(); + $query = $this->db->query("SELECT gl_produk,gl_bagihasil FROM master_tabungan"); + $data = $query->result_array(); $glproduk = $data[0]["gl_produk"]; $glbonus = $data[0]["gl_bagihasil"]; $hasil = $this->db->query("SELECT basilwadiah_value AS jlh,basilwadiah_code,basilwadiah_rek FROM tb_basilwadiah WHERE start_date >='$tglawal' AND end_date <='$tglakhir'")->result(); @@ -54,18 +54,18 @@ function distribusiprofit(){ //$data1['accounttrans_posted'] = '1'; //$this->master->simpan('tb_accounttemp',$data1); - $data2['accounttrans_listid'] = $glproduk; - $data2['accounttrans_date'] = date('Y-m-d'); - $data2['accounttrans_code'] = $glproduk." - ".$row->basilwadiah_rek; - $data2['accounttrans_type'] = '01'; - $data2['accounttrans_value'] = $row->jlh; - $data2['accounttrans_desc'] = "BONUS WADIAH"; + $data2['accounttrans_listid'] = $glproduk; + $data2['accounttrans_date'] = date('Y-m-d'); + $data2['accounttrans_code'] = $glproduk." - ".$row->basilwadiah_rek; + $data2['accounttrans_type'] = '01'; + $data2['accounttrans_value'] = $row->jlh; + $data2['accounttrans_desc'] = "BONUS WADIAH"; $data2['accounttrans_user'] = $row->basilwadiah_rek; - $data2['create_date'] = date("Y-m-d H:i:s"); - $data2['create_by'] = $this->session->userdata('username'); - $data2['update_by'] = $this->session->userdata('username'); - $this->master->simpan('tb_accounttrans',$data2); - //$data2['accounttrans_posted'] = '1'; + $data2['create_date'] = date("Y-m-d H:i:s"); + $data2['create_by'] = $this->session->userdata('username'); + $data2['update_by'] = $this->session->userdata('username'); + $this->master->simpan('tb_accounttrans',$data2); + //$data2['accounttrans_posted'] = '1'; //$this->master->simpan('tb_accounttemp',$data2); } @@ -74,14 +74,14 @@ function distribusiprofit(){ $hasil = $this->db->query("SELECT basiltrans_value AS jlh,kode_produk,basiltrans_rek FROM tb_basiltrans WHERE basiltrans_type=0 AND start_date >='$tglawal' AND end_date <='$tglakhir'")->result(); foreach ($hasil as $row){ $basiln = $row->jlh; - $query = $this->db->query("SELECT gl_produk,gl_bagihasil,gl_titipanbagihasil FROM master_deposito WHERE kode_produk='".$row->kode_produk."'"); - $data = $query->result_array(); - $glproduk = $data[0]["gl_produk"]; - $glbasil = $data[0]["gl_bagihasil"]; - $gltitipanbasil = $data[0]["gl_titipanbagihasil"]; + $query = $this->db->query("SELECT gl_produk,gl_bagihasil,gl_titipanbagihasil FROM master_deposito WHERE kode_produk='".$row->kode_produk."'"); + $data = $query->result_array(); + $glproduk = $data[0]["gl_produk"]; + $glbasil = $data[0]["gl_bagihasil"]; + $gltitipanbasil = $data[0]["gl_titipanbagihasil"]; // cek rekening nasabah - $query1 = $this->db->query("SELECT rekening_basil FROM tb_deposito WHERE nomor_rekening='".$row->basiltrans_rek."'"); - $dataa = $query1->result_array(); + $query1 = $this->db->query("SELECT rekening_basil FROM tb_deposito WHERE nomor_rekening='".$row->basiltrans_rek."'"); + $dataa = $query1->result_array(); $rekening_basil = $dataa[0]["rekening_basil"]; if(isset($rekening_basil)){ $data1['accounttrans_listid'] = $glbasil; diff --git a/bmt-system/application/controllers/trans/kaskeluarmasuk.php b/application/controllers/trans/Kaskeluarmasuk.php similarity index 97% rename from bmt-system/application/controllers/trans/kaskeluarmasuk.php rename to application/controllers/trans/Kaskeluarmasuk.php index f4a5936..f18e00b 100755 --- a/bmt-system/application/controllers/trans/kaskeluarmasuk.php +++ b/application/controllers/trans/Kaskeluarmasuk.php @@ -8,30 +8,30 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Kaskeluarmasuk extends Controller { +class Kaskeluarmasuk extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); - $this->load->model('master_model','master'); + $this->load->model('master_model','master'); $this->load->model('admin_model','modelku'); - $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); - $this->menuact = "transaksikas"; - $this->menuactsub = "kaskeluarmasuk"; + $this->nama_group = $this->authlib->getGroup($this->encrypt->decode($this->session->userdata('id_group'))); + $this->menuact = "transaksikas"; + $this->menuactsub = "kaskeluarmasuk"; } //---- Admin function index() { - $data['idpeg'] = $this->session->userdata('username'); + $data['idpeg'] = $this->session->userdata('username'); $data['menunya'] = $this->authlib->loadMenu('0',$this->nama_group,$this->menuact,$this->menuactsub); - $data['tema'] = $this->tema; + $data['tema'] = $this->tema; $this->load->view('trans/kaskeluarmasuk',$data); - } + } - function tarikkas(){ + function tarikkas(){ $data = $this->allfunct->securePost(); //kas keluar if($data['accounttrans_type'] == "02"){ @@ -78,28 +78,28 @@ function tarikkas(){ $data2['create_by'] = $this->session->userdata('username'); $data2['update_by'] = $this->session->userdata('username'); echo $this->master->simpan('tb_accounttemp',$data2); - } - } - function single_pegawai() - { - $data = $this->allfunct->securePost(); - $peg = $data['peg']; - $query = $this->db->query("SELECT nama_pegawai FROM pegawai WHERE nip='".$peg."'"); - $data = $query->result_array(); - if($query->num_rows() > 0) { - $ppeg = $data[0]["nama_pegawai"]; - echo $ppeg; - }else{ - echo ""; - } - } - function login() - { - $data = $this->allfunct->securePost(); - $login = array($data['username'], $data['password']); - $resp = $this->authlib->login1($login); - echo $resp; - } + } + } + function single_pegawai() + { + $data = $this->allfunct->securePost(); + $peg = $data['peg']; + $query = $this->db->query("SELECT nama_pegawai FROM pegawai WHERE nip='".$peg."'"); + $data = $query->result_array(); + if($query->num_rows() > 0) { + $ppeg = $data[0]["nama_pegawai"]; + echo $ppeg; + }else{ + echo ""; + } + } + function login() + { + $data = $this->allfunct->securePost(); + $login = array($data['username'], $data['password']); + $resp = $this->authlib->login1($login); + echo $resp; + } } diff --git a/bmt-system/application/controllers/trans/reportteller.php b/application/controllers/trans/Reportteller.php similarity index 96% rename from bmt-system/application/controllers/trans/reportteller.php rename to application/controllers/trans/Reportteller.php index c562f7a..a0ffa7d 100644 --- a/bmt-system/application/controllers/trans/reportteller.php +++ b/application/controllers/trans/Reportteller.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Reportteller extends Controller { +class Reportteller extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -46,21 +46,21 @@ function saldokhasanah() echo "0"; } } - function viewtransaksihead() - { - $data = $this->allfunct->securePost(); - $tglawal = $this->allfunct->revDate($data['tglawal']); - $tglakhir = $this->allfunct->revDate($data['tglakhir']); - $id = $this->session->userdata('user_id'); - $where = "WHERE accounttrans_date BETWEEN '$tglawal' AND '$tglakhir' "; - if($id != "0"){ - $where .= " AND accounttrans_listid='568' AND t2.user_id='".$id."'"; + function viewtransaksihead() + { + $data = $this->allfunct->securePost(); + $tglawal = $this->allfunct->revDate($data['tglawal']); + $tglakhir = $this->allfunct->revDate($data['tglakhir']); + $id = $this->session->userdata('user_id'); + $where = "WHERE accounttrans_date BETWEEN '$tglawal' AND '$tglakhir' "; + if($id != "0"){ + $where .= " AND accounttrans_listid='568' AND t2.user_id='".$id."'"; } $hasil = $this->db->query("SELECT accounttrans_date,accounttrans_code,accounttrans_type,accounttrans_desc,accounttrans_value,create_by, accounttrans_value FROM tb_accounttrans AS t1 INNER JOIN users AS t2 ON t2.username=t1.create_by - ".$where."")->result(); + ".$where."")->result(); $pTitle = ""; $i = 0; foreach ($hasil as $row){ @@ -71,13 +71,13 @@ function viewtransaksihead() $kredit = 0; $debet = $row->accounttrans_value; } - $saldo = $kredit + $debet; - $clr = (($i%2) == 0) ? '#fff' : '#EFF1F1'; + $saldo = $kredit + $debet; + $clr = (($i%2) == 0) ? '#fff' : '#EFF1F1'; $pTitle .= $row->accounttrans_value."**"; - $i++; + $i++; } - echo $pTitle; + echo $pTitle; } function viewtransaksi() { diff --git a/bmt-system/application/controllers/trans/reporttransaksi.php b/application/controllers/trans/Reporttransaksi.php similarity index 95% rename from bmt-system/application/controllers/trans/reporttransaksi.php rename to application/controllers/trans/Reporttransaksi.php index 0aff3b4..92d4ad2 100755 --- a/bmt-system/application/controllers/trans/reporttransaksi.php +++ b/application/controllers/trans/Reporttransaksi.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Reporttransaksi extends Controller { +class Reporttransaksi extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); diff --git a/bmt-system/application/controllers/trans/selisihkuranglebih.php b/application/controllers/trans/Selisihkuranglebih.php similarity index 96% rename from bmt-system/application/controllers/trans/selisihkuranglebih.php rename to application/controllers/trans/Selisihkuranglebih.php index a2d70a9..7f5c74b 100755 --- a/bmt-system/application/controllers/trans/selisihkuranglebih.php +++ b/application/controllers/trans/Selisihkuranglebih.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Selisihkuranglebih extends Controller { +class Selisihkuranglebih extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -34,50 +34,50 @@ function index() function selisih(){ $data = $this->allfunct->securePost(); if($data['accounttrans_type'] == "02"){ - $data1['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); - $data1['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); - $data1['accounttrans_desc'] = $data['ket']; - $data1['accounttrans_code'] = $data['nomor_ref']."-01"; - $data1['accounttrans_type'] = "01"; - $data1['accounttrans_listid'] = "19"; - $data1['create_date'] = date("Y-m-d H:i:s"); - $data1['create_by'] = $this->session->userdata('username'); + $data1['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); + $data1['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); + $data1['accounttrans_desc'] = $data['ket']; + $data1['accounttrans_code'] = $data['nomor_ref']."-01"; + $data1['accounttrans_type'] = "01"; + $data1['accounttrans_listid'] = "19"; + $data1['create_date'] = date("Y-m-d H:i:s"); + $data1['create_by'] = $this->session->userdata('username'); $data1['update_by'] = $this->session->userdata('username'); $this->master->simpan('tb_accounttemp',$data1); - $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); - $data2['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); - $data2['accounttrans_desc'] = $data['ket']; - $data2['accounttrans_code'] = $data['nomor_ref']."-02"; - $data2['accounttrans_type'] = "02"; - $data2['accounttrans_listid'] = "187"; - $data2['create_date'] = date("Y-m-d H:i:s"); - $data2['create_by'] = $this->session->userdata('username'); - $data2['update_by'] = $this->session->userdata('username'); + $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); + $data2['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); + $data2['accounttrans_desc'] = $data['ket']; + $data2['accounttrans_code'] = $data['nomor_ref']."-02"; + $data2['accounttrans_type'] = "02"; + $data2['accounttrans_listid'] = "187"; + $data2['create_date'] = date("Y-m-d H:i:s"); + $data2['create_by'] = $this->session->userdata('username'); + $data2['update_by'] = $this->session->userdata('username'); echo $this->master->simpan('tb_accounttemp',$data2); } - if($data['accounttrans_type'] == "01"){ - $data1['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); - $data1['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); - $data1['accounttrans_desc'] = $data['ket']; - $data1['accounttrans_code'] = $data['nomor_ref']."-02"; - $data1['accounttrans_type'] = "02"; - $data1['accounttrans_listid'] = "19"; - $data1['create_date'] = date("Y-m-d H:i:s"); - $data1['create_by'] = $this->session->userdata('username'); - $data1['update_by'] = $this->session->userdata('username'); - $this->master->simpan('tb_accounttemp',$data1); - - $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); - $data2['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); - $data2['accounttrans_desc'] = $data['ket']; - $data2['accounttrans_code'] = $data['nomor_ref']."-01"; - $data2['accounttrans_type'] = "01"; - $data2['accounttrans_listid'] = "187"; - $data2['create_date'] = date("Y-m-d H:i:s"); - $data2['create_by'] = $this->session->userdata('username'); - $data2['update_by'] = $this->session->userdata('username'); - echo $this->master->simpan('tb_accounttemp',$data2); + if($data['accounttrans_type'] == "01"){ + $data1['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); + $data1['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); + $data1['accounttrans_desc'] = $data['ket']; + $data1['accounttrans_code'] = $data['nomor_ref']."-02"; + $data1['accounttrans_type'] = "02"; + $data1['accounttrans_listid'] = "19"; + $data1['create_date'] = date("Y-m-d H:i:s"); + $data1['create_by'] = $this->session->userdata('username'); + $data1['update_by'] = $this->session->userdata('username'); + $this->master->simpan('tb_accounttemp',$data1); + + $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); + $data2['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); + $data2['accounttrans_desc'] = $data['ket']; + $data2['accounttrans_code'] = $data['nomor_ref']."-01"; + $data2['accounttrans_type'] = "01"; + $data2['accounttrans_listid'] = "187"; + $data2['create_date'] = date("Y-m-d H:i:s"); + $data2['create_by'] = $this->session->userdata('username'); + $data2['update_by'] = $this->session->userdata('username'); + echo $this->master->simpan('tb_accounttemp',$data2); } } function single_pegawai() diff --git a/bmt-system/application/controllers/trans/transaksilain.php b/application/controllers/trans/Transaksilain.php similarity index 96% rename from bmt-system/application/controllers/trans/transaksilain.php rename to application/controllers/trans/Transaksilain.php index b9306be..6286e49 100755 --- a/bmt-system/application/controllers/trans/transaksilain.php +++ b/application/controllers/trans/Transaksilain.php @@ -8,11 +8,11 @@ * email : edi.suwoto@gmail.com */ /*----------------------------------------------------------*/ -class Transaksilain extends Controller { +class Transaksilain extends CI_Controller { function __construct() { - parent::Controller(); + parent::__construct(); $this->authlib->cekcontr(); $this->tema = $this->allfunct->getSetupapp('tema'); $this->load->model('master_model','master'); @@ -34,50 +34,50 @@ function index() function selisih(){ $data = $this->allfunct->securePost(); if($data['accounttrans_code'] == "02"){ - $data1['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); - $data1['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); - $data1['accounttrans_desc'] = $data['ket']; - $data1['accounttrans_code'] = $data['nomor_ref']."-01"; - $data1['accounttrans_type'] = "01"; - $data1['accounttrans_listid'] = "19"; - $data1['create_date'] = date("Y-m-d H:i:s"); - $data1['create_by'] = $this->session->userdata('username'); + $data1['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); + $data1['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); + $data1['accounttrans_desc'] = $data['ket']; + $data1['accounttrans_code'] = $data['nomor_ref']."-01"; + $data1['accounttrans_type'] = "01"; + $data1['accounttrans_listid'] = "19"; + $data1['create_date'] = date("Y-m-d H:i:s"); + $data1['create_by'] = $this->session->userdata('username'); $data1['update_by'] = $this->session->userdata('username'); $this->master->simpan('tb_accounttemp',$data1); - $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); - $data2['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); - $data2['accounttrans_desc'] = $data['ket']; - $data2['accounttrans_code'] = $data['nomor_ref']."-02"; - $data2['accounttrans_type'] = "02"; - $data2['accounttrans_listid'] = $data['accounttrans_type']; - $data2['create_date'] = date("Y-m-d H:i:s"); - $data2['create_by'] = $this->session->userdata('username'); - $data2['update_by'] = $this->session->userdata('username'); + $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); + $data2['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); + $data2['accounttrans_desc'] = $data['ket']; + $data2['accounttrans_code'] = $data['nomor_ref']."-02"; + $data2['accounttrans_type'] = "02"; + $data2['accounttrans_listid'] = $data['accounttrans_type']; + $data2['create_date'] = date("Y-m-d H:i:s"); + $data2['create_by'] = $this->session->userdata('username'); + $data2['update_by'] = $this->session->userdata('username'); echo $this->master->simpan('tb_accounttemp',$data2); } - if($data['accounttrans_code'] == "01"){ - $data1['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); - $data1['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); - $data1['accounttrans_desc'] = $data['ket']; - $data1['accounttrans_code'] = $data['nomor_ref']."-02"; - $data1['accounttrans_type'] = "02"; - $data1['accounttrans_listid'] = "19"; - $data1['create_date'] = date("Y-m-d H:i:s"); - $data1['create_by'] = $this->session->userdata('username'); - $data1['update_by'] = $this->session->userdata('username'); - $this->master->simpan('tb_accounttemp',$data1); - - $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); - $data2['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); - $data2['accounttrans_desc'] = $data['ket']; - $data2['accounttrans_code'] = $data['nomor_ref']."-01"; - $data2['accounttrans_type'] = "01"; - $data2['accounttrans_listid'] = $data['accounttrans_type']; - $data2['create_date'] = date("Y-m-d H:i:s"); - $data2['create_by'] = $this->session->userdata('username'); - $data2['update_by'] = $this->session->userdata('username'); - echo $this->master->simpan('tb_accounttemp',$data2); + if($data['accounttrans_code'] == "01"){ + $data1['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); + $data1['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); + $data1['accounttrans_desc'] = $data['ket']; + $data1['accounttrans_code'] = $data['nomor_ref']."-02"; + $data1['accounttrans_type'] = "02"; + $data1['accounttrans_listid'] = "19"; + $data1['create_date'] = date("Y-m-d H:i:s"); + $data1['create_by'] = $this->session->userdata('username'); + $data1['update_by'] = $this->session->userdata('username'); + $this->master->simpan('tb_accounttemp',$data1); + + $data2['accounttrans_date'] = $this->allfunct->revDate($data['tgl_transaksi']); + $data2['accounttrans_value'] = $this->allfunct->uangDB($data['jumlah']); + $data2['accounttrans_desc'] = $data['ket']; + $data2['accounttrans_code'] = $data['nomor_ref']."-01"; + $data2['accounttrans_type'] = "01"; + $data2['accounttrans_listid'] = $data['accounttrans_type']; + $data2['create_date'] = date("Y-m-d H:i:s"); + $data2['create_by'] = $this->session->userdata('username'); + $data2['update_by'] = $this->session->userdata('username'); + echo $this->master->simpan('tb_accounttemp',$data2); } } function single_pegawai() diff --git a/application/core/index.html b/application/core/index.html new file mode 100644 index 0000000..b48b490 --- /dev/null +++ b/application/core/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/helpers/app_helper.php b/application/helpers/app_helper.php new file mode 100644 index 0000000..4c1b19f --- /dev/null +++ b/application/helpers/app_helper.php @@ -0,0 +1,649 @@ +'; + print_r($data); + if ($die) { + die(); + } + } + } + + if (!function_exists('generate_nama')) { + function generate_nama($first_name = '', $last_name = '') + { + if ($first_name != '' && $last_name != '') { + return ucfirst(strtolower($first_name)).' '.ucfirst(strtolower($last_name)); + } else { + return ucfirst(strtolower($first_name)).ucfirst(strtolower($last_name)); + } + } + } + + /* + * Convert an array to a user-readable JSON string + * + * @param array $array - The original array to convert to JSON + * @return string - Friendly formatted JSON string + */ + if (!function_exists('json_indent')) { + function json_indent($array = array()) + { + // make sure array is provided + if (empty($array)) { + return null; + } + + //Encode the string + $json = json_encode($array); + + $result = ''; + $pos = 0; + $str_len = strlen($json); + $indent_str = ' '; + $new_line = "\n"; + $prev_char = ''; + $out_of_quotes = true; + + for ($i = 0; $i <= $str_len; ++$i) { + // grab the next character in the string + $char = substr($json, $i, 1); + + // are we inside a quoted string? + if ($char == '"' && $prev_char != '\\') { + $out_of_quotes = !$out_of_quotes; + } + // if this character is the end of an element, output a new line and indent the next line + elseif (($char == '}' or $char == ']') && $out_of_quotes) { + $result .= $new_line; + --$pos; + + for ($j = 0; $j < $pos; ++$j) { + $result .= $indent_str; + } + } + + // add the character to the result string + $result .= $char; + + // if the last character was the beginning of an element, output a new line and indent the next line + if (($char == ',' or $char == '{' or $char == '[') && $out_of_quotes) { + $result .= $new_line; + + if ($char == '{' or $char == '[') { + ++$pos; + } + + for ($j = 0; $j < $pos; ++$j) { + $result .= $indent_str; + } + } + + $prev_char = $char; + } + + // return result + return $result.$new_line; + } + } + + if (!function_exists('convert_ke_bulan')) { + function convert_ke_bulan($idbulan, $full = false) + { + $shortName = array( + 'Jan', + 'Feb', + 'Mar', + 'Apr', + 'Mei', + 'Jun', + 'Jul', + 'Ags', + 'Sep', + 'Okt', + 'Nov', + 'Des', + ); + + if ($full) { + $fullName = array( + 'Januari', + 'Februari', + 'Maret', + 'April', + 'Mei', + 'Juni', + 'Juli', + 'Agustus', + 'September', + 'Oktober', + 'November', + 'Desember', + ); + + return $fullName[$idbulan - 1]; + } + + return $shortName[$idbulan - 1]; + } + } + + if (!function_exists('tglIndonesia')) { + function tglIndonesia($tgldb, $separator_asal = '-', $separator_tujuan = ' ', $full = false) + { + if (empty($tgldb) && (strlen($tgldb) < 4)) { + return null; + } + /* $tgldb formatnya 2015-05-29 , rubah menjadi 29-Mei-2015 */ + /* cek apakah mengandung jam atau detik, panjang max = 10 karakter */ + $tgldb = substr($tgldb, 0, 10); + + $tgl = explode($separator_asal, $tgldb); + if (!(count($tgl) > 1)) { + return $tgldb; + } + $newTgl = array( + $tgl[2], + convert_ke_bulan($tgl[1], $full), + $tgl[0], + ); + + return implode($separator_tujuan, $newTgl); + } + } + + if (!function_exists('dateFormatter')) { + function dateFormatter($tgl, $format = 'Y-m-d') + { + if (empty($tgl)) { + return null; + } + /* $tgl formatnya d-m-Y , rubah menjadi Y-m-d atau yang lain */ + $date = new DateTime($tgl); + + $new_date = $date->format($format); + + return $new_date; + } + } + + if (!function_exists('prev_date')) { + function prev_date($date, $minus = 1) + { + return date('Y-m-d', strtotime('-'.$minus.' day', strtotime($date))); + } + } + + if (!function_exists('next_date')) { + function next_date($date, $plus = 1) + { + return date('Y-m-d', strtotime('+'.$plus.' day', strtotime($date))); + } + } + + if (!function_exists('angkaRibuan')) { + function angkaRibuan($angka, $default = 0) + { + if (isset($angka)) { + if (is_numeric($angka)) { + return number_format($angka, 0, '', '.'); + } else { + return $angka; + } + } else { + return $default; + } + } + } + + if (!function_exists('angkaDecimal')) { + function angkaDecimal($angka, $default = 0) + { + if (isset($angka)) { + if (is_numeric($angka)) { + return number_format(($angka * 1), $default, ',', '.'); + } else { + return $angka; + } + } else { + return $default; + } + } + } + + if (!function_exists('ubahNama')) { + function ubahNama($filename) + { + $ext_pos = strrpos($filename, '.'); + $ext = substr($filename, $ext_pos); + $filename = substr($filename, 0, $ext_pos); + $filename = preg_replace('/\s+/', '_', $filename); + + return str_replace('.', '_', $filename).$ext; + $filename = preg_replace('/\s+/', '_', $filename); + + return str_replace(',', '_', $filename).$ext; + } + } + + if (!function_exists('outputJson')) { + function outputJson($data) + { + $CI = &get_instance(); + $CI->output + ->set_content_type('application/json') + ->set_output(json_encode($data)); + } + } + + if (!function_exists('jamIndonesia')) { + function jamIndonesia($tgldb, $jmlChar = 5) + { + if (empty($tgldb)) { + return null; + } + /* $tgldb formatnya 2015-05-29 , rubah menjadi 29-Mei-2015 */ + /* cek apakah mengandung jam atau detik, panjang max = 10 karakter */ + $tgldb = substr($tgldb, 0, $jmlChar); + + return $tgldb; + } + } + + if (!function_exists('dateDifference')) { + function dateDifference($date_1, $date_2, $differenceFormat = '%a') + { + $datetime1 = date_create($date_1); + $datetime2 = date_create($date_2); + + $interval = date_diff($datetime1, $datetime2); + + return $interval->format($differenceFormat); + } + } + /* convert hari menjadi minggu + hari */ + if (!function_exists('convertUmur')) { + function convertUmur($hari) + { + if (empty($hari)) { + return 0; + } + + return strval(floor($hari / 7)).'+'.strval($hari % 7); + } + } + + if (!function_exists('convertElemenTglWaktuIndonesia')) { + function convertElemenTglWaktuIndonesia($a, $detik = false) + { + $tgl = null; + if (!empty($a)) { + /* cek apakah mengandung waktu */ + $t = explode(' ', $a); + $tgl = tglIndonesia($t[0], '-', ' '); + if (!empty($t[1])) { + if (!$detik) { + $t[1] = substr($t[1], 0, 5); + } + $tgl .= ' '.$t[1]; + } + } + + return $tgl; + } + } + + if (!function_exists('arr2to1D')) { + function arr2to1D($arr, $key) + { + $tmp = array(); + foreach ($arr as $k) { + array_push($tmp, $k[$key]); + } + + return $tmp; + } + } + + if (!function_exists('convertArr')) { + function convertArr($arr, $key) + { + $tmp = array(); + foreach ($arr as $val) { + $id = $val[$key]; + $tmp[$id] = $val; + } + + return $tmp; + } + } + + if (!function_exists('dropdown')) { + function dropdown($arr, $key, $keytext) + { + $tmp = array(); + foreach ($arr as $val) { + $id = $val[$key]; + $tmp[$id] = $val[$keytext]; + } + + return $tmp; + } + } + + if (!function_exists('mapTree')) { + /** * Assign high numeric IDs to a config item to force appending. + * * * @param array $array + * + * * @return array */ + function mapTree($dataset, $parent = 0) + { + $tree = array(); + foreach ($dataset as $id => $node) { + if ($node->parent_id != $parent) { + continue; + } + $node->children = mapTree($dataset, $node->id); + $tree[$id] = $node; + } + + return $tree; + } + } + if (!function_exists('prepareMenu')) { + function prepareMenu($tree, $level = 0) + { + $data = ' +
     TOTAL ".$val->listakun_name."".number_format($totaln, 0)."
           
    ".$this->allfunct->revDate($row->accounttrans_date)."Saldo".$this->allfunct->rupiah($debet)."".$this->allfunct->rupiah($kredit)."".$this->allfunct->rupiah($saldo)."
    ', - 'heading_row_start' => '', - 'heading_previous_cell' => '', - 'heading_title_cell' => '', - 'heading_next_cell' => '', - 'heading_row_end' => '', - 'week_row_start' => '', - 'week_day_cell' => '', - 'week_row_end' => '', - 'cal_row_start' => '', - 'cal_cell_start' => '', - 'cal_cell_end_today' => '', - 'cal_row_end' => '', - 'table_close' => '
    <<{heading}>>
    {week_day}
    ', - 'cal_cell_start_today' => '', - 'cal_cell_content' => '{day}', - 'cal_cell_content_today' => '{day}', - 'cal_cell_no_content' => '{day}', - 'cal_cell_no_content_today' => '{day}', - 'cal_cell_blank' => ' ', - 'cal_cell_end' => '
    ' - ); - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * used to display the calendar - * - * @access public - * @return void - */ - function parse_template() - { - $this->temp = $this->default_template(); - - if ($this->template == '') - { - return; - } - - $today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today'); - - foreach (array('table_open', 'table_close', 'heading_row_start', 'heading_previous_cell', 'heading_title_cell', 'heading_next_cell', 'heading_row_end', 'week_row_start', 'week_day_cell', 'week_row_end', 'cal_row_start', 'cal_cell_start', 'cal_cell_content', 'cal_cell_no_content', 'cal_cell_blank', 'cal_cell_end', 'cal_row_end', 'cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today') as $val) - { - if (preg_match("/\{".$val."\}(.*?)\{\/".$val."\}/si", $this->template, $match)) - { - $this->temp[$val] = $match['1']; - } - else - { - if (in_array($val, $today, TRUE)) - { - $this->temp[$val] = $this->temp[str_replace('_today', '', $val)]; - } - } - } - } - -} - -// END CI_Calendar class - -/* End of file Calendar.php */ -/* Location: ./system/libraries/Calendar.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Config.php b/bmt-system/libraries/Config.php deleted file mode 100755 index 027f6bf..0000000 --- a/bmt-system/libraries/Config.php +++ /dev/null @@ -1,244 +0,0 @@ -config =& get_config(); - log_message('debug', "Config Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Load Config File - * - * @access public - * @param string the config file name - * @return boolean if the file was loaded correctly - */ - function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); - - if (in_array($file, $this->is_loaded, TRUE)) - { - return TRUE; - } - - if ( ! file_exists(APPPATH.'config/'.$file.EXT)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('The configuration file '.$file.EXT.' does not exist.'); - } - - include(APPPATH.'config/'.$file.EXT); - - if ( ! isset($config) OR ! is_array($config)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); - } - - if ($use_sections === TRUE) - { - if (isset($this->config[$file])) - { - $this->config[$file] = array_merge($this->config[$file], $config); - } - else - { - $this->config[$file] = $config; - } - } - else - { - $this->config = array_merge($this->config, $config); - } - - $this->is_loaded[] = $file; - unset($config); - - log_message('debug', 'Config file loaded: config/'.$file.EXT); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a config file item - * - * - * @access public - * @param string the config item name - * @param string the index name - * @param bool - * @return string - */ - function item($item, $index = '') - { - if ($index == '') - { - if ( ! isset($this->config[$item])) - { - return FALSE; - } - - $pref = $this->config[$item]; - } - else - { - if ( ! isset($this->config[$index])) - { - return FALSE; - } - - if ( ! isset($this->config[$index][$item])) - { - return FALSE; - } - - $pref = $this->config[$index][$item]; - } - - return $pref; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a config file item - adds slash after item - * - * The second parameter allows a slash to be added to the end of - * the item, in the case of a path. - * - * @access public - * @param string the config item name - * @param bool - * @return string - */ - function slash_item($item) - { - if ( ! isset($this->config[$item])) - { - return FALSE; - } - - $pref = $this->config[$item]; - - if ($pref != '' && substr($pref, -1) != '/') - { - $pref .= '/'; - } - - return $pref; - } - - // -------------------------------------------------------------------- - - /** - * Site URL - * - * @access public - * @param string the URI string - * @return string - */ - function site_url($uri = '') - { - if (is_array($uri)) - { - $uri = implode('/', $uri); - } - - if ($uri == '') - { - return $this->slash_item('base_url').$this->item('index_page'); - } - else - { - $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; - } - } - - // -------------------------------------------------------------------- - - /** - * System URL - * - * @access public - * @return string - */ - function system_url() - { - $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); - return $this->slash_item('base_url').end($x).'/'; - } - - // -------------------------------------------------------------------- - - /** - * Set a config file item - * - * @access public - * @param string the config item key - * @param string the config item value - * @return void - */ - function set_item($item, $value) - { - $this->config[$item] = $value; - } - -} - -// END CI_Config class - -/* End of file Config.php */ -/* Location: ./system/libraries/Config.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Controller.php b/bmt-system/libraries/Controller.php deleted file mode 100755 index 5d9b80d..0000000 --- a/bmt-system/libraries/Controller.php +++ /dev/null @@ -1,127 +0,0 @@ -_ci_initialize(); - log_message('debug', "Controller Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize - * - * Assigns all the bases classes loaded by the front controller to - * variables in this class. Also calls the autoload routine. - * - * @access private - * @return void - */ - function _ci_initialize() - { - // Assign all the class objects that were instantiated by the - // front controller to local class variables so that CI can be - // run as one big super object. - $classes = array( - 'config' => 'Config', - 'input' => 'Input', - 'benchmark' => 'Benchmark', - 'uri' => 'URI', - 'output' => 'Output', - 'lang' => 'Language', - 'router' => 'Router' - ); - - foreach ($classes as $var => $class) - { - $this->$var =& load_class($class); - } - - // In PHP 5 the Loader class is run as a discreet - // class. In PHP 4 it extends the Controller - if (floor(phpversion()) >= 5) - { - $this->load =& load_class('Loader'); - $this->load->_ci_autoloader(); - } - else - { - $this->_ci_autoloader(); - - // sync up the objects since PHP4 was working from a copy - foreach (array_keys(get_object_vars($this)) as $attribute) - { - if (is_object($this->$attribute)) - { - $this->load->$attribute =& $this->$attribute; - } - } - } - } - - // -------------------------------------------------------------------- - - /** - * Run Scaffolding - * - * @access private - * @return void - */ - function _ci_scaffolding() - { - if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) - { - show_404('Scaffolding unavailable'); - } - - $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); - - require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); - $scaff = new Scaffolding($this->_ci_scaff_table); - $scaff->$method(); - } - - -} -// END _Controller class - -/* End of file Controller.php */ -/* Location: ./system/libraries/Controller.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Email.php b/bmt-system/libraries/Email.php deleted file mode 100755 index f863d41..0000000 --- a/bmt-system/libraries/Email.php +++ /dev/null @@ -1,2035 +0,0 @@ - 0) - { - $this->initialize($config); - } - else - { - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; - } - - log_message('debug', "Email Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - function initialize($config = array()) - { - $this->clear(); - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $method = 'set_'.$key; - - if (method_exists($this, $method)) - { - $this->$method($val); - } - else - { - $this->$key = $val; - } - } - } - - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Email Data - * - * @access public - * @return void - */ - function clear($clear_attachments = FALSE) - { - $this->_subject = ""; - $this->_body = ""; - $this->_finalbody = ""; - $this->_header_str = ""; - $this->_replyto_flag = FALSE; - $this->_recipients = array(); - $this->_headers = array(); - $this->_debug_msg = array(); - - $this->_set_header('User-Agent', $this->useragent); - $this->_set_header('Date', $this->_set_date()); - - if ($clear_attachments !== FALSE) - { - $this->_attach_name = array(); - $this->_attach_type = array(); - $this->_attach_disp = array(); - } - } - - // -------------------------------------------------------------------- - - /** - * Set FROM - * - * @access public - * @param string - * @param string - * @return void - */ - function from($from, $name = '') - { - if (preg_match( '/\<(.*)\>/', $from, $match)) - { - $from = $match['1']; - } - - if ($this->validate) - { - $this->validate_email($this->_str_to_array($from)); - } - - // prepare the display name - if ($name != '') - { - // only use Q encoding if there are characters that would require it - if ( ! preg_match('/[\200-\377]/', $name)) - { - // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes - $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"'; - } - else - { - $name = $this->_prep_q_encoding($name, TRUE); - } - } - - $this->_set_header('From', $name.' <'.$from.'>'); - $this->_set_header('Return-Path', '<'.$from.'>'); - } - - // -------------------------------------------------------------------- - - /** - * Set Reply-to - * - * @access public - * @param string - * @param string - * @return void - */ - function reply_to($replyto, $name = '') - { - if (preg_match( '/\<(.*)\>/', $replyto, $match)) - { - $replyto = $match['1']; - } - - if ($this->validate) - { - $this->validate_email($this->_str_to_array($replyto)); - } - - if ($name == '') - { - $name = $replyto; - } - - if (strncmp($name, '"', 1) != 0) - { - $name = '"'.$name.'"'; - } - - $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); - $this->_replyto_flag = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Recipients - * - * @access public - * @param string - * @return void - */ - function to($to) - { - $to = $this->_str_to_array($to); - $to = $this->clean_email($to); - - if ($this->validate) - { - $this->validate_email($to); - } - - if ($this->_get_protocol() != 'mail') - { - $this->_set_header('To', implode(", ", $to)); - } - - switch ($this->_get_protocol()) - { - case 'smtp' : $this->_recipients = $to; - break; - case 'sendmail' : $this->_recipients = implode(", ", $to); - break; - case 'mail' : $this->_recipients = implode(", ", $to); - break; - } - } - - // -------------------------------------------------------------------- - - /** - * Set CC - * - * @access public - * @param string - * @return void - */ - function cc($cc) - { - $cc = $this->_str_to_array($cc); - $cc = $this->clean_email($cc); - - if ($this->validate) - { - $this->validate_email($cc); - } - - $this->_set_header('Cc', implode(", ", $cc)); - - if ($this->_get_protocol() == "smtp") - { - $this->_cc_array = $cc; - } - } - - // -------------------------------------------------------------------- - - /** - * Set BCC - * - * @access public - * @param string - * @param string - * @return void - */ - function bcc($bcc, $limit = '') - { - if ($limit != '' && is_numeric($limit)) - { - $this->bcc_batch_mode = TRUE; - $this->bcc_batch_size = $limit; - } - - $bcc = $this->_str_to_array($bcc); - $bcc = $this->clean_email($bcc); - - if ($this->validate) - { - $this->validate_email($bcc); - } - - if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) - { - $this->_bcc_array = $bcc; - } - else - { - $this->_set_header('Bcc', implode(", ", $bcc)); - } - } - - // -------------------------------------------------------------------- - - /** - * Set Email Subject - * - * @access public - * @param string - * @return void - */ - function subject($subject) - { - $subject = $this->_prep_q_encoding($subject); - $this->_set_header('Subject', $subject); - } - - // -------------------------------------------------------------------- - - /** - * Set Body - * - * @access public - * @param string - * @return void - */ - function message($body) - { - $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); - } - - // -------------------------------------------------------------------- - - /** - * Assign file attachments - * - * @access public - * @param string - * @return void - */ - function attach($filename, $disposition = 'attachment') - { - $this->_attach_name[] = $filename; - $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters - } - - // -------------------------------------------------------------------- - - /** - * Add a Header Item - * - * @access private - * @param string - * @param string - * @return void - */ - function _set_header($header, $value) - { - $this->_headers[$header] = $value; - } - - // -------------------------------------------------------------------- - - /** - * Convert a String to an Array - * - * @access private - * @param string - * @return array - */ - function _str_to_array($email) - { - if ( ! is_array($email)) - { - if (strpos($email, ',') !== FALSE) - { - $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY); - } - else - { - $email = trim($email); - settype($email, "array"); - } - } - return $email; - } - - // -------------------------------------------------------------------- - - /** - * Set Multipart Value - * - * @access public - * @param string - * @return void - */ - function set_alt_message($str = '') - { - $this->alt_message = ($str == '') ? '' : $str; - } - - // -------------------------------------------------------------------- - - /** - * Set Mailtype - * - * @access public - * @param string - * @return void - */ - function set_mailtype($type = 'text') - { - $this->mailtype = ($type == 'html') ? 'html' : 'text'; - } - - // -------------------------------------------------------------------- - - /** - * Set Wordwrap - * - * @access public - * @param string - * @return void - */ - function set_wordwrap($wordwrap = TRUE) - { - $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Protocol - * - * @access public - * @param string - * @return void - */ - function set_protocol($protocol = 'mail') - { - $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); - } - - // -------------------------------------------------------------------- - - /** - * Set Priority - * - * @access public - * @param integer - * @return void - */ - function set_priority($n = 3) - { - if ( ! is_numeric($n)) - { - $this->priority = 3; - return; - } - - if ($n < 1 OR $n > 5) - { - $this->priority = 3; - return; - } - - $this->priority = $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Newline Character - * - * @access public - * @param string - * @return void - */ - function set_newline($newline = "\n") - { - if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") - { - $this->newline = "\n"; - return; - } - - $this->newline = $newline; - } - - // -------------------------------------------------------------------- - - /** - * Set CRLF - * - * @access public - * @param string - * @return void - */ - function set_crlf($crlf = "\n") - { - if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r") - { - $this->crlf = "\n"; - return; - } - - $this->crlf = $crlf; - } - - // -------------------------------------------------------------------- - - /** - * Set Message Boundary - * - * @access private - * @return void - */ - function _set_boundaries() - { - $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative - $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary - } - - // -------------------------------------------------------------------- - - /** - * Get the Message ID - * - * @access private - * @return string - */ - function _get_message_id() - { - $from = $this->_headers['Return-Path']; - $from = str_replace(">", "", $from); - $from = str_replace("<", "", $from); - - return "<".uniqid('').strstr($from, '@').">"; - } - - // -------------------------------------------------------------------- - - /** - * Get Mail Protocol - * - * @access private - * @param bool - * @return string - */ - function _get_protocol($return = TRUE) - { - $this->protocol = strtolower($this->protocol); - $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; - - if ($return == TRUE) - { - return $this->protocol; - } - } - - // -------------------------------------------------------------------- - - /** - * Get Mail Encoding - * - * @access private - * @param bool - * @return string - */ - function _get_encoding($return = TRUE) - { - $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; - - foreach ($this->_base_charsets as $charset) - { - if (strncmp($charset, $this->charset, strlen($charset)) == 0) - { - $this->_encoding = '7bit'; - } - } - - if ($return == TRUE) - { - return $this->_encoding; - } - } - - // -------------------------------------------------------------------- - - /** - * Get content type (text/html/attachment) - * - * @access private - * @return string - */ - function _get_content_type() - { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) - { - return 'html'; - } - elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) - { - return 'html-attach'; - } - elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) - { - return 'plain-attach'; - } - else - { - return 'plain'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set RFC 822 Date - * - * @access private - * @return string - */ - function _set_date() - { - $timezone = date("Z"); - $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; - $timezone = abs($timezone); - $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; - - return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); - } - - // -------------------------------------------------------------------- - - /** - * Mime message - * - * @access private - * @return string - */ - function _get_mime_message() - { - return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; - } - - // -------------------------------------------------------------------- - - /** - * Validate Email Address - * - * @access public - * @param string - * @return bool - */ - function validate_email($email) - { - if ( ! is_array($email)) - { - $this->_set_error_message('email_must_be_array'); - return FALSE; - } - - foreach ($email as $val) - { - if ( ! $this->valid_email($val)) - { - $this->_set_error_message('email_invalid_address', $val); - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Email Validation - * - * @access public - * @param string - * @return bool - */ - function valid_email($address) - { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Clean Extended Email Address: Joe Smith - * - * @access public - * @param string - * @return string - */ - function clean_email($email) - { - if ( ! is_array($email)) - { - if (preg_match('/\<(.*)\>/', $email, $match)) - { - return $match['1']; - } - else - { - return $email; - } - } - - $clean_email = array(); - - foreach ($email as $addy) - { - if (preg_match( '/\<(.*)\>/', $addy, $match)) - { - $clean_email[] = $match['1']; - } - else - { - $clean_email[] = $addy; - } - } - - return $clean_email; - } - - // -------------------------------------------------------------------- - - /** - * Build alternative plain text message - * - * This function provides the raw message for use - * in plain-text headers of HTML-formatted emails. - * If the user hasn't specified his own alternative message - * it creates one by stripping the HTML - * - * @access private - * @return string - */ - function _get_alt_message() - { - if ($this->alt_message != "") - { - return $this->word_wrap($this->alt_message, '76'); - } - - if (preg_match('/\(.*)\<\/body\>/si', $this->_body, $match)) - { - $body = $match['1']; - } - else - { - $body = $this->_body; - } - - $body = trim(strip_tags($body)); - $body = preg_replace( '# '.$message. ' '.$filepath.' '.$line, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * 404 Page Not Found Handler - * - * @access private - * @param string - * @return string - */ - function show_404($page = '') - { - $heading = "404 Page Not Found"; - $message = "The page you requested was not found."; - - log_message('error', '404 Page Not Found --> '.$page); - echo $this->show_error($heading, $message, 'error_404'); - exit; - } - - // -------------------------------------------------------------------- - - /** - * General Error Page - * - * This function takes an error message as input - * (either as a string or an array) and displays - * it using the specified template. - * - * @access private - * @param string the heading - * @param string the message - * @param string the template name - * @return string - */ - function show_error($heading, $message, $template = 'error_general') - { - $message = '

    '.implode('

    ', ( ! is_array($message)) ? array($message) : $message).'

    '; - - if (ob_get_level() > $this->ob_level + 1) - { - ob_end_flush(); - } - ob_start(); - include(APPPATH.'errors/'.$template.EXT); - $buffer = ob_get_contents(); - ob_end_clean(); - return $buffer; - } - - // -------------------------------------------------------------------- - - /** - * Native PHP error handler - * - * @access private - * @param string the error severity - * @param string the error string - * @param string the error filepath - * @param string the error line number - * @return string - */ - function show_php_error($severity, $message, $filepath, $line) - { - $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; - - $filepath = str_replace("\\", "/", $filepath); - - // For safety reasons we do not show the full file path - if (FALSE !== strpos($filepath, '/')) - { - $x = explode('/', $filepath); - $filepath = $x[count($x)-2].'/'.end($x); - } - - if (ob_get_level() > $this->ob_level + 1) - { - ob_end_flush(); - } - ob_start(); - include(APPPATH.'errors/error_php'.EXT); - $buffer = ob_get_contents(); - ob_end_clean(); - echo $buffer; - } - - -} -// END Exceptions Class - -/* End of file Exceptions.php */ -/* Location: ./system/libraries/Exceptions.php */ diff --git a/bmt-system/libraries/Form_validation.php b/bmt-system/libraries/Form_validation.php deleted file mode 100755 index 0917532..0000000 --- a/bmt-system/libraries/Form_validation.php +++ /dev/null @@ -1,1278 +0,0 @@ -'; - var $_error_suffix = '

    '; - var $error_string = ''; - var $_safe_form_data = FALSE; - - - /** - * Constructor - * - */ - function CI_Form_validation($rules = array()) - { - $this->CI =& get_instance(); - - // Validation rules can be stored in a config file. - $this->_config_rules = $rules; - - // Automatically load the form helper - $this->CI->load->helper('form'); - - // Set the character encoding in MB. - if (function_exists('mb_internal_encoding')) - { - mb_internal_encoding($this->CI->config->item('charset')); - } - - log_message('debug', "Form Validation Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set Rules - * - * This function takes an array of field names and validation - * rules as input, validates the info, and stores it - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_rules($field, $label = '', $rules = '') - { - // No reason to set rules if we have no POST data - if (count($_POST) == 0) - { - return; - } - - // If an array was passed via the first parameter instead of indidual string - // values we cycle through it and recursively call this function. - if (is_array($field)) - { - foreach ($field as $row) - { - // Houston, we have a problem... - if ( ! isset($row['field']) OR ! isset($row['rules'])) - { - continue; - } - - // If the field label wasn't passed we use the field name - $label = ( ! isset($row['label'])) ? $row['field'] : $row['label']; - - // Here we go! - $this->set_rules($row['field'], $label, $row['rules']); - } - return; - } - - // No fields? Nothing to do... - if ( ! is_string($field) OR ! is_string($rules) OR $field == '') - { - return; - } - - // If the field label wasn't passed we use the field name - $label = ($label == '') ? $field : $label; - - // Is the field name an array? We test for the existence of a bracket "[" in - // the field name to determine this. If it is an array, we break it apart - // into its components so that we can fetch the corresponding POST data later - if (strpos($field, '[') !== FALSE AND preg_match_all('/\[(.*?)\]/', $field, $matches)) - { - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $x = explode('[', $field); - $indexes[] = current($x); - - for ($i = 0; $i < count($matches['0']); $i++) - { - if ($matches['1'][$i] != '') - { - $indexes[] = $matches['1'][$i]; - } - } - - $is_array = TRUE; - } - else - { - $indexes = array(); - $is_array = FALSE; - } - - // Build our master array - $this->_field_data[$field] = array( - 'field' => $field, - 'label' => $label, - 'rules' => $rules, - 'is_array' => $is_array, - 'keys' => $indexes, - 'postdata' => NULL, - 'error' => '' - ); - } - - // -------------------------------------------------------------------- - - /** - * Set Error Message - * - * Lets users set their own error messages on the fly. Note: The key - * name has to match the function name that it corresponds to. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_message($lang, $val = '') - { - if ( ! is_array($lang)) - { - $lang = array($lang => $val); - } - - $this->_error_messages = array_merge($this->_error_messages, $lang); - } - - // -------------------------------------------------------------------- - - /** - * Set The Error Delimiter - * - * Permits a prefix/suffix to be added to each error message - * - * @access public - * @param string - * @param string - * @return void - */ - function set_error_delimiters($prefix = '

    ', $suffix = '

    ') - { - $this->_error_prefix = $prefix; - $this->_error_suffix = $suffix; - } - - // -------------------------------------------------------------------- - - /** - * Get Error Message - * - * Gets the error message associated with a particular field - * - * @access public - * @param string the field name - * @return void - */ - function error($field = '', $prefix = '', $suffix = '') - { - if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '') - { - return ''; - } - - if ($prefix == '') - { - $prefix = $this->_error_prefix; - } - - if ($suffix == '') - { - $suffix = $this->_error_suffix; - } - - return $prefix.$this->_field_data[$field]['error'].$suffix; - } - - // -------------------------------------------------------------------- - - /** - * Error String - * - * Returns the error messages as a string, wrapped in the error delimiters - * - * @access public - * @param string - * @param string - * @return str - */ - function error_string($prefix = '', $suffix = '') - { - // No errrors, validation passes! - if (count($this->_error_array) === 0) - { - return ''; - } - - if ($prefix == '') - { - $prefix = $this->_error_prefix; - } - - if ($suffix == '') - { - $suffix = $this->_error_suffix; - } - - // Generate the error string - $str = ''; - foreach ($this->_error_array as $val) - { - if ($val != '') - { - $str .= $prefix.$val.$suffix."\n"; - } - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Run the Validator - * - * This function does all the work. - * - * @access public - * @return bool - */ - function run($group = '') - { - // Do we even have any data to process? Mm? - if (count($_POST) == 0) - { - return FALSE; - } - - // Does the _field_data array containing the validation rules exist? - // If not, we look to see if they were assigned via a config file - if (count($this->_field_data) == 0) - { - // No validation rules? We're done... - if (count($this->_config_rules) == 0) - { - return FALSE; - } - - // Is there a validation rule for the particular URI being accessed? - $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group; - - if ($uri != '' AND isset($this->_config_rules[$uri])) - { - $this->set_rules($this->_config_rules[$uri]); - } - else - { - $this->set_rules($this->_config_rules); - } - - // We're we able to set the rules correctly? - if (count($this->_field_data) == 0) - { - log_message('debug', "Unable to find validation rules"); - return FALSE; - } - } - - // Load the language file containing error messages - $this->CI->lang->load('form_validation'); - - // Cycle through the rules for each field, match the - // corresponding $_POST item and test for errors - foreach ($this->_field_data as $field => $row) - { - // Fetch the data from the corresponding $_POST array and cache it in the _field_data array. - // Depending on whether the field name is an array or a string will determine where we get it from. - - if ($row['is_array'] == TRUE) - { - $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']); - } - else - { - if (isset($_POST[$field]) AND $_POST[$field] != "") - { - $this->_field_data[$field]['postdata'] = $_POST[$field]; - } - } - - $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); - } - - // Did we end up with any errors? - $total_errors = count($this->_error_array); - - if ($total_errors > 0) - { - $this->_safe_form_data = TRUE; - } - - // Now we need to re-set the POST data with the new, processed data - $this->_reset_post_array(); - - // No errors, validation passes! - if ($total_errors == 0) - { - return TRUE; - } - - // Validation fails - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Traverse a multidimensional $_POST array index until the data is found - * - * @access private - * @param array - * @param array - * @param integer - * @return mixed - */ - function _reduce_array($array, $keys, $i = 0) - { - if (is_array($array)) - { - if (isset($keys[$i])) - { - if (isset($array[$keys[$i]])) - { - $array = $this->_reduce_array($array[$keys[$i]], $keys, ($i+1)); - } - else - { - return NULL; - } - } - else - { - return $array; - } - } - - return $array; - } - - // -------------------------------------------------------------------- - - /** - * Re-populate the _POST array with our finalized and processed data - * - * @access private - * @return null - */ - function _reset_post_array() - { - foreach ($this->_field_data as $field => $row) - { - if ( ! is_null($row['postdata'])) - { - if ($row['is_array'] == FALSE) - { - if (isset($_POST[$row['field']])) - { - $_POST[$row['field']] = $this->prep_for_form($row['postdata']); - } - } - else - { - // start with a reference - $post_ref =& $_POST; - - // before we assign values, make a reference to the right POST key - if (count($row['keys']) == 1) - { - $post_ref =& $post_ref[current($row['keys'])]; - } - else - { - foreach ($row['keys'] as $val) - { - $post_ref =& $post_ref[$val]; - } - } - - if (is_array($row['postdata'])) - { - $array = array(); - foreach ($row['postdata'] as $k => $v) - { - $array[$k] = $this->prep_for_form($v); - } - - $post_ref = $array; - } - else - { - $post_ref = $this->prep_for_form($row['postdata']); - } - } - } - } - } - - // -------------------------------------------------------------------- - - /** - * Executes the Validation routines - * - * @access private - * @param array - * @param array - * @param mixed - * @param integer - * @return mixed - */ - function _execute($row, $rules, $postdata = NULL, $cycles = 0) - { - // If the $_POST data is an array we will run a recursive call - if (is_array($postdata)) - { - foreach ($postdata as $key => $val) - { - $this->_execute($row, $rules, $val, $cycles); - $cycles++; - } - - return; - } - - // -------------------------------------------------------------------- - - // If the field is blank, but NOT required, no further tests are necessary - $callback = FALSE; - if ( ! in_array('required', $rules) AND is_null($postdata)) - { - // Before we bail out, does the rule contain a callback? - if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match)) - { - $callback = TRUE; - $rules = (array('1' => $match[1])); - } - else - { - return; - } - } - - // -------------------------------------------------------------------- - - // Isset Test. Typically this rule will only apply to checkboxes. - if (is_null($postdata) AND $callback == FALSE) - { - if (in_array('isset', $rules, TRUE) OR in_array('required', $rules)) - { - // Set the message type - $type = (in_array('required', $rules)) ? 'required' : 'isset'; - - if ( ! isset($this->_error_messages[$type])) - { - if (FALSE === ($line = $this->CI->lang->line($type))) - { - $line = 'The field was not set'; - } - } - else - { - $line = $this->_error_messages[$type]; - } - - // Build the error message - $message = sprintf($line, $this->_translate_fieldname($row['label'])); - - // Save the error message - $this->_field_data[$row['field']]['error'] = $message; - - if ( ! isset($this->_error_array[$row['field']])) - { - $this->_error_array[$row['field']] = $message; - } - } - - return; - } - - // -------------------------------------------------------------------- - - // Cycle through each rule and run it - foreach ($rules As $rule) - { - $_in_array = FALSE; - - // We set the $postdata variable with the current data in our master array so that - // each cycle of the loop is dealing with the processed data from the last cycle - if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata'])) - { - // We shouldn't need this safety, but just in case there isn't an array index - // associated with this cycle we'll bail out - if ( ! isset($this->_field_data[$row['field']]['postdata'][$cycles])) - { - continue; - } - - $postdata = $this->_field_data[$row['field']]['postdata'][$cycles]; - $_in_array = TRUE; - } - else - { - $postdata = $this->_field_data[$row['field']]['postdata']; - } - - // -------------------------------------------------------------------- - - // Is the rule a callback? - $callback = FALSE; - if (substr($rule, 0, 9) == 'callback_') - { - $rule = substr($rule, 9); - $callback = TRUE; - } - - // Strip the parameter (if exists) from the rule - // Rules can contain a parameter: max_length[5] - $param = FALSE; - if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) - { - $rule = $match[1]; - $param = $match[2]; - } - - // Call the function that corresponds to the rule - if ($callback === TRUE) - { - if ( ! method_exists($this->CI, $rule)) - { - continue; - } - - // Run the function and grab the result - $result = $this->CI->$rule($postdata, $param); - - // Re-assign the result to the master data array - if ($_in_array == TRUE) - { - $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; - } - else - { - $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; - } - - // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE) - { - return; - } - } - else - { - if ( ! method_exists($this, $rule)) - { - // If our own wrapper function doesn't exist we see if a native PHP function does. - // Users can use any native PHP function call that has one param. - if (function_exists($rule)) - { - $result = $rule($postdata); - - if ($_in_array == TRUE) - { - $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; - } - else - { - $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; - } - } - - continue; - } - - $result = $this->$rule($postdata, $param); - - if ($_in_array == TRUE) - { - $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; - } - else - { - $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; - } - } - - // Did the rule test negatively? If so, grab the error. - if ($result === FALSE) - { - if ( ! isset($this->_error_messages[$rule])) - { - if (FALSE === ($line = $this->CI->lang->line($rule))) - { - $line = 'Unable to access an error message corresponding to your field name.'; - } - } - else - { - $line = $this->_error_messages[$rule]; - } - - // Is the parameter we are inserting into the error message the name - // of another field? If so we need to grab its "field label" - if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label'])) - { - $param = $this->_field_data[$param]['label']; - } - - // Build the error message - $message = sprintf($line, $this->_translate_fieldname($row['label']), $param); - - // Save the error message - $this->_field_data[$row['field']]['error'] = $message; - - if ( ! isset($this->_error_array[$row['field']])) - { - $this->_error_array[$row['field']] = $message; - } - - return; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Translate a field name - * - * @access private - * @param string the field name - * @return string - */ - function _translate_fieldname($fieldname) - { - // Do we need to translate the field name? - // We look for the prefix lang: to determine this - if (substr($fieldname, 0, 5) == 'lang:') - { - // Grab the variable - $line = substr($fieldname, 5); - - // Were we able to translate the field name? If not we use $line - if (FALSE === ($fieldname = $this->CI->lang->line($line))) - { - return $line; - } - } - - return $fieldname; - } - - // -------------------------------------------------------------------- - - /** - * Get the value from a form - * - * Permits you to repopulate a form field with the value it was submitted - * with, or, if that value doesn't exist, with the default - * - * @access public - * @param string the field name - * @param string - * @return void - */ - function set_value($field = '', $default = '') - { - if ( ! isset($this->_field_data[$field])) - { - return $default; - } - - return $this->_field_data[$field]['postdata']; - } - - // -------------------------------------------------------------------- - - /** - * Set Select - * - * Enables pull-down lists to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_select($field = '', $value = '', $default = FALSE) - { - if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) - { - if ($default === TRUE AND count($this->_field_data) === 0) - { - return ' selected="selected"'; - } - return ''; - } - - $field = $this->_field_data[$field]['postdata']; - - if (is_array($field)) - { - if ( ! in_array($value, $field)) - { - return ''; - } - } - else - { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } - } - - return ' selected="selected"'; - } - - // -------------------------------------------------------------------- - - /** - * Set Radio - * - * Enables radio buttons to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_radio($field = '', $value = '', $default = FALSE) - { - if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) - { - if ($default === TRUE AND count($this->_field_data) === 0) - { - return ' checked="checked"'; - } - return ''; - } - - $field = $this->_field_data[$field]['postdata']; - - if (is_array($field)) - { - if ( ! in_array($value, $field)) - { - return ''; - } - } - else - { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } - } - - return ' checked="checked"'; - } - - // -------------------------------------------------------------------- - - /** - * Set Checkbox - * - * Enables checkboxes to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_checkbox($field = '', $value = '', $default = FALSE) - { - if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) - { - if ($default === TRUE AND count($this->_field_data) === 0) - { - return ' checked="checked"'; - } - return ''; - } - - $field = $this->_field_data[$field]['postdata']; - - if (is_array($field)) - { - if ( ! in_array($value, $field)) - { - return ''; - } - } - else - { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } - } - - return ' checked="checked"'; - } - - // -------------------------------------------------------------------- - - /** - * Required - * - * @access public - * @param string - * @return bool - */ - function required($str) - { - if ( ! is_array($str)) - { - return (trim($str) == '') ? FALSE : TRUE; - } - else - { - return ( ! empty($str)); - } - } - - // -------------------------------------------------------------------- - - /** - * Match one field to another - * - * @access public - * @param string - * @param field - * @return bool - */ - function matches($str, $field) - { - if ( ! isset($_POST[$field])) - { - return FALSE; - } - - $field = $_POST[$field]; - - return ($str !== $field) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Minimum Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function min_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) < $val) ? FALSE : TRUE; - } - - return (strlen($str) < $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Max Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function max_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) > $val) ? FALSE : TRUE; - } - - return (strlen($str) > $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Exact Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function exact_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) != $val) ? FALSE : TRUE; - } - - return (strlen($str) != $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Email - * - * @access public - * @param string - * @return bool - */ - function valid_email($str) - { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Emails - * - * @access public - * @param string - * @return bool - */ - function valid_emails($str) - { - if (strpos($str, ',') === FALSE) - { - return $this->valid_email(trim($str)); - } - - foreach(explode(',', $str) as $email) - { - if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * @access public - * @param string - * @return string - */ - function valid_ip($ip) - { - return $this->CI->input->valid_ip($ip); - } - - // -------------------------------------------------------------------- - - /** - * Alpha - * - * @access public - * @param string - * @return bool - */ - function alpha($str) - { - return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric - * - * @access public - * @param string - * @return bool - */ - function alpha_numeric($str) - { - return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric with underscores and dashes - * - * @access public - * @param string - * @return bool - */ - function alpha_dash($str) - { - return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Numeric - * - * @access public - * @param string - * @return bool - */ - function numeric($str) - { - return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); - - } - - // -------------------------------------------------------------------- - - /** - * Is Numeric - * - * @access public - * @param string - * @return bool - */ - function is_numeric($str) - { - return ( ! is_numeric($str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Integer - * - * @access public - * @param string - * @return bool - */ - function integer($str) - { - return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Is a Natural number (0,1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural($str) - { - return (bool)preg_match( '/^[0-9]+$/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Is a Natural number, but not a zero (1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural_no_zero($str) - { - if ( ! preg_match( '/^[0-9]+$/', $str)) - { - return FALSE; - } - - if ($str == 0) - { - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Base64 - * - * Tests a string for characters outside of the Base64 alphabet - * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 - * - * @access public - * @param string - * @return bool - */ - function valid_base64($str) - { - return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Prep data for form - * - * This function allows HTML to be safely shown in a form. - * Special characters are converted. - * - * @access public - * @param string - * @return string - */ - function prep_for_form($data = '') - { - if (is_array($data)) - { - foreach ($data as $key => $val) - { - $data[$key] = $this->prep_for_form($val); - } - - return $data; - } - - if ($this->_safe_form_data == FALSE OR $data === '') - { - return $data; - } - - return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); - } - - // -------------------------------------------------------------------- - - /** - * Prep URL - * - * @access public - * @param string - * @return string - */ - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - return ''; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ - function strip_image_tags($str) - { - return $this->CI->input->strip_image_tags($str); - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * @access public - * @param string - * @return string - */ - function xss_clean($str) - { - return $this->CI->input->xss_clean($str); - } - - // -------------------------------------------------------------------- - - /** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ - function encode_php_tags($str) - { - return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); - } - -} -// END Form Validation Class - -/* End of file Form_validation.php */ -/* Location: ./system/libraries/Form_validation.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Ftp.php b/bmt-system/libraries/Ftp.php deleted file mode 100755 index ec84eb0..0000000 --- a/bmt-system/libraries/Ftp.php +++ /dev/null @@ -1,618 +0,0 @@ - 0) - { - $this->initialize($config); - } - - log_message('debug', "FTP Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - function initialize($config = array()) - { - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - - // Prep the hostname - $this->hostname = preg_replace('|.+?://|', '', $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * FTP Connect - * - * @access public - * @param array the connection values - * @return bool - */ - function connect($config = array()) - { - if (count($config) > 0) - { - $this->initialize($config); - } - - if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port))) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_connect'); - } - return FALSE; - } - - if ( ! $this->_login()) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_login'); - } - return FALSE; - } - - // Set passive mode if needed - if ($this->passive == TRUE) - { - ftp_pasv($this->conn_id, TRUE); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * FTP Login - * - * @access private - * @return bool - */ - function _login() - { - return @ftp_login($this->conn_id, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Validates the connection ID - * - * @access private - * @return bool - */ - function _is_conn() - { - if ( ! is_resource($this->conn_id)) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_no_connection'); - } - return FALSE; - } - return TRUE; - } - - // -------------------------------------------------------------------- - - - /** - * Change direcotry - * - * The second parameter lets us momentarily turn off debugging so that - * this function can be used to test for the existance of a folder - * without throwing an error. There's no FTP equivalent to is_dir() - * so we do it by trying to change to a particular directory. - * Internally, this paramter is only used by the "mirror" function below. - * - * @access public - * @param string - * @param bool - * @return bool - */ - function changedir($path = '', $supress_debug = FALSE) - { - if ($path == '' OR ! $this->_is_conn()) - { - return FALSE; - } - - $result = @ftp_chdir($this->conn_id, $path); - - if ($result === FALSE) - { - if ($this->debug == TRUE AND $supress_debug == FALSE) - { - $this->_error('ftp_unable_to_changedir'); - } - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Create a directory - * - * @access public - * @param string - * @return bool - */ - function mkdir($path = '', $permissions = NULL) - { - if ($path == '' OR ! $this->_is_conn()) - { - return FALSE; - } - - $result = @ftp_mkdir($this->conn_id, $path); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_makdir'); - } - return FALSE; - } - - // Set file permissions if needed - if ( ! is_null($permissions)) - { - $this->chmod($path, (int)$permissions); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Upload a file to the server - * - * @access public - * @param string - * @param string - * @param string - * @return bool - */ - function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - if ( ! file_exists($locpath)) - { - $this->_error('ftp_no_source_file'); - return FALSE; - } - - // Set the mode if not specified - if ($mode == 'auto') - { - // Get the file extension so we can set the upload type - $ext = $this->_getext($locpath); - $mode = $this->_settype($ext); - } - - $mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY; - - $result = @ftp_put($this->conn_id, $rempath, $locpath, $mode); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_upload'); - } - return FALSE; - } - - // Set file permissions if needed - if ( ! is_null($permissions)) - { - $this->chmod($rempath, (int)$permissions); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rename (or move) a file - * - * @access public - * @param string - * @param string - * @param bool - * @return bool - */ - function rename($old_file, $new_file, $move = FALSE) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - $result = @ftp_rename($this->conn_id, $old_file, $new_file); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $msg = ($move == FALSE) ? 'ftp_unable_to_rename' : 'ftp_unable_to_move'; - - $this->_error($msg); - } - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Move a file - * - * @access public - * @param string - * @param string - * @return bool - */ - function move($old_file, $new_file) - { - return $this->rename($old_file, $new_file, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Rename (or move) a file - * - * @access public - * @param string - * @return bool - */ - function delete_file($filepath) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - $result = @ftp_delete($this->conn_id, $filepath); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_delete'); - } - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Delete a folder and recursively delete everything (including sub-folders) - * containted within it. - * - * @access public - * @param string - * @return bool - */ - function delete_dir($filepath) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - // Add a trailing slash to the file path if needed - $filepath = preg_replace("/(.+?)\/*$/", "\\1/", $filepath); - - $list = $this->list_files($filepath); - - if ($list !== FALSE AND count($list) > 0) - { - foreach ($list as $item) - { - // If we can't delete the item it's probaly a folder so - // we'll recursively call delete_dir() - if ( ! @ftp_delete($this->conn_id, $item)) - { - $this->delete_dir($item); - } - } - } - - $result = @ftp_rmdir($this->conn_id, $filepath); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_delete'); - } - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set file permissions - * - * @access public - * @param string the file path - * @param string the permissions - * @return bool - */ - function chmod($path, $perm) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - // Permissions can only be set when running PHP 5 - if ( ! function_exists('ftp_chmod')) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_chmod'); - } - return FALSE; - } - - $result = @ftp_chmod($this->conn_id, $perm, $path); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_chmod'); - } - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * FTP List files in the specified directory - * - * @access public - * @return array - */ - function list_files($path = '.') - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - return ftp_nlist($this->conn_id, $path); - } - - // ------------------------------------------------------------------------ - - /** - * Read a directory and recreate it remotely - * - * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure - * of the original file path will be recreated on the server. - * - * @access public - * @param string path to source with trailing slash - * @param string path to destination - include the base folder with trailing slash - * @return bool - */ - function mirror($locpath, $rempath) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - // Open the local file path - if ($fp = @opendir($locpath)) - { - // Attempt to open the remote file path. - if ( ! $this->changedir($rempath, TRUE)) - { - // If it doesn't exist we'll attempt to create the direcotory - if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)) - { - return FALSE; - } - } - - // Recursively read the local directory - while (FALSE !== ($file = readdir($fp))) - { - if (@is_dir($locpath.$file) && substr($file, 0, 1) != '.') - { - $this->mirror($locpath.$file."/", $rempath.$file."/"); - } - elseif (substr($file, 0, 1) != ".") - { - // Get the file extension so we can se the upload type - $ext = $this->_getext($file); - $mode = $this->_settype($ext); - - $this->upload($locpath.$file, $rempath.$file, $mode); - } - } - return TRUE; - } - - return FALSE; - } - - - // -------------------------------------------------------------------- - - /** - * Extract the file extension - * - * @access private - * @param string - * @return string - */ - function _getext($filename) - { - if (FALSE === strpos($filename, '.')) - { - return 'txt'; - } - - $x = explode('.', $filename); - return end($x); - } - - - // -------------------------------------------------------------------- - - /** - * Set the upload type - * - * @access private - * @param string - * @return string - */ - function _settype($ext) - { - $text_types = array( - 'txt', - 'text', - 'php', - 'phps', - 'php4', - 'js', - 'css', - 'htm', - 'html', - 'phtml', - 'shtml', - 'log', - 'xml' - ); - - - return (in_array($ext, $text_types)) ? 'ascii' : 'binary'; - } - - // ------------------------------------------------------------------------ - - /** - * Close the connection - * - * @access public - * @param string path to source - * @param string path to destination - * @return bool - */ - function close() - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - @ftp_close($this->conn_id); - } - - // ------------------------------------------------------------------------ - - /** - * Display error message - * - * @access private - * @param string - * @return bool - */ - function _error($line) - { - $CI =& get_instance(); - $CI->lang->load('ftp'); - show_error($CI->lang->line($line)); - } - - -} -// END FTP Class - -/* End of file Ftp.php */ -/* Location: ./system/libraries/Ftp.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Hooks.php b/bmt-system/libraries/Hooks.php deleted file mode 100755 index 46f3ac4..0000000 --- a/bmt-system/libraries/Hooks.php +++ /dev/null @@ -1,226 +0,0 @@ -_initialize(); - log_message('debug', "Hooks Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Hooks Preferences - * - * @access private - * @return void - */ - function _initialize() - { - $CFG =& load_class('Config'); - - // If hooks are not enabled in the config file - // there is nothing else to do - - if ($CFG->item('enable_hooks') == FALSE) - { - return; - } - - // Grab the "hooks" definition file. - // If there are no hooks, we're done. - - @include(APPPATH.'config/hooks'.EXT); - - if ( ! isset($hook) OR ! is_array($hook)) - { - return; - } - - $this->hooks =& $hook; - $this->enabled = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Call Hook - * - * Calls a particular hook - * - * @access private - * @param string the hook name - * @return mixed - */ - function _call_hook($which = '') - { - if ( ! $this->enabled OR ! isset($this->hooks[$which])) - { - return FALSE; - } - - if (isset($this->hooks[$which][0]) AND is_array($this->hooks[$which][0])) - { - foreach ($this->hooks[$which] as $val) - { - $this->_run_hook($val); - } - } - else - { - $this->_run_hook($this->hooks[$which]); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Run Hook - * - * Runs a particular hook - * - * @access private - * @param array the hook details - * @return bool - */ - function _run_hook($data) - { - if ( ! is_array($data)) - { - return FALSE; - } - - // ----------------------------------- - // Safety - Prevents run-away loops - // ----------------------------------- - - // If the script being called happens to have the same - // hook call within it a loop can happen - - if ($this->in_progress == TRUE) - { - return; - } - - // ----------------------------------- - // Set file path - // ----------------------------------- - - if ( ! isset($data['filepath']) OR ! isset($data['filename'])) - { - return FALSE; - } - - $filepath = APPPATH.$data['filepath'].'/'.$data['filename']; - - if ( ! file_exists($filepath)) - { - return FALSE; - } - - // ----------------------------------- - // Set class/function name - // ----------------------------------- - - $class = FALSE; - $function = FALSE; - $params = ''; - - if (isset($data['class']) AND $data['class'] != '') - { - $class = $data['class']; - } - - if (isset($data['function'])) - { - $function = $data['function']; - } - - if (isset($data['params'])) - { - $params = $data['params']; - } - - if ($class === FALSE AND $function === FALSE) - { - return FALSE; - } - - // ----------------------------------- - // Set the in_progress flag - // ----------------------------------- - - $this->in_progress = TRUE; - - // ----------------------------------- - // Call the requested class and/or function - // ----------------------------------- - - if ($class !== FALSE) - { - if ( ! class_exists($class)) - { - require($filepath); - } - - $HOOK = new $class; - $HOOK->$function($params); - } - else - { - if ( ! function_exists($function)) - { - require($filepath); - } - - $function($params); - } - - $this->in_progress = FALSE; - return TRUE; - } - -} - -// END CI_Hooks class - -/* End of file Hooks.php */ -/* Location: ./system/libraries/Hooks.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Image_lib.php b/bmt-system/libraries/Image_lib.php deleted file mode 100755 index 2896c9e..0000000 --- a/bmt-system/libraries/Image_lib.php +++ /dev/null @@ -1,1544 +0,0 @@ - 0) - { - $this->initialize($props); - } - - log_message('debug', "Image Lib Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize image properties - * - * Resets values in case this class is used in a loop - * - * @access public - * @return void - */ - function clear() - { - $props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity'); - - foreach ($props as $val) - { - $this->$val = ''; - } - - // special consideration for master_dim - $this->master_dim = 'auto'; - } - - // -------------------------------------------------------------------- - - /** - * initialize image preferences - * - * @access public - * @param array - * @return bool - */ - function initialize($props = array()) - { - /* - * Convert array elements into class variables - */ - if (count($props) > 0) - { - foreach ($props as $key => $val) - { - $this->$key = $val; - } - } - - /* - * Is there a source image? - * - * If not, there's no reason to continue - * - */ - if ($this->source_image == '') - { - $this->set_error('imglib_source_image_required'); - return FALSE; - } - - /* - * Is getimagesize() Available? - * - * We use it to determine the image properties (width/height). - * Note: We need to figure out how to determine image - * properties using ImageMagick and NetPBM - * - */ - if ( ! function_exists('getimagesize')) - { - $this->set_error('imglib_gd_required_for_props'); - return FALSE; - } - - $this->image_library = strtolower($this->image_library); - - /* - * Set the full server path - * - * The source image may or may not contain a path. - * Either way, we'll try use realpath to generate the - * full server path in order to more reliably read it. - * - */ - if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) - { - $full_source_path = str_replace("\\", "/", realpath($this->source_image)); - } - else - { - $full_source_path = $this->source_image; - } - - $x = explode('/', $full_source_path); - $this->source_image = end($x); - $this->source_folder = str_replace($this->source_image, '', $full_source_path); - - // Set the Image Properties - if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) - { - return FALSE; - } - - /* - * Assign the "new" image name/path - * - * If the user has set a "new_image" name it means - * we are making a copy of the source image. If not - * it means we are altering the original. We'll - * set the destination filename and path accordingly. - * - */ - if ($this->new_image == '') - { - $this->dest_image = $this->source_image; - $this->dest_folder = $this->source_folder; - } - else - { - if (strpos($this->new_image, '/') === FALSE) - { - $this->dest_folder = $this->source_folder; - $this->dest_image = $this->new_image; - } - else - { - if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) - { - $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); - } - else - { - $full_dest_path = $this->new_image; - } - - // Is there a file name? - if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path)) - { - $this->dest_folder = $full_dest_path.'/'; - $this->dest_image = $this->source_image; - } - else - { - $x = explode('/', $full_dest_path); - $this->dest_image = end($x); - $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); - } - } - } - - /* - * Compile the finalized filenames/paths - * - * We'll create two master strings containing the - * full server path to the source image and the - * full server path to the destination image. - * We'll also split the destination image name - * so we can insert the thumbnail marker if needed. - * - */ - if ($this->create_thumb === FALSE OR $this->thumb_marker == '') - { - $this->thumb_marker = ''; - } - - $xp = $this->explode_name($this->dest_image); - - $filename = $xp['name']; - $file_ext = $xp['ext']; - - $this->full_src_path = $this->source_folder.$this->source_image; - $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; - - /* - * Should we maintain image proportions? - * - * When creating thumbs or copies, the target width/height - * might not be in correct proportion with the source - * image's width/height. We'll recalculate it here. - * - */ - if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) - { - $this->image_reproportion(); - } - - /* - * Was a width and height specified? - * - * If the destination width/height was - * not submitted we will use the values - * from the actual file - * - */ - if ($this->width == '') - $this->width = $this->orig_width; - - if ($this->height == '') - $this->height = $this->orig_height; - - // Set the quality - $this->quality = trim(str_replace("%", "", $this->quality)); - - if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) - $this->quality = 90; - - // Set the x/y coordinates - $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; - $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; - - // Watermark-related Stuff... - if ($this->wm_font_color != '') - { - if (strlen($this->wm_font_color) == 6) - { - $this->wm_font_color = '#'.$this->wm_font_color; - } - } - - if ($this->wm_shadow_color != '') - { - if (strlen($this->wm_shadow_color) == 6) - { - $this->wm_shadow_color = '#'.$this->wm_shadow_color; - } - } - - if ($this->wm_overlay_path != '') - { - $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); - } - - if ($this->wm_shadow_color != '') - { - $this->wm_use_drop_shadow = TRUE; - } - - if ($this->wm_font_path != '') - { - $this->wm_use_truetype = TRUE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Resize - * - * This is a wrapper function that chooses the proper - * resize function based on the protocol specified - * - * @access public - * @return bool - */ - function resize() - { - $protocol = 'image_process_'.$this->image_library; - - if (eregi("gd2$", $protocol)) - { - $protocol = 'image_process_gd'; - } - - return $this->$protocol('resize'); - } - - // -------------------------------------------------------------------- - - /** - * Image Crop - * - * This is a wrapper function that chooses the proper - * cropping function based on the protocol specified - * - * @access public - * @return bool - */ - function crop() - { - $protocol = 'image_process_'.$this->image_library; - - if (eregi("gd2$", $protocol)) - { - $protocol = 'image_process_gd'; - } - - return $this->$protocol('crop'); - } - - // -------------------------------------------------------------------- - - /** - * Image Rotate - * - * This is a wrapper function that chooses the proper - * rotation function based on the protocol specified - * - * @access public - * @return bool - */ - function rotate() - { - // Allowed rotation values - $degs = array(90, 180, 270, 'vrt', 'hor'); - - if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) - { - $this->set_error('imglib_rotation_angle_required'); - return FALSE; - } - - // Reassign the width and height - if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) - { - $this->width = $this->orig_height; - $this->height = $this->orig_width; - } - else - { - $this->width = $this->orig_width; - $this->height = $this->orig_height; - } - - - // Choose resizing function - if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') - { - $protocol = 'image_process_'.$this->image_library; - - return $this->$protocol('rotate'); - } - - if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') - { - return $this->image_mirror_gd(); - } - else - { - return $this->image_rotate_gd(); - } - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using GD/GD2 - * - * This function will resize or crop - * - * @access public - * @param string - * @return bool - */ - function image_process_gd($action = 'resize') - { - $v2_override = FALSE; - - // If the target width/height match the source, AND if the new file name is not equal to the old file name - // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off. - if ($this->dynamic_output === FALSE) - { - if ($this->orig_width == $this->width AND $this->orig_height == $this->height) - { - if ($this->source_image != $this->new_image) - { - if (@copy($this->full_src_path, $this->full_dst_path)) - { - @chmod($this->full_dst_path, DIR_WRITE_MODE); - } - } - - return TRUE; - } - } - - // Let's set up our values based on the action - if ($action == 'crop') - { - // Reassign the source width/height if cropping - $this->orig_width = $this->width; - $this->orig_height = $this->height; - - // GD 2.0 has a cropping bug so we'll test for it - if ($this->gd_version() !== FALSE) - { - $gd_version = str_replace('0', '', $this->gd_version()); - $v2_override = ($gd_version == 2) ? TRUE : FALSE; - } - } - else - { - // If resizing the x/y axis must be zero - $this->x_axis = 0; - $this->y_axis = 0; - } - - // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - // Create The Image - // - // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" - // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment - // below should that ever prove inaccurate. - // - // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) - if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) - { - $create = 'imagecreatetruecolor'; - $copy = 'imagecopyresampled'; - } - else - { - $create = 'imagecreate'; - $copy = 'imagecopyresized'; - } - - $dst_img = $create($this->width, $this->height); - $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); - - // Show the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($dst_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($dst_img); - imagedestroy($src_img); - - // Set the file to 777 - @chmod($this->full_dst_path, DIR_WRITE_MODE); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using ImageMagick - * - * This function will resize, crop or rotate - * - * @access public - * @param string - * @return bool - */ - function image_process_imagemagick($action = 'resize') - { - // Do we have a vaild library path? - if ($this->library_path == '') - { - $this->set_error('imglib_libpath_invalid'); - return FALSE; - } - - if ( ! eregi("convert$", $this->library_path)) - { - if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; - - $this->library_path .= 'convert'; - } - - // Execute the command - $cmd = $this->library_path." -quality ".$this->quality; - - if ($action == 'crop') - { - $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - elseif ($action == 'rotate') - { - switch ($this->rotation_angle) - { - case 'hor' : $angle = '-flop'; - break; - case 'vrt' : $angle = '-flip'; - break; - default : $angle = '-rotate '.$this->rotation_angle; - break; - } - - $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - else // Resize - { - $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - - $retval = 1; - - @exec($cmd, $output, $retval); - - // Did it work? - if ($retval > 0) - { - $this->set_error('imglib_image_process_failed'); - return FALSE; - } - - // Set the file to 777 - @chmod($this->full_dst_path, DIR_WRITE_MODE); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using NetPBM - * - * This function will resize, crop or rotate - * - * @access public - * @param string - * @return bool - */ - function image_process_netpbm($action = 'resize') - { - if ($this->library_path == '') - { - $this->set_error('imglib_libpath_invalid'); - return FALSE; - } - - // Build the resizing command - switch ($this->image_type) - { - case 1 : - $cmd_in = 'giftopnm'; - $cmd_out = 'ppmtogif'; - break; - case 2 : - $cmd_in = 'jpegtopnm'; - $cmd_out = 'ppmtojpeg'; - break; - case 3 : - $cmd_in = 'pngtopnm'; - $cmd_out = 'ppmtopng'; - break; - } - - if ($action == 'crop') - { - $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; - } - elseif ($action == 'rotate') - { - switch ($this->rotation_angle) - { - case 90 : $angle = 'r270'; - break; - case 180 : $angle = 'r180'; - break; - case 270 : $angle = 'r90'; - break; - case 'vrt' : $angle = 'tb'; - break; - case 'hor' : $angle = 'lr'; - break; - } - - $cmd_inner = 'pnmflip -'.$angle.' '; - } - else // Resize - { - $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height; - } - - $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; - - $retval = 1; - - @exec($cmd, $output, $retval); - - // Did it work? - if ($retval > 0) - { - $this->set_error('imglib_image_process_failed'); - return FALSE; - } - - // With NetPBM we have to create a temporary image. - // If you try manipulating the original it fails so - // we have to rename the temp file. - copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); - unlink ($this->dest_folder.'netpbm.tmp'); - @chmod($this->full_dst_path, DIR_WRITE_MODE); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Rotate Using GD - * - * @access public - * @return bool - */ - function image_rotate_gd() - { - // Is Image Rotation Supported? - // this function is only supported as of PHP 4.3 - if ( ! function_exists('imagerotate')) - { - $this->set_error('imglib_rotate_unsupported'); - return FALSE; - } - - // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - // Set the background color - // This won't work with transparent PNG files so we are - // going to have to figure out how to determine the color - // of the alpha channel in a future release. - - $white = imagecolorallocate($src_img, 255, 255, 255); - - // Rotate it! - $dst_img = imagerotate($src_img, $this->rotation_angle, $white); - - // Save the Image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($dst_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($dst_img); - imagedestroy($src_img); - - // Set the file to 777 - - @chmod($this->full_dst_path, DIR_WRITE_MODE); - - return true; - } - - // -------------------------------------------------------------------- - - /** - * Create Mirror Image using GD - * - * This function will flip horizontal or vertical - * - * @access public - * @return bool - */ - function image_mirror_gd() - { - if ( ! $src_img = $this->image_create_gd()) - { - return FALSE; - } - - $width = $this->orig_width; - $height = $this->orig_height; - - if ($this->rotation_angle == 'hor') - { - for ($i = 0; $i < $height; $i++) - { - $left = 0; - $right = $width-1; - - while ($left < $right) - { - $cl = imagecolorat($src_img, $left, $i); - $cr = imagecolorat($src_img, $right, $i); - - imagesetpixel($src_img, $left, $i, $cr); - imagesetpixel($src_img, $right, $i, $cl); - - $left++; - $right--; - } - } - } - else - { - for ($i = 0; $i < $width; $i++) - { - $top = 0; - $bot = $height-1; - - while ($top < $bot) - { - $ct = imagecolorat($src_img, $i, $top); - $cb = imagecolorat($src_img, $i, $bot); - - imagesetpixel($src_img, $i, $top, $cb); - imagesetpixel($src_img, $i, $bot, $ct); - - $top++; - $bot--; - } - } - } - - // Show the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($src_img); - - // Set the file to 777 - @chmod($this->full_dst_path, DIR_WRITE_MODE); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Watermark - * - * This is a wrapper function that chooses the type - * of watermarking based on the specified preference. - * - * @access public - * @param string - * @return bool - */ - function watermark() - { - if ($this->wm_type == 'overlay') - { - return $this->overlay_watermark(); - } - else - { - return $this->text_watermark(); - } - } - - // -------------------------------------------------------------------- - - /** - * Watermark - Graphic Version - * - * @access public - * @return bool - */ - function overlay_watermark() - { - if ( ! function_exists('imagecolortransparent')) - { - $this->set_error('imglib_gd_required'); - return FALSE; - } - - // Fetch source image properties - $this->get_image_properties(); - - // Fetch watermark image properties - $props = $this->get_image_properties($this->wm_overlay_path, TRUE); - $wm_img_type = $props['image_type']; - $wm_width = $props['width']; - $wm_height = $props['height']; - - // Create two image resources - $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); - $src_img = $this->image_create_gd($this->full_src_path); - - // Reverse the offset if necessary - // When the image is positioned at the bottom - // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Same with the horizontal - // offset when the image is at the right - - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - - if ($this->wm_vrt_alignment == 'B') - $this->wm_vrt_offset = $this->wm_vrt_offset * -1; - - if ($this->wm_hor_alignment == 'R') - $this->wm_hor_offset = $this->wm_hor_offset * -1; - - // Set the base x and y axis values - $x_axis = $this->wm_hor_offset + $this->wm_padding; - $y_axis = $this->wm_vrt_offset + $this->wm_padding; - - // Set the vertical position - switch ($this->wm_vrt_alignment) - { - case 'T': - break; - case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); - break; - case 'B': $y_axis += $this->orig_height - $wm_height; - break; - } - - // Set the horizontal position - switch ($this->wm_hor_alignment) - { - case 'L': - break; - case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); - break; - case 'R': $x_axis += $this->orig_width - $wm_width; - break; - } - - // Build the finalized image - if ($wm_img_type == 3 AND function_exists('imagealphablending')) - { - @imagealphablending($src_img, TRUE); - } - - // Set RGB values for text and shadow - $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); - $alpha = ($rgba & 0x7F000000) >> 24; - - // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency - if ($alpha > 0) - { - // copy the image directly, the image's alpha transparency being the sole determinant of blending - imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height); - } - else - { - // set our RGB value from above to be transparent and merge the images with the specified opacity - imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); - imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); - } - - // Output the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } - } - - imagedestroy($src_img); - imagedestroy($wm_img); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Watermark - Text Version - * - * @access public - * @return bool - */ - function text_watermark() - { - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) - { - $this->set_error('imglib_missing_font'); - return FALSE; - } - - // Fetch source image properties - $this->get_image_properties(); - - // Set RGB values for text and shadow - $this->wm_font_color = str_replace('#', '', $this->wm_font_color); - $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); - - $R1 = hexdec(substr($this->wm_font_color, 0, 2)); - $G1 = hexdec(substr($this->wm_font_color, 2, 2)); - $B1 = hexdec(substr($this->wm_font_color, 4, 2)); - - $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); - $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); - $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); - - $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); - $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); - - // Reverse the vertical offset - // When the image is positioned at the bottom - // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Note: The horizontal - // offset flips itself automatically - - if ($this->wm_vrt_alignment == 'B') - $this->wm_vrt_offset = $this->wm_vrt_offset * -1; - - if ($this->wm_hor_alignment == 'R') - $this->wm_hor_offset = $this->wm_hor_offset * -1; - - // Set font width and height - // These are calculated differently depending on - // whether we are using the true type font or not - if ($this->wm_use_truetype == TRUE) - { - if ($this->wm_font_size == '') - $this->wm_font_size = '17'; - - $fontwidth = $this->wm_font_size-($this->wm_font_size/4); - $fontheight = $this->wm_font_size; - $this->wm_vrt_offset += $this->wm_font_size; - } - else - { - $fontwidth = imagefontwidth($this->wm_font_size); - $fontheight = imagefontheight($this->wm_font_size); - } - - // Set base X and Y axis values - $x_axis = $this->wm_hor_offset + $this->wm_padding; - $y_axis = $this->wm_vrt_offset + $this->wm_padding; - - // Set verticle alignment - if ($this->wm_use_drop_shadow == FALSE) - $this->wm_shadow_distance = 0; - - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - - switch ($this->wm_vrt_alignment) - { - case "T" : - break; - case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); - break; - case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); - break; - } - - $x_shad = $x_axis + $this->wm_shadow_distance; - $y_shad = $y_axis + $this->wm_shadow_distance; - - // Set horizontal alignment - switch ($this->wm_hor_alignment) - { - case "L": - break; - case "R": - if ($this->wm_use_drop_shadow) - $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - break; - case "C": - if ($this->wm_use_drop_shadow) - $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); - break; - } - - // Add the text to the source image - if ($this->wm_use_truetype) - { - if ($this->wm_use_drop_shadow) - imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); - imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); - } - else - { - if ($this->wm_use_drop_shadow) - imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); - imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); - } - - // Output the final image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - $this->image_save_gd($src_img); - } - - imagedestroy($src_img); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Create Image - GD - * - * This simply creates an image resource handle - * based on the type of image being processed - * - * @access public - * @param string - * @return resource - */ - function image_create_gd($path = '', $image_type = '') - { - if ($path == '') - $path = $this->full_src_path; - - if ($image_type == '') - $image_type = $this->image_type; - - - switch ($image_type) - { - case 1 : - if ( ! function_exists('imagecreatefromgif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } - - return imagecreatefromgif($path); - break; - case 2 : - if ( ! function_exists('imagecreatefromjpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } - - return imagecreatefromjpeg($path); - break; - case 3 : - if ( ! function_exists('imagecreatefrompng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } - - return imagecreatefrompng($path); - break; - - } - - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Write image file to disk - GD - * - * Takes an image resource as input and writes the file - * to the specified destination - * - * @access public - * @param resource - * @return bool - */ - function image_save_gd($resource) - { - switch ($this->image_type) - { - case 1 : - if ( ! function_exists('imagegif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } - - if ( ! @imagegif($resource, $this->full_dst_path)) - { - $this->set_error('imglib_save_failed'); - return FALSE; - } - break; - case 2 : - if ( ! function_exists('imagejpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } - - if (phpversion() == '4.4.1') - { - @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround - } - - if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality)) - { - $this->set_error('imglib_save_failed'); - return FALSE; - } - break; - case 3 : - if ( ! function_exists('imagepng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } - - if ( ! @imagepng($resource, $this->full_dst_path)) - { - $this->set_error('imglib_save_failed'); - return FALSE; - } - break; - default : - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; - break; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Dynamically outputs an image - * - * @access public - * @param resource - * @return void - */ - function image_display_gd($resource) - { - header("Content-Disposition: filename={$this->source_image};"); - header("Content-Type: {$this->mime_type}"); - header('Content-Transfer-Encoding: binary'); - header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); - - switch ($this->image_type) - { - case 1 : imagegif($resource); - break; - case 2 : imagejpeg($resource, '', $this->quality); - break; - case 3 : imagepng($resource); - break; - default : echo 'Unable to display the image'; - break; - } - } - - // -------------------------------------------------------------------- - - /** - * Re-proportion Image Width/Height - * - * When creating thumbs, the desired width/height - * can end up warping the image due to an incorrect - * ratio between the full-sized image and the thumb. - * - * This function lets us re-proportion the width/height - * if users choose to maintain the aspect ratio when resizing. - * - * @access public - * @return void - */ - function image_reproportion() - { - if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) - return; - - if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) - return; - - $new_width = ceil($this->orig_width*$this->height/$this->orig_height); - $new_height = ceil($this->width*$this->orig_height/$this->orig_width); - - $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); - - if ($this->master_dim != 'width' AND $this->master_dim != 'height') - { - $this->master_dim = ($ratio < 0) ? 'width' : 'height'; - } - - if (($this->width != $new_width) AND ($this->height != $new_height)) - { - if ($this->master_dim == 'height') - { - $this->width = $new_width; - } - else - { - $this->height = $new_height; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Get image properties - * - * A helper function that gets info about the file - * - * @access public - * @param string - * @return mixed - */ - function get_image_properties($path = '', $return = FALSE) - { - // For now we require GD but we should - // find a way to determine this using IM or NetPBM - - if ($path == '') - $path = $this->full_src_path; - - if ( ! file_exists($path)) - { - $this->set_error('imglib_invalid_path'); - return FALSE; - } - - $vals = @getimagesize($path); - - $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - - $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; - - if ($return == TRUE) - { - $v['width'] = $vals['0']; - $v['height'] = $vals['1']; - $v['image_type'] = $vals['2']; - $v['size_str'] = $vals['3']; - $v['mime_type'] = $mime; - - return $v; - } - - $this->orig_width = $vals['0']; - $this->orig_height = $vals['1']; - $this->image_type = $vals['2']; - $this->size_str = $vals['3']; - $this->mime_type = $mime; - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Size calculator - * - * This function takes a known width x height and - * recalculates it to a new size. Only one - * new variable needs to be known - * - * $props = array( - * 'width' => $width, - * 'height' => $height, - * 'new_width' => 40, - * 'new_height' => '' - * ); - * - * @access public - * @param array - * @return array - */ - function size_calculator($vals) - { - if ( ! is_array($vals)) - { - return; - } - - $allowed = array('new_width', 'new_height', 'width', 'height'); - - foreach ($allowed as $item) - { - if ( ! isset($vals[$item]) OR $vals[$item] == '') - $vals[$item] = 0; - } - - if ($vals['width'] == 0 OR $vals['height'] == 0) - { - return $vals; - } - - if ($vals['new_width'] == 0) - { - $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); - } - elseif ($vals['new_height'] == 0) - { - $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); - } - - return $vals; - } - - // -------------------------------------------------------------------- - - /** - * Explode source_image - * - * This is a helper function that extracts the extension - * from the source_image. This function lets us deal with - * source_images with multiple periods, like: my.cool.jpg - * It returns an associative array with two elements: - * $array['ext'] = '.jpg'; - * $array['name'] = 'my.cool'; - * - * @access public - * @param array - * @return array - */ - function explode_name($source_image) - { - $ext = strrchr($source_image, '.'); - $name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext)); - - return array('ext' => $ext, 'name' => $name); - } - - // -------------------------------------------------------------------- - - /** - * Is GD Installed? - * - * @access public - * @return bool - */ - function gd_loaded() - { - if ( ! extension_loaded('gd')) - { - if ( ! dl('gd.so')) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Get GD version - * - * @access public - * @return mixed - */ - function gd_version() - { - if (function_exists('gd_info')) - { - $gd_version = @gd_info(); - $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); - - return $gd_version; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - $CI =& get_instance(); - $CI->lang->load('imglib'); - - if (is_array($msg)) - { - foreach ($msg as $val) - { - - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - else - { - $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - - // -------------------------------------------------------------------- - - /** - * Show error messages - * - * @access public - * @param string - * @return string - */ - function display_errors($open = '

    ', $close = '

    ') - { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; - } - -} -// END Image_lib Class - -/* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Input.php b/bmt-system/libraries/Input.php deleted file mode 100755 index b6498f8..0000000 --- a/bmt-system/libraries/Input.php +++ /dev/null @@ -1,1067 +0,0 @@ - '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - 'window.location' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[' - ); - /* never allowed, regex replacement */ - var $never_allowed_regex = array( - "javascript\s*:" => '[removed]', - "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE - "vbscript\s*:" => '[removed]', // IE, surprise! - "Redirect\s+302" => '[removed]' - ); - - /** - * Constructor - * - * Sets whether to globally enable the XSS processing - * and whether to allow the $_GET array - * - * @access public - */ - function CI_Input() - { - log_message('debug', "Input Class Initialized"); - - $CFG =& load_class('Config'); - $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; - $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; - $this->_sanitize_globals(); - } - - // -------------------------------------------------------------------- - - /** - * Sanitize Globals - * - * This function does the following: - * - * Unsets $_GET data (if query strings are not enabled) - * - * Unsets all globals if register_globals is enabled - * - * Standardizes newline characters to \n - * - * @access private - * @return void - */ - function _sanitize_globals() - { - // Would kind of be "wrong" to unset any of these GLOBALS - $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA', - 'system_folder', 'application_folder', 'BM', 'EXT', 'CFG', 'URI', 'RTR', 'OUT', 'IN'); - - // Unset globals for security. - // This is effectively the same as register_globals = off - foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) - { - if ( ! is_array($global)) - { - if ( ! in_array($global, $protected)) - { - unset($GLOBALS[$global]); - } - } - else - { - foreach ($global as $key => $val) - { - if ( ! in_array($key, $protected)) - { - unset($GLOBALS[$key]); - } - - if (is_array($val)) - { - foreach($val as $k => $v) - { - if ( ! in_array($k, $protected)) - { - unset($GLOBALS[$k]); - } - } - } - } - } - } - - // Is $_GET data allowed? If not we'll set the $_GET to an empty array - if ($this->allow_get_array == FALSE) - { - $_GET = array(); - } - else - { - $_GET = $this->_clean_input_data($_GET); - } - - // Clean $_POST Data - $_POST = $this->_clean_input_data($_POST); - - // Clean $_COOKIE Data - // Also get rid of specially treated cookies that might be set by a server - // or silly application, that are of no use to a CI application anyway - // but that when present will trip our 'Disallowed Key Characters' alarm - // http://www.ietf.org/rfc/rfc2109.txt - // note that the key names below are single quoted strings, and are not PHP variables - unset($_COOKIE['$Version']); - unset($_COOKIE['$Path']); - unset($_COOKIE['$Domain']); - $_COOKIE = $this->_clean_input_data($_COOKIE); - - log_message('debug', "Global POST and COOKIE data sanitized"); - } - - // -------------------------------------------------------------------- - - /** - * Clean Input Data - * - * This is a helper function. It escapes data and - * standardizes newline characters to \n - * - * @access private - * @param string - * @return string - */ - function _clean_input_data($str) - { - if (is_array($str)) - { - $new_array = array(); - foreach ($str as $key => $val) - { - $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - return $new_array; - } - - // We strip slashes if magic quotes is on to keep things consistent - if (get_magic_quotes_gpc()) - { - $str = stripslashes($str); - } - - // Should we filter the input data? - if ($this->use_xss_clean === TRUE) - { - $str = $this->xss_clean($str); - } - - // Standardize newlines - if (strpos($str, "\r") !== FALSE) - { - $str = str_replace(array("\r\n", "\r"), "\n", $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Clean Keys - * - * This is a helper function. To prevent malicious users - * from trying to exploit keys we make sure that keys are - * only named with alpha-numeric text and a few other items. - * - * @access private - * @param string - * @return string - */ - function _clean_input_keys($str) - { - if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) - { - exit('Disallowed Key Characters.'); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Fetch from array - * - * This is a helper function to retrieve values from global arrays - * - * @access private - * @param array - * @param string - * @param bool - * @return string - */ - function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE) - { - if ( ! isset($array[$index])) - { - return FALSE; - } - - if ($xss_clean === TRUE) - { - return $this->xss_clean($array[$index]); - } - - return $array[$index]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the GET array - * - * @access public - * @param string - * @param bool - * @return string - */ - function get($index = '', $xss_clean = FALSE) - { - return $this->_fetch_from_array($_GET, $index, $xss_clean); - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the POST array - * - * @access public - * @param string - * @param bool - * @return string - */ - function post($index = '', $xss_clean = FALSE) - { - return $this->_fetch_from_array($_POST, $index, $xss_clean); - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from either the GET array or the POST - * - * @access public - * @param string The index key - * @param bool XSS cleaning - * @return string - */ - function get_post($index = '', $xss_clean = FALSE) - { - if ( ! isset($_POST[$index]) ) - { - return $this->get($index, $xss_clean); - } - else - { - return $this->post($index, $xss_clean); - } - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the COOKIE array - * - * @access public - * @param string - * @param bool - * @return string - */ - function cookie($index = '', $xss_clean = FALSE) - { - return $this->_fetch_from_array($_COOKIE, $index, $xss_clean); - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the SERVER array - * - * @access public - * @param string - * @param bool - * @return string - */ - function server($index = '', $xss_clean = FALSE) - { - return $this->_fetch_from_array($_SERVER, $index, $xss_clean); - } - - // -------------------------------------------------------------------- - - /** - * Fetch the IP Address - * - * @access public - * @return string - */ - function ip_address() - { - if ($this->ip_address !== FALSE) - { - return $this->ip_address; - } - - if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) - { - $proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY); - $proxies = is_array($proxies) ? $proxies : array($proxies); - - $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; - } - elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('REMOTE_ADDR')) - { - $this->ip_address = $_SERVER['REMOTE_ADDR']; - } - elseif ($this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('HTTP_X_FORWARDED_FOR')) - { - $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; - } - - if ($this->ip_address === FALSE) - { - $this->ip_address = '0.0.0.0'; - return $this->ip_address; - } - - if (strstr($this->ip_address, ',')) - { - $x = explode(',', $this->ip_address); - $this->ip_address = trim(end($x)); - } - - if ( ! $this->valid_ip($this->ip_address)) - { - $this->ip_address = '0.0.0.0'; - } - - return $this->ip_address; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * Updated version suggested by Geert De Deckere - * - * @access public - * @param string - * @return string - */ - function valid_ip($ip) - { - $ip_segments = explode('.', $ip); - - // Always 4 segments needed - if (count($ip_segments) != 4) - { - return FALSE; - } - // IP can not start with 0 - if ($ip_segments[0][0] == '0') - { - return FALSE; - } - // Check each segment - foreach ($ip_segments as $segment) - { - // IP segments must be digits and can not be - // longer than 3 digits or greater then 255 - if ($segment == '' OR preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * User Agent - * - * @access public - * @return string - */ - function user_agent() - { - if ($this->user_agent !== FALSE) - { - return $this->user_agent; - } - - $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; - - return $this->user_agent; - } - - // -------------------------------------------------------------------- - - /** - * Filename Security - * - * @access public - * @param string - * @return string - */ - function filename_security($str) - { - $bad = array( - "../", - "./", - "", - "<", - ">", - "'", - '"', - '&', - '$', - '#', - '{', - '}', - '[', - ']', - '=', - ';', - '?', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - return stripslashes(str_replace($bad, '', $str)); - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * Sanitizes data so that Cross Site Scripting Hacks can be - * prevented. This function does a fair amount of work but - * it is extremely thorough, designed to prevent even the - * most obscure XSS attempts. Nothing is ever 100% foolproof, - * of course, but I haven't been able to get anything passed - * the filter. - * - * Note: This function should only be used to deal with data - * upon submission. It's not something that should - * be used for general runtime processing. - * - * This function was based in part on some code and ideas I - * got from Bitflux: http://blog.bitflux.ch/wiki/XSS_Prevention - * - * To help develop this script I used this great list of - * vulnerabilities along with a few other hacks I've - * harvested from examining vulnerabilities in other programs: - * http://ha.ckers.org/xss.html - * - * @access public - * @param string - * @return string - */ - function xss_clean($str, $is_image = FALSE) - { - /* - * Is the string an array? - * - */ - if (is_array($str)) - { - while (list($key) = each($str)) - { - $str[$key] = $this->xss_clean($str[$key]); - } - - return $str; - } - - /* - * Remove Invisible Characters - */ - $str = $this->_remove_invisible_characters($str); - - /* - * Protect GET variables in URLs - */ - - // 901119URL5918AMP18930PROTECT8198 - - $str = preg_replace('|\&([a-z\_0-9]+)\=([a-z\_0-9]+)|i', $this->xss_hash()."\\1=\\2", $str); - - /* - * Validate standard character entities - * - * Add a semicolon if missing. We do this to enable - * the conversion of entities to ASCII later. - * - */ - $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); - - /* - * Validate UTF16 two byte encoding (x00) - * - * Just as above, adds a semicolon if missing. - * - */ - $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); - - /* - * Un-Protect GET variables in URLs - */ - $str = str_replace($this->xss_hash(), '&', $str); - - /* - * URL Decode - * - * Just in case stuff like this is submitted: - * - * Google - * - * Note: Use rawurldecode() so it does not remove plus signs - * - */ - $str = rawurldecode($str); - - /* - * Convert character entities to ASCII - * - * This permits our tests below to work reliably. - * We only convert entities that are within tags since - * these are the ones that will pose security problems. - * - */ - - $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - - $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_html_entity_decode_callback'), $str); - - /* - * Remove Invisible Characters Again! - */ - $str = $this->_remove_invisible_characters($str); - - /* - * Convert all tabs to spaces - * - * This prevents strings like this: ja vascript - * NOTE: we deal with spaces between characters later. - * NOTE: preg_replace was found to be amazingly slow here on large blocks of data, - * so we use str_replace. - * - */ - - if (strpos($str, "\t") !== FALSE) - { - $str = str_replace("\t", ' ', $str); - } - - /* - * Capture converted string for later comparison - */ - $converted_string = $str; - - /* - * Not Allowed Under Any Conditions - */ - - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - /* - * Makes PHP tags safe - * - * Note: XML tags are inadvertently replaced too: - * - * '), array('<?php', '<?PHP', '<?', '?>'), $str); - } - - /* - * Compact any exploded words - * - * This corrects words like: j a v a s c r i p t - * These words are compacted back to their correct state. - * - */ - $words = array('javascript', 'expression', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); - foreach ($words as $word) - { - $temp = ''; - - for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) - { - $temp .= substr($word, $i, 1)."\s*"; - } - - // We only want to do this when it is followed by a non-word character - // That way valid stuff like "dealer to" does not become "dealerto" - $str = preg_replace_callback('#('.substr($temp, 0, -3).')(\W)#is', array($this, '_compact_exploded_words'), $str); - } - - /* - * Remove disallowed Javascript in links or img tags - * We used to do some version comparisons and use of stripos for PHP5, but it is dog slow compared - * to these simplified non-capturing preg_match(), especially if the pattern exists in the string - */ - do - { - $original = $str; - - if (preg_match("/]*?)(>|$)#si", array($this, '_js_link_removal'), $str); - } - - if (preg_match("/]*?)(\s?/?>|$)#si", array($this, '_js_img_removal'), $str); - } - - if (preg_match("/script/i", $str) OR preg_match("/xss/i", $str)) - { - $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); - } - } - while($original != $str); - - unset($original); - - /* - * Remove JavaScript Event Handlers - * - * Note: This code is a little blunt. It removes - * the event handler and anything up to the closing >, - * but it's unlikely to be a problem. - * - */ - $event_handlers = array('[^a-z_\-]on\w*','xmlns'); - - if ($is_image === TRUE) - { - /* - * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, - * so we have to allow this for images. -Paul - */ - unset($event_handlers[array_search('xmlns', $event_handlers)]); - } - - $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); - - /* - * Sanitize naughty HTML elements - * - * If a tag containing any of the words in the list - * below is found, the tag gets converted to entities. - * - * So this: - * Becomes: <blink> - * - */ - $naughty = 'alert|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|xml|xss'; - $str = preg_replace_callback('#<(/*\s*)('.$naughty.')([^><]*)([><]*)#is', array($this, '_sanitize_naughty_html'), $str); - - /* - * Sanitize naughty scripting elements - * - * Similar to above, only instead of looking for - * tags it looks for PHP and JavaScript commands - * that are disallowed. Rather than removing the - * code, it simply converts the parenthesis to entities - * rendering the code un-executable. - * - * For example: eval('some code') - * Becomes: eval('some code') - * - */ - $str = preg_replace('#(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str); - - /* - * Final clean up - * - * This adds a bit of extra precaution in case - * something got through the above filters - * - */ - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - /* - * Images are Handled in a Special Way - * - Essentially, we want to know that after all of the character conversion is done whether - * any unwanted, likely XSS, code was found. If not, we return TRUE, as the image is clean. - * However, if the string post-conversion does not matched the string post-removal of XSS, - * then it fails, as there was unwanted XSS code found and removed/changed during processing. - */ - - if ($is_image === TRUE) - { - if ($str == $converted_string) - { - return TRUE; - } - else - { - return FALSE; - } - } - - log_message('debug', "XSS Filtering completed"); - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Random Hash for protecting URLs - * - * @access public - * @return string - */ - function xss_hash() - { - if ($this->xss_hash == '') - { - if (phpversion() >= 4.2) - mt_srand(); - else - mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); - - $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); - } - - return $this->xss_hash; - } - - // -------------------------------------------------------------------- - - /** - * Remove Invisible Characters - * - * This prevents sandwiching null characters - * between ascii characters, like Java\0script. - * - * @access public - * @param string - * @return string - */ - function _remove_invisible_characters($str) - { - static $non_displayables; - - if ( ! isset($non_displayables)) - { - // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), - $non_displayables = array( - '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 - '/%1[0-9a-f]/', // url encoded 16-31 - '/[\x00-\x08]/', // 00-08 - '/\x0b/', '/\x0c/', // 11, 12 - '/[\x0e-\x1f]/' // 14-31 - ); - } - - do - { - $cleaned = $str; - $str = preg_replace($non_displayables, '', $str); - } - while ($cleaned != $str); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Compact Exploded Words - * - * Callback function for xss_clean() to remove whitespace from - * things like j a v a s c r i p t - * - * @access public - * @param type - * @return type - */ - function _compact_exploded_words($matches) - { - return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; - } - - // -------------------------------------------------------------------- - - /** - * Sanitize Naughty HTML - * - * Callback function for xss_clean() to remove naughty HTML elements - * - * @access private - * @param array - * @return string - */ - function _sanitize_naughty_html($matches) - { - // encode opening brace - $str = '<'.$matches[1].$matches[2].$matches[3]; - - // encode captured opening or closing brace to prevent recursive vectors - $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * JS Link Removal - * - * Callback function for xss_clean() to sanitize links - * This limits the PCRE backtracks, making it more performance friendly - * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in - * PHP 5.2+ on link-heavy strings - * - * @access private - * @param array - * @return string - */ - function _js_link_removal($match) - { - $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), array('>', '<', '\\\\'), $match[0]); - } - - // -------------------------------------------------------------------- - - /** - * HTML Entity Decode Callback - * - * Used as a callback for XSS Clean - * - * @access public - * @param array - * @return string - */ - function _html_entity_decode_callback($match) - { - $CFG =& load_class('Config'); - $charset = $CFG->item('charset'); - - return $this->_html_entity_decode($match[0], strtoupper($charset)); - } - - // -------------------------------------------------------------------- - - /** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 - * - * @access private - * @param string - * @param string - * @return string - */ - /* ------------------------------------------------- - /* Replacement for html_entity_decode() - /* -------------------------------------------------*/ - - /* - NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - character set, and the PHP developers said they were not back porting the - fix to versions other than PHP 5.x. - */ - function _html_entity_decode($str, $charset='UTF-8') - { - if (stristr($str, '&') === FALSE) return $str; - - // The reason we are not using html_entity_decode() by itself is because - // while it is not technically correct to leave out the semicolon - // at the end of an entity most browsers will still interpret the entity - // correctly. html_entity_decode() does not convert entities without - // semicolons, so we are left with our own little solution here. Bummer. - - if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) - { - $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); - return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); - } - - // Numeric Entities - $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); - $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); - - // Literal Entities - Slightly slow so we do another check - if (stristr($str, '&') === FALSE) - { - $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Filter Attributes - * - * Filters tag attributes for consistency and safety - * - * @access public - * @param string - * @return string - */ - function _filter_attributes($str) - { - $out = ''; - - if (preg_match_all('#\s*[a-z\-]+\s*=\s*(\042|\047)([^\\1]*?)\\1#is', $str, $matches)) - { - foreach ($matches[0] as $match) - { - $out .= preg_replace("#/\*.*?\*/#s", '', $match); - } - } - - return $out; - } - - // -------------------------------------------------------------------- - -} -// END Input class - -/* End of file Input.php */ -/* Location: ./system/libraries/Input.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Language.php b/bmt-system/libraries/Language.php deleted file mode 100755 index 78f4143..0000000 --- a/bmt-system/libraries/Language.php +++ /dev/null @@ -1,123 +0,0 @@ -is_loaded, TRUE)) - { - return; - } - - if ($idiom == '') - { - $CI =& get_instance(); - $deft_lang = $CI->config->item('language'); - $idiom = ($deft_lang == '') ? 'english' : $deft_lang; - } - - // Determine where the language file is and load it - if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) - { - include(APPPATH.'language/'.$idiom.'/'.$langfile); - } - else - { - if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) - { - include(BASEPATH.'language/'.$idiom.'/'.$langfile); - } - else - { - show_error('Unable to load the requested language file: language/'.$langfile); - } - } - - if ( ! isset($lang)) - { - log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); - return; - } - - if ($return == TRUE) - { - return $lang; - } - - $this->is_loaded[] = $langfile; - $this->language = array_merge($this->language, $lang); - unset($lang); - - log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a single line of text from the language array - * - * @access public - * @param string $line the language line - * @return string - */ - function line($line = '') - { - $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; - return $line; - } - -} -// END Language Class - -/* End of file Language.php */ -/* Location: ./system/libraries/Language.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Loader.php b/bmt-system/libraries/Loader.php deleted file mode 100755 index 3b6e927..0000000 --- a/bmt-system/libraries/Loader.php +++ /dev/null @@ -1,1089 +0,0 @@ - 'unit', 'user_agent' => 'agent'); - - - /** - * Constructor - * - * Sets the path to the view files and gets the initial output buffering level - * - * @access public - */ - function CI_Loader() - { - $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; - $this->_ci_view_path = APPPATH.'views/'; - $this->_ci_ob_level = ob_get_level(); - - log_message('debug', "Loader Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Class Loader - * - * This function lets users load and instantiate classes. - * It is designed to be called from a user's app controllers. - * - * @access public - * @param string the name of the class - * @param mixed the optional parameters - * @param string an optional object name - * @return void - */ - function library($library = '', $params = NULL, $object_name = NULL) - { - if ($library == '') - { - return FALSE; - } - - if ( ! is_null($params) AND ! is_array($params)) - { - $params = NULL; - } - - if (is_array($library)) - { - foreach ($library as $class) - { - $this->_ci_load_class($class, $params, $object_name); - } - } - else - { - $this->_ci_load_class($library, $params, $object_name); - } - - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Model Loader - * - * This function lets users load and instantiate models. - * - * @access public - * @param string the name of the class - * @param string name for the model - * @param bool database connection - * @return void - */ - function model($model, $name = '', $db_conn = FALSE) - { - if (is_array($model)) - { - foreach($model as $babe) - { - $this->model($babe); - } - return; - } - - if ($model == '') - { - return; - } - - // Is the model in a sub-folder? If so, parse out the filename and path. - if (strpos($model, '/') === FALSE) - { - $path = ''; - } - else - { - $x = explode('/', $model); - $model = end($x); - unset($x[count($x)-1]); - $path = implode('/', $x).'/'; - } - - if ($name == '') - { - $name = $model; - } - - if (in_array($name, $this->_ci_models, TRUE)) - { - return; - } - - $CI =& get_instance(); - if (isset($CI->$name)) - { - show_error('The model name you are loading is the name of a resource that is already being used: '.$name); - } - - $model = strtolower($model); - - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) - { - show_error('Unable to locate the model you have specified: '.$model); - } - - if ($db_conn !== FALSE AND ! class_exists('CI_DB')) - { - if ($db_conn === TRUE) - $db_conn = ''; - - $CI->load->database($db_conn, FALSE, TRUE); - } - - if ( ! class_exists('Model')) - { - load_class('Model', FALSE); - } - - require_once(APPPATH.'models/'.$path.$model.EXT); - - $model = ucfirst($model); - - $CI->$name = new $model(); - $CI->$name->_assign_libraries(); - - $this->_ci_models[] = $name; - } - - // -------------------------------------------------------------------- - - /** - * Database Loader - * - * @access public - * @param string the DB credentials - * @param bool whether to return the DB object - * @param bool whether to enable active record (this allows us to override the config setting) - * @return object - */ - function database($params = '', $return = FALSE, $active_record = FALSE) - { - // Grab the super object - $CI =& get_instance(); - - // Do we even need to load the database class? - if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE AND isset($CI->db) AND is_object($CI->db)) - { - return FALSE; - } - - require_once(BASEPATH.'database/DB'.EXT); - - if ($return === TRUE) - { - return DB($params, $active_record); - } - - // Initialize the db variable. Needed to prevent - // reference errors with some configurations - $CI->db = ''; - - // Load the DB class - $CI->db =& DB($params, $active_record); - - // Assign the DB object to any existing models - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Load the Utilities Class - * - * @access public - * @return string - */ - function dbutil() - { - if ( ! class_exists('CI_DB')) - { - $this->database(); - } - - $CI =& get_instance(); - - // for backwards compatibility, load dbforge so we can extend dbutils off it - // this use is deprecated and strongly discouraged - $CI->load->dbforge(); - - require_once(BASEPATH.'database/DB_utility'.EXT); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); - $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; - - //$CI->dbutil =& new $class(); - $CI->dbutil = new $class(); - - $CI->load->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Load the Database Forge Class - * - * @access public - * @return string - */ - function dbforge() - { - if ( ! class_exists('CI_DB')) - { - $this->database(); - } - - $CI =& get_instance(); - - require_once(BASEPATH.'database/DB_forge'.EXT); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT); - $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; - - $CI->dbforge = new $class(); - - $CI->load->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Load View - * - * This function is used to load a "view" file. It has three parameters: - * - * 1. The name of the "view" file to be included. - * 2. An associative array of data to be extracted for use in the view. - * 3. TRUE/FALSE - whether to return the data or load it. In - * some cases it's advantageous to be able to return data so that - * a developer can process it in some way. - * - * @access public - * @param string - * @param array - * @param bool - * @return void - */ - function view($view, $vars = array(), $return = FALSE) - { - return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); - } - - // -------------------------------------------------------------------- - - /** - * Load File - * - * This is a generic file loader - * - * @access public - * @param string - * @param bool - * @return string - */ - function file($path, $return = FALSE) - { - return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); - } - - // -------------------------------------------------------------------- - - /** - * Set Variables - * - * Once variables are set they become available within - * the controller class and its "view" files. - * - * @access public - * @param array - * @return void - */ - function vars($vars = array(), $val = '') - { - if ($val != '' AND is_string($vars)) - { - $vars = array($vars => $val); - } - - $vars = $this->_ci_object_to_array($vars); - - if (is_array($vars) AND count($vars) > 0) - { - foreach ($vars as $key => $val) - { - $this->_ci_cached_vars[$key] = $val; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Load Helper - * - * This function loads the specified helper file. - * - * @access public - * @param mixed - * @return void - */ - function helper($helpers = array()) - { - if ( ! is_array($helpers)) - { - $helpers = array($helpers); - } - - foreach ($helpers as $helper) - { - $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - - if (isset($this->_ci_helpers[$helper])) - { - continue; - } - - $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT; - - // Is this a helper extension request? - if (file_exists($ext_helper)) - { - $base_helper = BASEPATH.'helpers/'.$helper.EXT; - - if ( ! file_exists($base_helper)) - { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); - } - - include_once($ext_helper); - include_once($base_helper); - } - elseif (file_exists(APPPATH.'helpers/'.$helper.EXT)) - { - include_once(APPPATH.'helpers/'.$helper.EXT); - } - else - { - if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) - { - include_once(BASEPATH.'helpers/'.$helper.EXT); - } - else - { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); - } - } - - $this->_ci_helpers[$helper] = TRUE; - log_message('debug', 'Helper loaded: '.$helper); - } - } - - // -------------------------------------------------------------------- - - /** - * Load Helpers - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function helpers($helpers = array()) - { - $this->helper($helpers); - } - - // -------------------------------------------------------------------- - - /** - * Load Plugin - * - * This function loads the specified plugin. - * - * @access public - * @param array - * @return void - */ - function plugin($plugins = array()) - { - if ( ! is_array($plugins)) - { - $plugins = array($plugins); - } - - foreach ($plugins as $plugin) - { - $plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi'); - - if (isset($this->_ci_plugins[$plugin])) - { - continue; - } - - if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) - { - include_once(APPPATH.'plugins/'.$plugin.EXT); - } - else - { - if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) - { - include_once(BASEPATH.'plugins/'.$plugin.EXT); - } - else - { - show_error('Unable to load the requested file: plugins/'.$plugin.EXT); - } - } - - $this->_ci_plugins[$plugin] = TRUE; - log_message('debug', 'Plugin loaded: '.$plugin); - } - } - - // -------------------------------------------------------------------- - - /** - * Load Plugins - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function plugins($plugins = array()) - { - $this->plugin($plugins); - } - - // -------------------------------------------------------------------- - - /** - * Loads a language file - * - * @access public - * @param array - * @param string - * @return void - */ - function language($file = array(), $lang = '') - { - $CI =& get_instance(); - - if ( ! is_array($file)) - { - $file = array($file); - } - - foreach ($file as $langfile) - { - $CI->lang->load($langfile, $lang); - } - } - - /** - * Loads language files for scaffolding - * - * @access public - * @param string - * @return arra - */ - function scaffold_language($file = '', $lang = '', $return = FALSE) - { - $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); - } - - // -------------------------------------------------------------------- - - /** - * Loads a config file - * - * @access public - * @param string - * @return void - */ - function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $CI =& get_instance(); - $CI->config->load($file, $use_sections, $fail_gracefully); - } - - // -------------------------------------------------------------------- - - /** - * Scaffolding Loader - * - * This initializing function works a bit different than the - * others. It doesn't load the class. Instead, it simply - * sets a flag indicating that scaffolding is allowed to be - * used. The actual scaffolding function below is - * called by the front controller based on whether the - * second segment of the URL matches the "secret" scaffolding - * word stored in the application/config/routes.php - * - * @access public - * @param string - * @return void - */ - function scaffolding($table = '') - { - if ($table === FALSE) - { - show_error('You must include the name of the table you would like to access when you initialize scaffolding'); - } - - $CI =& get_instance(); - $CI->_ci_scaffolding = TRUE; - $CI->_ci_scaff_table = $table; - } - - // -------------------------------------------------------------------- - - /** - * Loader - * - * This function is used to load views and files. - * Variables are prefixed with _ci_ to avoid symbol collision with - * variables made available to view files - * - * @access private - * @param array - * @return void - */ - function _ci_load($_ci_data) - { - // Set the default data variables - foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) - { - $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; - } - - // Set the path to the requested file - if ($_ci_path == '') - { - $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); - $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view; - $_ci_path = $this->_ci_view_path.$_ci_file; - } - else - { - $_ci_x = explode('/', $_ci_path); - $_ci_file = end($_ci_x); - } - - if ( ! file_exists($_ci_path)) - { - show_error('Unable to load the requested file: '.$_ci_file); - } - - // This allows anything loaded using $this->load (views, files, etc.) - // to become accessible from within the Controller and Model functions. - // Only needed when running PHP 5 - - if ($this->_ci_is_instance()) - { - $_ci_CI =& get_instance(); - foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) - { - if ( ! isset($this->$_ci_key)) - { - $this->$_ci_key =& $_ci_CI->$_ci_key; - } - } - } - - /* - * Extract and cache variables - * - * You can either set variables using the dedicated $this->load_vars() - * function or via the second parameter of this function. We'll merge - * the two types and cache them so that views that are embedded within - * other views can have access to these variables. - */ - if (is_array($_ci_vars)) - { - $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); - } - extract($this->_ci_cached_vars); - - /* - * Buffer the output - * - * We buffer the output for two reasons: - * 1. Speed. You get a significant speed boost. - * 2. So that the final rendered template can be - * post-processed by the output class. Why do we - * need post processing? For one thing, in order to - * show the elapsed page load time. Unless we - * can intercept the content right before it's sent to - * the browser and then stop the timer it won't be accurate. - */ - ob_start(); - - // If the PHP installation does not support short tags we'll - // do a little string replacement, changing the short tags - // to standard PHP echo statements. - - if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) - { - echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace(' $this->_ci_ob_level + 1) - { - ob_end_flush(); - } - else - { - // PHP 4 requires that we use a global - global $OUT; - $OUT->append_output(ob_get_contents()); - @ob_end_clean(); - } - } - - // -------------------------------------------------------------------- - - /** - * Load class - * - * This function loads the requested class. - * - * @access private - * @param string the item that is being loaded - * @param mixed any additional parameters - * @param string an optional object name - * @return void - */ - function _ci_load_class($class, $params = NULL, $object_name = NULL) - { - // Get the class name, and while we're at it trim any slashes. - // The directory path can be included as part of the class name, - // but we don't want a leading slash - $class = str_replace(EXT, '', trim($class, '/')); - - // Was the path included with the class name? - // We look for a slash to determine this - $subdir = ''; - if (strpos($class, '/') !== FALSE) - { - // explode the path so we can separate the filename from the path - $x = explode('/', $class); - - // Reset the $class variable now that we know the actual filename - $class = end($x); - - // Kill the filename from the array - unset($x[count($x)-1]); - - // Glue the path back together, sans filename - $subdir = implode($x, '/').'/'; - } - - // We'll test for both lowercase and capitalized versions of the file name - foreach (array(ucfirst($class), strtolower($class)) as $class) - { - $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT; - - // Is this a class extension request? - if (file_exists($subclass)) - { - $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; - - if ( ! file_exists($baseclass)) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the requested class: ".$class); - } - - // Safety: Was the class already loaded by a previous call? - if (in_array($subclass, $this->_ci_loaded_files)) - { - // Before we deem this to be a duplicate request, let's see - // if a custom object name is being supplied. If so, we'll - // return a new instance of the object - if ( ! is_null($object_name)) - { - $CI =& get_instance(); - if ( ! isset($CI->$object_name)) - { - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); - } - } - - $is_duplicate = TRUE; - log_message('debug', $class." class already loaded. Second attempt ignored."); - return; - } - - include_once($baseclass); - include_once($subclass); - $this->_ci_loaded_files[] = $subclass; - - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); - } - - // Lets search for the requested library file and load it. - $is_duplicate = FALSE; - for ($i = 1; $i < 3; $i++) - { - $path = ($i % 2) ? APPPATH : BASEPATH; - $filepath = $path.'libraries/'.$subdir.$class.EXT; - - // Does the file exist? No? Bummer... - if ( ! file_exists($filepath)) - { - continue; - } - - // Safety: Was the class already loaded by a previous call? - if (in_array($filepath, $this->_ci_loaded_files)) - { - // Before we deem this to be a duplicate request, let's see - // if a custom object name is being supplied. If so, we'll - // return a new instance of the object - if ( ! is_null($object_name)) - { - $CI =& get_instance(); - if ( ! isset($CI->$object_name)) - { - return $this->_ci_init_class($class, '', $params, $object_name); - } - } - - $is_duplicate = TRUE; - log_message('debug', $class." class already loaded. Second attempt ignored."); - return; - } - - include_once($filepath); - $this->_ci_loaded_files[] = $filepath; - return $this->_ci_init_class($class, '', $params, $object_name); - } - } // END FOREACH - - // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? - if ($subdir == '') - { - $path = strtolower($class).'/'.$class; - return $this->_ci_load_class($path, $params); - } - - // If we got this far we were unable to find the requested class. - // We do not issue errors if the load call failed due to a duplicate request - if ($is_duplicate == FALSE) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the requested class: ".$class); - } - } - - // -------------------------------------------------------------------- - - /** - * Instantiates a class - * - * @access private - * @param string - * @param string - * @param string an optional object name - * @return null - */ - function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) - { - // Is there an associated config file for this class? - if ($config === NULL) - { - // We test for both uppercase and lowercase, for servers that - // are case-sensitive with regard to file names - if (file_exists(APPPATH.'config/'.strtolower($class).EXT)) - { - include_once(APPPATH.'config/'.strtolower($class).EXT); - } - else - { - if (file_exists(APPPATH.'config/'.ucfirst(strtolower($class)).EXT)) - { - include_once(APPPATH.'config/'.ucfirst(strtolower($class)).EXT); - } - } - } - - if ($prefix == '') - { - if (class_exists('CI_'.$class)) - { - $name = 'CI_'.$class; - } - elseif (class_exists(config_item('subclass_prefix').$class)) - { - $name = config_item('subclass_prefix').$class; - } - else - { - $name = $class; - } - } - else - { - $name = $prefix.$class; - } - - // Is the class name valid? - if ( ! class_exists($name)) - { - log_message('error', "Non-existent class: ".$name); - show_error("Non-existent class: ".$class); - } - - // Set the variable name we will assign the class to - // Was a custom class name supplied? If so we'll use it - $class = strtolower($class); - - if (is_null($object_name)) - { - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; - } - else - { - $classvar = $object_name; - } - - // Save the class name and object name - $this->_ci_classes[$class] = $classvar; - - // Instantiate the class - $CI =& get_instance(); - if ($config !== NULL) - { - $CI->$classvar = new $name($config); - } - else - { - $CI->$classvar = new $name; - } - } - - // -------------------------------------------------------------------- - - /** - * Autoloader - * - * The config/autoload.php file contains an array that permits sub-systems, - * libraries, plugins, and helpers to be loaded automatically. - * - * @access private - * @param array - * @return void - */ - function _ci_autoloader() - { - include_once(APPPATH.'config/autoload'.EXT); - - if ( ! isset($autoload)) - { - return FALSE; - } - - // Load any custom config file - if (count($autoload['config']) > 0) - { - $CI =& get_instance(); - foreach ($autoload['config'] as $key => $val) - { - $CI->config->load($val); - } - } - - // Autoload plugins, helpers and languages - foreach (array('helper', 'plugin', 'language') as $type) - { - if (isset($autoload[$type]) AND count($autoload[$type]) > 0) - { - $this->$type($autoload[$type]); - } - } - - // A little tweak to remain backward compatible - // The $autoload['core'] item was deprecated - if ( ! isset($autoload['libraries'])) - { - $autoload['libraries'] = $autoload['core']; - } - - // Load libraries - if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) - { - // Load the database driver. - if (in_array('database', $autoload['libraries'])) - { - $this->database(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); - } - - // Load scaffolding - if (in_array('scaffolding', $autoload['libraries'])) - { - $this->scaffolding(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); - } - - // Load all other libraries - foreach ($autoload['libraries'] as $item) - { - $this->library($item); - } - } - - // Autoload models - if (isset($autoload['model'])) - { - $this->model($autoload['model']); - } - - } - - // -------------------------------------------------------------------- - - /** - * Assign to Models - * - * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) - * will be available to models, if any exist. - * - * @access private - * @param object - * @return array - */ - function _ci_assign_to_models() - { - if (count($this->_ci_models) == 0) - { - return; - } - - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - foreach ($this->_ci_models as $model) - { - $CI->$model->_assign_libraries(); - } - } - else - { - foreach ($this->_ci_models as $model) - { - $this->$model->_assign_libraries(); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @access private - * @param object - * @return array - */ - function _ci_object_to_array($object) - { - return (is_object($object)) ? get_object_vars($object) : $object; - } - - // -------------------------------------------------------------------- - - /** - * Determines whether we should use the CI instance or $this - * - * @access private - * @return bool - */ - function _ci_is_instance() - { - if ($this->_ci_is_php5 == TRUE) - { - return TRUE; - } - - global $CI; - return (is_object($CI)) ? TRUE : FALSE; - } - -} - -/* End of file Loader.php */ -/* Location: ./system/libraries/Loader.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Log.php b/bmt-system/libraries/Log.php deleted file mode 100755 index 326edaa..0000000 --- a/bmt-system/libraries/Log.php +++ /dev/null @@ -1,117 +0,0 @@ - '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); - - /** - * Constructor - * - * @access public - */ - function CI_Log() - { - $config =& get_config(); - - $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; - - if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) - { - $this->_enabled = FALSE; - } - - if (is_numeric($config['log_threshold'])) - { - $this->_threshold = $config['log_threshold']; - } - - if ($config['log_date_format'] != '') - { - $this->_date_fmt = $config['log_date_format']; - } - } - - // -------------------------------------------------------------------- - - /** - * Write Log File - * - * Generally this function will be called using the global log_message() function - * - * @access public - * @param string the error level - * @param string the error message - * @param bool whether the error is a native PHP error - * @return bool - */ - function write_log($level = 'error', $msg, $php_error = FALSE) - { - if ($this->_enabled === FALSE) - { - return FALSE; - } - - $level = strtoupper($level); - - if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) - { - return FALSE; - } - - $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; - $message = ''; - - if ( ! file_exists($filepath)) - { - $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; - } - - if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) - { - return FALSE; - } - - $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n"; - - flock($fp, LOCK_EX); - fwrite($fp, $message); - flock($fp, LOCK_UN); - fclose($fp); - - @chmod($filepath, FILE_WRITE_MODE); - return TRUE; - } - -} -// END Log Class - -/* End of file Log.php */ -/* Location: ./system/libraries/Log.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Model.php b/bmt-system/libraries/Model.php deleted file mode 100755 index c4cba56..0000000 --- a/bmt-system/libraries/Model.php +++ /dev/null @@ -1,83 +0,0 @@ -_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); - - // We don't want to assign the model object to itself when using the - // assign_libraries function below so we'll grab the name of the model parent - $this->_parent_name = ucfirst(get_class($this)); - - log_message('debug', "Model Class Initialized"); - } - - /** - * Assign Libraries - * - * Creates local references to all currently instantiated objects - * so that any syntax that can be legally used in a controller - * can be used within models. - * - * @access private - */ - function _assign_libraries($use_reference = TRUE) - { - $CI =& get_instance(); - foreach (array_keys(get_object_vars($CI)) as $key) - { - if ( ! isset($this->$key) AND $key != $this->_parent_name) - { - // In some cases using references can cause - // problems so we'll conditionally use them - if ($use_reference == TRUE) - { - $this->$key = NULL; // Needed to prevent reference errors with some configurations - $this->$key =& $CI->$key; - } - else - { - $this->$key = $CI->$key; - } - } - } - } - -} -// END Model Class - -/* End of file Model.php */ -/* Location: ./system/libraries/Model.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Output.php b/bmt-system/libraries/Output.php deleted file mode 100755 index b93963a..0000000 --- a/bmt-system/libraries/Output.php +++ /dev/null @@ -1,478 +0,0 @@ -final_output; - } - - // -------------------------------------------------------------------- - - /** - * Set Output - * - * Sets the output string - * - * @access public - * @param string - * @return void - */ - function set_output($output) - { - $this->final_output = $output; - } - - // -------------------------------------------------------------------- - - /** - * Append Output - * - * Appends data onto the output string - * - * @access public - * @param string - * @return void - */ - function append_output($output) - { - if ($this->final_output == '') - { - $this->final_output = $output; - } - else - { - $this->final_output .= $output; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Header - * - * Lets you set a server header which will be outputted with the final display. - * - * Note: If a file is cached, headers will not be sent. We need to figure out - * how to permit header data to be saved with the cache data... - * - * @access public - * @param string - * @return void - */ - function set_header($header, $replace = TRUE) - { - $this->headers[] = array($header, $replace); - } - - // -------------------------------------------------------------------- - - /** - * Set HTTP Status Header - * - * @access public - * @param int the status code - * @param string - * @return void - */ - function set_status_header($code = '200', $text = '') - { - $stati = array( - '200' => 'OK', - '201' => 'Created', - '202' => 'Accepted', - '203' => 'Non-Authoritative Information', - '204' => 'No Content', - '205' => 'Reset Content', - '206' => 'Partial Content', - - '300' => 'Multiple Choices', - '301' => 'Moved Permanently', - '302' => 'Found', - '304' => 'Not Modified', - '305' => 'Use Proxy', - '307' => 'Temporary Redirect', - - '400' => 'Bad Request', - '401' => 'Unauthorized', - '403' => 'Forbidden', - '404' => 'Not Found', - '405' => 'Method Not Allowed', - '406' => 'Not Acceptable', - '407' => 'Proxy Authentication Required', - '408' => 'Request Timeout', - '409' => 'Conflict', - '410' => 'Gone', - '411' => 'Length Required', - '412' => 'Precondition Failed', - '413' => 'Request Entity Too Large', - '414' => 'Request-URI Too Long', - '415' => 'Unsupported Media Type', - '416' => 'Requested Range Not Satisfiable', - '417' => 'Expectation Failed', - - '500' => 'Internal Server Error', - '501' => 'Not Implemented', - '502' => 'Bad Gateway', - '503' => 'Service Unavailable', - '504' => 'Gateway Timeout', - '505' => 'HTTP Version Not Supported' - ); - - if ($code == '' OR ! is_numeric($code)) - { - show_error('Status codes must be numeric'); - } - - if (isset($stati[$code]) AND $text == '') - { - $text = $stati[$code]; - } - - if ($text == '') - { - show_error('No status text available. Please check your status code number or supply your own message text.'); - } - - $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE; - - if (substr(php_sapi_name(), 0, 3) == 'cgi') - { - header("Status: {$code} {$text}", TRUE); - } - elseif ($server_protocol == 'HTTP/1.1' OR $server_protocol == 'HTTP/1.0') - { - header($server_protocol." {$code} {$text}", TRUE, $code); - } - else - { - header("HTTP/1.1 {$code} {$text}", TRUE, $code); - } - } - - // -------------------------------------------------------------------- - - /** - * Enable/disable Profiler - * - * @access public - * @param bool - * @return void - */ - function enable_profiler($val = TRUE) - { - $this->enable_profiler = (is_bool($val)) ? $val : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Cache - * - * @access public - * @param integer - * @return void - */ - function cache($time) - { - $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; - } - - // -------------------------------------------------------------------- - - /** - * Display Output - * - * All "view" data is automatically put into this variable by the controller class: - * - * $this->final_output - * - * This function sends the finalized output data to the browser along - * with any server headers and profile data. It also stops the - * benchmark timer so the page rendering speed and memory usage can be shown. - * - * @access public - * @return mixed - */ - function _display($output = '') - { - // Note: We use globals because we can't use $CI =& get_instance() - // since this function is sometimes called by the caching mechanism, - // which happens before the CI super object is available. - global $BM, $CFG; - - // -------------------------------------------------------------------- - - // Set the output data - if ($output == '') - { - $output =& $this->final_output; - } - - // -------------------------------------------------------------------- - - // Do we need to write a cache file? - if ($this->cache_expiration > 0) - { - $this->_write_cache($output); - } - - // -------------------------------------------------------------------- - - // Parse out the elapsed time and memory usage, - // then swap the pseudo-variables with the data - - $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); - $output = str_replace('{elapsed_time}', $elapsed, $output); - - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; - $output = str_replace('{memory_usage}', $memory, $output); - - // -------------------------------------------------------------------- - - // Is compression requested? - if ($CFG->item('compress_output') === TRUE) - { - if (extension_loaded('zlib')) - { - if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) - { - ob_start('ob_gzhandler'); - } - } - } - - // -------------------------------------------------------------------- - - // Are there any server headers to send? - if (count($this->headers) > 0) - { - foreach ($this->headers as $header) - { - @header($header[0], $header[1]); - } - } - - // -------------------------------------------------------------------- - - // Does the get_instance() function exist? - // If not we know we are dealing with a cache file so we'll - // simply echo out the data and exit. - if ( ! function_exists('get_instance')) - { - echo $output; - log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); - return TRUE; - } - - // -------------------------------------------------------------------- - - // Grab the super object. We'll need it in a moment... - $CI =& get_instance(); - - // Do we need to generate profile data? - // If so, load the Profile class and run it. - if ($this->enable_profiler == TRUE) - { - $CI->load->library('profiler'); - - // If the output data contains closing and tags - // we will remove them and add them back after we insert the profile data - if (preg_match("|.*?|is", $output)) - { - $output = preg_replace("|.*?|is", '', $output); - $output .= $CI->profiler->run(); - $output .= ''; - } - else - { - $output .= $CI->profiler->run(); - } - } - - // -------------------------------------------------------------------- - - // Does the controller contain a function named _output()? - // If so send the output there. Otherwise, echo it. - if (method_exists($CI, '_output')) - { - $CI->_output($output); - } - else - { - echo $output; // Send it to the browser! - } - - log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); - } - - // -------------------------------------------------------------------- - - /** - * Write a Cache File - * - * @access public - * @return void - */ - function _write_cache($output) - { - $CI =& get_instance(); - $path = $CI->config->item('cache_path'); - - $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - - if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) - { - return; - } - - $uri = $CI->config->item('base_url'). - $CI->config->item('index_page'). - $CI->uri->uri_string(); - - $cache_path .= md5($uri); - - if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE)) - { - log_message('error', "Unable to write cache file: ".$cache_path); - return; - } - - $expire = time() + ($this->cache_expiration * 60); - - if (flock($fp, LOCK_EX)) - { - fwrite($fp, $expire.'TS--->'.$output); - flock($fp, LOCK_UN); - } - else - { - log_message('error', "Unable to secure a file lock for file at: ".$cache_path); - return; - } - fclose($fp); - @chmod($cache_path, DIR_WRITE_MODE); - - log_message('debug', "Cache file written: ".$cache_path); - } - - // -------------------------------------------------------------------- - - /** - * Update/serve a cached file - * - * @access public - * @return void - */ - function _display_cache(&$CFG, &$URI) - { - $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - - if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) - { - return FALSE; - } - - // Build the file path. The file name is an MD5 hash of the full URI - $uri = $CFG->item('base_url'). - $CFG->item('index_page'). - $URI->uri_string; - - $filepath = $cache_path.md5($uri); - - if ( ! @file_exists($filepath)) - { - return FALSE; - } - - if ( ! $fp = @fopen($filepath, FOPEN_READ)) - { - return FALSE; - } - - flock($fp, LOCK_SH); - - $cache = ''; - if (filesize($filepath) > 0) - { - $cache = fread($fp, filesize($filepath)); - } - - flock($fp, LOCK_UN); - fclose($fp); - - // Strip out the embedded timestamp - if ( ! preg_match("/(\d+TS--->)/", $cache, $match)) - { - return FALSE; - } - - // Has the file expired? If so we'll delete it. - if (time() >= trim(str_replace('TS--->', '', $match['1']))) - { - @unlink($filepath); - log_message('debug', "Cache file has expired. File deleted"); - return FALSE; - } - - // Display the cache - $this->_display(str_replace($match['0'], '', $cache)); - log_message('debug', "Cache file is current. Sending it to browser."); - return TRUE; - } - - -} -// END Output Class - -/* End of file Output.php */ -/* Location: ./system/libraries/Output.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Pagination.php b/bmt-system/libraries/Pagination.php deleted file mode 100755 index 09b5bec..0000000 --- a/bmt-system/libraries/Pagination.php +++ /dev/null @@ -1,244 +0,0 @@ -'; - var $cur_tag_close = ''; - var $next_tag_open = ' '; - var $next_tag_close = ' '; - var $prev_tag_open = ' '; - var $prev_tag_close = ''; - var $num_tag_open = ' '; - var $num_tag_close = ''; - var $page_query_string = FALSE; - var $query_string_segment = 'per_page'; - - /** - * Constructor - * - * @access public - * @param array initialization parameters - */ - function CI_Pagination($params = array()) - { - if (count($params) > 0) - { - $this->initialize($params); - } - - log_message('debug', "Pagination Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Preferences - * - * @access public - * @param array initialization parameters - * @return void - */ - function initialize($params = array()) - { - if (count($params) > 0) - { - foreach ($params as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - } - } - - // -------------------------------------------------------------------- - - /** - * Generate the pagination links - * - * @access public - * @return string - */ - function create_links() - { - // If our item count or per-page total is zero there is no need to continue. - if ($this->total_rows == 0 OR $this->per_page == 0) - { - return ''; - } - - // Calculate the total number of pages - $num_pages = ceil($this->total_rows / $this->per_page); - - // Is there only one page? Hm... nothing more to do here then. - if ($num_pages == 1) - { - return ''; - } - - // Determine the current page number. - $CI =& get_instance(); - - if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) - { - if ($CI->input->get($this->query_string_segment) != 0) - { - $this->cur_page = $CI->input->get($this->query_string_segment); - - // Prep the current page - no funny business! - $this->cur_page = (int) $this->cur_page; - } - } - else - { - if ($CI->uri->segment($this->uri_segment) != 0) - { - $this->cur_page = $CI->uri->segment($this->uri_segment); - - // Prep the current page - no funny business! - $this->cur_page = (int) $this->cur_page; - } - } - - $this->num_links = (int)$this->num_links; - - if ($this->num_links < 1) - { - show_error('Your number of links must be a positive number.'); - } - - if ( ! is_numeric($this->cur_page)) - { - $this->cur_page = 0; - } - - // Is the page number beyond the result range? - // If so we show the last page - if ($this->cur_page > $this->total_rows) - { - $this->cur_page = ($num_pages - 1) * $this->per_page; - } - - $uri_page_number = $this->cur_page; - $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); - - // Calculate the start and end numbers. These determine - // which number to start and end the digit links with - $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; - $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; - - // Is pagination being used over GET or POST? If get, add a per_page query - // string. If post, add a trailing slash to the base URL if needed - if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) - { - $this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'='; - } - else - { - $this->base_url = rtrim($this->base_url, '/') .'/'; - } - - // And here we go... - $output = ''; - - // Render the "First" link - if ($this->cur_page > ($this->num_links + 1)) - { - $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; - } - - // Render the "previous" link - if ($this->cur_page != 1) - { - $i = $uri_page_number - $this->per_page; - if ($i == 0) $i = ''; - $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; - } - - // Write the digit links - for ($loop = $start -1; $loop <= $end; $loop++) - { - $i = ($loop * $this->per_page) - $this->per_page; - - if ($i >= 0) - { - if ($this->cur_page == $loop) - { - $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page - } - else - { - $n = ($i == 0) ? '' : $i; - $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; - } - } - } - - // Render the "next" link - if ($this->cur_page < $num_pages) - { - $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; - } - - // Render the "Last" link - if (($this->cur_page + $this->num_links) < $num_pages) - { - $i = (($num_pages * $this->per_page) - $this->per_page); - $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; - } - - // Kill double slashes. Note: Sometimes we can end up with a double slash - // in the penultimate link so we'll kill all double slashes. - $output = preg_replace("#([^:])//+#", "\\1/", $output); - - // Add the wrapper HTML if exists - $output = $this->full_tag_open.$output.$this->full_tag_close; - - return $output; - } -} -// END Pagination Class - -/* End of file Pagination.php */ -/* Location: ./system/libraries/Pagination.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Parser.php b/bmt-system/libraries/Parser.php deleted file mode 100755 index 3d379b2..0000000 --- a/bmt-system/libraries/Parser.php +++ /dev/null @@ -1,173 +0,0 @@ -load->view($template, $data, TRUE); - - if ($template == '') - { - return FALSE; - } - - foreach ($data as $key => $val) - { - if (is_array($val)) - { - $template = $this->_parse_pair($key, $val, $template); - } - else - { - $template = $this->_parse_single($key, (string)$val, $template); - } - } - - if ($return == FALSE) - { - $CI->output->append_output($template); - } - - return $template; - } - - // -------------------------------------------------------------------- - - /** - * Set the left/right variable delimiters - * - * @access public - * @param string - * @param string - * @return void - */ - function set_delimiters($l = '{', $r = '}') - { - $this->l_delim = $l; - $this->r_delim = $r; - } - - // -------------------------------------------------------------------- - - /** - * Parse a single key/value - * - * @access private - * @param string - * @param string - * @param string - * @return string - */ - function _parse_single($key, $val, $string) - { - return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); - } - - // -------------------------------------------------------------------- - - /** - * Parse a tag pair - * - * Parses tag pairs: {some_tag} string... {/some_tag} - * - * @access private - * @param string - * @param array - * @param string - * @return string - */ - function _parse_pair($variable, $data, $string) - { - if (FALSE === ($match = $this->_match_pair($string, $variable))) - { - return $string; - } - - $str = ''; - foreach ($data as $row) - { - $temp = $match['1']; - foreach ($row as $key => $val) - { - if ( ! is_array($val)) - { - $temp = $this->_parse_single($key, $val, $temp); - } - else - { - $temp = $this->_parse_pair($key, $val, $temp); - } - } - - $str .= $temp; - } - - return str_replace($match['0'], $str, $string); - } - - // -------------------------------------------------------------------- - - /** - * Matches a variable pair - * - * @access private - * @param string - * @param string - * @return mixed - */ - function _match_pair($string, $variable) - { - if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+?)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) - { - return FALSE; - } - - return $match; - } - -} -// END Parser Class - -/* End of file Parser.php */ -/* Location: ./system/libraries/Parser.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Profiler.php b/bmt-system/libraries/Profiler.php deleted file mode 100755 index 5e9fa8b..0000000 --- a/bmt-system/libraries/Profiler.php +++ /dev/null @@ -1,392 +0,0 @@ -CI =& get_instance(); - $this->CI->load->language('profiler'); - } - - // -------------------------------------------------------------------- - - /** - * Auto Profiler - * - * This function cycles through the entire array of mark points and - * matches any two points that are named identically (ending in "_start" - * and "_end" respectively). It then compiles the execution times for - * all points and returns it as an array - * - * @access private - * @return array - */ - function _compile_benchmarks() - { - $profile = array(); - foreach ($this->CI->benchmark->marker as $key => $val) - { - // We match the "end" marker so that the list ends - // up in the order that it was defined - if (preg_match("/(.+?)_end/i", $key, $match)) - { - if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start'])) - { - $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); - } - } - } - - // Build a table containing the profile data. - // Note: At some point we should turn this into a template that can - // be modified. We also might want to make this data available to be logged - - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; - $output .= "\n"; - $output .= "\n\n\n"; - - foreach ($profile as $key => $val) - { - $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "\n"; - } - - $output .= "
    ".$key."  ".$val."
    \n"; - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile Queries - * - * @access private - * @return string - */ - function _compile_queries() - { - $dbs = array(); - - // Let's determine which databases are currently connected to - foreach (get_object_vars($this->CI) as $CI_object) - { - if ( is_subclass_of(get_class($CI_object), 'CI_DB') ) - { - $dbs[] = $CI_object; - } - } - - if (count($dbs) == 0) - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; - $output .= "\n"; - $output .= "\n\n\n"; - $output .="\n"; - $output .= "
    ".$this->CI->lang->line('profiler_no_db')."
    \n"; - $output .= "
    "; - - return $output; - } - - // Load the text helper so we can highlight the SQL - $this->CI->load->helper('text'); - - // Key words we want bolded - $highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR', 'HAVING', 'OFFSET', 'NOT IN', 'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')'); - - $output = "\n\n"; - - foreach ($dbs as $db) - { - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).'   '; - $output .= "\n"; - $output .= "\n\n\n"; - - if (count($db->queries) == 0) - { - $output .= "\n"; - } - else - { - foreach ($db->queries as $key => $val) - { - $time = number_format($db->query_times[$key], 4); - - $val = highlight_code($val, ENT_QUOTES); - - foreach ($highlight as $bold) - { - $val = str_replace($bold, ''.$bold.'', $val); - } - - $output .= "\n"; - } - } - - $output .= "
    ".$this->CI->lang->line('profiler_no_queries')."
    ".$time."  ".$val."
    \n"; - $output .= "
    "; - - } - - return $output; - } - - - // -------------------------------------------------------------------- - - /** - * Compile $_GET Data - * - * @access private - * @return string - */ - function _compile_get() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_get_data').'  '; - $output .= "\n"; - - if (count($_GET) == 0) - { - $output .= "
    ".$this->CI->lang->line('profiler_no_get')."
    "; - } - else - { - $output .= "\n\n\n"; - - foreach ($_GET as $key => $val) - { - if ( ! is_numeric($key)) - { - $key = "'".$key."'"; - } - - $output .= "\n"; - } - - $output .= "
    $_GET[".$key."]   "; - if (is_array($val)) - { - $output .= "
    " . htmlspecialchars(stripslashes(print_r($val, true))) . "
    "; - } - else - { - $output .= htmlspecialchars(stripslashes($val)); - } - $output .= "
    \n"; - } - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile $_POST Data - * - * @access private - * @return string - */ - function _compile_post() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; - $output .= "\n"; - - if (count($_POST) == 0) - { - $output .= "
    ".$this->CI->lang->line('profiler_no_post')."
    "; - } - else - { - $output .= "\n\n\n"; - - foreach ($_POST as $key => $val) - { - if ( ! is_numeric($key)) - { - $key = "'".$key."'"; - } - - $output .= "\n"; - } - - $output .= "
    $_POST[".$key."]   "; - if (is_array($val)) - { - $output .= "
    " . htmlspecialchars(stripslashes(print_r($val, true))) . "
    "; - } - else - { - $output .= htmlspecialchars(stripslashes($val)); - } - $output .= "
    \n"; - } - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Show query string - * - * @access private - * @return string - */ - function _compile_uri_string() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_uri_string').'  '; - $output .= "\n"; - - if ($this->CI->uri->uri_string == '') - { - $output .= "
    ".$this->CI->lang->line('profiler_no_uri')."
    "; - } - else - { - $output .= "
    ".$this->CI->uri->uri_string."
    "; - } - - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Show the controller and function that were called - * - * @access private - * @return string - */ - function _compile_controller_info() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_controller_info').'  '; - $output .= "\n"; - - $output .= "
    ".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."
    "; - - - $output .= "
    "; - - return $output; - } - // -------------------------------------------------------------------- - - /** - * Compile memory usage - * - * Display total used memory - * - * @access public - * @return string - */ - function _compile_memory_usage() - { - $output = "\n\n"; - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_memory_usage').'  '; - $output .= "\n"; - - if (function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') - { - $output .= "
    ".number_format($usage).' bytes
    '; - } - else - { - $output .= "
    ".$this->CI->lang->line('profiler_no_memory_usage')."
    "; - } - - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Run the Profiler - * - * @access private - * @return string - */ - function run() - { - $output = "
    "; - - $output .= $this->_compile_uri_string(); - $output .= $this->_compile_controller_info(); - $output .= $this->_compile_memory_usage(); - $output .= $this->_compile_benchmarks(); - $output .= $this->_compile_get(); - $output .= $this->_compile_post(); - $output .= $this->_compile_queries(); - - $output .= '
    '; - - return $output; - } - -} - -// END CI_Profiler class - -/* End of file Profiler.php */ -/* Location: ./system/libraries/Profiler.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Router.php b/bmt-system/libraries/Router.php deleted file mode 100755 index bc46da4..0000000 --- a/bmt-system/libraries/Router.php +++ /dev/null @@ -1,389 +0,0 @@ -config =& load_class('Config'); - $this->uri =& load_class('URI'); - $this->_set_routing(); - log_message('debug', "Router Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set the route mapping - * - * This function determines what should be served based on the URI request, - * as well as any "routes" that have been set in the routing config file. - * - * @access private - * @return void - */ - function _set_routing() - { - // Are query strings enabled in the config file? - // If so, we're done since segment based URIs are not used with query strings. - if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) - { - $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); - - if (isset($_GET[$this->config->item('function_trigger')])) - { - $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); - } - - return; - } - - // Load the routes.php file. - @include(APPPATH.'config/routes'.EXT); - $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; - unset($route); - - // Set the default controller so we can display it in the event - // the URI doesn't correlated to a valid controller. - $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - - // Fetch the complete URI string - $this->uri->_fetch_uri_string(); - - // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if ($this->uri->uri_string == '') - { - if ($this->default_controller === FALSE) - { - show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file."); - } - - if (strpos($this->default_controller, '/') !== FALSE) - { - $x = explode('/', $this->default_controller); - - $this->set_class(end($x)); - $this->set_method('index'); - $this->_set_request($x); - } - else - { - $this->set_class($this->default_controller); - $this->set_method('index'); - $this->_set_request(array($this->default_controller, 'index')); - } - - // re-index the routed segments array so it starts with 1 rather than 0 - $this->uri->_reindex_segments(); - - log_message('debug', "No URI present. Default controller set."); - return; - } - unset($this->routes['default_controller']); - - // Do we need to remove the URL suffix? - $this->uri->_remove_url_suffix(); - - // Compile the segments into an array - $this->uri->_explode_segments(); - - // Parse any custom routing that may exist - $this->_parse_routes(); - - // Re-index the segment array so that it starts with 1 rather than 0 - $this->uri->_reindex_segments(); - } - - // -------------------------------------------------------------------- - - /** - * Set the Route - * - * This function takes an array of URI segments as - * input, and sets the current class/method - * - * @access private - * @param array - * @param bool - * @return void - */ - function _set_request($segments = array()) - { - $segments = $this->_validate_request($segments); - - if (count($segments) == 0) - { - return; - } - - $this->set_class($segments[0]); - - if (isset($segments[1])) - { - // A scaffolding request. No funny business with the URL - if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') - { - $this->scaffolding_request = TRUE; - unset($this->routes['scaffolding_trigger']); - } - else - { - // A standard method request - $this->set_method($segments[1]); - } - } - else - { - // This lets the "routed" segment array identify that the default - // index method is being used. - $segments[1] = 'index'; - } - - // Update our "routed" segment array to contain the segments. - // Note: If there is no custom routing, this array will be - // identical to $this->uri->segments - $this->uri->rsegments = $segments; - } - - // -------------------------------------------------------------------- - - /** - * Validates the supplied segments. Attempts to determine the path to - * the controller. - * - * @access private - * @param array - * @return array - */ - function _validate_request($segments) - { - // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) - { - return $segments; - } - - // Is the controller in a sub-folder? - if (is_dir(APPPATH.'controllers/'.$segments[0])) - { - // Set the directory and remove it from the segment array - $this->set_directory($segments[0]); - $segments = array_slice($segments, 1); - - if (count($segments) > 0) - { - // Does the requested controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) - { - show_404($this->fetch_directory().$segments[0]); - } - } - else - { - $this->set_class($this->default_controller); - $this->set_method('index'); - - // Does the default controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) - { - $this->directory = ''; - return array(); - } - - } - - return $segments; - } - - // Can't find the requested controller... - show_404($segments[0]); - } - - // -------------------------------------------------------------------- - - /** - * Parse Routes - * - * This function matches any routes that may exist in - * the config/routes.php file against the URI to - * determine if the class/method need to be remapped. - * - * @access private - * @return void - */ - function _parse_routes() - { - // Do we even have any custom routing to deal with? - // There is a default scaffolding trigger, so we'll look just for 1 - if (count($this->routes) == 1) - { - $this->_set_request($this->uri->segments); - return; - } - - // Turn the segment array into a URI string - $uri = implode('/', $this->uri->segments); - - // Is there a literal match? If so we're done - if (isset($this->routes[$uri])) - { - $this->_set_request(explode('/', $this->routes[$uri])); - return; - } - - // Loop through the route array looking for wild-cards - foreach ($this->routes as $key => $val) - { - // Convert wild-cards to RegEx - $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); - - // Does the RegEx match? - if (preg_match('#^'.$key.'$#', $uri)) - { - // Do we have a back-reference? - if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) - { - $val = preg_replace('#^'.$key.'$#', $val, $uri); - } - - $this->_set_request(explode('/', $val)); - return; - } - } - - // If we got this far it means we didn't encounter a - // matching route so we'll set the site default route - $this->_set_request($this->uri->segments); - } - - // -------------------------------------------------------------------- - - /** - * Set the class name - * - * @access public - * @param string - * @return void - */ - function set_class($class) - { - $this->class = $class; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the current class - * - * @access public - * @return string - */ - function fetch_class() - { - return $this->class; - } - - // -------------------------------------------------------------------- - - /** - * Set the method name - * - * @access public - * @param string - * @return void - */ - function set_method($method) - { - $this->method = $method; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the current method - * - * @access public - * @return string - */ - function fetch_method() - { - if ($this->method == $this->fetch_class()) - { - return 'index'; - } - - return $this->method; - } - - // -------------------------------------------------------------------- - - /** - * Set the directory name - * - * @access public - * @param string - * @return void - */ - function set_directory($dir) - { - $this->directory = $dir.'/'; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the sub-directory (if any) that contains the requested controller class - * - * @access public - * @return string - */ - function fetch_directory() - { - return $this->directory; - } - -} -// END Router Class - -/* End of file Router.php */ -/* Location: ./system/libraries/Router.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Session.php b/bmt-system/libraries/Session.php deleted file mode 100755 index 660ce8f..0000000 --- a/bmt-system/libraries/Session.php +++ /dev/null @@ -1,758 +0,0 @@ -CI =& get_instance(); - - // Set all the session preferences, which can either be set - // manually via the $params array above or via the config file - foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) - { - $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); - } - - // Load the string helper so we can use the strip_slashes() function - $this->CI->load->helper('string'); - - // Do we need encryption? If so, load the encryption class - if ($this->sess_encrypt_cookie == TRUE) - { - $this->CI->load->library('encrypt'); - } - - // Are we using a database? If so, load it - if ($this->sess_use_database === TRUE AND $this->sess_table_name != '') - { - $this->CI->load->database(); - } - - // Set the "now" time. Can either be GMT or server time, based on the - // config prefs. We use this to set the "last activity" time - $this->now = $this->_get_time(); - - // Set the session length. If the session expiration is - // set to zero we'll set the expiration two years from now. - if ($this->sess_expiration == 0) - { - $this->sess_expiration = (60*60*24*365*2); - } - - // Set the cookie name - $this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name; - - // Run the Session routine. If a session doesn't exist we'll - // create a new one. If it does, we'll update it. - if ( ! $this->sess_read()) - { - $this->sess_create(); - } - else - { - $this->sess_update(); - } - - // Delete 'old' flashdata (from last request) - $this->_flashdata_sweep(); - - // Mark all new flashdata as old (data will be deleted before next request) - $this->_flashdata_mark(); - - // Delete expired sessions if necessary - $this->_sess_gc(); - - log_message('debug', "Session routines successfully run"); - } - - // -------------------------------------------------------------------- - - /** - * Fetch the current session data if it exists - * - * @access public - * @return bool - */ - function sess_read() - { - // Fetch the cookie - $session = $this->CI->input->cookie($this->sess_cookie_name); - - // No cookie? Goodbye cruel world!... - if ($session === FALSE) - { - log_message('debug', 'A session cookie was not found.'); - return FALSE; - } - - // Decrypt the cookie data - if ($this->sess_encrypt_cookie == TRUE) - { - $session = $this->CI->encrypt->decode($session); - } - else - { - // encryption was not used, so we need to check the md5 hash - $hash = substr($session, strlen($session)-32); // get last 32 chars - $session = substr($session, 0, strlen($session)-32); - - // Does the md5 hash match? This is to prevent manipulation of session data in userspace - if ($hash !== md5($session.$this->encryption_key)) - { - log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); - $this->sess_destroy(); - return FALSE; - } - } - - // Unserialize the session array - $session = $this->_unserialize($session); - - // Is the session data we unserialized an array with the correct format? - if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['ip_address']) OR ! isset($session['user_agent']) OR ! isset($session['last_activity'])) - { - $this->sess_destroy(); - return FALSE; - } - - // Is the session current? - if (($session['last_activity'] + $this->sess_expiration) < $this->now) - { - $this->sess_destroy(); - return FALSE; - } - - // Does the IP Match? - if ($this->sess_match_ip == TRUE AND $session['ip_address'] != $this->CI->input->ip_address()) - { - $this->sess_destroy(); - return FALSE; - } - - // Does the User Agent Match? - if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 50))) - { - $this->sess_destroy(); - return FALSE; - } - - // Is there a corresponding session in the DB? - if ($this->sess_use_database === TRUE) - { - $this->CI->db->where('session_id', $session['session_id']); - - if ($this->sess_match_ip == TRUE) - { - $this->CI->db->where('ip_address', $session['ip_address']); - } - - if ($this->sess_match_useragent == TRUE) - { - $this->CI->db->where('user_agent', $session['user_agent']); - } - - $query = $this->CI->db->get($this->sess_table_name); - - // No result? Kill it! - if ($query->num_rows() == 0) - { - $this->sess_destroy(); - return FALSE; - } - - // Is there custom data? If so, add it to the main session array - $row = $query->row(); - if (isset($row->user_data) AND $row->user_data != '') - { - $custom_data = $this->_unserialize($row->user_data); - - if (is_array($custom_data)) - { - foreach ($custom_data as $key => $val) - { - $session[$key] = $val; - } - } - } - } - - // Session is valid! - $this->userdata = $session; - unset($session); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Write the session data - * - * @access public - * @return void - */ - function sess_write() - { - // Are we saving custom data to the DB? If not, all we do is update the cookie - if ($this->sess_use_database === FALSE) - { - $this->_set_cookie(); - return; - } - - // set the custom userdata, the session data we will set in a second - $custom_userdata = $this->userdata; - $cookie_userdata = array(); - - // Before continuing, we need to determine if there is any custom data to deal with. - // Let's determine this by removing the default indexes to see if there's anything left in the array - // and set the session data while we're at it - foreach (array('session_id','ip_address','user_agent','last_activity') as $val) - { - unset($custom_userdata[$val]); - $cookie_userdata[$val] = $this->userdata[$val]; - } - - // Did we find any custom data? If not, we turn the empty array into a string - // since there's no reason to serialize and store an empty array in the DB - if (count($custom_userdata) === 0) - { - $custom_userdata = ''; - } - else - { - // Serialize the custom data array so we can store it - $custom_userdata = $this->_serialize($custom_userdata); - } - - // Run the update query - $this->CI->db->where('session_id', $this->userdata['session_id']); - $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata)); - - // Write the cookie. Notice that we manually pass the cookie data array to the - // _set_cookie() function. Normally that function will store $this->userdata, but - // in this case that array contains custom data, which we do not want in the cookie. - $this->_set_cookie($cookie_userdata); - } - - // -------------------------------------------------------------------- - - /** - * Create a new session - * - * @access public - * @return void - */ - function sess_create() - { - $sessid = ''; - while (strlen($sessid) < 32) - { - $sessid .= mt_rand(0, mt_getrandmax()); - } - - // To make the session ID even more secure we'll combine it with the user's IP - $sessid .= $this->CI->input->ip_address(); - - $this->userdata = array( - 'session_id' => md5(uniqid($sessid, TRUE)), - 'ip_address' => $this->CI->input->ip_address(), - 'user_agent' => substr($this->CI->input->user_agent(), 0, 50), - 'last_activity' => $this->now - ); - - - // Save the data to the DB if needed - if ($this->sess_use_database === TRUE) - { - $this->CI->db->query($this->CI->db->insert_string($this->sess_table_name, $this->userdata)); - } - - // Write the cookie - $this->_set_cookie(); - } - - // -------------------------------------------------------------------- - - /** - * Update an existing session - * - * @access public - * @return void - */ - function sess_update() - { - // We only update the session every five minutes by default - if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now) - { - return; - } - - // Save the old session id so we know which record to - // update in the database if we need it - $old_sessid = $this->userdata['session_id']; - $new_sessid = ''; - while (strlen($new_sessid) < 32) - { - $new_sessid .= mt_rand(0, mt_getrandmax()); - } - - // To make the session ID even more secure we'll combine it with the user's IP - $new_sessid .= $this->CI->input->ip_address(); - - // Turn it into a hash - $new_sessid = md5(uniqid($new_sessid, TRUE)); - - // Update the session data in the session data array - $this->userdata['session_id'] = $new_sessid; - $this->userdata['last_activity'] = $this->now; - - // _set_cookie() will handle this for us if we aren't using database sessions - // by pushing all userdata to the cookie. - $cookie_data = NULL; - - // Update the session ID and last_activity field in the DB if needed - if ($this->sess_use_database === TRUE) - { - // set cookie explicitly to only have our session data - $cookie_data = array(); - foreach (array('session_id','ip_address','user_agent','last_activity') as $val) - { - $cookie_data[$val] = $this->userdata[$val]; - } - - $this->CI->db->query($this->CI->db->update_string($this->sess_table_name, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid))); - } - - // Write the cookie - $this->_set_cookie($cookie_data); - } - - // -------------------------------------------------------------------- - - /** - * Destroy the current session - * - * @access public - * @return void - */ - function sess_destroy() - { - // Kill the session DB row - if ($this->sess_use_database === TRUE AND isset($this->userdata['session_id'])) - { - $this->CI->db->where('session_id', $this->userdata['session_id']); - $this->CI->db->delete($this->sess_table_name); - } - - // Kill the cookie - setcookie( - $this->sess_cookie_name, - addslashes(serialize(array())), - ($this->now - 31500000), - $this->cookie_path, - $this->cookie_domain, - 0 - ); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a specific item from the session array - * - * @access public - * @param string - * @return string - */ - function userdata($item) - { - return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch all session data - * - * @access public - * @return mixed - */ - function all_userdata() - { - return ( ! isset($this->userdata)) ? FALSE : $this->userdata; - } - - // -------------------------------------------------------------------- - - /** - * Add or change data in the "userdata" array - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_userdata($newdata = array(), $newval = '') - { - if (is_string($newdata)) - { - $newdata = array($newdata => $newval); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - $this->userdata[$key] = $val; - } - } - - $this->sess_write(); - } - - // -------------------------------------------------------------------- - - /** - * Delete a session variable from the "userdata" array - * - * @access array - * @return void - */ - function unset_userdata($newdata = array()) - { - if (is_string($newdata)) - { - $newdata = array($newdata => ''); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - unset($this->userdata[$key]); - } - } - - $this->sess_write(); - } - - // ------------------------------------------------------------------------ - - /** - * Add or change flashdata, only available - * until the next request - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_flashdata($newdata = array(), $newval = '') - { - if (is_string($newdata)) - { - $newdata = array($newdata => $newval); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - $flashdata_key = $this->flashdata_key.':new:'.$key; - $this->set_userdata($flashdata_key, $val); - } - } - } - - // ------------------------------------------------------------------------ - - /** - * Keeps existing flashdata available to next request. - * - * @access public - * @param string - * @return void - */ - function keep_flashdata($key) - { - // 'old' flashdata gets removed. Here we mark all - // flashdata as 'new' to preserve it from _flashdata_sweep() - // Note the function will return FALSE if the $key - // provided cannot be found - $old_flashdata_key = $this->flashdata_key.':old:'.$key; - $value = $this->userdata($old_flashdata_key); - - $new_flashdata_key = $this->flashdata_key.':new:'.$key; - $this->set_userdata($new_flashdata_key, $value); - } - - // ------------------------------------------------------------------------ - - /** - * Fetch a specific flashdata item from the session array - * - * @access public - * @param string - * @return string - */ - function flashdata($key) - { - $flashdata_key = $this->flashdata_key.':old:'.$key; - return $this->userdata($flashdata_key); - } - - // ------------------------------------------------------------------------ - - /** - * Identifies flashdata as 'old' for removal - * when _flashdata_sweep() runs. - * - * @access private - * @return void - */ - function _flashdata_mark() - { - $userdata = $this->all_userdata(); - foreach ($userdata as $name => $value) - { - $parts = explode(':new:', $name); - if (is_array($parts) && count($parts) === 2) - { - $new_name = $this->flashdata_key.':old:'.$parts[1]; - $this->set_userdata($new_name, $value); - $this->unset_userdata($name); - } - } - } - - // ------------------------------------------------------------------------ - - /** - * Removes all flashdata marked as 'old' - * - * @access private - * @return void - */ - - function _flashdata_sweep() - { - $userdata = $this->all_userdata(); - foreach ($userdata as $key => $value) - { - if (strpos($key, ':old:')) - { - $this->unset_userdata($key); - } - } - - } - - // -------------------------------------------------------------------- - - /** - * Get the "now" time - * - * @access private - * @return string - */ - function _get_time() - { - if (strtolower($this->time_reference) == 'gmt') - { - $now = time(); - $time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - } - else - { - $time = time(); - } - - return $time; - } - - // -------------------------------------------------------------------- - - /** - * Write the session cookie - * - * @access public - * @return void - */ - function _set_cookie($cookie_data = NULL) - { - if (is_null($cookie_data)) - { - $cookie_data = $this->userdata; - } - - // Serialize the userdata for the cookie - $cookie_data = $this->_serialize($cookie_data); - - if ($this->sess_encrypt_cookie == TRUE) - { - $cookie_data = $this->CI->encrypt->encode($cookie_data); - } - else - { - // if encryption is not used, we provide an md5 hash to prevent userside tampering - $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key); - } - - // Set the cookie - setcookie( - $this->sess_cookie_name, - $cookie_data, - $this->sess_expiration + time(), - $this->cookie_path, - $this->cookie_domain, - 0 - ); - } - - // -------------------------------------------------------------------- - - /** - * Serialize an array - * - * This function first converts any slashes found in the array to a temporary - * marker, so when it gets unserialized the slashes will be preserved - * - * @access private - * @param array - * @return string - */ - function _serialize($data) - { - if (is_array($data)) - { - foreach ($data as $key => $val) - { - $data[$key] = str_replace('\\', '{{slash}}', $val); - } - } - else - { - $data = str_replace('\\', '{{slash}}', $data); - } - - return serialize($data); - } - - // -------------------------------------------------------------------- - - /** - * Unserialize - * - * This function unserializes a data string, then converts any - * temporary slash markers back to actual slashes - * - * @access private - * @param array - * @return string - */ - function _unserialize($data) - { - $data = @unserialize(strip_slashes($data)); - - if (is_array($data)) - { - foreach ($data as $key => $val) - { - $data[$key] = str_replace('{{slash}}', '\\', $val); - } - - return $data; - } - - return str_replace('{{slash}}', '\\', $data); - } - - // -------------------------------------------------------------------- - - /** - * Garbage collection - * - * This deletes expired session rows from database - * if the probability percentage is met - * - * @access public - * @return void - */ - function _sess_gc() - { - if ($this->sess_use_database != TRUE) - { - return; - } - - srand(time()); - if ((rand() % 100) < $this->gc_probability) - { - $expire = $this->now - $this->sess_expiration; - - $this->CI->db->where("last_activity < {$expire}"); - $this->CI->db->delete($this->sess_table_name); - - log_message('debug', 'Session garbage collection performed.'); - } - } - - -} -// END Session Class - -/* End of file Session.php */ -/* Location: ./system/libraries/Session.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Sha1.php b/bmt-system/libraries/Sha1.php deleted file mode 100755 index cc6e212..0000000 --- a/bmt-system/libraries/Sha1.php +++ /dev/null @@ -1,251 +0,0 @@ -> 6) + 1; - - for ($i = 0; $i < $n * 16; $i++) - { - $x[$i] = 0; - } - - for ($i = 0; $i < strlen($str); $i++) - { - $x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8); - } - - $x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); - - $x[$n * 16 - 1] = strlen($str) * 8; - - $a = 1732584193; - $b = -271733879; - $c = -1732584194; - $d = 271733878; - $e = -1009589776; - - for ($i = 0; $i < count($x); $i += 16) - { - $olda = $a; - $oldb = $b; - $oldc = $c; - $oldd = $d; - $olde = $e; - - for($j = 0; $j < 80; $j++) - { - if ($j < 16) - { - $w[$j] = $x[$i + $j]; - } - else - { - $w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); - } - - $t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j))); - - $e = $d; - $d = $c; - $c = $this->_rol($b, 30); - $b = $a; - $a = $t; - } - - $a = $this->_safe_add($a, $olda); - $b = $this->_safe_add($b, $oldb); - $c = $this->_safe_add($c, $oldc); - $d = $this->_safe_add($d, $oldd); - $e = $this->_safe_add($e, $olde); - } - - return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); - } - - // -------------------------------------------------------------------- - - /** - * Convert a decimal to hex - * - * @access private - * @param string - * @return string - */ - function _hex($str) - { - $str = dechex($str); - - if (strlen($str) == 7) - { - $str = '0'.$str; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Return result based on iteration - * - * @access private - * @return string - */ - function _ft($t, $b, $c, $d) - { - if ($t < 20) - return ($b & $c) | ((~$b) & $d); - if ($t < 40) - return $b ^ $c ^ $d; - if ($t < 60) - return ($b & $c) | ($b & $d) | ($c & $d); - - return $b ^ $c ^ $d; - } - - // -------------------------------------------------------------------- - - /** - * Determine the additive constant - * - * @access private - * @return string - */ - function _kt($t) - { - if ($t < 20) - { - return 1518500249; - } - else if ($t < 40) - { - return 1859775393; - } - else if ($t < 60) - { - return -1894007588; - } - else - { - return -899497514; - } - } - - // -------------------------------------------------------------------- - - /** - * Add integers, wrapping at 2^32 - * - * @access private - * @return string - */ - function _safe_add($x, $y) - { - $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); - $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); - - return ($msw << 16) | ($lsw & 0xFFFF); - } - - // -------------------------------------------------------------------- - - /** - * Bitwise rotate a 32-bit number - * - * @access private - * @return integer - */ - function _rol($num, $cnt) - { - return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt); - } - - // -------------------------------------------------------------------- - - /** - * Pad string with zero - * - * @access private - * @return string - */ - function _zero_fill($a, $b) - { - $bin = decbin($a); - - if (strlen($bin) < $b) - { - $bin = 0; - } - else - { - $bin = substr($bin, 0, strlen($bin) - $b); - } - - for ($i=0; $i < $b; $i++) - { - $bin = "0".$bin; - } - - return bindec($bin); - } -} -// END CI_SHA - -/* End of file Sha1.php */ -/* Location: ./system/libraries/Sha1.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Table.php b/bmt-system/libraries/Table.php deleted file mode 100755 index 1afc17c..0000000 --- a/bmt-system/libraries/Table.php +++ /dev/null @@ -1,440 +0,0 @@ -template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Set the table heading - * - * Can be passed as an array or discreet params - * - * @access public - * @param mixed - * @return void - */ - function set_heading() - { - $args = func_get_args(); - $this->heading = (is_array($args[0])) ? $args[0] : $args; - } - - // -------------------------------------------------------------------- - - /** - * Set columns. Takes a one-dimensional array as input and creates - * a multi-dimensional array with a depth equal to the number of - * columns. This allows a single array with many elements to be - * displayed in a table that has a fixed column count. - * - * @access public - * @param array - * @param int - * @return void - */ - function make_columns($array = array(), $col_limit = 0) - { - if ( ! is_array($array) OR count($array) == 0) - { - return FALSE; - } - - // Turn off the auto-heading feature since it's doubtful we - // will want headings from a one-dimensional array - $this->auto_heading = FALSE; - - if ($col_limit == 0) - { - return $array; - } - - $new = array(); - while(count($array) > 0) - { - $temp = array_splice($array, 0, $col_limit); - - if (count($temp) < $col_limit) - { - for ($i = count($temp); $i < $col_limit; $i++) - { - $temp[] = ' '; - } - } - - $new[] = $temp; - } - - return $new; - } - - // -------------------------------------------------------------------- - - /** - * Set "empty" cells - * - * Can be passed as an array or discreet params - * - * @access public - * @param mixed - * @return void - */ - function set_empty($value) - { - $this->empty_cells = $value; - } - - // -------------------------------------------------------------------- - - /** - * Add a table row - * - * Can be passed as an array or discreet params - * - * @access public - * @param mixed - * @return void - */ - function add_row() - { - $args = func_get_args(); - $this->rows[] = (is_array($args[0])) ? $args[0] : $args; - } - - // -------------------------------------------------------------------- - - /** - * Add a table caption - * - * @access public - * @param string - * @return void - */ - function set_caption($caption) - { - $this->caption = $caption; - } - - // -------------------------------------------------------------------- - - /** - * Generate the table - * - * @access public - * @param mixed - * @return string - */ - function generate($table_data = NULL) - { - // The table data can optionally be passed to this function - // either as a database result object or an array - if ( ! is_null($table_data)) - { - if (is_object($table_data)) - { - $this->_set_from_object($table_data); - } - elseif (is_array($table_data)) - { - $set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE; - $this->_set_from_array($table_data, $set_heading); - } - } - - // Is there anything to display? No? Smite them! - if (count($this->heading) == 0 AND count($this->rows) == 0) - { - return 'Undefined table data'; - } - - // Compile and validate the template date - $this->_compile_template(); - - - // Build the table! - - $out = $this->template['table_open']; - $out .= $this->newline; - - // Add any caption here - if ($this->caption) - { - $out .= $this->newline; - $out .= '' . $this->caption . ''; - $out .= $this->newline; - } - - // Is there a table heading to display? - if (count($this->heading) > 0) - { - $out .= $this->template['heading_row_start']; - $out .= $this->newline; - - foreach($this->heading as $heading) - { - $out .= $this->template['heading_cell_start']; - $out .= $heading; - $out .= $this->template['heading_cell_end']; - } - - $out .= $this->template['heading_row_end']; - $out .= $this->newline; - } - - // Build the table rows - if (count($this->rows) > 0) - { - $i = 1; - foreach($this->rows as $row) - { - if ( ! is_array($row)) - { - break; - } - - // We use modulus to alternate the row colors - $name = (fmod($i++, 2)) ? '' : 'alt_'; - - $out .= $this->template['row_'.$name.'start']; - $out .= $this->newline; - - foreach($row as $cell) - { - $out .= $this->template['cell_'.$name.'start']; - - if ($cell === "") - { - $out .= $this->empty_cells; - } - else - { - $out .= $cell; - } - - $out .= $this->template['cell_'.$name.'end']; - } - - $out .= $this->template['row_'.$name.'end']; - $out .= $this->newline; - } - } - - $out .= $this->template['table_close']; - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Clears the table arrays. Useful if multiple tables are being generated - * - * @access public - * @return void - */ - function clear() - { - $this->rows = array(); - $this->heading = array(); - $this->auto_heading = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set table data from a database result object - * - * @access public - * @param object - * @return void - */ - function _set_from_object($query) - { - if ( ! is_object($query)) - { - return FALSE; - } - - // First generate the headings from the table column names - if (count($this->heading) == 0) - { - if ( ! method_exists($query, 'list_fields')) - { - return FALSE; - } - - $this->heading = $query->list_fields(); - } - - // Next blast through the result array and build out the rows - - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $this->rows[] = $row; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set table data from an array - * - * @access public - * @param array - * @return void - */ - function _set_from_array($data, $set_heading = TRUE) - { - if ( ! is_array($data) OR count($data) == 0) - { - return FALSE; - } - - $i = 0; - foreach ($data as $row) - { - if ( ! is_array($row)) - { - $this->rows[] = $data; - break; - } - - // If a heading hasn't already been set we'll use the first row of the array as the heading - if ($i == 0 AND count($data) > 1 AND count($this->heading) == 0 AND $set_heading == TRUE) - { - $this->heading = $row; - } - else - { - $this->rows[] = $row; - } - - $i++; - } - } - - // -------------------------------------------------------------------- - - /** - * Compile Template - * - * @access private - * @return void - */ - function _compile_template() - { - if ($this->template == NULL) - { - $this->template = $this->_default_template(); - return; - } - - $this->temp = $this->_default_template(); - foreach (array('table_open','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val) - { - if ( ! isset($this->template[$val])) - { - $this->template[$val] = $this->temp[$val]; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Default Template - * - * @access private - * @return void - */ - function _default_template() - { - return array ( - 'table_open' => '', - - 'heading_row_start' => '', - 'heading_row_end' => '', - 'heading_cell_start' => '', - - 'row_start' => '', - 'row_end' => '', - 'cell_start' => '', - - 'row_alt_start' => '', - 'row_alt_end' => '', - 'cell_alt_start' => '', - - 'table_close' => '
    ', - 'heading_cell_end' => '
    ', - 'cell_end' => '
    ', - 'cell_alt_end' => '
    ' - ); - } - - -} - - -/* End of file Table.php */ -/* Location: ./system/libraries/Table.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Trackback.php b/bmt-system/libraries/Trackback.php deleted file mode 100755 index 844e503..0000000 --- a/bmt-system/libraries/Trackback.php +++ /dev/null @@ -1,550 +0,0 @@ - '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); - var $convert_ascii = TRUE; - var $response = ''; - var $error_msg = array(); - - /** - * Constructor - * - * @access public - */ - function CI_Trackback() - { - log_message('debug', "Trackback Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Send Trackback - * - * @access public - * @param array - * @return bool - */ - function send($tb_data) - { - if ( ! is_array($tb_data)) - { - $this->set_error('The send() method must be passed an array'); - return FALSE; - } - - // Pre-process the Trackback Data - foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item) - { - if ( ! isset($tb_data[$item])) - { - $this->set_error('Required item missing: '.$item); - return FALSE; - } - - switch ($item) - { - case 'ping_url' : $$item = $this->extract_urls($tb_data[$item]); - break; - case 'excerpt' : $$item = $this->limit_characters($this->convert_xml(strip_tags(stripslashes($tb_data[$item])))); - break; - case 'url' : $$item = str_replace('-', '-', $this->convert_xml(strip_tags(stripslashes($tb_data[$item])))); - break; - default : $$item = $this->convert_xml(strip_tags(stripslashes($tb_data[$item]))); - break; - } - - // Convert High ASCII Characters - if ($this->convert_ascii == TRUE) - { - if ($item == 'excerpt') - { - $$item = $this->convert_ascii($$item); - } - elseif ($item == 'title') - { - $$item = $this->convert_ascii($$item); - } - elseif($item == 'blog_name') - { - $$item = $this->convert_ascii($$item); - } - } - } - - // Build the Trackback data string - $charset = ( ! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset']; - - $data = "url=".rawurlencode($url)."&title=".rawurlencode($title)."&blog_name=".rawurlencode($blog_name)."&excerpt=".rawurlencode($excerpt)."&charset=".rawurlencode($charset); - - // Send Trackback(s) - $return = TRUE; - if (count($ping_url) > 0) - { - foreach ($ping_url as $url) - { - if ($this->process($url, $data) == FALSE) - { - $return = FALSE; - } - } - } - - return $return; - } - - // -------------------------------------------------------------------- - - /** - * Receive Trackback Data - * - * This function simply validates the incoming TB data. - * It returns false on failure and true on success. - * If the data is valid it is set to the $this->data array - * so that it can be inserted into a database. - * - * @access public - * @return bool - */ - function receive() - { - foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) - { - if ( ! isset($_POST[$val]) OR $_POST[$val] == '') - { - $this->set_error('The following required POST variable is missing: '.$val); - return FALSE; - } - - $this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset'])); - - if ($val != 'url' && function_exists('mb_convert_encoding')) - { - $_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']); - } - - $_POST[$val] = ($val != 'url') ? $this->convert_xml(strip_tags($_POST[$val])) : strip_tags($_POST[$val]); - - if ($val == 'excerpt') - { - $_POST['excerpt'] = $this->limit_characters($_POST['excerpt']); - } - - $this->data[$val] = $_POST[$val]; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Send Trackback Error Message - * - * Allows custom errors to be set. By default it - * sends the "incomplete information" error, as that's - * the most common one. - * - * @access public - * @param string - * @return void - */ - function send_error($message = 'Incomplete Information') - { - echo "\n\n1\n".$message."\n"; - exit; - } - - // -------------------------------------------------------------------- - - /** - * Send Trackback Success Message - * - * This should be called when a trackback has been - * successfully received and inserted. - * - * @access public - * @return void - */ - function send_success() - { - echo "\n\n0\n"; - exit; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a particular item - * - * @access public - * @param string - * @return string - */ - function data($item) - { - return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; - } - - // -------------------------------------------------------------------- - - /** - * Process Trackback - * - * Opens a socket connection and passes the data to - * the server. Returns true on success, false on failure - * - * @access public - * @param string - * @param string - * @return bool - */ - function process($url, $data) - { - $target = parse_url($url); - - // Open the socket - if ( ! $fp = @fsockopen($target['host'], 80)) - { - $this->set_error('Invalid Connection: '.$url); - return FALSE; - } - - // Build the path - $ppath = ( ! isset($target['path'])) ? $url : $target['path']; - - $path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath; - - // Add the Trackback ID to the data string - if ($id = $this->get_id($url)) - { - $data = "tb_id=".$id."&".$data; - } - - // Transfer the data - fputs ($fp, "POST " . $path . " HTTP/1.0\r\n" ); - fputs ($fp, "Host: " . $target['host'] . "\r\n" ); - fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n" ); - fputs ($fp, "Content-length: " . strlen($data) . "\r\n" ); - fputs ($fp, "Connection: close\r\n\r\n" ); - fputs ($fp, $data); - - // Was it successful? - $this->response = ""; - - while( ! feof($fp)) - { - $this->response .= fgets($fp, 128); - } - @fclose($fp); - - if ( ! eregi("0", $this->response)) - { - $message = 'An unknown error was encountered'; - - if (preg_match("/(.*?)<\/message>/is", $this->response, $match)) - { - $message = trim($match['1']); - } - - $this->set_error($message); - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Extract Trackback URLs - * - * This function lets multiple trackbacks be sent. - * It takes a string of URLs (separated by comma or - * space) and puts each URL into an array - * - * @access public - * @param string - * @return string - */ - function extract_urls($urls) - { - // Remove the pesky white space and replace with a comma. - $urls = preg_replace("/\s*(\S+)\s*/", "\\1,", $urls); - - // If they use commas get rid of the doubles. - $urls = str_replace(",,", ",", $urls); - - // Remove any comma that might be at the end - if (substr($urls, -1) == ",") - { - $urls = substr($urls, 0, -1); - } - - // Break into an array via commas - $urls = preg_split('/[,]/', $urls); - - // Removes duplicates - $urls = array_unique($urls); - - array_walk($urls, array($this, 'validate_url')); - - return $urls; - } - - // -------------------------------------------------------------------- - - /** - * Validate URL - * - * Simply adds "http://" if missing - * - * @access public - * @param string - * @return string - */ - function validate_url($url) - { - $url = trim($url); - - if (substr($url, 0, 4) != "http") - { - $url = "http://".$url; - } - } - - // -------------------------------------------------------------------- - - /** - * Find the Trackback URL's ID - * - * @access public - * @param string - * @return string - */ - function get_id($url) - { - $tb_id = ""; - - if (strstr($url, '?')) - { - $tb_array = explode('/', $url); - $tb_end = $tb_array[count($tb_array)-1]; - - if ( ! is_numeric($tb_end)) - { - $tb_end = $tb_array[count($tb_array)-2]; - } - - $tb_array = explode('=', $tb_end); - $tb_id = $tb_array[count($tb_array)-1]; - } - else - { - if (ereg("/$", $url)) - { - $url = substr($url, 0, -1); - } - - $tb_array = explode('/', $url); - $tb_id = $tb_array[count($tb_array)-1]; - - if ( ! is_numeric($tb_id)) - { - $tb_id = $tb_array[count($tb_array)-2]; - } - } - - if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) - { - return false; - } - else - { - return $tb_id; - } - } - - // -------------------------------------------------------------------- - - /** - * Convert Reserved XML characters to Entities - * - * @access public - * @param string - * @return string - */ - function convert_xml($str) - { - $temp = '__TEMP_AMPERSANDS__'; - - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - - $str = str_replace(array("&","<",">","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); - - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Character limiter - * - * Limits the string based on the character count. Will preserve complete words. - * - * @access public - * @param string - * @param integer - * @param string - * @return string - */ - function limit_characters($str, $n = 500, $end_char = '…') - { - if (strlen($str) < $n) - { - return $str; - } - - $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); - - if (strlen($str) <= $n) - { - return $str; - } - - $out = ""; - foreach (explode(' ', trim($str)) as $val) - { - $out .= $val.' '; - if (strlen($out) >= $n) - { - return trim($out).$end_char; - } - } - } - - // -------------------------------------------------------------------- - - /** - * High ASCII to Entities - * - * Converts Hight ascii text and MS Word special chars - * to character entities - * - * @access public - * @param string - * @return string - */ - function convert_ascii($str) - { - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) - { - $ordinal = ord($str[$i]); - - if ($ordinal < 128) - { - $out .= $str[$i]; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - - $out .= '&#'.$number.';'; - $count = 1; - $temp = array(); - } - } - } - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Set error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - log_message('error', $msg); - $this->error_msg[] = $msg; - } - - // -------------------------------------------------------------------- - - /** - * Show error messages - * - * @access public - * @param string - * @param string - * @return string - */ - function display_errors($open = '

    ', $close = '

    ') - { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; - } - -} -// END Trackback Class - -/* End of file Trackback.php */ -/* Location: ./system/libraries/Trackback.php */ \ No newline at end of file diff --git a/bmt-system/libraries/URI.php b/bmt-system/libraries/URI.php deleted file mode 100755 index bcdc038..0000000 --- a/bmt-system/libraries/URI.php +++ /dev/null @@ -1,586 +0,0 @@ -config =& load_class('Config'); - log_message('debug', "URI Class Initialized"); - } - - - // -------------------------------------------------------------------- - - /** - * Get the URI String - * - * @access private - * @return string - */ - function _fetch_uri_string() - { - if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') - { - // If the URL has a question mark then it's simplest to just - // build the URI string from the zero index of the $_GET array. - // This avoids having to deal with $_SERVER variables, which - // can be unreliable in some environments - if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') - { - $this->uri_string = key($_GET); - return; - } - - // Is there a PATH_INFO variable? - // Note: some servers seem to have trouble with getenv() so we'll test it two ways - $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - if (trim($path, '/') != '' && $path != "/".SELF) - { - $this->uri_string = $path; - return; - } - - // No PATH_INFO?... What about QUERY_STRING? - $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - if (trim($path, '/') != '') - { - $this->uri_string = $path; - return; - } - - // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? - $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if (trim($path, '/') != '' && $path != "/".SELF) - { - // remove path and script information so we have good URI data - $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path); - return; - } - - // We've exhausted all our options... - $this->uri_string = ''; - } - else - { - $uri = strtoupper($this->config->item('uri_protocol')); - - if ($uri == 'REQUEST_URI') - { - $this->uri_string = $this->_parse_request_uri(); - return; - } - - $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); - } - - // If the URI contains only a slash we'll kill it - if ($this->uri_string == '/') - { - $this->uri_string = ''; - } - } - - // -------------------------------------------------------------------- - - /** - * Parse the REQUEST_URI - * - * Due to the way REQUEST_URI works it usually contains path info - * that makes it unusable as URI data. We'll trim off the unnecessary - * data, hopefully arriving at a valid URI that we can use. - * - * @access private - * @return string - */ - function _parse_request_uri() - { - if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') - { - return ''; - } - - $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - - if ($request_uri == '' OR $request_uri == SELF) - { - return ''; - } - - $fc_path = FCPATH; - if (strpos($request_uri, '?') !== FALSE) - { - $fc_path .= '?'; - } - - $parsed_uri = explode("/", $request_uri); - - $i = 0; - foreach(explode("/", $fc_path) as $segment) - { - if (isset($parsed_uri[$i]) && $segment == $parsed_uri[$i]) - { - $i++; - } - } - - $parsed_uri = implode("/", array_slice($parsed_uri, $i)); - - if ($parsed_uri != '') - { - $parsed_uri = '/'.$parsed_uri; - } - - return $parsed_uri; - } - - // -------------------------------------------------------------------- - - /** - * Filter segments for malicious characters - * - * @access private - * @param string - * @return string - */ - function _filter_uri($str) - { - if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) - { - //if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) - if ( ! preg_match("|^[\w".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) - { - header('HTTP/1.1 400 Bad Request'); - show_error('The URI you submitted has disallowed characters.'); - } - } - - // Convert programatic characters to entities - $bad = array('$', '(', ')', '%28', '%29'); - $good = array('$', '(', ')', '(', ')'); - - return str_replace($bad, $good, $str); - } - - // -------------------------------------------------------------------- - - /** - * Remove the suffix from the URL if needed - * - * @access private - * @return void - */ - function _remove_url_suffix() - { - if ($this->config->item('url_suffix') != "") - { - $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); - } - } - - // -------------------------------------------------------------------- - - /** - * Explode the URI Segments. The individual segments will - * be stored in the $this->segments array. - * - * @access private - * @return void - */ - function _explode_segments() - { - foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) - { - // Filter segments for security - $val = trim($this->_filter_uri($val)); - - if ($val != '') - { - $this->segments[] = $val; - } - } - } - - // -------------------------------------------------------------------- - /** - * Re-index Segments - * - * This function re-indexes the $this->segment array so that it - * starts at 1 rather than 0. Doing so makes it simpler to - * use functions like $this->uri->segment(n) since there is - * a 1:1 relationship between the segment array and the actual segments. - * - * @access private - * @return void - */ - function _reindex_segments() - { - array_unshift($this->segments, NULL); - array_unshift($this->rsegments, NULL); - unset($this->segments[0]); - unset($this->rsegments[0]); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment - * - * This function returns the URI segment based on the number provided. - * - * @access public - * @param integer - * @param bool - * @return string - */ - function segment($n, $no_result = FALSE) - { - return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI "routed" Segment - * - * This function returns the re-routed URI segment (assuming routing rules are used) - * based on the number provided. If there is no routing this function returns the - * same result as $this->segment() - * - * @access public - * @param integer - * @param bool - * @return string - */ - function rsegment($n, $no_result = FALSE) - { - return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; - } - - // -------------------------------------------------------------------- - - /** - * Generate a key value pair from the URI string - * - * This function generates and associative array of URI data starting - * at the supplied segment. For example, if this is your URI: - * - * example.com/user/search/name/joe/location/UK/gender/male - * - * You can use this function to generate an array with this prototype: - * - * array ( - * name => joe - * location => UK - * gender => male - * ) - * - * @access public - * @param integer the starting segment number - * @param array an array of default values - * @return array - */ - function uri_to_assoc($n = 3, $default = array()) - { - return $this->_uri_to_assoc($n, $default, 'segment'); - } - /** - * Identical to above only it uses the re-routed segment array - * - */ - function ruri_to_assoc($n = 3, $default = array()) - { - return $this->_uri_to_assoc($n, $default, 'rsegment'); - } - - // -------------------------------------------------------------------- - - /** - * Generate a key value pair from the URI string or Re-routed URI string - * - * @access private - * @param integer the starting segment number - * @param array an array of default values - * @param string which array we should use - * @return array - */ - function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') - { - if ($which == 'segment') - { - $total_segments = 'total_segments'; - $segment_array = 'segment_array'; - } - else - { - $total_segments = 'total_rsegments'; - $segment_array = 'rsegment_array'; - } - - if ( ! is_numeric($n)) - { - return $default; - } - - if (isset($this->keyval[$n])) - { - return $this->keyval[$n]; - } - - if ($this->$total_segments() < $n) - { - if (count($default) == 0) - { - return array(); - } - - $retval = array(); - foreach ($default as $val) - { - $retval[$val] = FALSE; - } - return $retval; - } - - $segments = array_slice($this->$segment_array(), ($n - 1)); - - $i = 0; - $lastval = ''; - $retval = array(); - foreach ($segments as $seg) - { - if ($i % 2) - { - $retval[$lastval] = $seg; - } - else - { - $retval[$seg] = FALSE; - $lastval = $seg; - } - - $i++; - } - - if (count($default) > 0) - { - foreach ($default as $val) - { - if ( ! array_key_exists($val, $retval)) - { - $retval[$val] = FALSE; - } - } - } - - // Cache the array for reuse - $this->keyval[$n] = $retval; - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Generate a URI string from an associative array - * - * - * @access public - * @param array an associative array of key/values - * @return array - */ - function assoc_to_uri($array) - { - $temp = array(); - foreach ((array)$array as $key => $val) - { - $temp[] = $key; - $temp[] = $val; - } - - return implode('/', $temp); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment and add a trailing slash - * - * @access public - * @param integer - * @param string - * @return string - */ - function slash_segment($n, $where = 'trailing') - { - return $this->_slash_segment($n, $where, 'segment'); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment and add a trailing slash - * - * @access public - * @param integer - * @param string - * @return string - */ - function slash_rsegment($n, $where = 'trailing') - { - return $this->_slash_segment($n, $where, 'rsegment'); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment and add a trailing slash - helper function - * - * @access private - * @param integer - * @param string - * @param string - * @return string - */ - function _slash_segment($n, $where = 'trailing', $which = 'segment') - { - if ($where == 'trailing') - { - $trailing = '/'; - $leading = ''; - } - elseif ($where == 'leading') - { - $leading = '/'; - $trailing = ''; - } - else - { - $leading = '/'; - $trailing = '/'; - } - return $leading.$this->$which($n).$trailing; - } - - // -------------------------------------------------------------------- - - /** - * Segment Array - * - * @access public - * @return array - */ - function segment_array() - { - return $this->segments; - } - - // -------------------------------------------------------------------- - - /** - * Routed Segment Array - * - * @access public - * @return array - */ - function rsegment_array() - { - return $this->rsegments; - } - - // -------------------------------------------------------------------- - - /** - * Total number of segments - * - * @access public - * @return integer - */ - function total_segments() - { - return count($this->segments); - } - - // -------------------------------------------------------------------- - - /** - * Total number of routed segments - * - * @access public - * @return integer - */ - function total_rsegments() - { - return count($this->rsegments); - } - - // -------------------------------------------------------------------- - - /** - * Fetch the entire URI string - * - * @access public - * @return string - */ - function uri_string() - { - return $this->uri_string; - } - - - // -------------------------------------------------------------------- - - /** - * Fetch the entire Re-routed URI string - * - * @access public - * @return string - */ - function ruri_string() - { - return '/'.implode('/', $this->rsegment_array()).'/'; - } - -} -// END URI Class - -/* End of file URI.php */ -/* Location: ./system/libraries/URI.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Unit_test.php b/bmt-system/libraries/Unit_test.php deleted file mode 100755 index a5aa381..0000000 --- a/bmt-system/libraries/Unit_test.php +++ /dev/null @@ -1,347 +0,0 @@ -active == FALSE) - { - return FALSE; - } - - if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) - { - $expected = str_replace('is_float', 'is_double', $expected); - $result = ($expected($test)) ? TRUE : FALSE; - $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); - } - else - { - if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; - else - $result = ($test == $expected) ? TRUE : FALSE; - - $extype = gettype($expected); - } - - $back = $this->_backtrace(); - - $report[] = array ( - 'test_name' => $test_name, - 'test_datatype' => gettype($test), - 'res_datatype' => $extype, - 'result' => ($result === TRUE) ? 'passed' : 'failed', - 'file' => $back['file'], - 'line' => $back['line'] - ); - - $this->results[] = $report; - - return($this->report($this->result($report))); - } - - // -------------------------------------------------------------------- - - /** - * Generate a report - * - * Displays a table with the test data - * - * @access public - * @return string - */ - function report($result = array()) - { - if (count($result) == 0) - { - $result = $this->result(); - } - - $CI =& get_instance(); - $CI->load->language('unit_test'); - - $this->_parse_template(); - - $r = ''; - foreach ($result as $res) - { - $table = ''; - - foreach ($res as $key => $val) - { - - if ($key == $CI->lang->line('ut_result')) - { - if ($val == $CI->lang->line('ut_passed')) - { - $val = ''.$val.''; - } - elseif ($val == $CI->lang->line('ut_failed')) - { - $val = ''.$val.''; - } - } - - $temp = $this->_template_rows; - $temp = str_replace('{item}', $key, $temp); - $temp = str_replace('{result}', $val, $temp); - $table .= $temp; - } - - $r .= str_replace('{rows}', $table, $this->_template); - } - - return $r; - } - - // -------------------------------------------------------------------- - - /** - * Use strict comparison - * - * Causes the evaluation to use === rather than == - * - * @access public - * @param bool - * @return null - */ - function use_strict($state = TRUE) - { - $this->strict = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Make Unit testing active - * - * Enables/disables unit testing - * - * @access public - * @param bool - * @return null - */ - function active($state = TRUE) - { - $this->active = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Result Array - * - * Returns the raw result data - * - * @access public - * @return array - */ - function result($results = array()) - { - $CI =& get_instance(); - $CI->load->language('unit_test'); - - if (count($results) == 0) - { - $results = $this->results; - } - - $retval = array(); - foreach ($results as $result) - { - $temp = array(); - foreach ($result as $key => $val) - { - if (is_array($val)) - { - foreach ($val as $k => $v) - { - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) - { - $v = $line; - } - $temp[$CI->lang->line('ut_'.$k)] = $v; - } - } - else - { - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) - { - $val = $line; - } - $temp[$CI->lang->line('ut_'.$key)] = $val; - } - } - - $retval[] = $temp; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Set the template - * - * This lets us set the template to be used to display results - * - * @access public - * @param string - * @return void - */ - function set_template($template) - { - $this->_template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Generate a backtrace - * - * This lets us show file names and line numbers - * - * @access private - * @return array - */ - function _backtrace() - { - if (function_exists('debug_backtrace')) - { - $back = debug_backtrace(); - - $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; - $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; - - return array('file' => $file, 'line' => $line); - } - return array('file' => 'Unknown', 'line' => 'Unknown'); - } - - // -------------------------------------------------------------------- - - /** - * Get Default Template - * - * @access private - * @return string - */ - function _default_template() - { - $this->_template = "\n".''; - $this->_template .= '{rows}'; - $this->_template .= "\n".'
    '; - - $this->_template_rows = "\n\t".''; - $this->_template_rows .= "\n\t\t".'{item}'; - $this->_template_rows .= "\n\t\t".'{result}'; - $this->_template_rows .= "\n\t".''; - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * - * @access private - * @return void - */ - function _parse_template() - { - if ( ! is_null($this->_template_rows)) - { - return; - } - - if (is_null($this->_template)) - { - $this->_default_template(); - return; - } - - if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) - { - $this->_default_template(); - return; - } - - $this->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); - } - -} -// END Unit_test Class - -/** - * Helper functions to test boolean true/false - * - * - * @access private - * @return bool - */ -function is_true($test) -{ - return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; -} -function is_false($test) -{ - return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; -} - - -/* End of file Unit_test.php */ -/* Location: ./system/libraries/Unit_test.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Upload.php b/bmt-system/libraries/Upload.php deleted file mode 100755 index e40ef2b..0000000 --- a/bmt-system/libraries/Upload.php +++ /dev/null @@ -1,942 +0,0 @@ - 0) - { - $this->initialize($props); - } - - log_message('debug', "Upload Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - function initialize($config = array()) - { - $defaults = array( - 'max_size' => 0, - 'max_width' => 0, - 'max_height' => 0, - 'max_filename' => 0, - 'allowed_types' => "", - 'file_temp' => "", - 'file_name' => "", - 'orig_name' => "", - 'file_type' => "", - 'file_size' => "", - 'file_ext' => "", - 'upload_path' => "", - 'overwrite' => FALSE, - 'encrypt_name' => FALSE, - 'is_image' => FALSE, - 'image_width' => '', - 'image_height' => '', - 'image_type' => '', - 'image_size_str' => '', - 'error_msg' => array(), - 'mimes' => array(), - 'remove_spaces' => TRUE, - 'xss_clean' => FALSE, - 'temp_prefix' => "temp_file_" - ); - - - foreach ($defaults as $key => $val) - { - if (isset($config[$key])) - { - $method = 'set_'.$key; - if (method_exists($this, $method)) - { - $this->$method($config[$key]); - } - else - { - $this->$key = $config[$key]; - } - } - else - { - $this->$key = $val; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Perform the file upload - * - * @access public - * @return bool - */ - function do_upload($field = 'userfile') - { - // Is $_FILES[$field] set? If not, no reason to continue. - if ( ! isset($_FILES[$field])) - { - $this->set_error('upload_no_file_selected'); - return FALSE; - } - - // Is the upload path valid? - if ( ! $this->validate_upload_path()) - { - // errors will already be set by validate_upload_path() so just return FALSE - return FALSE; - } - - // Was the file able to be uploaded? If not, determine the reason why. - if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) - { - $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; - - switch($error) - { - case 1: // UPLOAD_ERR_INI_SIZE - $this->set_error('upload_file_exceeds_limit'); - break; - case 2: // UPLOAD_ERR_FORM_SIZE - $this->set_error('upload_file_exceeds_form_limit'); - break; - case 3: // UPLOAD_ERR_PARTIAL - $this->set_error('upload_file_partial'); - break; - case 4: // UPLOAD_ERR_NO_FILE - $this->set_error('upload_no_file_selected'); - break; - case 6: // UPLOAD_ERR_NO_TMP_DIR - $this->set_error('upload_no_temp_directory'); - break; - case 7: // UPLOAD_ERR_CANT_WRITE - $this->set_error('upload_unable_to_write_file'); - break; - case 8: // UPLOAD_ERR_EXTENSION - $this->set_error('upload_stopped_by_extension'); - break; - default : $this->set_error('upload_no_file_selected'); - break; - } - - return FALSE; - } - - // Set the uploaded data as class variables - $this->file_temp = $_FILES[$field]['tmp_name']; - $this->file_name = $this->_prep_filename($_FILES[$field]['name']); - $this->file_size = $_FILES[$field]['size']; - $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); - $this->file_type = strtolower($this->file_type); - $this->file_ext = $this->get_extension($_FILES[$field]['name']); - - // Convert the file size to kilobytes - if ($this->file_size > 0) - { - $this->file_size = round($this->file_size/1024, 2); - } - - // Is the file type allowed to be uploaded? - if ( ! $this->is_allowed_filetype()) - { - $this->set_error('upload_invalid_filetype'); - return FALSE; - } - - // Is the file size within the allowed maximum? - if ( ! $this->is_allowed_filesize()) - { - $this->set_error('upload_invalid_filesize'); - return FALSE; - } - - // Are the image dimensions within the allowed size? - // Note: This can fail if the server has an open_basdir restriction. - if ( ! $this->is_allowed_dimensions()) - { - $this->set_error('upload_invalid_dimensions'); - return FALSE; - } - - // Sanitize the file name for security - $this->file_name = $this->clean_file_name($this->file_name); - - // Truncate the file name if it's too long - if ($this->max_filename > 0) - { - $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename); - } - - // Remove white spaces in the name - if ($this->remove_spaces == TRUE) - { - $this->file_name = preg_replace("/\s+/", "_", $this->file_name); - } - - /* - * Validate the file name - * This function appends an number onto the end of - * the file if one with the same name already exists. - * If it returns false there was a problem. - */ - $this->orig_name = $this->file_name; - - if ($this->overwrite == FALSE) - { - $this->file_name = $this->set_filename($this->upload_path, $this->file_name); - - if ($this->file_name === FALSE) - { - return FALSE; - } - } - - /* - * Move the file to the final destination - * To deal with different server configurations - * we'll attempt to use copy() first. If that fails - * we'll use move_uploaded_file(). One of the two should - * reliably work in most environments - */ - if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) - { - if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) - { - $this->set_error('upload_destination_error'); - return FALSE; - } - } - - /* - * Run the file through the XSS hacking filter - * This helps prevent malicious code from being - * embedded within a file. Scripts can easily - * be disguised as images or other file types. - */ - if ($this->xss_clean == TRUE) - { - $this->do_xss_clean(); - } - - /* - * Set the finalized image dimensions - * This sets the image width/height (assuming the - * file was an image). We use this information - * in the "data" function. - */ - $this->set_image_properties($this->upload_path.$this->file_name); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Finalized Data Array - * - * Returns an associative array containing all of the information - * related to the upload, allowing the developer easy access in one array. - * - * @access public - * @return array - */ - function data() - { - return array ( - 'file_name' => $this->file_name, - 'file_type' => $this->file_type, - 'file_path' => $this->upload_path, - 'full_path' => $this->upload_path.$this->file_name, - 'raw_name' => str_replace($this->file_ext, '', $this->file_name), - 'orig_name' => $this->orig_name, - 'file_ext' => $this->file_ext, - 'file_size' => $this->file_size, - 'is_image' => $this->is_image(), - 'image_width' => $this->image_width, - 'image_height' => $this->image_height, - 'image_type' => $this->image_type, - 'image_size_str' => $this->image_size_str, - ); - } - - // -------------------------------------------------------------------- - - /** - * Set Upload Path - * - * @access public - * @param string - * @return void - */ - function set_upload_path($path) - { - // Make sure it has a trailing slash - $this->upload_path = rtrim($path, '/').'/'; - } - - // -------------------------------------------------------------------- - - /** - * Set the file name - * - * This function takes a filename/path as input and looks for the - * existence of a file with the same name. If found, it will append a - * number to the end of the filename to avoid overwriting a pre-existing file. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_filename($path, $filename) - { - if ($this->encrypt_name == TRUE) - { - mt_srand(); - $filename = md5(uniqid(mt_rand())).$this->file_ext; - } - - if ( ! file_exists($path.$filename)) - { - return $filename; - } - - $filename = str_replace($this->file_ext, '', $filename); - - $new_filename = ''; - for ($i = 1; $i < 100; $i++) - { - if ( ! file_exists($path.$filename.$i.$this->file_ext)) - { - $new_filename = $filename.$i.$this->file_ext; - break; - } - } - - if ($new_filename == '') - { - $this->set_error('upload_bad_filename'); - return FALSE; - } - else - { - return $new_filename; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum File Size - * - * @access public - * @param integer - * @return void - */ - function set_max_filesize($n) - { - $this->max_size = ((int) $n < 0) ? 0: (int) $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum File Name Length - * - * @access public - * @param integer - * @return void - */ - function set_max_filename($n) - { - $this->max_filename = ((int) $n < 0) ? 0: (int) $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum Image Width - * - * @access public - * @param integer - * @return void - */ - function set_max_width($n) - { - $this->max_width = ((int) $n < 0) ? 0: (int) $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum Image Height - * - * @access public - * @param integer - * @return void - */ - function set_max_height($n) - { - $this->max_height = ((int) $n < 0) ? 0: (int) $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Allowed File Types - * - * @access public - * @param string - * @return void - */ - function set_allowed_types($types) - { - $this->allowed_types = explode('|', $types); - } - - // -------------------------------------------------------------------- - - /** - * Set Image Properties - * - * Uses GD to determine the width/height/type of image - * - * @access public - * @param string - * @return void - */ - function set_image_properties($path = '') - { - if ( ! $this->is_image()) - { - return; - } - - if (function_exists('getimagesize')) - { - if (FALSE !== ($D = @getimagesize($path))) - { - $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - - $this->image_width = $D['0']; - $this->image_height = $D['1']; - $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; - $this->image_size_str = $D['3']; // string containing height and width - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set XSS Clean - * - * Enables the XSS flag so that the file that was uploaded - * will be run through the XSS filter. - * - * @access public - * @param bool - * @return void - */ - function set_xss_clean($flag = FALSE) - { - $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Validate the image - * - * @access public - * @return bool - */ - function is_image() - { - // IE will sometimes return odd mime-types during upload, so here we just standardize all - // jpegs or pngs to the same file type. - - $png_mimes = array('image/x-png'); - $jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg'); - - if (in_array($this->file_type, $png_mimes)) - { - $this->file_type = 'image/png'; - } - - if (in_array($this->file_type, $jpeg_mimes)) - { - $this->file_type = 'image/jpeg'; - } - - $img_mimes = array( - 'image/gif', - 'image/jpeg', - 'image/png', - ); - - return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Verify that the filetype is allowed - * - * @access public - * @return bool - */ - function is_allowed_filetype() - { - if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types)) - { - $this->set_error('upload_no_file_types'); - return FALSE; - } - - $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe'); - - foreach ($this->allowed_types as $val) - { - $mime = $this->mimes_types(strtolower($val)); - - // Images get some additional checks - if (in_array($val, $image_types)) - { - if (getimagesize($this->file_temp) === FALSE) - { - return FALSE; - } - } - - if (is_array($mime)) - { - if (in_array($this->file_type, $mime, TRUE)) - { - return TRUE; - } - } - else - { - if ($mime == $this->file_type) - { - return TRUE; - } - } - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Verify that the file is within the allowed size - * - * @access public - * @return bool - */ - function is_allowed_filesize() - { - if ($this->max_size != 0 AND $this->file_size > $this->max_size) - { - return FALSE; - } - else - { - return TRUE; - } - } - - // -------------------------------------------------------------------- - - /** - * Verify that the image is within the allowed width/height - * - * @access public - * @return bool - */ - function is_allowed_dimensions() - { - if ( ! $this->is_image()) - { - return TRUE; - } - - if (function_exists('getimagesize')) - { - $D = @getimagesize($this->file_temp); - - if ($this->max_width > 0 AND $D['0'] > $this->max_width) - { - return FALSE; - } - - if ($this->max_height > 0 AND $D['1'] > $this->max_height) - { - return FALSE; - } - - return TRUE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate Upload Path - * - * Verifies that it is a valid upload path with proper permissions. - * - * - * @access public - * @return bool - */ - function validate_upload_path() - { - if ($this->upload_path == '') - { - $this->set_error('upload_no_filepath'); - return FALSE; - } - - if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE) - { - $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); - } - - if ( ! @is_dir($this->upload_path)) - { - $this->set_error('upload_no_filepath'); - return FALSE; - } - - if ( ! is_really_writable($this->upload_path)) - { - $this->set_error('upload_not_writable'); - return FALSE; - } - - $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Extract the file extension - * - * @access public - * @param string - * @return string - */ - function get_extension($filename) - { - $x = explode('.', $filename); - return '.'.end($x); - } - - // -------------------------------------------------------------------- - - /** - * Clean the file name for security - * - * @access public - * @param string - * @return string - */ - function clean_file_name($filename) - { - $bad = array( - "", - "'", - "<", - ">", - '"', - '&', - '$', - '=', - ';', - '?', - '/', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - $filename = str_replace($bad, '', $filename); - - return stripslashes($filename); - } - - // -------------------------------------------------------------------- - - /** - * Limit the File Name Length - * - * @access public - * @param string - * @return string - */ - function limit_filename_length($filename, $length) - { - if (strlen($filename) < $length) - { - return $filename; - } - - $ext = ''; - if (strpos($filename, '.') !== FALSE) - { - $parts = explode('.', $filename); - $ext = '.'.array_pop($parts); - $filename = implode('.', $parts); - } - - return substr($filename, 0, ($length - strlen($ext))).$ext; - } - - // -------------------------------------------------------------------- - - /** - * Runs the file through the XSS clean function - * - * This prevents people from embedding malicious code in their files. - * I'm not sure that it won't negatively affect certain files in unexpected ways, - * but so far I haven't found that it causes trouble. - * - * @access public - * @return void - */ - function do_xss_clean() - { - $file = $this->upload_path.$this->file_name; - - if (filesize($file) == 0) - { - return FALSE; - } - - if (($data = @file_get_contents($file)) === FALSE) - { - return FALSE; - } - - if ( ! $fp = @fopen($file, FOPEN_READ_WRITE)) - { - return FALSE; - } - - $CI =& get_instance(); - $data = $CI->input->xss_clean($data); - - flock($fp, LOCK_EX); - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); - } - - // -------------------------------------------------------------------- - - /** - * Set an error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - $CI =& get_instance(); - $CI->lang->load('upload'); - - if (is_array($msg)) - { - foreach ($msg as $val) - { - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - else - { - $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - - // -------------------------------------------------------------------- - - /** - * Display the error message - * - * @access public - * @param string - * @param string - * @return string - */ - function display_errors($open = '

    ', $close = '

    ') - { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * List of Mime Types - * - * This is a list of mime types. We use it to validate - * the "allowed types" set by the developer - * - * @access public - * @param string - * @return string - */ - function mimes_types($mime) - { - global $mimes; - - if (count($this->mimes) == 0) - { - if (@require_once(APPPATH.'config/mimes'.EXT)) - { - $this->mimes = $mimes; - unset($mimes); - } - } - - return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; - } - - // -------------------------------------------------------------------- - - /** - * Prep Filename - * - * Prevents possible script execution from Apache's handling of files multiple extensions - * http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext - * - * @access private - * @param string - * @return string - */ - function _prep_filename($filename) - { - if (strpos($filename, '.') === FALSE) - { - return $filename; - } - - $parts = explode('.', $filename); - $ext = array_pop($parts); - $filename = array_shift($parts); - - foreach ($parts as $part) - { - if ($this->mimes_types(strtolower($part)) === FALSE) - { - $filename .= '.'.$part.'_'; - } - else - { - $filename .= '.'.$part; - } - } - - $filename .= '.'.$ext; - - return $filename; - } - - // -------------------------------------------------------------------- - -} -// END Upload Class - -/* End of file Upload.php */ -/* Location: ./system/libraries/Upload.php */ \ No newline at end of file diff --git a/bmt-system/libraries/User_agent.php b/bmt-system/libraries/User_agent.php deleted file mode 100755 index 78178d0..0000000 --- a/bmt-system/libraries/User_agent.php +++ /dev/null @@ -1,502 +0,0 @@ -agent = trim($_SERVER['HTTP_USER_AGENT']); - } - - if ( ! is_null($this->agent)) - { - if ($this->_load_agent_file()) - { - $this->_compile_data(); - } - } - - log_message('debug', "User Agent Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Compile the User Agent Data - * - * @access private - * @return bool - */ - function _load_agent_file() - { - if ( ! @include(APPPATH.'config/user_agents'.EXT)) - { - return FALSE; - } - - $return = FALSE; - - if (isset($platforms)) - { - $this->platforms = $platforms; - unset($platforms); - $return = TRUE; - } - - if (isset($browsers)) - { - $this->browsers = $browsers; - unset($browsers); - $return = TRUE; - } - - if (isset($mobiles)) - { - $this->mobiles = $mobiles; - unset($mobiles); - $return = TRUE; - } - - if (isset($robots)) - { - $this->robots = $robots; - unset($robots); - $return = TRUE; - } - - return $return; - } - - // -------------------------------------------------------------------- - - /** - * Compile the User Agent Data - * - * @access private - * @return bool - */ - function _compile_data() - { - $this->_set_platform(); - - foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function) - { - if ($this->$function() === TRUE) - { - break; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set the Platform - * - * @access private - * @return mixed - */ - function _set_platform() - { - if (is_array($this->platforms) AND count($this->platforms) > 0) - { - foreach ($this->platforms as $key => $val) - { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) - { - $this->platform = $val; - return TRUE; - } - } - } - $this->platform = 'Unknown Platform'; - } - - // -------------------------------------------------------------------- - - /** - * Set the Browser - * - * @access private - * @return bool - */ - function _set_browser() - { - if (is_array($this->browsers) AND count($this->browsers) > 0) - { - foreach ($this->browsers as $key => $val) - { - if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) - { - $this->is_browser = TRUE; - $this->version = $match[1]; - $this->browser = $val; - $this->_set_mobile(); - return TRUE; - } - } - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set the Robot - * - * @access private - * @return bool - */ - function _set_robot() - { - if (is_array($this->robots) AND count($this->robots) > 0) - { - foreach ($this->robots as $key => $val) - { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) - { - $this->is_robot = TRUE; - $this->robot = $val; - return TRUE; - } - } - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set the Mobile Device - * - * @access private - * @return bool - */ - function _set_mobile() - { - if (is_array($this->mobiles) AND count($this->mobiles) > 0) - { - foreach ($this->mobiles as $key => $val) - { - if (FALSE !== (strpos(strtolower($this->agent), $key))) - { - $this->is_mobile = TRUE; - $this->mobile = $val; - return TRUE; - } - } - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set the accepted languages - * - * @access private - * @return void - */ - function _set_languages() - { - if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') - { - $languages = preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))); - - $this->languages = explode(',', $languages); - } - - if (count($this->languages) == 0) - { - $this->languages = array('Undefined'); - } - } - - // -------------------------------------------------------------------- - - /** - * Set the accepted character sets - * - * @access private - * @return void - */ - function _set_charsets() - { - if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') - { - $charsets = preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))); - - $this->charsets = explode(',', $charsets); - } - - if (count($this->charsets) == 0) - { - $this->charsets = array('Undefined'); - } - } - - // -------------------------------------------------------------------- - - /** - * Is Browser - * - * @access public - * @return bool - */ - function is_browser() - { - return $this->is_browser; - } - - // -------------------------------------------------------------------- - - /** - * Is Robot - * - * @access public - * @return bool - */ - function is_robot() - { - return $this->is_robot; - } - - // -------------------------------------------------------------------- - - /** - * Is Mobile - * - * @access public - * @return bool - */ - function is_mobile() - { - return $this->is_mobile; - } - - // -------------------------------------------------------------------- - - /** - * Is this a referral from another site? - * - * @access public - * @return bool - */ - function is_referral() - { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Agent String - * - * @access public - * @return string - */ - function agent_string() - { - return $this->agent; - } - - // -------------------------------------------------------------------- - - /** - * Get Platform - * - * @access public - * @return string - */ - function platform() - { - return $this->platform; - } - - // -------------------------------------------------------------------- - - /** - * Get Browser Name - * - * @access public - * @return string - */ - function browser() - { - return $this->browser; - } - - // -------------------------------------------------------------------- - - /** - * Get the Browser Version - * - * @access public - * @return string - */ - function version() - { - return $this->version; - } - - // -------------------------------------------------------------------- - - /** - * Get The Robot Name - * - * @access public - * @return string - */ - function robot() - { - return $this->robot; - } - // -------------------------------------------------------------------- - - /** - * Get the Mobile Device - * - * @access public - * @return string - */ - function mobile() - { - return $this->mobile; - } - - // -------------------------------------------------------------------- - - /** - * Get the referrer - * - * @access public - * @return bool - */ - function referrer() - { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); - } - - // -------------------------------------------------------------------- - - /** - * Get the accepted languages - * - * @access public - * @return array - */ - function languages() - { - if (count($this->languages) == 0) - { - $this->_set_languages(); - } - - return $this->languages; - } - - // -------------------------------------------------------------------- - - /** - * Get the accepted Character Sets - * - * @access public - * @return array - */ - function charsets() - { - if (count($this->charsets) == 0) - { - $this->_set_charsets(); - } - - return $this->charsets; - } - - // -------------------------------------------------------------------- - - /** - * Test for a particular language - * - * @access public - * @return bool - */ - function accept_lang($lang = 'en') - { - return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Test for a particular character set - * - * @access public - * @return bool - */ - function accept_charset($charset = 'utf-8') - { - return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE; - } - - -} - - -/* End of file User_agent.php */ -/* Location: ./system/libraries/User_agent.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Validation.php b/bmt-system/libraries/Validation.php deleted file mode 100755 index 4baf78b..0000000 --- a/bmt-system/libraries/Validation.php +++ /dev/null @@ -1,875 +0,0 @@ -'; - var $_error_suffix = '

    '; - - - - /** - * Constructor - * - */ - function CI_Validation() - { - $this->CI =& get_instance(); - - if (function_exists('mb_internal_encoding')) - { - mb_internal_encoding($this->CI->config->item('charset')); - } - - log_message('debug', "Validation Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set Fields - * - * This function takes an array of field names as input - * and generates class variables with the same name, which will - * either be blank or contain the $_POST value corresponding to it - * - * @access public - * @param string - * @param string - * @return void - */ - function set_fields($data = '', $field = '') - { - if ($data == '') - { - if (count($this->_fields) == 0) - { - return FALSE; - } - } - else - { - if ( ! is_array($data)) - { - $data = array($data => $field); - } - - if (count($data) > 0) - { - $this->_fields = $data; - } - } - - foreach($this->_fields as $key => $val) - { - $this->$key = ( ! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); - - $error = $key.'_error'; - if ( ! isset($this->$error)) - { - $this->$error = ''; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set Rules - * - * This function takes an array of field names and validation - * rules as input ad simply stores is for use later. - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_rules($data, $rules = '') - { - if ( ! is_array($data)) - { - if ($rules == '') - return; - - $data = array($data => $rules); - } - - foreach ($data as $key => $val) - { - $this->_rules[$key] = $val; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Error Message - * - * Lets users set their own error messages on the fly. Note: The key - * name has to match the function name that it corresponds to. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_message($lang, $val = '') - { - if ( ! is_array($lang)) - { - $lang = array($lang => $val); - } - - $this->_error_messages = array_merge($this->_error_messages, $lang); - } - - // -------------------------------------------------------------------- - - /** - * Set The Error Delimiter - * - * Permits a prefix/suffix to be added to each error message - * - * @access public - * @param string - * @param string - * @return void - */ - function set_error_delimiters($prefix = '

    ', $suffix = '

    ') - { - $this->_error_prefix = $prefix; - $this->_error_suffix = $suffix; - } - - // -------------------------------------------------------------------- - - /** - * Run the Validator - * - * This function does all the work. - * - * @access public - * @return bool - */ - function run() - { - // Do we even have any data to process? Mm? - if (count($_POST) == 0 OR count($this->_rules) == 0) - { - return FALSE; - } - - // Load the language file containing error messages - $this->CI->lang->load('validation'); - - // Cycle through the rules and test for errors - foreach ($this->_rules as $field => $rules) - { - //Explode out the rules! - $ex = explode('|', $rules); - - // Is the field required? If not, if the field is blank we'll move on to the next test - if ( ! in_array('required', $ex, TRUE)) - { - if ( ! isset($_POST[$field]) OR $_POST[$field] == '') - { - continue; - } - } - - /* - * Are we dealing with an "isset" rule? - * - * Before going further, we'll see if one of the rules - * is to check whether the item is set (typically this - * applies only to checkboxes). If so, we'll - * test for it here since there's not reason to go - * further - */ - if ( ! isset($_POST[$field])) - { - if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) - { - if ( ! isset($this->_error_messages['isset'])) - { - if (FALSE === ($line = $this->CI->lang->line('isset'))) - { - $line = 'The field was not set'; - } - } - else - { - $line = $this->_error_messages['isset']; - } - - // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $message = sprintf($line, $mfield); - - // Set the error variable. Example: $this->username_error - $error = $field.'_error'; - $this->$error = $this->_error_prefix.$message.$this->_error_suffix; - $this->_error_array[] = $message; - } - - continue; - } - - /* - * Set the current field - * - * The various prepping functions need to know the - * current field name so they can do this: - * - * $_POST[$this->_current_field] == 'bla bla'; - */ - $this->_current_field = $field; - - // Cycle through the rules! - foreach ($ex As $rule) - { - // Is the rule a callback? - $callback = FALSE; - if (substr($rule, 0, 9) == 'callback_') - { - $rule = substr($rule, 9); - $callback = TRUE; - } - - // Strip the parameter (if exists) from the rule - // Rules can contain a parameter: max_length[5] - $param = FALSE; - if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) - { - $rule = $match[1]; - $param = $match[2]; - } - - // Call the function that corresponds to the rule - if ($callback === TRUE) - { - if ( ! method_exists($this->CI, $rule)) - { - continue; - } - - $result = $this->CI->$rule($_POST[$field], $param); - - // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) - { - continue 2; - } - - } - else - { - if ( ! method_exists($this, $rule)) - { - /* - * Run the native PHP function if called for - * - * If our own wrapper function doesn't exist we see - * if a native PHP function does. Users can use - * any native PHP function call that has one param. - */ - if (function_exists($rule)) - { - $_POST[$field] = $rule($_POST[$field]); - $this->$field = $_POST[$field]; - } - - continue; - } - - $result = $this->$rule($_POST[$field], $param); - } - - // Did the rule test negatively? If so, grab the error. - if ($result === FALSE) - { - if ( ! isset($this->_error_messages[$rule])) - { - if (FALSE === ($line = $this->CI->lang->line($rule))) - { - $line = 'Unable to access an error message corresponding to your field name.'; - } - } - else - { - $line = $this->_error_messages[$rule]; - } - - // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; - $message = sprintf($line, $mfield, $mparam); - - // Set the error variable. Example: $this->username_error - $error = $field.'_error'; - $this->$error = $this->_error_prefix.$message.$this->_error_suffix; - - // Add the error to the error array - $this->_error_array[] = $message; - continue 2; - } - } - - } - - $total_errors = count($this->_error_array); - - /* - * Recompile the class variables - * - * If any prepping functions were called the $_POST data - * might now be different then the corresponding class - * variables so we'll set them anew. - */ - if ($total_errors > 0) - { - $this->_safe_form_data = TRUE; - } - - $this->set_fields(); - - // Did we end up with any errors? - if ($total_errors == 0) - { - return TRUE; - } - - // Generate the error string - foreach ($this->_error_array as $val) - { - $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Required - * - * @access public - * @param string - * @return bool - */ - function required($str) - { - if ( ! is_array($str)) - { - return (trim($str) == '') ? FALSE : TRUE; - } - else - { - return ( ! empty($str)); - } - } - - // -------------------------------------------------------------------- - - /** - * Match one field to another - * - * @access public - * @param string - * @param field - * @return bool - */ - function matches($str, $field) - { - if ( ! isset($_POST[$field])) - { - return FALSE; - } - - return ($str !== $_POST[$field]) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Minimum Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function min_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) < $val) ? FALSE : TRUE; - } - - return (strlen($str) < $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Max Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function max_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) > $val) ? FALSE : TRUE; - } - - return (strlen($str) > $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Exact Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function exact_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) != $val) ? FALSE : TRUE; - } - - return (strlen($str) != $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Email - * - * @access public - * @param string - * @return bool - */ - function valid_email($str) - { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Emails - * - * @access public - * @param string - * @return bool - */ - function valid_emails($str) - { - if (strpos($str, ',') === FALSE) - { - return $this->valid_email(trim($str)); - } - - foreach(explode(',', $str) as $email) - { - if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * @access public - * @param string - * @return string - */ - function valid_ip($ip) - { - return $this->CI->input->valid_ip($ip); - } - - // -------------------------------------------------------------------- - - /** - * Alpha - * - * @access public - * @param string - * @return bool - */ - function alpha($str) - { - return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric - * - * @access public - * @param string - * @return bool - */ - function alpha_numeric($str) - { - return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric with underscores and dashes - * - * @access public - * @param string - * @return bool - */ - function alpha_dash($str) - { - return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Numeric - * - * @access public - * @param string - * @return bool - */ - function numeric($str) - { - return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); - - } - - // -------------------------------------------------------------------- - - /** - * Is Numeric - * - * @access public - * @param string - * @return bool - */ - function is_numeric($str) - { - return ( ! is_numeric($str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Integer - * - * @access public - * @param string - * @return bool - */ - function integer($str) - { - return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Is a Natural number (0,1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural($str) - { - return (bool)preg_match( '/^[0-9]+$/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Is a Natural number, but not a zero (1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural_no_zero($str) - { - if ( ! preg_match( '/^[0-9]+$/', $str)) - { - return FALSE; - } - - if ($str == 0) - { - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Base64 - * - * Tests a string for characters outside of the Base64 alphabet - * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 - * - * @access public - * @param string - * @return bool - */ - function valid_base64($str) - { - return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Set Select - * - * Enables pull-down lists to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_select($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' selected="selected"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Radio - * - * Enables radio buttons to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_radio($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Checkbox - * - * Enables checkboxes to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_checkbox($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Prep data for form - * - * This function allows HTML to be safely shown in a form. - * Special characters are converted. - * - * @access public - * @param string - * @return string - */ - function prep_for_form($data = '') - { - if (is_array($data)) - { - foreach ($data as $key => $val) - { - $data[$key] = $this->prep_for_form($val); - } - - return $data; - } - - if ($this->_safe_form_data == FALSE OR $data == '') - { - return $data; - } - - return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); - } - - // -------------------------------------------------------------------- - - /** - * Prep URL - * - * @access public - * @param string - * @return string - */ - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - $_POST[$this->_current_field] = ''; - return; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - $_POST[$this->_current_field] = $str; - } - - // -------------------------------------------------------------------- - - /** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ - function strip_image_tags($str) - { - $_POST[$this->_current_field] = $this->CI->input->strip_image_tags($str); - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * @access public - * @param string - * @return string - */ - function xss_clean($str) - { - $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); - } - - // -------------------------------------------------------------------- - - /** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ - function encode_php_tags($str) - { - $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); - } - -} -// END Validation Class - -/* End of file Validation.php */ -/* Location: ./system/libraries/Validation.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Xmlrpc.php b/bmt-system/libraries/Xmlrpc.php deleted file mode 100755 index 987f274..0000000 --- a/bmt-system/libraries/Xmlrpc.php +++ /dev/null @@ -1,1421 +0,0 @@ -xmlrpcName = $this->xmlrpcName; - $this->xmlrpc_backslash = chr(92).chr(92); - - // Types for info sent back and forth - $this->xmlrpcTypes = array( - $this->xmlrpcI4 => '1', - $this->xmlrpcInt => '1', - $this->xmlrpcBoolean => '1', - $this->xmlrpcString => '1', - $this->xmlrpcDouble => '1', - $this->xmlrpcDateTime => '1', - $this->xmlrpcBase64 => '1', - $this->xmlrpcArray => '2', - $this->xmlrpcStruct => '3' - ); - - // Array of Valid Parents for Various XML-RPC elements - $this->valid_parents = array('BOOLEAN' => array('VALUE'), - 'I4' => array('VALUE'), - 'INT' => array('VALUE'), - 'STRING' => array('VALUE'), - 'DOUBLE' => array('VALUE'), - 'DATETIME.ISO8601' => array('VALUE'), - 'BASE64' => array('VALUE'), - 'ARRAY' => array('VALUE'), - 'STRUCT' => array('VALUE'), - 'PARAM' => array('PARAMS'), - 'METHODNAME' => array('METHODCALL'), - 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'), - 'MEMBER' => array('STRUCT'), - 'NAME' => array('MEMBER'), - 'DATA' => array('ARRAY'), - 'FAULT' => array('METHODRESPONSE'), - 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT') - ); - - - // XML-RPC Responses - $this->xmlrpcerr['unknown_method'] = '1'; - $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; - $this->xmlrpcerr['invalid_return'] = '2'; - $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; - $this->xmlrpcerr['incorrect_params'] = '3'; - $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; - $this->xmlrpcerr['introspect_unknown'] = '4'; - $this->xmlrpcstr['introspect_unknown'] = "Cannot inspect signature for request: method unknown"; - $this->xmlrpcerr['http_error'] = '5'; - $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server."; - $this->xmlrpcerr['no_data'] = '6'; - $this->xmlrpcstr['no_data'] ='No data received from server.'; - - $this->initialize($config); - - log_message('debug', "XML-RPC Class Initialized"); - } - - - //------------------------------------- - // Initialize Prefs - //------------------------------------- - - function initialize($config = array()) - { - if (count($config) > 0) - { - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - } - } - // END - - //------------------------------------- - // Take URL and parse it - //------------------------------------- - - function server($url, $port=80) - { - if (substr($url, 0, 4) != "http") - { - $url = "http://".$url; - } - - $parts = parse_url($url); - - $path = ( ! isset($parts['path'])) ? '/' : $parts['path']; - - if (isset($parts['query']) && $parts['query'] != '') - { - $path .= '?'.$parts['query']; - } - - $this->client = new XML_RPC_Client($path, $parts['host'], $port); - } - // END - - //------------------------------------- - // Set Timeout - //------------------------------------- - - function timeout($seconds=5) - { - if ( ! is_null($this->client) && is_int($seconds)) - { - $this->client->timeout = $seconds; - } - } - // END - - //------------------------------------- - // Set Methods - //------------------------------------- - - function method($function) - { - $this->method = $function; - } - // END - - //------------------------------------- - // Take Array of Data and Create Objects - //------------------------------------- - - function request($incoming) - { - if ( ! is_array($incoming)) - { - // Send Error - } - - $this->data = array(); - - foreach($incoming as $key => $value) - { - $this->data[$key] = $this->values_parsing($value); - } - } - // END - - - //------------------------------------- - // Set Debug - //------------------------------------- - - function set_debug($flag = TRUE) - { - $this->debug = ($flag == TRUE) ? TRUE : FALSE; - } - - //------------------------------------- - // Values Parsing - //------------------------------------- - - function values_parsing($value, $return = FALSE) - { - if (is_array($value) && isset($value['0'])) - { - if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) - { - if (is_array($value[0])) - { - $temp = new XML_RPC_Values($value['0'], 'array'); - } - else - { - $temp = new XML_RPC_Values($value['0'], 'string'); - } - } - elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) - { - while (list($k) = each($value['0'])) - { - $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); - } - - $temp = new XML_RPC_Values($value['0'], $value['1']); - } - else - { - $temp = new XML_RPC_Values($value['0'], $value['1']); - } - } - else - { - $temp = new XML_RPC_Values($value, 'string'); - } - - return $temp; - } - // END - - - //------------------------------------- - // Sends XML-RPC Request - //------------------------------------- - - function send_request() - { - $this->message = new XML_RPC_Message($this->method,$this->data); - $this->message->debug = $this->debug; - - if ( ! $this->result = $this->client->send($this->message)) - { - $this->error = $this->result->errstr; - return FALSE; - } - elseif( ! is_object($this->result->val)) - { - $this->error = $this->result->errstr; - return FALSE; - } - - $this->response = $this->result->decode(); - - return TRUE; - } - // END - - //------------------------------------- - // Returns Error - //------------------------------------- - - function display_error() - { - return $this->error; - } - // END - - //------------------------------------- - // Returns Remote Server Response - //------------------------------------- - - function display_response() - { - return $this->response; - } - // END - - //------------------------------------- - // Sends an Error Message for Server Request - //------------------------------------- - - function send_error_message($number, $message) - { - return new XML_RPC_Response('0',$number, $message); - } - // END - - - //------------------------------------- - // Send Response for Server Request - //------------------------------------- - - function send_response($response) - { - // $response should be array of values, which will be parsed - // based on their data and type into a valid group of XML-RPC values - - $response = $this->values_parsing($response); - - return new XML_RPC_Response($response); - } - // END - -} // END XML_RPC Class - - - -/** - * XML-RPC Client class - * - * @category XML-RPC - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Client extends CI_Xmlrpc -{ - var $path = ''; - var $server = ''; - var $port = 80; - var $errno = ''; - var $errstring = ''; - var $timeout = 5; - var $no_multicall = false; - - function XML_RPC_Client($path, $server, $port=80) - { - parent::CI_Xmlrpc(); - - $this->port = $port; - $this->server = $server; - $this->path = $path; - } - - function send($msg) - { - if (is_array($msg)) - { - // Multi-call disabled - $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']); - return $r; - } - - return $this->sendPayload($msg); - } - - function sendPayload($msg) - { - $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); - - if ( ! is_resource($fp)) - { - error_log($this->xmlrpcstr['http_error']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); - return $r; - } - - if(empty($msg->payload)) - { - // $msg = XML_RPC_Messages - $msg->createPayload(); - } - - $r = "\r\n"; - $op = "POST {$this->path} HTTP/1.0$r"; - $op .= "Host: {$this->server}$r"; - $op .= "Content-Type: text/xml$r"; - $op .= "User-Agent: {$this->xmlrpcName}$r"; - $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; - $op .= $msg->payload; - - - if ( ! fputs($fp, $op, strlen($op))) - { - error_log($this->xmlrpcstr['http_error']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); - return $r; - } - $resp = $msg->parseResponse($fp); - fclose($fp); - return $resp; - } - -} // end class XML_RPC_Client - - -/** - * XML-RPC Response class - * - * @category XML-RPC - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Response -{ - var $val = 0; - var $errno = 0; - var $errstr = ''; - var $headers = array(); - - function XML_RPC_Response($val, $code = 0, $fstr = '') - { - if ($code != 0) - { - // error - $this->errno = $code; - $this->errstr = htmlentities($fstr); - } - else if ( ! is_object($val)) - { - // programmer error, not an object - error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); - $this->val = new XML_RPC_Values(); - } - else - { - $this->val = $val; - } - } - - function faultCode() - { - return $this->errno; - } - - function faultString() - { - return $this->errstr; - } - - function value() - { - return $this->val; - } - - function prepare_response() - { - $result = "\n"; - if ($this->errno) - { - $result .= ' - - - - faultCode - ' . $this->errno . ' - - - faultString - ' . $this->errstr . ' - - - -'; - } - else - { - $result .= "\n\n" . - $this->val->serialize_class() . - "\n"; - } - $result .= "\n"; - return $result; - } - - function decode($array=FALSE) - { - $CI =& get_instance(); - - if ($array !== FALSE && is_array($array)) - { - while (list($key) = each($array)) - { - if (is_array($array[$key])) - { - $array[$key] = $this->decode($array[$key]); - } - else - { - $array[$key] = $CI->input->xss_clean($array[$key]); - } - } - - $result = $array; - } - else - { - $result = $this->xmlrpc_decoder($this->val); - - if (is_array($result)) - { - $result = $this->decode($result); - } - else - { - $result = $CI->input->xss_clean($result); - } - } - - return $result; - } - - - - //------------------------------------- - // XML-RPC Object to PHP Types - //------------------------------------- - - function xmlrpc_decoder($xmlrpc_val) - { - $kind = $xmlrpc_val->kindOf(); - - if($kind == 'scalar') - { - return $xmlrpc_val->scalarval(); - } - elseif($kind == 'array') - { - reset($xmlrpc_val->me); - list($a,$b) = each($xmlrpc_val->me); - $size = count($b); - - $arr = array(); - - for($i = 0; $i < $size; $i++) - { - $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); - } - return $arr; - } - elseif($kind == 'struct') - { - reset($xmlrpc_val->me['struct']); - $arr = array(); - - while(list($key,$value) = each($xmlrpc_val->me['struct'])) - { - $arr[$key] = $this->xmlrpc_decoder($value); - } - return $arr; - } - } - - - //------------------------------------- - // ISO-8601 time to server or UTC time - //------------------------------------- - - function iso8601_decode($time, $utc=0) - { - // return a timet in the localtime, or UTC - $t = 0; - if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs)) - { - if ($utc == 1) - $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - else - $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - } - return $t; - } - -} // End Response Class - - - -/** - * XML-RPC Message class - * - * @category XML-RPC - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Message extends CI_Xmlrpc -{ - var $payload; - var $method_name; - var $params = array(); - var $xh = array(); - - function XML_RPC_Message($method, $pars=0) - { - parent::CI_Xmlrpc(); - - $this->method_name = $method; - if (is_array($pars) && count($pars) > 0) - { - for($i=0; $iparams[] = $pars[$i]; - } - } - } - - //------------------------------------- - // Create Payload to Send - //------------------------------------- - - function createPayload() - { - $this->payload = "\r\n\r\n"; - $this->payload .= '' . $this->method_name . "\r\n"; - $this->payload .= "\r\n"; - - for($i=0; $iparams); $i++) - { - // $p = XML_RPC_Values - $p = $this->params[$i]; - $this->payload .= "\r\n".$p->serialize_class()."\r\n"; - } - - $this->payload .= "\r\n\r\n"; - } - - //------------------------------------- - // Parse External XML-RPC Server's Response - //------------------------------------- - - function parseResponse($fp) - { - $data = ''; - - while($datum = fread($fp, 4096)) - { - $data .= $datum; - } - - //------------------------------------- - // DISPLAY HTTP CONTENT for DEBUGGING - //------------------------------------- - - if ($this->debug === TRUE) - { - echo "
    ";
    -			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    -			echo "
    "; - } - - //------------------------------------- - // Check for data - //------------------------------------- - - if($data == "") - { - error_log($this->xmlrpcstr['no_data']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); - return $r; - } - - - //------------------------------------- - // Check for HTTP 200 Response - //------------------------------------- - - if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) - { - $errstr= substr($data, 0, strpos($data, "\n")-1); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')'); - return $r; - } - - //------------------------------------- - // Create and Set Up XML Parser - //------------------------------------- - - $parser = xml_parser_create($this->xmlrpc_defencoding); - - $this->xh[$parser] = array(); - $this->xh[$parser]['isf'] = 0; - $this->xh[$parser]['ac'] = ''; - $this->xh[$parser]['headers'] = array(); - $this->xh[$parser]['stack'] = array(); - $this->xh[$parser]['valuestack'] = array(); - $this->xh[$parser]['isf_reason'] = 0; - - xml_set_object($parser, $this); - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); - xml_set_element_handler($parser, 'open_tag', 'closing_tag'); - xml_set_character_data_handler($parser, 'character_data'); - //xml_set_default_handler($parser, 'default_handler'); - - - //------------------------------------- - // GET HEADERS - //------------------------------------- - - $lines = explode("\r\n", $data); - while (($line = array_shift($lines))) - { - if (strlen($line) < 1) - { - break; - } - $this->xh[$parser]['headers'][] = $line; - } - $data = implode("\r\n", $lines); - - - //------------------------------------- - // PARSE XML DATA - //------------------------------------- - - if ( ! xml_parse($parser, $data, count($data))) - { - $errstr = sprintf('XML error: %s at line %d', - xml_error_string(xml_get_error_code($parser)), - xml_get_current_line_number($parser)); - //error_log($errstr); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); - xml_parser_free($parser); - return $r; - } - xml_parser_free($parser); - - // --------------------------------------- - // Got Ourselves Some Badness, It Seems - // --------------------------------------- - - if ($this->xh[$parser]['isf'] > 1) - { - if ($this->debug === TRUE) - { - echo "---Invalid Return---\n"; - echo $this->xh[$parser]['isf_reason']; - echo "---Invalid Return---\n\n"; - } - - $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); - return $r; - } - elseif ( ! is_object($this->xh[$parser]['value'])) - { - $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); - return $r; - } - - //------------------------------------- - // DISPLAY XML CONTENT for DEBUGGING - //------------------------------------- - - if ($this->debug === TRUE) - { - echo "
    ";
    -			
    -			if (count($this->xh[$parser]['headers'] > 0))
    -			{
    -				echo "---HEADERS---\n";
    -				foreach ($this->xh[$parser]['headers'] as $header)
    -				{
    -					echo "$header\n";
    -				}
    -				echo "---END HEADERS---\n\n";
    -			}
    -			
    -			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    -			
    -			echo "---PARSED---\n" ;
    -			var_dump($this->xh[$parser]['value']);
    -			echo "\n---END PARSED---
    "; - } - - //------------------------------------- - // SEND RESPONSE - //------------------------------------- - - $v = $this->xh[$parser]['value']; - - if ($this->xh[$parser]['isf']) - { - $errno_v = $v->me['struct']['faultCode']; - $errstr_v = $v->me['struct']['faultString']; - $errno = $errno_v->scalarval(); - - if ($errno == 0) - { - // FAULT returned, errno needs to reflect that - $errno = -1; - } - - $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); - } - else - { - $r = new XML_RPC_Response($v); - } - - $r->headers = $this->xh[$parser]['headers']; - return $r; - } - - // ------------------------------------ - // Begin Return Message Parsing section - // ------------------------------------ - - // quick explanation of components: - // ac - used to accumulate values - // isf - used to indicate a fault - // lv - used to indicate "looking for a value": implements - // the logic to allow values with no types to be strings - // params - used to store parameters in method calls - // method - used to store method name - // stack - array with parent tree of the xml element, - // used to validate the nesting of elements - - //------------------------------------- - // Start Element Handler - //------------------------------------- - - function open_tag($the_parser, $name, $attrs) - { - // If invalid nesting, then return - if ($this->xh[$the_parser]['isf'] > 1) return; - - // Evaluate and check for correct nesting of XML elements - - if (count($this->xh[$the_parser]['stack']) == 0) - { - if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') - { - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; - return; - } - } - else - { - // not top level element: see if parent is OK - if ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) - { - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; - return; - } - } - - switch($name) - { - case 'STRUCT': - case 'ARRAY': - // Creates array for child elements - - $cur_val = array('value' => array(), - 'type' => $name); - - array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); - break; - case 'METHODNAME': - case 'NAME': - $this->xh[$the_parser]['ac'] = ''; - break; - case 'FAULT': - $this->xh[$the_parser]['isf'] = 1; - break; - case 'PARAM': - $this->xh[$the_parser]['value'] = null; - break; - case 'VALUE': - $this->xh[$the_parser]['vt'] = 'value'; - $this->xh[$the_parser]['ac'] = ''; - $this->xh[$the_parser]['lv'] = 1; - break; - case 'I4': - case 'INT': - case 'STRING': - case 'BOOLEAN': - case 'DOUBLE': - case 'DATETIME.ISO8601': - case 'BASE64': - if ($this->xh[$the_parser]['vt'] != 'value') - { - //two data elements inside a value: an error occurred! - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value"; - return; - } - - $this->xh[$the_parser]['ac'] = ''; - break; - case 'MEMBER': - // Set name of to nothing to prevent errors later if no is found - $this->xh[$the_parser]['valuestack'][0]['name'] = ''; - - // Set NULL value to check to see if value passed for this param/member - $this->xh[$the_parser]['value'] = null; - break; - case 'DATA': - case 'METHODCALL': - case 'METHODRESPONSE': - case 'PARAMS': - // valid elements that add little to processing - break; - default: - /// An Invalid Element is Found, so we have trouble - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name"; - break; - } - - // Add current element name to stack, to allow validation of nesting - array_unshift($this->xh[$the_parser]['stack'], $name); - - if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0; - } - // END - - - //------------------------------------- - // End Element Handler - //------------------------------------- - - function closing_tag($the_parser, $name) - { - if ($this->xh[$the_parser]['isf'] > 1) return; - - // Remove current element from stack and set variable - // NOTE: If the XML validates, then we do not have to worry about - // the opening and closing of elements. Nesting is checked on the opening - // tag so we be safe there as well. - - $curr_elem = array_shift($this->xh[$the_parser]['stack']); - - switch($name) - { - case 'STRUCT': - case 'ARRAY': - $cur_val = array_shift($this->xh[$the_parser]['valuestack']); - $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; - $this->xh[$the_parser]['vt'] = strtolower($name); - break; - case 'NAME': - $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; - break; - case 'BOOLEAN': - case 'I4': - case 'INT': - case 'STRING': - case 'DOUBLE': - case 'DATETIME.ISO8601': - case 'BASE64': - $this->xh[$the_parser]['vt'] = strtolower($name); - - if ($name == 'STRING') - { - $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; - } - elseif ($name=='DATETIME.ISO8601') - { - $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; - $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; - } - elseif ($name=='BASE64') - { - $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); - } - elseif ($name=='BOOLEAN') - { - // Translated BOOLEAN values to TRUE AND FALSE - if ($this->xh[$the_parser]['ac'] == '1') - { - $this->xh[$the_parser]['value'] = TRUE; - } - else - { - $this->xh[$the_parser]['value'] = FALSE; - } - } - elseif ($name=='DOUBLE') - { - // we have a DOUBLE - // we must check that only 0123456789-. are characters here - if ( ! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; - } - else - { - $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac']; - } - } - else - { - // we have an I4/INT - // we must check that only 0123456789- are characters here - if ( ! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; - } - else - { - $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac']; - } - } - $this->xh[$the_parser]['ac'] = ''; - $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value - break; - case 'VALUE': - // This if() detects if no scalar was inside - if ($this->xh[$the_parser]['vt']=='value') - { - $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; - $this->xh[$the_parser]['vt'] = $this->xmlrpcString; - } - - // build the XML-RPC value out of the data received, and substitute it - $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']); - - if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY') - { - // Array - $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; - } - else - { - // Struct - $this->xh[$the_parser]['value'] = $temp; - } - break; - case 'MEMBER': - $this->xh[$the_parser]['ac']=''; - - // If value add to array in the stack for the last element built - if ($this->xh[$the_parser]['value']) - { - $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; - } - break; - case 'DATA': - $this->xh[$the_parser]['ac']=''; - break; - case 'PARAM': - if ($this->xh[$the_parser]['value']) - { - $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; - } - break; - case 'METHODNAME': - $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']); - break; - case 'PARAMS': - case 'FAULT': - case 'METHODCALL': - case 'METHORESPONSE': - // We're all good kids with nuthin' to do - break; - default: - // End of an Invalid Element. Taken care of during the opening tag though - break; - } - } - - //------------------------------------- - // Parses Character Data - //------------------------------------- - - function character_data($the_parser, $data) - { - if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already - - // If a value has not been found - if ($this->xh[$the_parser]['lv'] != 3) - { - if ($this->xh[$the_parser]['lv'] == 1) - { - $this->xh[$the_parser]['lv'] = 2; // Found a value - } - - if( ! @isset($this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['ac'] = ''; - } - - $this->xh[$the_parser]['ac'] .= $data; - } - } - - - function addParam($par) { $this->params[]=$par; } - - function output_parameters($array=FALSE) - { - $CI =& get_instance(); - - if ($array !== FALSE && is_array($array)) - { - while (list($key) = each($array)) - { - if (is_array($array[$key])) - { - $array[$key] = $this->output_parameters($array[$key]); - } - else - { - $array[$key] = $CI->input->xss_clean($array[$key]); - } - } - - $parameters = $array; - } - else - { - $parameters = array(); - - for ($i = 0; $i < count($this->params); $i++) - { - $a_param = $this->decode_message($this->params[$i]); - - if (is_array($a_param)) - { - $parameters[] = $this->output_parameters($a_param); - } - else - { - $parameters[] = $CI->input->xss_clean($a_param); - } - } - } - - return $parameters; - } - - - function decode_message($param) - { - $kind = $param->kindOf(); - - if($kind == 'scalar') - { - return $param->scalarval(); - } - elseif($kind == 'array') - { - reset($param->me); - list($a,$b) = each($param->me); - - $arr = array(); - - for($i = 0; $i < count($b); $i++) - { - $arr[] = $this->decode_message($param->me['array'][$i]); - } - - return $arr; - } - elseif($kind == 'struct') - { - reset($param->me['struct']); - - $arr = array(); - - while(list($key,$value) = each($param->me['struct'])) - { - $arr[$key] = $this->decode_message($value); - } - - return $arr; - } - } - -} // End XML_RPC_Messages class - - - -/** - * XML-RPC Values class - * - * @category XML-RPC - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Values extends CI_Xmlrpc -{ - var $me = array(); - var $mytype = 0; - - function XML_RPC_Values($val=-1, $type='') - { - parent::CI_Xmlrpc(); - - if ($val != -1 OR $type != '') - { - $type = $type == '' ? 'string' : $type; - - if ($this->xmlrpcTypes[$type] == 1) - { - $this->addScalar($val,$type); - } - elseif ($this->xmlrpcTypes[$type] == 2) - { - $this->addArray($val); - } - elseif ($this->xmlrpcTypes[$type] == 3) - { - $this->addStruct($val); - } - } - } - - function addScalar($val, $type='string') - { - $typeof = $this->xmlrpcTypes[$type]; - - if ($this->mytype==1) - { - echo 'XML_RPC_Values: scalar can have only one value
    '; - return 0; - } - - if ($typeof != 1) - { - echo 'XML_RPC_Values: not a scalar type (${typeof})
    '; - return 0; - } - - if ($type == $this->xmlrpcBoolean) - { - if (strcasecmp($val,'true')==0 OR $val==1 OR ($val==true && strcasecmp($val,'false'))) - { - $val = 1; - } - else - { - $val=0; - } - } - - if ($this->mytype == 2) - { - // adding to an array here - $ar = $this->me['array']; - $ar[] = new XML_RPC_Values($val, $type); - $this->me['array'] = $ar; - } - else - { - // a scalar, so set the value and remember we're scalar - $this->me[$type] = $val; - $this->mytype = $typeof; - } - return 1; - } - - function addArray($vals) - { - if ($this->mytype != 0) - { - echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
    '; - return 0; - } - - $this->mytype = $this->xmlrpcTypes['array']; - $this->me['array'] = $vals; - return 1; - } - - function addStruct($vals) - { - if ($this->mytype != 0) - { - echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
    '; - return 0; - } - $this->mytype = $this->xmlrpcTypes['struct']; - $this->me['struct'] = $vals; - return 1; - } - - function kindOf() - { - switch($this->mytype) - { - case 3: - return 'struct'; - break; - case 2: - return 'array'; - break; - case 1: - return 'scalar'; - break; - default: - return 'undef'; - } - } - - function serializedata($typ, $val) - { - $rs = ''; - - switch($this->xmlrpcTypes[$typ]) - { - case 3: - // struct - $rs .= "\n"; - reset($val); - while(list($key2, $val2) = each($val)) - { - $rs .= "\n{$key2}\n"; - $rs .= $this->serializeval($val2); - $rs .= "\n"; - } - $rs .= ''; - break; - case 2: - // array - $rs .= "\n\n"; - for($i=0; $i < count($val); $i++) - { - $rs .= $this->serializeval($val[$i]); - } - $rs.="\n\n"; - break; - case 1: - // others - switch ($typ) - { - case $this->xmlrpcBase64: - $rs .= "<{$typ}>" . base64_encode($val) . "\n"; - break; - case $this->xmlrpcBoolean: - $rs .= "<{$typ}>" . ($val ? '1' : '0') . "\n"; - break; - case $this->xmlrpcString: - $rs .= "<{$typ}>" . htmlspecialchars($val). "\n"; - break; - default: - $rs .= "<{$typ}>{$val}\n"; - break; - } - default: - break; - } - return $rs; - } - - function serialize_class() - { - return $this->serializeval($this); - } - - function serializeval($o) - { - $ar = $o->me; - reset($ar); - - list($typ, $val) = each($ar); - $rs = "\n".$this->serializedata($typ, $val)."\n"; - return $rs; - } - - function scalarval() - { - reset($this->me); - list($a,$b) = each($this->me); - return $b; - } - - - //------------------------------------- - // Encode time in ISO-8601 form. - //------------------------------------- - - // Useful for sending time in XML-RPC - - function iso8601_encode($time, $utc=0) - { - if ($utc == 1) - { - $t = strftime("%Y%m%dT%H:%M:%S", $time); - } - else - { - if (function_exists('gmstrftime')) - $t = gmstrftime("%Y%m%dT%H:%M:%S", $time); - else - $t = strftime("%Y%m%dT%H:%M:%S", $time - date('Z')); - } - return $t; - } - -} -// END XML_RPC_Values Class - -/* End of file Xmlrpc.php */ -/* Location: ./system/libraries/Xmlrpc.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Xmlrpcs.php b/bmt-system/libraries/Xmlrpcs.php deleted file mode 100755 index 3f53849..0000000 --- a/bmt-system/libraries/Xmlrpcs.php +++ /dev/null @@ -1,536 +0,0 @@ -set_system_methods(); - - if (isset($config['functions']) && is_array($config['functions'])) - { - $this->methods = array_merge($this->methods, $config['functions']); - } - - log_message('debug', "XML-RPC Server Class Initialized"); - } - - //------------------------------------- - // Initialize Prefs and Serve - //------------------------------------- - - function initialize($config=array()) - { - if (isset($config['functions']) && is_array($config['functions'])) - { - $this->methods = array_merge($this->methods, $config['functions']); - } - - if (isset($config['debug'])) - { - $this->debug = $config['debug']; - } - - if (isset($config['object']) && is_object($config['object'])) - { - $this->object = $config['object']; - } - } - - //------------------------------------- - // Setting of System Methods - //------------------------------------- - - function set_system_methods () - { - $this->methods = array( - 'system.listMethods' => array( - 'function' => 'this.listMethods', - 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)), - 'docstring' => 'Returns an array of available methods on this server'), - 'system.methodHelp' => array( - 'function' => 'this.methodHelp', - 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)), - 'docstring' => 'Returns a documentation string for the specified method'), - 'system.methodSignature' => array( - 'function' => 'this.methodSignature', - 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)), - 'docstring' => 'Returns an array describing the return type and required parameters of a method'), - 'system.multicall' => array( - 'function' => 'this.multicall', - 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)), - 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details') - ); - } - - - //------------------------------------- - // Main Server Function - //------------------------------------- - - function serve() - { - $r = $this->parseRequest(); - $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; - $payload .= $this->debug_msg; - $payload .= $r->prepare_response(); - - header("Content-Type: text/xml"); - header("Content-Length: ".strlen($payload)); - echo $payload; - } - - //------------------------------------- - // Add Method to Class - //------------------------------------- - - function add_to_map($methodname,$function,$sig,$doc) - { - $this->methods[$methodname] = array( - 'function' => $function, - 'signature' => $sig, - 'docstring' => $doc - ); - } - - - //------------------------------------- - // Parse Server Request - //------------------------------------- - - function parseRequest($data='') - { - global $HTTP_RAW_POST_DATA; - - //------------------------------------- - // Get Data - //------------------------------------- - - if ($data == '') - { - $data = $HTTP_RAW_POST_DATA; - } - - //------------------------------------- - // Set up XML Parser - //------------------------------------- - - $parser = xml_parser_create($this->xmlrpc_defencoding); - $parser_object = new XML_RPC_Message("filler"); - - $parser_object->xh[$parser] = array(); - $parser_object->xh[$parser]['isf'] = 0; - $parser_object->xh[$parser]['isf_reason'] = ''; - $parser_object->xh[$parser]['params'] = array(); - $parser_object->xh[$parser]['stack'] = array(); - $parser_object->xh[$parser]['valuestack'] = array(); - $parser_object->xh[$parser]['method'] = ''; - - xml_set_object($parser, $parser_object); - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); - xml_set_element_handler($parser, 'open_tag', 'closing_tag'); - xml_set_character_data_handler($parser, 'character_data'); - //xml_set_default_handler($parser, 'default_handler'); - - - //------------------------------------- - // PARSE + PROCESS XML DATA - //------------------------------------- - - if ( ! xml_parse($parser, $data, 1)) - { - // return XML error as a faultCode - $r = new XML_RPC_Response(0, - $this->xmlrpcerrxml + xml_get_error_code($parser), - sprintf('XML error: %s at line %d', - xml_error_string(xml_get_error_code($parser)), - xml_get_current_line_number($parser))); - xml_parser_free($parser); - } - elseif($parser_object->xh[$parser]['isf']) - { - return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); - } - else - { - xml_parser_free($parser); - - $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); - $plist=''; - - for($i=0; $i < count($parser_object->xh[$parser]['params']); $i++) - { - if ($this->debug === TRUE) - { - $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; - } - - $m->addParam($parser_object->xh[$parser]['params'][$i]); - } - - if ($this->debug === TRUE) - { - echo "
    ";
    -				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
    -				echo "
    "; - } - - $r = $this->_execute($m); - } - - //------------------------------------- - // SET DEBUGGING MESSAGE - //------------------------------------- - - if ($this->debug === TRUE) - { - $this->debug_msg = "\n"; - } - - return $r; - } - - //------------------------------------- - // Executes the Method - //------------------------------------- - - function _execute($m) - { - $methName = $m->method_name; - - // Check to see if it is a system call - $system_call = (strncmp($methName, 'system', 5) == 0) ? TRUE : FALSE; - - //------------------------------------- - // Valid Method - //------------------------------------- - - if ( ! isset($this->methods[$methName]['function'])) - { - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - } - - //------------------------------------- - // Check for Method (and Object) - //------------------------------------- - - $method_parts = explode(".", $this->methods[$methName]['function']); - $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? TRUE : FALSE; - - if ($system_call === TRUE) - { - if ( ! is_callable(array($this,$method_parts['1']))) - { - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - } - } - else - { - if ($objectCall && ! is_callable(array($method_parts['0'],$method_parts['1']))) - { - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - } - elseif ( ! $objectCall && ! is_callable($this->methods[$methName]['function'])) - { - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - } - } - - //------------------------------------- - // Checking Methods Signature - //------------------------------------- - - if (isset($this->methods[$methName]['signature'])) - { - $sig = $this->methods[$methName]['signature']; - for($i=0; $iparams)+1) - { - for($n=0; $n < count($m->params); $n++) - { - $p = $m->params[$n]; - $pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf(); - - if ($pt != $current_sig[$n+1]) - { - $pno = $n+1; - $wanted = $current_sig[$n+1]; - - return new XML_RPC_Response(0, - $this->xmlrpcerr['incorrect_params'], - $this->xmlrpcstr['incorrect_params'] . - ": Wanted {$wanted}, got {$pt} at param {$pno})"); - } - } - } - } - } - - //------------------------------------- - // Calls the Function - //------------------------------------- - - if ($objectCall === TRUE) - { - if ($method_parts[0] == "this" && $system_call == TRUE) - { - return call_user_func(array($this, $method_parts[1]), $m); - } - else - { - if ($this->object === FALSE) - { - $CI =& get_instance(); - return $CI->$method_parts['1']($m); - } - else - { - return $this->object->$method_parts['1']($m); - //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); - } - } - } - else - { - return call_user_func($this->methods[$methName]['function'], $m); - } - } - - - //------------------------------------- - // Server Function: List Methods - //------------------------------------- - - function listMethods($m) - { - $v = new XML_RPC_Values(); - $output = array(); - - foreach($this->methods as $key => $value) - { - $output[] = new XML_RPC_Values($key, 'string'); - } - - foreach($this->system_methods as $key => $value) - { - $output[]= new XML_RPC_Values($key, 'string'); - } - - $v->addArray($output); - return new XML_RPC_Response($v); - } - - //------------------------------------- - // Server Function: Return Signature for Method - //------------------------------------- - - function methodSignature($m) - { - $parameters = $m->output_parameters(); - $method_name = $parameters[0]; - - if (isset($this->methods[$method_name])) - { - if ($this->methods[$method_name]['signature']) - { - $sigs = array(); - $signature = $this->methods[$method_name]['signature']; - - for($i=0; $i < count($signature); $i++) - { - $cursig = array(); - $inSig = $signature[$i]; - for($j=0; $jxmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); - } - return $r; - } - - //------------------------------------- - // Server Function: Doc String for Method - //------------------------------------- - - function methodHelp($m) - { - $parameters = $m->output_parameters(); - $method_name = $parameters[0]; - - if (isset($this->methods[$method_name])) - { - $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : ''; - - return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); - } - else - { - return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); - } - } - - //------------------------------------- - // Server Function: Multi-call - //------------------------------------- - - function multicall($m) - { - // Disabled - return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - - $parameters = $m->output_parameters(); - $calls = $parameters[0]; - - $result = array(); - - foreach ($calls as $value) - { - //$attempt = $this->_execute(new XML_RPC_Message($value[0], $value[1])); - - $m = new XML_RPC_Message($value[0]); - $plist=''; - - for($i=0; $i < count($value[1]); $i++) - { - $m->addParam(new XML_RPC_Values($value[1][$i], 'string')); - } - - $attempt = $this->_execute($m); - - if ($attempt->faultCode() != 0) - { - return $attempt; - } - - $result[] = new XML_RPC_Values(array($attempt->value()), 'array'); - } - - return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); - } - - - //------------------------------------- - // Multi-call Function: Error Handling - //------------------------------------- - - function multicall_error($err) - { - $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); - $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode(); - - $struct['faultCode'] = new XML_RPC_Values($code, 'int'); - $struct['faultString'] = new XML_RPC_Values($str, 'string'); - - return new XML_RPC_Values($struct, 'struct'); - } - - - //------------------------------------- - // Multi-call Function: Processes method - //------------------------------------- - - function do_multicall($call) - { - if ($call->kindOf() != 'struct') - return $this->multicall_error('notstruct'); - elseif ( ! $methName = $call->me['struct']['methodName']) - return $this->multicall_error('nomethod'); - - list($scalar_type,$scalar_value)=each($methName->me); - $scalar_type = $scalar_type == $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type; - - if ($methName->kindOf() != 'scalar' OR $scalar_type != 'string') - return $this->multicall_error('notstring'); - elseif ($scalar_value == 'system.multicall') - return $this->multicall_error('recursion'); - elseif ( ! $params = $call->me['struct']['params']) - return $this->multicall_error('noparams'); - elseif ($params->kindOf() != 'array') - return $this->multicall_error('notarray'); - - list($a,$b)=each($params->me); - $numParams = count($b); - - $msg = new XML_RPC_Message($scalar_value); - for ($i = 0; $i < $numParams; $i++) - { - $msg->params[] = $params->me['array'][$i]; - } - - $result = $this->_execute($msg); - - if ($result->faultCode() != 0) - { - return $this->multicall_error($result); - } - - return new XML_RPC_Values(array($result->value()), 'array'); - } - -} -// END XML_RPC_Server class - - -/* End of file Xmlrpcs.php */ -/* Location: ./system/libraries/Xmlrpcs.php */ \ No newline at end of file diff --git a/bmt-system/libraries/Zip.php b/bmt-system/libraries/Zip.php deleted file mode 100755 index 7318815..0000000 --- a/bmt-system/libraries/Zip.php +++ /dev/null @@ -1,359 +0,0 @@ -_add_dir($dir); - } - } - - // -------------------------------------------------------------------- - - /** - * Add Directory - * - * @access private - * @param string the directory name - * @return void - */ - function _add_dir($dir) - { - $dir = str_replace("\\", "/", $dir); - - $this->zipdata .= - "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack('V', 0) // crc32 - .pack('V', 0) // compressed filesize - .pack('V', 0) // uncompressed filesize - .pack('v', strlen($dir)) // length of pathname - .pack('v', 0) // extra field length - .$dir - // below is "data descriptor" segment - .pack('V', 0) // crc32 - .pack('V', 0) // compressed filesize - .pack('V', 0); // uncompressed filesize - - $this->directory .= - "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack('V',0) // crc32 - .pack('V',0) // compressed filesize - .pack('V',0) // uncompressed filesize - .pack('v', strlen($dir)) // length of pathname - .pack('v', 0) // extra field length - .pack('v', 0) // file comment length - .pack('v', 0) // disk number start - .pack('v', 0) // internal file attributes - .pack('V', 16) // external file attributes - 'directory' bit set - .pack('V', $this->offset) // relative offset of local header - .$dir; - - $this->offset = strlen($this->zipdata); - $this->entries++; - } - - // -------------------------------------------------------------------- - - /** - * Add Data to Zip - * - * Lets you add files to the archive. If the path is included - * in the filename it will be placed within a directory. Make - * sure you use add_dir() first to create the folder. - * - * @access public - * @param mixed - * @param string - * @return void - */ - function add_data($filepath, $data = NULL) - { - if (is_array($filepath)) - { - foreach ($filepath as $path => $data) - { - $this->_add_data($path, $data); - } - } - else - { - $this->_add_data($filepath, $data); - } - } - - // -------------------------------------------------------------------- - - /** - * Add Data to Zip - * - * @access private - * @param string the file name/path - * @param string the data to be encoded - * @return void - */ - function _add_data($filepath, $data) - { - $filepath = str_replace("\\", "/", $filepath); - - $uncompressed_size = strlen($data); - $crc32 = crc32($data); - - $gzdata = gzcompress($data); - $gzdata = substr($gzdata, 2, -4); - $compressed_size = strlen($gzdata); - - $this->zipdata .= - "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack('V', $crc32) - .pack('V', $compressed_size) - .pack('V', $uncompressed_size) - .pack('v', strlen($filepath)) // length of filename - .pack('v', 0) // extra field length - .$filepath - .$gzdata; // "file data" segment - - $this->directory .= - "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack('V', $crc32) - .pack('V', $compressed_size) - .pack('V', $uncompressed_size) - .pack('v', strlen($filepath)) // length of filename - .pack('v', 0) // extra field length - .pack('v', 0) // file comment length - .pack('v', 0) // disk number start - .pack('v', 0) // internal file attributes - .pack('V', 32) // external file attributes - 'archive' bit set - .pack('V', $this->offset) // relative offset of local header - .$filepath; - - $this->offset = strlen($this->zipdata); - $this->entries++; - $this->file_num++; - } - - // -------------------------------------------------------------------- - - /** - * Read the contents of a file and add it to the zip - * - * @access public - * @return bool - */ - function read_file($path, $preserve_filepath = FALSE) - { - if ( ! file_exists($path)) - { - return FALSE; - } - - if (FALSE !== ($data = file_get_contents($path))) - { - $name = str_replace("\\", "/", $path); - - if ($preserve_filepath === FALSE) - { - $name = preg_replace("|.*/(.+)|", "\\1", $name); - } - - $this->add_data($name, $data); - return TRUE; - } - return FALSE; - } - - // ------------------------------------------------------------------------ - - /** - * Read a directory and add it to the zip. - * - * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a zip based on it. Whatever directory structure - * is in the original file path will be recreated in the zip file. - * - * @access public - * @param string path to source - * @return bool - */ - function read_dir($path) - { - if ($fp = @opendir($path)) - { - while (FALSE !== ($file = readdir($fp))) - { - if (@is_dir($path.$file) && substr($file, 0, 1) != '.') - { - $this->read_dir($path.$file."/"); - } - elseif (substr($file, 0, 1) != ".") - { - if (FALSE !== ($data = file_get_contents($path.$file))) - { - $this->add_data(str_replace("\\", "/", $path).$file, $data); - } - } - } - return TRUE; - } - } - - // -------------------------------------------------------------------- - - /** - * Get the Zip file - * - * @access public - * @return binary string - */ - function get_zip() - { - // Is there any data to return? - if ($this->entries == 0) - { - return FALSE; - } - - $zip_data = $this->zipdata; - $zip_data .= $this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00"; - $zip_data .= pack('v', $this->entries); // total # of entries "on this disk" - $zip_data .= pack('v', $this->entries); // total # of entries overall - $zip_data .= pack('V', strlen($this->directory)); // size of central dir - $zip_data .= pack('V', strlen($this->zipdata)); // offset to start of central dir - $zip_data .= "\x00\x00"; // .zip file comment length - - return $zip_data; - } - - // -------------------------------------------------------------------- - - /** - * Write File to the specified directory - * - * Lets you write a file - * - * @access public - * @param string the file name - * @return bool - */ - function archive($filepath) - { - if ( ! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE))) - { - return FALSE; - } - - flock($fp, LOCK_EX); - fwrite($fp, $this->get_zip()); - flock($fp, LOCK_UN); - fclose($fp); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Download - * - * @access public - * @param string the file name - * @param string the data to be encoded - * @return bool - */ - function download($filename = 'backup.zip') - { - if ( ! preg_match("|.+?\.zip$|", $filename)) - { - $filename .= '.zip'; - } - - $zip_content =& $this->get_zip(); - - $CI =& get_instance(); - $CI->load->helper('download'); - - force_download($filename, $zip_content); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Data - * - * Lets you clear current zip data. Useful if you need to create - * multiple zips with different data. - * - * @access public - * @return void - */ - function clear_data() - { - $this->zipdata = ''; - $this->directory = ''; - $this->entries = 0; - $this->file_num = 0; - $this->offset = 0; - } - -} - -/* End of file Zip.php */ -/* Location: ./system/libraries/Zip.php */ \ No newline at end of file diff --git a/bmt-system/libraries/index.html b/bmt-system/libraries/index.html deleted file mode 100755 index c942a79..0000000 --- a/bmt-system/libraries/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/bmt-system/logs/index.html b/bmt-system/logs/index.html deleted file mode 100755 index c942a79..0000000 --- a/bmt-system/logs/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/bmt-system/plugins/captcha_pi.php b/bmt-system/plugins/captcha_pi.php deleted file mode 100755 index 4a09dcb..0000000 --- a/bmt-system/plugins/captcha_pi.php +++ /dev/null @@ -1,356 +0,0 @@ -load->plugin('captcha'); - -Once loaded you can generate a captcha like this: - - $vals = array( - 'word' => 'Random word', - 'img_path' => './captcha/', - 'img_url' => 'http://example.com/captcha/', - 'font_path' => './system/fonts/texb.ttf', - 'img_width' => '150', - 'img_height' => 30, - 'expiration' => 7200 - ); - - $cap = create_captcha($vals); - echo $cap['image']; - - -NOTES: - - The captcha function requires the GD image library. - - Only the img_path and img_url are required. - - If a "word" is not supplied, the function will generate a random - ASCII string. You might put together your own word library that - you can draw randomly from. - - If you do not specify a path to a TRUE TYPE font, the native ugly GD - font will be used. - - The "captcha" folder must be writable (666, or 777) - - The "expiration" (in seconds) signifies how long an image will - remain in the captcha folder before it will be deleted. The default - is two hours. - -RETURNED DATA - -The create_captcha() function returns an associative array with this data: - - [array] - ( - 'image' => IMAGE TAG - 'time' => TIMESTAMP (in microtime) - 'word' => CAPTCHA WORD - ) - -The "image" is the actual image tag: - - -The "time" is the micro timestamp used as the image name without the file -extension. It will be a number like this: 1139612155.3422 - -The "word" is the word that appears in the captcha image, which if not -supplied to the function, will be a random string. - - -ADDING A DATABASE - -In order for the captcha function to prevent someone from posting, you will need -to add the information returned from create_captcha() function to your database. -Then, when the data from the form is submitted by the user you will need to verify -that the data exists in the database and has not expired. - -Here is a table prototype: - - CREATE TABLE captcha ( - captcha_id bigint(13) unsigned NOT NULL auto_increment, - captcha_time int(10) unsigned NOT NULL, - ip_address varchar(16) default '0' NOT NULL, - word varchar(20) NOT NULL, - PRIMARY KEY `captcha_id` (`captcha_id`), - KEY `word` (`word`) - ) - - -Here is an example of usage with a DB. - -On the page where the captcha will be shown you'll have something like this: - - $this->load->plugin('captcha'); - $vals = array( - 'img_path' => './captcha/', - 'img_url' => 'http://example.com/captcha/' - ); - - $cap = create_captcha($vals); - - $data = array( - 'captcha_id' => '', - 'captcha_time' => $cap['time'], - 'ip_address' => $this->input->ip_address(), - 'word' => $cap['word'] - ); - - $query = $this->db->insert_string('captcha', $data); - $this->db->query($query); - - echo 'Submit the word you see below:'; - echo $cap['image']; - echo ''; - - -Then, on the page that accepts the submission you'll have something like this: - - // First, delete old captchas - $expiration = time()-7200; // Two hour limit - $DB->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); - - // Then see if a captcha exists: - $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND date > ?"; - $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); - $query = $this->db->query($sql, $binds); - $row = $query->row(); - - if ($row->count == 0) - { - echo "You must submit the word that appears in the image"; - } - -*/ - - - -/** -|========================================================== -| Create Captcha -|========================================================== -| -*/ -function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '') -{ - $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200); - - foreach ($defaults as $key => $val) - { - if ( ! is_array($data)) - { - if ( ! isset($$key) OR $$key == '') - { - $$key = $val; - } - } - else - { - $$key = ( ! isset($data[$key])) ? $val : $data[$key]; - } - } - - if ($img_path == '' OR $img_url == '') - { - return FALSE; - } - - if ( ! @is_dir($img_path)) - { - return FALSE; - } - - if ( ! is_really_writable($img_path)) - { - return FALSE; - } - - if ( ! extension_loaded('gd')) - { - return FALSE; - } - - // ----------------------------------- - // Remove old images - // ----------------------------------- - - list($usec, $sec) = explode(" ", microtime()); - $now = ((float)$usec + (float)$sec); - - $current_dir = @opendir($img_path); - - while($filename = @readdir($current_dir)) - { - if ($filename != "." and $filename != ".." and $filename != "index.html") - { - $name = str_replace(".jpg", "", $filename); - - if (($name + $expiration) < $now) - { - @unlink($img_path.$filename); - } - } - } - - @closedir($current_dir); - - // ----------------------------------- - // Do we have a "word" yet? - // ----------------------------------- - - if ($word == '') - { - $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - - $str = ''; - for ($i = 0; $i < 8; $i++) - { - $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); - } - - $word = $str; - } - - // ----------------------------------- - // Determine angle and position - // ----------------------------------- - - $length = strlen($word); - $angle = ($length >= 6) ? rand(-($length-6), ($length-6)) : 0; - $x_axis = rand(6, (360/$length)-16); - $y_axis = ($angle >= 0 ) ? rand($img_height, $img_width) : rand(6, $img_height); - - // ----------------------------------- - // Create image - // ----------------------------------- - - // PHP.net recommends imagecreatetruecolor(), but it isn't always available - if (function_exists('imagecreatetruecolor')) - { - $im = imagecreatetruecolor($img_width, $img_height); - } - else - { - $im = imagecreate($img_width, $img_height); - } - - // ----------------------------------- - // Assign colors - // ----------------------------------- - - $bg_color = imagecolorallocate ($im, 255, 255, 255); - $border_color = imagecolorallocate ($im, 153, 102, 102); - $text_color = imagecolorallocate ($im, 204, 153, 153); - $grid_color = imagecolorallocate($im, 255, 182, 182); - $shadow_color = imagecolorallocate($im, 255, 240, 240); - - // ----------------------------------- - // Create the rectangle - // ----------------------------------- - - ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color); - - // ----------------------------------- - // Create the spiral pattern - // ----------------------------------- - - $theta = 1; - $thetac = 7; - $radius = 16; - $circles = 20; - $points = 32; - - for ($i = 0; $i < ($circles * $points) - 1; $i++) - { - $theta = $theta + $thetac; - $rad = $radius * ($i / $points ); - $x = ($rad * cos($theta)) + $x_axis; - $y = ($rad * sin($theta)) + $y_axis; - $theta = $theta + $thetac; - $rad1 = $radius * (($i + 1) / $points); - $x1 = ($rad1 * cos($theta)) + $x_axis; - $y1 = ($rad1 * sin($theta )) + $y_axis; - imageline($im, $x, $y, $x1, $y1, $grid_color); - $theta = $theta - $thetac; - } - - // ----------------------------------- - // Write the text - // ----------------------------------- - - $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE; - - if ($use_font == FALSE) - { - $font_size = 5; - $x = rand(0, $img_width/($length/3)); - $y = 0; - } - else - { - $font_size = 16; - $x = rand(0, $img_width/($length/1.5)); - $y = $font_size+2; - } - - for ($i = 0; $i < strlen($word); $i++) - { - if ($use_font == FALSE) - { - $y = rand(0 , $img_height/2); - imagestring($im, $font_size, $x, $y, substr($word, $i, 1), $text_color); - $x += ($font_size*2); - } - else - { - $y = rand($img_height/2, $img_height-3); - imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1)); - $x += $font_size; - } - } - - - // ----------------------------------- - // Create the border - // ----------------------------------- - - imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); - - // ----------------------------------- - // Generate the image - // ----------------------------------- - - $img_name = $now.'.jpg'; - - ImageJPEG($im, $img_path.$img_name); - - $img = "\""; - - ImageDestroy($im); - - return array('word' => $word, 'time' => $now, 'image' => $img); -} - - -/* End of file captcha_pi.php */ -/* Location: ./system/plugins/captcha_pi.php */ \ No newline at end of file diff --git a/bmt-system/plugins/index.html b/bmt-system/plugins/index.html deleted file mode 100755 index c942a79..0000000 --- a/bmt-system/plugins/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/bmt-system/plugins/js_calendar_pi.php b/bmt-system/plugins/js_calendar_pi.php deleted file mode 100755 index 6dadd4a..0000000 --- a/bmt-system/plugins/js_calendar_pi.php +++ /dev/null @@ -1,629 +0,0 @@ -load->plugin('js_calendar'); - -Once loaded you'll add the calendar script to the of your page like this: - - - -The above function will be passed the name of your form. - -Then to show the actual calendar you'll do this: - - -
    - -

    Today

    -
    - - -Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, -and the third tells the calendar whether to highlight the current day or not. - -Lastly, you'll need some CSS for your calendar: - -.calendar { - border: 1px #6975A3 solid; - background-color: transparent; -} -.calheading { - background-color: #7C8BC0; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; -} -.calnavleft { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - padding: 4px; - cursor: pointer; -} -.calnavright { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - text-align: right; - padding: 4px; - cursor: pointer; -} -.caldayheading { - background-color: #000; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - text-align: center; - padding: 6px 2px 6px 2px; -} -.caldaycells{ - color: #000; - background-color: #D1D7E6; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #E0E5F1 solid; - cursor: pointer; -} -.caldaycellhover{ - color: #fff; - background-color: #B3BCD4; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #B3BCD4 solid; - cursor: pointer; -} -.caldayselected{ - background-color: #737FAC; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; - border: 1px #566188 solid; - padding: 3px; - cursor: pointer; -} -.calblanktop { - background-color: #fff; - padding: 4px; -} -.calblankbot { - background-color: #fff; - padding: 4px; -} - - -*/ - -function js_calendar_script($form_name = 'entryform') -{ -$CI =& get_instance(); -$CI->load->language('calendar'); -ob_start(); -?> - - - var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); - document.write('.$field_id.'.write()); - '; -} - - -/* End of file js_calendar_pi.php */ -/* Location: ./system/plugins/js_calendar_pi.php */ \ No newline at end of file diff --git a/bmt-system/scaffolding/Scaffolding.php b/bmt-system/scaffolding/Scaffolding.php deleted file mode 100755 index 1d52670..0000000 --- a/bmt-system/scaffolding/Scaffolding.php +++ /dev/null @@ -1,291 +0,0 @@ -CI =& get_instance(); - - $this->CI->load->database("", FALSE, TRUE); - $this->CI->load->library('pagination'); - - // Turn off caching - $this->CI->db->cache_off(); - - /** - * Set the current table name - * This is done when initializing scaffolding: - * $this->load->scaffolding('table_name') - * - */ - $this->current_table = $db_table; - - /** - * Set the path to the "view" files - * We'll manually override the "view" path so that - * the load->view function knows where to look. - */ - - $this->CI->load->_ci_view_path = BASEPATH.'scaffolding/views/'; - - // Set the base URL - $this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both'); - $this->base_uri = $this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'leading'); - - // Set a few globals - $data = array( - 'image_url' => $this->CI->config->system_url().'scaffolding/images/', - 'base_uri' => $this->base_uri, - 'base_url' => $this->base_url, - 'title' => $this->current_table - ); - - $this->CI->load->vars($data); - - // Load the language file and create variables - $this->lang = $this->CI->load->scaffold_language('scaffolding', '', TRUE); - $this->CI->load->vars($this->lang); - - // Load the helper files we plan to use - $this->CI->load->helper(array('url', 'form')); - - - log_message('debug', 'Scaffolding Class Initialized'); - } - - // -------------------------------------------------------------------- - - /** - * "Add" Page - * - * Shows a form representing the currently selected DB - * so that data can be inserted - * - * @access public - * @return string the HTML "add" page - */ - function add() - { - $data = array( - 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], - 'fields' => $this->CI->db->field_data($this->current_table), - 'action' => $this->base_uri.'/insert' - ); - - $this->CI->load->view('add', $data); - } - - // -------------------------------------------------------------------- - - /** - * Insert the data - * - * @access public - * @return void redirects to the view page - */ - function insert() - { - if ($this->CI->db->insert($this->current_table, $_POST) === FALSE) - { - $this->add(); - } - else - { - redirect($this->base_uri.'/view/'); - } - } - - // -------------------------------------------------------------------- - - /** - * "View" Page - * - * Shows a table containing the data in the currently - * selected DB - * - * @access public - * @return string the HTML "view" page - */ - function view() - { - // Fetch the total number of DB rows - $total_rows = $this->CI->db->count_all($this->current_table); - - if ($total_rows < 1) - { - return $this->CI->load->view('no_data'); - } - - // Set the query limit/offset - $per_page = 20; - $offset = $this->CI->uri->segment(4, 0); - - // Run the query - $query = $this->CI->db->get($this->current_table, $per_page, $offset); - - // Now let's get the field names - $fields = $this->CI->db->list_fields($this->current_table); - - // We assume that the column in the first position is the primary field. - $primary = current($fields); - - // Pagination! - $this->CI->pagination->initialize( - array( - 'base_url' => $this->base_url.'/view', - 'total_rows' => $total_rows, - 'per_page' => $per_page, - 'uri_segment' => 4, - 'full_tag_open' => '

    ', - 'full_tag_close' => '

    ' - ) - ); - - $data = array( - 'title' => ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], - 'query' => $query, - 'fields' => $fields, - 'primary' => $primary, - 'paginate' => $this->CI->pagination->create_links() - ); - - $this->CI->load->view('view', $data); - } - - // -------------------------------------------------------------------- - - /** - * "Edit" Page - * - * Shows a form representing the currently selected DB - * so that data can be edited - * - * @access public - * @return string the HTML "edit" page - */ - function edit() - { - if (FALSE === ($id = $this->CI->uri->segment(4))) - { - return $this->view(); - } - - // Fetch the primary field name - $primary = $this->CI->db->primary($this->current_table); - - // Run the query - $query = $this->CI->db->get_where($this->current_table, array($primary => $id)); - - $data = array( - 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], - 'fields' => $query->field_data(), - 'query' => $query->row(), - 'action' => $this->base_uri.'/update/'.$this->CI->uri->segment(4) - ); - - $this->CI->load->view('edit', $data); - } - - // -------------------------------------------------------------------- - - /** - * Update - * - * @access public - * @return void redirects to the view page - */ - function update() - { - // Fetch the primary key - $primary = $this->CI->db->primary($this->current_table); - - // Now do the query - $this->CI->db->update($this->current_table, $_POST, array($primary => $this->CI->uri->segment(4))); - - redirect($this->base_uri.'/view/'); - } - - // -------------------------------------------------------------------- - - /** - * Delete Confirmation - * - * @access public - * @return string the HTML "delete confirm" page - */ - function delete() - { - if ( ! isset($this->lang['scaff_del_confirm'])) - { - $message = 'Are you sure you want to delete the following row: '.$this->CI->uri->segment(4); - } - else - { - $message = $this->lang['scaff_del_confirm'].' '.$this->CI->uri->segment(4); - } - - $data = array( - 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], - 'message' => $message, - 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), - 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) - ); - - $this->CI->load->view('delete', $data); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * @access public - * @return void redirects to the view page - */ - function do_delete() - { - // Fetch the primary key - $primary = $this->CI->db->primary($this->current_table); - - // Now do the query - $this->CI->db->where($primary, $this->CI->uri->segment(4)); - $this->CI->db->delete($this->current_table); - - header("Refresh:0;url=".site_url(array($this->base_uri, 'view'))); - exit; - } - -} - -/* End of file Scaffolding.php */ -/* Location: ./system/scaffolding/Scaffolding.php */ \ No newline at end of file diff --git a/bmt-system/scaffolding/images/background.jpg b/bmt-system/scaffolding/images/background.jpg deleted file mode 100755 index 9d5bdce..0000000 Binary files a/bmt-system/scaffolding/images/background.jpg and /dev/null differ diff --git a/bmt-system/scaffolding/images/index.html b/bmt-system/scaffolding/images/index.html deleted file mode 100755 index c942a79..0000000 --- a/bmt-system/scaffolding/images/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/bmt-system/scaffolding/images/logo.jpg b/bmt-system/scaffolding/images/logo.jpg deleted file mode 100755 index d6cc9a7..0000000 Binary files a/bmt-system/scaffolding/images/logo.jpg and /dev/null differ diff --git a/bmt-system/scaffolding/index.html b/bmt-system/scaffolding/index.html deleted file mode 100755 index c942a79..0000000 --- a/bmt-system/scaffolding/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/bmt-system/scaffolding/views/add.php b/bmt-system/scaffolding/views/add.php deleted file mode 100755 index cbb12f6..0000000 --- a/bmt-system/scaffolding/views/add.php +++ /dev/null @@ -1,32 +0,0 @@ -load->view('header'); ?> - -

    - - - - - - - -primary_key == 1) continue; ?> - - - - - type == 'blob'): ?> - - - - - - - -
    name; echo ' '.$field->default; ?>
    - - - - - -load->view('footer'); -/* End of file add.php */ -/* Location: ./system/scaffolding/views/add.php */ diff --git a/bmt-system/scaffolding/views/delete.php b/bmt-system/scaffolding/views/delete.php deleted file mode 100755 index d195421..0000000 --- a/bmt-system/scaffolding/views/delete.php +++ /dev/null @@ -1,9 +0,0 @@ -load->view('header'); ?> - -

    - -

      |   - -load->view('footer'); -/* End of file delete.php */ -/* Location: ./system/scaffolding/views/delete.php */ diff --git a/bmt-system/scaffolding/views/edit.php b/bmt-system/scaffolding/views/edit.php deleted file mode 100755 index fe553e5..0000000 --- a/bmt-system/scaffolding/views/edit.php +++ /dev/null @@ -1,33 +0,0 @@ -load->view('header'); ?> - - -

    - - - - - - - -primary_key == 1) continue; ?> - - - - - type == 'blob'): ?> - - - - - - - -
    name; ?>
    - - - - - -load->view('footer'); -/* End of file edit.php */ -/* Location: ./system/scaffolding/views/edit.php */ \ No newline at end of file diff --git a/bmt-system/scaffolding/views/footer.php b/bmt-system/scaffolding/views/footer.php deleted file mode 100755 index 0e71401..0000000 --- a/bmt-system/scaffolding/views/footer.php +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/bmt-system/scaffolding/views/header.php b/bmt-system/scaffolding/views/header.php deleted file mode 100755 index 50f234a..0000000 --- a/bmt-system/scaffolding/views/header.php +++ /dev/null @@ -1,29 +0,0 @@ - - - - -<?php echo $title; ?> - - - - - - - - - - - - -
    -
    \ No newline at end of file diff --git a/bmt-system/scaffolding/views/index.html b/bmt-system/scaffolding/views/index.html deleted file mode 100755 index c942a79..0000000 --- a/bmt-system/scaffolding/views/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/bmt-system/scaffolding/views/no_data.php b/bmt-system/scaffolding/views/no_data.php deleted file mode 100755 index bc81e74..0000000 --- a/bmt-system/scaffolding/views/no_data.php +++ /dev/null @@ -1,8 +0,0 @@ -load->view('header'); ?> - -

    -

    - -load->view('footer'); -/* End of file no_data.php */ -/* Location: ./system/scaffolding/views/no_data.php */ \ No newline at end of file diff --git a/bmt-system/scaffolding/views/stylesheet.css b/bmt-system/scaffolding/views/stylesheet.css deleted file mode 100755 index 3f487dd..0000000 --- a/bmt-system/scaffolding/views/stylesheet.css +++ /dev/null @@ -1,143 +0,0 @@ -body { - margin: 0; - padding: 0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - color: #4F5155; - background: #fff url(background.jpg) repeat-x left top; -} - -a { - color: #8B0D00; - background-color: transparent; - text-decoration: none; - font-weight: bold; -} - -a:visited { - color: #8B0D00; - background-color: transparent; - text-decoration: none; -} - -a:hover { - color: #000; - text-decoration: none; - background-color: transparent; -} - - -#header { - margin: 0; - padding: 0; -} - -#header_left { - background-color: transparent; - float: left; - padding: 21px 0 0 32px; - margin: 0 -} - -#header_right { - background-color: transparent; - float: right; - text-align: right; - padding: 35px 50px 20px 0; - margin: 0 -} - -#footer { - margin: 20px 0 15px 0; - padding: 0; -} - -#footer p { - font-size: 10px; - color: #999; - text-align: center; -} - -#outer { - margin: 30px 40px 0 40px; -} - -img { - padding:0; - border: 0; - margin: 0; -} - -.nopad { - padding:0; - border: 0; - margin: 0; -} - -table { - background-color: #efefef; -} - -th { - background-color: #eee; - font-weight: bold; - padding: 6px; - text-align: left; -} - -td { - background-color: #fff; - padding: 6px; -} - - -form { - margin: 0; - padding: 0; -} - -.input { - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - width: 600px; - color: #333; - border: 1px solid #B3B4BD; - font-size: 11px; - height: 2em; - padding: 0; - margin: 0; -} - -.textarea { - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 12px; - width: 600px; - color: #333; - border: 1px solid #B3B4BD; - padding: 0; - margin: 0; -} - -.select { - background-color: #fff; - font-size: 11px; - font-weight: normal; - color: #333; - padding: 0; - margin: 0 0 3px 0; -} - -.checkbox { - background-color: transparent; - padding: 0; - border: 0; -} - -.submit { - background-color: #8B0D00; - color: #FFF; - font-weight: normal; - border: 1px solid #000; - margin: 6px 0 0 0; - padding: 1px 5px 1px 5px; -} diff --git a/bmt-system/scaffolding/views/view.php b/bmt-system/scaffolding/views/view.php deleted file mode 100755 index a81241d..0000000 --- a/bmt-system/scaffolding/views/view.php +++ /dev/null @@ -1,27 +0,0 @@ -load->view('header'); ?> - - - - - - - - - - -result() as $row): ?> - - - - - - - - -
    EditDelete
     $primary), $scaff_edit); ?> $primary), $scaff_delete); ?>$field);?>
    - - - -load->view('footer'); -/* End of file view.php */ -/* Location: ./system/scaffolding/views/view.php */ \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..2e88908 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "faisalman/simple-excel-php": "^0.3.15" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..2fc7deb --- /dev/null +++ b/composer.lock @@ -0,0 +1,73 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "72a68a220e79bcbd372e88b0335bd5b3", + "packages": [ + { + "name": "faisalman/simple-excel-php", + "version": "v0.3.15", + "source": { + "type": "git", + "url": "https://github.com/faisalman/simple-excel-php.git", + "reference": "c392d9ee34cce210f034c9a9ef814f635320351c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/faisalman/simple-excel-php/zipball/c392d9ee34cce210f034c9a9ef814f635320351c", + "reference": "c392d9ee34cce210f034c9a9ef814f635320351c", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "autoload": { + "psr-0": { + "SimpleExcel\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Faisal Salman", + "email": "fyzlman@gmail.com", + "homepage": "http://faisalman.com", + "role": "Developer" + } + ], + "description": "Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats", + "homepage": "http://faisalman.github.com/simple-excel-php", + "keywords": [ + "converter", + "csv", + "document", + "excel", + "html", + "json", + "parser", + "spreadsheet", + "tsv", + "writer", + "xml" + ], + "time": "2013-03-21T19:48:38+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..8938c4a --- /dev/null +++ b/contributing.md @@ -0,0 +1,95 @@ +# Contributing to CodeIgniter + + +CodeIgniter is a community driven project and accepts contributions of code and documentation from the community. These contributions are made in the form of Issues or [Pull Requests](http://help.github.com/send-pull-requests/) on the [CodeIgniter repository](https://github.com/bcit-ci/CodeIgniter>) on GitHub. + +Issues are a quick way to point out a bug. If you find a bug or documentation error in CodeIgniter then please check a few things first: + +1. There is not already an open Issue +2. The issue has already been fixed (check the develop branch, or look for closed Issues) +3. Is it something really obvious that you can fix yourself? + +Reporting issues is helpful but an even better approach is to send a Pull Request, which is done by "Forking" the main repository and committing to your own copy. This will require you to use the version control system called Git. + +## Guidelines + +Before we look into how, here are the guidelines. If your Pull Requests fail +to pass these guidelines it will be declined and you will need to re-submit +when you’ve made the changes. This might sound a bit tough, but it is required +for us to maintain quality of the code-base. + +### PHP Style + +All code must meet the [Style Guide](http://codeigniter.com/user_guide/general/styleguide.html), which is +essentially the [Allman indent style](http://en.wikipedia.org/wiki/Indent_style#Allman_style), underscores and readable operators. This makes certain that all code is the same format as the existing code and means it will be as readable as possible. + +### Documentation + +If you change anything that requires a change to documentation then you will need to add it. New classes, methods, parameters, changing default values, etc are all things that will require a change to documentation. The change-log must also be updated for every change. Also PHPDoc blocks must be maintained. + +### Compatibility + +CodeIgniter recommends PHP 5.4 or newer to be used, but it should be +compatible with PHP 5.2.4 so all code supplied must stick to this +requirement. If PHP 5.3 (and above) functions or features are used then +there must be a fallback for PHP 5.2.4. + +### Branching + +CodeIgniter uses the [Git-Flow](http://nvie.com/posts/a-successful-git-branching-model/) branching model which requires all pull requests to be sent to the "develop" branch. This is +where the next planned version will be developed. The "master" branch will always contain the latest stable version and is kept clean so a "hotfix" (e.g: an emergency security patch) can be applied to master to create a new version, without worrying about other features holding it up. For this reason all commits need to be made to "develop" and any sent to "master" will be closed automatically. If you have multiple changes to submit, please place all changes into their own branch on your fork. + +One thing at a time: A pull request should only contain one change. That does not mean only one commit, but one change - however many commits it took. The reason for this is that if you change X and Y but send a pull request for both at the same time, we might really want X but disagree with Y, meaning we cannot merge the request. Using the Git-Flow branching model you can create new branches for both of these features and send two requests. + +### Signing + +You must sign your work, certifying that you either wrote the work or otherwise have the right to pass it on to an open source project. git makes this trivial as you merely have to use `--signoff` on your commits to your CodeIgniter fork. + +`git commit --signoff` + +or simply + +`git commit -s` + +This will sign your commits with the information setup in your git config, e.g. + +`Signed-off-by: John Q Public ` + +If you are using [Tower](http://www.git-tower.com/) there is a "Sign-Off" checkbox in the commit window. You could even alias git commit to use the `-s` flag so you don’t have to think about it. + +By signing your work in this manner, you certify to a "Developer's Certificate of Origin". The current version of this certificate is in the `DCO.txt` file in the root of this repository. + + +## How-to Guide + +There are two ways to make changes, the easy way and the hard way. Either way you will need to [create a GitHub account](https://github.com/signup/free). + +Easy way GitHub allows in-line editing of files for making simple typo changes and quick-fixes. This is not the best way as you are unable to test the code works. If you do this you could be introducing syntax errors, etc, but for a Git-phobic user this is good for a quick-fix. + +Hard way The best way to contribute is to "clone" your fork of CodeIgniter to your development area. That sounds like some jargon, but "forking" on GitHub means "making a copy of that repo to your account" and "cloning" means "copying that code to your environment so you can work on it". + +1. Set up Git (Windows, Mac & Linux) +2. Go to the CodeIgniter repo +3. Fork it +4. Clone your CodeIgniter repo: git@github.com:/CodeIgniter.git +5. Checkout the "develop" branch At this point you are ready to start making changes. +6. Fix existing bugs on the Issue tracker after taking a look to see nobody else is working on them. +7. Commit the files +8. Push your develop branch to your fork +9. Send a pull request [http://help.github.com/send-pull-requests/](http://help.github.com/send-pull-requests/) + +The Reactor Engineers will now be alerted about the change and at least one of the team will respond. If your change fails to meet the guidelines it will be bounced, or feedback will be provided to help you improve it. + +Once the Reactor Engineer handling your pull request is happy with it they will merge it into develop and your patch will be part of the next release. + +### Keeping your fork up-to-date + +Unlike systems like Subversion, Git can have multiple remotes. A remote is the name for a URL of a Git repository. By default your fork will have a remote named "origin" which points to your fork, but you can add another remote named "codeigniter" which points to `git://github.com/bcit-ci/CodeIgniter.git`. This is a read-only remote but you can pull from this develop branch to update your own. + +If you are using command-line you can do the following: + +1. `git remote add codeigniter git://github.com/bcit-ci/CodeIgniter.git` +2. `git pull codeigniter develop` +3. `git push origin develop` + +Now your fork is up to date. This should be done regularly, or before you send a pull request at least. \ No newline at end of file diff --git a/db_aksioma_v1.0.sql b/db_aksioma_v1.0.sql deleted file mode 100644 index 5528ee8..0000000 --- a/db_aksioma_v1.0.sql +++ /dev/null @@ -1,9404 +0,0 @@ --- phpMyAdmin SQL Dump --- version 3.2.4 --- http://www.phpmyadmin.net --- --- Host: localhost --- Generation Time: Jun 20, 2016 at 12:54 PM --- Server version: 5.1.44 --- PHP Version: 5.3.1 - -SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; - - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; - --- --- Database: `bmt_v1` --- - --- -------------------------------------------------------- - --- --- Table structure for table `bmt` --- - -CREATE TABLE IF NOT EXISTS `bmt` ( - `bmt_id` int(11) NOT NULL AUTO_INCREMENT, - `nama` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kode_cabang` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `alamat` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kota` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kode_pos` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `propinsi` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `wilayah_kerja` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`bmt_id`), - UNIQUE KEY `kode` (`kode_cabang`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ; - --- --- Dumping data for table `bmt` --- - -INSERT INTO `bmt` (`bmt_id`, `nama`, `kode_cabang`, `alamat`, `kota`, `kode_pos`, `propinsi`, `wilayah_kerja`) VALUES -(1, 'BMT AKSIOMA', '01', 'Setia Budi', 'Jakarta Selatan', '15960', '31', '01'); - --- -------------------------------------------------------- - --- --- Table structure for table `bmt_wilayah` --- - -CREATE TABLE IF NOT EXISTS `bmt_wilayah` ( - `wilayah_id` int(11) NOT NULL AUTO_INCREMENT, - `kode` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `wilayah_kerja` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`wilayah_id`), - UNIQUE KEY `kode` (`kode`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ; - --- --- Dumping data for table `bmt_wilayah` --- - -INSERT INTO `bmt_wilayah` (`wilayah_id`, `kode`, `wilayah_kerja`) VALUES -(1, '01', 'Jakarta'); - --- -------------------------------------------------------- - --- --- Table structure for table `coa_listakun` --- - -CREATE TABLE IF NOT EXISTS `coa_listakun` ( - `listakun_id` int(11) NOT NULL AUTO_INCREMENT, - `listakun_code` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `listakun_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `listakun_alias` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `listakun_parent` int(11) DEFAULT NULL, - `listakun_folder` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `listakun_level` int(11) DEFAULT NULL, - `listakun_pattern` varchar(90) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `listakun_sign` int(11) DEFAULT NULL, - `listakun_wight` int(11) DEFAULT NULL, - `listakun_active` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - PRIMARY KEY (`listakun_id`), - UNIQUE KEY `code` (`listakun_code`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=612 ; - --- --- Dumping data for table `coa_listakun` --- - -INSERT INTO `coa_listakun` (`listakun_id`, `listakun_code`, `listakun_name`, `listakun_alias`, `listakun_parent`, `listakun_folder`, `listakun_level`, `listakun_pattern`, `listakun_sign`, `listakun_wight`, `listakun_active`) VALUES -(506, '750.03.01', 'BEBAN PPAP – ISTISHNA', 'SSL', 505, '0', NULL, '7*3*3*1', -1, NULL, '1'), -(576, '201.60.00', 'TITIPAN ZAKAT, INFAQ, DANA KEBAJIKAN', '', 188, '1', NULL, '2*1*3', -1, 0, '1'), -(446, '605.01.01', 'BAGI HASIL TABUNGAN MUDHARABAH', 'SSL', 445, '0', NULL, '6*2*1*1', 1, NULL, '1'), -(507, '750.04.00', 'BEBAN PPAP – MUDHARABAH', 'SL', 500, '1', NULL, '7*3*4', -1, NULL, '1'), -(447, '605.05.00', 'BAGI HASIL DEPOSITO MUDHARABAH', 'SL', 444, '1', NULL, '6*2*2', 1, NULL, '1'), -(299, '505.00.00', 'PENDAPATAN KEUNTUNGAN SALAM', 'GL', 5, '1', NULL, '5*2', -1, NULL, '1'), -(300, '505.01.00', 'PENDAPATAN SALAM', 'SL', 299, '1', NULL, '5*2*1', -1, NULL, '1'), -(508, '750.04.01', 'BEBAN PPAP – MUDHARABAH', 'SSL', 507, '0', NULL, '7*3*4*1', -1, NULL, '1'), -(448, '605.05.01', 'BAGI HASIL DEPOSITO MUDHARABAH – 1 BULAN', 'SSL', 447, '0', NULL, '6*2*2*1', 1, NULL, '1'), -(301, '505.01.01', 'PENDAPATAN KEUNTUNGAN SALAM', 'SSL', 300, '0', NULL, '5*2*1*1', -1, NULL, '1'), -(400, '575.50.01', 'PENDAPATAN ADM MSY – MODAL KERJA', 'SSL', 399, '0', NULL, '5*12*2*1', -1, NULL, '1'), -(1, '100.00.00', 'AKTIVA', 'AKTIVA', 0, '1', NULL, '1', 1, NULL, '1'), -(2, '200.00.00', 'KEWAJIBAN, INVESTASI TIDAK TERIKAT DAN MODAL', 'KEWAJIBAN, INVESTASI TIDAK TER', 0, '1', NULL, '2', -1, NULL, '1'), -(3, '300.00.00', 'INVESTASI TIDAK TERIKAT', 'INVESTASI TIDAK TERIKAT', 0, '1', NULL, '3', -1, NULL, '1'), -(4, '400.00.00', 'M O D A L', 'M O D A L', 0, '1', NULL, '4', -1, NULL, '1'), -(5, '500.00.00', 'PENDAPATAN', 'BIAYA ATAS PENDAPATAN', 0, '1', NULL, '5', -1, NULL, '1'), -(6, '600.00.00', 'BAGI HASIL ITT DAN BEBAN', 'BAGI HASIL ITT DAN BEBAN', 0, '1', NULL, '6', 1, NULL, '1'), -(7, '700.00.00', 'PERKIRAAN BEBAN', 'PERKIRAAN BEBAN', 0, '1', NULL, '7', -1, NULL, '1'), -(10, '101.00.00', 'KAS', 'GL', 1, '1', NULL, '1*1', 1, NULL, '1'), -(11, '101.01.00', 'KAS KHASANAH UTAMA', 'SL', 10, '1', NULL, '1*1*1', 1, NULL, '1'), -(12, '101.03.00', 'KAS TELLER', 'SL', 10, '1', NULL, '1*1*2', 1, NULL, '1'), -(13, '110.00.00', 'BANK-BANK LAIN', 'GL', 1, '1', NULL, '1*2', 1, NULL, '1'), -(14, '110.01.00', 'BANK UMUM SYARIAH (GIRO)', 'BANK UMUM SYARIAH (GIRO)', 13, '1', NULL, '1*2*1', 1, NULL, '1'), -(15, '110.05.00', 'BPR SYARIAH (TABUNGAN)', 'BPR SYARIAH (TABUNGAN)', 13, '1', NULL, '1*2*2', 1, NULL, '1'), -(16, '499.99.00', 'BALLANCING', 'GL', 4, '1', NULL, '4*1', -1, NULL, '1'), -(17, '499.99.99', 'HISTORICAL BALLANCING', 'HISTORICAL BALLANCING', 16, '0', NULL, '4*1*1', -1, NULL, '1'), -(43, '125.05.00', 'MARGIN MURABAHAH DITANGGUHKAN (KR)', 'MARGIN MURABAHAH DITANGGUHKAN ', 37, '1', NULL, '1*3*2', 1, NULL, '1'), -(192, '250.00.00', 'KEWAJIBAN INVST TERIKAT EXECUTING (KITE)', 'GL', 2, '1', NULL, '2*5', -1, NULL, '1'), -(302, '510.00.00', 'PENDAPATAN MARGIN ISTISHNA', 'GL', 5, '1', NULL, '5*3', -1, NULL, '1'), -(44, '125.05.21', 'MARGIN MBA DITANGGUHKAN', '', 43, '0', NULL, '1*3*2*1', 1, 0, '1'), -(193, '301.00.00', 'INVT TDK TERIKAT BUKAN BANK', 'GL', 3, '1', NULL, '3*1', -1, NULL, '1'), -(572, '195.30.00', 'REKENING ANTAR BAGIAN', '', 78, '1', NULL, '1*17*4', 1, 0, '1'), -(382, '570.00.00', 'PENDAPATAN ADM - JUAL BELI', 'GL', 5, '1', NULL, '5*11', -1, 0, '1'), -(545, '780.00.00', 'BEBAN PENGEMBANGAN, PENGAWASAN & JASA AHLI (BPPJA)', 'GL', 7, '1', NULL, '7*5', -1, NULL, '1'), -(303, '510.01.00', 'PENDAPATAN MARGIN ISTISHNA', 'SL', 302, '1', NULL, '5*3*1', -1, NULL, '1'), -(19, '101.03.01', 'KAS TELLER', 'SSL', 12, '0', NULL, '1*1*2*1', 1, NULL, '1'), -(194, '310.00.00', 'INVESTASI TDK TERIKAT BANK', 'GL', 3, '1', NULL, '3*2', -1, NULL, '1'), -(20, '101.10.00', 'KAS KECIL', 'SL', 10, '1', NULL, '1*1*3', 1, NULL, '1'), -(452, '701.00.00', 'BEBAN PERSONALIA (BESON)', 'GL', 7, '1', NULL, '7*1', -1, NULL, '1'), -(546, '780.01.00', 'BPPJA – TENAGA AHLI', 'SL', 545, '1', NULL, '7*5*1', -1, NULL, '1'), -(304, '510.01.02', 'PENDAPATAN MARGIN ISTISHNA – INVESTASI', 'SSL', 303, '0', NULL, '5*3*1*1', -1, NULL, '1'), -(21, '101.10.01', 'KAS KECIL', 'SSL', 20, '0', NULL, '1*1*3*1', 1, NULL, '1'), -(383, '570.01.00', 'PENDAPATAN ADM MURABAHAH', 'SL', 382, '1', NULL, '5*11*1', -1, NULL, '1'), -(453, '701.01.00', 'BEBAN PENGURUS, BADAN PENGAWAS(BENGUS)', 'SL', 452, '1', NULL, '7*1*1', -1, NULL, '1'), -(305, '510.01.04', 'PENDAPATAN MARGIN ISTISHNA– PEMILIKAN RUMAH', 'SSL', 303, '0', NULL, '5*3*1*2', -1, NULL, '1'), -(22, '110.01.01', 'BANK UMUM SYARIAH-A (NAMA BANK)', 'BANK UMUM SYARIAH-A (NAMA BANK', 14, '0', NULL, '1*2*1*1', 1, NULL, '1'), -(195, '301.01.00', 'TABUNGAN MUDHARABAH', 'SL', 193, '1', NULL, '3*1*1', -1, NULL, '1'), -(23, '110.01.02', 'BANK UMUM SYARIAH– B (NAMA BANK)', 'BANK UMUM SYARIAH– B (NAMA BAN', 14, '0', NULL, '1*2*1*2', 1, NULL, '1'), -(547, '780.01.03', 'BPPJA –JASA KONSULTAN', 'SSL', 546, '0', NULL, '7*5*1*1', -1, NULL, '1'), -(48, '125.50.00', 'PIUTANG MURABAHAH JATUH TEMPO', 'PIUTANG MURABAHAH JATUH TEMPO', 37, '1', NULL, '1*3*3', 1, NULL, '1'), -(569, '301.05.03', 'INVESTASI MUDHARABAH - 3 BULAN', '', 196, '0', NULL, '3*1*2*2', -1, 0, '1'), -(24, '110.05.01', 'BPR-SYARIAH – A (NAMA BANK)', 'BPR-SYARIAH – A (NAMA BANK)', 15, '0', NULL, '1*2*2*1', 1, NULL, '1'), -(384, '570.01.02', 'PENDAPATAN ADM MURABAHAH – INVESTASI', 'SSL', 383, '0', NULL, '5*11*1*1', -1, NULL, '1'), -(25, '110.05.02', 'BPR SYARIAH – B (NAMA BANK', 'BPR SYARIAH – B (NAMA BANK', 15, '0', NULL, '1*2*2*2', 1, NULL, '1'), -(306, '510.01.05', 'PENDPTAN MRG ISTISHNA – PEMILIKAN KENDARAAN', 'SSL', 303, '0', NULL, '5*3*1*3', -1, NULL, '1'), -(196, '301.05.00', 'INVESTASI MUDHARABAH', 'SL', 193, '1', NULL, '3*1*2', -1, NULL, '1'), -(49, '125.50.02', 'PIUTANG MURABAHAH JT – INVESTASI', 'PIUTANG MURABAHAH JT – INVESTA', 48, '0', NULL, '1*3*3*1', 1, NULL, '1'), -(26, '115.00.00', 'PENEMPATAN PADA BANK LAIN', 'PENEMPATAN PADA BANK LAIN', 13, '1', NULL, '1*2*3', 1, NULL, '1'), -(454, '701.01.01', 'BEBAN PENGURUS DAN BADAN PENGAWAS', 'SSL', 453, '1', NULL, '7*1*1*1', -1, NULL, '1'), -(27, '115.01.00', 'DANA INVESTASI TDK TERIKAT', 'DANA INVESTASI TDK TERIKAT', 26, '1', NULL, '1*2*3*1', 1, NULL, '1'), -(50, '125.50.04', 'PIUTANG MURABAHAH JT– PEMILIKAN RUMAH', 'PIUTANG MURABAHAH JT– PEMILIKA', 48, '0', NULL, '1*3*3*2', 1, NULL, '1'), -(197, '301.01.01', 'TABUNGAN MUDHARABAH', 'SSL', 195, '0', NULL, '3*1*1*1', -1, NULL, '1'), -(28, '115.01.01', 'TABUNGAN MUDHARABAH', 'TABUNGAN MUDHARABAH', 27, '0', NULL, '1*2*3*1*1', 1, NULL, '1'), -(548, '780.01.05', 'BPPJA – HONORARIUM', 'SSL', 546, '0', NULL, '7*5*1*2', -1, NULL, '1'), -(385, '570.01.04', 'PENDAPATAN ADM MBA – PEMILIKAN RUMAH', 'SSL', 383, '0', NULL, '5*11*1*2', -1, NULL, '1'), -(307, '510.01.99', 'PENDAPATAN MARGIN ISTISHNA – LAINNYA', 'SSL', 303, '0', NULL, '5*3*1*4', -1, NULL, '1'), -(29, '115.01.02', 'DEPOSITO MUDHARABAH', 'DEPOSITO MUDHARABAH', 27, '0', NULL, '1*2*3*1*2', 1, NULL, '1'), -(51, '125.50.05', 'PIUTANG MURABAHAH JT– PEMILIKAN KENDARAAN', 'PIUTANG MURABAHAH JT– PEMILIKA', 48, '0', NULL, '1*3*3*3', 1, NULL, '1'), -(30, '115.85.00', 'LAINNYA', 'LAINNYA', 26, '1', NULL, '1*2*3*2', 1, NULL, '1'), -(198, '301.05.01', 'INVESTASI MUDHARABAH – 1 BULAN', 'SSL', 196, '0', NULL, '3*1*2*1', -1, NULL, '1'), -(31, '115.85.99', 'LAINNYA', 'LAINNYA', 30, '0', NULL, '1*2*3*2*1', 1, NULL, '1'), -(52, '125.50.99', 'MARGIN MBA DITANGGUHKAN – LAINNYA (KR)', 'MARGIN MBA DITANGGUHKAN – LAIN', 48, '0', NULL, '1*3*3*4', 1, NULL, '1'), -(308, '510.05.00', 'POTONGAN PELUNASAN ISTISHNA (DR)', 'SL', 302, '1', NULL, '5*3*2', -1, NULL, '1'), -(386, '570.01.05', 'PENDAPATAN ADM MBA – PEMILIKAN KENDARAAN', 'SSL', 383, '0', NULL, '5*11*1*3', -1, NULL, '1'), -(549, '780.01.06', 'BPPJA – PENDIDIKAN DAN PELATIHAN', 'SSL', 546, '0', NULL, '7*5*1*3', -1, NULL, '1'), -(53, '125.55.00', 'MARGIN MBA DITANGGUHKAN JATUH TEMPO (KR)', 'MARGIN MBA DITANGGUHKAN JATUH ', 37, '1', NULL, '1*3*4', 1, NULL, '1'), -(309, '510.05.02', 'POT PELUNASAN ISTISHNA – INVESTASI (DR)', 'SSL', 308, '0', NULL, '5*3*2*1', -1, NULL, '1'), -(387, '570.01.99', 'PENDAPATAN ADM MURABAHAH – LAINNYA', 'SSL', 383, '0', NULL, '5*11*1*4', -1, NULL, '1'), -(550, '780.10.00', 'BEBAN PERTEMUAN DAN RAPAT', 'SL', 545, '1', NULL, '7*5*2', -1, NULL, '1'), -(37, '125.00.00', 'PIUTANG MURABAHAH', 'GL', 1, '1', NULL, '1*3', 1, NULL, '1'), -(310, '510.05.04', 'POT PELUNASAN ISTISHNA– PEMILIKAN RUMAH (DR)', 'SSL', 308, '0', NULL, '5*3*2*2', -1, NULL, '1'), -(38, '125.01.21', 'PIUTANG MURABAHAH', '', 42, '0', NULL, '1*3*1*1', 1, 0, '1'), -(388, '570.40.00', 'PENDAPATAN ADM SALAM', 'SL', 382, '1', NULL, '5*11*2', -1, NULL, '1'), -(54, '125.55.02', 'MARGIN MBA DITGHKAN JT – INVESTASI (KR)', 'MARGIN MBA DITGHKAN JT – INVES', 53, '0', NULL, '1*3*4*1', 1, NULL, '1'), -(311, '510.05.05', 'POT PELUNASAN ISTISHNA – PEMILIKAN KEND (DR)', 'SSL', 308, '0', NULL, '5*3*2*3', -1, NULL, '1'), -(455, '701.02.02', 'BEBAN GAJI DAN UPAH POKOK', 'SSL', 453, '0', NULL, '7*1*1*2', -1, NULL, '1'), -(56, '125.55.05', 'MARGIN MBA DITGHKAN JT – PEMLK KEND (KR)', 'MARGIN MBA DITGHKAN JT – PEMLK', 53, '0', NULL, '1*3*4*3', 1, NULL, '1'), -(42, '125.01.00', 'PIUTANG MURABAHAH', 'PIUTANG MURABAHAH', 37, '1', NULL, '1*3*1', 1, NULL, '1'), -(55, '125.55.04', 'MARGIN MBA DITGHKAN JT – PEMLK RUMAH (KR)', 'MARGIN MBA DITGHKAN JT – PEMLK', 53, '0', NULL, '1*3*4*2', 1, NULL, '1'), -(389, '570.40.01', 'PENDAPATANADM SALAM', 'SSL', 388, '0', NULL, '5*11*2*1', -1, NULL, '1'), -(57, '125.55.99', 'MARGIN MBA DITGHKAN JT – LAINNYA (KR)', 'MARGIN MBA DITGHKAN JT – LAINN', 53, '0', NULL, '1*3*4*4', 1, NULL, '1'), -(325, '525.02.00', 'BEBAN AKTIVA IJARAH (DR)', 'SL', 321, '1', NULL, '5*6*2', -1, NULL, '1'), -(58, '130.00.00', 'PIUTANG SALAM', 'GL', 1, '1', NULL, '1*4', 1, NULL, '1'), -(551, '780.10.01', 'BEBAN PERTEMUAN DAN RAPAT', 'SSL', 550, '0', NULL, '7*5*2*1', -1, NULL, '1'), -(312, '510.05.99', 'POT PELUNASAN ISTISHNA – LAINNYA (DR)', 'SSL', 308, '0', NULL, '5*3*2*4', -1, NULL, '1'), -(59, '130.01.00', 'PIUTANG SALAM', 'PIUTANG SALAM', 58, '1', NULL, '1*4*1', 1, NULL, '1'), -(456, '701.05.00', 'BEBAN TUNJANGAN (BETUN)', 'SL', 452, '1', NULL, '7*1*2', -1, NULL, '1'), -(390, '570.50.00', 'PENDAPATAN ADM ISTISHNA', 'SL', 382, '1', NULL, '5*11*3', -1, NULL, '1'), -(326, '525.02.01', 'BEBAN PENYUSUTAN AKTIVA IJARAH (DR)', 'SSL', 325, '0', NULL, '5*6*2*1', -1, NULL, '1'), -(60, '130.01.01', 'PIUTANG SALAM', 'PIUTANG SALAM', 59, '0', NULL, '1*4*1*1', 1, NULL, '1'), -(61, '135.00.00', 'PIUTANG ISTISHNA', 'GL', 1, '1', NULL, '1*5', 1, NULL, '1'), -(62, '135.01.00', 'PIUTANG ISTISHNA', 'PIUTANG ISTISHNA', 61, '1', NULL, '1*5*1', 1, NULL, '1'), -(313, '515.00.00', 'PENDAPATAN BAGI HASIL MUDHARABAH', 'GL', 5, '1', NULL, '5*4', -1, NULL, '1'), -(552, '780.15.00', 'BEBAN– UMUM (BEBUM)', 'SL', 545, '1', NULL, '7*5*3', -1, NULL, '1'), -(63, '135.01.02', 'PIUTANG ISTISHNA – INVESTASI', 'PIUTANG ISTISHNA – INVESTASI', 62, '0', NULL, '1*5*1*1', 1, NULL, '1'), -(391, '570.50.02', 'PENDAPATAN ADM ISTISHNA – INVESTASI', 'SSL', 390, '0', NULL, '5*11*3*1', -1, NULL, '1'), -(64, '135.50.04', 'PIUTANG ISTISHNA JT – PEMILIKAN RUMAH', 'PIUTANG ISTISHNA JT – PEMILIKA', 62, '0', NULL, '1*5*1*2', 1, NULL, '1'), -(457, '701.05.01', 'TUNJANGAN JABATAN (TUNJAB)', 'SSL', 456, '0', NULL, '7*1*2*1', -1, NULL, '1'), -(65, '135.50.05', 'PIUTANG ISTISHNA JT – PEMILIKAN KENDARAAN', 'PIUTANG ISTISHNA JT – PEMILIKA', 62, '0', NULL, '1*5*1*3', 1, NULL, '1'), -(66, '135.50.99', 'MARGIN IST DITGHKAN JT– LAINNYA (KR)', 'MARGIN IST DITGHKAN JT– LAINNY', 62, '0', NULL, '1*5*1*4', 1, NULL, '1'), -(314, '515.01.00', 'PENDAPATAN BAGI HASIL MUDHARABAH(MDH)', 'SL', 313, '1', NULL, '5*4*1', -1, NULL, '1'), -(67, '140.00.00', 'PEMBIAYAAN MUDHARABAH', 'GL', 1, '1', NULL, '1*6', 1, NULL, '1'), -(199, '280.00.00', 'KEWAJIBAN LAINNYA', 'GL', 2, '1', NULL, '2*6', -1, NULL, '1'), -(68, '145.00.00', 'PEMBIAYAAN MUSYARAKAH', 'GL', 1, '1', NULL, '1*7', 1, NULL, '1'), -(69, '150.00.00', 'AKTIVA IJARAH', 'GL', 1, '1', NULL, '1*8', 1, NULL, '1'), -(70, '155.00.00', 'PENYALURAN INVST TERIKAT EXECUTING (PITE)', 'GL', 1, '1', NULL, '1*9', 1, NULL, '1'), -(71, '160.00.00', 'PINJAMAN QARDH', 'GL', 1, '1', NULL, '1*10', 1, NULL, '1'), -(458, '701.05.02', 'TUNJANGAN TRANSPORT (TUNTRAN) DAN MAKAN', 'SSL', 456, '0', NULL, '7*1*2*2', -1, NULL, '1'), -(200, '295.00.00', 'PINJAMAN SUBORDINASI & PINJ MODAL', 'GL', 2, '1', NULL, '2*7', -1, NULL, '1'), -(72, '165.00.00', 'PERSEDIAAN', 'GL', 1, '1', NULL, '1*11', 1, NULL, '1'), -(315, '515.01.01', 'PENDAPATAN BAGI HASIL MDH', 'SSL', 314, '0', NULL, '5*4*1*1', -1, 0, '1'), -(73, '170.00.00', 'AKTIVA ISTISHNA DLM PENYELESAIAN', 'GL', 1, '1', NULL, '1*12', 1, NULL, '1'), -(465, '701.15.01', 'BEBAN PENGOBATAN', 'SSL', 464, '0', NULL, '7*1*4*1', -1, NULL, '1'), -(553, '780.15.01', 'BEBAN UMUM – TRANSPORT DAN PENGIRIMAN BRG', 'SSL', 552, '0', NULL, '7*5*3*1', -1, NULL, '1'), -(74, '173.00.00', 'PENYERTAAN PADA ENTITAS LAIN', 'GL', 1, '1', NULL, '1*13', 1, NULL, '1'), -(466, '701.15.02', 'BEBAN OLAHRAGA / REKREASI', 'SSL', 464, '0', NULL, '7*1*4*2', -1, NULL, '1'), -(75, '175.00.00', 'PIUTANG LAINNYA', 'GL', 1, '1', NULL, '1*14', 1, NULL, '1'), -(467, '701.90.00', 'BEBAN TENAGA KERJA LAINNYA(BETEKLA)', 'SL', 452, '1', NULL, '7*1*5', -1, NULL, '1'), -(76, '180.00.00', 'AKTIVA TETAP', 'GL', 1, '1', NULL, '1*15', 1, NULL, '1'), -(201, '201.01.00', 'WADIAH', 'SL', 188, '1', NULL, '2*1*1', -1, NULL, '1'), -(77, '185.00.00', 'BEBAN DIBAYAR DIMUKA (BDD)', 'GL', 1, '1', NULL, '1*16', 1, NULL, '1'), -(468, '701.90.01', 'HADIAH TAHUNAN / THR', 'SSL', 467, '0', NULL, '7*1*5*1', -1, NULL, '1'), -(78, '195.00.00', 'AKTIVA LAINNYA', 'GL', 1, '1', NULL, '1*17', 1, NULL, '1'), -(554, '780.15.02', 'BEBAN UMUM – BIAYA ADM BANK', 'SSL', 552, '0', NULL, '7*5*3*2', -1, NULL, '1'), -(561, '790.05.06', 'KERUGIAN PENJUALAN INVENTARIS LAINNYA', 'SSL', 556, '0', NULL, '7*6*1*5', -1, NULL, '1'), -(79, '140.01.00', 'PEMBIAYAAN MUDHARABAH', 'PEMBIAYAAN MUDHARABAH', 67, '1', NULL, '1*6*1', 1, NULL, '1'), -(392, '570.50.04', 'PENDAPATAN ADM ISTISHNA– PEMILIKAN RUMAH', 'SSL', 390, '0', NULL, '5*11*3*2', -1, NULL, '1'), -(80, '140.01.01', 'PEMBIAYAAN MUDHARABAH', '', 79, '0', NULL, '1*6*1*1', 1, 0, '1'), -(459, '701.05.03', 'TUNJANGAN LAINNYA', 'SSL', 456, '0', NULL, '7*1*2*3', -1, NULL, '1'), -(317, '520.00.00', 'PENDAPATAN BAGI HASIL MUSYARAKAH', 'GL', 5, '1', NULL, '5*5', -1, NULL, '1'), -(82, '140.10.00', 'PIUTANG MUDHARIB JATUH TEMPO PEMB MDH', 'PIUTANG MUDHARIB JATUH TEMPO P', 67, '1', NULL, '1*6*2', 1, NULL, '1'), -(83, '140.10.01', 'PIUTANG MUDHARIB JT PEMB MDH – MODAL KERJA', 'PIUTANG MUDHARIB JT PEMB MDH –', 82, '0', NULL, '1*6*2*1', 1, NULL, '1'), -(202, '201.50.00', 'DANA INVESTASI TERIKAT CHANELLING', 'SL', 188, '1', NULL, '2*1*2', -1, NULL, '1'), -(84, '140.10.99', 'PIUTANG MUDHARIB JT PEMB MDH – LAINNYA', 'PIUTANG MUDHARIB JT PEMB MDH –', 82, '0', NULL, '1*6*2*2', 1, NULL, '1'), -(85, '145.01.00', 'PEMBIAYAAN MUSYARAKAH', 'PEMBIAYAAN MUSYARAKAH', 68, '1', NULL, '1*7*1', 1, NULL, '1'), -(86, '145.10.00', 'PIUTANG MITRA JT PEMBIAYAAN MUSYARAKAH', 'PIUTANG MITRA JT PEMBIAYAAN MU', 68, '1', NULL, '1*7*2', 1, NULL, '1'), -(87, '145.01.01', 'PEMBIAYAAN MUSYARAKAH – MODAL KERJA', 'PEMBIAYAAN MUSYARAKAH – MODAL ', 85, '0', NULL, '1*7*1*1', 1, NULL, '1'), -(393, '570.50.05', 'PENDPTAN ADM ISTISHNA – PEMILIKAN KENDARAAN', 'SSL', 390, '0', NULL, '5*11*3*3', -1, NULL, '1'), -(88, '145.01.02', 'PEMBIAYAAN MUSYARAKAH – LAINNYA', 'PEMBIAYAAN MUSYARAKAH – LAINNY', 85, '0', NULL, '1*7*1*2', 1, NULL, '1'), -(89, '145.01.03', 'PIUTANG MITRA JT PEMB MSY – MODAL KERJA', 'PIUTANG MITRA JT PEMB MSY – MO', 85, '1', NULL, '1*7*1*3', 1, NULL, '1'), -(555, '790.00.00', 'BEBAN NON OPERASI LAINNYA', 'GL', 7, '1', NULL, '7*6', -1, NULL, '1'), -(401, '575.50.99', 'PENDAPATAN ADM MSY – LAINNYA', 'SSL', 399, '0', NULL, '5*12*2*2', -1, NULL, '1'), -(460, '701.05.04', 'UPAH PEGAWAI HARIAN (UPEH)', 'SSL', 456, '0', NULL, '7*1*2*4', -1, NULL, '1'), -(90, '145.10.01', 'PIUTANG MITRA JT PEMB MSY – MODAL KERJA', 'PIUTANG MITRA JT PEMB MSY – MO', 86, '0', NULL, '1*7*2*1', 1, NULL, '1'), -(402, '580.00.00', 'PENDAPATAN ADM - IJARAH', 'GL', 5, '1', NULL, '5*13', -1, 0, '1'), -(91, '145.10.99', 'PIUTANG MITRA JT PEMB MSY– LAINNYA', 'PIUTANG MITRA JT PEMB MSY– LAI', 86, '0', NULL, '1*7*2*2', 1, NULL, '1'), -(203, '201.01.11', 'SIMPANAN WADIAH HALIM', 'SSL', 201, '0', NULL, '2*1*1*1', -1, NULL, '1'), -(92, '150.01.00', 'AKTIVA IJARAH', 'AKTIVA IJARAH', 69, '1', NULL, '1*8*1', 1, NULL, '1'), -(403, '580.01.00', 'PENDAPATAN ADM IJARAH', 'SL', 402, '1', NULL, '5*13*1', -1, NULL, '1'), -(93, '150.01.01', 'AKTIVA IJARAH', 'AKTIVA IJARAH', 92, '0', NULL, '1*8*1*1', 1, NULL, '1'), -(94, '150.10.00', 'AKUMULASI PENYUSUTAN AKTIVA IJARAH (KR)', 'AKUMULASI PENYUSUTAN AKTIVA IJ', 69, '1', NULL, '1*8*2', 1, NULL, '1'), -(394, '570.50.99', 'PENDAPATAN ADM ISTISHNA – LAINNYA', 'SSL', 390, '0', NULL, '5*11*3*4', -1, NULL, '1'), -(95, '150.10.01', 'AKUMULASI PENYUSUTAN AKTIVA IJARAH (KR)', 'AKUMULASI PENYUSUTAN AKTIVA IJ', 94, '0', NULL, '1*8*2*1', 1, NULL, '1'), -(318, '520.01.00', 'PENDAPATAN BAGI HASIL MUSYARAKAH', 'SL', 317, '1', NULL, '5*5*1', -1, NULL, '1'), -(96, '150.30.00', 'AKTIVA IJARAH MUTHAIA BITTAMLIK', 'AKTIVA IJARAH MUTHAIA BITTAMLI', 69, '1', NULL, '1*8*3', 1, NULL, '1'), -(97, '150.40.00', 'AKUMULASI PENYUSUTAN IMB (KR)', 'AKUMULASI PENYUSUTAN IMB (KR)', 69, '1', NULL, '1*8*4', 1, NULL, '1'), -(461, '701.10.00', 'BEBAN LEMBUR PEGAWAI (BELEM)', 'SL', 452, '1', NULL, '7*1*3', -1, NULL, '1'), -(98, '150.60.00', 'SEWA DISEWAKAN KEMBALI', 'SEWA DISEWAKAN KEMBALI', 69, '1', NULL, '1*8*5', 1, NULL, '1'), -(99, '150.30.01', 'AKTIVA IJARAH MUTHAIA BITTAMLIK', 'AKTIVA IJARAH MUTHAIA BITTAMLI', 96, '0', NULL, '1*8*3*1', 1, NULL, '1'), -(100, '150.40.01', 'AKUMULASI PENYUSUTAN IMB (KR)', 'AKUMULASI PENYUSUTAN IMB (KR)', 97, '0', NULL, '1*8*4*1', 1, NULL, '1'), -(204, '201.50.01', 'DANA INVESTASI TERIKAT CHANELLING', 'SSL', 202, '0', NULL, '2*1*2*1', -1, NULL, '1'), -(101, '150.60.01', 'UANG MUKA SEWA AKT IJARAH', 'UANG MUKA SEWA AKT IJARAH', 98, '0', NULL, '1*8*5*1', 1, NULL, '1'), -(102, '150.60.02', 'AKUMULASI AMORTISASI UANG MUKA SEWA (KR)', 'AKUMULASI AMORTISASI UANG MUKA', 98, '0', NULL, '1*8*5*2', 1, NULL, '1'), -(103, '155.01.00', 'PITE MURABAHAH', 'PITE MURABAHAH', 70, '1', NULL, '1*9*1', 1, NULL, '1'), -(462, '701.10.01', 'BEBAN LEMBUR PEGAWAI', 'SSL', 461, '0', NULL, '7*1*3*1', -1, NULL, '1'), -(104, '155.50.00', 'PITE ISTISHNA', 'PITE ISTISHNA', 70, '1', NULL, '1*9*2', 1, NULL, '1'), -(206, '210.01.01', 'KIRIMAN UANG', 'SSL', 205, '0', NULL, '2*2*1*1', -1, NULL, '1'), -(562, '790.10.00', 'KERUGIAN PENGHAPUSAN AKTIVA TETAP', 'SL', 555, '1', NULL, '7*6*2', -1, NULL, '1'), -(207, '210.01.02', 'WESEL BAYAR', 'SSL', 205, '0', NULL, '2*2*1*2', -1, NULL, '1'), -(105, '155.01.02', 'PITE MURABAHAH – INVESTASI', 'PITE MURABAHAH – INVESTASI', 103, '0', NULL, '1*9*1*1', 1, NULL, '1'), -(208, '210.01.03', 'PENDAPATAN NON HALAL', 'SSL', 205, '0', NULL, '2*2*1*3', -1, NULL, '1'), -(395, '575.00.00', 'PENDAPATAN ADM – BAGI HASIL', 'GL', 5, '1', NULL, '5*12', -1, 0, '1'), -(106, '155.01.04', 'PITE MURABAHAH – PEMILIKAN RUMAH', 'PITE MURABAHAH – PEMILIKAN RUM', 103, '0', NULL, '1*9*1*2', 1, NULL, '1'), -(107, '155.01.05', 'PITE MURABAHAH – PEMILIKAN KENDARAAN', 'PITE MURABAHAH – PEMILIKAN KEN', 103, '0', NULL, '1*9*1*3', 1, NULL, '1'), -(108, '155.01.99', 'PITE MURABAHAH – LAINNYA', 'PITE MURABAHAH – LAINNYA', 103, '0', NULL, '1*9*1*4', 1, NULL, '1'), -(556, '790.05.00', 'KERUGIAN PENJUALAN AKTIVA TETAP', 'SL', 555, '1', NULL, '7*6*1', -1, NULL, '1'), -(109, '155.50.02', 'PITE ISTISHNA – INVESTASI', 'PITE ISTISHNA – INVESTASI', 104, '0', NULL, '1*9*2*1', 1, NULL, '1'), -(110, '155.50.04', 'PITE ISTISHNA– PEMILIKAN RUMAH', 'PITE ISTISHNA– PEMILIKAN RUMAH', 104, '0', NULL, '1*9*2*2', 1, NULL, '1'), -(111, '155.50.05', 'PITE ISTISHNA – PEMILIKAN KENDARAAN', 'PITE ISTISHNA – PEMILIKAN KEND', 104, '0', NULL, '1*9*2*3', 1, NULL, '1'), -(327, '525.02.02', 'BEBAN PEMELIHARAAN AKTIVA IJARAH (DR)', 'SSL', 325, '0', NULL, '5*6*2*2', -1, NULL, '1'), -(112, '155.50.99', 'PITE ISTISHNA – LAINNYA', 'PITE ISTISHNA – LAINNYA', 104, '0', NULL, '1*9*2*4', 1, NULL, '1'), -(557, '790.05.01', 'KERUGIAN PENJUALAN TANAH & BANGUNAN', 'SSL', 556, '0', NULL, '7*6*1*1', -1, NULL, '1'), -(328, '525.02.03', 'BEBAN PENGEMBALIAN KELEBIHAN PENERIMAAN SEWA', 'SSL', 325, '0', NULL, '5*6*2*3', -1, NULL, '1'), -(113, '160.01.00', 'PINJAMAN QARDH', 'PINJAMAN QARDH', 71, '1', NULL, '1*10*1', 1, NULL, '1'), -(114, '160.01.01', 'PINJAMAN QARDH – MODAL KERJA', 'PINJAMAN QARDH – MODAL KERJA', 113, '0', NULL, '1*10*1*1', 1, NULL, '1'), -(463, '701.10.02', 'UANG MAKAN MINUM PEGAWAI', 'SSL', 461, '0', NULL, '7*1*3*2', -1, NULL, '1'), -(115, '160.01.03', 'PINJAMAN QARDH – KONSUMSI', 'PINJAMAN QARDH – KONSUMSI', 113, '0', NULL, '1*10*1*2', 1, NULL, '1'), -(563, '790.10.01', 'KERUGIAN KARENA KEHILANGAN AKTIVA TETAP', 'SSL', 562, '0', NULL, '7*6*2*1', -1, NULL, '1'), -(469, '701.90.02', 'BANTUAN KESEJAHTERAAN', 'SSL', 467, '0', NULL, '7*1*5*2', -1, NULL, '1'), -(329, '525.02.04', 'KERUGIAN PENJUALAN AKTIVA IJARAH', 'SSL', 325, '0', NULL, '5*6*2*4', -1, NULL, '1'), -(396, '575.01.00', 'PENDAPATAN ADM MUDHARABAH(MDH)', 'SL', 395, '1', NULL, '5*12*1', -1, NULL, '1'), -(116, '160.01.99', 'PINJAMAN QARDH – LAINNYA', 'PINJAMAN QARDH – LAINNYA', 113, '0', NULL, '1*10*1*3', 1, NULL, '1'), -(404, '580.01.01', 'PENDAPATAN ADM IJARAH', 'SSL', 403, '0', NULL, '5*13*1*1', -1, NULL, '1'), -(405, '580.30.00', 'PENDAPATAN ADM IJARAH MUTHAIA BITTAMLIK (IMB)', 'SL', 402, '1', NULL, '5*13*2', -1, NULL, '1'), -(117, '165.01.00', 'PERSEDIAAN', 'PERSEDIAAN', 72, '1', NULL, '1*11*1', 1, NULL, '1'), -(406, '580.30.01', 'PENDAPATAN ADM IJARAH MUTHAIA BITTAMLIK', 'SSL', 405, '0', NULL, '5*13*2*1', -1, NULL, '1'), -(118, '165.01.01', 'PERSEDIAAN MURABAHAH', 'PERSEDIAAN MURABAHAH', 117, '0', NULL, '1*11*1*1', 1, NULL, '1'), -(470, '701.90.04', 'UANG PESANGON', 'SSL', 467, '0', NULL, '7*1*5*3', -1, NULL, '1'), -(119, '165.01.02', 'PERSEDIAAN SALAM', 'PERSEDIAAN SALAM', 117, '0', NULL, '1*11*1*2', 1, NULL, '1'), -(407, '580.60.00', 'PENDAPATAN ADM SEWA DISEWAKAN KEMBALI', 'SL', 402, '1', NULL, '5*13*3', -1, NULL, '1'), -(120, '165.01.03', 'PERSEDIAAN ISTISHNA', 'PERSEDIAAN ISTISHNA', 117, '0', NULL, '1*11*1*3', 1, NULL, '1'), -(471, '720.00.00', 'BEBAN UMUM DAN ADMISTRASI', 'GL', 7, '1', NULL, '7*2', -1, NULL, '1'), -(121, '165.01.04', 'PERSEDIAAN MUDHARABAH', 'PERSEDIAAN MUDHARABAH', 117, '0', NULL, '1*11*1*4', 1, NULL, '1'), -(408, '580.60.01', 'PENDAPATAN ADM SEWA DISEWAKAN KEMBALI', 'SSL', 407, '0', NULL, '5*13*3*1', -1, NULL, '1'), -(122, '165.01.05', 'PERSEDIAAN MUSYARAKAH', 'PERSEDIAAN MUSYARAKAH', 117, '0', NULL, '1*11*1*5', 1, NULL, '1'), -(123, '170.01.00', 'AKTIVA ISTISHNA DALAM PENYELESAIAN', 'AKTIVA ISTISHNA DALAM PENYELES', 73, '1', NULL, '1*12*1', 1, NULL, '1'), -(472, '720.10.00', 'BEBAN AIR, LISTRIK, TELEPON (BEALISTEL)', 'SL', 471, '1', NULL, '7*2*1', -1, NULL, '1'), -(409, '585.00.00', 'PENDAPATAN ADM - QARDH', 'GL', 5, '1', NULL, '5*14', -1, 0, '1'), -(124, '170.05.00', 'TERMIN ISTISHNA (KR)', 'TERMIN ISTISHNA (KR)', 73, '1', NULL, '1*12*2', 1, NULL, '1'), -(565, '790.25.00', 'SUMBANGAN –SUMBANGAN', 'SL', 555, '1', NULL, '7*6*3', -1, NULL, '1'), -(410, '585.01.00', 'PENDAPATAN ADM QARDH', 'SL', 409, '1', NULL, '5*14*1', -1, NULL, '1'), -(473, '720.10.01', 'BEALISTEL – INTERNET', 'SSL', 472, '0', NULL, '7*2*1*1', -1, NULL, '1'), -(564, '790.10.05', 'KERUGIAN KARENA PENGHAPUSAN AKTIVA TETAP', 'SSL', 562, '0', NULL, '7*6*2*2', -1, NULL, '1'), -(125, '170.01.01', 'AKTIVA ISTISHNA DALAM PENYELESAIAN', 'AKTIVA ISTISHNA DALAM PENYELES', 123, '0', NULL, '1*12*1*1', 1, NULL, '1'), -(474, '720.10.02', 'BEALISTEL – LISTRIK', 'SSL', 472, '0', NULL, '7*2*1*2', -1, NULL, '1'), -(126, '170.05.01', 'TERMIN ISTISHNA (KR)', 'TERMIN ISTISHNA (KR)', 124, '0', NULL, '1*12*2*1', 1, NULL, '1'), -(127, '173.10.00', 'PENYERTAAN LAINNYA', 'PENYERTAAN LAINNYA', 74, '1', NULL, '1*13*1', 1, NULL, '1'), -(475, '720 10 03', 'BEALISTEL – TELEPON', 'SSL', 472, '0', NULL, '7*2*1*3', -1, NULL, '1'), -(566, '790.25.01', 'SUMBANGAN –SUMBANGAN', 'SSL', 565, '0', NULL, '7*6*3*1', -1, NULL, '1'), -(128, '173.10.01', 'PENYERTAAN LAINNYA', 'PENYERTAAN LAINNYA', 127, '0', NULL, '1*13*1*1', 1, NULL, '1'), -(129, '175.05.00', 'PIUTANG PENDAPATAN BAGI HASIL', 'PIUTANG PENDAPATAN BAGI HASIL', 75, '1', NULL, '1*14*1', 1, NULL, '1'), -(130, '175.10.00', 'PIUTANG PENDAPATAN IJARAH', 'PIUTANG PENDAPATAN IJARAH', 75, '1', NULL, '1*14*2', 1, NULL, '1'), -(131, '175.15.00', 'PIUTANG KEPADA PEMBELI', 'PIUTANG KEPADA PEMBELI', 75, '1', NULL, '1*14*3', 1, NULL, '1'), -(132, '175.20.00', 'PIUTANG KEPADA PENJUAL', 'PIUTANG KEPADA PENJUAL', 75, '1', NULL, '1*14*4', 1, NULL, '1'), -(133, '175.90.00', 'PIUTANG LAINNYA', 'PIUTANG LAINNYA', 75, '1', NULL, '1*14*5', 1, NULL, '1'), -(134, '175.05.01', 'PIUTANG PENDAPATAN BAGI HASIL – MUDHARABAH', 'PIUTANG PENDAPATAN BAGI HASIL ', 129, '0', NULL, '1*14*1*1', 1, NULL, '1'), -(135, '175.05.02', 'PIUTANG PENDAPATAN BAGI HASIL - MUSYARAKAH', 'PIUTANG PENDAPATAN BAGI HASIL ', 129, '0', NULL, '1*14*1*2', 1, NULL, '1'), -(136, '175.05.03', 'PIUTANG PENDAPATAN BAGI HASIL SURAT BERHARGA', 'PIUTANG PENDAPATAN BAGI HASIL ', 129, '0', NULL, '1*14*1*3', 1, NULL, '1'), -(330, '525.02.09', 'BEBAN IJARAH LAINNYA', 'SSL', 325, '0', NULL, '5*6*2*5', -1, NULL, '1'), -(137, '175.10.02', 'PIUTANG PENDAPATAN IMB', 'PIUTANG PENDAPATAN IMB', 130, '0', NULL, '1*14*2*1', 1, NULL, '1'), -(331, '525.31.00', 'PENDAPATAN SEWA IJARAH MUTHAIA BITTAMLIK', 'SL', 321, '1', NULL, '5*6*3', -1, NULL, '1'), -(138, '175.10.01', 'PIUTANG PENDAPATAN IJARAH', 'PIUTANG PENDAPATAN IJARAH', 130, '0', NULL, '1*14*2*2', 1, NULL, '1'), -(332, '525.31.01', 'PENDAPATAN SEWA IJARAH MUTHAIA BITTAMLIK', 'SSL', 331, '0', NULL, '5*6*3*1', -1, NULL, '1'), -(139, '175.15.01', 'PIUTANG KEPADA PEMBELI MURABAHAH', 'PIUTANG KEPADA PEMBELI MURABAH', 131, '0', NULL, '1*14*3*1', 1, NULL, '1'), -(333, '525.31.02', 'KEUNTUNGAN PENJUALAN AKTIVA IMB', 'SSL', 331, '0', NULL, '5*6*3*2', -1, NULL, '1'), -(140, '175.20.01', 'PIUTANG KEPADA PENJUAL - MURABAHAH', 'PIUTANG KEPADA PENJUAL - MURAB', 132, '0', NULL, '1*14*4*1', 1, NULL, '1'), -(334, '525.32.00', 'BEBAN IMB (DR)', 'SL', 321, '1', NULL, '5*6*4', -1, NULL, '1'), -(141, '175.20.02', 'PIUTANG KEPADA PENJUAL – SALAM', 'PIUTANG KEPADA PENJUAL – SALAM', 132, '0', NULL, '1*14*4*2', 1, NULL, '1'), -(142, '175.90.01', 'DANA TALANGAN TRANSAKSI PERDAGANGAN', 'DANA TALANGAN TRANSAKSI PERDAG', 133, '0', NULL, '1*14*5*1', 1, NULL, '1'), -(335, '525.32.01', 'BEBAN PENYUSUTAN IMB (DR)', 'SSL', 334, '0', NULL, '5*6*4*1', -1, NULL, '1'), -(143, '175.90.02', 'DANA TALANGAN LAINNYA', 'DANA TALANGAN LAINNYA', 133, '0', NULL, '1*14*5*2', 1, NULL, '1'), -(476, '720 10 04', 'BEALISTEL – TELEX', 'SSL', 472, '0', NULL, '7*2*1*4', -1, NULL, '1'), -(144, '180.01.00', 'TANAH', 'TANAH', 76, '1', NULL, '1*15*1', 1, NULL, '1'), -(209, '230.0.00', 'BEBAN PERSONALIA', 'SL', 190, '1', NULL, '2*3*1', -1, NULL, '1'), -(145, '180.10.00', 'GEDUNG KANTOR & RUMAH', 'GEDUNG KANTOR & RUMAH', 76, '0', NULL, '1*15*2', 1, NULL, '1'), -(477, '720 10 05', 'BEALISTEL – GAS', 'SSL', 472, '0', NULL, '7*2*1*5', -1, NULL, '1'), -(146, '180.11.00', 'AKUMULASI PENYUSUTAN GEDUNG & RUMAH', 'AKUMULASI PENYUSUTAN GEDUNG & ', 76, '1', NULL, '1*15*3', 1, NULL, '1'), -(210, '230.02.00', 'BEBAN OPERASI', 'SL', 190, '1', NULL, '2*3*2', -1, NULL, '1'), -(147, '180.20.00', 'KENDARAAN KANTOR', 'KENDARAAN KANTOR', 76, '1', NULL, '1*15*4', 1, NULL, '1'), -(478, '720 10 06', 'BEALISTEL – TROMOLPOS', 'SSL', 472, '0', NULL, '7*2*1*6', -1, NULL, '1'), -(148, '180.21.00', 'AKUMULASI PENYUSUTAN KENDARAAN KANTOR', 'AKUMULASI PENYUSUTAN KENDARAAN', 76, '1', NULL, '1*15*5', 1, NULL, '1'), -(479, '720.20.00', 'BEBAN PEMELIHARAAN & PERBAIKAN (BEMEL)', 'SL', 471, '1', NULL, '7*2*2', -1, NULL, '1'), -(149, '180.30.00', 'INVENTARIS KANTOR', 'INVENTARIS KANTOR', 76, '1', NULL, '1*15*6', 1, NULL, '1'), -(480, '720.20.01', 'BEMEL – GEDUNG & RUMAH', 'SSL', 479, '0', NULL, '7*2*2*1', -1, NULL, '1'), -(150, '180.31.00', 'AKUMULASI PENYUSUTAN INVESTARIS KANTOR', 'AKUMULASI PENYUSUTAN INVESTARI', 76, '1', NULL, '1*15*7', 1, NULL, '1'), -(151, '180.40.00', 'KOMPUTER', 'KOMPUTER', 76, '1', NULL, '1*15*8', 1, NULL, '1'), -(211, '230.01.01', 'BEBAN YADIB PERSONALIA - BEBAN DIBAYAR THT', 'SSL', 209, '0', NULL, '2*3*1*1', -1, NULL, '1'), -(152, '180.41.00', 'AKUMULASI PENYUSUTAN KOMPUTER', 'AKUMULASI PENYUSUTAN KOMPUTER', 76, '1', NULL, '1*15*9', 1, NULL, '1'), -(212, '230.01.02', 'BEBAN YADIB PERSONALIA - DANA CADANGAN THR', 'SSL', 209, '0', NULL, '2*3*1*2', -1, NULL, '1'), -(213, '230.01.03', 'BEBAN YADIB PERSONALIA - GAJI AKAN DIBAYAR', 'SSL', 209, '0', NULL, '2*3*1*3', -1, NULL, '1'), -(153, '180.01.01', 'TANAH', 'TANAH', 144, '0', NULL, '1*15*1*1', 1, NULL, '1'), -(154, '180.10.01', 'GEDUNG KANTOR', 'GEDUNG KANTOR', 145, '0', NULL, '1*15*2*1', 1, NULL, '1'), -(411, '585.01.01', 'PENDAPATAN ADM QARDH – MODAL KERJA', 'SSL', 410, '0', NULL, '5*14*1*1', -1, NULL, '1'), -(155, '180.11.01', 'AKUMULASI PENYUSUTAN GEDUNG KANTOR', 'AKUMULASI PENYUSUTAN GEDUNG KA', 146, '0', NULL, '1*15*3*1', 1, NULL, '1'), -(412, '585.01.03', 'PENDAPATAN ADM QARDH – KONSUMSI', 'SSL', 410, '0', NULL, '5*14*1*2', -1, NULL, '1'), -(156, '180.20.01', 'KENDARAAN KANTOR MOBIL', 'KENDARAAN KANTOR MOBIL', 147, '0', NULL, '1*15*4*1', 1, NULL, '1'), -(481, '720.20.02', 'BEMEL – KENDARAAN', 'SSL', 479, '0', NULL, '7*2*2*2', -1, NULL, '1'), -(157, '180.20.02', 'KENDARAAN KANTOR SEPEDA MOTOR', 'KENDARAAN KANTOR SEPEDA MOTOR', 147, '0', NULL, '1*15*4*2', 1, NULL, '1'), -(413, '585.01.99', 'PENDAPATAN ADM QARDH – LAINNYA', 'SSL', 410, '0', NULL, '5*14*1*3', -1, NULL, '1'), -(158, '180.21.02', 'KENDARAAN KANTOR SEPEDA MOTOR', 'KENDARAAN KANTOR SEPEDA MOTOR', 148, '0', NULL, '1*15*5*1', 1, NULL, '1'), -(414, '590.00.00', 'PENDAPATAN ADM PRODUK', 'GL', 5, '1', NULL, '5*15', -1, NULL, '1'), -(159, '180.21.01', 'KENDARAAN KANTOR MOBIL', 'KENDARAAN KANTOR MOBIL', 148, '0', NULL, '1*15*5*2', 1, NULL, '1'), -(415, '590.05.00', 'PENDAPATAN ADM TABUNGAN WADIAH', 'SL', 414, '1', NULL, '5*15*1', -1, NULL, '1'), -(160, '180.30.01', 'INVENTARIS KANTOR', 'INVENTARIS KANTOR', 149, '0', NULL, '1*15*6*1', 1, NULL, '1'), -(161, '180.31.01', 'AKUMULASI PENYUSUTAN INVENTARIS KANTOR', 'AKUMULASI PENYUSUTAN INVENTARI', 150, '0', NULL, '1*15*7*1', 1, NULL, '1'), -(205, '210.01.00', 'KU/WESEL/INKASO', 'SL', 189, '1', NULL, '2*2*1', -1, NULL, '1'), -(162, '180.40.01', 'KOMPUTER', 'KOMPUTER', 151, '0', NULL, '1*15*8*1', 1, NULL, '1'), -(319, '520.01.01', 'PENDAPATAN BAGI HASIL MSY – MODAL KERJA', 'SSL', 318, '0', NULL, '5*5*1*1', -1, NULL, '1'), -(416, '590.05.01', 'PENDAPATAN ADM TABUNGAN WADIAH', 'SSL', 415, '0', NULL, '5*15*1*1', -1, NULL, '1'), -(163, '180.41.01', 'AKUMULASI PENYUSUTAN KOMPUTER', 'AKUMULASI PENYUSUTAN KOMPUTER', 152, '0', NULL, '1*15*9*1', 1, NULL, '1'), -(164, '185.01 01', 'BEBAN DIBAYAR DIMUKA (BDD)', 'BEBAN DIBAYAR DIMUKA (BDD)', 77, '1', NULL, '1*16*1', 1, NULL, '1'), -(165, '185.10.00', 'UANG MUKA AKAD (UMA)', 'UANG MUKA AKAD (UMA)', 77, '1', NULL, '1*16*2', 1, NULL, '1'), -(166, '185.50.00', 'UANG MUKA PANJAR (UMP)', 'UANG MUKA PANJAR (UMP)', 77, '1', NULL, '1*16*3', 1, NULL, '1'), -(214, '230.01.04', 'BEBAN YADIB PERSONALIA - BONUS', 'SSL', 209, '0', NULL, '2*3*1*4', -1, NULL, '1'), -(167, '185.51.00', 'UANG MUKA BENDA POS (UMBP)', 'UANG MUKA BENDA POS (UMBP)', 77, '1', NULL, '1*16*4', 1, NULL, '1'), -(336, '525.32.02', 'BEBAN PEMELIHARAAN IMB (DR)', 'SSL', 334, '0', NULL, '5*6*4*2', -1, NULL, '1'), -(168, '185.90.00', 'UANG MUKA LAINNYA (UML)', 'UANG MUKA LAINNYA (UML)', 77, '1', NULL, '1*16*5', 1, NULL, '1'), -(337, '525.32.03', 'BEBAN PENGEMBALIAN KELEBIHAN PENERIMAAN SEWA', 'SSL', 334, '0', NULL, '5*6*4*3', -1, NULL, '1'), -(338, '525.32.04', 'KERUGIAN PENJUALAN AKTIVA IMB', 'SSL', 334, '0', NULL, '5*6*4*4', -1, NULL, '1'), -(169, '185.01 02', 'BDD – PREMI ASURANSI', 'BDD – PREMI ASURANSI', 164, '0', NULL, '1*16*1*1', 1, NULL, '1'), -(170, '185.01 03', 'BDD – PROMOSI', 'BDD – PROMOSI', 164, '0', NULL, '1*16*1*2', 1, NULL, '1'), -(171, '185.01 90', 'BDD – LAINNYA', 'BDD – LAINNYA', 164, '0', NULL, '1*16*1*3', 1, NULL, '1'), -(172, '185.10.01', 'UMA – AKAD DITANGGUHKAN - ISTISHNA', 'UMA – AKAD DITANGGUHKAN - ISTI', 165, '0', NULL, '1*16*2*1', 1, NULL, '1'), -(173, '185.10.02', 'UMA – AKAD DITANGGUHKAN – MUDHARABAH', 'UMA – AKAD DITANGGUHKAN – MUDH', 165, '0', NULL, '1*16*2*2', 1, NULL, '1'), -(174, '185.10.03', 'UMA – AKAD DITANGGUHKAN - MUSYARAKAH', 'UMA – AKAD DITANGGUHKAN - MUSY', 165, '0', NULL, '1*16*2*3', 1, NULL, '1'), -(320, '520.01.99', 'PENDAPATAN BAGI HASIL MSY – LAINNYA', 'SSL', 318, '0', NULL, '5*5*1*2', -1, NULL, '1'), -(215, '230 01 90', 'BEBAN YADIB PERSONALIA - LAINNYA', 'SSL', 209, '0', NULL, '2*3*1*5', -1, NULL, '1'), -(175, '185.50.01', 'UMP – PANJAR PEMBUKAN KANTOR', 'UMP – PANJAR PEMBUKAN KANTOR', 166, '0', NULL, '1*16*3*1', 1, NULL, '1'), -(216, '230.02.90', 'BEBAN YADIB OPERASI - LAINNYA', 'SSL', 210, '0', NULL, '2*3*2*1', -1, NULL, '1'), -(176, '185.50.02', 'UMP – PANJAR LAINNYA', 'UMP – PANJAR LAINNYA', 166, '0', NULL, '1*16*3*2', 1, NULL, '1'), -(177, '185.51.01', 'UMBP – METERAI', 'UMBP – METERAI', 167, '0', NULL, '1*16*4*1', 1, NULL, '1'), -(178, '185.51.02', 'UMBP – PERANGKO', 'UMBP – PERANGKO', 167, '0', NULL, '1*16*4*2', 1, NULL, '1'), -(217, '240.01.00', 'PEMBIAYAAN MUDHARABAH', 'SL', 191, '1', NULL, '2*4*1', -1, NULL, '1'), -(179, '185.51.03', 'UMBP – LAINYA', 'UMBP – LAINYA', 167, '0', NULL, '1*16*4*3', 1, NULL, '1'), -(218, '240.05.00', 'PEMBIAYAAN MUSYARAKAH', 'SL', 191, '1', NULL, '2*4*2', -1, NULL, '1'), -(180, '185.90.01', 'UML – LAINNYA', 'UML – LAINNYA', 168, '0', NULL, '1*16*5*1', 1, NULL, '1'), -(219, '240.10.00', 'PINJAMAN QARDH', 'SL', 191, '1', NULL, '2*4*3', -1, NULL, '1'), -(181, '195.01.00', 'PERSEDIAAN METERAI & PRANGKO', 'PERSEDIAAN METERAI & PRANGKO', 78, '1', NULL, '1*17*1', 1, NULL, '1'), -(182, '195.10.00', 'PERSEDIAAN ALAT KANTOR', 'PERSEDIAAN ALAT KANTOR', 78, '1', NULL, '1*17*2', 1, NULL, '1'), -(183, '195.20.00', 'SELISIH KAS DALAM PENYELESAIAN', 'SELISIH KAS DALAM PENYELESAIAN', 78, '1', NULL, '1*17*3', 1, NULL, '1'), -(220, '240.40.00', 'PINJAMAN LAINNYA', 'SL', 191, '1', NULL, '2*4*4', -1, NULL, '1'), -(321, '525.00.00', 'PENDAPATAN SEWA IJARAH', 'GL', 5, '1', NULL, '5*6', -1, NULL, '1'), -(184, '195.01.01', 'PERSEDIAAN METERAI', 'PERSEDIAAN METERAI', 181, '0', NULL, '1*17*1*1', 1, NULL, '1'), -(185, '195.01.02', 'PERSEDIAAN PERANGKO', 'PERSEDIAAN PERANGKO', 181, '0', NULL, '1*17*1*2', 1, NULL, '1'), -(186, '195.10.01', 'PERSEDIAAN ALAT KANTOR', 'PERSEDIAAN ALAT KANTOR', 182, '0', NULL, '1*17*2*1', 1, NULL, '1'), -(187, '195.20.01', 'SELISIH KAS DALAM PENYELESAIAN', 'SELISIH KAS DALAM PENYELESAIAN', 183, '0', NULL, '1*17*3*1', 1, NULL, '1'), -(339, '525.32.09', 'BEBAN IMB LAINNYA', 'SSL', 334, '0', NULL, '5*6*4*5', -1, NULL, '1'), -(340, '525.51.00', 'PENDAPATAN SEWA DISEWAKAN KEMBALI', 'SL', 321, '1', NULL, '5*6*5', -1, NULL, '1'), -(221, '240.01.01', 'PEMBIAYAAN MUDHARABAH', 'SSL', 217, '0', NULL, '2*4*1*1', -1, NULL, '1'), -(397, '575.01.01', 'PENDAPATAN ADM MDH – MODAL KERJA', 'SSL', 396, '0', NULL, '5*12*1*1', -1, NULL, '1'), -(341, '525.51.01', 'PENDAPATAN SEWA (DISEWAKAN KEMBALI)', 'SSL', 340, '0', NULL, '5*6*5*1', -1, NULL, '1'), -(222, '240.05.01', 'PEMBIAYAAN MUSYARAKAH', 'SSL', 218, '0', NULL, '2*4*2*1', -1, NULL, '1'), -(223, '240.10.01', 'PINJAMAN QARDH', 'SSL', 219, '0', NULL, '2*4*3*1', -1, NULL, '1'), -(342, '525.52.00', 'BEBAN AMORTISASI SEWA DISEWAKAN KEMBALI (DR)', 'SL', 321, '1', NULL, '5*6*6', -1, NULL, '1'), -(224, '240.40.90', 'PINJAMAN LAINNYA', 'SSL', 220, '0', NULL, '2*4*4*1', -1, NULL, '1'), -(343, '525.52.02', 'BEBAN AMORTISASI UANG MUKA SEWA (DR)', 'SSL', 342, '0', NULL, '5*6*6*1', -1, NULL, '1'), -(344, '525.90.00', 'PENDAPATAN IJARAH LAINNYA', 'SL', 321, '1', NULL, '5*6*7', -1, NULL, '1'), -(225, '250.01.00', 'KITE MURABAHAH', 'SL', 192, '1', NULL, '2*5*1', -1, NULL, '1'), -(482, '720.20.03', 'BEMEL – KOMPUTER', 'SSL', 479, '0', NULL, '7*2*2*3', -1, NULL, '1'), -(417, '590.15.00', 'PENDAPATAN WAKALAH', 'SL', 414, '1', NULL, '5*15*2', -1, NULL, '1'), -(345, '525.90.01', 'PENDAPATAN IJARAH LAINNYA', 'SSL', 344, '0', NULL, '5*6*7*1', -1, NULL, '1'), -(226, '250.10.00', 'KITE ISTISHNA', 'SL', 192, '1', NULL, '2*5*2', -1, NULL, '1'), -(483, '720.20.04', 'BEMEL – PERALATAN KOMUNIKASI', 'SSL', 479, '0', NULL, '7*2*2*4', -1, NULL, '1'), -(418, '590.15.01', 'PENDAPATAN FEE TRANSFER', 'SSL', 417, '0', NULL, '5*15*2*1', -1, NULL, '1'), -(346, '540.00.00', 'PENDAPATAN PENEMPATAN PD BANK LAIN', 'GL', 5, '1', NULL, '5*7', -1, 0, '1'), -(484, '720.30.00', 'Beban Umum & Rumah Tangga', 'SSL', 479, '0', NULL, '7*2*2*5', -1, NULL, '1'), -(227, '250.01.02', 'KITE MURABAHAH – INVESTASI', 'SSL', 225, '0', NULL, '2*5*1*1', -1, NULL, '1'), -(419, '590.15.02', 'PENDAPATAN FEE INKASO', 'SSL', 417, '0', NULL, '5*15*2*2', -1, NULL, '1'), -(347, '540.01.00', 'BONUS SIMPANAN WADIAH', 'SL', 346, '1', NULL, '5*7*1', -1, NULL, '1'), -(228, '250.01.04', 'KITE MURABAHAH – PEMILIKAN RUMAH', 'SSL', 225, '0', NULL, '2*5*1*2', -1, NULL, '1'), -(229, '250.01.05', 'KITE MURABAHAH – PEMILIKAN KENDARAAN', 'SSL', 225, '0', NULL, '2*5*1*3', -1, NULL, '1'), -(398, '575.01.99', 'PENDAPATAN ADM MDH – LAINNYA', 'SSL', 396, '0', NULL, '5*12*1*2', -1, NULL, '1'), -(420, '590.90.00', 'PENDAPATAN PENGGANTIAN LAINNYA', 'SL', 414, '0', NULL, '5*15*3', -1, NULL, '1'), -(485, '720.30.01', 'Biaya Rumah Tangga', 'SSL', 479, '0', NULL, '7*2*2*6', -1, NULL, '1'), -(230, '250.01.99', 'KITE MURABAHAH – LAINNYA', 'SSL', 225, '0', NULL, '2*5*1*4', -1, NULL, '1'), -(348, '540.01.01', 'BONUS GIRO WADIAH', 'SSL', 347, '0', NULL, '5*7*1*1', -1, NULL, '1'), -(231, '250.10.02', 'KITE ISTISHNA – INVESTASI', 'SSL', 226, '0', NULL, '2*5*2*1', -1, NULL, '1'), -(232, '250.10.04', 'KITE ISTISHNA– PEMILIKAN RUMAH', 'SSL', 226, '0', NULL, '2*5*2*2', -1, NULL, '1'), -(349, '540.01.02', 'BONUS TABUNGAN WADIAH', 'SSL', 347, '0', NULL, '5*7*1*2', -1, NULL, '1'), -(233, '250.10.05', 'KITE ISTISHNA – PEMILIKAN KENDARAAN', 'SSL', 226, '0', NULL, '2*5*2*3', -1, NULL, '1'), -(234, '250.10.99', 'KITE ISTISHNA – LAINNYA', 'SSL', 226, '0', NULL, '2*5*2*4', -1, NULL, '1'), -(322, '525.01.00', 'PENDAPATAN SEWA IJARAH', 'SL', 321, '1', NULL, '5*6*1', -1, NULL, '1'), -(235, '280.01.00', 'HUTANG SALAM', 'SL', 199, '1', NULL, '2*6*1', -1, NULL, '1'), -(421, '590.90.01', 'PENDAPATAN NON HALAL', 'SSL', 420, '0', NULL, '5*15*3*1', -1, NULL, '1'), -(236, '280.10.00', 'HUTANG ISTISHNA', 'SL', 199, '1', NULL, '2*6*2', -1, NULL, '1'), -(422, '590.90.02', 'PENDAPATAN LAINNYA IJARAH', 'SSL', 420, '0', NULL, '5*15*3*2', -1, NULL, '1'), -(188, '201.00.00', 'WADIAH (TITIPAN)', 'GL', 2, '1', NULL, '2*1', -1, NULL, '1'), -(423, '590.90.90', 'PENDAPATAN LAINNYA ( METERAI )', 'SSL', 420, '0', NULL, '5*15*3*3', -1, NULL, '1'), -(237, '280.30.00', 'HUTANG PAJAK', 'SL', 199, '1', NULL, '2*6*3', -1, NULL, '1'), -(350, '540.01.99', 'BONUS LAINNYA', 'SSL', 347, '0', NULL, '5*7*1*3', -1, NULL, '1'), -(189, '210.00.00', 'KEWAJIBAN SEGERA LAINNYA', 'GL', 2, '1', NULL, '2*2', -1, NULL, '1'), -(424, '595.00.00', 'PENDAPATAN OPERASI LAINNYA', 'GL', 5, '1', NULL, '5*16', -1, NULL, '1'), -(238, '280.40.00', 'BAGI HASIL YANG SDH JATUH TEMPO', 'SL', 199, '1', NULL, '2*6*4', -1, NULL, '1'), -(190, '230.00.00', 'BEBAN YANG AKAN DIBAYAR', 'GL', 2, '1', NULL, '2*3', -1, NULL, '1'), -(351, '540.05.00', 'BAGI HASIL DANA INVESTASI TDK TERIKAT', 'SL', 346, '1', NULL, '5*7*2', -1, NULL, '1'), -(239, '280.50.00', 'UANG MUKA MURABAHAH DARI PEMBELI', 'SL', 199, '1', NULL, '2*6*5', -1, NULL, '1'), -(191, '240.00.00', 'PINJAMAN DITERIMA', 'GL', 2, '1', NULL, '2*4', -1, NULL, '1'), -(352, '540.05.01', 'BAGI HASIL TABUNGAN MUDHARABAH', 'SSL', 351, '0', NULL, '5*7*2*1', -1, NULL, '1'), -(240, '280.60.00', 'UANG MUKA ISTISHNA DARI PEMBELI', 'SL', 199, '1', NULL, '2*6*6', -1, NULL, '1'), -(241, '280.90.00', 'KEWAJIBAN LAINNYA', 'SL', 199, '1', NULL, '2*6*7', -1, NULL, '1'), -(353, '540.05.02', 'BAGI HASIL DEPOSITO MUDHARABAH', 'SSL', 351, '0', NULL, '5*7*2*2', -1, NULL, '1'), -(242, '280.01.01', 'HUTANG SALAM', 'SSL', 235, '0', NULL, '2*6*1*1', -1, NULL, '1'), -(243, '280.10.01', 'HUTANG ISTISHNA KEPADA PRODUSEN', 'SSL', 236, '0', NULL, '2*6*2*1', -1, NULL, '1'), -(244, '280.30.01', 'HUTANG PAJAK', 'SSL', 237, '0', NULL, '2*6*3*1', -1, NULL, '1'), -(245, '295.01.00', 'PINJAMAN SUBORDINASI', 'SL', 200, '1', NULL, '2*7*1', -1, NULL, '1'), -(359, '550.00.00', 'PENDAPATAN PENYALURAN INVST TERIKAT EXECUTING', 'GL', 5, '1', NULL, '5*8', -1, NULL, '1'), -(486, '720.40.00', 'BEBAN PENYUSUTAN (BENYUT)', 'SL', 471, '1', NULL, '7*2*3', -1, NULL, '1'), -(246, '280.40.01', 'BAGI HASIL YANG SDH JATUH TEMPO', 'SSL', 238, '0', NULL, '2*6*4*1', -1, 0, '1'), -(360, '550.01.00', 'PENDAPATAN PITE MURABAHAH', 'SL', 359, '1', NULL, '5*8*1', -1, NULL, '1'), -(487, '720.40.01', 'BEBAN PENYUSUTAN GEDUNG & RUMAH', 'SSL', 486, '0', NULL, '7*2*3*1', -1, NULL, '1'), -(247, '280.60.01', 'UANG MUKA ISTISHNA DARI PEMBELI', 'SSL', 240, '0', NULL, '2*6*6*1', -1, NULL, '1'), -(361, '550.01.02', 'PENDAPATAN PITE MURABAHAH – INVESTASI', 'SSL', 360, '0', NULL, '5*8*1*1', -1, NULL, '1'), -(248, '280.90.01', 'KEWAJIBAN KEPADA PEMERINTAH', 'SSL', 241, '0', NULL, '2*6*7*1', -1, NULL, '1'), -(488, '720.40.02', 'BEBAN PENYUSUTAN KENDARAAN KANTOR', 'SSL', 486, '0', NULL, '7*2*3*2', -1, NULL, '1'), -(249, '280.90.90', 'BIAYA RUMAH TANGGA', 'SSL', 241, '0', NULL, '2*6*7*2', -1, NULL, '1'), -(250, '280.50.01', 'UANG MUKA MURABAHAH DARI PEMBELI', 'SSL', 239, '0', NULL, '2*6*5*1', -1, NULL, '1'), -(489, '720.40.03', 'BEBAN PENYUSUTAN INVESTARIS KANTOR', 'SSL', 486, '0', NULL, '7*2*3*3', -1, NULL, '1'), -(425, '595.05.00', 'KEUNTUNGANPENJUALAN AKTIVA TETAP', 'SL', 424, '1', NULL, '5*16*1', -1, NULL, '1'), -(251, '295.10.00', 'PINJAMAN MODAL (LOAN CAPITAL)', 'SL', 200, '1', NULL, '2*7*2', -1, NULL, '1'), -(323, '525.01.01', 'PENDAPATAN SEWA IJARAH', 'SSL', 322, '0', NULL, '5*6*1*1', -1, NULL, '1'), -(490, '720.40.04', 'BEBAN PENYUSUTAN KOMPUTER', 'SSL', 486, '0', NULL, '7*2*3*4', -1, NULL, '1'), -(426, '595.05.01', 'KEUNTUNGAN PENJUALAN TANAH & BANGUNAN', 'SSL', 425, '0', NULL, '5*16*1*1', -1, NULL, '1'), -(252, '295.01.01', 'PINJAMAN SUBORDINASI', 'SSL', 245, '0', NULL, '2*7*1*1', -1, NULL, '1'), -(362, '550.01.04', 'PENDAPATAN PITE MURABAHAH – PEMILIKAN RMH', 'SSL', 360, '0', NULL, '5*8*1*2', -1, NULL, '1'), -(253, '295.10.01', 'PINJAMAN MODAL (LOAN CAPITAL)', 'SSL', 251, '0', NULL, '2*7*2*1', -1, NULL, '1'), -(427, '595.05.02', 'KEUNTUNGAN PENJUALAN KENDARAAN', 'SSL', 425, '0', NULL, '5*16*1*2', -1, NULL, '1'), -(254, '305.01.00', 'TABUNGAN MUDHARABAH', 'SL', 194, '1', NULL, '3*2*1', -1, NULL, '1'), -(491, '720.40.05', 'BEBAN PENYUSUTAN KOMUNIKASI KOMPUTER', 'SSL', 486, '0', NULL, '7*2*3*5', -1, NULL, '1'), -(363, '550.01.05', 'PENDAPATAN PITE MURABAHAH – PEMILIKAN KEND', 'SSL', 360, '0', NULL, '5*8*1*3', -1, NULL, '1'), -(255, '305.05.00', 'INVESTASI MUDHARABAH', 'SL', 194, '1', NULL, '3*2*2', -1, NULL, '1'), -(428, '595.05.03', 'KEUNTUNGAN PENJUALAN KOMPUTER', 'SSL', 425, '0', NULL, '5*16*1*3', -1, NULL, '1'), -(256, '305.01.01', 'TABUNGAN MUDHARABAH', 'SSL', 254, '0', NULL, '3*2*1*1', -1, NULL, '1'), -(364, '550.01.99', 'PENDAPATAN PITE MURABAHAH – LAINNYA', 'SSL', 360, '0', NULL, '5*8*1*4', -1, NULL, '1'), -(429, '595.05.04', 'KEUNTUNGAN PENJUALAN MESIN DAN AC', 'SSL', 425, '0', NULL, '5*16*1*4', -1, NULL, '1'), -(257, '305.05.01', 'INVESTASI MUDHARABAH – 1 BULAN', 'SSL', 255, '0', NULL, '3*2*2*1', -1, NULL, '1'), -(365, '550.50.00', 'PENDAPATAN PITE ISTISHNA', 'SL', 359, '1', NULL, '5*8*2', -1, NULL, '1'), -(258, '305.05.03', 'INVESTASI MUDHARABAH – 3 BULAN', 'SSL', 255, '0', NULL, '3*2*2*2', -1, NULL, '1'), -(399, '575.50.00', 'PENDAPATAN ADM MUSYARAKAH', 'SL', 395, '1', NULL, '5*12*2', -1, NULL, '1'), -(259, '305.05.06', 'INVESTASI MUDHARABAH – 6 BULAN', 'SSL', 255, '0', NULL, '3*2*2*3', -1, NULL, '1'), -(260, '305.05.12', 'INVESTASI MUDHARABAH – 12 BULAN', 'SSL', 255, '0', NULL, '3*2*2*4', -1, NULL, '1'), -(366, '550.50.02', 'PENDAPATAN PITE ISTISHNA – INVESTASI', 'SSL', 365, '0', NULL, '5*8*2*1', -1, NULL, '1'), -(367, '550.50.04', 'PENDAPATAN PITE ISTISHNA– PEMILIKAN RUMAH', 'SSL', 365, '0', NULL, '5*8*2*2', -1, NULL, '1'), -(430, '595.05.05', 'KEUNTUNGAN PENJUALAN PERALATAN KOMUNIKASI', 'SSL', 425, '0', NULL, '5*16*1*5', -1, NULL, '1'), -(368, '550.50.05', 'PENDAPATAN PITE ISTISHNA – PEMILIKAN KEND', 'SSL', 365, '0', NULL, '5*8*2*3', -1, NULL, '1'), -(431, '595.05.06', 'KEUNTUNGAN PENJUALAN INVENTARIS LAINNYA', 'SSL', 425, '0', NULL, '5*16*1*6', -1, NULL, '1'), -(369, '550.50.99', 'PENDAPATAN PITE ISTISHNA – LAINNYA', 'SSL', 365, '0', NULL, '5*8*2*4', -1, NULL, '1'), -(262, '401.01.00', 'MODAL DISETOR', 'SL', 583, '0', NULL, '4*2', -1, NULL, '1'), -(432, '595.10.00', 'HASIL JASA KONSULTASI', 'SL', 424, '1', NULL, '5*16*2', -1, NULL, '1'), -(370, '555.00.00', 'PENDAPATAN BONUS', 'GL', 5, '1', NULL, '5*9', -1, NULL, '1'), -(263, '401.01.01', 'SIMPANAN POKOK KHUSUS', 'SSL', 262, '0', NULL, '4*2*1', -1, NULL, '1'), -(371, '555.01.00', 'PENDAPATAN BONUS QARDH', 'SL', 370, '1', NULL, '5*9*1', -1, NULL, '1'), -(264, '401.01.02', 'SIMPANAN POKOK & WAJIB', 'SL', 262, '0', NULL, '4*2*2', -1, NULL, '1'), -(433, '595.10.01', 'HASIL JASA KONSULTASI', 'SSL', 432, '0', NULL, '5*16*2*1', -1, NULL, '1'), -(265, '405.00.00', 'PERKIRAAN TAMBAHAN MODAL DISETOR', 'GL', 4, '1', NULL, '4*3', -1, NULL, '1'), -(372, '555.01.01', 'PENDAPATAN BONUS QARDH – MODAL KERJA', 'SSL', 371, '0', NULL, '5*9*1*1', -1, NULL, '1'), -(434, '595.90.00', 'LAINNYA', 'SL', 424, '1', NULL, '5*16*3', -1, NULL, '1'), -(493, '720.50.00', 'BEBAN ALAT TULIS DAN BARANG CETAK', 'SL', 471, '1', NULL, '7*2*4', -1, NULL, '1'), -(373, '555.01.03', 'PENDAPATAN BONUS QARDH – KONSUMSI', 'SSL', 371, '0', NULL, '5*9*1*2', -1, NULL, '1'), -(266, '405.01.00', 'PERKIRAAN TAMBAHAN MODAL DISETOR', 'SL', 265, '1', NULL, '4*3*1', -1, NULL, '1'), -(435, '595.90.01', 'LAINNYA', 'SSL', 434, '0', NULL, '5*16*3*1', -1, NULL, '1'), -(494, '720.50.01', 'BEBAN ALAT TULIS', 'SSL', 493, '0', NULL, '7*2*4*1', -1, NULL, '1'), -(267, '405.01.01', 'AGIO', 'SSL', 266, '0', NULL, '4*3*1*1', -1, NULL, '1'), -(374, '555.01.99', 'PENDAPATAN BONUS QARDH – LAINNYA', 'SSL', 371, '0', NULL, '5*9*1*3', -1, NULL, '1'), -(268, '405.01.02', 'DISAGIO (DB)', 'SSL', 266, '0', NULL, '4*3*1*2', -1, NULL, '1'), -(495, '720.50.02', 'BEBAN BARANG CETAK', 'SSL', 493, '0', NULL, '7*2*4*2', -1, NULL, '1'), -(375, '565.00.00', 'PENDAPATAN PENYERAHAN AKTIVA', 'GL', 5, '1', NULL, '5*10', -1, NULL, '1'), -(269, '405.01.03', 'MODAL KUASI', 'SSL', 266, '0', NULL, '4*3*1*3', -1, NULL, '1'), -(436, '601.00.00', 'BAGI HASIL ITT BUKAN BANK', 'GL', 6, '1', NULL, '6*1', 1, NULL, '1'), -(270, '405.01.04', 'PENYESUAIAN AKIBAT PENJA. LAP. KEUANGAN', 'SSL', 266, '0', NULL, '4*3*1*4', -1, NULL, '1'), -(376, '565.10.00', 'KEUNTUNGAN PENYERAHAN AKTIVA', 'SL', 375, '1', NULL, '5*10*1', -1, NULL, '1'), -(496, '720.60.00', 'BEBAN SEWA (BESE)', 'SL', 471, '1', NULL, '7*2*5', -1, NULL, '1'), -(271, '405.01.05', 'BIAYA ADM BANK', 'SSL', 266, '0', NULL, '4*3*1*5', -1, NULL, '1'), -(377, '565.10.01', 'KEUNTUNGAN PENYERAHAN AKTIVA – SALAM', 'SSL', 376, '0', NULL, '5*10*1*1', -1, NULL, '1'), -(497, '720.60.01', 'BESE – GEDUNG & RUMAH', 'SSL', 496, '0', NULL, '7*2*5*1', -1, NULL, '1'), -(437, '601.01.00', 'BAGI HASIL TABUNGAN MUDHARABAH', 'SL', 436, '1', NULL, '6*1*1', 1, NULL, '1'), -(272, '410.00.00', 'SELISIH PENILAIAN KEMBALI AKTIVA TETAP', 'GL', 4, '1', NULL, '4*4', -1, NULL, '1'), -(378, '565.10.02', 'KEUNTUNGAN PENYERAHAN AKTIVA - MUDHARABAH', 'SSL', 376, '0', NULL, '5*10*1*2', -1, NULL, '1'), -(273, '420.00.00', 'LABA DITAHAN', 'GL', 4, '1', NULL, '4*5', -1, NULL, '1'), -(438, '601.01.01', 'BAGI HASIL TABUNGAN MUDHARABAH', 'SSL', 437, '0', NULL, '6*1*1*1', 1, NULL, '1'), -(274, '420.01.00', 'CADANGAN TUJUAN', 'SL', 273, '1', NULL, '4*5*1', -1, NULL, '1'), -(498, '720.60.02', 'BESE – MESIN KOMPUTER', 'SSL', 496, '0', NULL, '7*2*5*2', -1, NULL, '1'), -(379, '565.10.03', 'KEUNTUNGAN PENYERAHAN AKTIVA – MUSYARAKAH', 'SSL', 376, '0', NULL, '5*10*1*3', -1, NULL, '1'), -(275, '420.01.01', 'CADANGAN TUJUAN', 'SSL', 274, '0', NULL, '4*5*1*1', -1, NULL, '1'), -(439, '601.05.00', 'BAGI HASIL DEPOSITO MUDHARABAH', 'SL', 436, '1', NULL, '6*1*2', 1, NULL, '1'), -(276, '420.02.00', 'CADANGAN UMUM', 'SL', 273, '1', NULL, '4*5*2', -1, NULL, '1'), -(277, '420.02.01', 'CADANGAN UMUM', 'SSL', 276, '0', NULL, '4*5*2*1', -1, NULL, '1'), -(440, '601.05.01', 'BAGI HASIL DEPOSITO MUDHARABAH – 1 BULAN', 'SSL', 439, '0', NULL, '6*1*2*1', 1, NULL, '1'), -(278, '420.02.02', 'LABA YANG DITAHAN', 'SSL', 276, '0', NULL, '4*5*2*2', -1, NULL, '1'), -(279, '420.04.00', 'CADANGAN DEVIDEN SAHAM', 'SL', 273, '1', NULL, '4*5*3', -1, NULL, '1'), -(324, '525.01.02', 'KEUNTUNGAN PENJUALAN AKTIVA IJARAH', 'SSL', 322, '0', NULL, '5*6*1*2', -1, NULL, '1'), -(441, '601.05.03', 'BAGI HASIL DEPOSITO MUDHARABAH – 3 BULAN', 'SSL', 439, '0', NULL, '6*1*2*2', 1, NULL, '1'), -(280, '420.04.01', 'CADANGAN DEVIDEN SAHAM', 'SSL', 279, '0', NULL, '4*5*3*1', -1, NULL, '1'), -(464, '701.15.00', 'BEBAN KESEHATAN (BEKES)', 'SL', 452, '1', NULL, '7*1*4', -1, NULL, '1'), -(281, '430.00.00', 'SISA LABA YANG BELUM DICADANGKAN', 'GL', 4, '1', NULL, '4*6', -1, NULL, '1'), -(282, '430.01.00', 'LABA/RUGI TAHUN LALU', 'SL', 281, '1', NULL, '4*6*1', -1, NULL, '1'), -(558, '790.05.02', 'KERUGIAN PENJUALAN KENDARAAN', 'SSL', 556, '0', NULL, '7*6*1*2', -1, NULL, '1'), -(499, '720.60.03', 'BESE – KENDARAAN', 'SSL', 496, '0', NULL, '7*2*5*3', -1, NULL, '1'), -(283, '430.01.01', 'LABA/RUGI TAHUN LALU', 'SSL', 282, '0', NULL, '4*6*1*1', -1, NULL, '1'), -(284, '430.02.00', 'LABA/RUGI TAHUN BERJALAN', 'SL', 281, '1', NULL, '4*6*2', -1, NULL, '1'), -(285, '430.02.01', 'LABA/RUGI TAHUN BERJALAN', 'SSL', 284, '0', NULL, '4*6*2*1', -1, NULL, '1'), -(442, '601.05.06', 'BAGI HASIL DEPOSITO MUDHARABAH – 6 BULAN', 'SSL', 439, '0', NULL, '6*1*2*3', 1, NULL, '1'), -(443, '601.05.12', 'BAGI HASIL DEPOSITO MUDHARABAH – 12 BULAN', 'SSL', 439, '0', NULL, '6*1*2*4', 1, NULL, '1'), -(500, '750.00.00', 'BEBAN PPAP – PENYALURAN DANA', 'GL', 7, '1', NULL, '7*3', -1, NULL, '1'), -(286, '501.00.00', 'PENDAPATAN MARGIN MURABAHAH', 'GL', 5, '1', NULL, '5*1', -1, NULL, '1'), -(444, '605.00.00', 'BAGI HASIL ITT BANK', 'GL', 6, '1', NULL, '6*2', 1, NULL, '1'), -(287, '501.01.00', 'PENDAPATAN MARGIN MURABAHAH', 'SL', 286, '1', NULL, '5*1*1', -1, NULL, '1'), -(501, '750.01.00', 'BEBAN PPAP – MURABAHAH', 'SL', 500, '1', NULL, '7*3*1', -1, NULL, '1'), -(288, '501.01.21', 'PENDAPATAN MARGIN MURABAHAH', 'SSL', 287, '0', NULL, '5*1*1*1', -1, 0, '1'), -(445, '605.01.00', 'BAGI HASIL TABUNGAN MUDHARABAH', 'SL', 444, '1', NULL, '6*2*1', 1, NULL, '1'); -INSERT INTO `coa_listakun` (`listakun_id`, `listakun_code`, `listakun_name`, `listakun_alias`, `listakun_parent`, `listakun_folder`, `listakun_level`, `listakun_pattern`, `listakun_sign`, `listakun_wight`, `listakun_active`) VALUES -(502, '750.01.01', 'BEBAN PPAP – MURABAHAH', 'SSL', 501, '0', NULL, '7*3*1*1', -1, NULL, '1'), -(503, '750.02.00', 'BEBAN PPAP – SALAM', 'SL', 500, '1', NULL, '7*3*2', -1, NULL, '1'), -(504, '750.02.01', 'BEBAN PPAP – SALAM', 'SSL', 503, '0', NULL, '7*3*2*1', -1, NULL, '1'), -(293, '501.05.00', 'POTONGAN PELUNASAN MURABAHAH (DR)', 'SL', 286, '1', NULL, '5*1*2', -1, NULL, '1'), -(505, '750.03.00', 'BEBAN PPAP – ISTISHNA', 'SL', 500, '1', NULL, '7*3*3', -1, NULL, '1'), -(294, '501.05.21', 'POTONGAN PELUNASAN MBA', '', 293, '0', NULL, '5*1*2*1', -1, 0, '1'), -(449, '605.05.03', 'BAGI HASIL DEPOSITO MUDHARABAH – 3 BULAN', 'SSL', 447, '0', NULL, '6*2*2*2', 1, NULL, '1'), -(450, '605.05.06', 'BAGI HASIL DEPOSITO MUDHARABAH – 6 BULAN', 'SSL', 447, '0', NULL, '6*2*2*3', 1, NULL, '1'), -(509, '750.05.00', 'BEBAN PPAP – MUSYARAKAH', 'SL', 500, '1', NULL, '7*3*5', -1, NULL, '1'), -(451, '605.05.12', 'BAGI HASIL DEPOSITO MUDHARABAH – 12 BULAN', 'SSL', 447, '0', NULL, '6*2*2*4', 1, NULL, '1'), -(510, '750.05.01', 'BEBAN PPAP – MUSYARAKAH', 'SSL', 509, '0', NULL, '7*3*5*1', -1, NULL, '1'), -(511, '750.06.00', 'BEBAN PPAP – IJARAH', 'SL', 500, '1', NULL, '7*3*6', -1, NULL, '1'), -(512, '750.06.01', 'BEBAN PPAP – IJARAH', 'SSL', 511, '0', NULL, '7*3*6*1', -1, NULL, '1'), -(513, '750.07.00', 'BEBAN PPAP – PINJAMAN QARDH', 'SL', 500, '1', NULL, '7*3*7', -1, NULL, '1'), -(514, '750.07.01', 'BEBAN PPAP – PINJAMAN QARDH', 'SSL', 513, '0', NULL, '7*3*7*1', -1, NULL, '1'), -(515, '750.09.00', 'BEBAN PPAP – LAINNYA', 'SL', 500, '1', NULL, '7*3*8', -1, NULL, '1'), -(516, '750.09.01', 'BEBAN PPAP – LAINNYA', 'SSL', 515, '0', NULL, '7*3*8*1', -1, NULL, '1'), -(517, '770.00.00', 'BEBAN LAINNYA (BELA)', 'GL', 7, '1', NULL, '7*4', -1, NULL, '1'), -(518, '770.01.00', 'BELA – PROMOSI', 'SL', 517, '1', NULL, '7*4*1', -1, NULL, '1'), -(519, '770.01.01', 'BELA – PROMOSI USAHA', 'SSL', 518, '0', NULL, '7*4*1*1', -1, NULL, '1'), -(559, '790.05.03', 'KERUGIAN PENJUALAN KOMPUTER', 'SSL', 556, '0', NULL, '7*6*1*3', -1, NULL, '1'), -(520, '770.02.00', 'BELA – REPRESENTASE DAN HUMAS', 'SL', 517, '1', NULL, '7*4*2', -1, NULL, '1'), -(521, '770.02.01', 'BELA – REPRESENTASE', 'SSL', 520, '0', NULL, '7*4*2*1', -1, NULL, '1'), -(522, '770.02.02', 'BELA – SURAT KABAR & MAJALAH', 'SSL', 520, '0', NULL, '7*4*2*2', -1, NULL, '1'), -(523, '770.03.00', 'BELA – PREMI ASURANSI', 'SL', 517, '1', NULL, '7*4*3', -1, NULL, '1'), -(524, '770.03.01', 'BELA – PREMI ASURANSI – KEPEGAWAIAN', 'SSL', 523, '0', NULL, '7*4*3*1', -1, NULL, '1'), -(525, '770.03.03', 'BELA – PREMI ASURANSI – AKT TETAP & INVENTARIS', 'SSL', 523, '0', NULL, '7*4*3*2', -1, NULL, '1'), -(526, '770.03.04', 'BELA – PREMI ASURANSI – CASH IN SAFE', 'SSL', 523, '0', NULL, '7*4*3*3', -1, NULL, '1'), -(527, '770.03.07', 'BELA – PREMI ASURANSI – KESEHATAN', 'SSL', 523, '0', NULL, '7*4*3*4', -1, NULL, '1'), -(528, '770.04.00', 'BELA – PAJAK & PUNGUTAN', 'SL', 517, '1', NULL, '7*4*4', -1, NULL, '1'), -(529, '770.04.01', 'BELA – PAJAK PENGHASILAN PASAL 21', 'SSL', 528, '0', NULL, '7*4*4*1', -1, NULL, '1'), -(530, '770.04.02', 'BELA – PAJAK PORTO DAN METERAI', 'SSL', 528, '0', NULL, '7*4*4*2', -1, NULL, '1'), -(531, '770.04.03', 'BELA – PAJAK AKTIVA TETAP & INVENTARIS', 'SSL', 528, '0', NULL, '7*4*4*3', -1, NULL, '1'), -(532, '770.04.05', 'BELA – PAJAK RETRIBUSI DAN USAHA', 'SSL', 528, '0', NULL, '7*4*4*4', -1, NULL, '1'), -(533, '770.06.01', 'BIAYA ADM BANK', 'SSL', 517, '0', NULL, '7*4*4*5', -1, NULL, '1'), -(534, '770.10.00', 'KERUGIAN PENYERAHAN AKTIVA', 'SL', 517, '1', NULL, '7*4*5', -1, NULL, '1'), -(535, '770.10.01', 'KERUGIAN PENYERAHAN AKTIVA – SALAM', 'SSL', 534, '0', NULL, '7*4*5*1', -1, NULL, '1'), -(536, '770.10.02', 'KERUGIAN PENYERAHAN AKTIVA – MUDHARABAH', 'SSL', 534, '0', NULL, '7*4*5*2', -1, NULL, '1'), -(537, '770.10.03', 'KERUGIAN PENYERAHAN AKTIVA – MUSYARAKAH', 'SSL', 534, '0', NULL, '7*4*5*3', -1, NULL, '1'), -(560, '790.05.04', 'KERUGIAN PENJUALAN MESIN DAN AC', 'SSL', 556, '0', NULL, '7*6*1*4', -1, NULL, '1'), -(538, '770.10.04', 'KERUGIAN PENYERAHAN AKTIVA - LAINNYA', 'SSL', 534, '0', NULL, '7*4*5*4', -1, NULL, '1'), -(539, '770.20.00', 'BEBAN PRODUK LAINNYA', 'SL', 517, '1', NULL, '7*4*6', -1, NULL, '1'), -(540, '770.20.02', 'BEBAN AKAD', 'SSL', 539, '0', NULL, '7*4*6*1', -1, NULL, '1'), -(541, '770.20.03', 'KERUGIAN PESANAN MURABAHAH', 'SSL', 539, '0', NULL, '7*4*6*2', -1, NULL, '1'), -(542, '770.20.05', 'KERUGIAN TRANSAKSI SALAM', 'SSL', 539, '0', NULL, '7*4*6*3', -1, NULL, '1'), -(543, '770.20.06', 'KERUGIAN PENURUNAN NILAI PERSEDIAAN', 'SSL', 539, '0', NULL, '7*4*6*4', -1, NULL, '1'), -(568, '101.01.01', 'KAS KHASANAH UTAMA', '', 11, '0', NULL, '1*1*1*1', 1, NULL, '1'), -(577, '201.60.01', 'TITIPAN ZAKAT', '', 576, '0', NULL, '2*1*3*1', -1, 0, '1'), -(570, '301.05.06', 'INVESTASI MUDHARABAH - 6 BULAN', '', 196, '0', NULL, '3*1*2*3', -1, 0, '1'), -(571, '301.05.12', 'INVESTASI MUDHARABAH - 12 BULAN', '', 196, '0', NULL, '3*1*2*4', -1, 0, '1'), -(573, '195.30.01', 'REKENING ANTAR BAGIAN', '', 572, '0', NULL, '1*17*4*1', 1, 0, '1'), -(578, '201.60.02', 'TITIPAN INFAQ', '', 576, '0', NULL, '2*1*3*2', -1, 0, '1'), -(579, '201.60.03', 'TITIPAN DANA KEBAJIKAN', '', 576, '0', NULL, '2*1*3*3', -1, 0, '1'), -(580, '590.10.00', 'PENDAPATAN ADM TABUNGAN', '', 414, '1', NULL, '5*15*4', -1, 0, '1'), -(581, '590.10.01', 'PENDAPATAN ADM TABUNGAN', '', 580, '0', NULL, '5*15*4*1', -1, 0, '1'), -(583, '401.00.00', 'MODAL DISETOR', 'GL', 4, '0', NULL, NULL, NULL, NULL, ''), -(584, '180.02.00', 'KOMPUTER & PRINTER', 'KOMPUTER & PRINTER', 76, '0', NULL, NULL, NULL, NULL, ''), -(585, '180.02.01', 'KOMPUTER', 'KOMPUTER', 584, '0', NULL, NULL, NULL, NULL, ''), -(586, '180.02.02', 'PRINTER PASSBOOK', 'PRINTER PASSBOOK', 584, '0', NULL, NULL, NULL, NULL, ''), -(587, '180.02.03', 'PRINTER INTJET', 'PRINTER INTJET', 584, '0', NULL, NULL, NULL, NULL, ''), -(588, '180.02.04', 'LAN JANYAN', 'LAN JANYAN', 584, '0', NULL, NULL, NULL, NULL, ''), -(589, '180.03.00', 'FURNITURE & MEUBEULER', 'RNITURE & MEUBEULER', 76, '0', NULL, NULL, NULL, NULL, ''), -(590, '180.03.01', 'KURSI & MEJA OFFICE', 'KURSI & MEJA OFFICE', 589, '0', NULL, NULL, NULL, NULL, ''), -(591, '180.03.02', 'BRANGKAS', 'BRANGKAS', 589, '0', NULL, NULL, NULL, NULL, ''), -(592, '180.03.03', 'MEJA TELLER', 'MEJA TELLER', 589, '0', NULL, NULL, NULL, NULL, ''), -(593, '180.03.04', 'LEMARI ARSIP', 'LEMARI ARSIP', 589, '0', NULL, NULL, NULL, NULL, ''), -(594, '180.04.00', 'PERALATAN ELEKTRONIK', 'SL', 76, '0', NULL, NULL, NULL, NULL, ''), -(595, '180.04.01', 'PERALATAN ELEKTRONIK', 'SSL', 594, '0', NULL, NULL, NULL, NULL, ''), -(596, '180.05.00', 'PERALATAN NON ELEKTRONIK', 'SL', 76, '0', NULL, NULL, NULL, NULL, ''), -(597, '180.05.01', 'PERALATAN NON ELEKTRONIK', 'SSL', 596, '0', NULL, NULL, NULL, NULL, ''), -(598, '180.04.02', 'GENSET', 'SL', 594, '0', NULL, NULL, NULL, NULL, ''), -(599, '175.90.03', 'PIUTANG WAKALAH', 'SSGL', 133, '0', NULL, NULL, NULL, NULL, ''), -(600, '185.01.04', 'BDD-INTERNET', 'BDD-INTERNET', 164, '0', NULL, NULL, NULL, NULL, ''), -(601, '110.02.00', 'BANK UMUM', 'BANK UMUM', 13, '0', NULL, NULL, NULL, NULL, ''), -(602, '110.02.01', 'BANK BRI', 'BANK BRI', 601, '0', NULL, NULL, NULL, NULL, ''), -(603, '780.15.03', 'BEBAN UMUM – LAINNYA', '', 552, '0', NULL, NULL, NULL, NULL, ''), -(604, '590.90.03', 'PENDAPATAN PENGGANTIAN KERUGIAN PERSH ASURANSI', 'PENDAPATAN PENGGANTIAN KERUGIA', 420, '0', NULL, NULL, NULL, NULL, ''), -(605, '770.04.06', 'BELA – PAJAK LAINNYA', '', 517, '0', NULL, NULL, NULL, NULL, ''), -(606, '770.04.07', 'BELA – LAINNYA', '', 528, '0', NULL, NULL, NULL, NULL, ''), -(607, '185.02.01', 'BIAYA RUMAH TANGGA', 'BIAYA RUMAH TANGGA', 77, '0', NULL, NULL, NULL, NULL, ''), -(608, '720.20.05', 'BEMEL – MESIN & AC', '', 471, '0', NULL, NULL, NULL, NULL, ''), -(609, '720.20.06', 'BEMEL – INVENTARIS LAINNYA', '', 608, '0', NULL, NULL, NULL, NULL, ''), -(610, '720.10.07', 'BEALISTEL – AIR', 'SSL', 472, '0', NULL, NULL, NULL, NULL, ''), -(611, '110.02.02', 'MASPAY', 'PPOB', 601, '0', NULL, NULL, NULL, NULL, ''); - --- -------------------------------------------------------- - --- --- Table structure for table `groups` --- - -CREATE TABLE IF NOT EXISTS `groups` ( - `group_id` int(11) NOT NULL AUTO_INCREMENT, - `nama_group` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, - `controller` text COLLATE utf8_unicode_ci, - PRIMARY KEY (`group_id`), - UNIQUE KEY `namagroup` (`nama_group`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=12 ; - --- --- Dumping data for table `groups` --- - -INSERT INTO `groups` (`group_id`, `nama_group`, `controller`) VALUES -(1, 'Admin', 'a:51:{i:0;s:0:"";i:1;s:10:"setortunai";i:2;s:10:"tariktunai";i:3;s:13:"setordeposito";i:4;s:17:"pencairandeposito";i:5;s:19:"pencairanpembiayaan";i:6;s:8:"angsuran";i:7;s:9:"lapmutasi";i:8;s:14:"hapustransaksi";i:9;s:4:"help";i:10;s:7:"profile";i:11;s:9:"param/bmt";i:12;s:14:"param/deposito";i:13;s:22:"param/distribusiprofit";i:14;s:20:"param/kolektibilitas";i:15;s:14:"param/listakun";i:16;s:13:"param/nasabah";i:17;s:13:"param/pegawai";i:18;s:16:"param/pembiayaan";i:19;s:15:"param/setupmenu";i:20;s:14:"param/tabungan";i:21;s:10:"param/umum";i:22;s:10:"param/user";i:23;s:13:"base/deposito";i:24;s:12:"base/jaminan";i:25;s:12:"base/nasabah";i:26;s:15:"base/pembiayaan";i:27;s:13:"base/tabungan";i:28;s:15:"akunting/jurnal";i:29;s:17:"akunting/labarugi";i:30;s:15:"akunting/neraca";i:31;s:16:"akunting/posting";i:32;s:20:"trans/kaskeluarmasuk";i:33;s:18:"trans/reportteller";i:34;s:21:"trans/reporttransaksi";i:35;s:24:"trans/selisihkuranglebih";i:36;s:19:"trans/transaksilain";i:37;s:24:"monitor/aktivasitabungan";i:38;s:21:"monitor/cetaktabungan";i:39;s:16:"monitor/deposito";i:40;s:20:"monitor/listtabungan";i:41;s:11:"monitor/npf";i:42;s:18:"monitor/pembiayaan";i:43;s:15:"tool/backupdata";i:44;s:12:"tool/cronjob";i:45;s:8:"tool/eoy";i:46;s:16:"tool/hitungbasil";i:47;s:21:"setting/cetaktabungan";i:48;s:12:"setting/logo";i:49;s:17:"setting/sampultab";i:50;s:13:"setting/theme";}'), -(3, 'TELLER', 'a:31:{i:0;s:0:"";i:1;s:10:"setortunai";i:2;s:10:"tariktunai";i:3;s:13:"setordeposito";i:4;s:17:"pencairandeposito";i:5;s:19:"pencairanpembiayaan";i:6;s:8:"angsuran";i:7;s:9:"lapmutasi";i:8;s:14:"hapustransaksi";i:9;s:4:"help";i:10;s:7:"profile";i:11;s:9:"param/bmt";i:12;s:10:"param/user";i:13;s:13:"base/deposito";i:14;s:12:"base/jaminan";i:15;s:12:"base/nasabah";i:16;s:15:"base/pembiayaan";i:17;s:13:"base/tabungan";i:18;s:20:"trans/kaskeluarmasuk";i:19;s:18:"trans/reportteller";i:20;s:21:"trans/reporttransaksi";i:21;s:24:"trans/selisihkuranglebih";i:22;s:19:"trans/transaksilain";i:23;s:24:"monitor/aktivasitabungan";i:24;s:21:"monitor/cetaktabungan";i:25;s:16:"monitor/deposito";i:26;s:20:"monitor/listtabungan";i:27;s:11:"monitor/npf";i:28;s:18:"monitor/pembiayaan";i:29;s:21:"setting/cetaktabungan";i:30;s:17:"setting/sampultab";}'), -(4, 'MARKETING', 'a:10:{i:0;s:0:"";i:1;s:4:"help";i:2;s:7:"profile";i:3;s:10:"param/user";i:4;s:24:"monitor/aktivasitabungan";i:5;s:21:"monitor/cetaktabungan";i:6;s:16:"monitor/deposito";i:7;s:20:"monitor/listtabungan";i:8;s:11:"monitor/npf";i:9;s:18:"monitor/pembiayaan";}'), -(5, 'CS', 'a:15:{i:0;s:0:"";i:1;s:4:"help";i:2;s:7:"profile";i:3;s:13:"base/deposito";i:4;s:12:"base/jaminan";i:5;s:12:"base/nasabah";i:6;s:15:"base/pembiayaan";i:7;s:13:"base/tabungan";i:8;s:24:"monitor/aktivasitabungan";i:9;s:21:"monitor/cetaktabungan";i:10;s:16:"monitor/deposito";i:11;s:20:"monitor/listtabungan";i:12;s:11:"monitor/npf";i:13;s:18:"monitor/pembiayaan";i:14;s:16:"tool/hitungbasil";}'), -(8, 'ADM LEGAL', 'a:15:{i:0;s:0:"";i:1;s:4:"help";i:2;s:7:"profile";i:3;s:10:"param/user";i:4;s:13:"base/deposito";i:5;s:12:"base/jaminan";i:6;s:12:"base/nasabah";i:7;s:15:"base/pembiayaan";i:8;s:13:"base/tabungan";i:9;s:24:"monitor/aktivasitabungan";i:10;s:21:"monitor/cetaktabungan";i:11;s:16:"monitor/deposito";i:12;s:20:"monitor/listtabungan";i:13;s:11:"monitor/npf";i:14;s:18:"monitor/pembiayaan";}'), -(9, 'Operasional & Keuang', 'a:36:{i:0;s:0:"";i:1;s:4:"help";i:2;s:7:"profile";i:3;s:9:"param/bmt";i:4;s:14:"param/deposito";i:5;s:22:"param/distribusiprofit";i:6;s:20:"param/kolektibilitas";i:7;s:14:"param/listakun";i:8;s:13:"param/nasabah";i:9;s:13:"param/pegawai";i:10;s:16:"param/pembiayaan";i:11;s:15:"param/setupmenu";i:12;s:14:"param/tabungan";i:13;s:10:"param/umum";i:14;s:10:"param/user";i:15;s:13:"base/deposito";i:16;s:12:"base/jaminan";i:17;s:12:"base/nasabah";i:18;s:15:"base/pembiayaan";i:19;s:13:"base/tabungan";i:20;s:15:"akunting/jurnal";i:21;s:17:"akunting/labarugi";i:22;s:15:"akunting/neraca";i:23;s:16:"akunting/posting";i:24;s:24:"monitor/aktivasitabungan";i:25;s:21:"monitor/cetaktabungan";i:26;s:16:"monitor/deposito";i:27;s:20:"monitor/listtabungan";i:28;s:11:"monitor/npf";i:29;s:18:"monitor/pembiayaan";i:30;s:15:"tool/backupdata";i:31;s:16:"tool/hitungbasil";i:32;s:21:"setting/cetaktabungan";i:33;s:12:"setting/logo";i:34;s:17:"setting/sampultab";i:35;s:13:"setting/theme";}'), -(10, 'AKUNTANSI', 'a:24:{i:0;s:0:"";i:1;s:4:"help";i:2;s:7:"profile";i:3;s:13:"base/deposito";i:4;s:12:"base/jaminan";i:5;s:12:"base/nasabah";i:6;s:15:"base/pembiayaan";i:7;s:13:"base/tabungan";i:8;s:15:"akunting/jurnal";i:9;s:17:"akunting/labarugi";i:10;s:15:"akunting/neraca";i:11;s:16:"akunting/posting";i:12;s:24:"monitor/aktivasitabungan";i:13;s:21:"monitor/cetaktabungan";i:14;s:16:"monitor/deposito";i:15;s:20:"monitor/listtabungan";i:16;s:11:"monitor/npf";i:17;s:18:"monitor/pembiayaan";i:18;s:15:"tool/backupdata";i:19;s:16:"tool/hitungbasil";i:20;s:21:"setting/cetaktabungan";i:21;s:12:"setting/logo";i:22;s:17:"setting/sampultab";i:23;s:13:"setting/theme";}'), -(11, 'MANAGER', 'a:26:{i:0;s:0:"";i:1;s:4:"help";i:2;s:7:"profile";i:3;s:9:"param/bmt";i:4;s:14:"param/deposito";i:5;s:22:"param/distribusiprofit";i:6;s:20:"param/kolektibilitas";i:7;s:14:"param/listakun";i:8;s:13:"param/nasabah";i:9;s:13:"param/pegawai";i:10;s:16:"param/pembiayaan";i:11;s:15:"param/setupmenu";i:12;s:14:"param/tabungan";i:13;s:10:"param/umum";i:14;s:10:"param/user";i:15;s:13:"base/deposito";i:16;s:12:"base/jaminan";i:17;s:12:"base/nasabah";i:18;s:15:"base/pembiayaan";i:19;s:13:"base/tabungan";i:20;s:24:"monitor/aktivasitabungan";i:21;s:21:"monitor/cetaktabungan";i:22;s:16:"monitor/deposito";i:23;s:20:"monitor/listtabungan";i:24;s:11:"monitor/npf";i:25;s:18:"monitor/pembiayaan";}'); - --- -------------------------------------------------------- - --- --- Table structure for table `jabatan` --- - -CREATE TABLE IF NOT EXISTS `jabatan` ( - `jabatan_id` int(11) NOT NULL AUTO_INCREMENT, - `nama_jabatan` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - `keterangan` text COLLATE utf8_unicode_ci, - PRIMARY KEY (`jabatan_id`), - UNIQUE KEY `jabatan` (`nama_jabatan`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=7 ; - --- --- Dumping data for table `jabatan` --- - -INSERT INTO `jabatan` (`jabatan_id`, `nama_jabatan`, `keterangan`) VALUES -(1, 'Administrator', 'Pengelola System'), -(2, 'Direktur', 'Direktur'), -(3, 'Manager', 'Manager'), -(4, 'Senior Staf', 'Senior Staf menejemen'), -(5, 'Staf', 'Staf'), -(6, 'Staf Magang', 'Staf Magang'); - --- -------------------------------------------------------- - --- --- Table structure for table `kabupaten` --- - -CREATE TABLE IF NOT EXISTS `kabupaten` ( - `kodeBPS` int(11) NOT NULL, - `namaKabupaten` varchar(100) COLLATE latin1_general_ci NOT NULL, - `kodeProvinsi` int(11) NOT NULL, - PRIMARY KEY (`kodeBPS`), - KEY `idProvinsi` (`kodeProvinsi`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; - --- --- Dumping data for table `kabupaten` --- - -INSERT INTO `kabupaten` (`kodeBPS`, `namaKabupaten`, `kodeProvinsi`) VALUES -(1101, 'SIMEULUE', 11), -(1102, 'ACEH SINGKIL', 11), -(1103, 'ACEH SELATAN', 11), -(1104, 'ACEH TENGGARA', 11), -(1105, 'ACEH TIMUR', 11), -(1106, 'ACEH TENGAH', 11), -(1107, 'ACEH BARAT', 11), -(1108, 'ACEH BESAR', 11), -(1109, 'PIDIE', 11), -(1110, 'BIREUEN', 11), -(1111, 'ACEH UTARA', 11), -(1112, 'ACEH BARAT DAYA', 11), -(1113, 'GAYO LUES', 11), -(1114, 'ACEH TAMIANG', 11), -(1115, 'NAGAN RAYA', 11), -(1116, 'ACEH JAYA', 11), -(1117, 'BENER MERIAH', 11), -(1118, 'PIDIE JAYA', 11), -(1171, 'BANDA ACEH', 11), -(1172, 'SABANG', 11), -(1173, 'LANGSA', 11), -(1174, 'LHOKSEUMAWE', 11), -(1175, 'SUBULUSSALAM', 11), -(1201, 'NIAS', 12), -(1202, 'MANDAILING NATAL', 12), -(1203, 'TAPANULI SELATAN', 12), -(1204, 'TAPANULI TENGAH', 12), -(1205, 'TAPANULI UTARA', 12), -(1206, 'TOBA SAMOSIR', 12), -(1207, 'LABUHAN BATU', 12), -(1208, 'ASAHAN', 12), -(1209, 'SIMALUNGUN', 12), -(1210, 'DAIRI', 12), -(1211, 'KARO', 12), -(1212, 'DELI SERDANG', 12), -(1213, 'LANGKAT', 12), -(1214, 'NIAS SELATAN', 12), -(1215, 'HUMBANG HASUNDUTAN', 12), -(1216, 'PAKPAK BHARAT', 12), -(1217, 'SAMOSIR', 12), -(1218, 'SERDANG BEDAGAI', 12), -(1219, 'BATU BARA', 12), -(1220, 'PADANG LAWAS UTARA', 12), -(1221, 'PADANG LAWAS', 12), -(1222, 'LABUHAN BATU SELATAN', 12), -(1223, 'LABUHAN BATU UTARA', 12), -(1224, 'NIAS UTARA', 12), -(1225, 'NIAS BARAT', 12), -(1271, 'SIBOLGA', 12), -(1272, 'TANJUNG BALAI', 12), -(1273, 'PEMATANG SIANTAR', 12), -(1274, 'TEBING TINGGI', 12), -(1275, 'MEDAN', 12), -(1276, 'BINJAI', 12), -(1277, 'PADANGSIDIMPUAN', 12), -(1278, 'GUNUNGSITOLI', 12), -(1301, 'KEPULAUAN MENTAWAI', 13), -(1302, 'PESISIR SELATAN', 13), -(1303, 'SOLOK', 13), -(1304, 'SIJUNJUNG', 13), -(1305, 'TANAH DATAR', 13), -(1306, 'PADANG PARIAMAN', 13), -(1307, 'AGAM', 13), -(1308, 'LIMA PULUH KOTA', 13), -(1309, 'PASAMAN', 13), -(1310, 'SOLOK SELATAN', 13), -(1311, 'DHARMASRAYA', 13), -(1312, 'PASAMAN BARAT', 13), -(1371, 'PADANG', 13), -(1372, 'SOLOK', 13), -(1373, 'SAWAH LUNTO', 13), -(1374, 'PADANG PANJANG', 13), -(1375, 'BUKITTINGGI', 13), -(1376, 'PAYAKUMBUH', 13), -(1377, 'PARIAMAN', 13), -(1401, 'KUANTAN SINGINGI', 14), -(1402, 'INDRAGIRI HULU', 14), -(1403, 'INDRAGIRI HILIR', 14), -(1404, 'PELALAWAN', 14), -(1405, 'S I A K', 14), -(1406, 'KAMPAR', 14), -(1407, 'ROKAN HULU', 14), -(1408, 'BENGKALIS', 14), -(1409, 'ROKAN HILIR', 14), -(1410, 'KEPULAUAN MERANTI', 14), -(1471, 'PEKANBARU', 14), -(1473, 'D U M A I', 14), -(1501, 'KERINCI', 15), -(1502, 'MERANGIN', 15), -(1503, 'SAROLANGUN', 15), -(1504, 'BATANG HARI', 15), -(1505, 'MUARO JAMBI', 15), -(1506, 'TANJUNG JABUNG TIMUR', 15), -(1507, 'TANJUNG JABUNG BARAT', 15), -(1508, 'TEBO', 15), -(1509, 'BUNGO', 15), -(1571, 'JAMBI', 15), -(1572, 'SUNGAI PENUH', 15), -(1601, 'OGAN KOMERING ULU', 16), -(1602, 'OGAN KOMERING ILIR', 16), -(1603, 'MUARA ENIM', 16), -(1604, 'LAHAT', 16), -(1605, 'MUSI RAWAS', 16), -(1606, 'MUSI BANYUASIN', 16), -(1607, 'BANYU ASIN', 16), -(1608, 'OGAN KOMERING ULU SELATAN', 16), -(1609, 'OGAN KOMERING ULU TIMUR', 16), -(1610, 'OGAN ILIR', 16), -(1611, 'EMPAT LAWANG', 16), -(1671, 'PALEMBANG', 16), -(1672, 'PRABUMULIH', 16), -(1673, 'PAGAR ALAM', 16), -(1674, 'LUBUKLINGGAU', 16), -(1701, 'BENGKULU SELATAN', 17), -(1702, 'REJANG LEBONG', 17), -(1703, 'BENGKULU UTARA', 17), -(1704, 'KAUR', 17), -(1705, 'SELUMA', 17), -(1706, 'MUKOMUKO', 17), -(1707, 'LEBONG', 17), -(1708, 'KEPAHIANG', 17), -(1709, 'BENGKULU TENGAH', 17), -(1771, 'BENGKULU', 17), -(1801, 'LAMPUNG BARAT', 18), -(1802, 'TANGGAMUS', 18), -(1803, 'LAMPUNG SELATAN', 18), -(1804, 'LAMPUNG TIMUR', 18), -(1805, 'LAMPUNG TENGAH', 18), -(1806, 'LAMPUNG UTARA', 18), -(1807, 'WAY KANAN', 18), -(1808, 'TULANGBAWANG', 18), -(1809, 'PESAWARAN', 18), -(1810, 'PRINGSEWU', 18), -(1811, 'MESUJI', 18), -(1812, 'TULANG BAWANG BARAT', 18), -(1871, 'BANDAR LAMPUNG', 18), -(1872, 'METRO', 18), -(1901, 'BANGKA', 19), -(1902, 'BELITUNG', 19), -(1903, 'BANGKA BARAT', 19), -(1904, 'BANGKA TENGAH', 19), -(1905, 'BANGKA SELATAN', 19), -(1906, 'BELITUNG TIMUR', 19), -(1971, 'PANGKAL PINANG', 19), -(2101, 'KARIMUN', 21), -(2102, 'BINTAN', 21), -(2103, 'NATUNA', 21), -(2104, 'LINGGA', 21), -(2105, 'KEPULAUAN ANAMBAS', 21), -(2171, 'B A T A M', 21), -(2172, 'TANJUNG PINANG', 21), -(3101, 'KEPULAUAN SERIBU', 31), -(3171, 'JAKARTA SELATAN', 31), -(3172, 'JAKARTA TIMUR', 31), -(3173, 'JAKARTA PUSAT', 31), -(3174, 'JAKARTA BARAT', 31), -(3175, 'JAKARTA UTARA', 31), -(3201, 'BOGOR', 32), -(3202, 'SUKABUMI', 32), -(3203, 'CIANJUR', 32), -(3204, 'BANDUNG', 32), -(3205, 'GARUT', 32), -(3206, 'TASIKMALAYA', 32), -(3207, 'CIAMIS', 32), -(3208, 'KUNINGAN', 32), -(3209, 'CIREBON', 32), -(3210, 'MAJALENGKA', 32), -(3211, 'SUMEDANG', 32), -(3212, 'INDRAMAYU', 32), -(3213, 'SUBANG', 32), -(3214, 'PURWAKARTA', 32), -(3215, 'KARAWANG', 32), -(3216, 'BEKASI', 32), -(3217, 'BANDUNG BARAT', 32), -(3271, 'BOGOR', 32), -(3272, 'SUKABUMI', 32), -(3273, 'BANDUNG', 32), -(3274, 'CIREBON', 32), -(3275, 'BEKASI', 32), -(3276, 'DEPOK', 32), -(3277, 'CIMAHI', 32), -(3278, 'TASIKMALAYA', 32), -(3279, 'BANJAR', 32), -(3301, 'CILACAP', 33), -(3302, 'BANYUMAS', 33), -(3303, 'PURBALINGGA', 33), -(3304, 'BANJARNEGARA', 33), -(3305, 'KEBUMEN', 33), -(3306, 'PURWOREJO', 33), -(3307, 'WONOSOBO', 33), -(3308, 'MAGELANG', 33), -(3309, 'BOYOLALI', 33), -(3310, 'KLATEN', 33), -(3311, 'SUKOHARJO', 33), -(3312, 'WONOGIRI', 33), -(3313, 'KARANGANYAR', 33), -(3314, 'SRAGEN', 33), -(3315, 'GROBOGAN', 33), -(3316, 'BLORA', 33), -(3317, 'REMBANG', 33), -(3318, 'PATI', 33), -(3319, 'KUDUS', 33), -(3320, 'JEPARA', 33), -(3321, 'DEMAK', 33), -(3322, 'SEMARANG', 33), -(3323, 'TEMANGGUNG', 33), -(3324, 'KENDAL', 33), -(3325, 'BATANG', 33), -(3326, 'PEKALONGAN', 33), -(3327, 'PEMALANG', 33), -(3328, 'TEGAL', 33), -(3329, 'BREBES', 33), -(3371, 'MAGELANG', 33), -(3372, 'SURAKARTA', 33), -(3373, 'SALATIGA', 33), -(3374, 'SEMARANG', 33), -(3375, 'PEKALONGAN', 33), -(3376, 'TEGAL', 33), -(3401, 'KULON PROGO', 34), -(3402, 'BANTUL', 34), -(3403, 'GUNUNG KIDUL', 34), -(3404, 'SLEMAN', 34), -(3471, 'YOGYAKARTA', 34), -(3501, 'PACITAN', 35), -(3502, 'PONOROGO', 35), -(3503, 'TRENGGALEK', 35), -(3504, 'TULUNGAGUNG', 35), -(3505, 'BLITAR', 35), -(3506, 'KEDIRI', 35), -(3507, 'MALANG', 35), -(3508, 'LUMAJANG', 35), -(3509, 'JEMBER', 35), -(3510, 'BANYUWANGI', 35), -(3511, 'BONDOWOSO', 35), -(3512, 'SITUBONDO', 35), -(3513, 'PROBOLINGGO', 35), -(3514, 'PASURUAN', 35), -(3515, 'SIDOARJO', 35), -(3516, 'MOJOKERTO', 35), -(3517, 'JOMBANG', 35), -(3518, 'NGANJUK', 35), -(3519, 'MADIUN', 35), -(3520, 'MAGETAN', 35), -(3521, 'NGAWI', 35), -(3522, 'BOJONEGORO', 35), -(3523, 'TUBAN', 35), -(3524, 'LAMONGAN', 35), -(3525, 'GRESIK', 35), -(3526, 'BANGKALAN', 35), -(3527, 'SAMPANG', 35), -(3528, 'PAMEKASAN', 35), -(3529, 'SUMENEP', 35), -(3571, 'KEDIRI', 35), -(3572, 'BLITAR', 35), -(3573, 'MALANG', 35), -(3574, 'PROBOLINGGO', 35), -(3575, 'PASURUAN', 35), -(3576, 'MOJOKERTO', 35), -(3577, 'MADIUN', 35), -(3578, 'SURABAYA', 35), -(3579, 'BATU', 35), -(3601, 'PANDEGLANG', 36), -(3602, 'LEBAK', 36), -(3603, 'TANGERANG', 36), -(3604, 'SERANG', 36), -(3671, 'TANGERANG', 36), -(3672, 'CILEGON', 36), -(3673, 'SERANG', 36), -(3674, 'TANGERANG SELATAN', 36), -(5101, 'JEMBRANA', 51), -(5102, 'TABANAN', 51), -(5103, 'BADUNG', 51), -(5104, 'GIANYAR', 51), -(5105, 'KLUNGKUNG', 51), -(5106, 'BANGLI', 51), -(5107, 'KARANG ASEM', 51), -(5108, 'BULELENG', 51), -(5171, 'DENPASAR', 51), -(5201, 'LOMBOK BARAT', 52), -(5202, 'LOMBOK TENGAH', 52), -(5203, 'LOMBOK TIMUR', 52), -(5204, 'SUMBAWA', 52), -(5205, 'DOMPU', 52), -(5206, 'BIMA', 52), -(5207, 'SUMBAWA BARAT', 52), -(5208, 'LOMBOK UTARA', 52), -(5271, 'MATARAM', 52), -(5272, 'BIMA', 52), -(5301, 'SUMBA BARAT', 53), -(5302, 'SUMBA TIMUR', 53), -(5303, 'KUPANG', 53), -(5304, 'TIMOR TENGAH SELATAN', 53), -(5305, 'TIMOR TENGAH UTARA', 53), -(5306, 'BELU', 53), -(5307, 'ALOR', 53), -(5308, 'LEMBATA', 53), -(5309, 'FLORES TIMUR', 53), -(5310, 'SIKKA', 53), -(5311, 'ENDE', 53), -(5312, 'NGADA', 53), -(5313, 'MANGGARAI', 53), -(5314, 'ROTE NDAO', 53), -(5315, 'MANGGARAI BARAT', 53), -(5316, 'SUMBA TENGAH', 53), -(5317, 'SUMBA BARAT DAYA', 53), -(5318, 'NAGEKEO', 53), -(5319, 'MANGGARAI TIMUR', 53), -(5320, 'SABU RAIJUA', 53), -(5371, 'KUPANG', 53), -(6101, 'SAMBAS', 61), -(6102, 'BENGKAYANG', 61), -(6103, 'LANDAK', 61), -(6104, 'PONTIANAK', 61), -(6105, 'SANGGAU', 61), -(6106, 'KETAPANG', 61), -(6107, 'SINTANG', 61), -(6108, 'KAPUAS HULU', 61), -(6109, 'SEKADAU', 61), -(6110, 'MELAWI', 61), -(6111, 'KAYONG UTARA', 61), -(6112, 'KUBU RAYA', 61), -(6171, 'PONTIANAK', 61), -(6172, 'SINGKAWANG', 61), -(6201, 'KOTAWARINGIN BARAT', 62), -(6202, 'KOTAWARINGIN TIMUR', 62), -(6203, 'KAPUAS', 62), -(6204, 'BARITO SELATAN', 62), -(6205, 'BARITO UTARA', 62), -(6206, 'SUKAMARA', 62), -(6207, 'LAMANDAU', 62), -(6208, 'SERUYAN', 62), -(6209, 'KATINGAN', 62), -(6210, 'PULANG PISAU', 62), -(6211, 'GUNUNG MAS', 62), -(6212, 'BARITO TIMUR', 62), -(6213, 'MURUNG RAYA', 62), -(6271, 'PALANGKA RAYA', 62), -(6301, 'TANAH LAUT', 63), -(6302, 'KOTA BARU', 63), -(6303, 'BANJAR', 63), -(6304, 'BARITO KUALA', 63), -(6305, 'TAPIN', 63), -(6306, 'HULU SUNGAI SELATAN', 63), -(6307, 'HULU SUNGAI TENGAH', 63), -(6308, 'HULU SUNGAI UTARA', 63), -(6309, 'TABALONG', 63), -(6310, 'TANAH BUMBU', 63), -(6311, 'BALANGAN', 63), -(6371, 'BANJARMASIN', 63), -(6372, 'BANJAR BARU', 63), -(6401, 'PASER', 64), -(6402, 'KUTAI BARAT', 64), -(6403, 'KUTAI KARTANEGARA', 64), -(6404, 'KUTAI TIMUR', 64), -(6405, 'BERAU', 64), -(6406, 'MALINAU', 64), -(6407, 'BULUNGAN', 64), -(6408, 'NUNUKAN', 64), -(6409, 'PENAJAM PASER UTARA', 64), -(6410, 'TANA TIDUNG', 64), -(6471, 'BALIKPAPAN', 64), -(6472, 'SAMARINDA', 64), -(6473, 'TARAKAN', 64), -(6474, 'BONTANG', 64), -(7101, 'BOLAANG MONGONDOW', 71), -(7102, 'MINAHASA', 71), -(7103, 'KEPULAUAN SANGIHE', 71), -(7104, 'KEPULAUAN TALAUD', 71), -(7105, 'MINAHASA SELATAN', 71), -(7106, 'MINAHASA UTARA', 71), -(7107, 'BOLAANG MONGONDOW UTARA', 71), -(7108, 'SIAU TAGULANDANG BIARO', 71), -(7109, 'MINAHASA TENGGARA', 71), -(7110, 'BOLAANG MONGONDOW SELATAN', 71), -(7111, 'BOLAANG MONGONDOW TIMUR', 71), -(7171, 'MANADO', 71), -(7172, 'BITUNG', 71), -(7173, 'TOMOHON', 71), -(7174, 'KOTAMOBAGU', 71), -(7201, 'BANGGAI KEPULAUAN', 72), -(7202, 'BANGGAI', 72), -(7203, 'MOROWALI', 72), -(7204, 'POSO', 72), -(7205, 'DONGGALA', 72), -(7206, 'TOLI-TOLI', 72), -(7207, 'BUOL', 72), -(7208, 'PARIGI MOUTONG', 72), -(7209, 'TOJO UNA-UNA', 72), -(7210, 'SIGI', 72), -(7271, 'PALU', 72), -(7301, 'SELAYAR', 73), -(7302, 'BULUKUMBA', 73), -(7303, 'BANTAENG', 73), -(7304, 'JENEPONTO', 73), -(7305, 'TAKALAR', 73), -(7306, 'GOWA', 73), -(7307, 'SINJAI', 73), -(7308, 'MAROS', 73), -(7309, 'PANGKAJENE DAN KEPULAUAN', 73), -(7310, 'BARRU', 73), -(7311, 'BONE', 73), -(7312, 'SOPPENG', 73), -(7313, 'WAJO', 73), -(7314, 'SIDENRENG RAPPANG', 73), -(7315, 'PINRANG', 73), -(7316, 'ENREKANG', 73), -(7317, 'LUWU', 73), -(7318, 'TANA TORAJA', 73), -(7322, 'LUWU UTARA', 73), -(7325, 'LUWU TIMUR', 73), -(7326, 'TORAJA UTARA', 73), -(7371, 'MAKASSAR', 73), -(7372, 'PARE-PARE', 73), -(7373, 'PALOPO', 73), -(7401, 'BUTON', 74), -(7402, 'MUNA', 74), -(7403, 'KONAWE', 74), -(7404, 'KOLAKA', 74), -(7405, 'KONAWE SELATAN', 74), -(7406, 'BOMBANA', 74), -(7407, 'WAKATOBI', 74), -(7408, 'KOLAKA UTARA', 74), -(7409, 'BUTON UTARA', 74), -(7410, 'KONAWE UTARA', 74), -(7471, 'KENDARI', 74), -(7472, 'BAU-BAU', 74), -(7501, 'BOALEMO', 75), -(7502, 'GORONTALO', 75), -(7503, 'POHUWATO', 75), -(7504, 'BONE BOLANGO', 75), -(7505, 'GORONTALO UTARA', 75), -(7571, 'GORONTALO', 75), -(7601, 'MAJENE', 76), -(7602, 'POLEWALI MANDAR', 76), -(7603, 'MAMASA', 76), -(7604, 'MAMUJU', 76), -(7605, 'MAMUJU UTARA', 76), -(8101, 'MALUKU TENGGARA BARAT', 81), -(8102, 'MALUKU TENGGARA', 81), -(8103, 'MALUKU TENGAH', 81), -(8104, 'BURU', 81), -(8105, 'KEPULAUAN ARU', 81), -(8106, 'SERAM BAGIAN BARAT', 81), -(8107, 'SERAM BAGIAN TIMUR', 81), -(8108, 'MALUKU BARAT DAYA', 81), -(8109, 'BURU SELATAN', 81), -(8171, 'AMBON', 81), -(8172, 'TUAL', 81), -(8201, 'HALMAHERA BARAT', 82), -(8202, 'HALMAHERA TENGAH', 82), -(8203, 'KEPULAUAN SULA', 82), -(8204, 'HALMAHERA SELATAN', 82), -(8205, 'HALMAHERA UTARA', 82), -(8206, 'HALMAHERA TIMUR', 82), -(8207, 'PULAU MOROTAI', 82), -(8271, 'TERNATE', 82), -(8272, 'TIDORE KEPULAUAN', 82), -(9101, 'FAKFAK', 91), -(9102, 'KAIMANA', 91), -(9103, 'TELUK WONDAMA', 91), -(9104, 'TELUK BINTUNI', 91), -(9105, 'MANOKWARI', 91), -(9106, 'SORONG SELATAN', 91), -(9107, 'SORONG', 91), -(9108, 'RAJA AMPAT', 91), -(9109, 'TAMBRAUW', 91), -(9110, 'MAYBRAT', 91), -(9171, 'SORONG', 91), -(9401, 'MERAUKE', 94), -(9402, 'JAYAWIJAYA', 94), -(9403, 'JAYAPURA', 94), -(9404, 'NABIRE', 94), -(9408, 'KEPULAUAN YAPEN', 94), -(9409, 'BIAK NUMFOR', 94), -(9410, 'PANIAI', 94), -(9411, 'PUNCAK JAYA', 94), -(9412, 'MIMIKA', 94), -(9413, 'BOVEN DIGOEL', 94), -(9414, 'MAPPI', 94), -(9415, 'ASMAT', 94), -(9416, 'YAHUKIMO', 94), -(9417, 'PEGUNUNGAN BINTANG', 94), -(9418, 'TOLIKARA', 94), -(9419, 'SARMI', 94), -(9420, 'KEEROM', 94), -(9426, 'WAROPEN', 94), -(9427, 'SUPIORI', 94), -(9428, 'MAMBERAMO RAYA', 94), -(9429, 'NDUGA', 94), -(9430, 'LANNY JAYA', 94), -(9431, 'MAMBERAMO TENGAH', 94), -(9432, 'YALIMO', 94), -(9433, 'PUNCAK', 94), -(9434, 'DOGIYAI', 94), -(9435, 'INTAN JAYA', 94), -(9436, 'DEIYAI', 94), -(9471, 'JAYAPURA', 94); - --- -------------------------------------------------------- - --- --- Table structure for table `kecamatan` --- - -CREATE TABLE IF NOT EXISTS `kecamatan` ( - `kodeBps` int(11) NOT NULL, - `namaKecamatan` varchar(50) COLLATE latin1_general_ci NOT NULL, - `kodeKabupaten` int(11) NOT NULL, - PRIMARY KEY (`kodeBps`), - UNIQUE KEY `kodeBps` (`kodeBps`), - KEY `kodeKabupaten` (`kodeKabupaten`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; - --- --- Dumping data for table `kecamatan` --- - -INSERT INTO `kecamatan` (`kodeBps`, `namaKecamatan`, `kodeKabupaten`) VALUES -(1101010, 'TEUPAH SELATAN', 1101), -(1101020, 'SIMEULUE TIMUR', 1101), -(1101021, 'TEUPAH BARAT', 1101), -(1101030, 'SIMEULUE TENGAH', 1101), -(1101031, 'TELUK DALAM', 1101), -(1101040, 'SALANG', 1101), -(1101050, 'SIMEULUE BARAT', 1101), -(1101051, 'ALAFAN', 1101), -(1102010, 'PULAU BANYAK', 1102), -(1102011, 'PULAU BANYAK BARAT', 1102), -(1102020, 'SINGKIL', 1102), -(1102021, 'SINGKIL UTARA', 1102), -(1102022, 'KUALA BARU', 1102), -(1102030, 'SIMPANG KANAN', 1102), -(1102031, 'GUNUNG MERIAH', 1102), -(1102032, 'DANAU PARIS', 1102), -(1102033, 'SURO', 1102), -(1102042, 'SINGKOHOR', 1102), -(1102043, 'KOTA BAHARU', 1102), -(1103010, 'TRUMON', 1103), -(1103011, 'TRUMON TIMUR', 1103), -(1103012, 'TRUMON TENGAH', 1103), -(1103020, 'BAKONGAN', 1103), -(1103021, 'BAKONGAN TIMUR', 1103), -(1103022, 'KOTA BAHAGIA', 1103), -(1103030, 'KLUET SELATAN', 1103), -(1103031, 'KLUET TIMUR', 1103), -(1103040, 'KLUET UTARA', 1103), -(1103041, 'PASIE RAJA', 1103), -(1103042, 'KLUET TENGAH', 1103), -(1103050, 'TAPAK TUAN', 1103), -(1103060, 'SAMA DUA', 1103), -(1103070, 'SAWANG', 1103), -(1103080, 'MEUKEK', 1103), -(1103090, 'LABUHAN HAJI', 1103), -(1103091, 'LABUHAN HAJI TIMUR', 1103), -(1103092, 'LABUHAN HAJI BARAT', 1103), -(1104010, 'LAWE ALAS', 1104), -(1104011, 'BABUL RAHMAD', 1104), -(1104012, 'TANOH ALAS', 1104), -(1104020, 'LAWE SIGALA-GALA', 1104), -(1104021, 'BABUL MAKMUR', 1104), -(1104022, 'SEMADAM', 1104), -(1104023, 'LAUSER', 1104), -(1104030, 'BAMBEL', 1104), -(1104031, 'BUKIT TUSAM', 1104), -(1104032, 'LAWE SUMUR', 1104), -(1104040, 'BABUSSALAM', 1104), -(1104041, 'LAWE BULAN', 1104), -(1104050, 'BADAR', 1104), -(1104051, 'DARUL HASANAH', 1104), -(1104052, 'KETAMBE', 1104), -(1104053, 'DELENG POKHKISEN', 1104), -(1105080, 'SERBA JADI', 1105), -(1105081, 'SIMPANG JERNIH', 1105), -(1105082, 'PEUNARON', 1105), -(1105090, 'BIREM BAYEUN', 1105), -(1105100, 'RANTAU SELAMAT', 1105), -(1105101, 'SUNGAI RAYA', 1105), -(1105110, 'PEUREULAK', 1105), -(1105111, 'PEUREULAK TIMUR', 1105), -(1105112, 'PEUREULAK BARAT', 1105), -(1105120, 'RANTO PEUREULAK', 1105), -(1105130, 'IDI RAYEUK', 1105), -(1105131, 'PEUDAWA', 1105), -(1105132, 'BANDA ALAM', 1105), -(1105133, 'IDI TUNONG', 1105), -(1105134, 'DARUL IHSAN', 1105), -(1105135, 'IDI TIMUR', 1105), -(1105140, 'DARUL AMAN', 1105), -(1105150, 'NURUSSALAM', 1105), -(1105151, 'DARUL FALAH', 1105), -(1105160, 'JULOK', 1105), -(1105161, 'INDRA MAKMUR', 1105), -(1105170, 'PANTE BIDARI', 1105), -(1105180, 'SIMPANG ULIM', 1105), -(1105181, 'MADAT', 1105), -(1106010, 'LINGE', 1106), -(1106011, 'ATU LINTANG', 1106), -(1106012, 'JAGONG JEGET', 1106), -(1106020, 'BINTANG', 1106), -(1106031, 'LUT TAWAR', 1106), -(1106032, 'KEBAYAKAN', 1106), -(1106040, 'PEGASING', 1106), -(1106041, 'BIES', 1106), -(1106050, 'BEBESEN', 1106), -(1106051, 'KUTE PANANG', 1106), -(1106060, 'SILIH NARA', 1106), -(1106061, 'KETOL', 1106), -(1106062, 'CELALA', 1106), -(1106063, 'RUSIP ANTARA', 1106), -(1107050, 'JOHAN PAHLAWAN', 1107), -(1107060, 'SAMATIGA', 1107), -(1107061, 'BUBON', 1107), -(1107062, 'ARONGAN LAMBALEK', 1107), -(1107070, 'WOYLA', 1107), -(1107071, 'WOYLA BARAT', 1107), -(1107072, 'WOYLA TIMUR', 1107), -(1107080, 'KAWAY XVI', 1107), -(1107081, 'MEUREUBO', 1107), -(1107082, 'PANTAI CEUREMEN', 1107), -(1107083, 'PANTON REU', 1107), -(1107090, 'SUNGAI MAS', 1107), -(1108010, 'LHOONG', 1108), -(1108020, 'LHOKNGA', 1108), -(1108021, 'LEUPUNG', 1108), -(1108030, 'INDRAPURI', 1108), -(1108031, 'KUTA COT GLIE', 1108), -(1108040, 'SEULIMEUM', 1108), -(1108041, 'KOTA JANTHO', 1108), -(1108042, 'LEMBAH SEULAWAH', 1108), -(1108050, 'MESJID RAYA', 1108), -(1108060, 'DARUSSALAM', 1108), -(1108061, 'BAITUSSALAM', 1108), -(1108070, 'KUTA BARO', 1108), -(1108080, 'MONTASIK', 1108), -(1108081, 'BLANG BINTANG', 1108), -(1108090, 'INGIN JAYA', 1108), -(1108091, 'KRUENG BARONA JAYA', 1108), -(1108100, 'SUKA MAKMUR', 1108), -(1108101, 'KUTA MALAKA', 1108), -(1108102, 'SIMPANG TIGA', 1108), -(1108110, 'DARUL IMARAH', 1108), -(1108111, 'DARUL KAMAL', 1108), -(1108120, 'PEUKAN BADA', 1108), -(1108130, 'PULO ACEH', 1108), -(1109010, 'GEUMPANG', 1109), -(1109011, 'MANE', 1109), -(1109070, 'GLUMPANG TIGA', 1109), -(1109071, 'GLUMPANG BARO', 1109), -(1109080, 'MUTIARA', 1109), -(1109081, 'MUTIARA TIMUR', 1109), -(1109090, 'TIRO/TRUSEB', 1109), -(1109100, 'TANGSE', 1109), -(1109111, 'KEUMALA', 1109), -(1109112, 'TITEUE', 1109), -(1109120, 'SAKTI', 1109), -(1109130, 'MILA', 1109), -(1109140, 'PADANG TIJI', 1109), -(1109150, 'DELIMA', 1109), -(1109151, 'GRONG GRONG', 1109), -(1109160, 'INDRAJAYA', 1109), -(1109170, 'PEUKAN BARO', 1109), -(1109180, 'KEMBANG TANJONG', 1109), -(1109190, 'SIMPANG TIGA', 1109), -(1109200, 'KOTA SIGLI', 1109), -(1109210, 'PIDIE', 1109), -(1109220, 'BATEE', 1109), -(1109230, 'MUARA TIGA', 1109), -(1110010, 'SAMALANGA', 1110), -(1110011, 'SIMPANG MAMPLAM', 1110), -(1110020, 'PANDRAH', 1110), -(1110030, 'JEUNIEB', 1110), -(1110031, 'PEULIMBANG', 1110), -(1110040, 'PEUDADA', 1110), -(1110050, 'JULI', 1110), -(1110060, 'JEUMPA', 1110), -(1110061, 'KOTA JUANG', 1110), -(1110062, 'KUALA', 1110), -(1110070, 'JANGKA', 1110), -(1110080, 'PEUSANGAN', 1110), -(1110081, 'PEUSANGAN SELATAN', 1110), -(1110082, 'PEUSANGAN SIBLAH KRUENG', 1110), -(1110090, 'MAKMUR', 1110), -(1110100, 'GANDA PURA', 1110), -(1110101, 'KUTA BLANG', 1110), -(1111010, 'SAWANG', 1111), -(1111020, 'NISAM', 1111), -(1111021, 'NISAM ANTARA', 1111), -(1111022, 'BANDA BARO', 1111), -(1111030, 'KUTA MAKMUR', 1111), -(1111031, 'SIMPANG KERAMAT', 1111), -(1111040, 'SYAMTALIRA BAYU', 1111), -(1111041, 'GEUREUDONG PASE', 1111), -(1111050, 'MEURAH MULIA', 1111), -(1111060, 'MATANGKULI', 1111), -(1111061, 'PAYA BAKONG', 1111), -(1111062, 'PIRAK TIMU', 1111), -(1111070, 'COT GIREK', 1111), -(1111080, 'TANAH JAMBO AYE', 1111), -(1111081, 'LANGKAHAN', 1111), -(1111090, 'SEUNUDON', 1111), -(1111100, 'BAKTIYA', 1111), -(1111101, 'BAKTIYA BARAT', 1111), -(1111110, 'LHOKSUKON', 1111), -(1111120, 'TANAH LUAS', 1111), -(1111121, 'NIBONG', 1111), -(1111130, 'SAMUDERA', 1111), -(1111140, 'SYAMTALIRA ARON', 1111), -(1111150, 'TANAH PASIR', 1111), -(1111151, 'LAPANG', 1111), -(1111160, 'MUARA BATU', 1111), -(1111170, 'DEWANTARA', 1111), -(1112010, 'MANGGENG', 1112), -(1112011, 'LEMBAH SABIL', 1112), -(1112020, 'TANGAN-TANGAN', 1112), -(1112021, 'SETIA', 1112), -(1112030, 'BLANG PIDIE', 1112), -(1112031, 'JEUMPA', 1112), -(1112040, 'SUSOH', 1112), -(1112050, 'KUALA BATEE', 1112), -(1112060, 'BABAH ROT', 1112), -(1113010, 'KUTA PANJANG', 1113), -(1113011, 'BLANG JERANGO', 1113), -(1113020, 'BLANGKEJEREN', 1113), -(1113021, 'PUTRI BETUNG', 1113), -(1113022, 'DABUN GELANG', 1113), -(1113023, 'BLANG PEGAYON', 1113), -(1113030, 'PINING', 1113), -(1113040, 'RIKIT GAIB', 1113), -(1113041, 'PANTAN CUACA', 1113), -(1113050, 'TERANGUN', 1113), -(1113051, 'TRIPE JAYA', 1113), -(1114010, 'TAMIANG HULU', 1114), -(1114011, 'BANDAR PUSAKA', 1114), -(1114020, 'KEJURUAN MUDA', 1114), -(1114021, 'TENGGULUN', 1114), -(1114030, 'RANTAU', 1114), -(1114040, 'KOTA KUALA SIMPANG', 1114), -(1114050, 'SEURUWAY', 1114), -(1114060, 'BENDAHARA', 1114), -(1114061, 'BANDA MULIA', 1114), -(1114070, 'KARANG BARU', 1114), -(1114071, 'SEKERAK', 1114), -(1114080, 'MANYAK PAYED', 1114), -(1115010, 'DARUL MAKMUR', 1115), -(1115011, 'TRIPA MAKMUR', 1115), -(1115020, 'KUALA', 1115), -(1115021, 'KUALA PESISIR', 1115), -(1115022, 'TADU RAYA', 1115), -(1115030, 'BEUTONG', 1115), -(1115031, 'BEUTONG ATEUH BANGGALANG', 1115), -(1115040, 'SEUNAGAN', 1115), -(1115041, 'SUKA MAKMUE', 1115), -(1115050, 'SEUNAGAN TIMUR', 1115), -(1116010, 'TEUNOM', 1116), -(1116020, 'PANGA', 1116), -(1116030, 'KRUENG SABEE', 1116), -(1116040, 'SETIA BAKTI', 1116), -(1116050, 'SAMPOINIET', 1116), -(1116060, 'JAYA', 1116), -(1117010, 'TIMANG GAJAH', 1117), -(1117011, 'GAJAH PUTIH', 1117), -(1117020, 'PINTU RIME GAYO', 1117), -(1117030, 'BUKIT', 1117), -(1117040, 'WIH PESAM', 1117), -(1117050, 'BANDAR', 1117), -(1117051, 'BENER KELIPAH', 1117), -(1117060, 'SYIAH UTAMA', 1117), -(1117061, 'MESIDAH', 1117), -(1117070, 'PERMATA', 1117), -(1118010, 'MEUREUDU', 1118), -(1118020, 'MEURAH DUA', 1118), -(1118030, 'BANDAR DUA', 1118), -(1118040, 'JANGKA BUYA', 1118), -(1118050, 'ULIM', 1118), -(1118060, 'TRIENGGADENG', 1118), -(1118070, 'PANTERAJA', 1118), -(1118080, 'BANDAR BARU', 1118), -(1171010, 'MEURAXA', 1171), -(1171011, 'JAYA BARU', 1171), -(1171012, 'BANDA RAYA', 1171), -(1171020, 'BAITURRAHMAN', 1171), -(1171021, 'LUENG BATA', 1171), -(1171030, 'KUTA ALAM', 1171), -(1171031, 'KUTA RAJA', 1171), -(1171040, 'SYIAH KUALA', 1171), -(1171041, 'ULEE KARENG', 1171), -(1172010, 'SUKAJAYA', 1172), -(1172020, 'SUKAKARYA', 1172), -(1173010, 'LANGSA TIMUR', 1173), -(1173011, 'LANGSA LAMA', 1173), -(1173020, 'LANGSA BARAT', 1173), -(1173021, 'LANGSA BARO', 1173), -(1173030, 'LANGSA KOTA', 1173), -(1174010, 'BLANG MANGAT', 1174), -(1174020, 'MUARA DUA', 1174), -(1174021, 'MUARA SATU', 1174), -(1174030, 'BANDA SAKTI', 1174), -(1175010, 'SIMPANG KIRI', 1175), -(1175020, 'PENANGGALAN', 1175), -(1175030, 'RUNDENG', 1175), -(1175040, 'SULTAN DAULAT', 1175), -(1175050, 'LONGKIB', 1175), -(1201060, 'IDANO GAWO', 1201), -(1201061, 'BAWOLATO', 1201), -(1201062, 'ULUGAWO', 1201), -(1201070, 'GIDO', 1201), -(1201081, 'MA U', 1201), -(1201082, 'SOMOLO - MOLO', 1201), -(1201130, 'HILIDUHO', 1201), -(1201131, 'HILI SERANGKAI', 1201), -(1201132, 'BOTOMUZOI', 1201), -(1202010, 'BATAHAN', 1202), -(1202011, 'SINUNUKAN', 1202), -(1202020, 'BATANG NATAL', 1202), -(1202021, 'LINGGA BAYU', 1202), -(1202022, 'RANTO BAEK', 1202), -(1202030, 'KOTANOPAN', 1202), -(1202031, 'ULU PUNGKUT', 1202), -(1202032, 'TAMBANGAN', 1202), -(1202033, 'LEMBAH SORIK MARAPI', 1202), -(1202034, 'PUNCAK SORIK MARAPI', 1202), -(1202040, 'MUARA SIPONGI', 1202), -(1202041, 'PAKANTAN', 1202), -(1202050, 'PANYABUNGAN', 1202), -(1202051, 'PANYABUNGAN SELATAN', 1202), -(1202052, 'PANYABUNGAN BARAT', 1202), -(1202053, 'PANYABUNGAN UTARA', 1202), -(1202054, 'PANYABUNGAN TIMUR', 1202), -(1202055, 'HUTA BARGOT', 1202), -(1202060, 'NATAL', 1202), -(1202070, 'MUARA BATANG GADIS', 1202), -(1202080, 'SIABU', 1202), -(1202081, 'BUKIT MALINTANG', 1202), -(1202082, 'NAGA JUANG', 1202), -(1203010, 'BATANG ANGKOLA', 1203), -(1203011, 'SAYUR MATINGGI', 1203), -(1203012, 'TANO TOMBANGAN ANGKOLA', 1203), -(1203070, 'ANGKOLA TIMUR', 1203), -(1203080, 'ANGKOLA SELATAN', 1203), -(1203090, 'ANGKOLA BARAT', 1203), -(1203091, 'ANGKOLA SANGKUNUR', 1203), -(1203100, 'BATANG TORU', 1203), -(1203101, 'MARANCAR', 1203), -(1203102, 'MUARA BATANG TORU', 1203), -(1203110, 'SIPIROK', 1203), -(1203120, 'ARSE', 1203), -(1203160, 'SAIPAR DOLOK HOLE', 1203), -(1203161, 'AEK BILAH', 1203), -(1204010, 'PINANG SORI', 1204), -(1204011, 'BADIRI', 1204), -(1204020, 'SIBABANGUN', 1204), -(1204021, 'LUMUT', 1204), -(1204022, 'SUKABANGUN', 1204), -(1204030, 'PANDAN', 1204), -(1204031, 'TUKKA', 1204), -(1204032, 'SARUDIK', 1204), -(1204040, 'TAPIAN NAULI', 1204), -(1204041, 'SITAHUIS', 1204), -(1204050, 'KOLANG', 1204), -(1204060, 'SORKAM', 1204), -(1204061, 'SORKAM BARAT', 1204), -(1204062, 'PASARIBU TOBING', 1204), -(1204070, 'BARUS', 1204), -(1204071, 'SOSOR GADONG', 1204), -(1204072, 'ANDAM DEWI', 1204), -(1204073, 'BARUS UTARA', 1204), -(1204080, 'MANDUAMAS', 1204), -(1204081, 'SIRANDORUNG', 1204), -(1205030, 'PARMONANGAN', 1205), -(1205040, 'ADIAN KOTING', 1205), -(1205050, 'SIPOHOLON', 1205), -(1205060, 'TARUTUNG', 1205), -(1205061, 'SIATAS BARITA', 1205), -(1205070, 'PAHAE JULU', 1205), -(1205080, 'PAHAE JAE', 1205), -(1205081, 'PURBATUA', 1205), -(1205082, 'SIMANGUMBAN', 1205), -(1205090, 'PANGARIBUAN', 1205), -(1205100, 'GAROGA', 1205), -(1205110, 'SIPAHUTAR', 1205), -(1205120, 'SIBORONG-BORONG', 1205), -(1205130, 'PAGARAN', 1205), -(1205180, 'MUARA', 1205), -(1206030, 'BALIGE', 1206), -(1206031, 'TAMPAHAN', 1206), -(1206040, 'LAGUBOTI', 1206), -(1206050, 'HABINSARAN', 1206), -(1206051, 'BORBOR', 1206), -(1206052, 'NASSAU', 1206), -(1206060, 'SILAEN', 1206), -(1206061, 'SIGUMPAR', 1206), -(1206070, 'PORSEA', 1206), -(1206071, 'PINTU POHAN MERANTI', 1206), -(1206072, 'SIANTAR NARUMONDA', 1206), -(1206073, 'PARMAKSIAN', 1206), -(1206080, 'LUMBAN JULU', 1206), -(1206081, 'ULUAN', 1206), -(1206082, 'AJIBATA', 1206), -(1206083, 'BONATUA LUNASI', 1206), -(1207050, 'BILAH HULU', 1207), -(1207070, 'PANGKATAN', 1207), -(1207080, 'BILAH BARAT', 1207), -(1207130, 'BILAH HILIR', 1207), -(1207140, 'PANAI HULU', 1207), -(1207150, 'PANAI TENGAH', 1207), -(1207160, 'PANAI HILIR', 1207), -(1207210, 'RANTAU SELATAN', 1207), -(1207220, 'RANTAU UTARA', 1207), -(1208010, 'BANDAR PASIR MANDOGE', 1208), -(1208020, 'BANDAR PULAU', 1208), -(1208021, 'AEK SONGSONGAN', 1208), -(1208022, 'RAHUNING', 1208), -(1208030, 'PULAU RAKYAT', 1208), -(1208031, 'AEK KUASAN', 1208), -(1208032, 'AEK LEDONG', 1208), -(1208040, 'SEI KEPAYANG', 1208), -(1208041, 'SEI KEPAYANG BARAT', 1208), -(1208042, 'SEI KEPAYANG TIMUR', 1208), -(1208050, 'TANJUNG BALAI', 1208), -(1208060, 'SIMPANG EMPAT', 1208), -(1208061, 'TELUK DALAM', 1208), -(1208070, 'AIR BATU', 1208), -(1208071, 'SEI DADAP', 1208), -(1208080, 'BUNTU PANE', 1208), -(1208081, 'TINGGI RAJA', 1208), -(1208082, 'SETIA JANJI', 1208), -(1208090, 'MERANTI', 1208), -(1208091, 'PULO BANDRING', 1208), -(1208092, 'RAWANG PANCA ARGA', 1208), -(1208100, 'AIR JOMAN', 1208), -(1208101, 'SILAU LAUT', 1208), -(1208160, 'KISARAN BARAT', 1208), -(1208170, 'KISARAN TIMUR', 1208), -(1209010, 'SILIMAKUTA', 1209), -(1209011, 'PEMATANG SILIMAHUTA', 1209), -(1209020, 'PURBA', 1209), -(1209021, 'HARANGGAOL HORISON', 1209), -(1209030, 'DOLOK PARDAMEAN', 1209), -(1209040, 'SIDAMANIK', 1209), -(1209041, 'PEMATANG SIDAMANIK', 1209), -(1209050, 'GIRSANG SIPANGAN BOLON', 1209), -(1209060, 'TANAH JAWA', 1209), -(1209061, 'HATONDUHAN', 1209), -(1209070, 'DOLOK PANRIBUAN', 1209), -(1209080, 'JORLANG HATARAN', 1209), -(1209090, 'PANEI', 1209), -(1209091, 'PANOMBEAN PANEI', 1209), -(1209100, 'RAYA', 1209), -(1209110, 'DOLOK SILAU', 1209), -(1209120, 'SILAU KAHEAN', 1209), -(1209130, 'RAYA KAHEAN', 1209), -(1209140, 'TAPIAN DOLOK', 1209), -(1209150, 'DOLOK BATU NANGGAR', 1209), -(1209160, 'SIANTAR', 1209), -(1209161, 'GUNUNG MALELA', 1209), -(1209162, 'GUNUNG MALIGAS', 1209), -(1209170, 'HUTABAYU RAJA', 1209), -(1209171, 'JAWA MARAJA BAH JAMBI', 1209), -(1209180, 'PEMATANG BANDAR', 1209), -(1209181, 'BANDAR HULUAN', 1209), -(1209190, 'BANDAR', 1209), -(1209191, 'BANDAR MASILAM', 1209), -(1209200, 'BOSAR MALIGAS', 1209), -(1209210, 'UJUNG PADANG', 1209), -(1210030, 'SIDIKALANG', 1210), -(1210031, 'BERAMPU', 1210), -(1210032, 'SITINJO', 1210), -(1210040, 'PARBULUAN', 1210), -(1210050, 'SUMBUL', 1210), -(1210051, 'SILAHI SABUNGAN', 1210), -(1210060, 'SILIMA PUNGGA-PUNGGA', 1210), -(1210061, 'LAE PARIRA', 1210), -(1210070, 'SIEMPAT NEMPU', 1210), -(1210080, 'SIEMPAT NEMPU HULU', 1210), -(1210090, 'SIEMPAT NEMPU HILIR', 1210), -(1210100, 'TIGA LINGGA', 1210), -(1210101, 'GUNUNG SITEMBER', 1210), -(1210110, 'PEGAGAN HILIR', 1210), -(1210120, 'TANAH PINEM', 1210), -(1211010, 'MARDINGDING', 1211), -(1211020, 'LAUBALENG', 1211), -(1211030, 'TIGA BINANGA', 1211), -(1211040, 'JUHAR', 1211), -(1211050, 'MUNTE', 1211), -(1211060, 'KUTA BULUH', 1211), -(1211070, 'PAYUNG', 1211), -(1211071, 'TIGANDERKET', 1211), -(1211080, 'SIMPANG EMPAT', 1211), -(1211081, 'NAMAN TERAN', 1211), -(1211082, 'MERDEKA', 1211), -(1211090, 'KABANJAHE', 1211), -(1211100, 'BERASTAGI', 1211), -(1211110, 'TIGAPANAH', 1211), -(1211111, 'DOLAT RAYAT', 1211), -(1211120, 'MEREK', 1211), -(1211130, 'BARUSJAHE', 1211), -(1212010, 'GUNUNG MERIAH', 1212), -(1212020, 'SINEMBAH TANJUNG MUDA HULU', 1212), -(1212030, 'SIBOLANGIT', 1212), -(1212040, 'KUTALIMBARU', 1212), -(1212050, 'PANCUR BATU', 1212), -(1212060, 'NAMO RAMBE', 1212), -(1212070, 'BIRU-BIRU', 1212), -(1212080, 'SINEMBAH TANJUNG MUDA HILIR', 1212), -(1212090, 'BANGUN PURBA', 1212), -(1212190, 'GALANG', 1212), -(1212200, 'TANJUNG MORAWA', 1212), -(1212210, 'PATUMBAK', 1212), -(1212220, 'DELI TUA', 1212), -(1212230, 'SUNGGAL', 1212), -(1212240, 'HAMPARAN PERAK', 1212), -(1212250, 'LABUHAN DELI', 1212), -(1212260, 'PERCUT SEI TUAN', 1212), -(1212270, 'BATANG KUIS', 1212), -(1212280, 'PANTAI LABU', 1212), -(1212290, 'BERINGIN', 1212), -(1212300, 'LUBUK PAKAM', 1212), -(1212310, 'PAGAR MERBAU', 1212), -(1213010, 'BOHOROK', 1213), -(1213011, 'SIRAPIT', 1213), -(1213020, 'SALAPIAN', 1213), -(1213021, 'KUTAMBARU', 1213), -(1213030, 'SEI BINGAI', 1213), -(1213040, 'KUALA', 1213), -(1213050, 'SELESAI', 1213), -(1213060, 'BINJAI', 1213), -(1213070, 'STABAT', 1213), -(1213080, 'WAMPU', 1213), -(1213090, 'BATANG SERANGAN', 1213), -(1213100, 'SAWIT SEBERANG', 1213), -(1213110, 'PADANG TUALANG', 1213), -(1213120, 'HINAI', 1213), -(1213130, 'SECANGGANG', 1213), -(1213140, 'TANJUNG PURA', 1213), -(1213150, 'GEBANG', 1213), -(1213160, 'BABALAN', 1213), -(1213170, 'SEI LEPAN', 1213), -(1213180, 'BRANDAN BARAT', 1213), -(1213190, 'BESITANG', 1213), -(1213200, 'PANGKALAN SUSU', 1213), -(1213201, 'PEMATANG JAYA', 1213), -(1214010, 'HIBALA', 1214), -(1214020, 'PULAU-PULAU BATU', 1214), -(1214021, 'PULAU-PULAU BATU TIMUR', 1214), -(1214030, 'TELUK DALAM', 1214), -(1214031, 'FANAYAMA', 1214), -(1214032, 'TOMA', 1214), -(1214033, 'MANIAMOLO', 1214), -(1214034, 'MAZINO', 1214), -(1214040, 'AMANDRAYA', 1214), -(1214041, 'ARAMO', 1214), -(1214050, 'LAHUSA', 1214), -(1214060, 'GOMO', 1214), -(1214061, 'SUSUA', 1214), -(1214062, 'MAZO', 1214), -(1214063, 'UMBUNASI', 1214), -(1214070, 'LOLOMATUA', 1214), -(1214080, 'LOLOWA''U', 1214), -(1214081, 'HILIMEGAI', 1214), -(1215010, 'PAKKAT', 1215), -(1215020, 'ONAN GANJANG', 1215), -(1215030, 'SIJAMA POLANG', 1215), -(1215040, 'DOLOK SANGGUL', 1215), -(1215050, 'LINTONG NIHUTA', 1215), -(1215060, 'PARANGINAN', 1215), -(1215070, 'BAKTI RAJA', 1215), -(1215080, 'POLLUNG', 1215), -(1215090, 'PARLILITAN', 1215), -(1215100, 'TARA BINTANG', 1215), -(1216010, 'SALAK', 1216), -(1216011, 'SITELLU TALI URANG JEHE', 1216), -(1216012, 'PAGINDAR', 1216), -(1216013, 'SITELLU TALI URANG JULU', 1216), -(1216014, 'PERGETTENG-GETTENG SENGKUT', 1216), -(1216020, 'KERAJAAN', 1216), -(1216021, 'TINADA', 1216), -(1216022, 'SIEMPAT RUBE', 1216), -(1217010, 'SIANJUR MULA MULA', 1217), -(1217020, 'HARIAN', 1217), -(1217030, 'SITIO-TIO', 1217), -(1217040, 'ONAN RUNGGU', 1217), -(1217050, 'NAINGGOLAN', 1217), -(1217060, 'PALIPI', 1217), -(1217070, 'RONGGUR NIHUTA', 1217), -(1217080, 'PANGURURAN', 1217), -(1217090, 'SIMANINDO', 1217), -(1218010, 'KOTARIH', 1218), -(1218011, 'SILINDA', 1218), -(1218012, 'BINTANG BAYU', 1218), -(1218020, 'DOLOK MASIHUL', 1218), -(1218021, 'SERBAJADI', 1218), -(1218030, 'SIPISPIS', 1218), -(1218040, 'DOLOK MERAWAN', 1218), -(1218050, 'TEBINGTINGGI', 1218), -(1218051, 'TEBING SYAHBANDAR', 1218), -(1218060, 'BANDAR KHALIPAH', 1218), -(1218070, 'TANJUNG BERINGIN', 1218), -(1218080, 'SEI RAMPAH', 1218), -(1218081, 'SEI BAMBAN', 1218), -(1218090, 'TELUK MENGKUDU', 1218), -(1218100, 'PERBAUNGAN', 1218), -(1218101, 'PEGAJAHAN', 1218), -(1218110, 'PANTAI CERMIN', 1218), -(1219010, 'SEI BALAI', 1219), -(1219020, 'TANJUNG TIRAM', 1219), -(1219030, 'TALAWI', 1219), -(1219040, 'LIMAPULUH', 1219), -(1219050, 'AIR PUTIH', 1219), -(1219060, 'SEI SUKA', 1219), -(1219070, 'MEDANG DERAS', 1219), -(1220010, 'BATANG ONANG', 1220), -(1220020, 'PADANG BOLAK JULU', 1220), -(1220030, 'PORTIBI', 1220), -(1220040, 'PADANG BOLAK', 1220), -(1220050, 'SIMANGAMBAT', 1220), -(1220060, 'HALONGONAN', 1220), -(1220070, 'DOLOK', 1220), -(1220080, 'DOLOK SIGOMPULON', 1220), -(1220090, 'HULU SIHAPAS', 1220), -(1221010, 'SOSOPAN', 1221), -(1221020, 'ULU BARUMUN', 1221), -(1221030, 'BARUMUN', 1221), -(1221031, 'BARUMUN SELATAN', 1221), -(1221040, 'LUBUK BARUMUN', 1221), -(1221050, 'SOSA', 1221), -(1221060, 'BATANG LUBU SUTAM', 1221), -(1221070, 'HUTA RAJA TINGGI', 1221), -(1221080, 'HURISTAK', 1221), -(1221090, 'BARUMUN TENGAH', 1221), -(1221091, 'AEK NABARA BARUMUN', 1221), -(1222010, 'SUNGAI KANAN', 1222), -(1222020, 'TORGAMBA', 1222), -(1222030, 'KOTA PINANG', 1222), -(1222040, 'SILANGKITANG', 1222), -(1222050, 'KAMPUNG RAKYAT', 1222), -(1223010, 'NA IX-X', 1223), -(1223020, 'MARBAU', 1223), -(1223030, 'AEK KUO', 1223), -(1223040, 'AEK NATAS', 1223), -(1223050, 'KUALUH SELATAN', 1223), -(1223060, 'KUALUH HILIR', 1223), -(1223070, 'KUALUH HULU', 1223), -(1223080, 'KUALUH LEIDONG', 1223), -(1224010, 'TUGALA OYO', 1224), -(1224020, 'ALASA', 1224), -(1224030, 'ALASA TALU MUZOI', 1224), -(1224040, 'NAMOHALU ESIWA', 1224), -(1224050, 'SITOLU ORI', 1224), -(1224060, 'TUHEMBERUA', 1224), -(1224070, 'SAWO', 1224), -(1224080, 'LOTU', 1224), -(1224090, 'LAHEWA TIMUR', 1224), -(1224100, 'AFULU', 1224), -(1224110, 'LAHEWA', 1224), -(1225010, 'SIROMBU', 1225), -(1225020, 'LAHOMI', 1225), -(1225030, 'ULU MORO O', 1225), -(1225040, 'LOLOFITU MOI', 1225), -(1225050, 'MANDREHE UTARA', 1225), -(1225060, 'MANDREHE', 1225), -(1225070, 'MANDREHE BARAT', 1225), -(1225080, 'MORO O', 1225), -(1271010, 'SIBOLGA UTARA', 1271), -(1271020, 'SIBOLGA KOTA', 1271), -(1271030, 'SIBOLGA SELATAN', 1271), -(1271031, 'SIBOLGA SAMBAS', 1271), -(1272010, 'DATUK BANDAR', 1272), -(1272011, 'DATUK BANDAR TIMUR', 1272), -(1272020, 'TANJUNG BALAI SELATAN', 1272), -(1272030, 'TANJUNG BALAI UTARA', 1272), -(1272040, 'SEI TUALANG RASO', 1272), -(1272050, 'TELUK NIBUNG', 1272), -(1273010, 'SIANTAR MARIHAT', 1273), -(1273011, 'SIANTAR MARIMBUN', 1273), -(1273020, 'SIANTAR SELATAN', 1273), -(1273030, 'SIANTAR BARAT', 1273), -(1273040, 'SIANTAR UTARA', 1273), -(1273050, 'SIANTAR TIMUR', 1273), -(1273060, 'SIANTAR MARTOBA', 1273), -(1273061, 'SIANTAR SITALASARI', 1273), -(1274010, 'PADANG HULU', 1274), -(1274011, 'TEBING TINGGI KOTA', 1274), -(1274020, 'RAMBUTAN', 1274), -(1274021, 'BAJENIS', 1274), -(1274030, 'PADANG HILIR', 1274), -(1275010, 'MEDAN TUNTUNGAN', 1275), -(1275020, 'MEDAN JOHOR', 1275), -(1275030, 'MEDAN AMPLAS', 1275), -(1275040, 'MEDAN DENAI', 1275), -(1275050, 'MEDAN AREA', 1275), -(1275060, 'MEDAN KOTA', 1275), -(1275070, 'MEDAN MAIMUN', 1275), -(1275080, 'MEDAN POLONIA', 1275), -(1275090, 'MEDAN BARU', 1275), -(1275100, 'MEDAN SELAYANG', 1275), -(1275110, 'MEDAN SUNGGAL', 1275), -(1275120, 'MEDAN HELVETIA', 1275), -(1275130, 'MEDAN PETISAH', 1275), -(1275140, 'MEDAN BARAT', 1275), -(1275150, 'MEDAN TIMUR', 1275), -(1275160, 'MEDAN PERJUANGAN', 1275), -(1275170, 'MEDAN TEMBUNG', 1275), -(1275180, 'MEDAN DELI', 1275), -(1275190, 'MEDAN LABUHAN', 1275), -(1275200, 'MEDAN MARELAN', 1275), -(1275210, 'MEDAN BELAWAN', 1275), -(1276010, 'BINJAI SELATAN', 1276), -(1276020, 'BINJAI KOTA', 1276), -(1276030, 'BINJAI TIMUR', 1276), -(1276040, 'BINJAI UTARA', 1276), -(1276050, 'BINJAI BARAT', 1276), -(1277010, 'PADANGSIDIMPUAN TENGGARA', 1277), -(1277020, 'PADANGSIDIMPUAN SELATAN', 1277), -(1277030, 'PADANGSIDIMPUAN BATUNADUA', 1277), -(1277040, 'PADANGSIDIMPUAN UTARA', 1277), -(1277050, 'PADANGSIDIMPUAN HUTAIMBARU', 1277), -(1277051, 'PADANGSIDIMPUAN ANGKOLA JULU', 1277), -(1278010, 'GUNUNGSITOLI IDANOI', 1278), -(1278020, 'GUNUNGSITOLI SELATAN', 1278), -(1278030, 'GUNUNGSITOLI BARAT', 1278), -(1278040, 'GUNUNG SITOLI', 1278), -(1278050, 'GUNUNGSITOLI ALO OA', 1278), -(1278060, 'GUNUNGSITOLI UTARA', 1278), -(1301011, 'PAGAI SELATAN', 1301), -(1301012, 'SIKAKAP', 1301), -(1301013, 'PAGAI UTARA', 1301), -(1301021, 'SIPORA SELATAN', 1301), -(1301022, 'SIPORA UTARA', 1301), -(1301030, 'SIBERUT SELATAN', 1301), -(1301031, 'SEBERUT BARAT DAYA', 1301), -(1301032, 'SIBERUT TENGAH', 1301), -(1301040, 'SIBERUT UTARA', 1301), -(1301041, 'SIBERUT BARAT', 1301), -(1302010, 'LUNANG SILAUT', 1302), -(1302020, 'BASA AMPEK BALAI TAPAN', 1302), -(1302030, 'PANCUNG SOAL', 1302), -(1302040, 'LINGGO SARI BAGANTI', 1302), -(1302050, 'RANAH PESISIR', 1302), -(1302060, 'LENGAYANG', 1302), -(1302070, 'SUTERA', 1302), -(1302080, 'BATANG KAPAS', 1302), -(1302090, 'IV JURAI', 1302), -(1302100, 'BAYANG', 1302), -(1302101, 'IV NAGARI BAYANG UTARA', 1302), -(1302110, 'KOTO XI TARUSAN', 1302), -(1303040, 'PANTAI CERMIN', 1303), -(1303050, 'LEMBAH GUMANTI', 1303), -(1303051, 'HILIRAN GUMANTI', 1303), -(1303060, 'PAYUNG SEKAKI', 1303), -(1303061, 'TIGO LURAH BAJANJANG', 1303), -(1303070, 'LEMBANG JAYA', 1303), -(1303071, 'DANAU KEMBAR', 1303), -(1303080, 'GUNUNG TALANG', 1303), -(1303090, 'BUKIT SUNDI', 1303), -(1303100, 'IX KOTO SUNGAI LASI', 1303), -(1303110, 'KUBUNG', 1303), -(1303120, 'X KOTO DIATAS', 1303), -(1303130, 'X KOTO SINGKARAK', 1303), -(1303140, 'JUNJUNG SIRIH', 1303), -(1304050, 'KAMANG BARU', 1304), -(1304060, 'TANJUNG GADANG', 1304), -(1304070, 'SIJUNJUNG', 1304), -(1304071, 'LUBUK TAROK', 1304), -(1304080, 'IV NAGARI', 1304), -(1304090, 'KUPITAN', 1304), -(1304100, 'KOTO TUJUH', 1304), -(1304110, 'SUMPUR KUDUS', 1304), -(1305010, 'SEPULUH KOTO', 1305), -(1305020, 'BATIPUH', 1305), -(1305021, 'BATIPUH SELATAN', 1305), -(1305030, 'PARIANGAN', 1305), -(1305040, 'RAMBATAN', 1305), -(1305050, 'LIMA KAUM', 1305), -(1305060, 'TANJUNG EMAS', 1305), -(1305070, 'PADANG GANTING', 1305), -(1305080, 'LINTAU BUO', 1305), -(1305081, 'LINTAU BUO UTARA', 1305), -(1305090, 'SUNGAYANG', 1305), -(1305100, 'SUNGAI TARAB', 1305), -(1305110, 'SALIMPAUNG', 1305), -(1305111, 'TANJUNG BARU', 1305), -(1306010, 'BATANG ANAI', 1306), -(1306020, 'LUBUK ALUNG', 1306), -(1306021, 'SINTUK TOBOH GADANG', 1306), -(1306030, 'ULAKAN TAPAKIS', 1306), -(1306040, 'NAN SABARIS', 1306), -(1306050, '2 X 11 ENAM LINGKUNG', 1306), -(1306051, 'ENAM LINGKUNG', 1306), -(1306052, '2 X 11 KAYU TANAM', 1306), -(1306060, 'VII KOTO SUNGAI SARIAK', 1306), -(1306061, 'PATAMUAN', 1306), -(1306062, 'PADANG SAGO', 1306), -(1306070, 'V KOTO KP DALAM', 1306), -(1306071, 'V KOTO TIMUR', 1306), -(1306080, 'SUNGAI LIMAU', 1306), -(1306081, 'BATANG GASAN', 1306), -(1306090, 'SUNGAI GERINGGING', 1306), -(1306100, 'IV KOTO AUR MALINTANG', 1306), -(1307010, 'TANJUNG MUTIARA', 1307), -(1307020, 'LUBUK BASUNG', 1307), -(1307021, 'AMPEK NAGARI', 1307), -(1307030, 'TANJUNG RAYA', 1307), -(1307040, 'MATUR', 1307), -(1307050, 'IV KOTO', 1307), -(1307051, 'MALALAK', 1307), -(1307061, 'BANUHAMPU', 1307), -(1307062, 'SUNGAI PUA', 1307), -(1307070, 'AMPEK ANGKEK', 1307), -(1307071, 'CANDUANG', 1307), -(1307080, 'BASO', 1307), -(1307090, 'TILATANG KAMANG', 1307), -(1307091, 'KAMANG MAGEK', 1307), -(1307100, 'PALEMBAYAN', 1307), -(1307110, 'PALUPUH', 1307), -(1308010, 'PAYAKUMBUH', 1308), -(1308011, 'AKABILURU', 1308), -(1308020, 'LUAK', 1308), -(1308021, 'LAREH SAGO HALABAN', 1308), -(1308022, 'SITUJUAH LIMO NAGARI', 1308), -(1308030, 'HARAU', 1308), -(1308040, 'GUGUAK', 1308), -(1308041, 'MUNGKA', 1308), -(1308050, 'SULIKI', 1308), -(1308051, 'BUKIK BARISAN', 1308), -(1308060, 'GUNUANG OMEH', 1308), -(1308070, 'KAPUR IX', 1308), -(1308080, 'PANGKALAN KOTO BARU', 1308), -(1309070, 'BONJOL', 1309), -(1309071, 'TIGO NAGARI', 1309), -(1309072, 'SIMPANG ALAHAN MATI', 1309), -(1309080, 'LUBUK SIKAPING', 1309), -(1309100, 'DUA KOTO', 1309), -(1309110, 'PANTI', 1309), -(1309111, 'PADANG GELUGUR', 1309), -(1309121, 'RAO', 1309), -(1309122, 'MAPAT TUNGGUL', 1309), -(1309123, 'MAPAT TUNGGUL SELATAN', 1309), -(1309124, 'RAO SELATAN', 1309), -(1309125, 'RAO UTARA', 1309), -(1310010, 'SANGIR', 1310), -(1310020, 'SANGIR JUJUAN', 1310), -(1310021, 'SANGIR BALAI JANGGO', 1310), -(1310030, 'SANGIR BATANG HARI', 1310), -(1310040, 'SUNGAI PAGU', 1310), -(1310041, 'PAUAH DUO', 1310), -(1310050, 'KOTO PARIK GADANG DIATEH', 1310), -(1311010, 'SUNGAI RUMBAI', 1311), -(1311011, 'KOTO BESAR', 1311), -(1311012, 'ASAM JUJUHAN', 1311), -(1311020, 'KOTO BARU', 1311), -(1311021, 'KOTO SALAK', 1311), -(1311022, 'TIUMANG', 1311), -(1311023, 'PADANG LAWEH', 1311), -(1311030, 'SITIUNG', 1311), -(1311031, 'TIMPEH', 1311), -(1311040, 'PULAU PUNJUNG', 1311), -(1311041, 'IX KOTO', 1311), -(1312010, 'SUNGAI BEREMAS', 1312), -(1312020, 'RANAH BATAHAN', 1312), -(1312030, 'KOTO BALINGKA', 1312), -(1312040, 'SUNGAI AUR', 1312), -(1312050, 'LEMBAH MALINTANG', 1312), -(1312060, 'GUNUNG TULEH', 1312), -(1312070, 'TALAMAU', 1312), -(1312080, 'PASAMAN', 1312), -(1312090, 'LUHAK NAN DUO', 1312), -(1312100, 'SASAK RANAH PASISIE', 1312), -(1312110, 'KINALI', 1312), -(1371010, 'BUNGUS TELUK KABUNG', 1371), -(1371020, 'LUBUK KILANGAN', 1371), -(1371030, 'LUBUK BEGALUNG', 1371), -(1371040, 'PADANG SELATAN', 1371), -(1371050, 'PADANG TIMUR', 1371), -(1371060, 'PADANG BARAT', 1371), -(1371070, 'PADANG UTARA', 1371), -(1371080, 'NANGGALO', 1371), -(1371090, 'KURANJI', 1371), -(1371100, 'PAUH', 1371), -(1371110, 'KOTO TANGAH', 1371), -(1372010, 'LUBUK SIKARAH', 1372), -(1372020, 'TANJUNG HARAPAN', 1372), -(1373010, 'SILUNGKANG', 1373), -(1373020, 'LEMBAH SEGAR', 1373), -(1373030, 'BARANGIN', 1373), -(1373040, 'TALAWI', 1373), -(1374010, 'PADANG PANJANG BARAT', 1374), -(1374020, 'PADANG PANJANG TIMUR', 1374), -(1375010, 'GUGUK PANJANG', 1375), -(1375020, 'MANDIANGIN KOTO SELAYAN', 1375), -(1375030, 'AUR BIRUGO TIGO BALEH', 1375), -(1376010, 'PAYAKUMBUH BARAT', 1376), -(1376011, 'PAYAKUMBUH SELATAN', 1376), -(1376020, 'PAYAKUMBUH TIMUR', 1376), -(1376030, 'PAYAKUMBUH UTARA', 1376), -(1376031, 'LAMPOSI TIGO NAGORI', 1376), -(1377010, 'PARIAMAN SELATAN', 1377), -(1377020, 'PARIAMAN TENGAH', 1377), -(1377021, 'PARIAMAN TIMUR', 1377), -(1377030, 'PARIAMAN UTARA', 1377), -(1401010, 'KUANTAN MUDIK', 1401), -(1401011, 'HULU KUANTAN', 1401), -(1401012, 'GUNUNG TOAR', 1401), -(1401020, 'SINGINGI', 1401), -(1401021, 'SINGINGI HILIR', 1401), -(1401030, 'KUANTAN TENGAH', 1401), -(1401040, 'BENAI', 1401), -(1401050, 'KUANTAN HILIR', 1401), -(1401051, 'PANGEAN', 1401), -(1401052, 'LOGAS TANAH DARAT', 1401), -(1401060, 'CERENTI', 1401), -(1401061, 'INUMAN', 1401), -(1402010, 'PERANAP', 1402), -(1402011, 'BATANG PERANAP', 1402), -(1402020, 'SEBERIDA', 1402), -(1402021, 'BATANG CENAKU', 1402), -(1402022, 'BATANG GANSAL', 1402), -(1402030, 'KELAYANG', 1402), -(1402031, 'RAKIT KULIM', 1402), -(1402040, 'PASIR PENYU', 1402), -(1402041, 'LIRIK', 1402), -(1402042, 'SUNGAI LALA', 1402), -(1402043, 'LUBUK BATU JAYA', 1402), -(1402050, 'RENGAT BARAT', 1402), -(1402060, 'RENGAT', 1402), -(1402061, 'KUALA CENAKU', 1402), -(1403010, 'KERITANG', 1403), -(1403011, 'KEMUNING', 1403), -(1403020, 'RETEH', 1403), -(1403021, 'SUNGAI BATANG', 1403), -(1403030, 'ENOK', 1403), -(1403040, 'TANAH MERAH', 1403), -(1403050, 'KUALA INDRAGIRI', 1403), -(1403051, 'CONCONG', 1403), -(1403060, 'TEMBILAHAN', 1403), -(1403061, 'TEMBILAHAN HULU', 1403), -(1403070, 'TEMPULING', 1403), -(1403071, 'KEMPAS', 1403), -(1403080, 'BATANG TUAKA', 1403), -(1403090, 'GAUNG ANAK SERKA', 1403), -(1403100, 'GAUNG', 1403), -(1403110, 'MANDAH', 1403), -(1403120, 'KATEMAN', 1403), -(1403121, 'PELANGIRAN', 1403), -(1403122, 'TELUK BELENGKONG', 1403), -(1403123, 'PULAU BURUNG', 1403), -(1404010, 'LANGGAM', 1404), -(1404011, 'PANGKALAN KERINCI', 1404), -(1404012, 'BANDAR SEIKIJANG', 1404), -(1404020, 'PANGKALAN KURAS', 1404), -(1404021, 'UKUI', 1404), -(1404022, 'PANGKALAN LESUNG', 1404), -(1404030, 'BUNUT', 1404), -(1404031, 'PELALAWAN', 1404), -(1404032, 'BANDAR PETALANGAN', 1404), -(1404040, 'KUALA KAMPAR', 1404), -(1404041, 'KERUMUTAN', 1404), -(1404042, 'TELUK MERANTI', 1404), -(1405010, 'MINAS', 1405), -(1405011, 'SUNGAI MANDAU', 1405), -(1405012, 'KANDIS', 1405), -(1405020, 'SIAK', 1405), -(1405021, 'KERINCI KANAN', 1405), -(1405022, 'TUALANG', 1405), -(1405023, 'DAYUN', 1405), -(1405024, 'LUBUK DALAM', 1405), -(1405025, 'KOTO GASIB', 1405), -(1405026, 'MEMPURA', 1405), -(1405030, 'SUNGAI APIT', 1405), -(1405031, 'BUNGA RAYA', 1405), -(1405032, 'SABAK AUH', 1405), -(1405033, 'PUSAKO', 1405), -(1406010, 'KAMPAR KIRI', 1406), -(1406011, 'KAMPAR KIRI HULU', 1406), -(1406012, 'KAMPAR KIRI HILIR', 1406), -(1406013, 'GUNUNG SAHILAN', 1406), -(1406014, 'KAMPAR KIRI TENGAH', 1406), -(1406020, 'XIII KOTO KAMPAR', 1406), -(1406021, 'KOTO KAMPAR HULU', 1406), -(1406030, 'BANGKINANG BARAT', 1406), -(1406031, 'SALO', 1406), -(1406040, 'TAPUNG', 1406), -(1406041, 'TAPUNG HULU', 1406), -(1406042, 'TAPUNG HILIR', 1406), -(1406050, 'BANGKINANG', 1406), -(1406051, 'BANGKINANG SEBERANG', 1406), -(1406060, 'KAMPAR', 1406), -(1406061, 'KAMPAR TIMUR', 1406), -(1406062, 'RUMBIO JAYA', 1406), -(1406063, 'KAMPAR UTARA', 1406), -(1406070, 'TAMBANG', 1406), -(1406080, 'SIAK HULU', 1406), -(1406081, 'PERHENTIAN RAJA', 1406), -(1407010, 'ROKAN IV KOTO', 1407), -(1407011, 'PENDALIAN IV KOTO', 1407), -(1407020, 'TANDUN', 1407), -(1407021, 'KABUN', 1407), -(1407022, 'UJUNG BATU', 1407), -(1407030, 'RAMBAH SAMO', 1407), -(1407040, 'RAMBAH', 1407), -(1407041, 'RAMBAH HILIR', 1407), -(1407042, 'BANGUN PURBA', 1407), -(1407050, 'TAMBUSAI', 1407), -(1407051, 'TAMBUSAI UTARA', 1407), -(1407060, 'KEPENUHAN', 1407), -(1407061, 'KEPENUHAN HULU', 1407), -(1407070, 'KUNTO DARUSSALAM', 1407), -(1407071, 'PAGARAN TAPAH DARUSSALAM', 1407), -(1407072, 'BONAI DARUSSALAM', 1407), -(1408010, 'MANDAU', 1408), -(1408011, 'PINGGIR', 1408), -(1408020, 'BUKIT BATU', 1408), -(1408021, 'SIAK KECIL', 1408), -(1408030, 'RUPAT', 1408), -(1408031, 'RUPAT UTARA', 1408), -(1408040, 'BENGKALIS', 1408), -(1408050, 'BANTAN', 1408), -(1409010, 'TANAH PUTIH', 1409), -(1409011, 'PUJUD', 1409), -(1409012, 'TANAH PUTIH TANJUNG MELAWAN', 1409), -(1409013, 'RANTAU KOPAR', 1409), -(1409020, 'BAGAN SINEMBAH', 1409), -(1409021, 'SIMPANG KANAN', 1409), -(1409030, 'KUBU', 1409), -(1409031, 'PASIR LIMAU KAPAS', 1409), -(1409040, 'BANGKO', 1409), -(1409041, 'SINABOI', 1409), -(1409042, 'BATU HAMPAR', 1409), -(1409043, 'PEKAITAN', 1409), -(1409050, 'RIMBA MELINTANG', 1409), -(1409051, 'BANGKO PUSAKO', 1409), -(1410010, 'TEBING TINGGI BARAT', 1410), -(1410020, 'TEBING TINGGI', 1410), -(1410021, 'TEBING TINGGI TIMUR', 1410), -(1410030, 'RANGSANG', 1410), -(1410040, 'RANGSANG BARAT', 1410), -(1410050, 'MERBAU', 1410), -(1410051, 'PULAU MERBAU', 1410), -(1471010, 'TAMPAN', 1471), -(1471011, 'PAYUNG SEKAKI', 1471), -(1471020, 'BUKIT RAYA', 1471), -(1471021, 'MARPOYAN DAMAI', 1471), -(1471022, 'TENAYAN RAYA', 1471), -(1471030, 'LIMAPULUH', 1471), -(1471040, 'SAIL', 1471), -(1471050, 'PEKANBARU KOTA', 1471), -(1471060, 'SUKAJADI', 1471), -(1471070, 'SENAPELAN', 1471), -(1471080, 'RUMBAI', 1471), -(1471081, 'RUMBAI PESISIR', 1471), -(1473010, 'BUKIT KAPUR', 1473), -(1473011, 'MEDANG KAMPAI', 1473), -(1473012, 'SUNGAI SEMBILAN', 1473), -(1473020, 'DUMAI BARAT', 1473), -(1473030, 'DUMAI TIMUR', 1473), -(1501010, 'GUNUNG RAYA', 1501), -(1501020, 'BATANG MERANGIN', 1501), -(1501030, 'KELILING DANAU', 1501), -(1501040, 'DANAU KERINCI', 1501), -(1501050, 'SITINJAU LAUT', 1501), -(1501070, 'AIR HANGAT', 1501), -(1501071, 'AIR HANGAT TIMUR', 1501), -(1501072, 'DEPATI VII', 1501), -(1501080, 'GUNUNG KERINCI', 1501), -(1501081, 'SIULAK', 1501), -(1501090, 'KAYU ARO', 1501), -(1501091, 'GUNUNG TUJUH', 1501), -(1502010, 'JANGKAT', 1502), -(1502011, 'SUNGAI TENANG', 1502), -(1502020, 'MUARA SIAU', 1502), -(1502021, 'LEMBAH MASURAI', 1502), -(1502022, 'TIANG PUMPUNG', 1502), -(1502030, 'PAMENANG', 1502), -(1502031, 'PAMENANG BARAT', 1502), -(1502032, 'RENAH PAMENANG', 1502), -(1502033, 'PAMENANG SELATAN', 1502), -(1502040, 'BANGKO', 1502), -(1502041, 'BANGKO BARAT', 1502), -(1502042, 'NALO TANTAN', 1502), -(1502043, 'BATANG MASUMAI', 1502), -(1502050, 'SUNGAI MANAU', 1502), -(1502051, 'RENAH PEMBARAP', 1502), -(1502052, 'PANGKALAN JAMBU', 1502), -(1502060, 'TABIR', 1502), -(1502061, 'TABIR ULU', 1502), -(1502062, 'TABIR SELATAN', 1502), -(1502063, 'TABIR ILIR', 1502), -(1502064, 'TABIR TIMUR', 1502), -(1502065, 'TABIR LINTAS', 1502), -(1502066, 'MARGO TABIR', 1502), -(1502067, 'TABIR BARAT', 1502), -(1503010, 'BATANG ASAI', 1503), -(1503020, 'LIMUN', 1503), -(1503021, 'CERMIN NAN GEDANG', 1503), -(1503030, 'PELAWAN', 1503), -(1503031, 'SINGKUT', 1503), -(1503040, 'SAROLANGUN', 1503), -(1503041, 'BATHIN VIII', 1503), -(1503050, 'PAUH', 1503), -(1503051, 'AIR HITAM', 1503), -(1503060, 'MANDIANGIN', 1503), -(1504010, 'MERSAM', 1504), -(1504011, 'MARO SEBO ULU', 1504), -(1504020, 'BATIN XXIV', 1504), -(1504030, 'MUARA TEMBESI', 1504), -(1504040, 'MUARA BULIAN', 1504), -(1504041, 'BAJUBANG', 1504), -(1504042, 'MARO SEBO ILIR', 1504), -(1504050, 'PEMAYUNG', 1504), -(1505010, 'MESTONG', 1505), -(1505011, 'SUNGAI BAHAR', 1505), -(1505012, 'BAHAR SELATAN', 1505), -(1505013, 'BAHAR UTARA', 1505), -(1505020, 'KUMPEH ULU', 1505), -(1505021, 'SUNGAI GELAM', 1505), -(1505030, 'KUMPEH', 1505), -(1505040, 'MARO SEBO', 1505), -(1505041, 'TAMAN RAJO', 1505), -(1505050, 'JAMBI LUAR KOTA', 1505), -(1505060, 'SEKERNAN', 1505), -(1506010, 'MENDAHARA', 1506), -(1506011, 'MENDAHARA ULU', 1506), -(1506012, 'GERAGAI', 1506), -(1506020, 'DENDANG', 1506), -(1506031, 'MUARA SABAK BARAT', 1506), -(1506032, 'MUARA SABAK TIMUR', 1506), -(1506033, 'KUALA JAMBI', 1506), -(1506040, 'RANTAU RASAU', 1506), -(1506041, 'BERBAK', 1506), -(1506050, 'NIPAH PANJANG', 1506), -(1506060, 'SADU', 1506), -(1507010, 'TUNGKAL ULU', 1507), -(1507011, 'MERLUNG', 1507), -(1507012, 'BATANG ASAM', 1507), -(1507013, 'TEBING TINGGI', 1507), -(1507014, 'RENAH MENDALUH', 1507), -(1507015, 'MUARA PAPALIK', 1507), -(1507020, 'PENGABUAN', 1507), -(1507021, 'SENYERANG', 1507), -(1507030, 'TUNGKAL ILIR', 1507), -(1507031, 'BRAM ITAM', 1507), -(1507032, 'SEBERANG KOTA', 1507), -(1507040, 'BETARA', 1507), -(1507041, 'KUALA BETARA', 1507), -(1508010, 'TEBO ILIR', 1508), -(1508011, 'MUARA TABIR', 1508), -(1508020, 'TEBO TENGAH', 1508), -(1508021, 'SUMAY', 1508), -(1508022, 'TENGAH ILIR', 1508), -(1508030, 'RIMBO BUJANG', 1508), -(1508031, 'RIMBO ULU', 1508), -(1508032, 'RIMBO ILIR', 1508), -(1508040, 'TEBO ULU', 1508), -(1508041, 'VII KOTO', 1508), -(1508042, 'SERAI SERUMPUN', 1508), -(1508043, 'VII KOTO ILIR', 1508), -(1509010, 'PELEPAT', 1509), -(1509011, 'PELEPAT ILIR', 1509), -(1509021, 'BATHIN II BABEKO', 1509), -(1509022, 'RIMBO TENGAH', 1509), -(1509023, 'BUNGO DANI', 1509), -(1509024, 'PASAR MUARA BUNGO', 1509), -(1509025, 'BATHIN III', 1509), -(1509030, 'RANTAU PANDAN', 1509), -(1509031, 'MUKO-MUKO BATHIN VII', 1509), -(1509032, 'BATHIN III ULU', 1509), -(1509040, 'TANAH SEPENGGAL', 1509), -(1509041, 'TANAH SEPENGGAL LINTAS', 1509), -(1509050, 'TANAH TUMBUH', 1509), -(1509051, 'LIMBUR LUBUK MENGKUANG', 1509), -(1509052, 'BATHIN II PELAYANG', 1509), -(1509060, 'JUJUHAN', 1509), -(1509061, 'JUJUHAN ILIR', 1509), -(1571010, 'KOTA BARU', 1571), -(1571020, 'JAMBI SELATAN', 1571), -(1571030, 'JELUTUNG', 1571), -(1571040, 'PASAR JAMBI', 1571), -(1571050, 'TELANAIPURA', 1571), -(1571060, 'DANAU TELUK', 1571), -(1571070, 'PELAYANGAN', 1571), -(1571080, 'JAMBI TIMUR', 1571), -(1572010, 'TANAH KAMPUNG', 1572), -(1572020, 'KUMUN DEBAI', 1572), -(1572030, 'SUNGAI PENUH', 1572), -(1572040, 'HAMPARAN RAWANG', 1572), -(1572050, 'PESISIR BUKIT', 1572), -(1601052, 'LENGKITI', 1601), -(1601070, 'SOSOH BUAY RAYAP', 1601), -(1601080, 'PENGANDONAN', 1601), -(1601081, 'SEMIDANG AJI', 1601), -(1601082, 'ULU OGAN', 1601), -(1601083, 'MUARA JAYA', 1601), -(1601090, 'PENINJAUAN', 1601), -(1601091, 'LUBUK BATANG', 1601), -(1601092, 'SINAR PENINJAUAN', 1601), -(1601130, 'BATU RAJA TIMUR', 1601), -(1601131, 'LUBUK RAJA', 1601), -(1601140, 'BATU RAJA BARAT', 1601), -(1602010, 'LEMPUING', 1602), -(1602011, 'LEMPUING JAYA', 1602), -(1602020, 'MESUJI', 1602), -(1602021, 'SUNGAI MENANG', 1602), -(1602022, 'MESUJI MAKMUR', 1602), -(1602023, 'MESUJI RAYA', 1602), -(1602030, 'TULUNG SELAPAN', 1602), -(1602031, 'CENGAL', 1602), -(1602040, 'PEDAMARAN', 1602), -(1602041, 'PEDAMARAN TIMUR', 1602), -(1602050, 'TANJUNG LUBUK', 1602), -(1602051, 'TELUK GELAM', 1602), -(1602060, 'KOTA KAYU AGUNG', 1602), -(1602120, 'SIRAH PULAU PADANG', 1602), -(1602121, 'JEJAWI', 1602), -(1602130, 'PAMPANGAN', 1602), -(1602131, 'PANGKALAN LAPAM', 1602), -(1602140, 'AIR SUGIHAN', 1602), -(1603010, 'SEMENDO DARAT LAUT', 1603), -(1603011, 'SEMENDO DARAT ULU', 1603), -(1603012, 'SEMENDO DARAT TENGAH', 1603), -(1603020, 'TANJUNG AGUNG', 1603), -(1603031, 'RAMBANG', 1603), -(1603032, 'LUBAI', 1603), -(1603040, 'LAWANG KIDUL', 1603), -(1603050, 'MUARA ENIM', 1603), -(1603051, 'UJAN MAS', 1603), -(1603060, 'GUNUNG MEGANG', 1603), -(1603061, 'BENAKAT', 1603), -(1603070, 'RAMBANG DANGKU', 1603), -(1603080, 'TALANG UBI', 1603), -(1603081, 'PENUKAL', 1603), -(1603082, 'TANAH ABANG', 1603), -(1603083, 'PENUKAL UTARA', 1603), -(1603084, 'ABAB', 1603), -(1603090, 'GELUMBANG', 1603), -(1603091, 'LEMBAK', 1603), -(1603092, 'SUNGAI ROTAN', 1603), -(1603093, 'MUARA BELIDA', 1603), -(1603094, 'KELEKAR', 1603), -(1604011, 'TANJUNG SAKTI PUMI', 1604), -(1604012, 'TANJUNG SAKTI PUMU', 1604), -(1604040, 'KOTA AGUNG', 1604), -(1604041, 'MULAK ULU', 1604), -(1604042, 'TANJUNG TEBAT', 1604), -(1604050, 'PULAU PINANG', 1604), -(1604051, 'PAGAR GUNUNG', 1604), -(1604052, 'GUMAY ULU', 1604), -(1604060, 'JARAI', 1604), -(1604061, 'PAJAR BULAN', 1604), -(1604062, 'MUARA PAYANG', 1604), -(1604111, 'KIKIM BARAT', 1604), -(1604112, 'KIKIM TIMUR', 1604), -(1604113, 'KIKIM SELATAN', 1604), -(1604114, 'KIKIM TENGAH', 1604), -(1604120, 'LAHAT', 1604), -(1604121, 'GUMAY TALANG', 1604), -(1604122, 'PSEKSU', 1604), -(1604131, 'MERAPI BARAT', 1604), -(1604132, 'MERAPI TIMUR', 1604), -(1604133, 'MERAPI SELATAN', 1604), -(1605010, 'RAWAS ULU', 1605), -(1605011, 'ULU RAWAS', 1605), -(1605020, 'RUPIT', 1605), -(1605021, 'KARANG JAYA', 1605), -(1605030, 'SUKU TENGAH LAKITAN ULU', 1605), -(1605031, 'SELANGIT', 1605), -(1605032, 'SUMBER HARTA', 1605), -(1605040, 'TUGUMULYO', 1605), -(1605041, 'PURWODADI', 1605), -(1605050, 'MUARA BELITI', 1605), -(1605051, 'TIANG PUMPUNG KEPUNGUT', 1605), -(1605060, 'JAYALOKA', 1605), -(1605061, 'SUKA KARYA', 1605), -(1605070, 'MUARA KELINGI', 1605), -(1605071, 'BULANG TENGAH SUKU ULU', 1605), -(1605072, 'TUAH NEGERI', 1605), -(1605080, 'MUARA LAKITAN', 1605), -(1605090, 'MEGANG SAKTI', 1605), -(1605100, 'RAWAS ILIR', 1605), -(1605101, 'KARANG DAPO', 1605), -(1605102, 'NIBUNG', 1605), -(1606010, 'SANGA DESA', 1606), -(1606020, 'BABAT TOMAN', 1606), -(1606021, 'BATANGHARI LEKO', 1606), -(1606022, 'PLAKAT TINGGI', 1606), -(1606023, 'LAWANG WETAN', 1606), -(1606030, 'SUNGAI KERUH', 1606), -(1606040, 'SEKAYU', 1606), -(1606041, 'LAIS', 1606), -(1606090, 'SUNGAI LILIN', 1606), -(1606091, 'KELUANG', 1606), -(1606092, 'BABAT SUPAT', 1606), -(1606100, 'BAYUNG LENCIR', 1606), -(1606101, 'LALAN', 1606), -(1606102, 'TUNGKAL JAYA', 1606), -(1607010, 'RANTAU BAYUR', 1607), -(1607020, 'BETUNG', 1607), -(1607021, 'SUAK TAPEH', 1607), -(1607030, 'PULAU RIMAU', 1607), -(1607031, 'TUNGKAL ILIR', 1607), -(1607040, 'BANYUASIN III', 1607), -(1607041, 'SEMBAWA', 1607), -(1607050, 'TALANG KELAPA', 1607), -(1607051, 'TANJUNG LAGO', 1607), -(1607060, 'BANYUASIN I', 1607), -(1607070, 'RAMBUTAN', 1607), -(1607080, 'MUARA PADANG', 1607), -(1607081, 'MUARA SUGIHAN', 1607), -(1607090, 'MAKARTI JAYA', 1607), -(1607091, 'AIR SALEK', 1607), -(1607100, 'BANYUASIN II', 1607), -(1607110, 'MUARA TELANG', 1607), -(1608010, 'MEKAKAU ILIR', 1608), -(1608020, 'BANDING AGUNG', 1608), -(1608021, 'WARKUK RANAU SELATAN', 1608), -(1608022, 'BUAY PEMATANG RIBU RANAU TENGAH', 1608), -(1608030, 'BUAY PEMACA', 1608), -(1608040, 'SIMPANG', 1608), -(1608041, 'BUANA PEMACA', 1608), -(1608050, 'MUARADUA', 1608), -(1608051, 'BUAY RAWAN', 1608), -(1608060, 'BUAY SANDANG AJI', 1608), -(1608061, 'TIGA DIHAJI', 1608), -(1608070, 'BUAY RUNJUNG', 1608), -(1608071, 'RUNJUNG AGUNG', 1608), -(1608080, 'KISAM TINGGI', 1608), -(1608090, 'MUARADUA KISAM', 1608), -(1608091, 'KISAM ILIR', 1608), -(1608100, 'PULAU BERINGIN', 1608), -(1608101, 'SINDANG DANAU', 1608), -(1608102, 'SUNGAI ARE', 1608), -(1609010, 'MARTAPURA', 1609), -(1609011, 'BUNGA MAYANG', 1609), -(1609012, 'JAYA PURA', 1609), -(1609020, 'BUAY PEMUKA PELIUNG', 1609), -(1609030, 'BUAY MADANG', 1609), -(1609031, 'BUAY MADANG TIMUR', 1609), -(1609032, 'BUAY PEMUKA BANGSA RAJA', 1609), -(1609040, 'MADANG SUKU II', 1609), -(1609041, 'MADANG SUKU III', 1609), -(1609050, 'MADANG SUKU I', 1609), -(1609051, 'BELITANG MADANG RAYA', 1609), -(1609060, 'BELITANG', 1609), -(1609061, 'BELITANG JAYA', 1609), -(1609070, 'BELITANG III', 1609), -(1609080, 'BELITANG II', 1609), -(1609081, 'BELITANG MULYA', 1609), -(1609090, 'SEMENDAWAI SUKU III', 1609), -(1609091, 'SEMENDAWAI TIMUR', 1609), -(1609100, 'CEMPAKA', 1609), -(1609101, 'SEMENDAWAI BARAT', 1609), -(1610010, 'MUARA KUANG', 1610), -(1610011, 'RAMBANG KUANG', 1610), -(1610012, 'LUBUK KELIAT', 1610), -(1610020, 'TANJUNG BATU', 1610), -(1610021, 'PAYARAMAN', 1610), -(1610030, 'RANTAU ALAI', 1610), -(1610031, 'KANDIS', 1610), -(1610040, 'TANJUNG RAJA', 1610), -(1610041, 'RANTAU PANJANG', 1610), -(1610042, 'SUNGAI PINANG', 1610), -(1610050, 'PEMULUTAN', 1610), -(1610051, 'PEMULUTAN SELATAN', 1610), -(1610052, 'PEMULUTAN BARAT', 1610), -(1610060, 'INDRALAYA', 1610), -(1610061, 'INDRALAYA UTARA', 1610), -(1610062, 'INDRALAYA SELATAN', 1610), -(1611010, 'MUARA PINANG', 1611), -(1611020, 'LINTANG KANAN', 1611), -(1611030, 'PENDOPO', 1611), -(1611040, 'PASMA AIR KERUH', 1611), -(1611050, 'ULU MUSI', 1611), -(1611060, 'TALANG PADANG', 1611), -(1611070, 'TEBING TINGGI', 1611), -(1671010, 'ILIR BARAT II', 1671), -(1671011, 'GANDUS', 1671), -(1671020, 'SEBERANG ULU I', 1671), -(1671021, 'KERTAPATI', 1671), -(1671030, 'SEBERANG ULU II', 1671), -(1671031, 'PLAJU', 1671), -(1671040, 'ILIR BARAT I', 1671), -(1671041, 'BUKIT KECIL', 1671), -(1671050, 'ILIR TIMUR I', 1671), -(1671051, 'KEMUNING', 1671), -(1671060, 'ILIR TIMUR II', 1671), -(1671061, 'KALIDONI', 1671), -(1671070, 'SAKO', 1671), -(1671071, 'SEMATANG BORANG', 1671), -(1671080, 'SUKARAMI', 1671), -(1671081, 'ALANG ALANG LEBAR', 1671), -(1672010, 'RAMBANG KAPAK TENGAH', 1672), -(1672020, 'PRABUMULIH TIMUR', 1672), -(1672021, 'PRABUMULIH SELATAN', 1672), -(1672030, 'PRABUMULIH BARAT', 1672), -(1672031, 'PRABUMULIH UTARA', 1672), -(1672040, 'CAMBAI', 1672), -(1673010, 'DEMPO SELATAN', 1673), -(1673011, 'DEMPO TENGAH', 1673), -(1673020, 'DEMPO UTARA', 1673), -(1673030, 'PAGAR ALAM SELATAN', 1673), -(1673040, 'PAGAR ALAM UTARA', 1673), -(1674011, 'LUBUK LINGGAU BARAT I', 1674), -(1674012, 'LUBUK LINGGAU BARAT II', 1674), -(1674021, 'LUBUK LINGGAU SELATAN I', 1674), -(1674022, 'LUBUK LINGGAU SELATAN II', 1674), -(1674031, 'LUBUK LINGGAU TIMUR I', 1674), -(1674032, 'LUBUK LINGGAU TIMUR II', 1674), -(1674041, 'LUBUK LINGGAU UTARA I', 1674), -(1674042, 'LUBUK LINGGAU UTARA II', 1674), -(1701040, 'MANNA', 1701), -(1701041, 'KOTA MANNA', 1701), -(1701042, 'KEDURANG', 1701), -(1701043, 'BUNGA MAS', 1701), -(1701044, 'PASAR MANNA', 1701), -(1701045, 'KEDURANG ILIR', 1701), -(1701050, 'SEGINIM', 1701), -(1701051, 'AIR NIPIS', 1701), -(1701060, 'PINO', 1701), -(1701061, 'PINORAYA', 1701), -(1701062, 'ULU MANNA', 1701), -(1702020, 'KOTA PADANG', 1702), -(1702021, 'SINDANG BELITI ILIR', 1702), -(1702030, 'PADANG ULAK TANDING', 1702), -(1702031, 'SINDANG KELINGI', 1702), -(1702032, 'BINDU RIANG', 1702), -(1702033, 'SINDANG BELITI ULU', 1702), -(1702034, 'SINDANG DATARAN', 1702), -(1702040, 'CURUP', 1702), -(1702041, 'BERMANI ULU', 1702), -(1702042, 'SELUPU REJANG', 1702), -(1702043, 'CURUP SELATAN', 1702), -(1702044, 'CURUP TENGAH', 1702), -(1702045, 'BERMANI ULU RAYA', 1702), -(1702046, 'CURUP UTARA', 1702), -(1702047, 'CURUP TIMUR', 1702), -(1703010, 'ENGGANO', 1703), -(1703050, 'KERKAP', 1703), -(1703051, 'AIR NAPAL', 1703), -(1703052, 'AIR BESI', 1703), -(1703053, 'HULU PALIK', 1703), -(1703060, 'ARGA MAKMUR', 1703), -(1703070, 'LAIS', 1703), -(1703071, 'BATIK NAU', 1703), -(1703072, 'GIRI MULYA', 1703), -(1703073, 'AIR PADANG', 1703), -(1703080, 'PADANG JAYA', 1703), -(1703090, 'KETAHUN', 1703), -(1703091, 'NAPAL PUTIH', 1703), -(1703100, 'PUTRI HIJAU', 1703), -(1704010, 'NASAL', 1704), -(1704020, 'MAJE', 1704), -(1704030, 'KAUR SELATAN', 1704), -(1704031, 'TETAP', 1704), -(1704040, 'KAUR TENGAH', 1704), -(1704041, 'LUAS', 1704), -(1704042, 'MUARA SAHUNG', 1704), -(1704050, 'KINAL', 1704), -(1704051, 'SEMIDANG GUMAY', 1704), -(1704060, 'TANJUNG KEMUNING', 1704), -(1704061, 'KELAM TENGAH', 1704), -(1704070, 'KAUR UTARA', 1704), -(1704071, 'PADANG GUCI HILIR', 1704), -(1704072, 'LUNGKANG KULE', 1704), -(1704073, 'PADANG GUCI HULU', 1704), -(1705010, 'SEMIDANG ALAS MARAS', 1705), -(1705020, 'SEMIDANG ALAS', 1705), -(1705030, 'TALO', 1705), -(1705031, 'ILIR TALO', 1705), -(1705032, 'TALO KECIL', 1705), -(1705033, 'ULU TALO', 1705), -(1705040, 'SELUMA', 1705), -(1705041, 'SELUMA SELATAN', 1705), -(1705042, 'SELUMA BARAT', 1705), -(1705043, 'SELUMA TIMUR', 1705), -(1705044, 'SELUMA UTARA', 1705), -(1705050, 'SUKARAJA', 1705), -(1705051, 'AIR PERIUKAN', 1705), -(1705052, 'LUBUK SANDI', 1705), -(1706010, 'IPUH', 1706), -(1706011, 'AIR RAMI', 1706), -(1706012, 'MALIN DEMAN', 1706), -(1706020, 'PONDOK SUGUH', 1706), -(1706021, 'SUNGAI RUMBAI', 1706), -(1706022, 'TERAMANG JAYA', 1706), -(1706030, 'TERAS TERUNJAM', 1706), -(1706031, 'PENARIK', 1706), -(1706032, 'SELAGAN RAYA', 1706), -(1706040, 'KOTA MUKOMUKO', 1706), -(1706041, 'AIR DIKIT', 1706), -(1706042, 'XIV KOTO', 1706), -(1706050, 'LUBUK PINANG', 1706), -(1706051, 'AIR MANJUNTO', 1706), -(1706052, 'V KOTO', 1706), -(1707010, 'RIMBO PENGADANG', 1707), -(1707011, 'TOPOS', 1707), -(1707020, 'LEBONG SELATAN', 1707), -(1707021, 'BINGIN KUNING', 1707), -(1707030, 'LEBONG TENGAH', 1707), -(1707031, 'LEBONG SAKTI', 1707), -(1707040, 'LEBONG ATAS', 1707), -(1707041, 'PADANG BANO', 1707), -(1707042, 'PELABAI', 1707), -(1707050, 'LEBONG UTARA', 1707), -(1707051, 'AMEN', 1707), -(1707052, 'URAM JAYA', 1707), -(1707053, 'PINANG BELAPIS', 1707), -(1708010, 'MUARA KEMUMU', 1708), -(1708020, 'BERMANI ILIR', 1708), -(1708030, 'SEBERANG MUSI', 1708), -(1708040, 'TEBAT KARAI', 1708), -(1708050, 'KEPAHIANG', 1708), -(1708060, 'KABA WETAN', 1708), -(1708070, 'UJAN MAS', 1708), -(1708080, 'MERIGI', 1708), -(1709010, 'TALANG EMPAT', 1709), -(1709020, 'KARANG TINGGI', 1709), -(1709030, 'TABA PENANJUNG', 1709), -(1709031, 'MERIGI KELINDANG', 1709), -(1709040, 'PAGAR JATI', 1709), -(1709041, 'MERIGI SAKTI', 1709), -(1709050, 'PONDOK KELAPA', 1709), -(1709051, 'PONDOK KUBANG', 1709), -(1709060, 'PEMATANG TIGA', 1709), -(1709061, 'BANG HAJI', 1709), -(1771010, 'SELEBAR', 1771), -(1771011, 'KAMPUNG MELAYU', 1771), -(1771020, 'GADING CEMPAKA', 1771), -(1771021, 'RATU AGUNG', 1771), -(1771022, 'RATU SAMBAN', 1771), -(1771023, 'SINGARAN PATI', 1771), -(1771030, 'TELUK SEGARA', 1771), -(1771031, 'SUNGAI SERUT', 1771), -(1771040, 'MUARA BANGKA HULU', 1771), -(1801010, 'PESISIR SELATAN', 1801), -(1801011, 'BENGKUNAT', 1801), -(1801012, 'BENGKUNAT BELIMBING', 1801), -(1801013, 'NGAMBUR', 1801), -(1801020, 'PESISIR TENGAH', 1801), -(1801021, 'KARYA PENGGAWA', 1801), -(1801022, 'WAY KRUI', 1801), -(1801023, 'KRUI SELATAN', 1801), -(1801030, 'PESISIR UTARA', 1801), -(1801031, 'LEMONG', 1801), -(1801040, 'BALIK BUKIT', 1801), -(1801041, 'SUKAU', 1801), -(1801042, 'LUMBOK SEMINUNG', 1801), -(1801050, 'BELALAU', 1801), -(1801051, 'SEKINCAU', 1801), -(1801052, 'SUOH', 1801), -(1801053, 'BATU BRAK', 1801), -(1801054, 'PAGAR DEWA', 1801), -(1801055, 'BATU KETULIS', 1801), -(1801056, 'BANDAR NEGERI SUOH', 1801), -(1801060, 'SUMBER JAYA', 1801), -(1801061, 'WAY TENONG', 1801), -(1801062, 'GEDUNG SURIAN', 1801), -(1801063, 'KEBUN TEBU', 1801), -(1801064, 'AIR HITAM', 1801), -(1802010, 'WONOSOBO', 1802), -(1802011, 'SEMAKA', 1802), -(1802012, 'BANDAR NEGERI SEMUONG', 1802), -(1802020, 'KOTA AGUNG', 1802), -(1802021, 'PEMATANG SAWA', 1802), -(1802022, 'KOTA AGUNG TIMUR', 1802), -(1802023, 'KOTA AGUNG BARAT', 1802), -(1802030, 'PULAU PANGGUNG', 1802), -(1802031, 'ULUBELU', 1802), -(1802032, 'AIR NANINGAN', 1802), -(1802040, 'TALANG PADANG', 1802), -(1802041, 'SUMBEREJO', 1802), -(1802042, 'GISTING', 1802), -(1802043, 'GUNUNG ALIP', 1802), -(1802050, 'PUGUNG', 1802), -(1802101, 'BULOK', 1802), -(1802110, 'CUKUH BALAK', 1802), -(1802111, 'KELUMBAYAN', 1802), -(1802112, 'LIMAU', 1802), -(1802113, 'KELUMBAYAN BARAT', 1802), -(1803060, 'NATAR', 1803), -(1803070, 'JATI AGUNG', 1803), -(1803080, 'TANJUNG BINTANG', 1803), -(1803081, 'TANJUNG SARI', 1803), -(1803090, 'KATIBUNG', 1803), -(1803091, 'MERBAU MATARAM', 1803), -(1803092, 'WAY SULAN', 1803), -(1803100, 'SIDOMULYO', 1803), -(1803101, 'CANDIPURO', 1803), -(1803102, 'WAY PANJI', 1803), -(1803110, 'KALIANDA', 1803), -(1803111, 'RAJABASA', 1803), -(1803120, 'PALAS', 1803), -(1803121, 'SRAGI', 1803), -(1803130, 'PENENGAHAN', 1803), -(1803131, 'KETAPANG', 1803), -(1803132, 'BAKAUHENI', 1803), -(1804010, 'METRO KIBANG', 1804), -(1804020, 'BATANGHARI', 1804), -(1804030, 'SEKAMPUNG', 1804), -(1804040, 'MARGATIGA', 1804), -(1804050, 'SEKAMPUNG UDIK', 1804), -(1804060, 'JABUNG', 1804), -(1804061, 'PASIR SAKTI', 1804), -(1804062, 'WAWAY KARYA', 1804), -(1804063, 'MARGA SEKAPUNG', 1804), -(1804070, 'LABUHAN MARINGGAI', 1804), -(1804071, 'MATARAM BARU', 1804), -(1804072, 'BANDAR SRIBAWONO', 1804), -(1804073, 'MELINTING', 1804), -(1804074, 'GUNUNG PELINDUNG', 1804), -(1804080, 'WAY JEPARA', 1804), -(1804081, 'BRAJA SLEBAH', 1804), -(1804082, 'LABUHAN RATU', 1804), -(1804090, 'SUKADANA', 1804), -(1804091, 'BUMI AGUNG', 1804), -(1804092, 'BATANGHARI NUBAN', 1804), -(1804100, 'PEKALONGAN', 1804), -(1804110, 'RAMAN UTARA', 1804), -(1804120, 'PURBOLINGGO', 1804), -(1804121, 'WAY BUNGUR', 1804), -(1805010, 'PADANG RATU', 1805), -(1805011, 'SELAGAI LINGGA', 1805), -(1805012, 'PUBIAN', 1805), -(1805013, 'ANAK TUHA', 1805), -(1805014, 'ANAK RATU AJI', 1805), -(1805020, 'KALIREJO', 1805), -(1805021, 'SENDANG AGUNG', 1805), -(1805030, 'BANGUNREJO', 1805), -(1805040, 'GUNUNG SUGIH', 1805), -(1805041, 'BEKRI', 1805), -(1805042, 'BUMI RATU NUBAN', 1805), -(1805050, 'TRIMURJO', 1805), -(1805060, 'PUNGGUR', 1805), -(1805061, 'KOTA GAJAH', 1805), -(1805070, 'SEPUTIH RAMAN', 1805), -(1805080, 'TERBANGGI BESAR', 1805), -(1805081, 'SEPUTIH AGUNG', 1805), -(1805082, 'WAY PENGUBUAN', 1805), -(1805090, 'TERUSAN NUNYAI', 1805), -(1805100, 'SEPUTIH MATARAM', 1805), -(1805101, 'BANDAR MATARAM', 1805), -(1805110, 'SEPUTIH BANYAK', 1805), -(1805111, 'WAY SEPUTIH', 1805), -(1805120, 'RUMBIA', 1805), -(1805121, 'BUMI NABUNG', 1805), -(1805122, 'PUTRA RUMBIA', 1805), -(1805130, 'SEPUTIH SURABAYA', 1805), -(1805131, 'BANDAR SURABAYA', 1805), -(1806010, 'BUKIT KEMUNING', 1806), -(1806011, 'ABUNG TINGGI', 1806), -(1806020, 'TANJUNG RAJA', 1806), -(1806030, 'ABUNG BARAT', 1806), -(1806031, 'ABUNG TENGAH', 1806), -(1806032, 'ABUNG KUNANG', 1806), -(1806033, 'ABUNG PEKURUN', 1806), -(1806040, 'KOTABUMI', 1806), -(1806041, 'KOTABUMI UTARA', 1806), -(1806042, 'KOTABUMI SELATAN', 1806), -(1806050, 'ABUNG SELATAN', 1806), -(1806051, 'ABUNG SEMULI', 1806), -(1806052, 'BLAMBANGAN PAGAR', 1806), -(1806060, 'ABUNG TIMUR', 1806), -(1806061, 'ABUNG SURAKARTA', 1806), -(1806070, 'SUNGKAI SELATAN', 1806), -(1806071, 'MUARA SUNGKAI', 1806), -(1806072, 'BUNGA MAYANG', 1806), -(1806073, 'SUNGKAI BARAT', 1806), -(1806074, 'SUNGKAI JAYA', 1806), -(1806080, 'SUNGKAI UTARA', 1806), -(1806081, 'HULUSUNGKAI', 1806), -(1806082, 'SUNGKAI TENGAH', 1806), -(1807010, 'BANJIT', 1807), -(1807020, 'BARADATU', 1807); -INSERT INTO `kecamatan` (`kodeBps`, `namaKecamatan`, `kodeKabupaten`) VALUES -(1807021, 'GUNUNG LABUHAN', 1807), -(1807030, 'KASUI', 1807), -(1807031, 'REBANG TANGKAS', 1807), -(1807040, 'BLAMBANGAN UMPU', 1807), -(1807041, 'WAY TUBA', 1807), -(1807042, 'NEGERI AGUNG', 1807), -(1807050, 'BAHUGA', 1807), -(1807051, 'BUAY BAHUGA', 1807), -(1807052, 'BUMI AGUNG', 1807), -(1807060, 'PAKUAN RATU', 1807), -(1807061, 'NEGARA BATIN', 1807), -(1807062, 'NEGERI BESAR', 1807), -(1808030, 'BANJAR AGUNG', 1808), -(1808031, 'BANJAR MARGO', 1808), -(1808032, 'BANJAR BARU', 1808), -(1808040, 'GEDUNG AJI', 1808), -(1808041, 'PENAWAR AJI', 1808), -(1808042, 'MERAKSA AJI', 1808), -(1808050, 'MENGGALA', 1808), -(1808051, 'PENAWAR TAMA', 1808), -(1808052, 'RAWAJITU SELATAN', 1808), -(1808053, 'GEDUNG MENENG', 1808), -(1808054, 'RAWAJITU TIMUR', 1808), -(1808055, 'RAWA PITU', 1808), -(1808056, 'GEDUNG AJI BARU', 1808), -(1808057, 'DENTE TELADAS', 1808), -(1808058, 'MENGGALA TIMUR', 1808), -(1809010, 'PUNDUH PIDADA', 1809), -(1809020, 'PADANG CERMIN', 1809), -(1809030, 'KEDONDONG', 1809), -(1809040, 'WAY LIMA', 1809), -(1809050, 'GEDUNG TATAAN', 1809), -(1809060, 'NEGERI KATON', 1809), -(1809070, 'TEGINENENG', 1809), -(1810010, 'PARDASUKA', 1810), -(1810020, 'AMBARAWA', 1810), -(1810030, 'PAGELARAN', 1810), -(1810040, 'PRINGSEWU', 1810), -(1810050, 'GADING REJO', 1810), -(1810060, 'SUKOHARJO', 1810), -(1810070, 'BANYUMAS', 1810), -(1810080, 'ADI LUWIH', 1810), -(1811010, 'WAY SERDANG', 1811), -(1811020, 'SIMPANG PEMATANG', 1811), -(1811030, 'PANCA JAYA', 1811), -(1811040, 'TANJUNG RAYA', 1811), -(1811050, 'MESUJI', 1811), -(1811060, 'MESUJI TIMUR', 1811), -(1811070, 'RAWAJITU UTARA', 1811), -(1812010, 'TULANG BAWANG UDIK', 1812), -(1812020, 'TUMI JAJAR', 1812), -(1812030, 'TULANG BAWANG TENGAH', 1812), -(1812040, 'PAGAR DEWA', 1812), -(1812050, 'LAMBU KIBANG', 1812), -(1812060, 'GUNUNG TERANG', 1812), -(1812070, 'GUNUNG AGUNG', 1812), -(1812080, 'WAY KENANGA', 1812), -(1871010, 'TELUK BETUNG BARAT', 1871), -(1871020, 'TELUK BETUNG SELATAN', 1871), -(1871030, 'PANJANG', 1871), -(1871040, 'TANJUNG KARANG TIMUR', 1871), -(1871050, 'TELUK BETUNG UTARA', 1871), -(1871060, 'TANJUNG KARANG PUSAT', 1871), -(1871070, 'TANJUNG KARANG BARAT', 1871), -(1871071, 'KEMILING', 1871), -(1871080, 'KEDATON', 1871), -(1871081, 'RAJABASA', 1871), -(1871082, 'TANJUNG SENANG', 1871), -(1871090, 'SUKARAME', 1871), -(1871091, 'SUKABUMI', 1871), -(1872011, 'METRO SELATAN', 1872), -(1872012, 'METRO BARAT', 1872), -(1872021, 'METRO TIMUR', 1872), -(1872022, 'METRO PUSAT', 1872), -(1872023, 'METRO UTARA', 1872), -(1901070, 'MENDO BARAT', 1901), -(1901080, 'MERAWANG', 1901), -(1901081, 'PUDING BESAR', 1901), -(1901090, 'SUNGAI LIAT', 1901), -(1901091, 'PEMALI', 1901), -(1901092, 'BAKAM', 1901), -(1901130, 'BELINYU', 1901), -(1901131, 'RIAU SILIP', 1901), -(1902010, 'MEMBALONG', 1902), -(1902060, 'TANJUNG PANDAN', 1902), -(1902061, 'BADAU', 1902), -(1902062, 'SIJUK', 1902), -(1902063, 'SELAT NASIK', 1902), -(1903010, 'KELAPA', 1903), -(1903020, 'TEMPILANG', 1903), -(1903030, 'MENTOK', 1903), -(1903040, 'SIMPANG TERITIP', 1903), -(1903050, 'JEBUS', 1903), -(1903051, 'PARITTIGA', 1903), -(1904010, 'KOBA', 1904), -(1904011, 'LUBUK BESAR', 1904), -(1904020, 'PANGKALAN BARU', 1904), -(1904021, 'NAMANG', 1904), -(1904030, 'SUNGAI SELAN', 1904), -(1904040, 'SIMPANG KATIS', 1904), -(1905010, 'PAYUNG', 1905), -(1905011, 'PULAU BESAR', 1905), -(1905020, 'SIMPANG RIMBA', 1905), -(1905030, 'TOBOALI', 1905), -(1905031, 'TUKAK SADAI', 1905), -(1905040, 'AIR GEGAS', 1905), -(1905050, 'LEPAR PONGOK', 1905), -(1906010, 'DENDANG', 1906), -(1906011, 'SIMPANG PESAK', 1906), -(1906020, 'GANTUNG', 1906), -(1906021, 'SIMPANG RENGGIANG', 1906), -(1906030, 'MANGGAR', 1906), -(1906031, 'DAMAR', 1906), -(1906040, 'KELAPA KAMPIT', 1906), -(1971010, 'RANGKUI', 1971), -(1971020, 'BUKIT INTAN', 1971), -(1971021, 'GIRIMAYA', 1971), -(1971030, 'PANGKAL BALAM', 1971), -(1971031, 'GABEK', 1971), -(1971040, 'TAMAN SARI', 1971), -(1971041, 'GERUNGGANG', 1971), -(2101010, 'MORO', 2101), -(2101011, 'DURAI', 2101), -(2101020, 'KUNDUR', 2101), -(2101021, 'KUNDUR UTARA', 2101), -(2101022, 'KUNDUR BARAT', 2101), -(2101030, 'KARIMUN', 2101), -(2101031, 'BURU', 2101), -(2101032, 'MERAL', 2101), -(2101033, 'TEBING', 2101), -(2102040, 'TELUK BINTAN', 2102), -(2102050, 'BINTAN UTARA', 2102), -(2102051, 'TELUK SEBONG', 2102), -(2102052, 'SERI KUALA LOBAM', 2102), -(2102060, 'BINTAN TIMUR', 2102), -(2102061, 'GUNUNG KIJANG', 2102), -(2102062, 'MANTANG', 2102), -(2102063, 'BINTAN PESISIR', 2102), -(2102064, 'TOAPAYA', 2102), -(2102070, 'TAMBELAN', 2102), -(2103030, 'MIDAI', 2103), -(2103040, 'BUNGURAN BARAT', 2103), -(2103041, 'BUNGURAN UTARA', 2103), -(2103042, 'PULAU LAUT', 2103), -(2103043, 'PULAU TIGA', 2103), -(2103050, 'BUNGURAN TIMUR', 2103), -(2103051, 'BUNGURAN TIMUR LAUT', 2103), -(2103052, 'BUNGURAN TENGAH', 2103), -(2103053, 'BUNGURAN SELATAN', 2103), -(2103060, 'S E R A S A N', 2103), -(2103061, 'SUBI', 2103), -(2103062, 'SERASAN TIMUR', 2103), -(2104010, 'SINGKEP BARAT', 2104), -(2104020, 'SINGKEP', 2104), -(2104030, 'LINGGA', 2104), -(2104040, 'LINGGA UTARA', 2104), -(2104050, 'SENAYANG', 2104), -(2105010, 'JEMAJA', 2105), -(2105020, 'JEMAJA TIMUR', 2105), -(2105030, 'SIANTAN SELATAN', 2105), -(2105040, 'SIANTAN', 2105), -(2105050, 'SIANTAN TIMUR', 2105), -(2105060, 'SIANTAN TENGAH', 2105), -(2105070, 'PAL MATAK', 2105), -(2171010, 'BELAKANG PADANG', 2171), -(2171020, 'BULANG', 2171), -(2171030, 'GALANG', 2171), -(2171040, 'SEI BEDUK', 2171), -(2171041, 'SAGULUNG', 2171), -(2171050, 'NONGSA', 2171), -(2171051, 'BATAM KOTA', 2171), -(2171060, 'SEKUPANG', 2171), -(2171061, 'BATU AJI', 2171), -(2171070, 'LUBUK BAJA', 2171), -(2171080, 'BATU AMPAR', 2171), -(2171081, 'BENGKONG', 2171), -(2172010, 'BUKIT BESTARI', 2172), -(2172020, 'TANJUNGPINANG TIMUR', 2172), -(2172030, 'TANJUNGPINANG KOTA', 2172), -(2172040, 'TANJUNGPINANG BARAT', 2172), -(3101010, 'KEPULAUAN SERIBU SELATAN', 3101), -(3101020, 'KEPULAUAN SERIBU UTARA', 3101), -(3171010, 'JAGAKARSA', 3171), -(3171020, 'PASAR MINGGU', 3171), -(3171030, 'CILANDAK', 3171), -(3171040, 'PESANGGRAHAN', 3171), -(3171050, 'KEBAYORAN LAMA', 3171), -(3171060, 'KEBAYORAN BARU', 3171), -(3171070, 'MAMPANG PRAPATAN', 3171), -(3171080, 'PANCORAN', 3171), -(3171090, 'TEBET', 3171), -(3171100, 'SETIA BUDI', 3171), -(3172010, 'PASAR REBO', 3172), -(3172020, 'CIRACAS', 3172), -(3172030, 'CIPAYUNG', 3172), -(3172040, 'MAKASAR', 3172), -(3172050, 'KRAMAT JATI', 3172), -(3172060, 'JATINEGARA', 3172), -(3172070, 'DUREN SAWIT', 3172), -(3172080, 'CAKUNG', 3172), -(3172090, 'PULO GADUNG', 3172), -(3172100, 'MATRAMAN', 3172), -(3173010, 'TANAH ABANG', 3173), -(3173020, 'MENTENG', 3173), -(3173030, 'SENEN', 3173), -(3173040, 'JOHAR BARU', 3173), -(3173050, 'CEMPAKA PUTIH', 3173), -(3173060, 'KEMAYORAN', 3173), -(3173070, 'SAWAH BESAR', 3173), -(3173080, 'GAMBIR', 3173), -(3174010, 'KEMBANGAN', 3174), -(3174020, 'KEBON JERUK', 3174), -(3174030, 'PALMERAH', 3174), -(3174040, 'GROGOL PETAMBURAN', 3174), -(3174050, 'TAMBORA', 3174), -(3174060, 'TAMAN SARI', 3174), -(3174070, 'CENGKARENG', 3174), -(3174080, 'KALI DERES', 3174), -(3175010, 'PENJARINGAN', 3175), -(3175020, 'PADEMANGAN', 3175), -(3175030, 'TANJUNG PRIOK', 3175), -(3175040, 'KOJA', 3175), -(3175050, 'KELAPA GADING', 3175), -(3175060, 'CILINCING', 3175), -(3201010, 'NANGGUNG', 3201), -(3201020, 'LEUWILIANG', 3201), -(3201021, 'LEUWISADENG', 3201), -(3201030, 'PAMIJAHAN', 3201), -(3201040, 'CIBUNGBULANG', 3201), -(3201050, 'CIAMPEA', 3201), -(3201051, 'TENJOLAYA', 3201), -(3201060, 'DRAMAGA', 3201), -(3201070, 'CIOMAS', 3201), -(3201071, 'TAMANSARI', 3201), -(3201080, 'CIJERUK', 3201), -(3201081, 'CIGOMBONG', 3201), -(3201090, 'CARINGIN', 3201), -(3201100, 'CIAWI', 3201), -(3201110, 'CISARUA', 3201), -(3201120, 'MEGAMENDUNG', 3201), -(3201130, 'SUKARAJA', 3201), -(3201140, 'BABAKAN MADANG', 3201), -(3201150, 'SUKAMAKMUR', 3201), -(3201160, 'CARIU', 3201), -(3201161, 'TANJUNGSARI', 3201), -(3201170, 'JONGGOL', 3201), -(3201180, 'CILEUNGSI', 3201), -(3201181, 'KELAPA NUNGGAL', 3201), -(3201190, 'GUNUNG PUTRI', 3201), -(3201200, 'CITEUREUP', 3201), -(3201210, 'CIBINONG', 3201), -(3201220, 'BOJONG GEDE', 3201), -(3201221, 'TAJUR HALANG', 3201), -(3201230, 'KEMANG', 3201), -(3201231, 'RANCA BUNGUR', 3201), -(3201240, 'PARUNG', 3201), -(3201241, 'CISEENG', 3201), -(3201250, 'GUNUNG SINDUR', 3201), -(3201260, 'RUMPIN', 3201), -(3201270, 'CIGUDEG', 3201), -(3201271, 'SUKAJAYA', 3201), -(3201280, 'JASINGA', 3201), -(3201290, 'TENJO', 3201), -(3201300, 'PARUNG PANJANG', 3201), -(3202010, 'CIEMAS', 3202), -(3202020, 'CIRACAP', 3202), -(3202021, 'WALURAN', 3202), -(3202030, 'SURADE', 3202), -(3202031, 'CIBITUNG', 3202), -(3202040, 'JAMPANG KULON', 3202), -(3202041, 'CIMANGGU', 3202), -(3202050, 'KALI BUNDER', 3202), -(3202060, 'TEGAL BULEUD', 3202), -(3202070, 'CIDOLOG', 3202), -(3202080, 'SAGARANTEN', 3202), -(3202081, 'CIDADAP', 3202), -(3202082, 'CURUGKEMBAR', 3202), -(3202090, 'PABUARAN', 3202), -(3202100, 'LENGKONG', 3202), -(3202110, 'PELABUHAN RATU', 3202), -(3202111, 'SIMPENAN', 3202), -(3202120, 'WARUNG KIARA', 3202), -(3202121, 'BANTARGADUNG', 3202), -(3202130, 'JAMPANG TENGAH', 3202), -(3202131, 'PURABAYA', 3202), -(3202140, 'CIKEMBAR', 3202), -(3202150, 'NYALINDUNG', 3202), -(3202160, 'GEGER BITUNG', 3202), -(3202170, 'SUKARAJA', 3202), -(3202171, 'KEBONPEDES', 3202), -(3202172, 'CIREUNGHAS', 3202), -(3202173, 'SUKALARANG', 3202), -(3202180, 'SUKABUMI', 3202), -(3202190, 'KADUDAMPIT', 3202), -(3202200, 'CISAAT', 3202), -(3202201, 'GUNUNGGURUH', 3202), -(3202210, 'CIBADAK', 3202), -(3202211, 'CICANTAYAN', 3202), -(3202212, 'CARINGIN', 3202), -(3202220, 'NAGRAK', 3202), -(3202221, 'CIAMBAR', 3202), -(3202230, 'CICURUG', 3202), -(3202240, 'CIDAHU', 3202), -(3202250, 'PARAKAN SALAK', 3202), -(3202260, 'PARUNG KUDA', 3202), -(3202261, 'BOJONG GENTENG', 3202), -(3202270, 'KALAPA NUNGGAL', 3202), -(3202280, 'CIKIDANG', 3202), -(3202290, 'CISOLOK', 3202), -(3202291, 'CIKAKAK', 3202), -(3202300, 'KABANDUNGAN', 3202), -(3203010, 'AGRABINTA', 3203), -(3203011, 'LELES', 3203), -(3203020, 'SINDANGBARANG', 3203), -(3203030, 'CIDAUN', 3203), -(3203040, 'NARINGGUL', 3203), -(3203050, 'CIBINONG', 3203), -(3203051, 'CIKADU', 3203), -(3203060, 'TANGGEUNG', 3203), -(3203061, 'PASIRKUDA', 3203), -(3203070, 'KADUPANDAK', 3203), -(3203071, 'CIJATI', 3203), -(3203080, 'TAKOKAK', 3203), -(3203090, 'SUKANAGARA', 3203), -(3203100, 'PAGELARAN', 3203), -(3203110, 'CAMPAKA', 3203), -(3203111, 'CAMPAKA MULYA', 3203), -(3203120, 'CIBEBER', 3203), -(3203130, 'WARUNGKONDANG', 3203), -(3203131, 'GEKBRONG', 3203), -(3203140, 'CILAKU', 3203), -(3203150, 'SUKALUYU', 3203), -(3203160, 'BOJONGPICUNG', 3203), -(3203161, 'HAURWANGI', 3203), -(3203170, 'CIRANJANG', 3203), -(3203180, 'MANDE', 3203), -(3203190, 'KARANGTENGAH', 3203), -(3203200, 'CIANJUR', 3203), -(3203210, 'CUGENANG', 3203), -(3203220, 'PACET', 3203), -(3203221, 'CIPANAS', 3203), -(3203230, 'SUKARESMI', 3203), -(3203240, 'CIKALONGKULON', 3203), -(3204010, 'CIWIDEY', 3204), -(3204011, 'RANCABALI', 3204), -(3204020, 'PASIRJAMBU', 3204), -(3204030, 'CIMAUNG', 3204), -(3204040, 'PANGALENGAN', 3204), -(3204050, 'KERTASARI', 3204), -(3204060, 'PACET', 3204), -(3204070, 'IBUN', 3204), -(3204080, 'PASEH', 3204), -(3204090, 'CIKANCUNG', 3204), -(3204100, 'CICALENGKA', 3204), -(3204101, 'NAGREG', 3204), -(3204110, 'RANCAEKEK', 3204), -(3204120, 'MAJALAYA', 3204), -(3204121, 'SOLOKAN JERUK', 3204), -(3204130, 'CIPARAY', 3204), -(3204140, 'BALEENDAH', 3204), -(3204150, 'ARJASARI', 3204), -(3204160, 'BANJARAN', 3204), -(3204161, 'CANGKUANG', 3204), -(3204170, 'PAMEUNGPEUK', 3204), -(3204180, 'KATAPANG', 3204), -(3204190, 'SOREANG', 3204), -(3204191, 'KUTAWARINGIN', 3204), -(3204250, 'MARGAASIH', 3204), -(3204260, 'MARGAHAYU', 3204), -(3204270, 'DAYEUHKOLOT', 3204), -(3204280, 'BOJONGSOANG', 3204), -(3204290, 'CILEUNYI', 3204), -(3204300, 'CILENGKRANG', 3204), -(3204310, 'CIMENYAN', 3204), -(3205010, 'CISEWU', 3205), -(3205011, 'CARINGIN', 3205), -(3205020, 'TALEGONG', 3205), -(3205030, 'BUNGBULANG', 3205), -(3205031, 'MEKARMUKTI', 3205), -(3205040, 'PAMULIHAN', 3205), -(3205050, 'PAKENJENG', 3205), -(3205060, 'CIKELET', 3205), -(3205070, 'PAMEUNGPEUK', 3205), -(3205080, 'CIBALONG', 3205), -(3205090, 'CISOMPET', 3205), -(3205100, 'PEUNDEUY', 3205), -(3205110, 'SINGAJAYA', 3205), -(3205111, 'CIHURIP', 3205), -(3205120, 'CIKAJANG', 3205), -(3205130, 'BANJARWANGI', 3205), -(3205140, 'CILAWU', 3205), -(3205150, 'BAYONGBONG', 3205), -(3205151, 'CIGEDUG', 3205), -(3205160, 'CISURUPAN', 3205), -(3205161, 'SUKARESMI', 3205), -(3205170, 'SAMARANG', 3205), -(3205171, 'PASIRWANGI', 3205), -(3205181, 'TAROGONG KIDUL', 3205), -(3205182, 'TAROGONG KALER', 3205), -(3205190, 'GARUT KOTA', 3205), -(3205200, 'KARANGPAWITAN', 3205), -(3205210, 'WANARAJA', 3205), -(3205211, 'SUCINARAJA', 3205), -(3205212, 'PANGATIKAN', 3205), -(3205220, 'SUKAWENING', 3205), -(3205221, 'KARANGTENGAH', 3205), -(3205230, 'BANYURESMI', 3205), -(3205240, 'LELES', 3205), -(3205250, 'LEUWIGOONG', 3205), -(3205260, 'CIBATU', 3205), -(3205261, 'KERSAMANAH', 3205), -(3205270, 'CIBIUK', 3205), -(3205280, 'KADUNGORA', 3205), -(3205290, 'BLUBUR LIMBANGAN', 3205), -(3205300, 'SELAAWI', 3205), -(3205310, 'MALANGBONG', 3205), -(3206010, 'CIPATUJAH', 3206), -(3206020, 'KARANGNUNGGAL', 3206), -(3206030, 'CIKALONG', 3206), -(3206040, 'PANCATENGAH', 3206), -(3206050, 'CIKATOMAS', 3206), -(3206060, 'CIBALONG', 3206), -(3206061, 'PARUNGPONTENG', 3206), -(3206070, 'BANTARKALONG', 3206), -(3206071, 'BOJONGASIH', 3206), -(3206072, 'CULAMEGA', 3206), -(3206080, 'BOJONGGAMBIR', 3206), -(3206090, 'SODONGHILIR', 3206), -(3206100, 'TARAJU', 3206), -(3206110, 'SALAWU', 3206), -(3206111, 'PUSPAHIANG', 3206), -(3206120, 'TANJUNGJAYA', 3206), -(3206130, 'SUKARAJA', 3206), -(3206140, 'SALOPA', 3206), -(3206141, 'JATIWARAS', 3206), -(3206150, 'CINEAM', 3206), -(3206151, 'KARANGJAYA', 3206), -(3206160, 'MANONJAYA', 3206), -(3206161, 'GUNUNGTANJUNG', 3206), -(3206190, 'SINGAPARNA', 3206), -(3206191, 'SUKARAME', 3206), -(3206192, 'MANGUNREJA', 3206), -(3206200, 'CIGALONTANG', 3206), -(3206210, 'LEUWISARI', 3206), -(3206211, 'SARIWANGI', 3206), -(3206212, 'PADAKEMBANG', 3206), -(3206221, 'SUKARATU', 3206), -(3206230, 'CISAYONG', 3206), -(3206231, 'SUKAHENING', 3206), -(3206240, 'RAJAPOLAH', 3206), -(3206250, 'JAMANIS', 3206), -(3206260, 'CIAWI', 3206), -(3206261, 'KADIPATEN', 3206), -(3206270, 'PAGERAGEUNG', 3206), -(3206271, 'SUKARESIK', 3206), -(3207010, 'CIMERAK', 3207), -(3207020, 'CIJULANG', 3207), -(3207030, 'CIGUGUR', 3207), -(3207040, 'LANGKAPLANCAR', 3207), -(3207050, 'PARIGI', 3207), -(3207060, 'SIDAMULIH', 3207), -(3207070, 'PANGANDARAN', 3207), -(3207080, 'KALIPUCANG', 3207), -(3207090, 'PADAHERANG', 3207), -(3207091, 'MANGUNJAYA', 3207), -(3207100, 'BANJARSARI', 3207), -(3207110, 'LAKBOK', 3207), -(3207111, 'PURWADADI', 3207), -(3207120, 'PAMARICAN', 3207), -(3207130, 'CIDOLOG', 3207), -(3207140, 'CIMARAGAS', 3207), -(3207150, 'CIJEUNGJING', 3207), -(3207160, 'CISAGA', 3207), -(3207170, 'TAMBAKSARI', 3207), -(3207180, 'RANCAH', 3207), -(3207190, 'RAJADESA', 3207), -(3207200, 'SUKADANA', 3207), -(3207210, 'CIAMIS', 3207), -(3207211, 'BAREGBEG', 3207), -(3207220, 'CIKONENG', 3207), -(3207221, 'SINDANGKASIH', 3207), -(3207230, 'CIHAURBEUTI', 3207), -(3207240, 'SADANANYA', 3207), -(3207250, 'CIPAKU', 3207), -(3207260, 'JATINAGARA', 3207), -(3207270, 'PANAWANGAN', 3207), -(3207280, 'KAWALI', 3207), -(3207281, 'LUMBUNG', 3207), -(3207290, 'PANJALU', 3207), -(3207291, 'SUKAMANTRI', 3207), -(3207300, 'PANUMBANGAN', 3207), -(3208010, 'DARMA', 3208), -(3208020, 'KADUGEDE', 3208), -(3208021, 'NUSAHERANG', 3208), -(3208030, 'CINIRU', 3208), -(3208031, 'HANTARA', 3208), -(3208040, 'SELAJAMBE', 3208), -(3208050, 'SUBANG', 3208), -(3208051, 'CILEBAK', 3208), -(3208060, 'CIWARU', 3208), -(3208061, 'KARANGKANCANA', 3208), -(3208070, 'CIBINGBIN', 3208), -(3208071, 'CIBEUREUM', 3208), -(3208080, 'LURAGUNG', 3208), -(3208081, 'CIMAHI', 3208), -(3208090, 'CIDAHU', 3208), -(3208091, 'KALIMANGGIS', 3208), -(3208100, 'CIAWIGEBANG', 3208), -(3208101, 'CIPICUNG', 3208), -(3208110, 'LEBAKWANGI', 3208), -(3208111, 'MALEBER', 3208), -(3208120, 'GARAWANGI', 3208), -(3208121, 'SIDANGAGUNG', 3208), -(3208130, 'KUNINGAN', 3208), -(3208140, 'CIGUGUR', 3208), -(3208150, 'KRAMATMULYA', 3208), -(3208160, 'JALAKSANA', 3208), -(3208161, 'JAPARA', 3208), -(3208170, 'CILIMUS', 3208), -(3208171, 'CIGANDAMEKAR', 3208), -(3208180, 'MANDIRANCAN', 3208), -(3208181, 'PANCALANG', 3208), -(3208190, 'PASAWAHAN', 3208), -(3209010, 'WALED', 3209), -(3209011, 'PASALEMAN', 3209), -(3209020, 'CILEDUG', 3209), -(3209021, 'PABUARAN', 3209), -(3209030, 'LOSARI', 3209), -(3209031, 'PABEDILAN', 3209), -(3209040, 'BABAKAN', 3209), -(3209041, 'GEBANG', 3209), -(3209050, 'KARANGSEMBUNG', 3209), -(3209051, 'KARANGWARENG', 3209), -(3209060, 'LEMAHABANG', 3209), -(3209061, 'SUSUKANLEBAK', 3209), -(3209070, 'SEDONG', 3209), -(3209080, 'ASTANAJAPURA', 3209), -(3209081, 'PANGENAN', 3209), -(3209090, 'MUNDU', 3209), -(3209100, 'BEBER', 3209), -(3209101, 'GREGED', 3209), -(3209111, 'TALUN', 3209), -(3209120, 'SUMBER', 3209), -(3209121, 'DUKUPUNTANG', 3209), -(3209130, 'PALIMANAN', 3209), -(3209140, 'PLUMBON', 3209), -(3209141, 'DEPOK', 3209), -(3209150, 'WERU', 3209), -(3209151, 'PLERED', 3209), -(3209161, 'TENGAH TANI', 3209), -(3209162, 'KEDAWUNG', 3209), -(3209171, 'GUNUNGJATI', 3209), -(3209180, 'KAPETAKAN', 3209), -(3209181, 'SURANENGGALA', 3209), -(3209190, 'KLANGENAN', 3209), -(3209191, 'JAMBLANG', 3209), -(3209200, 'ARJAWINANGUN', 3209), -(3209201, 'PANGURAGAN', 3209), -(3209210, 'CIWARINGIN', 3209), -(3209211, 'GEMPOL', 3209), -(3209220, 'SUSUKAN', 3209), -(3209230, 'GEGESIK', 3209), -(3209231, 'KALIWEDI', 3209), -(3210010, 'LEMAHSUGIH', 3210), -(3210020, 'BANTARUJEG', 3210), -(3210021, 'MALAUSMA', 3210), -(3210030, 'CIKIJING', 3210), -(3210031, 'CINGAMBUL', 3210), -(3210040, 'TALAGA', 3210), -(3210041, 'BANJARAN', 3210), -(3210050, 'ARGAPURA', 3210), -(3210060, 'MAJA', 3210), -(3210070, 'MAJALENGKA', 3210), -(3210080, 'CIGASONG', 3210), -(3210090, 'SUKAHAJI', 3210), -(3210091, 'SINDANG', 3210), -(3210100, 'RAJAGALUH', 3210), -(3210110, 'SINDANGWANGI', 3210), -(3210120, 'LEUWIMUNDING', 3210), -(3210130, 'PALASAH', 3210), -(3210140, 'JATIWANGI', 3210), -(3210150, 'DAWUAN', 3210), -(3210151, 'KASOKANDEL', 3210), -(3210160, 'PANYINGKIRAN', 3210), -(3210170, 'KADIPATEN', 3210), -(3210180, 'KERTAJATI', 3210), -(3210190, 'JATITUJUH', 3210), -(3210200, 'LIGUNG', 3210), -(3210210, 'SUMBERJAYA', 3210), -(3211010, 'JATINANGOR', 3211), -(3211020, 'CIMANGGUNG', 3211), -(3211030, 'TANJUNGSARI', 3211), -(3211031, 'SUKASARI', 3211), -(3211032, 'PAMULIHAN', 3211), -(3211040, 'RANCAKALONG', 3211), -(3211050, 'SUMEDANG SELATAN', 3211), -(3211060, 'SUMEDANG UTARA', 3211), -(3211061, 'GANEAS', 3211), -(3211070, 'SITURAJA', 3211), -(3211071, 'CISITU', 3211), -(3211080, 'DARMARAJA', 3211), -(3211090, 'CIBUGEL', 3211), -(3211100, 'WADO', 3211), -(3211101, 'JATINUNGGAL', 3211), -(3211111, 'JATIGEDE', 3211), -(3211120, 'TOMO', 3211), -(3211130, 'UJUNG JAYA', 3211), -(3211140, 'CONGGEANG', 3211), -(3211150, 'PASEH', 3211), -(3211160, 'CIMALAKA', 3211), -(3211161, 'CISARUA', 3211), -(3211170, 'TANJUNGKERTA', 3211), -(3211171, 'TANJUNGMEDAR', 3211), -(3211180, 'BUAHDUA', 3211), -(3211181, 'SURIAN', 3211), -(3212010, 'HAURGEULIS', 3212), -(3212011, 'GANTAR', 3212), -(3212020, 'KROYA', 3212), -(3212030, 'GABUSWETAN', 3212), -(3212040, 'CIKEDUNG', 3212), -(3212041, 'TERISI', 3212), -(3212050, 'LELEA', 3212), -(3212060, 'BANGODUA', 3212), -(3212061, 'TUKDANA', 3212), -(3212070, 'WIDASARI', 3212), -(3212080, 'KERTASEMAYA', 3212), -(3212081, 'SUKAGUMIWANG', 3212), -(3212090, 'KRANGKENG', 3212), -(3212100, 'KARANGAMPEL', 3212), -(3212101, 'KEDOKAN BUNDER', 3212), -(3212110, 'JUNTINYUAT', 3212), -(3212120, 'SLIYEG', 3212), -(3212130, 'JATIBARANG', 3212), -(3212140, 'BALONGAN', 3212), -(3212150, 'INDRAMAYU', 3212), -(3212160, 'SINDANG', 3212), -(3212161, 'CANTIGI', 3212), -(3212162, 'PASEKAN', 3212), -(3212170, 'LOHBENER', 3212), -(3212171, 'ARAHAN', 3212), -(3212180, 'LOSARANG', 3212), -(3212190, 'KANDANGHAUR', 3212), -(3212200, 'BONGAS', 3212), -(3212210, 'ANJATAN', 3212), -(3212220, 'SUKRA', 3212), -(3212221, 'PATROL', 3212), -(3213010, 'SAGALAHERANG', 3213), -(3213011, 'SERANGPANJANG', 3213), -(3213020, 'JALANCAGAK', 3213), -(3213021, 'CIATER', 3213), -(3213030, 'CISALAK', 3213), -(3213031, 'KASOMALANG', 3213), -(3213040, 'TANJUNGSIANG', 3213), -(3213050, 'CIJAMBE', 3213), -(3213060, 'CIBOGO', 3213), -(3213070, 'SUBANG', 3213), -(3213080, 'KALIJATI', 3213), -(3213081, 'DAWUAN', 3213), -(3213090, 'CIPEUNDEUY', 3213), -(3213100, 'PABUARAN', 3213), -(3213110, 'PATOKBEUSI', 3213), -(3213120, 'PURWADADI', 3213), -(3213130, 'CIKAUM', 3213), -(3213140, 'PAGADEN', 3213), -(3213141, 'PAGADEN BARAT', 3213), -(3213150, 'CIPUNAGARA', 3213), -(3213160, 'COMPRENG', 3213), -(3213170, 'BINONG', 3213), -(3213171, 'TAMBAKDAHAN', 3213), -(3213180, 'CIASEM', 3213), -(3213190, 'PAMANUKAN', 3213), -(3213191, 'SUKASARI', 3213), -(3213200, 'PUSAKANAGARA', 3213), -(3213201, 'PUSAKAJAYA', 3213), -(3213210, 'LEGONKULON', 3213), -(3213220, 'BLANAKAN', 3213), -(3214010, 'JATILUHUR', 3214), -(3214011, 'SUKASARI', 3214), -(3214020, 'MANIIS', 3214), -(3214030, 'TEGAL WARU', 3214), -(3214040, 'PLERED', 3214), -(3214050, 'SUKATANI', 3214), -(3214060, 'DARANGDAN', 3214), -(3214070, 'BOJONG', 3214), -(3214080, 'WANAYASA', 3214), -(3214081, 'KIARAPEDES', 3214), -(3214090, 'PASAWAHAN', 3214), -(3214091, 'PONDOK SALAM', 3214), -(3214100, 'PURWAKARTA', 3214), -(3214101, 'BABAKANCIKAO', 3214), -(3214110, 'CAMPAKA', 3214), -(3214111, 'CIBATU', 3214), -(3214112, 'BUNGURSARI', 3214), -(3215010, 'PANGKALAN', 3215), -(3215011, 'TEGALWARU', 3215), -(3215020, 'CIAMPEL', 3215), -(3215031, 'TELUKJAMBE TIMUR', 3215), -(3215032, 'TELUKJAMBE BARAT', 3215), -(3215040, 'KLARI', 3215), -(3215050, 'CIKAMPEK', 3215), -(3215051, 'PURWASARI', 3215), -(3215060, 'TIRTAMULYA', 3215), -(3215070, 'JATISARI', 3215), -(3215071, 'BANYUSARI', 3215), -(3215072, 'KOTABARU', 3215), -(3215081, 'CILAMAYA WETAN', 3215), -(3215082, 'CILAMAYA KULON', 3215), -(3215090, 'LEMAHABANG', 3215), -(3215100, 'TALAGASARI', 3215), -(3215111, 'MAJALAYA', 3215), -(3215112, 'KARAWANG TIMUR', 3215), -(3215113, 'KARAWANG BARAT', 3215), -(3215120, 'RAWAMERTA', 3215), -(3215130, 'TEMPURAN', 3215), -(3215140, 'KUTAWALUYA', 3215), -(3215150, 'RENGASDENGKLOK', 3215), -(3215151, 'JAYAKERTA', 3215), -(3215160, 'PEDES', 3215), -(3215161, 'CILEBAR', 3215), -(3215170, 'CIBUAYA', 3215), -(3215180, 'TIRTAJAYA', 3215), -(3215190, 'BATUJAYA', 3215), -(3215200, 'PAKISJAYA', 3215), -(3216010, 'SETU', 3216), -(3216021, 'SERANG BARU', 3216), -(3216022, 'CIKARANG PUSAT', 3216), -(3216023, 'CIKARANG SELATAN', 3216), -(3216030, 'CIBARUSAH', 3216), -(3216031, 'BOJONGMANGU', 3216), -(3216041, 'CIKARANG TIMUR', 3216), -(3216050, 'KEDUNGWARINGIN', 3216), -(3216061, 'CIKARANG UTARA', 3216), -(3216062, 'KARANGBAHAGIA', 3216), -(3216070, 'CIBITUNG', 3216), -(3216071, 'CIKARANG BARAT', 3216), -(3216081, 'TAMBUN SELATAN', 3216), -(3216082, 'TAMBUN UTARA', 3216), -(3216090, 'BABELAN', 3216), -(3216100, 'TARUMAJAYA', 3216), -(3216110, 'TAMBELANG', 3216), -(3216111, 'SUKAWANGI', 3216), -(3216120, 'SUKATANI', 3216), -(3216121, 'SUKAKARYA', 3216), -(3216130, 'PEBAYURAN', 3216), -(3216140, 'CABANGBUNGIN', 3216), -(3216150, 'MUARA GEMBONG', 3216), -(3217010, 'RONGGA', 3217), -(3217020, 'GUNUNGHALU', 3217), -(3217030, 'SINDANGKERTA', 3217), -(3217040, 'CILILIN', 3217), -(3217050, 'CIHAMPELAS', 3217), -(3217060, 'CIPONGKOR', 3217), -(3217070, 'BATUJAJAR', 3217), -(3217080, 'CIPATAT', 3217), -(3217090, 'PADALARANG', 3217), -(3217100, 'NGAMPRAH', 3217), -(3217110, 'PARONGPONG', 3217), -(3217120, 'LEMBANG', 3217), -(3217130, 'CISARUA', 3217), -(3217140, 'CIKALONG WETAN', 3217), -(3217150, 'CIPEUNDEUY', 3217), -(3271010, 'BOGOR SELATAN', 3271), -(3271020, 'BOGOR TIMUR', 3271), -(3271030, 'BOGOR UTARA', 3271), -(3271040, 'BOGOR TENGAH', 3271), -(3271050, 'BOGOR BARAT', 3271), -(3271060, 'TANAH SEREAL', 3271), -(3272010, 'BAROS', 3272), -(3272011, 'LEMBURSITU', 3272), -(3272012, 'CIBEUREUM', 3272), -(3272020, 'CITAMIANG', 3272), -(3272030, 'WARUDOYONG', 3272), -(3272040, 'GUNUNG PUYUH', 3272), -(3272050, 'CIKOLE', 3272), -(3273010, 'BANDUNG KULON', 3273), -(3273020, 'BABAKAN CIPARAY', 3273), -(3273030, 'BOJONGLOA KALER', 3273), -(3273040, 'BOJONGLOA KIDUL', 3273), -(3273050, 'ASTANAANYAR', 3273), -(3273060, 'REGOL', 3273), -(3273070, 'LENGKONG', 3273), -(3273080, 'BANDUNG KIDUL', 3273), -(3273090, 'BUAHBATU', 3273), -(3273100, 'RANCASARI', 3273), -(3273101, 'GEDEBAGE', 3273), -(3273110, 'CIBIRU', 3273), -(3273111, 'PANYILEUKAN', 3273), -(3273120, 'UJUNG BERUNG', 3273), -(3273121, 'CINAMBO', 3273), -(3273130, 'ARCAMANIK', 3273), -(3273141, 'ANTAPANI', 3273), -(3273142, 'MANDALAJATI', 3273), -(3273150, 'KIARACONDONG', 3273), -(3273160, 'BATUNUNGGAL', 3273), -(3273170, 'SUMUR BANDUNG', 3273), -(3273180, 'ANDIR', 3273), -(3273190, 'CICENDO', 3273), -(3273200, 'BANDUNG WETAN', 3273), -(3273210, 'CIBEUNYING KIDUL', 3273), -(3273220, 'CIBEUNYING KALER', 3273), -(3273230, 'COBLONG', 3273), -(3273240, 'SUKAJADI', 3273), -(3273250, 'SUKASARI', 3273), -(3273260, 'CIDADAP', 3273), -(3274010, 'HARJAMUKTI', 3274), -(3274020, 'LEMAHWUNGKUK', 3274), -(3274030, 'PEKALIPAN', 3274), -(3274040, 'KESAMBI', 3274), -(3274050, 'KEJAKSAN', 3274), -(3275010, 'PONDOKGEDE', 3275), -(3275011, 'JATISAMPURNA', 3275), -(3275012, 'PONDOKMELATI', 3275), -(3275020, 'JATIASIH', 3275), -(3275030, 'BANTARGEBANG', 3275), -(3275031, 'MUSTIKAJAYA', 3275), -(3275040, 'BEKASI TIMUR', 3275), -(3275041, 'RAWALUMBU', 3275), -(3275050, 'BEKASI SELATAN', 3275), -(3275060, 'BEKASI BARAT', 3275), -(3275061, 'MEDAN SATRIA', 3275), -(3275070, 'BEKASI UTARA', 3275), -(3276010, 'SAWANGAN', 3276), -(3276011, 'BOJONGSARI', 3276), -(3276020, 'PANCORAN MAS', 3276), -(3276021, 'CIPAYUNG', 3276), -(3276030, 'SUKMA JAYA', 3276), -(3276031, 'CILODONG', 3276), -(3276040, 'CIMANGGIS', 3276), -(3276041, 'TAPOS', 3276), -(3276050, 'BEJI', 3276), -(3276060, 'LIMO', 3276), -(3276061, 'CINERE', 3276), -(3277010, 'CIMAHI SELATAN', 3277), -(3277020, 'CIMAHI TENGAH', 3277), -(3277030, 'CIMAHI UTARA', 3277), -(3278010, 'KAWALU', 3278), -(3278020, 'TAMANSARI', 3278), -(3278030, 'CIBEUREUM', 3278), -(3278031, 'PURBARATU', 3278), -(3278040, 'TAWANG', 3278), -(3278050, 'CIHIDEUNG', 3278), -(3278060, 'MANGKUBUMI', 3278), -(3278070, 'INDIHIANG', 3278), -(3278071, 'BUNGURSARI', 3278), -(3278080, 'CIPEDES', 3278), -(3279010, 'BANJAR', 3279), -(3279020, 'PURWAHARJA', 3279), -(3279030, 'PATARUMAN', 3279), -(3279040, 'LANGENSARI', 3279), -(3301010, 'DAYEUHLUHUR', 3301), -(3301020, 'WANAREJA', 3301), -(3301030, 'MAJENANG', 3301), -(3301040, 'CIMANGGU', 3301), -(3301050, 'KARANGPUCUNG', 3301), -(3301060, 'CIPARI', 3301), -(3301070, 'SIDAREJA', 3301), -(3301080, 'KEDUNGREJA', 3301), -(3301090, 'PATIMUAN', 3301), -(3301100, 'GANDRUNGMANGU', 3301), -(3301110, 'BANTARSARI', 3301), -(3301120, 'KAWUNGANTEN', 3301), -(3301121, 'KAMPUNG LAUT', 3301), -(3301130, 'JERUKLEGI', 3301), -(3301140, 'KESUGIHAN', 3301), -(3301150, 'ADIPALA', 3301), -(3301160, 'MAOS', 3301), -(3301170, 'SAMPANG', 3301), -(3301180, 'KROYA', 3301), -(3301190, 'BINANGUN', 3301), -(3301200, 'NUSAWUNGU', 3301), -(3301710, 'CILACAP SELATAN', 3301), -(3301720, 'CILACAP TENGAH', 3301), -(3301730, 'CILACAP UTARA', 3301), -(3302010, 'LUMBIR', 3302), -(3302020, 'WANGON', 3302), -(3302030, 'JATILAWANG', 3302), -(3302040, 'RAWALO', 3302), -(3302050, 'KEBASEN', 3302), -(3302060, 'KEMRANJEN', 3302), -(3302070, 'SUMPIUH', 3302), -(3302080, 'TAMBAK', 3302), -(3302090, 'SOMAGEDE', 3302), -(3302100, 'KALIBAGOR', 3302), -(3302110, 'BANYUMAS', 3302), -(3302120, 'PATIKRAJA', 3302), -(3302130, 'PURWOJATI', 3302), -(3302140, 'AJIBARANG', 3302), -(3302150, 'GUMELAR', 3302), -(3302160, 'PEKUNCEN', 3302), -(3302170, 'CILONGOK', 3302), -(3302180, 'KARANGLEWAS', 3302), -(3302190, 'KEDUNG BANTENG', 3302), -(3302200, 'BATURRADEN', 3302), -(3302210, 'SUMBANG', 3302), -(3302220, 'KEMBARAN', 3302), -(3302230, 'SOKARAJA', 3302), -(3302710, 'PURWOKERTO SELATAN', 3302), -(3302720, 'PURWOKERTO BARAT', 3302), -(3302730, 'PURWOKERTO TIMUR', 3302), -(3302740, 'PURWOKERTO UTARA', 3302), -(3303010, 'KEMANGKON', 3303), -(3303020, 'BUKATEJA', 3303), -(3303030, 'KEJOBONG', 3303), -(3303040, 'PENGADEGAN', 3303), -(3303050, 'KALIGONDANG', 3303), -(3303060, 'PURBALINGGA', 3303), -(3303070, 'KALIMANAH', 3303), -(3303080, 'PADAMARA', 3303), -(3303090, 'KUTASARI', 3303), -(3303100, 'BOJONGSARI', 3303), -(3303110, 'MREBET', 3303), -(3303120, 'BOBOTSARI', 3303), -(3303130, 'KARANGREJA', 3303), -(3303131, 'KARANGJAMBU', 3303), -(3303140, 'KARANGANYAR', 3303), -(3303141, 'KERTANEGARA', 3303), -(3303150, 'KARANGMONCOL', 3303), -(3303160, 'REMBANG', 3303), -(3304010, 'SUSUKAN', 3304), -(3304020, 'PURWOREJO KLAMPOK', 3304), -(3304030, 'MANDIRAJA', 3304), -(3304040, 'PURWANEGARA', 3304), -(3304050, 'BAWANG', 3304), -(3304060, 'BANJARNEGARA', 3304), -(3304061, 'PAGEDONGAN', 3304), -(3304070, 'SIGALUH', 3304), -(3304080, 'MADUKARA', 3304), -(3304090, 'BANJARMANGU', 3304), -(3304100, 'WANADADI', 3304), -(3304110, 'RAKIT', 3304), -(3304120, 'PUNGGELAN', 3304), -(3304130, 'KARANGKOBAR', 3304), -(3304140, 'PAGENTAN', 3304), -(3304150, 'PEJAWARAN', 3304), -(3304160, 'BATUR', 3304), -(3304170, 'WANAYASA', 3304), -(3304180, 'KALIBENING', 3304), -(3304181, 'PANDANARUM', 3304), -(3305010, 'AYAH', 3305), -(3305020, 'BUAYAN', 3305), -(3305030, 'PURING', 3305), -(3305040, 'PETANAHAN', 3305), -(3305050, 'KLIRONG', 3305), -(3305060, 'BULUSPESANTREN', 3305), -(3305070, 'AMBAL', 3305), -(3305080, 'MIRIT', 3305), -(3305081, 'BONOROWO', 3305), -(3305090, 'PREMBUN', 3305), -(3305091, 'PADURESO', 3305), -(3305100, 'KUTOWINANGUN', 3305), -(3305110, 'ALIAN', 3305), -(3305111, 'PONCOWARNO', 3305), -(3305120, 'KEBUMEN', 3305), -(3305130, 'PEJAGOAN', 3305), -(3305140, 'SRUWENG', 3305), -(3305150, 'ADIMULYO', 3305), -(3305160, 'KUWARASAN', 3305), -(3305170, 'ROWOKELE', 3305), -(3305180, 'SEMPOR', 3305), -(3305190, 'GOMBONG', 3305), -(3305200, 'KARANGANYAR', 3305), -(3305210, 'KARANGGAYAM', 3305), -(3305220, 'SADANG', 3305), -(3305221, 'KARANGSAMBUNG', 3305), -(3306010, 'GRABAG', 3306), -(3306020, 'NGOMBOL', 3306), -(3306030, 'PURWODADI', 3306), -(3306040, 'BAGELEN', 3306), -(3306050, 'KALIGESING', 3306), -(3306060, 'PURWOREJO', 3306), -(3306070, 'BANYU URIP', 3306), -(3306080, 'BAYAN', 3306), -(3306090, 'KUTOARJO', 3306), -(3306100, 'BUTUH', 3306), -(3306110, 'PITURUH', 3306), -(3306120, 'KEMIRI', 3306), -(3306130, 'BRUNO', 3306), -(3306140, 'GEBANG', 3306), -(3306150, 'LOANO', 3306), -(3306160, 'BENER', 3306), -(3307010, 'WADASLINTANG', 3307), -(3307020, 'KEPIL', 3307), -(3307030, 'SAPURAN', 3307), -(3307031, 'KALIBAWANG', 3307), -(3307040, 'KALIWIRO', 3307), -(3307050, 'LEKSONO', 3307), -(3307051, 'SUKOHARJO', 3307), -(3307060, 'SELOMERTO', 3307), -(3307070, 'KALIKAJAR', 3307), -(3307080, 'KERTEK', 3307), -(3307090, 'WONOSOBO', 3307), -(3307100, 'WATUMALANG', 3307), -(3307110, 'MOJOTENGAH', 3307), -(3307120, 'GARUNG', 3307), -(3307130, 'KEJAJAR', 3307), -(3308010, 'SALAMAN', 3308), -(3308020, 'BOROBUDUR', 3308), -(3308030, 'NGLUWAR', 3308), -(3308040, 'SALAM', 3308), -(3308050, 'SRUMBUNG', 3308), -(3308060, 'DUKUN', 3308), -(3308070, 'MUNTILAN', 3308), -(3308080, 'MUNGKID', 3308), -(3308090, 'SAWANGAN', 3308), -(3308100, 'CANDIMULYO', 3308), -(3308110, 'MERTOYUDAN', 3308), -(3308120, 'TEMPURAN', 3308), -(3308130, 'KAJORAN', 3308), -(3308140, 'KALIANGKRIK', 3308), -(3308150, 'BANDONGAN', 3308), -(3308160, 'WINDUSARI', 3308), -(3308170, 'SECANG', 3308), -(3308180, 'TEGALREJO', 3308), -(3308190, 'PAKIS', 3308), -(3308200, 'GRABAG', 3308), -(3308210, 'NGABLAK', 3308), -(3309010, 'SELO', 3309), -(3309020, 'AMPEL', 3309), -(3309030, 'CEPOGO', 3309), -(3309040, 'MUSUK', 3309), -(3309050, 'BOYOLALI', 3309), -(3309060, 'MOJOSONGO', 3309), -(3309070, 'TERAS', 3309), -(3309080, 'SAWIT', 3309), -(3309090, 'BANYUDONO', 3309), -(3309100, 'SAMBI', 3309), -(3309110, 'NGEMPLAK', 3309), -(3309120, 'NOGOSARI', 3309), -(3309130, 'SIMO', 3309), -(3309140, 'KARANGGEDE', 3309), -(3309150, 'KLEGO', 3309), -(3309160, 'ANDONG', 3309), -(3309170, 'KEMUSU', 3309), -(3309180, 'WONOSEGORO', 3309), -(3309190, 'JUWANGI', 3309), -(3310010, 'PRAMBANAN', 3310), -(3310020, 'GANTIWARNO', 3310), -(3310030, 'WEDI', 3310), -(3310040, 'BAYAT', 3310), -(3310050, 'CAWAS', 3310), -(3310060, 'TRUCUK', 3310), -(3310070, 'KALIKOTES', 3310), -(3310080, 'KEBONARUM', 3310), -(3310090, 'JOGONALAN', 3310), -(3310100, 'MANISRENGGO', 3310), -(3310110, 'KARANGNONGKO', 3310), -(3310120, 'NGAWEN', 3310), -(3310130, 'CEPER', 3310), -(3310140, 'PEDAN', 3310), -(3310150, 'KARANGDOWO', 3310), -(3310160, 'JUWIRING', 3310), -(3310170, 'WONOSARI', 3310), -(3310180, 'DELANGGU', 3310), -(3310190, 'POLANHARJO', 3310), -(3310200, 'KARANGANOM', 3310), -(3310210, 'TULUNG', 3310), -(3310220, 'JATINOM', 3310), -(3310230, 'KEMALANG', 3310), -(3310710, 'KLATEN SELATAN', 3310), -(3310720, 'KLATEN TENGAH', 3310), -(3310730, 'KLATEN UTARA', 3310), -(3311010, 'WERU', 3311), -(3311020, 'BULU', 3311), -(3311030, 'TAWANGSARI', 3311), -(3311040, 'SUKOHARJO', 3311), -(3311050, 'NGUTER', 3311), -(3311060, 'BENDOSARI', 3311), -(3311070, 'POLOKARTO', 3311), -(3311080, 'MOJOLABAN', 3311), -(3311090, 'GROGOL', 3311), -(3311100, 'BAKI', 3311), -(3311110, 'GATAK', 3311), -(3311120, 'KARTASURA', 3311), -(3312010, 'PRACIMANTORO', 3312), -(3312020, 'PARANGGUPITO', 3312), -(3312030, 'GIRITONTRO', 3312), -(3312040, 'GIRIWOYO', 3312), -(3312050, 'BATUWARNO', 3312), -(3312060, 'KARANGTENGAH', 3312), -(3312070, 'TIRTOMOYO', 3312), -(3312080, 'NGUNTORONADI', 3312), -(3312090, 'BATURETNO', 3312), -(3312100, 'EROMOKO', 3312), -(3312110, 'WURYANTORO', 3312), -(3312120, 'MANYARAN', 3312), -(3312130, 'SELOGIRI', 3312), -(3312140, 'WONOGIRI', 3312), -(3312150, 'NGADIROJO', 3312), -(3312160, 'SIDOHARJO', 3312), -(3312170, 'JATIROTO', 3312), -(3312180, 'KISMANTORO', 3312), -(3312190, 'PURWANTORO', 3312), -(3312200, 'BULUKERTO', 3312), -(3312201, 'PUHPELEM', 3312), -(3312210, 'SLOGOHIMO', 3312), -(3312220, 'JATISRONO', 3312), -(3312230, 'JATIPURNO', 3312), -(3312240, 'GIRIMARTO', 3312), -(3313010, 'JATIPURO', 3313), -(3313020, 'JATIYOSO', 3313), -(3313030, 'JUMAPOLO', 3313), -(3313040, 'JUMANTONO', 3313), -(3313050, 'MATESIH', 3313), -(3313060, 'TAWANGMANGU', 3313), -(3313070, 'NGARGOYOSO', 3313), -(3313080, 'KARANGPANDAN', 3313), -(3313090, 'KARANGANYAR', 3313), -(3313100, 'TASIKMADU', 3313), -(3313110, 'JATEN', 3313), -(3313120, 'COLOMADU', 3313), -(3313130, 'GONDANGREJO', 3313), -(3313140, 'KEBAKKRAMAT', 3313), -(3313150, 'MOJOGEDANG', 3313), -(3313160, 'KERJO', 3313), -(3313170, 'JENAWI', 3313), -(3314010, 'KALIJAMBE', 3314), -(3314020, 'PLUPUH', 3314), -(3314030, 'MASARAN', 3314), -(3314040, 'KEDAWUNG', 3314), -(3314050, 'SAMBIREJO', 3314), -(3314060, 'GONDANG', 3314), -(3314070, 'SAMBUNG MACAN', 3314), -(3314080, 'NGRAMPAL', 3314), -(3314090, 'KARANGMALANG', 3314), -(3314100, 'SRAGEN', 3314), -(3314110, 'SIDOHARJO', 3314), -(3314120, 'TANON', 3314), -(3314130, 'GEMOLONG', 3314), -(3314140, 'MIRI', 3314), -(3314150, 'SUMBERLAWANG', 3314), -(3314160, 'MONDOKAN', 3314), -(3314170, 'SUKODONO', 3314), -(3314180, 'GESI', 3314), -(3314190, 'TANGEN', 3314), -(3314200, 'JENAR', 3314), -(3315010, 'KEDUNGJATI', 3315), -(3315020, 'KARANGRAYUNG', 3315), -(3315030, 'PENAWANGAN', 3315), -(3315040, 'TOROH', 3315), -(3315050, 'GEYER', 3315), -(3315060, 'PULOKULON', 3315), -(3315070, 'KRADENAN', 3315), -(3315080, 'GABUS', 3315), -(3315090, 'NGARINGAN', 3315), -(3315100, 'WIROSARI', 3315), -(3315110, 'TAWANGHARJO', 3315), -(3315120, 'GROBOGAN', 3315), -(3315130, 'PURWODADI', 3315), -(3315140, 'BRATI', 3315), -(3315150, 'KLAMBU', 3315), -(3315160, 'GODONG', 3315), -(3315170, 'GUBUG', 3315), -(3315180, 'TEGOWANU', 3315), -(3315190, 'TANGGUNGHARJO', 3315), -(3316010, 'JATI', 3316), -(3316020, 'RANDUBLATUNG', 3316), -(3316030, 'KRADENAN', 3316), -(3316040, 'KEDUNGTUBAN', 3316), -(3316050, 'CEPU', 3316), -(3316060, 'SAMBONG', 3316), -(3316070, 'JIKEN', 3316), -(3316080, 'BOGOREJO', 3316), -(3316090, 'JEPON', 3316), -(3316100, 'KOTA BLORA', 3316), -(3316110, 'BANJAREJO', 3316), -(3316120, 'TUNJUNGAN', 3316), -(3316130, 'JAPAH', 3316), -(3316140, 'NGAWEN', 3316), -(3316150, 'KUNDURAN', 3316), -(3316160, 'TODANAN', 3316), -(3317010, 'SUMBER', 3317), -(3317020, 'BULU', 3317), -(3317030, 'GUNEM', 3317), -(3317040, 'SALE', 3317), -(3317050, 'SARANG', 3317), -(3317060, 'SEDAN', 3317), -(3317070, 'PAMOTAN', 3317), -(3317080, 'SULANG', 3317), -(3317090, 'KALIORI', 3317), -(3317100, 'REMBANG', 3317), -(3317110, 'PANCUR', 3317), -(3317120, 'KRAGAN', 3317), -(3317130, 'SLUKE', 3317), -(3317140, 'LASEM', 3317), -(3318010, 'SUKOLILO', 3318), -(3318020, 'KAYEN', 3318), -(3318030, 'TAMBAKROMO', 3318), -(3318040, 'WINONG', 3318), -(3318050, 'PUCAKWANGI', 3318), -(3318060, 'JAKEN', 3318), -(3318070, 'BATANGAN', 3318), -(3318080, 'JUWANA', 3318), -(3318090, 'JAKENAN', 3318), -(3318100, 'PATI', 3318), -(3318110, 'GABUS', 3318), -(3318120, 'MARGOREJO', 3318), -(3318130, 'GEMBONG', 3318), -(3318140, 'TLOGOWUNGU', 3318), -(3318150, 'WEDARIJAKSA', 3318), -(3318160, 'TRANGKIL', 3318), -(3318170, 'MARGOYOSO', 3318), -(3318180, 'GUNUNG WUNGKAL', 3318), -(3318190, 'CLUWAK', 3318), -(3318200, 'TAYU', 3318), -(3318210, 'DUKUHSETI', 3318), -(3319010, 'KALIWUNGU', 3319), -(3319020, 'KOTA KUDUS', 3319), -(3319030, 'JATI', 3319), -(3319040, 'UNDAAN', 3319), -(3319050, 'MEJOBO', 3319), -(3319060, 'JEKULO', 3319), -(3319070, 'BAE', 3319), -(3319080, 'GEBOG', 3319), -(3319090, 'DAWE', 3319), -(3320010, 'KEDUNG', 3320), -(3320020, 'PECANGAAN', 3320), -(3320021, 'KALINYAMATAN', 3320), -(3320030, 'WELAHAN', 3320), -(3320040, 'MAYONG', 3320), -(3320050, 'NALUMSARI', 3320), -(3320060, 'BATEALIT', 3320), -(3320070, 'TAHUNAN', 3320), -(3320080, 'JEPARA', 3320), -(3320090, 'MLONGGO', 3320), -(3320091, 'PAKIS AJI', 3320), -(3320100, 'BANGSRI', 3320), -(3320101, 'KEMBANG', 3320), -(3320110, 'KELING', 3320), -(3320111, 'DONOROJO', 3320), -(3320120, 'KARIMUNJAWA', 3320), -(3321010, 'MRANGGEN', 3321), -(3321020, 'KARANGAWEN', 3321), -(3321030, 'GUNTUR', 3321), -(3321040, 'SAYUNG', 3321), -(3321050, 'KARANG TENGAH', 3321), -(3321060, 'BONANG', 3321), -(3321070, 'DEMAK', 3321), -(3321080, 'WONOSALAM', 3321), -(3321090, 'DEMPET', 3321), -(3321091, 'KEBONAGUNG', 3321), -(3321100, 'GAJAH', 3321), -(3321110, 'KARANGANYAR', 3321), -(3321120, 'MIJEN', 3321), -(3321130, 'WEDUNG', 3321), -(3322010, 'GETASAN', 3322), -(3322020, 'TENGARAN', 3322), -(3322030, 'SUSUKAN', 3322), -(3322031, 'KALIWUNGU', 3322), -(3322040, 'SURUH', 3322), -(3322050, 'PABELAN', 3322), -(3322060, 'TUNTANG', 3322), -(3322070, 'BANYUBIRU', 3322), -(3322080, 'JAMBU', 3322), -(3322090, 'SUMOWONO', 3322), -(3322100, 'AMBARAWA', 3322), -(3322101, 'BANDUNGAN', 3322), -(3322110, 'BAWEN', 3322), -(3322120, 'BRINGIN', 3322), -(3322121, 'BANCAK', 3322), -(3322130, 'PRINGAPUS', 3322), -(3322140, 'BERGAS', 3322), -(3322151, 'UNGARAN BARAT', 3322), -(3322152, 'UNGARAN TIMUR', 3322), -(3323010, 'PARAKAN', 3323), -(3323011, 'KLEDUNG', 3323), -(3323012, 'BANSARI', 3323), -(3323020, 'BULU', 3323), -(3323030, 'TEMANGGUNG', 3323), -(3323031, 'TLOGOMULYO', 3323), -(3323040, 'TEMBARAK', 3323), -(3323041, 'SELOPAMPANG', 3323), -(3323050, 'KRANGGAN', 3323), -(3323060, 'PRINGSURAT', 3323), -(3323070, 'KALORAN', 3323), -(3323080, 'KANDANGAN', 3323), -(3323090, 'KEDU', 3323), -(3323100, 'NGADIREJO', 3323), -(3323110, 'JUMO', 3323), -(3323111, 'GEMAWANG', 3323), -(3323120, 'CANDIROTO', 3323), -(3323121, 'BEJEN', 3323), -(3323130, 'TRETEP', 3323), -(3323131, 'WONOBOYO', 3323), -(3324010, 'PLANTUNGAN', 3324), -(3324020, 'SUKOREJO', 3324), -(3324030, 'PAGERRUYUNG', 3324), -(3324040, 'PATEAN', 3324), -(3324050, 'SINGOROJO', 3324), -(3324060, 'LIMBANGAN', 3324), -(3324070, 'BOJA', 3324), -(3324080, 'KALIWUNGU', 3324), -(3324081, 'KALIWUNGU SELATAN', 3324), -(3324090, 'BRANGSONG', 3324), -(3324100, 'PEGANDON', 3324), -(3324101, 'NGAMPEL', 3324), -(3324110, 'GEMUH', 3324), -(3324111, 'RINGINARUM', 3324), -(3324120, 'WELERI', 3324), -(3324130, 'ROWOSARI', 3324), -(3324140, 'KANGKUNG', 3324), -(3324150, 'CEPIRING', 3324), -(3324160, 'PATEBON', 3324), -(3324170, 'KOTA KENDAL', 3324), -(3325010, 'WONOTUNGGAL', 3325), -(3325020, 'BANDAR', 3325), -(3325030, 'BLADO', 3325), -(3325040, 'REBAN', 3325), -(3325050, 'BAWANG', 3325), -(3325060, 'TERSONO', 3325), -(3325070, 'GRINGSING', 3325), -(3325080, 'LIMPUNG', 3325), -(3325081, 'BANYUPUTIH', 3325), -(3325090, 'SUBAH', 3325), -(3325091, 'PECALUNGAN', 3325), -(3325100, 'TULIS', 3325), -(3325101, 'KANDEMAN', 3325), -(3325110, 'BATANG', 3325), -(3325120, 'WARUNG ASEM', 3325), -(3326010, 'KANDANGSERANG', 3326), -(3326020, 'PANINGGARAN', 3326), -(3326030, 'LEBAKBARANG', 3326), -(3326040, 'PETUNGKRIONO', 3326), -(3326050, 'TALUN', 3326), -(3326060, 'DORO', 3326), -(3326070, 'KARANGANYAR', 3326), -(3326080, 'KAJEN', 3326), -(3326090, 'KESESI', 3326), -(3326100, 'SRAGI', 3326), -(3326101, 'SIWALAN', 3326), -(3326110, 'BOJONG', 3326), -(3326120, 'WONOPRINGGO', 3326), -(3326130, 'KEDUNGWUNI', 3326), -(3326131, 'KARANGDADAP', 3326), -(3326140, 'BUARAN', 3326), -(3326150, 'TIRTO', 3326), -(3326160, 'WIRADESA', 3326), -(3326161, 'WONOKERTO', 3326), -(3327010, 'MOGA', 3327), -(3327011, 'WARUNGPRING', 3327), -(3327020, 'PULOSARI', 3327), -(3327030, 'BELIK', 3327), -(3327040, 'WATUKUMPUL', 3327), -(3327050, 'BODEH', 3327), -(3327060, 'BANTARBOLANG', 3327), -(3327070, 'RANDUDONGKAL', 3327), -(3327080, 'PEMALANG', 3327), -(3327090, 'TAMAN', 3327), -(3327100, 'PETARUKAN', 3327), -(3327110, 'AMPELGADING', 3327), -(3327120, 'COMAL', 3327), -(3327130, 'ULUJAMI', 3327), -(3328010, 'MARGASARI', 3328), -(3328020, 'BUMIJAWA', 3328), -(3328030, 'BOJONG', 3328), -(3328040, 'BALAPULANG', 3328), -(3328050, 'PAGERBARANG', 3328), -(3328060, 'LEBAKSIU', 3328), -(3328070, 'JATINEGARA', 3328), -(3328080, 'KEDUNG BANTENG', 3328), -(3328090, 'PANGKAH', 3328), -(3328100, 'SLAWI', 3328), -(3328110, 'DUKUHWARU', 3328), -(3328120, 'ADIWERNA', 3328), -(3328130, 'DUKUHTURI', 3328), -(3328140, 'TALANG', 3328), -(3328150, 'TARUB', 3328), -(3328160, 'KRAMAT', 3328), -(3328170, 'SURADADI', 3328), -(3328180, 'WARUREJA', 3328), -(3329010, 'SALEM', 3329), -(3329020, 'BANTARKAWUNG', 3329), -(3329030, 'BUMIAYU', 3329), -(3329040, 'PAGUYANGAN', 3329), -(3329050, 'SIRAMPOG', 3329), -(3329060, 'TONJONG', 3329), -(3329070, 'LARANGAN', 3329), -(3329080, 'KETANGGUNGAN', 3329), -(3329090, 'BANJARHARJO', 3329), -(3329100, 'LOSARI', 3329), -(3329110, 'TANJUNG', 3329), -(3329120, 'KERSANA', 3329), -(3329130, 'BULAKAMBA', 3329), -(3329140, 'WANASARI', 3329), -(3329150, 'SONGGOM', 3329), -(3329160, 'JATIBARANG', 3329), -(3329170, 'BREBES', 3329), -(3371010, 'MAGELANG SELATAN', 3371), -(3371011, 'MAGELANG TENGAH', 3371), -(3371020, 'MAGELANG UTARA', 3371), -(3372010, 'LAWEYAN', 3372), -(3372020, 'SERENGAN', 3372), -(3372030, 'PASAR KLIWON', 3372), -(3372040, 'JEBRES', 3372), -(3372050, 'BANJARSARI', 3372), -(3373010, 'ARGOMULYO', 3373), -(3373020, 'TINGKIR', 3373), -(3373030, 'SIDOMUKTI', 3373), -(3373040, 'SIDOREJO', 3373), -(3374010, 'MIJEN', 3374), -(3374020, 'GUNUNG PATI', 3374), -(3374030, 'BANYUMANIK', 3374), -(3374040, 'GAJAH MUNGKUR', 3374), -(3374050, 'SEMARANG SELATAN', 3374), -(3374060, 'CANDISARI', 3374), -(3374070, 'TEMBALANG', 3374), -(3374080, 'PEDURUNGAN', 3374), -(3374090, 'GENUK', 3374), -(3374100, 'GAYAMSARI', 3374), -(3374110, 'SEMARANG TIMUR', 3374), -(3374120, 'SEMARANG UTARA', 3374), -(3374130, 'SEMARANG TENGAH', 3374), -(3374140, 'SEMARANG BARAT', 3374), -(3374150, 'TUGU', 3374), -(3374160, 'NGALIYAN', 3374), -(3375010, 'PEKALONGAN BARAT', 3375), -(3375020, 'PEKALONGAN TIMUR', 3375), -(3375030, 'PEKALONGAN SELATAN', 3375), -(3375040, 'PEKALONGAN UTARA', 3375), -(3376010, 'TEGAL SELATAN', 3376), -(3376020, 'TEGAL TIMUR', 3376), -(3376030, 'TEGAL BARAT', 3376), -(3376040, 'MARGADANA', 3376), -(3401010, 'TEMON', 3401), -(3401020, 'WATES', 3401), -(3401030, 'PANJATAN', 3401), -(3401040, 'GALUR', 3401), -(3401050, 'LENDAH', 3401), -(3401060, 'SENTOLO', 3401), -(3401070, 'PENGASIH', 3401), -(3401080, 'KOKAP', 3401), -(3401090, 'GIRIMULYO', 3401), -(3401100, 'NANGGULAN', 3401), -(3401110, 'KALIBAWANG', 3401), -(3401120, 'SAMIGALUH', 3401), -(3402010, 'SRANDAKAN', 3402), -(3402020, 'SANDEN', 3402), -(3402030, 'KRETEK', 3402), -(3402040, 'PUNDONG', 3402), -(3402050, 'BAMBANG LIPURO', 3402), -(3402060, 'PANDAK', 3402), -(3402070, 'BANTUL', 3402), -(3402080, 'JETIS', 3402), -(3402090, 'IMOGIRI', 3402), -(3402100, 'DLINGO', 3402), -(3402110, 'PLERET', 3402), -(3402120, 'PIYUNGAN', 3402), -(3402130, 'BANGUNTAPAN', 3402), -(3402140, 'SEWON', 3402), -(3402150, 'KASIHAN', 3402), -(3402160, 'PAJANGAN', 3402), -(3402170, 'SEDAYU', 3402), -(3403010, 'PANGGANG', 3403), -(3403011, 'PURWOSARI', 3403), -(3403020, 'PALIYAN', 3403), -(3403030, 'SAPTO SARI', 3403), -(3403040, 'TEPUS', 3403), -(3403041, 'TANJUNGSARI', 3403), -(3403050, 'RONGKOP', 3403), -(3403051, 'GIRISUBO', 3403), -(3403060, 'SEMANU', 3403), -(3403070, 'PONJONG', 3403), -(3403080, 'KARANGMOJO', 3403), -(3403090, 'WONOSARI', 3403), -(3403100, 'PLAYEN', 3403), -(3403110, 'PATUK', 3403), -(3403120, 'GEDANG SARI', 3403), -(3403130, 'NGLIPAR', 3403), -(3403140, 'NGAWEN', 3403), -(3403150, 'SEMIN', 3403), -(3404010, 'MOYUDAN', 3404), -(3404020, 'MINGGIR', 3404), -(3404030, 'SEYEGAN', 3404), -(3404040, 'GODEAN', 3404), -(3404050, 'GAMPING', 3404), -(3404060, 'MLATI', 3404), -(3404070, 'DEPOK', 3404), -(3404080, 'BERBAH', 3404), -(3404090, 'PRAMBANAN', 3404), -(3404100, 'KALASAN', 3404), -(3404110, 'NGEMPLAK', 3404), -(3404120, 'NGAGLIK', 3404), -(3404130, 'SLEMAN', 3404), -(3404140, 'TEMPEL', 3404), -(3404150, 'TURI', 3404), -(3404160, 'PAKEM', 3404), -(3404170, 'CANGKRINGAN', 3404), -(3471010, 'MANTRIJERON', 3471), -(3471020, 'KRATON', 3471), -(3471030, 'MERGANGSAN', 3471), -(3471040, 'UMBULHARJO', 3471), -(3471050, 'KOTAGEDE', 3471), -(3471060, 'GONDOKUSUMAN', 3471), -(3471070, 'DANUREJAN', 3471), -(3471080, 'PAKUALAMAN', 3471), -(3471090, 'GONDOMANAN', 3471), -(3471100, 'NGAMPILAN', 3471), -(3471110, 'WIROBRAJAN', 3471), -(3471120, 'GEDONG TENGEN', 3471), -(3471130, 'JETIS', 3471), -(3471140, 'TEGALREJO', 3471), -(3501010, 'DONOROJO', 3501), -(3501020, 'PUNUNG', 3501), -(3501030, 'PRINGKUKU', 3501), -(3501040, 'PACITAN', 3501), -(3501050, 'KEBONAGUNG', 3501), -(3501060, 'ARJOSARI', 3501), -(3501070, 'NAWANGAN', 3501), -(3501080, 'BANDAR', 3501), -(3501090, 'TEGALOMBO', 3501), -(3501100, 'TULAKAN', 3501), -(3501110, 'NGADIROJO', 3501), -(3501120, 'SUDIMORO', 3501), -(3502010, 'NGRAYUN', 3502), -(3502020, 'SLAHUNG', 3502), -(3502030, 'BUNGKAL', 3502), -(3502040, 'SAMBIT', 3502), -(3502050, 'SAWOO', 3502), -(3502060, 'SOOKO', 3502), -(3502061, 'PUDAK', 3502), -(3502070, 'PULUNG', 3502), -(3502080, 'MLARAK', 3502), -(3502090, 'SIMAN', 3502), -(3502100, 'JETIS', 3502), -(3502110, 'BALONG', 3502), -(3502120, 'KAUMAN', 3502), -(3502130, 'JAMBON', 3502), -(3502140, 'BADEGAN', 3502), -(3502150, 'SAMPUNG', 3502), -(3502160, 'SUKOREJO', 3502), -(3502170, 'PONOROGO', 3502), -(3502180, 'BABADAN', 3502), -(3502190, 'JENANGAN', 3502), -(3502200, 'NGEBEL', 3502), -(3503010, 'PANGGUL', 3503), -(3503020, 'MUNJUNGAN', 3503), -(3503030, 'WATULIMO', 3503), -(3503040, 'KAMPAK', 3503), -(3503050, 'DONGKO', 3503), -(3503060, 'PULE', 3503), -(3503070, 'KARANGAN', 3503), -(3503071, 'SURUH', 3503), -(3503080, 'GANDUSARI', 3503), -(3503090, 'DURENAN', 3503), -(3503100, 'POGALAN', 3503), -(3503110, 'TRENGGALEK', 3503), -(3503120, 'TUGU', 3503), -(3503130, 'BENDUNGAN', 3503), -(3504010, 'BESUKI', 3504), -(3504020, 'BANDUNG', 3504), -(3504030, 'PAKEL', 3504), -(3504040, 'CAMPUR DARAT', 3504), -(3504050, 'TANGGUNG GUNUNG', 3504), -(3504060, 'KALIDAWIR', 3504), -(3504070, 'PUCANG LABAN', 3504), -(3504080, 'REJOTANGAN', 3504), -(3504090, 'NGUNUT', 3504), -(3504100, 'SUMBERGEMPOL', 3504), -(3504110, 'BOYOLANGU', 3504), -(3504120, 'TULUNGAGUNG', 3504), -(3504130, 'KEDUNGWARU', 3504), -(3504140, 'NGANTRU', 3504), -(3504150, 'KARANGREJO', 3504), -(3504160, 'KAUMAN', 3504), -(3504170, 'GONDANG', 3504), -(3504180, 'PAGER WOJO', 3504), -(3504190, 'SENDANG', 3504), -(3505010, 'BAKUNG', 3505), -(3505020, 'WONOTIRTO', 3505), -(3505030, 'PANGGUNGREJO', 3505), -(3505040, 'WATES', 3505), -(3505050, 'BINANGUN', 3505), -(3505060, 'SUTOJAYAN', 3505), -(3505070, 'KADEMANGAN', 3505), -(3505080, 'KANIGORO', 3505), -(3505090, 'TALUN', 3505), -(3505100, 'SELOPURO', 3505), -(3505110, 'KESAMBEN', 3505), -(3505120, 'SELOREJO', 3505), -(3505130, 'DOKO', 3505), -(3505140, 'WLINGI', 3505), -(3505150, 'GANDUSARI', 3505), -(3505160, 'GARUM', 3505), -(3505170, 'NGLEGOK', 3505), -(3505180, 'SANANKULON', 3505), -(3505190, 'PONGGOK', 3505), -(3505200, 'SRENGAT', 3505), -(3505210, 'WONODADI', 3505), -(3505220, 'UDANAWU', 3505), -(3506010, 'MOJO', 3506), -(3506020, 'SEMEN', 3506), -(3506030, 'NGADILUWIH', 3506), -(3506040, 'KRAS', 3506), -(3506050, 'RINGINREJO', 3506), -(3506060, 'KANDAT', 3506), -(3506070, 'WATES', 3506), -(3506080, 'NGANCAR', 3506), -(3506090, 'PLOSOKLATEN', 3506), -(3506100, 'GURAH', 3506), -(3506110, 'PUNCU', 3506), -(3506120, 'KEPUNG', 3506), -(3506130, 'KANDANGAN', 3506), -(3506140, 'PARE', 3506), -(3506141, 'BADAS', 3506), -(3506150, 'KUNJANG', 3506), -(3506160, 'PLEMAHAN', 3506), -(3506170, 'PURWOASRI', 3506), -(3506180, 'PAPAR', 3506), -(3506190, 'PAGU', 3506), -(3506191, 'KAYEN KIDUL', 3506), -(3506200, 'GAMPENGREJO', 3506), -(3506201, 'NGASEM', 3506), -(3506210, 'BANYAKAN', 3506), -(3506220, 'GROGOL', 3506), -(3506230, 'TAROKAN', 3506), -(3507010, 'DONOMULYO', 3507), -(3507020, 'KALIPARE', 3507), -(3507030, 'PAGAK', 3507), -(3507040, 'BANTUR', 3507), -(3507050, 'GEDANGAN', 3507), -(3507060, 'SUMBERMANJING', 3507), -(3507070, 'DAMPIT', 3507), -(3507080, 'TIRTO YUDO', 3507), -(3507090, 'AMPELGADING', 3507), -(3507100, 'PONCOKUSUMO', 3507), -(3507110, 'WAJAK', 3507), -(3507120, 'TUREN', 3507), -(3507130, 'BULULAWANG', 3507), -(3507140, 'GONDANGLEGI', 3507), -(3507150, 'PAGELARAN', 3507), -(3507160, 'KEPANJEN', 3507), -(3507170, 'SUMBER PUCUNG', 3507), -(3507180, 'KROMENGAN', 3507), -(3507190, 'NGAJUM', 3507), -(3507200, 'WONOSARI', 3507), -(3507210, 'WAGIR', 3507), -(3507220, 'PAKISAJI', 3507), -(3507230, 'TAJINAN', 3507), -(3507240, 'TUMPANG', 3507), -(3507250, 'PAKIS', 3507), -(3507260, 'JABUNG', 3507), -(3507270, 'LAWANG', 3507), -(3507280, 'SINGOSARI', 3507), -(3507290, 'KARANGPLOSO', 3507), -(3507300, 'DAU', 3507), -(3507310, 'PUJON', 3507), -(3507320, 'NGANTANG', 3507), -(3507330, 'KASEMBON', 3507), -(3508010, 'TEMPURSARI', 3508), -(3508020, 'PRONOJIWO', 3508), -(3508030, 'CANDIPURO', 3508), -(3508040, 'PASIRIAN', 3508), -(3508050, 'TEMPEH', 3508), -(3508060, 'LUMAJANG', 3508), -(3508061, 'SUMBERSUKO', 3508), -(3508070, 'TEKUNG', 3508), -(3508080, 'KUNIR', 3508), -(3508090, 'YOSOWILANGUN', 3508), -(3508100, 'ROWOKANGKUNG', 3508), -(3508110, 'JATIROTO', 3508), -(3508120, 'RANDUAGUNG', 3508), -(3508130, 'SUKODONO', 3508), -(3508140, 'PADANG', 3508), -(3508150, 'PASRUJAMBE', 3508), -(3508160, 'SENDURO', 3508), -(3508170, 'GUCIALIT', 3508), -(3508180, 'KEDUNGJAJANG', 3508), -(3508190, 'KLAKAH', 3508), -(3508200, 'RANUYOSO', 3508), -(3509010, 'KENCONG', 3509), -(3509020, 'GUMUK MAS', 3509), -(3509030, 'PUGER', 3509), -(3509040, 'WULUHAN', 3509), -(3509050, 'AMBULU', 3509), -(3509060, 'TEMPUREJO', 3509), -(3509070, 'SILO', 3509), -(3509080, 'MAYANG', 3509), -(3509090, 'MUMBULSARI', 3509), -(3509100, 'JENGGAWAH', 3509), -(3509110, 'AJUNG', 3509), -(3509120, 'RAMBIPUJI', 3509), -(3509130, 'BALUNG', 3509), -(3509140, 'UMBULSARI', 3509), -(3509150, 'SEMBORO', 3509), -(3509160, 'JOMBANG', 3509), -(3509170, 'SUMBER BARU', 3509), -(3509180, 'TANGGUL', 3509), -(3509190, 'BANGSALSARI', 3509), -(3509200, 'PANTI', 3509), -(3509210, 'SUKORAMBI', 3509), -(3509220, 'ARJASA', 3509), -(3509230, 'PAKUSARI', 3509), -(3509240, 'KALISAT', 3509), -(3509250, 'LEDOKOMBO', 3509), -(3509260, 'SUMBERJAMBE', 3509), -(3509270, 'SUKOWONO', 3509), -(3509280, 'JELBUK', 3509), -(3509710, 'KALIWATES', 3509), -(3509720, 'SUMBERSARI', 3509), -(3509730, 'PATRANG', 3509), -(3510010, 'PESANGGARAN', 3510), -(3510011, 'SILIRAGUNG', 3510), -(3510020, 'BANGOREJO', 3510), -(3510030, 'PURWOHARJO', 3510), -(3510040, 'TEGALDLIMO', 3510), -(3510050, 'MUNCAR', 3510), -(3510060, 'CLURING', 3510), -(3510070, 'GAMBIRAN', 3510), -(3510071, 'TEGALSARI', 3510), -(3510080, 'GLENMORE', 3510), -(3510090, 'KALIBARU', 3510), -(3510100, 'GENTENG', 3510), -(3510110, 'SRONO', 3510), -(3510120, 'ROGOJAMPI', 3510), -(3510130, 'KABAT', 3510), -(3510140, 'SINGOJURUH', 3510), -(3510150, 'SEMPU', 3510), -(3510160, 'SONGGON', 3510), -(3510170, 'GLAGAH', 3510), -(3510171, 'LICIN', 3510), -(3510180, 'BANYUWANGI', 3510), -(3510190, 'GIRI', 3510), -(3510200, 'KALIPURO', 3510), -(3510210, 'WONGSOREJO', 3510), -(3511010, 'MAESAN', 3511), -(3511020, 'GRUJUGAN', 3511), -(3511030, 'TAMANAN', 3511), -(3511031, 'JAMBESARI DARUS SHOLAH', 3511), -(3511040, 'PUJER', 3511), -(3511050, 'TLOGOSARI', 3511), -(3511060, 'SUKOSARI', 3511), -(3511061, 'SUMBER WRINGIN', 3511), -(3511070, 'TAPEN', 3511), -(3511080, 'WONOSARI', 3511), -(3511090, 'TENGGARANG', 3511), -(3511100, 'BONDOWOSO', 3511), -(3511110, 'CURAH DAMI', 3511), -(3511111, 'BINAKAL', 3511), -(3511120, 'PAKEM', 3511), -(3511130, 'WRINGIN', 3511), -(3511140, 'TEGALAMPEL', 3511), -(3511141, 'TAMAN KROCOK', 3511), -(3511150, 'KLABANG', 3511), -(3511151, 'SEMPOL', 3511), -(3511152, 'BOTOLINGGO', 3511), -(3511160, 'PRAJEKAN', 3511), -(3511170, 'CERMEE', 3511), -(3512010, 'SUMBERMALANG', 3512), -(3512020, 'JATIBANTENG', 3512), -(3512030, 'BANYUGLUGUR', 3512), -(3512040, 'BESUKI', 3512), -(3512050, 'SUBOH', 3512), -(3512060, 'MLANDINGAN', 3512), -(3512070, 'BUNGATAN', 3512), -(3512080, 'KENDIT', 3512), -(3512090, 'PANARUKAN', 3512), -(3512100, 'SITUBONDO', 3512), -(3512110, 'MANGARAN', 3512), -(3512120, 'PANJI', 3512), -(3512130, 'KAPONGAN', 3512), -(3512140, 'ARJASA', 3512), -(3512150, 'JANGKAR', 3512), -(3512160, 'ASEMBAGUS', 3512), -(3512170, 'BANYUPUTIH', 3512), -(3513010, 'SUKAPURA', 3513), -(3513020, 'SUMBER', 3513), -(3513030, 'KURIPAN', 3513), -(3513040, 'BANTARAN', 3513), -(3513050, 'LECES', 3513), -(3513060, 'TEGALSIWALAN', 3513), -(3513070, 'BANYUANYAR', 3513), -(3513080, 'TIRIS', 3513), -(3513090, 'KRUCIL', 3513), -(3513100, 'GADING', 3513), -(3513110, 'PAKUNIRAN', 3513), -(3513120, 'KOTAANYAR', 3513), -(3513130, 'PAITON', 3513), -(3513140, 'BESUK', 3513), -(3513150, 'KRAKSAAN', 3513), -(3513160, 'KREJENGAN', 3513), -(3513170, 'PAJARAKAN', 3513), -(3513180, 'MARON', 3513), -(3513190, 'GENDING', 3513), -(3513200, 'DRINGU', 3513), -(3513210, 'WONOMERTO', 3513), -(3513220, 'LUMBANG', 3513), -(3513230, 'TONGAS', 3513), -(3513240, 'SUMBERASIH', 3513), -(3514010, 'PURWODADI', 3514), -(3514020, 'TUTUR', 3514), -(3514030, 'PUSPO', 3514), -(3514040, 'TOSARI', 3514), -(3514050, 'LUMBANG', 3514), -(3514060, 'PASREPAN', 3514), -(3514070, 'KEJAYAN', 3514), -(3514080, 'WONOREJO', 3514), -(3514090, 'PURWOSARI', 3514), -(3514100, 'PRIGEN', 3514), -(3514110, 'SUKOREJO', 3514), -(3514120, 'PANDAAN', 3514), -(3514130, 'GEMPOL', 3514), -(3514140, 'BEJI', 3514), -(3514150, 'BANGIL', 3514); -INSERT INTO `kecamatan` (`kodeBps`, `namaKecamatan`, `kodeKabupaten`) VALUES -(3514160, 'REMBANG', 3514), -(3514170, 'KRATON', 3514), -(3514180, 'POHJENTREK', 3514), -(3514190, 'GONDANG WETAN', 3514), -(3514200, 'REJOSO', 3514), -(3514210, 'WINONGAN', 3514), -(3514220, 'GRATI', 3514), -(3514230, 'LEKOK', 3514), -(3514240, 'NGULING', 3514), -(3515010, 'TARIK', 3515), -(3515020, 'PRAMBON', 3515), -(3515030, 'KREMBUNG', 3515), -(3515040, 'PORONG', 3515), -(3515050, 'JABON', 3515), -(3515060, 'TANGGULANGIN', 3515), -(3515070, 'CANDI', 3515), -(3515080, 'TULANGAN', 3515), -(3515090, 'WONOAYU', 3515), -(3515100, 'SUKODONO', 3515), -(3515110, 'SIDOARJO', 3515), -(3515120, 'BUDURAN', 3515), -(3515130, 'SEDATI', 3515), -(3515140, 'WARU', 3515), -(3515150, 'GEDANGAN', 3515), -(3515160, 'TAMAN', 3515), -(3515170, 'KRIAN', 3515), -(3515180, 'BALONG BENDO', 3515), -(3516010, 'JATIREJO', 3516), -(3516020, 'GONDANG', 3516), -(3516030, 'PACET', 3516), -(3516040, 'TRAWAS', 3516), -(3516050, 'NGORO', 3516), -(3516060, 'PUNGGING', 3516), -(3516070, 'KUTOREJO', 3516), -(3516080, 'MOJOSARI', 3516), -(3516090, 'BANGSAL', 3516), -(3516091, 'MOJOANYAR', 3516), -(3516100, 'DLANGGU', 3516), -(3516110, 'PURI', 3516), -(3516120, 'TROWULAN', 3516), -(3516130, 'SOOKO', 3516), -(3516140, 'GEDEK', 3516), -(3516150, 'KEMLAGI', 3516), -(3516160, 'JETIS', 3516), -(3516170, 'DAWAR BLANDONG', 3516), -(3517010, 'BANDAR KEDUNG MULYO', 3517), -(3517020, 'PERAK', 3517), -(3517030, 'GUDO', 3517), -(3517040, 'DIWEK', 3517), -(3517050, 'NGORO', 3517), -(3517060, 'MOJOWARNO', 3517), -(3517070, 'BARENG', 3517), -(3517080, 'WONOSALAM', 3517), -(3517090, 'MOJOAGUNG', 3517), -(3517100, 'SUMOBITO', 3517), -(3517110, 'JOGO ROTO', 3517), -(3517120, 'PETERONGAN', 3517), -(3517130, 'JOMBANG', 3517), -(3517140, 'MEGALUH', 3517), -(3517150, 'TEMBELANG', 3517), -(3517160, 'KESAMBEN', 3517), -(3517170, 'KUDU', 3517), -(3517171, 'NGUSIKAN', 3517), -(3517180, 'PLOSO', 3517), -(3517190, 'KABUH', 3517), -(3517200, 'PLANDAAN', 3517), -(3518010, 'SAWAHAN', 3518), -(3518020, 'NGETOS', 3518), -(3518030, 'BERBEK', 3518), -(3518040, 'LOCERET', 3518), -(3518050, 'PACE', 3518), -(3518060, 'TANJUNGANOM', 3518), -(3518070, 'PRAMBON', 3518), -(3518080, 'NGRONGGOT', 3518), -(3518090, 'KERTOSONO', 3518), -(3518100, 'PATIANROWO', 3518), -(3518110, 'BARON', 3518), -(3518120, 'GONDANG', 3518), -(3518130, 'SUKOMORO', 3518), -(3518140, 'NGANJUK', 3518), -(3518150, 'BAGOR', 3518), -(3518160, 'WILANGAN', 3518), -(3518170, 'REJOSO', 3518), -(3518180, 'NGLUYU', 3518), -(3518190, 'LENGKONG', 3518), -(3518200, 'JATIKALEN', 3518), -(3519010, 'KEBONSARI', 3519), -(3519020, 'GEGER', 3519), -(3519030, 'DOLOPO', 3519), -(3519040, 'DAGANGAN', 3519), -(3519050, 'WUNGU', 3519), -(3519060, 'KARE', 3519), -(3519070, 'GEMARANG', 3519), -(3519080, 'SARADAN', 3519), -(3519090, 'PILANGKENCENG', 3519), -(3519100, 'MEJAYAN', 3519), -(3519110, 'WONOASRI', 3519), -(3519120, 'BALEREJO', 3519), -(3519130, 'MADIUN', 3519), -(3519140, 'SAWAHAN', 3519), -(3519150, 'JIWAN', 3519), -(3520010, 'PONCOL', 3520), -(3520020, 'PARANG', 3520), -(3520030, 'LEMBEYAN', 3520), -(3520040, 'TAKERAN', 3520), -(3520041, 'NGUNTORONADI', 3520), -(3520050, 'KAWEDANAN', 3520), -(3520060, 'MAGETAN', 3520), -(3520061, 'NGARIBOYO', 3520), -(3520070, 'PLAOSAN', 3520), -(3520071, 'SIDOREJO', 3520), -(3520080, 'PANEKAN', 3520), -(3520090, 'SUKOMORO', 3520), -(3520100, 'BENDO', 3520), -(3520110, 'MAOSPATI', 3520), -(3520120, 'KARANGREJO', 3520), -(3520121, 'KARAS', 3520), -(3520130, 'BARAT', 3520), -(3520131, 'KARTOHARJO', 3520), -(3521010, 'SINE', 3521), -(3521020, 'NGRAMBE', 3521), -(3521030, 'JOGOROGO', 3521), -(3521040, 'KENDAL', 3521), -(3521050, 'GENENG', 3521), -(3521051, 'GERIH', 3521), -(3521060, 'KWADUNGAN', 3521), -(3521070, 'PANGKUR', 3521), -(3521080, 'KARANGJATI', 3521), -(3521090, 'BRINGIN', 3521), -(3521100, 'PADAS', 3521), -(3521101, 'KASREMAN', 3521), -(3521110, 'NGAWI', 3521), -(3521120, 'PARON', 3521), -(3521130, 'KEDUNGGALAR', 3521), -(3521140, 'PITU', 3521), -(3521150, 'WIDODAREN', 3521), -(3521160, 'MANTINGAN', 3521), -(3521170, 'KARANGANYAR', 3521), -(3522010, 'MARGOMULYO', 3522), -(3522020, 'NGRAHO', 3522), -(3522030, 'TAMBAKREJO', 3522), -(3522040, 'NGAMBON', 3522), -(3522041, 'SEKAR', 3522), -(3522050, 'BUBULAN', 3522), -(3522051, 'GONDANG', 3522), -(3522060, 'TEMAYANG', 3522), -(3522070, 'SUGIHWARAS', 3522), -(3522080, 'KEDUNGADEM', 3522), -(3522090, 'KEPOH BARU', 3522), -(3522100, 'BAURENO', 3522), -(3522110, 'KANOR', 3522), -(3522120, 'SUMBEREJO', 3522), -(3522130, 'BALEN', 3522), -(3522140, 'SUKOSEWU', 3522), -(3522150, 'KAPAS', 3522), -(3522160, 'BOJONEGORO', 3522), -(3522170, 'TRUCUK', 3522), -(3522180, 'DANDER', 3522), -(3522190, 'NGASEM', 3522), -(3522200, 'KALITIDU', 3522), -(3522210, 'MALO', 3522), -(3522220, 'PURWOSARI', 3522), -(3522230, 'PADANGAN', 3522), -(3522240, 'KASIMAN', 3522), -(3522241, 'KEDEWAN', 3522), -(3523010, 'KENDURUAN', 3523), -(3523020, 'BANGILAN', 3523), -(3523030, 'SENORI', 3523), -(3523040, 'SINGGAHAN', 3523), -(3523050, 'MONTONG', 3523), -(3523060, 'PARENGAN', 3523), -(3523070, 'SOKO', 3523), -(3523080, 'RENGEL', 3523), -(3523081, 'GRABAGAN', 3523), -(3523090, 'PLUMPANG', 3523), -(3523100, 'WIDANG', 3523), -(3523110, 'PALANG', 3523), -(3523120, 'SEMANDING', 3523), -(3523130, 'TUBAN', 3523), -(3523140, 'JENU', 3523), -(3523150, 'MERAKURAK', 3523), -(3523160, 'KEREK', 3523), -(3523170, 'TAMBAKBOYO', 3523), -(3523180, 'JATIROGO', 3523), -(3523190, 'BANCAR', 3523), -(3524010, 'SUKORAME', 3524), -(3524020, 'BLULUK', 3524), -(3524030, 'NGIMBANG', 3524), -(3524040, 'SAMBENG', 3524), -(3524050, 'MANTUP', 3524), -(3524060, 'KEMBANGBAHU', 3524), -(3524070, 'SUGIO', 3524), -(3524080, 'KEDUNGPRING', 3524), -(3524090, 'MODO', 3524), -(3524100, 'BABAT', 3524), -(3524110, 'PUCUK', 3524), -(3524120, 'SUKODADI', 3524), -(3524130, 'LAMONGAN', 3524), -(3524140, 'TIKUNG', 3524), -(3524141, 'SARIREJO', 3524), -(3524150, 'DEKET', 3524), -(3524160, 'GLAGAH', 3524), -(3524170, 'KARANGBINANGUN', 3524), -(3524180, 'TURI', 3524), -(3524190, 'KALITENGAH', 3524), -(3524200, 'KARANG GENENG', 3524), -(3524210, 'SEKARAN', 3524), -(3524220, 'MADURAN', 3524), -(3524230, 'LAREN', 3524), -(3524240, 'SOLOKURO', 3524), -(3524250, 'PACIRAN', 3524), -(3524260, 'BRONDONG', 3524), -(3525010, 'WRINGINANOM', 3525), -(3525020, 'DRIYOREJO', 3525), -(3525030, 'KEDAMEAN', 3525), -(3525040, 'MENGANTI', 3525), -(3525050, 'CERME', 3525), -(3525060, 'BENJENG', 3525), -(3525070, 'BALONGPANGGANG', 3525), -(3525080, 'DUDUKSAMPEYAN', 3525), -(3525090, 'KEBOMAS', 3525), -(3525100, 'GRESIK', 3525), -(3525110, 'MANYAR', 3525), -(3525120, 'BUNGAH', 3525), -(3525130, 'SIDAYU', 3525), -(3525140, 'DUKUN', 3525), -(3525150, 'PANCENG', 3525), -(3525160, 'UJUNGPANGKAH', 3525), -(3525170, 'SANGKAPURA', 3525), -(3525180, 'TAMBAK', 3525), -(3526010, 'KAMAL', 3526), -(3526020, 'LABANG', 3526), -(3526030, 'KWANYAR', 3526), -(3526040, 'MODUNG', 3526), -(3526050, 'BLEGA', 3526), -(3526060, 'KONANG', 3526), -(3526070, 'GALIS', 3526), -(3526080, 'TANAH MERAH', 3526), -(3526090, 'TRAGAH', 3526), -(3526100, 'SOCAH', 3526), -(3526110, 'BANGKALAN', 3526), -(3526120, 'BURNEH', 3526), -(3526130, 'AROSBAYA', 3526), -(3526140, 'GEGER', 3526), -(3526150, 'KOKOP', 3526), -(3526160, 'TANJUNGBUMI', 3526), -(3526170, 'SEPULU', 3526), -(3526180, 'KLAMPIS', 3526), -(3527010, 'SRESEH', 3527), -(3527020, 'TORJUN', 3527), -(3527021, 'PANGARENGAN', 3527), -(3527030, 'SAMPANG', 3527), -(3527040, 'CAMPLONG', 3527), -(3527050, 'OMBEN', 3527), -(3527060, 'KEDUNGDUNG', 3527), -(3527070, 'JRENGIK', 3527), -(3527080, 'TAMBELANGAN', 3527), -(3527090, 'BANYUATES', 3527), -(3527100, 'ROBATAL', 3527), -(3527101, 'KARANG PENANG', 3527), -(3527110, 'KETAPANG', 3527), -(3527120, 'SOKOBANAH', 3527), -(3528010, 'TLANAKAN', 3528), -(3528020, 'PADEMAWU', 3528), -(3528030, 'GALIS', 3528), -(3528040, 'LARANGAN', 3528), -(3528050, 'PAMEKASAN', 3528), -(3528060, 'PROPPO', 3528), -(3528070, 'PALENGAAN', 3528), -(3528080, 'PEGANTENAN', 3528), -(3528090, 'KADUR', 3528), -(3528100, 'PAKONG', 3528), -(3528110, 'WARU', 3528), -(3528120, 'BATU MARMAR', 3528), -(3528130, 'PASEAN', 3528), -(3529010, 'PRAGAAN', 3529), -(3529020, 'BLUTO', 3529), -(3529030, 'SARONGGI', 3529), -(3529040, 'GILIGENTENG', 3529), -(3529050, 'TALANGO', 3529), -(3529060, 'KALIANGET', 3529), -(3529070, 'KOTA SUMENEP', 3529), -(3529071, 'BATUAN', 3529), -(3529080, 'LENTENG', 3529), -(3529090, 'GANDING', 3529), -(3529100, 'GULUK GULUK', 3529), -(3529110, 'PASONGSONGAN', 3529), -(3529120, 'AMBUNTEN', 3529), -(3529130, 'RUBARU', 3529), -(3529140, 'DASUK', 3529), -(3529150, 'MANDING', 3529), -(3529160, 'BATUPUTIH', 3529), -(3529170, 'GAPURA', 3529), -(3529180, 'BATANG BATANG', 3529), -(3529190, 'DUNGKEK', 3529), -(3529200, 'NONGGUNONG', 3529), -(3529210, 'GAYAM', 3529), -(3529220, 'RAAS', 3529), -(3529230, 'SAPEKEN', 3529), -(3529240, 'ARJASA', 3529), -(3529241, 'KANGAYAN', 3529), -(3529250, 'MASALEMBU', 3529), -(3571010, 'MOJOROTO', 3571), -(3571020, 'KOTA KEDIRI', 3571), -(3571030, 'PESANTREN', 3571), -(3572010, 'SUKOREJO', 3572), -(3572020, 'KEPANJENKIDUL', 3572), -(3572030, 'SANANWETAN', 3572), -(3573010, 'KEDUNGKANDANG', 3573), -(3573020, 'SUKUN', 3573), -(3573030, 'KLOJEN', 3573), -(3573040, 'BLIMBING', 3573), -(3573050, 'LOWOKWARU', 3573), -(3574010, 'KADEMANGAN', 3574), -(3574011, 'KEDOPOK', 3574), -(3574020, 'WONOASIH', 3574), -(3574030, 'MAYANGAN', 3574), -(3574031, 'KANIGARAN', 3574), -(3575010, 'GADINGREJO', 3575), -(3575020, 'PURWOREJO', 3575), -(3575030, 'BUGULKIDUL', 3575), -(3576010, 'PRAJURIT KULON', 3576), -(3576020, 'MAGERSARI', 3576), -(3577010, 'MANGU HARJO', 3577), -(3577020, 'TAMAN', 3577), -(3577030, 'KARTOHARJO', 3577), -(3578010, 'KARANG PILANG', 3578), -(3578020, 'JAMBANGAN', 3578), -(3578030, 'GAYUNGAN', 3578), -(3578040, 'WONOCOLO', 3578), -(3578050, 'TENGGILIS MEJOYO', 3578), -(3578060, 'GUNUNG ANYAR', 3578), -(3578070, 'RUNGKUT', 3578), -(3578080, 'SUKOLILO', 3578), -(3578090, 'MULYOREJO', 3578), -(3578100, 'GUBENG', 3578), -(3578110, 'WONOKROMO', 3578), -(3578120, 'DUKUH PAKIS', 3578), -(3578130, 'WIYUNG', 3578), -(3578140, 'LAKARSANTRI', 3578), -(3578141, 'SAMBIKEREP', 3578), -(3578150, 'TANDES', 3578), -(3578160, 'SUKO MANUNGGAL', 3578), -(3578170, 'SAWAHAN', 3578), -(3578180, 'TEGALSARI', 3578), -(3578190, 'GENTENG', 3578), -(3578200, 'TAMBAKSARI', 3578), -(3578210, 'KENJERAN', 3578), -(3578211, 'BULAK', 3578), -(3578220, 'SIMOKERTO', 3578), -(3578230, 'SEMAMPIR', 3578), -(3578240, 'PABEAN CANTIAN', 3578), -(3578250, 'BUBUTAN', 3578), -(3578260, 'KREMBANGAN', 3578), -(3578270, 'ASEMROWO', 3578), -(3578280, 'BENOWO', 3578), -(3578281, 'PAKAL', 3578), -(3579010, 'BATU', 3579), -(3579020, 'JUNREJO', 3579), -(3579030, 'BUMIAJI', 3579), -(3601010, 'SUMUR', 3601), -(3601020, 'CIMANGGU', 3601), -(3601030, 'CIBALIUNG', 3601), -(3601031, 'CIBITUNG', 3601), -(3601040, 'CIKEUSIK', 3601), -(3601050, 'CIGEULIS', 3601), -(3601060, 'PANIMBANG', 3601), -(3601061, 'SOBANG', 3601), -(3601070, 'MUNJUL', 3601), -(3601071, 'ANGSANA', 3601), -(3601072, 'SINDANGRESMI', 3601), -(3601080, 'PICUNG', 3601), -(3601090, 'BOJONG', 3601), -(3601100, 'SAKETI', 3601), -(3601101, 'CISATA', 3601), -(3601110, 'PAGELARAN', 3601), -(3601111, 'PATIA', 3601), -(3601112, 'SUKARESMI', 3601), -(3601120, 'LABUAN', 3601), -(3601121, 'CARITA', 3601), -(3601130, 'JIPUT', 3601), -(3601131, 'CIKEDAL', 3601), -(3601140, 'MENES', 3601), -(3601141, 'PULOSARI', 3601), -(3601150, 'MANDALAWANGI', 3601), -(3601160, 'CIMANUK', 3601), -(3601161, 'CIPEUCANG', 3601), -(3601170, 'BANJAR', 3601), -(3601171, 'KADUHEJO', 3601), -(3601172, 'MEKARJAYA', 3601), -(3601180, 'PANDEGLANG', 3601), -(3601181, 'MAJASARI', 3601), -(3601190, 'CADASARI', 3601), -(3601191, 'KARANGTANJUNG', 3601), -(3601192, 'KORONCONG', 3601), -(3602010, 'MALINGPING', 3602), -(3602011, 'WANASALAM', 3602), -(3602020, 'PANGGARANGAN', 3602), -(3602021, 'CIHARA', 3602), -(3602030, 'BAYAH', 3602), -(3602031, 'CILOGRANG', 3602), -(3602040, 'CIBEBER', 3602), -(3602050, 'CIJAKU', 3602), -(3602051, 'CIGEMBLONG', 3602), -(3602060, 'BANJARSARI', 3602), -(3602070, 'CILELES', 3602), -(3602080, 'GUNUNG KENCANA', 3602), -(3602090, 'BOJONGMANIK', 3602), -(3602091, 'CIRINTEN', 3602), -(3602100, 'LEUWIDAMAR', 3602), -(3602110, 'MUNCANG', 3602), -(3602111, 'SOBANG', 3602), -(3602120, 'CIPANAS', 3602), -(3602121, 'LEBAKGEDONG', 3602), -(3602130, 'SAJIRA', 3602), -(3602140, 'CIMARGA', 3602), -(3602150, 'CIKULUR', 3602), -(3602160, 'WARUNGGUNUNG', 3602), -(3602170, 'CIBADAK', 3602), -(3602180, 'RANGKASBITUNG', 3602), -(3602181, 'KALANGANYAR', 3602), -(3602190, 'MAJA', 3602), -(3602191, 'CURUGBITUNG', 3602), -(3603010, 'CISOKA', 3603), -(3603011, 'SOLEAR', 3603), -(3603020, 'TIGARAKSA', 3603), -(3603021, 'JAMBE', 3603), -(3603030, 'CIKUPA', 3603), -(3603040, 'PANONGAN', 3603), -(3603050, 'CURUG', 3603), -(3603051, 'KELAPA DUA', 3603), -(3603060, 'LEGOK', 3603), -(3603070, 'PAGEDANGAN', 3603), -(3603081, 'CISAUK', 3603), -(3603120, 'PASARKEMIS', 3603), -(3603121, 'SINDANG JAYA', 3603), -(3603130, 'BALARAJA', 3603), -(3603131, 'JAYANTI', 3603), -(3603132, 'SUKAMULYA', 3603), -(3603140, 'KRESEK', 3603), -(3603141, 'GUNUNG KALER', 3603), -(3603150, 'KRONJO', 3603), -(3603151, 'MEKAR BARU', 3603), -(3603160, 'MAUK', 3603), -(3603161, 'KEMIRI', 3603), -(3603162, 'SUKADIRI', 3603), -(3603170, 'RAJEG', 3603), -(3603180, 'SEPATAN', 3603), -(3603181, 'SEPATAN TIMUR', 3603), -(3603190, 'PAKUHAJI', 3603), -(3603200, 'TELUKNAGA', 3603), -(3603210, 'KOSAMBI', 3603), -(3604010, 'CINANGKA', 3604), -(3604020, 'PADARINCANG', 3604), -(3604030, 'CIOMAS', 3604), -(3604040, 'PABUARAN', 3604), -(3604041, 'GUNUNG SARI', 3604), -(3604050, 'BAROS', 3604), -(3604060, 'PETIR', 3604), -(3604061, 'TUNJUNG TEJA', 3604), -(3604080, 'CIKEUSAL', 3604), -(3604090, 'PAMARAYAN', 3604), -(3604091, 'BANDUNG', 3604), -(3604100, 'JAWILAN', 3604), -(3604110, 'KOPO', 3604), -(3604120, 'CIKANDE', 3604), -(3604121, 'KIBIN', 3604), -(3604130, 'KRAGILAN', 3604), -(3604180, 'WARINGINKURUNG', 3604), -(3604190, 'MANCAK', 3604), -(3604200, 'ANYAR', 3604), -(3604210, 'BOJONEGARA', 3604), -(3604211, 'PULO AMPEL', 3604), -(3604220, 'KRAMATWATU', 3604), -(3604240, 'CIRUAS', 3604), -(3604250, 'PONTANG', 3604), -(3604260, 'CARENANG', 3604), -(3604261, 'BINUANG', 3604), -(3604270, 'TIRTAYASA', 3604), -(3604271, 'TANARA', 3604), -(3671010, 'CILEDUG', 3671), -(3671011, 'LARANGAN', 3671), -(3671012, 'KARANG TENGAH', 3671), -(3671020, 'CIPONDOH', 3671), -(3671021, 'PINANG', 3671), -(3671030, 'TANGERANG', 3671), -(3671031, 'KARAWACI', 3671), -(3671040, 'JATI UWUNG', 3671), -(3671041, 'CIBODAS', 3671), -(3671042, 'PERIUK', 3671), -(3671050, 'BATUCEPER', 3671), -(3671051, 'NEGLASARI', 3671), -(3671060, 'BENDA', 3671), -(3672010, 'CIWANDAN', 3672), -(3672011, 'CITANGKIL', 3672), -(3672020, 'PULOMERAK', 3672), -(3672021, 'PURWAKARTA', 3672), -(3672022, 'GROGOL', 3672), -(3672030, 'CILEGON', 3672), -(3672031, 'JOMBANG', 3672), -(3672040, 'CIBEBER', 3672), -(3673010, 'CURUG', 3673), -(3673020, 'WALANTAKA', 3673), -(3673030, 'CIPOCOK JAYA', 3673), -(3673040, 'SERANG', 3673), -(3673050, 'TAKTAKAN', 3673), -(3673060, 'KASEMEN', 3673), -(3674010, 'SETU', 3674), -(3674020, 'SERPONG', 3674), -(3674030, 'PAMULANG', 3674), -(3674040, 'CIPUTAT', 3674), -(3674050, 'CIPUTAT TIMUR', 3674), -(3674060, 'PONDOK AREN', 3674), -(3674070, 'SERPONG UTARA', 3674), -(5101010, 'MELAYA', 5101), -(5101020, 'NEGARA', 5101), -(5101021, 'JEMBRANA', 5101), -(5101030, 'MENDOYO', 5101), -(5101040, 'PEKUTATAN', 5101), -(5102010, 'SELEMADEG', 5102), -(5102011, 'SELEMADEG TIMUR', 5102), -(5102012, 'SELEMADEG BARAT', 5102), -(5102020, 'KERAMBITAN', 5102), -(5102030, 'TABANAN', 5102), -(5102040, 'KEDIRI', 5102), -(5102050, 'MARGA', 5102), -(5102060, 'BATURITI', 5102), -(5102070, 'PENEBEL', 5102), -(5102080, 'PUPUAN', 5102), -(5103010, 'KUTA SELATAN', 5103), -(5103020, 'KUTA', 5103), -(5103030, 'KUTA UTARA', 5103), -(5103040, 'MENGWI', 5103), -(5103050, 'ABIANSEMAL', 5103), -(5103060, 'PETANG', 5103), -(5104010, 'SUKAWATI', 5104), -(5104020, 'BLAHBATUH', 5104), -(5104030, 'GIANYAR', 5104), -(5104040, 'TAMPAKSIRING', 5104), -(5104050, 'UBUD', 5104), -(5104060, 'TEGALLALANG', 5104), -(5104070, 'PAYANGAN', 5104), -(5105010, 'NUSAPENIDA', 5105), -(5105020, 'BANJARANGKAN', 5105), -(5105030, 'KLUNGKUNG', 5105), -(5105040, 'DAWAN', 5105), -(5106010, 'SUSUT', 5106), -(5106020, 'BANGLI', 5106), -(5106030, 'TEMBUKU', 5106), -(5106040, 'KINTAMANI', 5106), -(5107010, 'RENDANG', 5107), -(5107020, 'SIDEMEN', 5107), -(5107030, 'MANGGIS', 5107), -(5107040, 'KARANGASEM', 5107), -(5107050, 'ABANG', 5107), -(5107060, 'BEBANDEM', 5107), -(5107070, 'SELAT', 5107), -(5107080, 'KUBU', 5107), -(5108010, 'GEROKGAK', 5108), -(5108020, 'SERIRIT', 5108), -(5108030, 'BUSUNGBIU', 5108), -(5108040, 'BANJAR', 5108), -(5108050, 'SUKASADA', 5108), -(5108060, 'BULELENG', 5108), -(5108070, 'SAWAN', 5108), -(5108080, 'KUBUTAMBAHAN', 5108), -(5108090, 'TEJAKULA', 5108), -(5171010, 'DENPASAR SELATAN', 5171), -(5171020, 'DENPASAR TIMUR', 5171), -(5171030, 'DENPASAR BARAT', 5171), -(5171031, 'DENPASAR UTARA', 5171), -(5201010, 'SEKOTONG TENGAH', 5201), -(5201011, 'LEMBAR', 5201), -(5201020, 'GERUNG', 5201), -(5201030, 'LABU API', 5201), -(5201040, 'KEDIRI', 5201), -(5201041, 'KURIPAN', 5201), -(5201050, 'NARMADA', 5201), -(5201051, 'LINGSAR', 5201), -(5201060, 'GUNUNG SARI', 5201), -(5201061, 'BATU LAYAR', 5201), -(5202010, 'PRAYA BARAT', 5202), -(5202011, 'PRAYA BARAT DAYA', 5202), -(5202020, 'PUJUT', 5202), -(5202030, 'PRAYA TIMUR', 5202), -(5202040, 'JANAPRIA', 5202), -(5202050, 'KOPANG', 5202), -(5202060, 'PRAYA', 5202), -(5202061, 'PRAYA TENGAH', 5202), -(5202070, 'JONGGAT', 5202), -(5202080, 'PRINGGARATA', 5202), -(5202090, 'BATUKLIANG', 5202), -(5202091, 'BATUKLIANG UTARA', 5202), -(5203010, 'KERUAK', 5203), -(5203011, 'JEROWARU', 5203), -(5203020, 'SAKRA', 5203), -(5203021, 'SAKRA BARAT', 5203), -(5203022, 'SAKRA TIMUR', 5203), -(5203030, 'TERARA', 5203), -(5203031, 'MONTONG GADING', 5203), -(5203040, 'SIKUR', 5203), -(5203050, 'MASBAGIK', 5203), -(5203051, 'PRINGGASELA', 5203), -(5203060, 'SUKAMULIA', 5203), -(5203061, 'SURALAGA', 5203), -(5203070, 'SELONG', 5203), -(5203071, 'LABUHAN HAJI', 5203), -(5203080, 'PRINGGABAYA', 5203), -(5203081, 'SUELA', 5203), -(5203090, 'AIKMEL', 5203), -(5203091, 'WANASABA', 5203), -(5203092, 'SEMBALUN', 5203), -(5203100, 'SAMBELIA', 5203), -(5204020, 'LUNYUK', 5204), -(5204021, 'ORONG TELU', 5204), -(5204050, 'ALAS', 5204), -(5204051, 'ALAS BARAT', 5204), -(5204052, 'BUER', 5204), -(5204061, 'UTAN', 5204), -(5204062, 'RHEE', 5204), -(5204070, 'BATULANTEH', 5204), -(5204080, 'SUMBAWA', 5204), -(5204081, 'LABUHAN BADAS', 5204), -(5204082, 'UNTER IWES', 5204), -(5204090, 'MOYOHILIR', 5204), -(5204091, 'MOYO UTARA', 5204), -(5204100, 'MOYOHULU', 5204), -(5204110, 'ROPANG', 5204), -(5204111, 'LENANGGUAR', 5204), -(5204112, 'LANTUNG', 5204), -(5204121, 'LAPE', 5204), -(5204122, 'LOPOK', 5204), -(5204130, 'PLAMPANG', 5204), -(5204131, 'LABANGKA', 5204), -(5204132, 'MARONGE', 5204), -(5204140, 'EMPANG', 5204), -(5204141, 'TARANO', 5204), -(5205010, 'HU''U', 5205), -(5205011, 'PAJO', 5205), -(5205020, 'DOMPU', 5205), -(5205030, 'WOJA', 5205), -(5205040, 'KILO', 5205), -(5205050, 'KEMPO', 5205), -(5205051, 'MANGGALEWA', 5205), -(5205060, 'PEKAT', 5205), -(5206010, 'MONTA', 5206), -(5206011, 'PARADO', 5206), -(5206020, 'BOLO', 5206), -(5206021, 'MADA PANGGA', 5206), -(5206030, 'WOHA', 5206), -(5206040, 'BELO', 5206), -(5206041, 'PALIBELO', 5206), -(5206050, 'WAWO', 5206), -(5206051, 'LANGGUDU', 5206), -(5206052, 'LAMBITU', 5206), -(5206060, 'SAPE', 5206), -(5206061, 'LAMBU', 5206), -(5206070, 'WERA', 5206), -(5206071, 'AMBALAWI', 5206), -(5206080, 'DONGGO', 5206), -(5206081, 'SOROMANDI', 5206), -(5206090, 'SANGGAR', 5206), -(5206091, 'TAMBORA', 5206), -(5207010, 'SEKONGKANG', 5207), -(5207020, 'JEREWEH', 5207), -(5207021, 'MALUK', 5207), -(5207030, 'TALIWANG', 5207), -(5207031, 'BRANG ENE', 5207), -(5207040, 'BRANG REA', 5207), -(5207050, 'SETELUK', 5207), -(5207051, 'POTO TANO', 5207), -(5208010, 'PEMENANG', 5208), -(5208020, 'TANJUNG', 5208), -(5208030, 'GANGGA', 5208), -(5208040, 'KAYANGAN', 5208), -(5208050, 'BAYAN', 5208), -(5271010, 'AMPENAN', 5271), -(5271011, 'SEKARBELA', 5271), -(5271020, 'MATARAM', 5271), -(5271021, 'SELAPARANG', 5271), -(5271030, 'CAKRANEGARA', 5271), -(5271031, 'SANDUBAYA', 5271), -(5272010, 'RASANAE BARAT', 5272), -(5272011, 'MPUNDA', 5272), -(5272020, 'RASANAE TIMUR', 5272), -(5272021, 'RABA', 5272), -(5272030, 'ASAKOTA', 5272), -(5301021, 'LAMBOYA', 5301), -(5301022, 'WANOKAKA', 5301), -(5301023, 'LABOYA BARAT', 5301), -(5301050, 'LOLI', 5301), -(5301060, 'KOTA WAIKABUBAK', 5301), -(5301072, 'TANA RIGHU', 5301), -(5302010, 'LEWA', 5302), -(5302011, 'NGGAHA ORIANGU', 5302), -(5302012, 'LEWA TIDAHU', 5302), -(5302013, 'KATALA HAMU LINGU', 5302), -(5302020, 'TABUNDUNG', 5302), -(5302021, 'PINUPAHAR', 5302), -(5302030, 'PABERIWAI', 5302), -(5302031, 'KARERA', 5302), -(5302032, 'MATAWAI LA PAWU', 5302), -(5302033, 'KAHAUNGU ETI', 5302), -(5302034, 'MAHU', 5302), -(5302035, 'NGADU NGALA', 5302), -(5302040, 'PAHUNGA LODU', 5302), -(5302041, 'WULA WAIJELU', 5302), -(5302051, 'RINDI', 5302), -(5302052, 'UMALULU', 5302), -(5302060, 'PANDAWAI', 5302), -(5302061, 'KAMBATA MAPAMBUHANG', 5302), -(5302070, 'KOTA WAINGAPU', 5302), -(5302071, 'KAMBERA', 5302), -(5302080, 'HAHARU', 5302), -(5302081, 'KANATANG', 5302), -(5303100, 'SEMAU', 5303), -(5303101, 'SEMAU SELATAN', 5303), -(5303110, 'KUPANG BARAT', 5303), -(5303111, 'NEKAMESE', 5303), -(5303120, 'KUPANG TENGAH', 5303), -(5303121, 'TAEBENU', 5303), -(5303130, 'AMARASI', 5303), -(5303131, 'AMARASI BARAT', 5303), -(5303132, 'AMARASI SELATAN', 5303), -(5303133, 'AMARASI TIMUR', 5303), -(5303140, 'KUPANG TIMUR', 5303), -(5303141, 'AMABI OEFETO TIMUR', 5303), -(5303142, 'AMABI OEFETO', 5303), -(5303150, 'SULAMU', 5303), -(5303160, 'FATULEU', 5303), -(5303161, 'FATULEU TENGAH', 5303), -(5303162, 'FATULEU BARAT', 5303), -(5303170, 'TAKARI', 5303), -(5303180, 'AMFOANG SELATAN', 5303), -(5303181, 'AMFOANG BARAT DAYA', 5303), -(5303182, 'AMFOANG TENGAH', 5303), -(5303190, 'AMFOANG UTARA', 5303), -(5303191, 'AMFOANG BARAT LAUT', 5303), -(5303192, 'AMFOANG TIMUR', 5303), -(5304010, 'MOLLO UTARA', 5304), -(5304011, 'FATUMNASI', 5304), -(5304012, 'TOBU', 5304), -(5304013, 'NUNBENA', 5304), -(5304020, 'MOLLO SELATAN', 5304), -(5304021, 'POLEN', 5304), -(5304022, 'MOLLO BARAT', 5304), -(5304023, 'MOLLO TENGAH', 5304), -(5304030, 'KOTA SOE', 5304), -(5304040, 'AMANUBAN BARAT', 5304), -(5304041, 'BATU PUTIH', 5304), -(5304042, 'KUATNANA', 5304), -(5304050, 'AMANUBAN SELATAN', 5304), -(5304051, 'NOEBEBA', 5304), -(5304060, 'KUAN FATU', 5304), -(5304061, 'KUALIN', 5304), -(5304070, 'AMANUBAN TENGAH', 5304), -(5304071, 'KOLBANO', 5304), -(5304072, 'OENINO', 5304), -(5304080, 'AMANUBAN TIMUR', 5304), -(5304081, 'FAUTMOLO', 5304), -(5304082, 'FATUKOPA', 5304), -(5304090, 'KIE', 5304), -(5304091, 'KOT''OLIN', 5304), -(5304100, 'AMANATUN SELATAN', 5304), -(5304101, 'BOKING', 5304), -(5304102, 'NUNKOLO', 5304), -(5304103, 'NOEBANA', 5304), -(5304104, 'SANTIAN', 5304), -(5304110, 'AMANATUN UTARA', 5304), -(5304111, 'TOIANAS', 5304), -(5304112, 'KOKBAUN', 5304), -(5305010, 'MIOMAFFO BARAT', 5305), -(5305011, 'MIOMAFFO TENGAH', 5305), -(5305012, 'MUSI', 5305), -(5305013, 'MUTIS', 5305), -(5305020, 'MIOMAFFO TIMUR', 5305), -(5305021, 'NOEMUTI', 5305), -(5305022, 'BIKOMI SELATAN', 5305), -(5305023, 'BIKOMI TENGAH', 5305), -(5305024, 'BIKOMI NILULAT', 5305), -(5305025, 'BIKOMI UTARA', 5305), -(5305026, 'NAIBENU', 5305), -(5305027, 'NOEMUTI TIMUR', 5305), -(5305030, 'KOTA KEFAMENANU', 5305), -(5305040, 'INSANA', 5305), -(5305041, 'INSANA UTARA', 5305), -(5305042, 'INSANA BARAT', 5305), -(5305043, 'INSANA TENGAH', 5305), -(5305044, 'INSANA FAFINESU', 5305), -(5305050, 'BIBOKI SELATAN', 5305), -(5305051, 'BIBOKI TANPAH', 5305), -(5305052, 'BIBOKI MOENLEU', 5305), -(5305060, 'BIBOKI UTARA', 5305), -(5305061, 'BIBOKI ANLEU', 5305), -(5305062, 'BIBOKI FEOTLEU', 5305), -(5306010, 'MALAKA BARAT', 5306), -(5306011, 'RINHAT', 5306), -(5306012, 'WEWIKU', 5306), -(5306013, 'WELIMAN', 5306), -(5306020, 'MALAKA TENGAH', 5306), -(5306021, 'SASITA MEAN', 5306), -(5306022, 'BOTIN LEOBELE', 5306), -(5306023, 'IO KUFEU', 5306), -(5306030, 'MALAKA TIMUR', 5306), -(5306031, 'LAEN MANEN', 5306), -(5306032, 'RAI MANUK', 5306), -(5306040, 'KOBALIMA', 5306), -(5306041, 'KOBALIMA TIMUR', 5306), -(5306050, 'TASIFETO BARAT', 5306), -(5306051, 'KAKULUK MESAK', 5306), -(5306052, 'NANAET DUBESI', 5306), -(5306060, 'ATAMBUA', 5306), -(5306061, 'ATAMBUA BARAT', 5306), -(5306062, 'ATAMBUA SELATAN', 5306), -(5306070, 'TASIFETO TIMUR', 5306), -(5306071, 'RAIHAT', 5306), -(5306072, 'LASIOLAT', 5306), -(5306080, 'LAMAKNEN', 5306), -(5306081, 'LAMAKNEN SELATAN', 5306), -(5307010, 'PANTAR', 5307), -(5307011, 'PANTAR BARAT', 5307), -(5307012, 'PANTAR TIMUR', 5307), -(5307013, 'PANTAR BARAT LAUT', 5307), -(5307014, 'PANTAR TENGAH', 5307), -(5307020, 'ALOR BARAT DAYA', 5307), -(5307021, 'MATARU', 5307), -(5307030, 'ALOR SELATAN', 5307), -(5307040, 'ALOR TIMUR', 5307), -(5307041, 'ALOR TIMUR LAUT', 5307), -(5307042, 'PUREMAN', 5307), -(5307050, 'TELUK MUTIARA', 5307), -(5307051, 'KABOLA', 5307), -(5307060, 'ALOR BARAT LAUT', 5307), -(5307061, 'ALOR TENGAH UTARA', 5307), -(5307062, 'PULAU PURA', 5307), -(5307063, 'LEMBUR', 5307), -(5308010, 'NAGAWUTUNG', 5308), -(5308011, 'WULANDONI', 5308), -(5308020, 'ATADEI', 5308), -(5308030, 'ILE APE', 5308), -(5308031, 'ILE APE TIMUR', 5308), -(5308040, 'LEBATUKAN', 5308), -(5308050, 'NUBATUKAN', 5308), -(5308060, 'OMESURI', 5308), -(5308070, 'BUYASARI', 5308), -(5309010, 'WULANGGITANG', 5309), -(5309011, 'TITEHENA', 5309), -(5309012, 'ILEBURA', 5309), -(5309020, 'TANJUNG BUNGA', 5309), -(5309021, 'LEWO LEMA', 5309), -(5309030, 'LARANTUKA', 5309), -(5309031, 'ILE MANDIRI', 5309), -(5309032, 'DEMON PAGONG', 5309), -(5309040, 'SOLOR BARAT', 5309), -(5309041, 'SOLOR SELATAN', 5309), -(5309050, 'SOLOR TIMUR', 5309), -(5309060, 'ADONARA BARAT', 5309), -(5309061, 'WOTAN ULU MADO', 5309), -(5309062, 'ADONARA TENGAH', 5309), -(5309070, 'ADONARA TIMUR', 5309), -(5309071, 'ILE BOLENG', 5309), -(5309072, 'WITIHAMA', 5309), -(5309073, 'KELUBAGOLIT', 5309), -(5309074, 'ADONARA', 5309), -(5310010, 'PAGA', 5310), -(5310011, 'MEGO', 5310), -(5310012, 'TANA WAWO', 5310), -(5310020, 'LELA', 5310), -(5310030, 'BOLA', 5310), -(5310031, 'DORENG', 5310), -(5310032, 'MAPITARA', 5310), -(5310040, 'TALIBURA', 5310), -(5310041, 'WAIGETE', 5310), -(5310042, 'WAIBLAMA', 5310), -(5310050, 'KEWAPANTE', 5310), -(5310051, 'HEWOKLOANG', 5310), -(5310052, 'KANGAE', 5310), -(5310061, 'PALUE', 5310), -(5310062, 'KOTING', 5310), -(5310063, 'NELLE', 5310), -(5310070, 'NITA', 5310), -(5310071, 'MAGEPANDA', 5310), -(5310080, 'ALOK', 5310), -(5310081, 'ALOK BARAT', 5310), -(5310082, 'ALOK TIMUR', 5310), -(5311010, 'NANGAPANDA', 5311), -(5311011, 'PULAU ENDE', 5311), -(5311012, 'MAUKARO', 5311), -(5311020, 'ENDE', 5311), -(5311030, 'ENDE SELATAN', 5311), -(5311031, 'ENDE TIMUR', 5311), -(5311032, 'ENDE TENGAH', 5311), -(5311033, 'ENDE UTARA', 5311), -(5311040, 'NDONA', 5311), -(5311041, 'NDONA TIMUR', 5311), -(5311050, 'WOLOWARU', 5311), -(5311051, 'WOLOJITA', 5311), -(5311052, 'LIO TIMUR', 5311), -(5311053, 'KELIMUTU', 5311), -(5311054, 'NDORI', 5311), -(5311060, 'MAUROLE', 5311), -(5311061, 'KOTABARU', 5311), -(5311062, 'DETUKELI', 5311), -(5311063, 'LEPEMBUSU KELISOKE', 5311), -(5311070, 'DETUSOKO', 5311), -(5311071, 'WEWARIA', 5311), -(5312010, 'AIMERE', 5312), -(5312011, 'JEREBUU', 5312), -(5312020, 'BAJAWA', 5312), -(5312030, 'GOLEWA', 5312), -(5312070, 'BAJAWA UTARA', 5312), -(5312071, 'SOA', 5312), -(5312080, 'RIUNG', 5312), -(5312081, 'RIUNG BARAT', 5312), -(5312082, 'WOLOMEZE', 5312), -(5313040, 'SATAR MESE', 5313), -(5313041, 'SATAR MESE BARAT', 5313), -(5313110, 'LANGKE REMBONG', 5313), -(5313120, 'RUTENG', 5313), -(5313121, 'WAE RII', 5313), -(5313122, 'LELAK', 5313), -(5313123, 'RAHONG UTARA', 5313), -(5313130, 'CIBAL', 5313), -(5313140, 'REOK', 5313), -(5314010, 'ROTE BARAT DAYA', 5314), -(5314020, 'ROTE BARAT LAUT', 5314), -(5314030, 'LOBALAIN', 5314), -(5314040, 'ROTE TENGAH', 5314), -(5314041, 'ROTE SELATAN', 5314), -(5314050, 'PANTAI BARU', 5314), -(5314060, 'ROTE TIMUR', 5314), -(5314070, 'ROTE BARAT', 5314), -(5315010, 'KOMODO', 5315), -(5315011, 'BOLENG', 5315), -(5315020, 'SANO NGGOANG', 5315), -(5315030, 'LEMBOR', 5315), -(5315031, 'WELAK', 5315), -(5315040, 'KUWUS', 5315), -(5315050, 'MACANG PACAR', 5315), -(5316010, 'KATIKUTANA', 5316), -(5316011, 'KATIKUTANA SELATAN', 5316), -(5316020, 'UMBU RATU NGGAY BARAT', 5316), -(5316030, 'UMBU RATU NGGAY', 5316), -(5316040, 'MAMBORO', 5316), -(5317010, 'KODI BANGEDO', 5317), -(5317020, 'KODI', 5317), -(5317030, 'KODI UTARA', 5317), -(5317040, 'WEWEWA SELATAN', 5317), -(5317050, 'WEWEWA BARAT', 5317), -(5317060, 'WEWEWA TIMUR', 5317), -(5317070, 'WEWEWA UTARA', 5317), -(5317080, 'LOURA', 5317), -(5318010, 'MAUPONGGO', 5318), -(5318020, 'KEO TENGAH', 5318), -(5318030, 'NANGARORO', 5318), -(5318040, 'BOAWAE', 5318), -(5318050, 'AESESA SELATAN', 5318), -(5318060, 'AESESA', 5318), -(5318070, 'WOLOWAE', 5318), -(5319010, 'BORONG', 5319), -(5319020, 'KOTA KOMBA', 5319), -(5319030, 'ELAR', 5319), -(5319040, 'SAMBI RAMPAS', 5319), -(5319050, 'POCO RANAKA', 5319), -(5319060, 'LAMBA LEDA', 5319), -(5320010, 'RAIJUA', 5320), -(5320020, 'HAWU MEHARA', 5320), -(5320030, 'SABU LIAE', 5320), -(5320040, 'SABU BARAT', 5320), -(5320050, 'SABU TENGAH', 5320), -(5320060, 'SABU TIMUR', 5320), -(5371010, 'ALAK', 5371), -(5371020, 'MAULAFA', 5371), -(5371030, 'OEBOBO', 5371), -(5371031, 'KOTA RAJA', 5371), -(5371040, 'KELAPA LIMA', 5371), -(5371041, 'KOTA LAMA', 5371), -(6101010, 'SELAKAU', 6101), -(6101011, 'SELAKAU TIMUR', 6101), -(6101020, 'PEMANGKAT', 6101), -(6101021, 'SEMPARUK', 6101), -(6101022, 'SALATIGA', 6101), -(6101030, 'TEBAS', 6101), -(6101031, 'TEKARANG', 6101), -(6101040, 'SAMBAS', 6101), -(6101041, 'SUBAH', 6101), -(6101042, 'SEBAWI', 6101), -(6101043, 'SAJAD', 6101), -(6101050, 'JAWAI', 6101), -(6101051, 'JAWAI SELATAN', 6101), -(6101060, 'TELUK KERAMAT', 6101), -(6101061, 'GALING', 6101), -(6101062, 'TANGARAN', 6101), -(6101070, 'SEJANGKUNG', 6101), -(6101080, 'SAJINGAN BESAR', 6101), -(6101090, 'PALOH', 6101), -(6102010, 'SUNGAI RAYA', 6102), -(6102011, 'CAPKALA', 6102), -(6102012, 'SUNGAI RAYA KEPULAUAN', 6102), -(6102030, 'SAMALANTAN', 6102), -(6102031, 'MONTERADO', 6102), -(6102032, 'LEMBAH BAWANG', 6102), -(6102040, 'BENGKAYANG', 6102), -(6102041, 'TERIAK', 6102), -(6102042, 'SUNGAI BETUNG', 6102), -(6102050, 'LEDO', 6102), -(6102051, 'SUTI SEMARANG', 6102), -(6102052, 'LUMAR', 6102), -(6102060, 'SANGGAU LEDO', 6102), -(6102061, 'TUJUHBELAS', 6102), -(6102070, 'SELUAS', 6102), -(6102080, 'JAGOI BABANG', 6102), -(6102081, 'SIDING', 6102), -(6103020, 'SEBANGKI', 6103), -(6103030, 'NGABANG', 6103), -(6103031, 'JELIMPO', 6103), -(6103040, 'SENGAH TEMILA', 6103), -(6103050, 'MANDOR', 6103), -(6103060, 'MENJALIN', 6103), -(6103070, 'MEMPAWAH HULU', 6103), -(6103071, 'SOMPAK', 6103), -(6103080, 'MENYUKE', 6103), -(6103081, 'BANYUKE HULU', 6103), -(6103090, 'MERANTI', 6103), -(6103100, 'KUALA BEHE', 6103), -(6103110, 'AIR BESAR', 6103), -(6104080, 'SIANTAN', 6104), -(6104081, 'SEGEDONG', 6104), -(6104090, 'SUNGAI PINYUH', 6104), -(6104091, 'ANJONGAN', 6104), -(6104100, 'MEMPAWAH HILIR', 6104), -(6104101, 'MEMPAWAH TIMUR', 6104), -(6104110, 'SUNGAI KUNYIT', 6104), -(6104120, 'TOHO', 6104), -(6104121, 'SADANIANG', 6104), -(6105010, 'TOBA', 6105), -(6105020, 'MELIAU', 6105), -(6105060, 'KAPUAS', 6105), -(6105070, 'MUKOK', 6105), -(6105120, 'JANGKANG', 6105), -(6105130, 'BONTI', 6105), -(6105140, 'PARINDU', 6105), -(6105150, 'TAYAN HILIR', 6105), -(6105160, 'BALAI', 6105), -(6105170, 'TAYAN HULU', 6105), -(6105180, 'KEMBAYAN', 6105), -(6105190, 'BEDUWAI', 6105), -(6105200, 'NOYAN', 6105), -(6105210, 'SEKAYAM', 6105), -(6105220, 'ENTIKONG', 6105), -(6106010, 'KENDAWANGAN', 6106), -(6106020, 'MANIS MATA', 6106), -(6106030, 'MARAU', 6106), -(6106031, 'SINGKUP', 6106), -(6106032, 'AIR UPAS', 6106), -(6106040, 'JELAI HULU', 6106), -(6106050, 'TUMBANG TITI', 6106), -(6106051, 'PEMAHAN', 6106), -(6106052, 'SUNGAI MELAYU RAYAK', 6106), -(6106060, 'MATAN HILIR SELATAN', 6106), -(6106061, 'BENUA KAYONG', 6106), -(6106070, 'MATAN HILIR UTARA', 6106), -(6106071, 'DELTA PAWAN', 6106), -(6106072, 'MUARA PAWAN', 6106), -(6106090, 'NANGA TAYAP', 6106), -(6106100, 'SANDAI', 6106), -(6106101, 'HULU SUNGAI', 6106), -(6106110, 'SUNGAI LAUR', 6106), -(6106120, 'SIMPANG HULU', 6106), -(6106121, 'SIMPANG DUA', 6106), -(6107060, 'SERAWAI', 6107), -(6107070, 'AMBALAU', 6107), -(6107080, 'KAYAN HULU', 6107), -(6107110, 'SEPAUK', 6107), -(6107120, 'TEMPUNAK', 6107), -(6107130, 'SUNGAI TEBELIAN', 6107), -(6107140, 'SINTANG', 6107), -(6107150, 'DEDAI', 6107), -(6107160, 'KAYAN HILIR', 6107), -(6107170, 'KELAM PERMAI', 6107), -(6107180, 'BINJAI HULU', 6107), -(6107190, 'KETUNGAU HILIR', 6107), -(6107200, 'KETUNGAU TENGAH', 6107), -(6107210, 'KETUNGAU HULU', 6107), -(6108010, 'SILAT HILIR', 6108), -(6108020, 'SILAT HULU', 6108), -(6108030, 'HULU GURUNG', 6108), -(6108040, 'BUNUT HULU', 6108), -(6108050, 'MENTEBAH', 6108), -(6108060, 'BIKA', 6108), -(6108070, 'KALIS', 6108), -(6108080, 'PUTUSSIBAU SELATAN', 6108), -(6108081, 'HULU KAPUAS', 6108), -(6108090, 'EMBALOH HILIR', 6108), -(6108100, 'BUNUT HILIR', 6108), -(6108110, 'BOYAN TANJUNG', 6108), -(6108120, 'PENGKADAN', 6108), -(6108130, 'JONGKONG', 6108), -(6108140, 'SELIMBAU', 6108), -(6108141, 'DANAU SENTARUM', 6108), -(6108150, 'SUHAID', 6108), -(6108160, 'SEBERUANG', 6108), -(6108170, 'SEMITAU', 6108), -(6108180, 'EMPANANG', 6108), -(6108190, 'PURING KENCANA', 6108), -(6108200, 'BADAU', 6108), -(6108210, 'BATANG LUPAR', 6108), -(6108220, 'EMBALOH HULU', 6108), -(6108230, 'PUTUSSIBAU UTARA', 6108), -(6109010, 'NANGA MAHAP', 6109), -(6109020, 'NANGA TAMAN', 6109), -(6109030, 'SEKADAU HULU', 6109), -(6109040, 'SEKADAU HILIR', 6109), -(6109050, 'BELITANG HILIR', 6109), -(6109060, 'BELITANG', 6109), -(6109070, 'BELITANG HULU', 6109), -(6110010, 'SOKAN', 6110), -(6110020, 'TANAH PINOH', 6110), -(6110021, 'TANAH PINOH BARAT', 6110), -(6110030, 'SAYAN', 6110), -(6110040, 'BELIMBING', 6110), -(6110041, 'BELIMBING HULU', 6110), -(6110050, 'NANGA PINOH', 6110), -(6110051, 'PINOH SELATAN', 6110), -(6110052, 'PINOH UTARA', 6110), -(6110060, 'ELLA HILIR', 6110), -(6110070, 'MENUKUNG', 6110), -(6111010, 'PULAU MAYA KARIMATA', 6111), -(6111020, 'SUKADANA', 6111), -(6111030, 'SIMPANG HILIR', 6111), -(6111040, 'TELUK BATANG', 6111), -(6111050, 'SEPONTI', 6111), -(6112010, 'BATU AMPAR', 6112), -(6112020, 'TERENTANG', 6112), -(6112030, 'KUBU', 6112), -(6112040, 'TELOK PA''KEDAI', 6112), -(6112050, 'SUNGAI KAKAP', 6112), -(6112060, 'RASAU JAYA', 6112), -(6112070, 'SUNGAI RAYA', 6112), -(6112080, 'SUNGAI AMBAWANG', 6112), -(6112090, 'KUALA MANDOR-B', 6112), -(6171010, 'PONTIANAK SELATAN', 6171), -(6171011, 'PONTIANAK TENGGARA', 6171), -(6171020, 'PONTIANAK TIMUR', 6171), -(6171030, 'PONTIANAK BARAT', 6171), -(6171031, 'PONTIANAK KOTA', 6171), -(6171040, 'PONTIANAK UTARA', 6171), -(6172010, 'SINGKAWANG SELATAN', 6172), -(6172020, 'SINGKAWANG TIMUR', 6172), -(6172030, 'SINGKAWANG UTARA', 6172), -(6172040, 'SINGKAWANG BARAT', 6172), -(6172050, 'SINGKAWANG TENGAH', 6172), -(6201040, 'KOTAWARINGIN LAMA', 6201), -(6201050, 'ARUT SELATAN', 6201), -(6201060, 'KUMAI', 6201), -(6201061, 'PANGKALAN BANTENG', 6201), -(6201062, 'PANGKALAN LADA', 6201), -(6201070, 'ARUT UTARA', 6201), -(6202020, 'MENTAYA HILIR SELATAN', 6202), -(6202021, 'TELUK SAMPIT', 6202), -(6202050, 'PULAU HANAUT', 6202), -(6202060, 'MENTAWA BARU/KETAPANG', 6202), -(6202061, 'SERANAU', 6202), -(6202070, 'MENTAYA HILIR UTARA', 6202), -(6202110, 'KOTA BESI', 6202), -(6202111, 'TELAWANG', 6202), -(6202120, 'BAAMANG', 6202), -(6202190, 'CEMPAGA', 6202), -(6202191, 'CEMPAGA HULU', 6202), -(6202200, 'PARENGGEAN', 6202), -(6202210, 'MENTAYA HULU', 6202), -(6202211, 'BUKIT SANTUAI', 6202), -(6202230, 'ANTANG KALANG', 6202), -(6203020, 'KAPUAS KUALA', 6203), -(6203021, 'TAMBAN CATUR', 6203), -(6203030, 'KAPUAS TIMUR', 6203), -(6203040, 'SELAT', 6203), -(6203041, 'BATAGUH', 6203), -(6203070, 'BASARANG', 6203), -(6203080, 'KAPUAS HILIR', 6203), -(6203090, 'PULAU PETAK', 6203), -(6203100, 'KAPUAS MURUNG', 6203), -(6203101, 'DADAHUP', 6203), -(6203110, 'KAPUAS BARAT', 6203), -(6203150, 'MANTANGAI', 6203), -(6203160, 'TIMPAH', 6203), -(6203170, 'KAPUAS TENGAH', 6203), -(6203171, 'PASAK TALAWANG', 6203), -(6203180, 'KAPUAS HULU', 6203), -(6203181, 'MANDAU TALAWANG', 6203), -(6204010, 'JENAMAS', 6204), -(6204020, 'DUSUN HILIR', 6204), -(6204030, 'KARAU KUALA', 6204), -(6204040, 'DUSUN SELATAN', 6204), -(6204050, 'DUSUN UTARA', 6204), -(6204060, 'GUNUNG BINTANG AWAI', 6204), -(6205010, 'MONTALAT', 6205), -(6205020, 'GUNUNG TIMANG', 6205), -(6205030, 'GUNUNG PUREI', 6205), -(6205040, 'TEWEH TIMUR', 6205), -(6205050, 'TEWEH TENGAH', 6205), -(6205060, 'LAHEI', 6205), -(6206010, 'JELAI', 6206), -(6206011, 'PANTAI LUNCI', 6206), -(6206020, 'SUKAMARA', 6206), -(6206030, 'BALAI RIAM', 6206), -(6206031, 'PERMATA KECUBUNG', 6206), -(6207010, 'BULIK', 6207), -(6207011, 'SEMATU JAYA', 6207), -(6207012, 'MENTHOBI RAYA', 6207), -(6207013, 'BULIK TIMUR', 6207), -(6207020, 'LAMANDAU', 6207), -(6207021, 'BELANTIKAN RAYA', 6207), -(6207030, 'DELANG', 6207), -(6207031, 'BATANGKAWA', 6207), -(6208010, 'SERUYAN HILIR', 6208), -(6208020, 'DANAU SEMBULUH', 6208), -(6208030, 'HANAU', 6208), -(6208040, 'SERUYAN TENGAH', 6208), -(6208050, 'SERUYAN HULU', 6208), -(6209010, 'KATINGAN KUALA', 6209), -(6209020, 'MENDAWAI', 6209), -(6209030, 'KAMIPANG', 6209), -(6209040, 'TASIK PAYAWAN', 6209), -(6209050, 'KATINGAN HILIR', 6209), -(6209060, 'TEWANG SANGALANG GARING', 6209), -(6209070, 'PULAU MALAN', 6209), -(6209080, 'KATINGAN TENGAH', 6209), -(6209090, 'SANAMAN MANTIKEI', 6209), -(6209091, 'PETAK MALAI', 6209), -(6209100, 'MARIKIT', 6209), -(6209110, 'KATINGAN HULU', 6209), -(6209111, 'BUKIT RAYA', 6209), -(6210010, 'KAHAYAN KUALA', 6210), -(6210011, 'SEBANGAU KUALA', 6210), -(6210020, 'PANDIH BATU', 6210), -(6210030, 'MALIKU', 6210), -(6210040, 'KAHAYAN HILIR', 6210), -(6210041, 'JABIREN RAYA', 6210), -(6210050, 'KAHAYAN TENGAH', 6210), -(6210060, 'BANAMATINGANG', 6210), -(6211010, 'MANUHING', 6211), -(6211011, 'MANUHING RAYA', 6211), -(6211020, 'RUNGAN', 6211), -(6211021, 'RUNGAN HULU', 6211), -(6211030, 'SEPANG', 6211), -(6211031, 'MIHING RAYA', 6211), -(6211040, 'KURUN', 6211), -(6211050, 'TEWAH', 6211), -(6211060, 'KAHAYAN HULU UTARA', 6211), -(6211061, 'DAMANG BATU', 6211), -(6211062, 'MIRI MANASA', 6211), -(6212010, 'BENUA LIMA', 6212), -(6212020, 'DUSUN TIMUR', 6212), -(6212021, 'PAJU EPAT', 6212), -(6212030, 'AWANG', 6212), -(6212040, 'PATANGKEP TUTUI', 6212), -(6212050, 'DUSUN TENGAH', 6212), -(6212051, 'RAREN BATUAH', 6212), -(6212052, 'PAKU', 6212), -(6212053, 'KARUSEN JANANG', 6212), -(6212060, 'PEMATANG KARAU', 6212), -(6213010, 'PERMATA INTAN', 6213), -(6213011, 'SUNGAI BABUAT', 6213), -(6213020, 'MURUNG', 6213), -(6213030, 'LAUNG TUHUP', 6213), -(6213031, 'BARITO TUHUP RAYA', 6213), -(6213040, 'TANAH SIANG', 6213), -(6213041, 'TANAH SIANG SELATAN', 6213), -(6213050, 'SUMBER BARITO', 6213), -(6213051, 'SERIBU RIAM', 6213), -(6213052, 'UUT MURUNG', 6213), -(6271010, 'PAHANDUT', 6271), -(6271011, 'SEBANGAU', 6271), -(6271012, 'JEKAN RAYA', 6271), -(6271020, 'BUKIT BATU', 6271), -(6271021, 'RAKUMPIT', 6271), -(6301010, 'PANYIPATAN', 6301), -(6301020, 'TAKISUNG', 6301), -(6301030, 'KURAU', 6301), -(6301031, 'BUMI MAKMUR', 6301), -(6301040, 'BATI - BATI', 6301), -(6301050, 'TAMBANG ULANG', 6301), -(6301060, 'PELAIHARI', 6301), -(6301061, 'BAJUIN', 6301), -(6301070, 'BATU AMPAR', 6301), -(6301080, 'JORONG', 6301), -(6301090, 'KINTAP', 6301), -(6302010, 'PULAU SEMBILAN', 6302), -(6302020, 'PULAU LAUT BARAT', 6302), -(6302030, 'PULAU LAUT SELATAN', 6302), -(6302031, 'PULAU LAUT KEPULAUAN', 6302), -(6302040, 'PULAU LAUT TIMUR', 6302), -(6302050, 'PULAU SEBUKU', 6302), -(6302060, 'PULAU LAUT UTARA', 6302), -(6302061, 'PULAU LAUT TENGAH', 6302), -(6302120, 'KELUMPANG SELATAN', 6302), -(6302121, 'KELUMPANG HILIR', 6302), -(6302130, 'KELUMPANG HULU', 6302), -(6302140, 'HAMPANG', 6302), -(6302150, 'SUNGAI DURIAN', 6302), -(6302160, 'KELUMPANG TENGAH', 6302), -(6302161, 'KELUMPANG BARAT', 6302), -(6302170, 'KELUMPANG UTARA', 6302), -(6302180, 'PAMUKAN SELATAN', 6302), -(6302190, 'SAMPANAHAN', 6302), -(6302200, 'PAMUKAN UTARA', 6302), -(6302210, 'PAMUKAN BARAT', 6302), -(6303010, 'ALUH - ALUH', 6303), -(6303011, 'BERUNTUNG BARU', 6303), -(6303020, 'GAMBUT', 6303), -(6303030, 'KERTAK HANYAR', 6303), -(6303031, 'TATAH MAKMUR', 6303), -(6303040, 'SUNGAI TABUK', 6303), -(6303050, 'MARTAPURA', 6303), -(6303051, 'MARTAPURA TIMUR', 6303), -(6303052, 'MARTAPURA BARAT', 6303), -(6303060, 'ASTAMBUL', 6303), -(6303070, 'KARANG INTAN', 6303), -(6303080, 'ARANIO', 6303), -(6303090, 'SUNGAI PINANG', 6303), -(6303091, 'PARAMASAN', 6303), -(6303100, 'PENGARON', 6303), -(6303101, 'SAMBUNG MAKMUR', 6303), -(6303110, 'MATARAMAN', 6303), -(6303120, 'SIMPANG EMPAT', 6303), -(6303121, 'TELAGA BAUNTUNG', 6303), -(6304010, 'TABUNGANEN', 6304), -(6304020, 'TAMBAN', 6304), -(6304030, 'MEKAR SARI', 6304), -(6304040, 'ANJIR PASAR', 6304), -(6304050, 'ANJIR MUARA', 6304), -(6304060, 'ALALAK', 6304), -(6304070, 'MANDASTANA', 6304), -(6304071, 'JEJANGKIT', 6304), -(6304080, 'BELAWANG', 6304), -(6304090, 'WANARAYA', 6304), -(6304100, 'BARAMBAI', 6304), -(6304110, 'RANTAU BADAUH', 6304), -(6304120, 'CERBON', 6304), -(6304130, 'BAKUMPAI', 6304), -(6304140, 'MARABAHAN', 6304), -(6304150, 'TABUKAN', 6304), -(6304160, 'KURIPAN', 6304), -(6305010, 'BINUANG', 6305), -(6305011, 'HATUNGUN', 6305), -(6305020, 'TAPIN SELATAN', 6305), -(6305021, 'SALAM BABARIS', 6305), -(6305030, 'TAPIN TENGAH', 6305), -(6305040, 'BUNGUR', 6305), -(6305050, 'PIANI', 6305), -(6305060, 'LOKPAIKAT', 6305), -(6305070, 'TAPIN UTARA', 6305), -(6305080, 'BAKARANGAN', 6305), -(6305090, 'CANDI LARAS SELATAN', 6305), -(6305100, 'CANDI LARAS UTARA', 6305), -(6306010, 'PADANG BATUNG', 6306), -(6306020, 'LOKSADO', 6306), -(6306030, 'TELAGA LANGSAT', 6306), -(6306040, 'ANGKINANG', 6306), -(6306050, 'KANDANGAN', 6306), -(6306060, 'SUNGAI RAYA', 6306), -(6306070, 'SIMPUR', 6306), -(6306080, 'KALUMPANG', 6306), -(6306090, 'DAHA SELATAN', 6306), -(6306091, 'DAHA BARAT', 6306), -(6306100, 'DAHA UTARA', 6306), -(6307010, 'HARUYAN', 6307), -(6307020, 'BATU BENAWA', 6307), -(6307030, 'HANTAKAN', 6307), -(6307040, 'BATANG ALAI SELATAN', 6307), -(6307041, 'BATANG ALAI TIMUR', 6307), -(6307050, 'BARABAI', 6307), -(6307060, 'LABUAN AMAS SELATAN', 6307), -(6307070, 'LABUAN AMAS UTARA', 6307), -(6307080, 'PANDAWAN', 6307), -(6307090, 'BATANG ALAI UTARA', 6307), -(6307091, 'LIMPASU', 6307), -(6308010, 'DANAU PANGGANG', 6308), -(6308011, 'PAMINGGIR', 6308), -(6308020, 'BABIRIK', 6308), -(6308030, 'SUNGAI PANDAN', 6308), -(6308031, 'SUNGAI TABUKAN', 6308), -(6308040, 'AMUNTAI SELATAN', 6308), -(6308050, 'AMUNTAI TENGAH', 6308), -(6308060, 'BANJANG', 6308), -(6308070, 'AMUNTAI UTARA', 6308), -(6308071, 'HAUR GADING', 6308), -(6309010, 'BANUA LAWAS', 6309), -(6309020, 'PUGAAN', 6309), -(6309030, 'KELUA', 6309), -(6309040, 'MUARA HARUS', 6309), -(6309050, 'TANTA', 6309), -(6309060, 'TANJUNG', 6309), -(6309070, 'MURUNG PUDAK', 6309), -(6309080, 'HARUAI', 6309), -(6309081, 'BINTANG ARA', 6309), -(6309090, 'UPAU', 6309), -(6309100, 'MUARA UYA', 6309), -(6309110, 'JARO', 6309), -(6310010, 'KUSAN HILIR', 6310), -(6310020, 'SUNGAI LOBAN', 6310), -(6310030, 'SATUI', 6310), -(6310031, 'ANGSANA', 6310), -(6310040, 'KUSAN HULU', 6310), -(6310041, 'KURANJI', 6310), -(6310050, 'BATU LICIN', 6310), -(6310051, 'KARANG BINTANG', 6310), -(6310052, 'SIMPANG EMPAT', 6310), -(6310053, 'MANTEWE', 6310), -(6311010, 'LAMPIHONG', 6311), -(6311020, 'BATU MANDI', 6311), -(6311030, 'AWAYAN', 6311), -(6311031, 'TEBING TINGGI', 6311), -(6311040, 'PARINGIN', 6311), -(6311041, 'PARINGIN SELATAN', 6311), -(6311050, 'JUAI', 6311), -(6311060, 'HALONG', 6311), -(6371010, 'BANJARMASIN SELATAN', 6371), -(6371020, 'BANJARMASIN TIMUR', 6371), -(6371030, 'BANJARMASIN BARAT', 6371), -(6371031, 'BANJARMASIN TENGAH', 6371), -(6371040, 'BANJARMASIN UTARA', 6371), -(6372010, 'LANDASAN ULIN', 6372), -(6372011, 'LIANG ANGGANG', 6372), -(6372020, 'CEMPAKA', 6372), -(6372031, 'BANJAR BARU UTARA', 6372), -(6372032, 'BANJAR BARU SELATAN', 6372), -(6401010, 'BATU SOPANG', 6401), -(6401011, 'MUARA SAMU', 6401), -(6401021, 'BATU ENGAU', 6401), -(6401022, 'TANJUNG HARAPAN', 6401), -(6401030, 'PASIR BELENGKONG', 6401), -(6401040, 'TANAH GROGOT', 6401), -(6401050, 'KUARO', 6401), -(6401060, 'LONG IKIS', 6401), -(6401070, 'MUARA KOMAM', 6401), -(6401080, 'LONG KALI', 6401), -(6402010, 'BONGAN', 6402), -(6402020, 'JEMPANG', 6402), -(6402030, 'PENYINGGAHAN', 6402), -(6402040, 'MUARA PAHU', 6402), -(6402041, 'SILUQ NGURAI', 6402), -(6402050, 'MUARA LAWA', 6402), -(6402051, 'BENTIAN BESAR', 6402), -(6402060, 'DAMAI', 6402), -(6402061, 'NYUATAN', 6402), -(6402070, 'BARONG TONGKOK', 6402), -(6402071, 'LINGGANG BIGUNG', 6402), -(6402080, 'MELAK', 6402), -(6402081, 'SEKOLAQ DARAT', 6402), -(6402082, 'MANOR BULATN', 6402), -(6402090, 'LONG IRAM', 6402), -(6402091, 'TERING', 6402), -(6402100, 'LONG HUBUNG', 6402), -(6402101, 'LAHAM', 6402), -(6402110, 'LONG BAGUN', 6402), -(6402120, 'LONG PAHANGAI', 6402), -(6402130, 'LONG APARI', 6402), -(6403010, 'SEMBOJA', 6403), -(6403020, 'MUARA JAWA', 6403), -(6403030, 'SANGA-SANGA', 6403), -(6403040, 'LOA JANAN', 6403), -(6403050, 'LOA KULU', 6403), -(6403060, 'MUARA MUNTAI', 6403), -(6403070, 'MUARA WIS', 6403), -(6403080, 'KOTABANGUN', 6403), -(6403090, 'TENGGARONG', 6403), -(6403100, 'SEBULU', 6403), -(6403110, 'TENGGARONG SEBERANG', 6403), -(6403120, 'ANGGANA', 6403), -(6403130, 'MUARA BADAK', 6403), -(6403140, 'MARANG KAYU', 6403), -(6403150, 'MUARA KAMAN', 6403), -(6403160, 'KENOHAN', 6403), -(6403170, 'KEMBANG JANGGUT', 6403), -(6403180, 'TABANG', 6403), -(6404010, 'MUARA ANCALONG', 6404), -(6404011, 'BUSANG', 6404), -(6404012, 'LONG MESANGAT', 6404), -(6404020, 'MUARA WAHAU', 6404), -(6404021, 'TELEN', 6404), -(6404022, 'KONGBENG', 6404), -(6404030, 'MUARA BENGKAL', 6404), -(6404031, 'BATU AMPAR', 6404), -(6404040, 'SANGATTA UTARA', 6404), -(6404041, 'BENGALON', 6404), -(6404042, 'TELUK PANDAN', 6404), -(6404043, 'SANGATTA SELATAN', 6404), -(6404044, 'RANTAU PULUNG', 6404), -(6404050, 'SANGKULIRANG', 6404), -(6404051, 'KALIORANG', 6404), -(6404052, 'SANDARAN', 6404), -(6404053, 'KAUBUN', 6404), -(6404054, 'KARANGAN', 6404), -(6405010, 'KELAY', 6405), -(6405020, 'TALISAYAN', 6405), -(6405021, 'TABALAR', 6405), -(6405030, 'BIDUK BIDUK', 6405), -(6405040, 'PULAU DERAWAN', 6405), -(6405041, 'MARATUA', 6405), -(6405050, 'SAMBALIUNG', 6405), -(6405060, 'TANJUNG REDEB', 6405), -(6405070, 'GUNUNG TABUR', 6405), -(6405080, 'SEGAH', 6405), -(6405090, 'TELUK BAYUR', 6405), -(6405100, 'BATU PUTIH', 6405), -(6405110, 'BIATAN', 6405), -(6406010, 'KAYAN HULU', 6406), -(6406011, 'SUNGAI BOH', 6406), -(6406012, 'KAYAN SELATAN', 6406), -(6406020, 'KAYAN HILIR', 6406), -(6406030, 'PUJUNGAN', 6406), -(6406031, 'BAHAU HULU', 6406), -(6406040, 'MALINAU KOTA', 6406), -(6406041, 'MALINAU SELATAN', 6406), -(6406042, 'MALINAU BARAT', 6406), -(6406043, 'MALINAU UTARA', 6406), -(6406050, 'MENTARANG', 6406), -(6406051, 'MENTARANG HULU', 6406), -(6407010, 'PESO', 6407), -(6407011, 'PESO HILIR', 6407), -(6407020, 'TANJUNG PALAS', 6407), -(6407021, 'TANJUNG PALAS BARAT', 6407), -(6407022, 'TANJUNG PALAS UTARA', 6407), -(6407023, 'TANJUNG PALAS TIMUR', 6407), -(6407024, 'TANJUNG SELOR', 6407), -(6407025, 'TANJUNG PALAS TENGAH', 6407), -(6407030, 'SEKATAK', 6407), -(6407050, 'BUNYU', 6407), -(6408010, 'KRAYAN', 6408), -(6408011, 'KRAYAN SELATAN', 6408), -(6408020, 'LUMBIS', 6408), -(6408030, 'SEMBAKUNG', 6408), -(6408040, 'NUNUKAN', 6408), -(6408041, 'SEBUKU', 6408), -(6408042, 'NUNUKAN SELATAN', 6408), -(6408050, 'SEBATIK', 6408), -(6408051, 'SEBATIK BARAT', 6408), -(6409010, 'BABULU', 6409), -(6409020, 'WARU', 6409), -(6409030, 'PENAJAM', 6409), -(6409040, 'SEPAKU', 6409), -(6410010, 'SESAYAP', 6410), -(6410020, 'SESAYAP HILIR', 6410), -(6410030, 'TANA LIA', 6410), -(6471010, 'BALIKPAPAN SELATAN', 6471), -(6471020, 'BALIKPAPAN TIMUR', 6471), -(6471030, 'BALIKPAPAN UTARA', 6471), -(6471040, 'BALIKPAPAN TENGAH', 6471), -(6471050, 'BALIKPAPAN BARAT', 6471), -(6472010, 'PALARAN', 6472), -(6472020, 'SAMARINDA ILIR', 6472), -(6472021, 'SAMARINDA KOTA', 6472), -(6472022, 'SAMBUTAN', 6472), -(6472030, 'SAMARINDA SEBERANG', 6472), -(6472031, 'LOA JANAN ILIR', 6472), -(6472040, 'SUNGAI KUNJANG', 6472), -(6472050, 'SAMARINDA ULU', 6472), -(6472060, 'SAMARINDA UTARA', 6472), -(6472061, 'SUNGAI PINANG', 6472), -(6473010, 'TARAKAN TIMUR', 6473), -(6473020, 'TARAKAN TENGAH', 6473), -(6473030, 'TARAKAN BARAT', 6473), -(6473040, 'TARAKAN UTARA', 6473), -(6474010, 'BONTANG SELATAN', 6474), -(6474020, 'BONTANG UTARA', 6474), -(6474030, 'BONTANG BARAT', 6474), -(7101021, 'DUMOGA BARAT', 7101), -(7101022, 'DUMOGA UTARA', 7101), -(7101023, 'DUMOGA TIMUR', 7101), -(7101060, 'LOLAYAN', 7101), -(7101081, 'PASSI BARAT', 7101), -(7101082, 'PASSI TIMUR', 7101), -(7101083, 'BILALANG', 7101), -(7101090, 'POIGAR', 7101), -(7101100, 'BOLAANG', 7101), -(7101101, 'BOLAANG TIMUR', 7101), -(7101110, 'LOLAK', 7101), -(7101120, 'SANGTOMBOLANG', 7101), -(7102091, 'LANGOWAN TIMUR', 7102), -(7102092, 'LANGOWAN BARAT', 7102), -(7102093, 'LANGOWAN SELATAN', 7102), -(7102094, 'LANGOWAN UTARA', 7102), -(7102110, 'TOMPASO', 7102), -(7102120, 'KAWANGKOAN', 7102), -(7102121, 'KAWANGKOAN BARAT', 7102), -(7102122, 'KAWANGKOAN UTARA', 7102), -(7102130, 'SONDER', 7102), -(7102160, 'TOMBARIRI', 7102), -(7102170, 'PINELENG', 7102), -(7102171, 'TOMBULU', 7102), -(7102190, 'TONDANO BARAT', 7102), -(7102191, 'TONDANO SELATAN', 7102), -(7102200, 'REMBOKEN', 7102), -(7102210, 'KAKAS', 7102), -(7102211, 'KAKAS BARAT', 7102), -(7102220, 'LEMBEAN TIMUR', 7102), -(7102230, 'ERIS', 7102), -(7102240, 'KOMBI', 7102), -(7102250, 'TONDANO TIMUR', 7102), -(7102251, 'TONDANO UTARA', 7102), -(7103040, 'MANGANITU SELATAN', 7103), -(7103041, 'TATOARENG', 7103), -(7103050, 'TAMAKO', 7103), -(7103060, 'TABUKAN SELATAN', 7103), -(7103061, 'TABUKAN SELATAN TENGAH', 7103), -(7103062, 'TABUKAN SELATAN TENGGARA', 7103), -(7103070, 'TABUKAN TENGAH', 7103), -(7103080, 'MANGANITU', 7103), -(7103090, 'TAHUNA', 7103), -(7103091, 'TAHUNA TIMUR', 7103), -(7103092, 'TAHUNA BARAT', 7103), -(7103100, 'TABUKAN UTARA', 7103), -(7103101, 'NUSA TABUKAN', 7103), -(7103102, 'KEPULAUAN MARORE', 7103), -(7103110, 'KENDAHE', 7103), -(7104010, 'KABARUAN', 7104), -(7104011, 'DAMAU', 7104), -(7104020, 'LIRUNG', 7104), -(7104021, 'SALIBABU', 7104), -(7104022, 'KALONGAN', 7104), -(7104023, 'MORONGE', 7104), -(7104030, 'MELONGUANE', 7104), -(7104031, 'MELONGUANE TIMUR', 7104), -(7104040, 'BEO', 7104), -(7104041, 'BEO UTARA', 7104), -(7104042, 'BEO SELATAN', 7104), -(7104050, 'RAINIS', 7104), -(7104051, 'TAMPA NA''MMA', 7104), -(7104052, 'PULUTAN', 7104), -(7104060, 'ESSANG', 7104), -(7104061, 'ESSANG SELATAN', 7104), -(7104070, 'GEMEH', 7104), -(7104080, 'NANUSA', 7104), -(7104081, 'MIANGAS', 7104), -(7105010, 'MODOINDING', 7105), -(7105020, 'TOMPASO BARU', 7105), -(7105021, 'MAESAAN', 7105), -(7105070, 'RANOYAPO', 7105), -(7105080, 'MOTOLING', 7105), -(7105081, 'KUMELEMBUAI', 7105), -(7105082, 'MOTOLING BARAT', 7105), -(7105083, 'MOTOLING TIMUR', 7105), -(7105090, 'SINONSAYANG', 7105), -(7105100, 'TENGA', 7105), -(7105111, 'AMURANG', 7105), -(7105112, 'AMURANG BARAT', 7105), -(7105113, 'AMURANG TIMUR', 7105), -(7105120, 'TARERAN', 7105), -(7105121, 'SULTA', 7105), -(7105130, 'TUMPAAN', 7105), -(7105131, 'TATAPAAN', 7105), -(7106010, 'KEMA', 7106), -(7106020, 'KAUDITAN', 7106), -(7106030, 'AIRMADIDI', 7106), -(7106040, 'KALAWAT', 7106), -(7106050, 'DIMEMBE', 7106), -(7106051, 'TALAWAAN', 7106), -(7106060, 'WORI', 7106), -(7106070, 'LIKUPANG BARAT', 7106), -(7106080, 'LIKUPANG TIMUR', 7106), -(7106081, 'LIKUPANG SELATAN', 7106), -(7107010, 'SANGKUB', 7107), -(7107020, 'BINTAUNA', 7107), -(7107030, 'BOLANG ITANG TIMUR', 7107), -(7107040, 'BOLANG ITANG BARAT', 7107), -(7107050, 'KAIDIPANG', 7107), -(7107060, 'PINOGALUMAN', 7107), -(7108010, 'BIARO', 7108), -(7108020, 'TAGULANDANG SELATAN', 7108), -(7108030, 'TAGULANDANG', 7108), -(7108040, 'TAGULANDANG UTARA', 7108), -(7108050, 'SIAU BARAT SELATAN', 7108), -(7108060, 'SIAU TIMUR SELATAN', 7108), -(7108070, 'SIAU BARAT', 7108), -(7108080, 'SIAU TENGAH', 7108), -(7108090, 'SIAU TIMUR', 7108), -(7108100, 'SIAU BARAT UTARA', 7108), -(7109010, 'RATATOTOK', 7109), -(7109020, 'PUSOMAEN', 7109), -(7109030, 'BELANG', 7109), -(7109040, 'RATAHAN', 7109), -(7109041, 'PASAN', 7109), -(7109042, 'RATAHAN TIMUR', 7109), -(7109050, 'TOMBATU', 7109), -(7109051, 'TOMBATU TIMUR', 7109), -(7109052, 'TOMBATU UTARA', 7109), -(7109060, 'TOULUAAN', 7109), -(7109061, 'TOULUAAN SELATAN', 7109), -(7109062, 'SILIAN RAYA', 7109), -(7110010, 'POSIGADAN', 7110), -(7110020, 'BOLANG UKI', 7110), -(7110030, 'PINOLOSIAN', 7110), -(7110040, 'PINOLOSIAN TENGAH', 7110), -(7110050, 'PINOLOSIAN TIMUR', 7110), -(7111010, 'NUANGAN', 7111), -(7111020, 'TUTUYAN', 7111), -(7111030, 'KOTABUNAN', 7111), -(7111040, 'MODAYAG', 7111), -(7111050, 'MODAYAG BARAT', 7111), -(7171010, 'MALALAYANG', 7171), -(7171020, 'SARIO', 7171), -(7171021, 'WANEA', 7171), -(7171030, 'WENANG', 7171), -(7171031, 'TIKALA', 7171), -(7171040, 'MAPANGET', 7171), -(7171051, 'SINGKIL', 7171), -(7171052, 'TUMINTING', 7171), -(7171053, 'BUNAKEN', 7171), -(7172010, 'MADIDIR', 7172), -(7172011, 'MATUARI', 7172), -(7172012, 'GIRIAN', 7172), -(7172021, 'LEMBEH SELATAN', 7172), -(7172022, 'LEMBEH UTARA', 7172), -(7172030, 'AERTEMBAGA', 7172), -(7172031, 'MAESA', 7172), -(7172040, 'RANOWULU', 7172), -(7173010, 'TOMOHON SELATAN', 7173), -(7173020, 'TOMOHON TENGAH', 7173), -(7173021, 'TOMOHON TIMUR', 7173), -(7173022, 'TOMOHON BARAT', 7173), -(7173030, 'TOMOHON UTARA', 7173), -(7174010, 'KOTAMOBAGU SELATAN', 7174), -(7174020, 'KOTAMOBAGU TIMUR', 7174), -(7174030, 'KOTAMOBAGU BARAT', 7174), -(7174040, 'KOTAMOBAGU UTARA', 7174), -(7201010, 'LABOBO', 7201), -(7201011, 'BOKAN KEPULAUAN', 7201), -(7201012, 'BANGKURUNG', 7201), -(7201020, 'BANGGAI', 7201), -(7201021, 'BANGGAI UTARA', 7201), -(7201022, 'BANGGAI TENGAH', 7201), -(7201023, 'BANGGAI SELATAN', 7201), -(7201030, 'TOTIKUM', 7201), -(7201031, 'TOTIKUM SELATAN', 7201), -(7201040, 'TINANGKUNG', 7201), -(7201041, 'TINANGKUNG SELATAN', 7201), -(7201042, 'TINANGKUNG UTARA', 7201), -(7201050, 'LIANG', 7201), -(7201051, 'PELING TENGAH', 7201), -(7201060, 'BULAGI', 7201), -(7201061, 'BULAGI SELATAN', 7201), -(7201062, 'BULAGI UTARA', 7201), -(7201070, 'BUKO', 7201), -(7201071, 'BUKO SELATAN', 7201), -(7202010, 'TOILI', 7202), -(7202011, 'TOILI BARAT', 7202), -(7202012, 'MOILONG', 7202), -(7202020, 'BATUI', 7202), -(7202021, 'BATUI SELATAN', 7202), -(7202030, 'BUNTA', 7202), -(7202031, 'NUHON', 7202), -(7202032, 'SIMPANG RAYA', 7202), -(7202040, 'KINTOM', 7202), -(7202050, 'LUWUK', 7202), -(7202051, 'LUWUK TIMUR', 7202), -(7202060, 'PAGIMANA', 7202), -(7202061, 'BUALEMO', 7202); -INSERT INTO `kecamatan` (`kodeBps`, `namaKecamatan`, `kodeKabupaten`) VALUES -(7202062, 'LOBU', 7202), -(7202070, 'LAMALA', 7202), -(7202071, 'MASAMA', 7202), -(7202080, 'BALANTAK', 7202), -(7202081, 'BALANTAK SELATAN', 7202), -(7203010, 'MENUI KEPULAUAN', 7203), -(7203020, 'BUNGKU SELATAN', 7203), -(7203021, 'BAHODOPI', 7203), -(7203030, 'BUNGKU TENGAH', 7203), -(7203040, 'BUNGKU BARAT', 7203), -(7203041, 'BUMI RAYA', 7203), -(7203042, 'WITA PONDA', 7203), -(7203050, 'LEMBO', 7203), -(7203060, 'MORI ATAS', 7203), -(7203061, 'MORI UTARA', 7203), -(7203070, 'PETASIA', 7203), -(7203071, 'SOYO JAYA', 7203), -(7203080, 'BUNGKU UTARA', 7203), -(7203081, 'MAMOSALATO', 7203), -(7204010, 'PAMONA SELATAN', 7204), -(7204011, 'PAMONA BARAT', 7204), -(7204012, 'PAMONA TENGGARA', 7204), -(7204020, 'LORE SELATAN', 7204), -(7204021, 'LORE BARAT', 7204), -(7204030, 'PAMONA PUSALEMBA', 7204), -(7204031, 'PAMONA TIMUR', 7204), -(7204032, 'PAMONA UTARA', 7204), -(7204040, 'LORE UTARA', 7204), -(7204041, 'LORE TENGAH', 7204), -(7204042, 'LORE TIMUR', 7204), -(7204043, 'LORE PEORE', 7204), -(7204050, 'POSO PESISIR', 7204), -(7204051, 'POSO PESISIR SELATAN', 7204), -(7204052, 'POSO PESISIR UTARA', 7204), -(7204060, 'LAGE', 7204), -(7204070, 'POSO KOTA', 7204), -(7204071, 'POSO KOTA UTARA', 7204), -(7204072, 'POSO KOTA SELATAN', 7204), -(7205041, 'RIO PAKAVA', 7205), -(7205051, 'PINEMBANI', 7205), -(7205080, 'BANAWA', 7205), -(7205081, 'BANAWA SELATAN', 7205), -(7205082, 'BANAWA TENGAH', 7205), -(7205090, 'LABUAN', 7205), -(7205091, 'TANANTOVEA', 7205), -(7205100, 'SINDUE', 7205), -(7205101, 'SINDUE TOMBUSABORA', 7205), -(7205102, 'SINDUE TOBATA', 7205), -(7205120, 'SIRENJA', 7205), -(7205130, 'BALAESANG', 7205), -(7205131, 'BALAESANG TANJUNG', 7205), -(7205140, 'DAMSOL', 7205), -(7205160, 'SOJOL', 7205), -(7205161, 'SOJOL UTARA', 7205), -(7206010, 'DAMPAL SELATAN', 7206), -(7206020, 'DAMPAL UTARA', 7206), -(7206030, 'DONDO', 7206), -(7206031, 'OGODEIDE', 7206), -(7206032, 'BASIDONDO', 7206), -(7206040, 'BAOLAN', 7206), -(7206041, 'LAMPASIO', 7206), -(7206050, 'GALANG', 7206), -(7206060, 'TOLITOLI UTARA', 7206), -(7206061, 'DAKO PAMEAN', 7206), -(7207010, 'LAKEA', 7207), -(7207011, 'BIAU', 7207), -(7207012, 'KARAMAT', 7207), -(7207020, 'MOMUNU', 7207), -(7207021, 'TILOAN', 7207), -(7207030, 'BOKAT', 7207), -(7207031, 'BUKAL', 7207), -(7207040, 'BUNOBOGU', 7207), -(7207041, 'GADUNG', 7207), -(7207050, 'PALELEH', 7207), -(7207051, 'PALELEH BARAT', 7207), -(7208010, 'SAUSU', 7208), -(7208011, 'TORUE', 7208), -(7208012, 'BALINGGI', 7208), -(7208020, 'PARIGI', 7208), -(7208021, 'PARIGI SELATAN', 7208), -(7208022, 'PARIGI BARAT', 7208), -(7208023, 'PARIGI UTARA', 7208), -(7208024, 'PARIGI TENGAH', 7208), -(7208030, 'AMPIBABO', 7208), -(7208031, 'KASIMBAR', 7208), -(7208032, 'TORIBULU', 7208), -(7208033, 'SINIU', 7208), -(7208040, 'TINOMBO', 7208), -(7208041, 'TINOMBO SELATAN', 7208), -(7208050, 'TOMINI', 7208), -(7208051, 'MEPANGA', 7208), -(7208052, 'PALASA', 7208), -(7208060, 'MOUTONG', 7208), -(7208061, 'BOLANO LAMBUNU', 7208), -(7208062, 'TAOPA', 7208), -(7209010, 'TOJO BARAT', 7209), -(7209020, 'TOJO', 7209), -(7209030, 'ULUBONGKA', 7209), -(7209040, 'AMPANA TETE', 7209), -(7209050, 'AMPANA KOTA', 7209), -(7209060, 'UNA - UNA', 7209), -(7209070, 'TOGEAN', 7209), -(7209080, 'WALEA KEPULAUAN', 7209), -(7209081, 'WALEA BESAR', 7209), -(7210010, 'PIPIKORO', 7210), -(7210020, 'KULAWI SELATAN', 7210), -(7210030, 'KULAWI', 7210), -(7210040, 'LINDU', 7210), -(7210050, 'NOKILALAKI', 7210), -(7210060, 'PALOLO', 7210), -(7210070, 'GUMBASA', 7210), -(7210080, 'DOLO SELATAN', 7210), -(7210090, 'DOLO BARAT', 7210), -(7210100, 'TANAMBULAVA', 7210), -(7210110, 'DOLO', 7210), -(7210120, 'SIGI BIROMARU', 7210), -(7210130, 'MARAWOLA', 7210), -(7210140, 'MARAWOLA BARAT', 7210), -(7210150, 'KINOVARO', 7210), -(7271010, 'PALU BARAT', 7271), -(7271020, 'PALU SELATAN', 7271), -(7271030, 'PALU TIMUR', 7271), -(7271040, 'PALU UTARA', 7271), -(7301010, 'PASIMARANNU', 7301), -(7301011, 'PASILAMBENA', 7301), -(7301020, 'PASIMASSUNGGU', 7301), -(7301021, 'TAKABONERATE', 7301), -(7301022, 'PASIMASSUNGGU TIMUR', 7301), -(7301030, 'BONTOSIKUYU', 7301), -(7301040, 'BONTOHARU', 7301), -(7301041, 'BENTENG', 7301), -(7301042, 'BONTOMANAI', 7301), -(7301050, 'BONTOMATENE', 7301), -(7301051, 'BUKI', 7301), -(7302010, 'GANTARANG', 7302), -(7302020, 'UJUNG BULU', 7302), -(7302021, 'UJUNG LOE', 7302), -(7302030, 'BONTO BAHARI', 7302), -(7302040, 'BONTOTIRO', 7302), -(7302050, 'HERO LANGE-LANGE', 7302), -(7302060, 'KAJANG', 7302), -(7302070, 'BULUKUMPA', 7302), -(7302080, 'RILAU ALE', 7302), -(7302090, 'KINDANG', 7302), -(7303010, 'BISSAPPU', 7303), -(7303011, 'ULUERE', 7303), -(7303012, 'SINOA', 7303), -(7303020, 'BANTAENG', 7303), -(7303021, 'EREMERASA', 7303), -(7303030, 'TOMPOBULU', 7303), -(7303031, 'PA''JUKUKANG', 7303), -(7303032, 'GANTARANGKEKE', 7303), -(7304010, 'BANGKALA', 7304), -(7304011, 'BANGKALA BARAT', 7304), -(7304020, 'TAMALATEA', 7304), -(7304021, 'BONTORAMBA', 7304), -(7304030, 'BINAMU', 7304), -(7304031, 'TURATEA', 7304), -(7304040, 'BATANG', 7304), -(7304041, 'ARUNGKEKE', 7304), -(7304042, 'TAROWANG', 7304), -(7304050, 'KELARA', 7304), -(7304051, 'RUMBIA', 7304), -(7305010, 'MANGARA BOMBANG', 7305), -(7305020, 'MAPPAKASUNGGU', 7305), -(7305021, 'SANROBONE', 7305), -(7305030, 'POLOMBANGKENG SELATAN', 7305), -(7305031, 'PATTALLASSANG', 7305), -(7305040, 'POLOMBANGKENG UTARA', 7305), -(7305050, 'GALESONG SELATAN', 7305), -(7305051, 'GALESONG', 7305), -(7305060, 'GALESONG UTARA', 7305), -(7306010, 'BONTONOMPO', 7306), -(7306011, 'BONTONOMPO SELATAN', 7306), -(7306020, 'BAJENG', 7306), -(7306021, 'BAJENG BARAT', 7306), -(7306030, 'PALLANGGA', 7306), -(7306031, 'BAROMBONG', 7306), -(7306040, 'SOMBA OPU', 7306), -(7306050, 'BONTOMARANNU', 7306), -(7306051, 'PATTALLASSANG', 7306), -(7306060, 'PARANGLOE', 7306), -(7306061, 'MANUJU', 7306), -(7306070, 'TINGGIMONCONG', 7306), -(7306071, 'TOMBOLO PAO', 7306), -(7306072, 'PARIGI', 7306), -(7306080, 'BUNGAYA', 7306), -(7306081, 'BONTOLEMPANGAN', 7306), -(7306090, 'TOMPOBULU', 7306), -(7306091, 'BIRINGBULU', 7306), -(7307010, 'SINJAI BARAT', 7307), -(7307020, 'SINJAI BORONG', 7307), -(7307030, 'SINJAI SELATAN', 7307), -(7307040, 'TELLU LIMPOE', 7307), -(7307050, 'SINJAI TIMUR', 7307), -(7307060, 'SINJAI TENGAH', 7307), -(7307070, 'SINJAI UTARA', 7307), -(7307080, 'BULUPODDO', 7307), -(7307090, 'PULAU SEMBILAN', 7307), -(7308010, 'MANDAI', 7308), -(7308011, 'MONCONGLOE', 7308), -(7308020, 'MAROS BARU', 7308), -(7308021, 'MARUSU', 7308), -(7308022, 'TURIKALE', 7308), -(7308023, 'LAU', 7308), -(7308030, 'BONTOA', 7308), -(7308040, 'BANTIMURUNG', 7308), -(7308041, 'SIMBANG', 7308), -(7308050, 'TANRALILI', 7308), -(7308051, 'TOMPU BULU', 7308), -(7308060, 'CAMBA', 7308), -(7308061, 'CENRANA', 7308), -(7308070, 'MALLAWA', 7308), -(7309010, 'LIUKANG TANGAYA', 7309), -(7309020, 'LIUKANG KALMAS', 7309), -(7309030, 'LIUKANG TUPABBIRING', 7309), -(7309031, 'LIUKANG TUPABBIRING UTARA', 7309), -(7309040, 'PANGKAJENE', 7309), -(7309041, 'MINASATENE', 7309), -(7309050, 'BALOCCI', 7309), -(7309051, 'TONDONG TALLASA', 7309), -(7309060, 'BUNGORO', 7309), -(7309070, 'LABAKKANG', 7309), -(7309080, 'MA''RANG', 7309), -(7309091, 'SEGERI', 7309), -(7309092, 'MANDALLE', 7309), -(7310010, 'TANETE RIAJA', 7310), -(7310011, 'PUJANANTING', 7310), -(7310020, 'TANETE RILAU', 7310), -(7310030, 'BARRU', 7310), -(7310040, 'SOPPENG RIAJA', 7310), -(7310041, 'BALUSU', 7310), -(7310050, 'MALLUSETASI', 7310), -(7311010, 'BONTOCANI', 7311), -(7311020, 'KAHU', 7311), -(7311030, 'KAJUARA', 7311), -(7311040, 'SALOMEKKO', 7311), -(7311050, 'TONRA', 7311), -(7311060, 'PATIMPENG', 7311), -(7311070, 'LIBURENG', 7311), -(7311080, 'MARE', 7311), -(7311090, 'SIBULUE', 7311), -(7311100, 'CINA', 7311), -(7311110, 'BAREBBO', 7311), -(7311120, 'PONRE', 7311), -(7311130, 'LAPPARIAJA', 7311), -(7311140, 'LAMURU', 7311), -(7311141, 'TELLU LIMPOE', 7311), -(7311150, 'BENGO', 7311), -(7311160, 'ULAWENG', 7311), -(7311170, 'PALAKKA', 7311), -(7311180, 'AWANGPONE', 7311), -(7311190, 'TELLU SIATTINGE', 7311), -(7311200, 'AMALI', 7311), -(7311210, 'AJANGALE', 7311), -(7311220, 'DUA BOCCOE', 7311), -(7311230, 'CENRANA', 7311), -(7311710, 'TANETE RIATTANG BARAT', 7311), -(7311720, 'TANETE RIATTANG', 7311), -(7311730, 'TANETE RIATTANG TIMUR', 7311), -(7312010, 'MARIO RIWAWO', 7312), -(7312020, 'LALABATA', 7312), -(7312030, 'LILI RIAJA', 7312), -(7312031, 'GANRA', 7312), -(7312032, 'CITTA', 7312), -(7312040, 'LILI RILAU', 7312), -(7312050, 'DONRI DONRI', 7312), -(7312060, 'MARIO RIAWA', 7312), -(7313010, 'SABBANG PARU', 7313), -(7313020, 'TEMPE', 7313), -(7313030, 'PAMMANA', 7313), -(7313040, 'BOLA', 7313), -(7313050, 'TAKKALALLA', 7313), -(7313060, 'SAJOANGING', 7313), -(7313061, 'PENRANG', 7313), -(7313070, 'MAJAULENG', 7313), -(7313080, 'TANA SITOLO', 7313), -(7313090, 'BELAWA', 7313), -(7313100, 'MANIANG PAJO', 7313), -(7313101, 'GILIRENG', 7313), -(7313110, 'KEERA', 7313), -(7313120, 'PITUMPANUA', 7313), -(7314010, 'PANCA LAUTANG', 7314), -(7314020, 'TELLULIMPO E', 7314), -(7314030, 'WATANG PULU', 7314), -(7314040, 'BARANTI', 7314), -(7314050, 'PANCA RIJANG', 7314), -(7314051, 'KULO', 7314), -(7314060, 'MARITENGNGAE', 7314), -(7314061, 'WATANG SIDENRENG', 7314), -(7314070, 'PITU RIAWA', 7314), -(7314080, 'DUAPITUE', 7314), -(7314081, 'PITU RIASE', 7314), -(7315010, 'SUPPA', 7315), -(7315020, 'MATTIROSOMPE', 7315), -(7315021, 'LANRISANG', 7315), -(7315030, 'MATTIRO BULU', 7315), -(7315040, 'WATANG SAWITTO', 7315), -(7315041, 'PALETEANG', 7315), -(7315042, 'TIROANG', 7315), -(7315050, 'PATAMPANUA', 7315), -(7315060, 'CEMPA', 7315), -(7315070, 'DUAMPANUA', 7315), -(7315071, 'BATULAPPA', 7315), -(7315080, 'LEMBANG', 7315), -(7316010, 'MAIWA', 7316), -(7316011, 'BUNGIN', 7316), -(7316020, 'ENREKANG', 7316), -(7316021, 'CENDANA', 7316), -(7316030, 'BARAKA', 7316), -(7316031, 'BUNTU BATU', 7316), -(7316040, 'ANGGERAJA', 7316), -(7316041, 'MALUA', 7316), -(7316050, 'ALLA', 7316), -(7316051, 'CURIO', 7316), -(7316052, 'MASALLE', 7316), -(7316053, 'BAROKO', 7316), -(7317010, 'LAROMPONG', 7317), -(7317011, 'LAROMPONG SELATAN', 7317), -(7317020, 'SULI', 7317), -(7317021, 'SULI BARAT', 7317), -(7317030, 'BELOPA', 7317), -(7317031, 'KAMANRE', 7317), -(7317032, 'BELOPA UTARA', 7317), -(7317040, 'BAJO', 7317), -(7317041, 'BAJO BARAT', 7317), -(7317050, 'BASSESANGTEMPE', 7317), -(7317051, 'LATIMOJONG', 7317), -(7317060, 'BUPON', 7317), -(7317061, 'PONRANG', 7317), -(7317062, 'PONRANG SELATAN', 7317), -(7317070, 'BUA', 7317), -(7317080, 'WALENRANG', 7317), -(7317081, 'WALENRANG TIMUR', 7317), -(7317090, 'LAMASI', 7317), -(7317091, 'WALENRANG UTARA', 7317), -(7317092, 'WALENRANG BARAT', 7317), -(7317093, 'LAMASI TIMUR', 7317), -(7318010, 'BONGGAKARADENG', 7318), -(7318011, 'SIMBUANG', 7318), -(7318012, 'RANO', 7318), -(7318013, 'MAPPAK', 7318), -(7318020, 'MENGKENDEK', 7318), -(7318021, 'GANDANG BATU SILANAN', 7318), -(7318030, 'SANGALLA', 7318), -(7318031, 'SANGALA SELATAN', 7318), -(7318032, 'SANGALLA UTARA', 7318), -(7318040, 'MAKALE', 7318), -(7318041, 'MAKALE SELATAN', 7318), -(7318042, 'MAKALE UTARA', 7318), -(7318050, 'SALUPUTTI', 7318), -(7318051, 'BITTUANG', 7318), -(7318052, 'REMBON', 7318), -(7318053, 'MASANDA', 7318), -(7318054, 'MALIMBONG BALEPE', 7318), -(7318061, 'RANTETAYO', 7318), -(7318067, 'KURRA', 7318), -(7322010, 'SABBANG', 7322), -(7322020, 'BAEBUNTA', 7322), -(7322030, 'MALANGKE', 7322), -(7322031, 'MALANGKE BARAT', 7322), -(7322040, 'SUKAMAJU', 7322), -(7322050, 'BONE-BONE', 7322), -(7322120, 'MASAMBA', 7322), -(7322121, 'MAPPEDECENG', 7322), -(7322122, 'RAMPI', 7322), -(7322130, 'LIMBONG', 7322), -(7322131, 'SEKO', 7322), -(7325010, 'BURAU', 7325), -(7325020, 'WOTU', 7325), -(7325030, 'TOMONI', 7325), -(7325031, 'TOMONI TIMUR', 7325), -(7325040, 'ANGKONA', 7325), -(7325050, 'MALILI', 7325), -(7325060, 'TOWUTI', 7325), -(7325070, 'NUHA', 7325), -(7325071, 'WASUPONDA', 7325), -(7325080, 'MANGKUTANA', 7325), -(7325081, 'KALAENA', 7325), -(7326010, 'SOPAI', 7326), -(7326020, 'KESU', 7326), -(7326030, 'SANGGALANGI', 7326), -(7326040, 'BUNTAO', 7326), -(7326050, 'RANTEBUA', 7326), -(7326060, 'NANGGALA', 7326), -(7326070, 'TONDON', 7326), -(7326080, 'TALLUNGLIPU', 7326), -(7326090, 'RANTEPAO', 7326), -(7326100, 'TIKALA', 7326), -(7326110, 'SESEAN', 7326), -(7326120, 'BALUSU', 7326), -(7326130, 'SA''DAN', 7326), -(7326140, 'BENGKELEKILA', 7326), -(7326150, 'SESEAN SULOARA', 7326), -(7326160, 'KAPALA PITU', 7326), -(7326170, 'DENDE PIONGAN NAPO', 7326), -(7326180, 'AWAN RANTE KARUA', 7326), -(7326190, 'RINDINGALO', 7326), -(7326200, 'BUNTU PEPASAN', 7326), -(7326210, 'BARUPPU', 7326), -(7371010, 'MARISO', 7371), -(7371020, 'MAMAJANG', 7371), -(7371030, 'TAMALATE', 7371), -(7371031, 'RAPPOCINI', 7371), -(7371040, 'MAKASSAR', 7371), -(7371050, 'UJUNG PANDANG', 7371), -(7371060, 'WAJO', 7371), -(7371070, 'BONTOALA', 7371), -(7371080, 'UJUNG TANAH', 7371), -(7371090, 'TALLO', 7371), -(7371100, 'PANAKKUKANG', 7371), -(7371101, 'MANGGALA', 7371), -(7371110, 'BIRING KANAYA', 7371), -(7371111, 'TAMALANREA', 7371), -(7372010, 'BACUKIKI', 7372), -(7372011, 'BACUKIKI BARAT', 7372), -(7372020, 'UJUNG', 7372), -(7372030, 'SOREANG', 7372), -(7373010, 'WARA SELATAN', 7373), -(7373011, 'SENDANA', 7373), -(7373020, 'WARA', 7373), -(7373021, 'WARA TIMUR', 7373), -(7373022, 'MUNGKAJANG', 7373), -(7373030, 'WARA UTARA', 7373), -(7373031, 'BARA', 7373), -(7373040, 'TELLUWANUA', 7373), -(7373041, 'WARA BARAT', 7373), -(7401050, 'LASALIMU', 7401), -(7401051, 'LASALIMU SELATAN', 7401), -(7401052, 'SIONTAPINA', 7401), -(7401060, 'PASAR WAJO', 7401), -(7401061, 'WOLOWA', 7401), -(7401062, 'WABULA', 7401), -(7401070, 'SAMPOLAWA', 7401), -(7401071, 'BATU ATAS', 7401), -(7401072, 'LAPANDEWA', 7401), -(7401080, 'BATAUGA', 7401), -(7401081, 'SIOMPU', 7401), -(7401082, 'KADATUA', 7401), -(7401083, 'SIOMPU BARAT', 7401), -(7401110, 'KAPONTORI', 7401), -(7401120, 'GU', 7401), -(7401121, 'SANGIA WAMBULU', 7401), -(7401130, 'LAKUDO', 7401), -(7401140, 'MAWASANGKA', 7401), -(7401141, 'MAWASANGKA TIMUR', 7401), -(7401142, 'MAWASANGKA TENGAH', 7401), -(7401151, 'TALAGA RAYA', 7401), -(7402010, 'TONGKUNO', 7402), -(7402011, 'TONGKUNO SELATAN', 7402), -(7402020, 'PARIGI', 7402), -(7402021, 'BONE', 7402), -(7402022, 'MAROBO', 7402), -(7402030, 'KABAWO', 7402), -(7402031, 'KABANGKA', 7402), -(7402032, 'KONTUKOWUNA', 7402), -(7402040, 'TIWORO KEPULAUAN', 7402), -(7402041, 'MAGINTI', 7402), -(7402042, 'TIWORO TENGAH', 7402), -(7402043, 'TIWORO SELATAN', 7402), -(7402044, 'TIWORO UTARA', 7402), -(7402050, 'LAWA', 7402), -(7402051, 'SAWERIGADI', 7402), -(7402052, 'BARANGKA', 7402), -(7402053, 'WA DAGA', 7402), -(7402060, 'KUSAMBI', 7402), -(7402061, 'KONTUNAGA', 7402), -(7402062, 'WATOPUTE', 7402), -(7402070, 'KATOBU', 7402), -(7402071, 'LOHIA', 7402), -(7402072, 'DURUKA', 7402), -(7402073, 'BATALAIWORU', 7402), -(7402080, 'NAPABALANO', 7402), -(7402081, 'LASALEPA', 7402), -(7402082, 'NAPANO KUSAMBI', 7402), -(7402083, 'TOWEA', 7402), -(7402090, 'WAKORUMBA SELATAN', 7402), -(7402091, 'PASIR PUTIH', 7402), -(7402092, 'PASI KOLAGA', 7402), -(7402111, 'MALIGANO', 7402), -(7402112, 'BATUKARA', 7402), -(7403071, 'WAWONII SELATAN', 7403), -(7403072, 'WAWONII BARAT', 7403), -(7403073, 'WAWONII TENGAH', 7403), -(7403074, 'WAWONII TENGGARA', 7403), -(7403081, 'WAWONII TIMUR', 7403), -(7403082, 'WAWONII UTARA', 7403), -(7403083, 'WAWONII TIMUR LAUT', 7403), -(7403090, 'SOROPIA', 7403), -(7403091, 'LALONGGASUMEETO', 7403), -(7403100, 'SAMPARA', 7403), -(7403101, 'BONDOALA', 7403), -(7403102, 'BESULUTU', 7403), -(7403103, 'KAPOIALA', 7403), -(7403130, 'LAMBUYA', 7403), -(7403131, 'UEPAI', 7403), -(7403132, 'PURIALA', 7403), -(7403133, 'ONEMBUTE', 7403), -(7403140, 'PONDIDAHA', 7403), -(7403141, 'WONGGEDUKU', 7403), -(7403142, 'AMONGGEDO', 7403), -(7403150, 'WAWOTOBI', 7403), -(7403151, 'MELUHU', 7403), -(7403152, 'KONAWE', 7403), -(7403170, 'UNAAHA', 7403), -(7403171, 'ANGGABERI', 7403), -(7403180, 'ABUKI', 7403), -(7403181, 'LATOMA', 7403), -(7403182, 'TONGAUNA', 7403), -(7403183, 'ASINUA', 7403), -(7403193, 'ROUTA', 7403), -(7404010, 'WATUBANGGA', 7404), -(7404011, 'TANGGETADA', 7404), -(7404012, 'TOARI', 7404), -(7404013, 'POLINGGONA', 7404), -(7404020, 'POMALAA', 7404), -(7404030, 'WUNDULAKO', 7404), -(7404031, 'BAULA', 7404), -(7404040, 'LADONGI', 7404), -(7404041, 'LAMBADIA', 7404), -(7404042, 'POLI-POLIA', 7404), -(7404050, 'TIRAWUTA', 7404), -(7404051, 'LALOLAE', 7404), -(7404052, 'LOEA', 7404), -(7404060, 'KOLAKA', 7404), -(7404061, 'LATAMBAGA', 7404), -(7404070, 'WOLO', 7404), -(7404071, 'SAMATURU', 7404), -(7404080, 'MOWEWE', 7404), -(7404081, 'ULUIWOI', 7404), -(7404082, 'TINONDO', 7404), -(7405010, 'TINANGGEA', 7405), -(7405011, 'LALEMBUU', 7405), -(7405020, 'ANDOOLO', 7405), -(7405021, 'BUKE', 7405), -(7405030, 'PALANGGA', 7405), -(7405031, 'PALANGGA SELATAN', 7405), -(7405032, 'BAITO', 7405), -(7405040, 'LAINEA', 7405), -(7405041, 'LAEYA', 7405), -(7405050, 'KOLONO', 7405), -(7405060, 'LAONTI', 7405), -(7405070, 'MORAMO', 7405), -(7405071, 'MORAMO UTARA', 7405), -(7405080, 'KONDA', 7405), -(7405081, 'WOLASI', 7405), -(7405090, 'RANOMEETO', 7405), -(7405091, 'RANOMEETO BARAT', 7405), -(7405100, 'LANDONO', 7405), -(7405101, 'MOWILA', 7405), -(7405110, 'ANGATA', 7405), -(7405111, 'BENUA', 7405), -(7405112, 'BASALA', 7405), -(7406010, 'KABAENA', 7406), -(7406011, 'KABAENA UTARA', 7406), -(7406012, 'KABAENA SELATAN', 7406), -(7406013, 'KABAENA BARAT', 7406), -(7406020, 'KABAENA TIMUR', 7406), -(7406021, 'KABAENA TENGAH', 7406), -(7406030, 'RUMBIA', 7406), -(7406031, 'MATA OLEO', 7406), -(7406032, 'KEP. MASALOKA RAYA', 7406), -(7406033, 'RUMBIA TENGAH', 7406), -(7406040, 'RAROWATU', 7406), -(7406041, 'RAROWATU UTARA', 7406), -(7406042, 'MATA USU', 7406), -(7406043, 'LANTARI JAYA', 7406), -(7406050, 'POLEANG TIMUR', 7406), -(7406051, 'POLEANG UTARA', 7406), -(7406052, 'POLEANG SELATAN', 7406), -(7406053, 'POLEANG TENGGARA', 7406), -(7406060, 'POLEANG', 7406), -(7406061, 'POLEANG BARAT', 7406), -(7406062, 'TONTONUNU', 7406), -(7406063, 'POLEANG TENGAH', 7406), -(7407010, 'BINONGKO', 7407), -(7407011, 'TOGO BINONGKO', 7407), -(7407020, 'TOMIA', 7407), -(7407021, 'TOMIA TIMUR', 7407), -(7407030, 'KALEDUPA', 7407), -(7407031, 'KALEDUPA SELATAN', 7407), -(7407040, 'WANGI-WANGI', 7407), -(7407050, 'WANGI-WANGI SELATAN', 7407), -(7408010, 'RANTEANGIN', 7408), -(7408011, 'LAMBAI', 7408), -(7408012, 'WAWO', 7408), -(7408020, 'LASUSUA', 7408), -(7408021, 'KATOI', 7408), -(7408030, 'KODEOHA', 7408), -(7408031, 'TIWU', 7408), -(7408040, 'NGAPA', 7408), -(7408041, 'WATUNOHU', 7408), -(7408050, 'PAKUE', 7408), -(7408051, 'PAKUE UTARA', 7408), -(7408052, 'PAKUE TENGAH', 7408), -(7408060, 'BATU PUTIH', 7408), -(7408061, 'POREHU', 7408), -(7408062, 'TOLALA', 7408), -(7409100, 'BONEGUNU', 7409), -(7409101, 'KAMBOWA', 7409), -(7409110, 'WAKORUMBA', 7409), -(7409120, 'KULISUSU', 7409), -(7409121, 'KULISUSU BARAT', 7409), -(7409122, 'KULISUSU UTARA', 7409), -(7410010, 'SAWA', 7410), -(7410011, 'MOTUI', 7410), -(7410020, 'LEMBO', 7410), -(7410030, 'LASOLO', 7410), -(7410040, 'MOLAWE', 7410), -(7410050, 'ASERA', 7410), -(7410051, 'ANDOWIA', 7410), -(7410052, 'OHEO', 7410), -(7410060, 'LANGGIKIMA', 7410), -(7410070, 'WIWIRANO', 7410), -(7471010, 'MANDONGA', 7471), -(7471011, 'BARUGA', 7471), -(7471012, 'PUUWATU', 7471), -(7471013, 'KADIA', 7471), -(7471014, 'WUA-WUA', 7471), -(7471020, 'POASIA', 7471), -(7471021, 'ABELI', 7471), -(7471022, 'KAMBU', 7471), -(7471030, 'KENDARI', 7471), -(7471031, 'KENDARI BARAT', 7471), -(7472010, 'BETOAMBARI', 7472), -(7472011, 'MURHUM', 7472), -(7472020, 'WOLIO', 7472), -(7472021, 'KOKALUKUNA', 7472), -(7472030, 'SORAWOLIO', 7472), -(7472040, 'BUNGI', 7472), -(7472041, 'LEA-LEA', 7472), -(7501031, 'MANANGGU', 7501), -(7501040, 'TILAMUTA', 7501), -(7501041, 'DULUPI', 7501), -(7501042, 'BOTUMOITO', 7501), -(7501050, 'PAGUYAMAN', 7501), -(7501051, 'WONOSARI', 7501), -(7501052, 'PAGUYAMAN PANTAI', 7501), -(7502010, 'BATUDAA PANTAI', 7502), -(7502011, 'BILUHU', 7502), -(7502020, 'BATUDAA', 7502), -(7502021, 'BONGOMEME', 7502), -(7502022, 'TABONGO', 7502), -(7502030, 'TIBAWA', 7502), -(7502031, 'PULUBALA', 7502), -(7502040, 'BOLIYOHUTO', 7502), -(7502041, 'MOOTILANGO', 7502), -(7502042, 'TOLANGOHULA', 7502), -(7502043, 'ASPARAGA', 7502), -(7502044, 'BILATO', 7502), -(7502070, 'LIMBOTO', 7502), -(7502071, 'LIMBOTO BARAT', 7502), -(7502080, 'TELAGA', 7502), -(7502081, 'TELAGA BIRU', 7502), -(7502082, 'TILANGO', 7502), -(7502083, 'TELAGA JAYA', 7502), -(7503010, 'POPAYATO', 7503), -(7503011, 'POPAYATO BARAT', 7503), -(7503012, 'POPAYATO TIMUR', 7503), -(7503020, 'LEMITO', 7503), -(7503021, 'WANGGARASI', 7503), -(7503030, 'MARISA', 7503), -(7503031, 'PATILANGGIO', 7503), -(7503032, 'BUNTULIA', 7503), -(7503033, 'DUHIADAA', 7503), -(7503040, 'RANDANGAN', 7503), -(7503041, 'TALUDITI', 7503), -(7503050, 'PAGUAT', 7503), -(7503051, 'DENGILO', 7503), -(7504010, 'TAPA', 7504), -(7504011, 'BULANGO UTARA', 7504), -(7504012, 'BULANGO SELATAN', 7504), -(7504013, 'BULANGO TIMUR', 7504), -(7504014, 'BULANGO ULU', 7504), -(7504020, 'KABILA', 7504), -(7504021, 'BOTU PINGGE', 7504), -(7504022, 'TILONGKABILA', 7504), -(7504030, 'SUWAWA', 7504), -(7504031, 'SUWAWA SELATAN', 7504), -(7504032, 'SUWAWA TIMUR', 7504), -(7504033, 'SUWAWA TENGAH', 7504), -(7504040, 'BONEPANTAI', 7504), -(7504041, 'KABILA BONE', 7504), -(7504042, 'BONE RAYA', 7504), -(7504043, 'BONE', 7504), -(7504044, 'BULAWA', 7504), -(7505010, 'ATINGGOLA', 7505), -(7505011, 'GENTUMA RAYA', 7505), -(7505020, 'KWANDANG', 7505), -(7505030, 'ANGGREK', 7505), -(7505040, 'SUMALATA', 7505), -(7505050, 'TOLINGGULA', 7505), -(7571010, 'KOTA BARAT', 7571), -(7571011, 'DUNGINGI', 7571), -(7571020, 'KOTA SELATAN', 7571), -(7571021, 'KOTA TIMUR', 7571), -(7571022, 'HULONTHALANGI', 7571), -(7571023, 'DUMBO RAYA', 7571), -(7571030, 'KOTA UTARA', 7571), -(7571031, 'KOTA TENGAH', 7571), -(7571032, 'SIPATANA', 7571), -(7601010, 'BANGGAE', 7601), -(7601011, 'BANGGAE TIMUR', 7601), -(7601020, 'PAMBOANG', 7601), -(7601030, 'SENDANA', 7601), -(7601031, 'TAMMERODO', 7601), -(7601033, 'TUBO SENDANA', 7601), -(7601040, 'MALUNDA', 7601), -(7601041, 'ULUMANDA', 7601), -(7602010, 'TINAMBUNG', 7602), -(7602011, 'BALANIPA', 7602), -(7602012, 'LIMBORO', 7602), -(7602020, 'TUBBI TARAMANU', 7602), -(7602021, 'ALU', 7602), -(7602030, 'CAMPALAGIAN', 7602), -(7602031, 'LUYO', 7602), -(7602040, 'WONOMULYO', 7602), -(7602041, 'MAPILLI', 7602), -(7602042, 'TAPANGO', 7602), -(7602043, 'MATAKALI', 7602), -(7602044, 'B U L O', 7602), -(7602050, 'POLEWALI', 7602), -(7602051, 'BINUANG', 7602), -(7602052, 'ANREAPI', 7602), -(7602061, 'MATANGNGA', 7602), -(7603010, 'SUMARORONG', 7603), -(7603020, 'MESSAWA', 7603), -(7603030, 'PANA', 7603), -(7603031, 'NOSU', 7603), -(7603040, 'TABANG', 7603), -(7603050, 'MAMASA', 7603), -(7603060, 'TANDUK KALUA', 7603), -(7603061, 'BALLA', 7603), -(7603070, 'SESENAPADANG', 7603), -(7603071, 'TAWALIAN', 7603), -(7603080, 'MAMBI', 7603), -(7603081, 'BAMBANG', 7603), -(7603082, 'RANTEBULAHAN TIMUR', 7603), -(7603083, 'MEHALAAN', 7603), -(7603090, 'ARALLE', 7603), -(7603091, 'BUNTU MALANGKA', 7603), -(7603100, 'TABULAHAN', 7603), -(7604010, 'TAPALANG', 7604), -(7604011, 'TAPALANG BARAT', 7604), -(7604020, 'MAMUJU', 7604), -(7604022, 'SIMBORO', 7604), -(7604023, 'BALABALAKANG', 7604), -(7604030, 'KALUKKU', 7604), -(7604031, 'PAPALANG', 7604), -(7604032, 'SAMPAGA', 7604), -(7604033, 'TOMMO', 7604), -(7604040, 'KALUMPANG', 7604), -(7604041, 'BONEHAU', 7604), -(7604050, 'BUDONG-BUDONG', 7604), -(7604051, 'PANGALE', 7604), -(7604052, 'TOPOYO', 7604), -(7604053, 'KAROSSA', 7604), -(7604054, 'TOBADAK', 7604), -(7605010, 'SARUDU', 7605), -(7605011, 'DAPURANG', 7605), -(7605012, 'DURIPOKU', 7605), -(7605020, 'BARAS', 7605), -(7605021, 'BULU TABA', 7605), -(7605022, 'LARIANG', 7605), -(7605030, 'PASANGKAYU', 7605), -(7605031, 'TIKKE RAYA', 7605), -(7605032, 'PEDONGGA', 7605), -(7605040, 'BAMBALAMOTU', 7605), -(7605041, 'BAMBAIRA', 7605), -(7605042, 'SARJO', 7605), -(8101040, 'TANIMBAR SELATAN', 8101), -(8101041, 'WER TAMRIAN', 8101), -(8101042, 'WER MAKTIAN', 8101), -(8101043, 'SELARU', 8101), -(8101050, 'TANIMBAR UTARA', 8101), -(8101051, 'YARU', 8101), -(8101052, 'WUAR LABOBAR', 8101), -(8101053, 'NIRUNMAS', 8101), -(8101054, 'KORMOMOLIN', 8101), -(8101055, 'MOLU MARU', 8101), -(8102010, 'KEI KECIL', 8102), -(8102012, 'KEI KECIL BARAT', 8102), -(8102013, 'KEI KECIL TIMUR', 8102), -(8102020, 'KEI BESAR', 8102), -(8102021, 'KEI BESAR UTARA TIMUR', 8102), -(8102022, 'KEI BESAR SELATAN', 8102), -(8103010, 'BANDA', 8103), -(8103040, 'TEHORU', 8103), -(8103041, 'TELUTIH', 8103), -(8103050, 'AMAHAI', 8103), -(8103051, 'KOTA MASOHI', 8103), -(8103052, 'TELUK ELPAPUTIH', 8103), -(8103060, 'TEON NILA SERUA', 8103), -(8103080, 'SAPARUA', 8103), -(8103081, 'NUSALAUT', 8103), -(8103090, 'P. HARUKU', 8103), -(8103100, 'SALAHUTU', 8103), -(8103110, 'LEIHITU', 8103), -(8103111, 'LEIHITU BARAT', 8103), -(8103140, 'SERAM UTARA', 8103), -(8103141, 'SERAM UTARA BARAT', 8103), -(8103142, 'SERAM UTARA TIMUR KOBI', 8103), -(8103143, 'SERAM UTARA TIMUR SETI', 8103), -(8104020, 'NAMLEA', 8104), -(8104021, 'WAEAPO', 8104), -(8104022, 'WAPLAU', 8104), -(8104023, 'BATA BUAL', 8104), -(8104030, 'AIR BUAYA', 8104), -(8105010, 'ARU SELATAN', 8105), -(8105011, 'ARU SELATAN TIMUR', 8105), -(8105020, 'ARU TENGAH', 8105), -(8105021, 'ARU TENGAH TIMUR', 8105), -(8105022, 'ARU TENGAH SELATAN', 8105), -(8105030, 'PULAU-PULAU ARU', 8105), -(8105031, 'ARU UTARA', 8105), -(8106010, 'HUAMUAL BELAKANG', 8106), -(8106011, 'KEPULAUAN MANIPA', 8106), -(8106020, 'SERAM BARAT', 8106), -(8106021, 'HUAMUAL', 8106), -(8106030, 'KAIRATU', 8106), -(8106031, 'KAIRATU BARAT', 8106), -(8106032, 'INAMOSOL', 8106), -(8106033, 'AMALATU', 8106), -(8106034, 'ELPAPUTIH', 8106), -(8106040, 'TANIWEL', 8106), -(8106041, 'TANIWEL TIMUR', 8106), -(8107010, 'PULAU GOROM', 8107), -(8107011, 'WAKATE', 8107), -(8107020, 'SERAM TIMUR', 8107), -(8107021, 'TUTUK TOLU', 8107), -(8107022, 'KILMURY', 8107), -(8107030, 'WERINAMA', 8107), -(8107031, 'SIWALALAT', 8107), -(8107040, 'BULA', 8107), -(8108010, 'PP. WETAR', 8108), -(8108020, 'PP. TERSELATAN', 8108), -(8108030, 'LETI MOA LAKOR', 8108), -(8108040, 'MOA LAKOR', 8108), -(8108050, 'DAMER', 8108), -(8108060, 'MDONA HIERA', 8108), -(8108070, 'PP. BABAR', 8108), -(8108080, 'BABAR TIMUR', 8108), -(8109010, 'KEPALA MADAN', 8109), -(8109020, 'LEKSULA', 8109), -(8109030, 'NAMROLE', 8109), -(8109040, 'WAISAMA', 8109), -(8109050, 'AMBALAU', 8109), -(8171010, 'NUSANIWE', 8171), -(8171020, 'SIRIMAU', 8171), -(8171021, 'LEITIMUR SELATAN', 8171), -(8171030, 'TELUK AMBON BAGUALA', 8171), -(8171031, 'TELUK AMBON', 8171), -(8172010, 'PP. KUR', 8172), -(8172020, 'TAYANDO TAM', 8172), -(8172030, 'PULAU DULLAH UTARA', 8172), -(8172040, 'PULAU DULLAH SELATAN', 8172), -(8201090, 'JAILOLO', 8201), -(8201091, 'JAILOLO SELATAN', 8201), -(8201092, 'JAILOLO TIMUR', 8201), -(8201100, 'SAHU', 8201), -(8201101, 'SAHU TIMUR', 8201), -(8201130, 'IBU', 8201), -(8201131, 'IBU SELATAN', 8201), -(8201132, 'IBU UTARA', 8201), -(8201140, 'LOLODA', 8201), -(8202030, 'WEDA', 8202), -(8202031, 'WEDA SELATAN', 8202), -(8202032, 'WEDA UTARA', 8202), -(8202033, 'WEDA TENGAH', 8202), -(8202041, 'PULAU GEBE', 8202), -(8202042, 'PATANI', 8202), -(8202043, 'PATANI UTARA', 8202), -(8202044, 'PATANI BARAT', 8202), -(8203010, 'SULA BESI BARAT', 8203), -(8203011, 'SULABESI SELATAN', 8203), -(8203020, 'SANANA', 8203), -(8203021, 'SULA BESI TENGAH', 8203), -(8203022, 'SULABESI TIMUR', 8203), -(8203023, 'SANANA UTARA', 8203), -(8203030, 'MANGOLI TIMUR', 8203), -(8203031, 'MANGOLI TENGAH', 8203), -(8203032, 'MANGOLI UTARA TIMUR', 8203), -(8203040, 'MANGOLI BARAT', 8203), -(8203041, 'MANGOLI UTARA', 8203), -(8203042, 'MANGOLI SELATAN', 8203), -(8203050, 'TALIABU TIMUR', 8203), -(8203051, 'TALIABU TIMUR SELATAN', 8203), -(8203060, 'TALIABU BARAT', 8203), -(8203061, 'TALIABU UTARA', 8203), -(8203062, 'TALIABU BARAT LAUT', 8203), -(8203063, 'LEDE', 8203), -(8203064, 'TALIABU SELATAN', 8203), -(8204010, 'OBI SELATAN', 8204), -(8204020, 'OBI', 8204), -(8204021, 'OBI BARAT', 8204), -(8204022, 'OBI TIMUR', 8204), -(8204023, 'OBI UTARA', 8204), -(8204030, 'BACAN', 8204), -(8204031, 'MANDIOLI SELATAN', 8204), -(8204032, 'MANDIOLI UTARA', 8204), -(8204033, 'BACAN SELATAN', 8204), -(8204034, 'BATANG LOMANG', 8204), -(8204040, 'BACAN TIMUR', 8204), -(8204041, 'BACAN TIMUR SELATAN', 8204), -(8204042, 'BACAN TIMUR TENGAH', 8204), -(8204050, 'BACAN BARAT', 8204), -(8204051, 'KASIRUTA BARAT', 8204), -(8204052, 'KASIRUTA TIMUR', 8204), -(8204053, 'BACAN BARAT UTARA', 8204), -(8204060, 'KAYOA', 8204), -(8204061, 'KAYOA BARAT', 8204), -(8204062, 'KAYOA SELATAN', 8204), -(8204063, 'KAYOA UTARA', 8204), -(8204070, 'PULAU MAKIAN', 8204), -(8204071, 'MAKIAN BARAT', 8204), -(8204080, 'GANE BARAT', 8204), -(8204081, 'GANE BARAT SELATAN', 8204), -(8204082, 'GANE BARAT UTARA', 8204), -(8204083, 'KEPULAUAN JORONGA', 8204), -(8204090, 'GANE TIMUR', 8204), -(8204091, 'GANE TIMUR TENGAH', 8204), -(8204092, 'GANE TIMUR SELATAN', 8204), -(8205010, 'MALIFUT', 8205), -(8205011, 'KAO TELUK', 8205), -(8205020, 'KAO', 8205), -(8205021, 'KAO BARAT', 8205), -(8205022, 'KAO UTARA', 8205), -(8205030, 'TOBELO SELATAN', 8205), -(8205031, 'TOBELO BARAT', 8205), -(8205032, 'TOBELO TIMUR', 8205), -(8205040, 'TOBELO', 8205), -(8205041, 'TOBELO TENGAH', 8205), -(8205042, 'TOBELO UTARA', 8205), -(8205050, 'GALELA', 8205), -(8205051, 'GALELA SELATAN', 8205), -(8205052, 'GALELA BARAT', 8205), -(8205053, 'GALELA UTARA', 8205), -(8205060, 'LOLODA UTARA', 8205), -(8205061, 'LOLODA KEPULAUAN', 8205), -(8206010, 'MABA SELATAN', 8206), -(8206011, 'KOTA MABA', 8206), -(8206020, 'WASILE SELATAN', 8206), -(8206030, 'WASILE', 8206), -(8206031, 'WASILE TIMUR', 8206), -(8206032, 'WASILE TENGAH', 8206), -(8206033, 'WASILE UTARA', 8206), -(8206040, 'MABA', 8206), -(8206041, 'MABA TENGAH', 8206), -(8206042, 'MABA UTARA', 8206), -(8207010, 'MOROTAI SELATAN', 8207), -(8207020, 'MOROTAI TIMUR', 8207), -(8207030, 'MOROTAI SELATAN BARAT', 8207), -(8207040, 'MOROTAI JAYA', 8207), -(8207050, 'MOROTAI UTARA', 8207), -(8271010, 'PULAU TERNATE', 8271), -(8271011, 'MOTI', 8271), -(8271012, 'PULAU BATANG DUA', 8271), -(8271013, 'PULAU HIRI', 8271), -(8271020, 'TERNATE SELATAN', 8271), -(8271021, 'TERNATE TENGAH', 8271), -(8271030, 'TERNATE UTARA', 8271), -(8272010, 'TIDORE SELATAN', 8272), -(8272020, 'TIDORE UTARA', 8272), -(8272030, 'TIDORE', 8272), -(8272031, 'TIDORE TIMUR', 8272), -(8272040, 'OBA', 8272), -(8272041, 'OBA SELATAN', 8272), -(8272050, 'OBA UTARA', 8272), -(8272051, 'OBA TENGAH', 8272), -(9101050, 'FAKFAK TIMUR', 9101), -(9101051, 'KARAS', 9101), -(9101060, 'FAKFAK', 9101), -(9101061, 'FAKFAK TENGAH', 9101), -(9101070, 'FAKFAK BARAT', 9101), -(9101080, 'KOKAS', 9101), -(9101081, 'TELUK PATIPI', 9101), -(9101082, 'KRAMONGMONGGA', 9101), -(9101083, 'BOMBERAY', 9101), -(9102010, 'BURUWAY', 9102), -(9102020, 'TELUK ARGUNI', 9102), -(9102021, 'TELUK ARGUNI BAWAH', 9102), -(9102030, 'KAIMANA', 9102), -(9102031, 'KAMBRAU', 9102), -(9102040, 'TELUK ETNA', 9102), -(9102041, 'YAMOR', 9102), -(9103010, 'NAIKERE', 9103), -(9103020, 'WONDIBOY', 9103), -(9103021, 'RASIEY', 9103), -(9103022, 'KURI WAMESA', 9103), -(9103030, 'WASIOR', 9103), -(9103040, 'DUAIRI', 9103), -(9103041, 'ROON', 9103), -(9103050, 'WINDESI', 9103), -(9103051, 'NIKIWAR', 9103), -(9103060, 'WAMESA', 9103), -(9103061, 'ROSWAR', 9103), -(9103070, 'RUMBERPON', 9103), -(9103071, 'SOUG JAYA', 9103), -(9104010, 'IRORUTU / FAFURWAR', 9104), -(9104020, 'BABO', 9104), -(9104021, 'SUMURI', 9104), -(9104022, 'AROBA', 9104), -(9104023, 'KAITARO', 9104), -(9104030, 'KURI', 9104), -(9104040, 'WAMESA', 9104), -(9104050, 'BINTUNI', 9104), -(9104051, 'MANIMERI', 9104), -(9104052, 'TUHIBA', 9104), -(9104053, 'DATARAN BEIMES', 9104), -(9104060, 'TEMBUNI', 9104), -(9104070, 'ARANDAY', 9104), -(9104071, 'KOMUNDAN', 9104), -(9104072, 'TOMU', 9104), -(9104073, 'WERIAGAR', 9104), -(9104080, 'MOSKONA SELATAN', 9104), -(9104081, 'MEYADO', 9104), -(9104082, 'MOSKONA BARAT', 9104), -(9104090, 'MERDEY', 9104), -(9104091, 'BISCOOP', 9104), -(9104092, 'MASYETA', 9104), -(9104100, 'MOSKONA UTARA', 9104), -(9104101, 'MOSKONA TIMUR', 9104), -(9105040, 'RANSIKI', 9105), -(9105041, 'MOMI WAREN', 9105), -(9105042, 'NENEI', 9105), -(9105080, 'SURUREY', 9105), -(9105090, 'ANGGI', 9105), -(9105091, 'TAIGE', 9105), -(9105092, 'MEMBEY', 9105), -(9105100, 'ORANSBARI', 9105), -(9105110, 'WARMARE', 9105), -(9105120, 'PRAFI', 9105), -(9105130, 'MENYAMBOUW', 9105), -(9105131, 'CATUBOUW', 9105), -(9105141, 'MANOKWARI BARAT', 9105), -(9105142, 'MANOKWARI TIMUR', 9105), -(9105143, 'MANOKWARI UTARA', 9105), -(9105144, 'MANOKWARI SELATAN', 9105), -(9105145, 'TESTEGA', 9105), -(9105146, 'TANAH RUBU', 9105), -(9105150, 'KEBAR', 9105), -(9105151, 'SENOPI', 9105), -(9105160, 'AMBERBAKEN', 9105), -(9105161, 'MUBARNI / ARFU', 9105), -(9105170, 'MASNI', 9105), -(9105171, 'SIDEY', 9105), -(9105180, 'TAHOSTA', 9105), -(9105190, 'DIDOHU', 9105), -(9105200, 'DATARAN ISIM', 9105), -(9105210, 'ANGGI GIDA', 9105), -(9105220, 'HINGK', 9105), -(9106010, 'INANWATAN', 9106), -(9106011, 'METEMANI', 9106), -(9106020, 'KOKODA', 9106), -(9106021, 'KAIS', 9106), -(9106022, 'KOKODA UTARA', 9106), -(9106060, 'MOSWAREN', 9106), -(9106070, 'TEMINABUAN', 9106), -(9106071, 'SEREMUK', 9106), -(9106072, 'WAYER', 9106), -(9106073, 'KONDA', 9106), -(9106074, 'SAIFI', 9106), -(9106080, 'SAWIAT', 9106), -(9106081, 'FOKOUR', 9106), -(9107060, 'MORAID', 9107), -(9107061, 'KLASO', 9107), -(9107100, 'MAKBON', 9107), -(9107101, 'KLAYILI', 9107), -(9107110, 'BERAUR', 9107), -(9107111, 'KLAMONO', 9107), -(9107112, 'KLABOT', 9107), -(9107113, 'KLAWAK', 9107), -(9107120, 'SALAWATI', 9107), -(9107121, 'MAYAMUK', 9107), -(9107122, 'SALAWATI TIMUR', 9107), -(9107130, 'SEGET', 9107), -(9107131, 'SEGUN', 9107), -(9107132, 'SALAWATI SELATAN', 9107), -(9107170, 'AIMAS', 9107), -(9107171, 'MARIAT', 9107), -(9107172, 'SORONG', 9107), -(9107180, 'SAYOSA', 9107), -(9107181, 'MAUDUS', 9107), -(9108011, 'MISOOL SELATAN', 9108), -(9108012, 'MISOOL BARAT', 9108), -(9108020, 'MISOOL', 9108), -(9108021, 'KOFIAU', 9108), -(9108022, 'MISOOL TIMUR', 9108), -(9108023, 'KEPULAUAN SEMBILAN', 9108), -(9108031, 'SALAWATI UTARA', 9108), -(9108033, 'SALAWATI TENGAH', 9108), -(9108034, 'SALAWATI BARAT', 9108), -(9108035, 'BATANTA SELATAN', 9108), -(9108036, 'BATANTA UTARA', 9108), -(9108040, 'WAIGEO SELATAN', 9108), -(9108041, 'TELUK MAYALIBIT', 9108), -(9108042, 'MEOS MANSAR', 9108), -(9108043, 'KOTA WAISAI', 9108), -(9108044, 'TIPLOL MAYALIBIT', 9108), -(9108050, 'WAIGEO BARAT', 9108), -(9108051, 'WAIGEO BARAT KEPULAUAN', 9108), -(9108060, 'WAIGEO UTARA', 9108), -(9108061, 'WARWARBOMI', 9108), -(9108062, 'SUPNIN', 9108), -(9108070, 'KEPULAUAN AYAU', 9108), -(9108071, 'AYAU', 9108), -(9108080, 'WAIGEO TIMUR', 9108), -(9109010, 'FEF', 9109), -(9109011, 'SYUJAK', 9109), -(9109020, 'MIYAH', 9109), -(9109030, 'ABUN', 9109), -(9109040, 'KWOOR', 9109), -(9109050, 'SAUSAPOR', 9109), -(9109060, 'YEMBUN', 9109), -(9110010, 'AITINYO BARAT/ATHABU', 9110), -(9110011, 'AYAMARU SELATAN JAYA', 9110), -(9110020, 'AITINYO', 9110), -(9110021, 'AITINYO TENGAH', 9110), -(9110030, 'AIFAT SELATAN', 9110), -(9110031, 'AIFAT TIMUR SELATAN', 9110), -(9110040, 'AIFAT', 9110), -(9110050, 'AITINYO UTARA', 9110), -(9110051, 'AITINYO RAYA', 9110), -(9110060, 'AYAMARU TIMUR', 9110), -(9110061, 'AYAMARU TIMUR SELATAN', 9110), -(9110070, 'AYAMARU', 9110), -(9110071, 'AYAMARU SELATAN', 9110), -(9110072, 'AYAMARU JAYA', 9110), -(9110073, 'AYAMARU TENGAH', 9110), -(9110074, 'AYAMARU BARAT', 9110), -(9110080, 'AYAMARU UTARA', 9110), -(9110081, 'AYAMARU UTARA TIMUR', 9110), -(9110090, 'MARE', 9110), -(9110091, 'MARE SELATAN', 9110), -(9110100, 'AIFAT UTARA', 9110), -(9110110, 'AIFAT TIMUR', 9110), -(9110111, 'AFIAT TIMUR TENGAH', 9110), -(9110112, 'AIFAT TIMUR JAUH', 9110), -(9171010, 'SORONG BARAT', 9171), -(9171011, 'SORONG KEPULAUAN', 9171), -(9171020, 'SORONG TIMUR', 9171), -(9171021, 'SORONG UTARA', 9171), -(9171022, 'SORONG', 9171), -(9171023, 'SORONG MANOI', 9171), -(9401010, 'KIMAAM', 9401), -(9401011, 'WAAN', 9401), -(9401012, 'TABONJI', 9401), -(9401013, 'ILWAYAB', 9401), -(9401020, 'OKABA', 9401), -(9401021, 'TUBANG', 9401), -(9401022, 'NGGUTI', 9401), -(9401023, 'KAPTEL', 9401), -(9401030, 'KURIK', 9401), -(9401031, 'MALIND', 9401), -(9401032, 'ANIMHA', 9401), -(9401040, 'MERAUKE', 9401), -(9401041, 'SEMANGGA', 9401), -(9401042, 'TANAH MIRING', 9401), -(9401043, 'JAGEBOB', 9401), -(9401044, 'SOTA', 9401), -(9401045, 'NAUKENJERAI', 9401), -(9401050, 'MUTING', 9401), -(9401051, 'ELIGOBEL', 9401), -(9401052, 'ULILIN', 9401), -(9402110, 'WAMENA', 9402), -(9402111, 'ASOLOKOBAL', 9402), -(9402112, 'WALELAGAMA', 9402), -(9402120, 'HUBIKOSI', 9402), -(9402121, 'PELEBAGA', 9402), -(9402180, 'ASOLOGAIMA', 9402), -(9402181, 'MUSATFAK', 9402), -(9402190, 'KURULU', 9402), -(9402220, 'BOLAKME', 9402), -(9402221, 'WOLLO', 9402), -(9402222, 'YALENGGA', 9402), -(9402223, 'TRIKORA', 9402), -(9402224, 'NAPUA', 9402), -(9402225, 'WALAIK', 9402), -(9402226, 'WOUMA', 9402), -(9402227, 'HUBIKIAK', 9402), -(9402228, 'IBELE', 9402), -(9402229, 'TAILAREK', 9402), -(9402230, 'ITLAY HISAGE', 9402), -(9402231, 'SIEPKOSI', 9402), -(9402232, 'USILIMO', 9402), -(9402233, 'WITA WAYA', 9402), -(9402234, 'LIBAREK', 9402), -(9402235, 'WADANGKU', 9402), -(9402236, 'KORAGI', 9402), -(9402237, 'TAGIME', 9402), -(9402238, 'MOLAGALOME', 9402), -(9402239, 'TAGINERI', 9402), -(9402240, 'SILO KARNO DOGA', 9402), -(9402241, 'PYRAMID', 9402), -(9402242, 'MULIAMA', 9402), -(9402243, 'BUGI', 9402), -(9402244, 'BPIRI', 9402), -(9402245, 'WALESI', 9402), -(9402246, 'ASOTIPO', 9402), -(9402247, 'MAIMA', 9402), -(9402248, 'PISUGI', 9402), -(9403080, 'KAUREH', 9403), -(9403081, 'AIRU', 9403), -(9403082, 'YAPSI', 9403), -(9403140, 'KEMTUK', 9403), -(9403150, 'KEMTUK GRESI', 9403), -(9403151, 'GRESI SELATAN', 9403), -(9403160, 'NIMBORAN', 9403), -(9403161, 'NIMBORAN TIMUR / NAMBLONG', 9403), -(9403170, 'NIMBOKRANG', 9403), -(9403180, 'UNURUM GUAY', 9403), -(9403200, 'DEMTA', 9403), -(9403201, 'YOKARI', 9403), -(9403210, 'DEPAPRE', 9403), -(9403211, 'RAVENIRARA', 9403), -(9403220, 'SENTANI BARAT', 9403), -(9403221, 'WAIBU', 9403), -(9403230, 'SENTANI', 9403), -(9403231, 'EBUNGFAU', 9403), -(9403240, 'SENTANI TIMUR', 9403), -(9404050, 'UWAPA', 9404), -(9404051, 'MENOU', 9404), -(9404052, 'DIPA', 9404), -(9404060, 'YAUR', 9404), -(9404061, 'TELUK UMAR', 9404), -(9404070, 'WANGGAR', 9404), -(9404071, 'NABIRE BARAT', 9404), -(9404080, 'NABIRE', 9404), -(9404081, 'TELUK KIMI', 9404), -(9404090, 'NAPAN', 9404), -(9404091, 'MAKIMI', 9404), -(9404092, 'WAPOGA', 9404), -(9404100, 'SIRIWO', 9404), -(9404110, 'YARO', 9404), -(9408040, 'YAPEN TIMUR', 9408), -(9408041, 'PANTURA YAPEN', 9408), -(9408042, 'TELUK AMPIMOI', 9408), -(9408043, 'RAIMBAWI', 9408), -(9408044, 'PULAU KURUDU', 9408), -(9408050, 'ANGKAISERA', 9408), -(9408051, 'KEP. AMBAI', 9408), -(9408060, 'YAPEN SELATAN', 9408), -(9408061, 'KOSIWO', 9408), -(9408070, 'YAPEN BARAT', 9408), -(9408071, 'WONAWA', 9408), -(9408072, 'PULAU YERUI', 9408), -(9408080, 'POOM', 9408), -(9408081, 'WINDESI', 9408), -(9409010, 'NUMFOR BARAT', 9409), -(9409011, 'ORKERI', 9409), -(9409020, 'NUMFOR TIMUR', 9409), -(9409021, 'BRUYADORI', 9409), -(9409022, 'POIRU', 9409), -(9409030, 'PADAIDO', 9409), -(9409031, 'AINANDO PADAIDO', 9409), -(9409040, 'BIAK TIMUR', 9409), -(9409041, 'ORIDEK', 9409), -(9409050, 'BIAK KOTA', 9409), -(9409060, 'SAMOFA', 9409), -(9409070, 'YENDIDORI', 9409), -(9409080, 'BIAK UTARA', 9409), -(9409081, 'ANDEY', 9409), -(9409090, 'WARSA', 9409), -(9409091, 'YAWOSI', 9409), -(9409092, 'BONDIFUAR', 9409), -(9409100, 'BIAK BARAT', 9409), -(9409101, 'SWANDIWE', 9409), -(9410030, 'PANIAI TIMUR', 9410), -(9410031, 'YATAMO', 9410), -(9410032, 'KEBO', 9410), -(9410040, 'BIBIDA', 9410), -(9410041, 'DUMADAMA', 9410), -(9410070, 'ARADIDE', 9410), -(9410071, 'EKADIDE', 9410), -(9410080, 'PANIAI BARAT', 9410), -(9410081, 'SIRIWO', 9410), -(9410090, 'BOGOBAIDA', 9410), -(9411040, 'FAWI', 9411), -(9411050, 'MULIA', 9411), -(9411051, 'MEWOLUK', 9411), -(9411052, 'YAMO', 9411), -(9411060, 'ILU', 9411), -(9411061, 'TORERE', 9411), -(9411062, 'JIGONIKME', 9411), -(9411070, 'TINGGINAMBUT', 9411), -(9412010, 'MIMIKA BARAT', 9412), -(9412011, 'MIMIKA BARAT JAUH', 9412), -(9412012, 'MIMIKA BARAT TENGAH', 9412), -(9412020, 'MIMIKA TIMUR', 9412), -(9412021, 'MIMIKA TENGAH', 9412), -(9412022, 'MIMIKA TIMUR JAUH', 9412), -(9412030, 'MIMIKA BARU', 9412), -(9412031, 'KUALA KENCANA', 9412), -(9412032, 'TEMBAGAPURA', 9412), -(9412040, 'AGIMUGA', 9412), -(9412041, 'JILA', 9412), -(9412042, 'JITA', 9412), -(9413010, 'JAIR', 9413), -(9413011, 'SUBUR', 9413), -(9413013, 'KIA', 9413), -(9413020, 'MINDIPTANA', 9413), -(9413021, 'INIYANDIT', 9413), -(9413022, 'KOMBUT', 9413), -(9413023, 'SESNUK', 9413), -(9413030, 'MANDOBO', 9413), -(9413031, 'FOFI', 9413), -(9413032, 'ARIMOP', 9413), -(9413040, 'KOUH', 9413), -(9413041, 'BOMAKIA', 9413), -(9413042, 'FIRIWAGE', 9413), -(9413043, 'MANGGELUM', 9413), -(9413044, 'YANIRUMA', 9413), -(9413045, 'KAWAGIT', 9413), -(9413046, 'KOMBAY', 9413), -(9413050, 'WAROPKO', 9413), -(9413051, 'AMBATKWI', 9413), -(9413052, 'NINATI', 9413), -(9414010, 'NAMBIOMAN BAPAI', 9414), -(9414011, 'MINYAMUR', 9414), -(9414020, 'EDERA', 9414), -(9414021, 'VENAHA', 9414), -(9414030, 'OBAA', 9414), -(9414031, 'PASSUE', 9414), -(9414040, 'HAJU', 9414), -(9414050, 'ASSUE', 9414), -(9414060, 'CITAKMITAK', 9414), -(9414061, 'KAIBAR', 9414), -(9415010, 'PANTAI KASUARI', 9415), -(9415020, 'FAYIT', 9415), -(9415030, 'ATSY', 9415), -(9415040, 'SUATOR', 9415), -(9415050, 'AKAT', 9415), -(9415060, 'AGATS', 9415), -(9415070, 'SAWA ERMA', 9415), -(9415071, 'SURU-SURU', 9415), -(9416010, 'KURIMA', 9416), -(9416011, 'MUSAIK', 9416), -(9416013, 'DEKAI', 9416), -(9416014, 'OBIO', 9416), -(9416015, 'PASEMA', 9416), -(9416016, 'AMUMA', 9416), -(9416017, 'SURU-SURU', 9416), -(9416018, 'WUSAMA', 9416), -(9416019, 'SILIMO', 9416), -(9416020, 'NINIA', 9416), -(9416021, 'HOLUWON', 9416), -(9416022, 'LOLAT', 9416), -(9416023, 'LANGDA', 9416), -(9416024, 'BOMELA', 9416), -(9416025, 'SUNTAMON', 9416), -(9416026, 'SOBAHAM', 9416), -(9416027, 'KORUPUN', 9416), -(9416028, 'SELA', 9416), -(9416029, 'KWELAMDUA', 9416), -(9416030, 'ANGGRUK', 9416), -(9416031, 'PANGGEMA', 9416), -(9416032, 'WALMA', 9416), -(9416033, 'KOSAREK', 9416), -(9416034, 'UBAHAK', 9416), -(9416035, 'NALCA', 9416), -(9416036, 'PULDAMA', 9416), -(9416037, 'NIPSAN', 9416), -(9416041, 'SAMENAGE', 9416), -(9416042, 'TANGMA', 9416), -(9416043, 'SOBA', 9416), -(9416044, 'MUGI', 9416), -(9416045, 'YOGOSEM', 9416), -(9416046, 'KAYO', 9416), -(9416047, 'SUMO', 9416), -(9416048, 'HOGIO', 9416), -(9416049, 'UKHA', 9416), -(9416051, 'WERIMA', 9416), -(9416052, 'SOLOIKMA', 9416), -(9416053, 'SERADALA', 9416), -(9416054, 'KABIANGGAMA', 9416), -(9416055, 'KWIKMA', 9416), -(9416056, 'HILIPUK', 9416), -(9416057, 'YAHULIAMBUT', 9416), -(9416058, 'HEREAPINI', 9416), -(9416059, 'UBALIHI', 9416), -(9416061, 'TALAMBO', 9416), -(9416062, 'PRONGGOLI', 9416), -(9416063, 'ENDOMEN', 9416), -(9416065, 'KONA', 9416), -(9416066, 'DURAM', 9416), -(9416067, 'DIRWEMNA', 9416), -(9417010, 'IWUR', 9417), -(9417011, 'KAWOR', 9417), -(9417012, 'TARUP', 9417), -(9417013, 'AWINBON', 9417), -(9417020, 'OKSIBIL', 9417), -(9417021, 'PEPERA', 9417), -(9417022, 'ALEMSOM', 9417), -(9417023, 'SERAMBAKON', 9417), -(9417025, 'OKSOP', 9417), -(9417026, 'OK BAPE', 9417), -(9417027, 'OK AON', 9417), -(9417030, 'BORME', 9417), -(9417031, 'BIME', 9417), -(9417032, 'EPUMEK', 9417), -(9417033, 'WEIME', 9417), -(9417034, 'PAMEK', 9417), -(9417035, 'NONGME', 9417), -(9417040, 'OKBI', 9417), -(9417041, 'ABOY', 9417), -(9417042, 'OKBAB', 9417), -(9417043, 'TEIRAPLU', 9417), -(9417051, 'KIWIROK TIMUR', 9417), -(9417052, 'OKSEBANG', 9417), -(9417053, 'OKHIKA', 9417), -(9417054, 'OKLIP', 9417), -(9417055, 'OKSAMOL', 9417), -(9417056, 'OKBEMTA', 9417), -(9417060, 'BATOM', 9417), -(9417061, 'MURKIM', 9417), -(9417062, 'MOFINOP', 9417), -(9418010, 'KANGGIME', 9418), -(9418011, 'WONIKI', 9418), -(9418012, 'NABUNAGE', 9418), -(9418013, 'GILUBANDU', 9418), -(9418014, 'WAKUO', 9418), -(9418015, 'AWEKU', 9418), -(9418016, 'BOGONUK', 9418), -(9418020, 'KARUBAGA', 9418), -(9418021, 'GOYAGE', 9418), -(9418022, 'WUNIN', 9418), -(9418023, 'KONDAGA', 9418), -(9418024, 'NELAWI', 9418), -(9418025, 'KUARI', 9418), -(9418026, 'LIANOGOMA', 9418), -(9418027, 'BIUK', 9418), -(9418030, 'BOKONDINI', 9418), -(9418031, 'BOKONERI', 9418), -(9418032, 'BEWANI', 9418), -(9418040, 'KEMBU', 9418), -(9418041, 'WINA', 9418), -(9418042, 'UMAGI', 9418), -(9418043, 'PANAGA', 9418), -(9418044, 'POGANERI', 9418), -(9418045, 'KAMBONERI', 9418), -(9418046, 'AIR GARAM', 9418), -(9418051, 'NUNGGAWI', 9418), -(9418052, 'TELENGGEME', 9418), -(9418060, 'KUBU', 9418), -(9418061, 'ANAWI', 9418), -(9418062, 'WUGI', 9418), -(9418070, 'GEYA', 9418), -(9418071, 'WENAM', 9418), -(9418080, 'NUMBA', 9418), -(9418081, 'KAI', 9418), -(9418090, 'DUNDU', 9418), -(9418091, 'GIKA', 9418), -(9418100, 'GUNDAGI', 9418), -(9418110, 'TIMORI', 9418), -(9418121, 'YUNERI', 9418), -(9418122, 'TAGINERI', 9418), -(9418125, 'TAGIME', 9418), -(9418126, 'DANIME', 9418), -(9418127, 'YUKO', 9418), -(9419021, 'PANTAI TIMUR BAGIAN BARAT', 9419), -(9419022, 'PANTAI TIMUR', 9419), -(9419031, 'BONGGO', 9419), -(9419032, 'BONGGO TIMUR', 9419), -(9419040, 'TOR ATAS', 9419), -(9419050, 'SARMI', 9419), -(9419051, 'SARMI TIMUR', 9419), -(9419052, 'SARMI SELATAN', 9419), -(9419060, 'PANTAI BARAT', 9419), -(9419061, 'APAWER HULU', 9419), -(9420010, 'WEB', 9420), -(9420011, 'TOWE HITAM', 9420), -(9420020, 'SENGGI', 9420), -(9420030, 'WARIS', 9420), -(9420040, 'ARSO', 9420), -(9420041, 'ARSO TIMUR', 9420), -(9420050, 'SKANTO', 9420), -(9426010, 'WAROPEN BAWAH', 9426), -(9426011, 'INGGERUS', 9426), -(9426012, 'UREI FAISEI', 9426), -(9426013, 'OUDATE', 9426), -(9426014, 'WAPOGA', 9426), -(9426020, 'MASIREI', 9426), -(9426021, 'RISEI SAYATI', 9426), -(9426022, 'DEMBA', 9426), -(9426030, 'WALANI', 9426), -(9426040, 'KIRIHI', 9426), -(9427010, 'SUPIORI SELATAN', 9427), -(9427011, 'KEPULAUAN ARURI', 9427), -(9427020, 'SUPIORI UTARA', 9427), -(9427021, 'SUPIORI BARAT', 9427), -(9427030, 'SUPIORI TIMUR', 9427), -(9428040, 'MAMBERAMO ILIR', 9428), -(9428050, 'MAMBERAMO TENGAH', 9428), -(9428060, 'MAMBERAMO TENGAH TIMUR', 9428), -(9428070, 'ROFAER', 9428), -(9428080, 'MAMBERAMO ULU', 9428), -(9429010, 'WOSAK', 9429), -(9429020, 'KENYAM', 9429), -(9429030, 'GESELMA', 9429), -(9429040, 'MAPENDUMA', 9429), -(9429050, 'MUGI', 9429), -(9429060, 'YIGI', 9429), -(9429070, 'MBUWA', 9429), -(9429080, 'GEAREK', 9429), -(9430010, 'MAKKI', 9430), -(9430020, 'PIRIME', 9430), -(9430030, 'TIOM', 9430), -(9430040, 'BALINGGA', 9430), -(9430050, 'KUYAWAGE', 9430), -(9430060, 'MALAGAINERI', 9430), -(9430070, 'TIOMNERI', 9430), -(9430080, 'DIMBA', 9430), -(9430090, 'GAMELIA', 9430), -(9430100, 'POGA', 9430), -(9431010, 'KOBAKMA', 9431), -(9431020, 'ILUGWA', 9431), -(9431030, 'KELILA', 9431), -(9431040, 'ERAGAYAM', 9431), -(9431050, 'MEGAMBILIS', 9431), -(9432010, 'WELAREK', 9432), -(9432020, 'APALAPSILI', 9432), -(9432030, 'ABENAHO', 9432), -(9432040, 'ELELIM', 9432), -(9432050, 'BENAWA', 9432), -(9433010, 'AGADUGUME', 9433), -(9433020, 'GOME', 9433), -(9433030, 'ILAGA', 9433), -(9433040, 'SINAK', 9433), -(9433050, 'POGOMA', 9433), -(9433060, 'WANGBE', 9433), -(9433070, 'BEOGA', 9433), -(9433080, 'DOUFO', 9433), -(9434010, 'SUKIKAI SELATAN', 9434), -(9434020, 'PIYAIYE', 9434), -(9434030, 'MAPIA BARAT', 9434), -(9434040, 'MAPIA TENGAH', 9434), -(9434050, 'MAPIA', 9434), -(9434060, 'DOGIYAI', 9434), -(9434070, 'KAMU SELATAN', 9434), -(9434080, 'KAMU', 9434), -(9434090, 'KAMU TIMUR', 9434), -(9434100, 'KAMU UTARA', 9434), -(9435010, 'HOMEYO', 9435), -(9435020, 'SUGAPA', 9435), -(9435030, 'HITADIPA', 9435), -(9435040, 'AGISIGA', 9435), -(9435050, 'BIANDOGA', 9435), -(9435060, 'WANDAI', 9435), -(9436010, 'KAPIRAYA', 9436), -(9436020, 'TIGI BARAT', 9436), -(9436030, 'TIGI', 9436), -(9436040, 'TIGI TIMUR', 9436), -(9436050, 'BOWOBADO', 9436), -(9471010, 'MUARA TAMI', 9471), -(9471020, 'ABEPURA', 9471), -(9471021, 'HERAM', 9471), -(9471030, 'JAYAPURA SELATAN', 9471), -(9471040, 'JAYAPURA UTARA', 9471); - --- -------------------------------------------------------- - --- --- Table structure for table `klascoa` --- - -CREATE TABLE IF NOT EXISTS `klascoa` ( - `klascoa_id` int(11) NOT NULL AUTO_INCREMENT, - `nama_klascoa` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - `kode_awal` varbinary(20) NOT NULL, - PRIMARY KEY (`klascoa_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=11 ; - --- --- Dumping data for table `klascoa` --- - -INSERT INTO `klascoa` (`klascoa_id`, `nama_klascoa`, `kode_awal`) VALUES -(1, 'AKTIVA', '1000000'), -(2, 'KEWAJIBAN, INVESTASI TIDAK TERIKAT DAN MODAL', '2000000'), -(3, 'INVESTASI TIDAK TERIKAT', '3000000'), -(4, 'MODAL', '4000000'), -(5, 'PENDAPATAN', '5000000'), -(6, 'BAGI HASIL ITT DAN BEBAN', '6000000'), -(7, 'PERKIRAAN BEBAN', '7000000'); - --- -------------------------------------------------------- - --- --- Table structure for table `kolekbilitas_bulanan` --- - -CREATE TABLE IF NOT EXISTS `kolekbilitas_bulanan` ( - `kbulanan_id` int(11) NOT NULL AUTO_INCREMENT, - `type_kolekbilitas` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `parameter` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `kode` varchar(2) COLLATE latin1_general_ci NOT NULL, - PRIMARY KEY (`kbulanan_id`), - UNIQUE KEY `jangkawaktu` (`parameter`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=6 ; - --- --- Dumping data for table `kolekbilitas_bulanan` --- - -INSERT INTO `kolekbilitas_bulanan` (`kbulanan_id`, `type_kolekbilitas`, `parameter`, `kode`) VALUES -(1, 'LANCAR', '1', 'L'), -(2, 'KURANG LANCAR', '1 - 2', 'KL'), -(3, 'DIRAGUKAN', '3', 'D'), -(4, 'MACET', '4', 'M'); - --- -------------------------------------------------------- - --- --- Table structure for table `kolekbilitas_harian` --- - -CREATE TABLE IF NOT EXISTS `kolekbilitas_harian` ( - `kharian_id` int(11) NOT NULL AUTO_INCREMENT, - `type_kolekbilitas` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `parameter` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `kode` varchar(2) COLLATE latin1_general_ci NOT NULL, - PRIMARY KEY (`kharian_id`), - UNIQUE KEY `jangkawaktu` (`parameter`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=6 ; - --- --- Dumping data for table `kolekbilitas_harian` --- - -INSERT INTO `kolekbilitas_harian` (`kharian_id`, `type_kolekbilitas`, `parameter`, `kode`) VALUES -(1, 'LANCAR', '1', 'L'), -(2, 'KURANG LANCAR', '1 - 2', 'KL'), -(3, 'DIRAGUKAN', '3', 'D'), -(4, 'MACET', '4', 'M'); - --- -------------------------------------------------------- - --- --- Table structure for table `kolekbilitas_jatuhtempo` --- - -CREATE TABLE IF NOT EXISTS `kolekbilitas_jatuhtempo` ( - `kjatuhtempo_id` int(11) NOT NULL AUTO_INCREMENT, - `type_kolekbilitas` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `jangka_waktu` int(11) DEFAULT NULL, - PRIMARY KEY (`kjatuhtempo_id`), - UNIQUE KEY `jangkawaktu` (`jangka_waktu`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=6 ; - --- --- Dumping data for table `kolekbilitas_jatuhtempo` --- - -INSERT INTO `kolekbilitas_jatuhtempo` (`kjatuhtempo_id`, `type_kolekbilitas`, `jangka_waktu`) VALUES -(1, 'LANCAR', 1), -(2, 'KURANG LANCAR', 30), -(3, 'DIRAGUKAN', 60), -(4, 'MACET 1', 90), -(5, 'MACET 2', 120); - --- -------------------------------------------------------- - --- --- Table structure for table `kolekbilitas_mingguan` --- - -CREATE TABLE IF NOT EXISTS `kolekbilitas_mingguan` ( - `kmingguan_id` int(11) NOT NULL AUTO_INCREMENT, - `type_kolekbilitas` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `parameter` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `kode` varchar(2) COLLATE latin1_general_ci NOT NULL, - PRIMARY KEY (`kmingguan_id`), - UNIQUE KEY `jangkawaktu` (`parameter`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=6 ; - --- --- Dumping data for table `kolekbilitas_mingguan` --- - -INSERT INTO `kolekbilitas_mingguan` (`kmingguan_id`, `type_kolekbilitas`, `parameter`, `kode`) VALUES -(1, 'LANCAR', '1', 'L'), -(2, 'KURANG LANCAR', '1 - 2', 'KL'), -(3, 'DIRAGUKAN', '3', 'D'), -(4, 'MACET', '4', 'M'); - --- -------------------------------------------------------- - --- --- Table structure for table `master_biaya` --- - -CREATE TABLE IF NOT EXISTS `master_biaya` ( - `biaya_id` int(11) NOT NULL AUTO_INCREMENT, - `kode` decimal(16,2) DEFAULT NULL, - `nama` decimal(16,2) DEFAULT NULL, - PRIMARY KEY (`biaya_id`), - UNIQUE KEY `kode` (`kode`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ; - --- --- Dumping data for table `master_biaya` --- - -INSERT INTO `master_biaya` (`biaya_id`, `kode`, `nama`) VALUES -(1, 500000.00, 500.00), -(2, 5000000.00, 1000.00), -(3, 50000000.00, 2000.00); - --- -------------------------------------------------------- - --- --- Table structure for table `master_deposito` --- - -CREATE TABLE IF NOT EXISTS `master_deposito` ( - `deposito_id` int(11) NOT NULL AUTO_INCREMENT, - `kode_produk` varchar(11) COLLATE latin1_general_ci NOT NULL, - `biaya_administrasi` decimal(16,2) NOT NULL, - `nominal` decimal(16,2) DEFAULT NULL, - `jangka_waktu` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `nisbah_bank` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `nisbah_nasabah` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `pph` varchar(20) COLLATE latin1_general_ci NOT NULL, - `zakat` varchar(20) COLLATE latin1_general_ci NOT NULL, - `bonus` varchar(200) COLLATE latin1_general_ci NOT NULL, - `gl_produk` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_bagihasil` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_titipanbagihasil` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_administrasi` varchar(20) COLLATE latin1_general_ci NOT NULL, - `gl_pajakpenghasilan` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_zakat` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_bonus` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - PRIMARY KEY (`deposito_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ; - --- --- Dumping data for table `master_deposito` --- - -INSERT INTO `master_deposito` (`deposito_id`, `kode_produk`, `biaya_administrasi`, `nominal`, `jangka_waktu`, `nisbah_bank`, `nisbah_nasabah`, `pph`, `zakat`, `bonus`, `gl_produk`, `gl_bagihasil`, `gl_titipanbagihasil`, `gl_administrasi`, `gl_pajakpenghasilan`, `gl_zakat`, `gl_bonus`) VALUES -(1, '11', 10000.00, 50000000.00, '1', '60', '40', '0', '0', '0', '257', '440', '246', '----------', '----------', '----------', '----------'), -(2, '12', 0.00, 5000000000.00, '3', '50', '50', '', '', '', '258', '449', '246', '----------', '----------', '----------', '----------'), -(3, '13', 0.00, 50000000.00, '6', '40', '50', '', '', '', '259', '442', '246', '----------', '----------', '----------', '----------'), -(4, '14', 0.00, 50000000.00, '12', '35', '65', '', '', '', '260', '443', '246', '----------', '----------', '----------', '----------'); - --- -------------------------------------------------------- - --- --- Table structure for table `master_groupdeposito` --- - -CREATE TABLE IF NOT EXISTS `master_groupdeposito` ( - `groupdeposito_id` int(11) NOT NULL AUTO_INCREMENT, - `kode_produk` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `groupdeposito_nama` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - PRIMARY KEY (`groupdeposito_id`), - UNIQUE KEY `kode` (`kode_produk`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ; - --- --- Dumping data for table `master_groupdeposito` --- - -INSERT INTO `master_groupdeposito` (`groupdeposito_id`, `kode_produk`, `groupdeposito_nama`, `status`) VALUES -(1, '11', 'INVESTASI 1 BL', '0'), -(2, '12', 'INVESTASI 3 BL', '0'), -(3, '13', 'INVESTASI 6 BL', '0'), -(4, '14', 'INVESTASI 12 BL', '0'); - --- -------------------------------------------------------- - --- --- Table structure for table `master_grouppembiayaan` --- - -CREATE TABLE IF NOT EXISTS `master_grouppembiayaan` ( - `grouppembiayaan_id` int(11) NOT NULL AUTO_INCREMENT, - `kode_produk` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `grouppembiayaan_nama` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - PRIMARY KEY (`grouppembiayaan_id`), - UNIQUE KEY `kode` (`kode_produk`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=8 ; - --- --- Dumping data for table `master_grouppembiayaan` --- - -INSERT INTO `master_grouppembiayaan` (`grouppembiayaan_id`, `kode_produk`, `grouppembiayaan_nama`, `status`) VALUES -(1, '41', 'MURABAHAH', '0'), -(2, '42', 'MUDHARABAH', '0'), -(3, '43', 'AL-QARDH', '0'), -(4, '44', 'MUSYARAKAH', '0'); - --- -------------------------------------------------------- - --- --- Table structure for table `master_grouptabungan` --- - -CREATE TABLE IF NOT EXISTS `master_grouptabungan` ( - `grouptabungan_id` int(11) NOT NULL AUTO_INCREMENT, - `kode_produk` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `grouptabungan_nama` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - PRIMARY KEY (`grouptabungan_id`), - UNIQUE KEY `kode` (`kode_produk`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ; - --- --- Dumping data for table `master_grouptabungan` --- - -INSERT INTO `master_grouptabungan` (`grouptabungan_id`, `kode_produk`, `grouptabungan_nama`, `status`) VALUES -(1, '21', 'SIMPANAN WADIAH BAROKAH', '0'), -(3, '22', 'SIMPANAN POKOK & WAJIB', '0'), -(4, '23', 'SImpnan Pokok', '0'); - --- -------------------------------------------------------- - --- --- Table structure for table `master_kodemutasi` --- - -CREATE TABLE IF NOT EXISTS `master_kodemutasi` ( - `mutasi_id` int(11) NOT NULL AUTO_INCREMENT, - `kode` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nama` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`mutasi_id`), - UNIQUE KEY `kode` (`kode`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=16 ; - --- --- Dumping data for table `master_kodemutasi` --- - -INSERT INTO `master_kodemutasi` (`mutasi_id`, `kode`, `nama`) VALUES -(1, '01', 'SETOR TUNAI'), -(2, '02', 'TARIK TUNAI'), -(3, '03', 'SETOR OVERBOOK'), -(4, '04', 'TARIK OVERBOOK'), -(5, '05', 'ADMINISTRASI'), -(6, '06', 'BAGI HASIL'), -(7, '07', 'BONUS/HADIAH'), -(8, '08', 'ZAKAT'), -(9, '09', 'PAJAK'), -(10, '10', 'BIAYA PENUTUPAN'), -(11, '11', 'BIAYA PEMBUKAAN'), -(12, '12', 'BIAYA BUKU'), -(13, '13', 'KOREKSI DEBIT'), -(14, '14', 'KOREKSI KREDIT'), -(15, '15', 'LAIN-LAIN'); - --- -------------------------------------------------------- - --- --- Table structure for table `master_otoritas` --- - -CREATE TABLE IF NOT EXISTS `master_otoritas` ( - `otoritas_id` int(11) NOT NULL AUTO_INCREMENT, - `kode` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `level` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`otoritas_id`), - UNIQUE KEY `kode` (`kode`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ; - --- --- Dumping data for table `master_otoritas` --- - -INSERT INTO `master_otoritas` (`otoritas_id`, `kode`, `level`) VALUES -(1, '5000000', '5'), -(2, '15000000', NULL); - --- -------------------------------------------------------- - --- --- Table structure for table `master_pembiayaan` --- - -CREATE TABLE IF NOT EXISTS `master_pembiayaan` ( - `pembiayaan_id` int(11) NOT NULL AUTO_INCREMENT, - `kode_produk` varchar(11) COLLATE latin1_general_ci NOT NULL, - `biaya_administrasi` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_produk` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_administrasi` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_marginditangguhkan` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_pendapatanmargin` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_diskon` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_pendapatanbagihasil` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_bonusalqardh` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `gl_pendapatanbagihasilmusy` varchar(20) COLLATE latin1_general_ci NOT NULL, - `gl_activaijarah` varchar(20) COLLATE latin1_general_ci NOT NULL, - `gl_pendapatanijarah` varchar(20) COLLATE latin1_general_ci NOT NULL, - `gl_asetistishna` varchar(20) COLLATE latin1_general_ci NOT NULL, - `gl_pendapatanmarjinistishna` varchar(20) COLLATE latin1_general_ci NOT NULL, - `gl_diskonistishna` varchar(20) COLLATE latin1_general_ci NOT NULL, - `gl_pendapatankeuntungansalam` varchar(20) COLLATE latin1_general_ci NOT NULL, - PRIMARY KEY (`pembiayaan_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=8 ; - --- --- Dumping data for table `master_pembiayaan` --- - -INSERT INTO `master_pembiayaan` (`pembiayaan_id`, `kode_produk`, `biaya_administrasi`, `gl_produk`, `gl_administrasi`, `gl_marginditangguhkan`, `gl_pendapatanmargin`, `gl_diskon`, `gl_pendapatanbagihasil`, `gl_bonusalqardh`, `gl_pendapatanbagihasilmusy`, `gl_activaijarah`, `gl_pendapatanijarah`, `gl_asetistishna`, `gl_pendapatanmarjinistishna`, `gl_diskonistishna`, `gl_pendapatankeuntungansalam`) VALUES -(1, '41', '10000', '38', '384', '44', '288', '294', NULL, NULL, '', '', '', '', '', '', ''), -(2, '42', '10000', '80', '396', '----------', '----------', '----------', '315', '----------', '', '', '', '', '', '', ''), -(3, '43', '10000', '114', '411', '----------', '----------', '----------', '----------', '372', '', '', '', '', '', '', ''), -(4, '44', '10000', '87', '400', '----------', '----------', '----------', '----------', '----------', '----------', '----------', '----------', '', '', '', ''); - --- -------------------------------------------------------- - --- --- Table structure for table `master_tabungan` --- - -CREATE TABLE IF NOT EXISTS `master_tabungan` ( - `mtabungan_id` int(11) NOT NULL AUTO_INCREMENT, - `kode_produk` varchar(11) COLLATE latin1_general_ci NOT NULL, - `adm_buka_rekening` decimal(16,2) DEFAULT NULL, - `adm_tutup_rekening` decimal(16,2) DEFAULT NULL, - `adm_lain_lain` decimal(16,2) DEFAULT NULL, - `tab_pph` varchar(20) COLLATE latin1_general_ci NOT NULL, - `tab_zakat` varchar(20) COLLATE latin1_general_ci NOT NULL, - `gl_produk` int(11) NOT NULL, - `gl_bagihasil` int(11) NOT NULL, - `gl_buka_tutup_rek` int(11) DEFAULT NULL, - `gl_bonus` int(11) DEFAULT NULL, - `gl_pemeliharaan` int(11) DEFAULT NULL, - `gl_zakat` int(11) NOT NULL, - `gl_pajak` int(11) NOT NULL, - PRIMARY KEY (`mtabungan_id`), - UNIQUE KEY `kode` (`kode_produk`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ; - --- --- Dumping data for table `master_tabungan` --- - -INSERT INTO `master_tabungan` (`mtabungan_id`, `kode_produk`, `adm_buka_rekening`, `adm_tutup_rekening`, `adm_lain_lain`, `tab_pph`, `tab_zakat`, `gl_produk`, `gl_bagihasil`, `gl_buka_tutup_rek`, `gl_bonus`, `gl_pemeliharaan`, `gl_zakat`, `gl_pajak`) VALUES -(1, '21', NULL, NULL, 5000.00, '1', '2.5', 203, 349, 581, 0, 416, 577, 244), -(3, '22', NULL, NULL, 1000.00, '1', '2.5', 264, 349, 581, 0, 416, 577, 244); - --- -------------------------------------------------------- - --- --- Table structure for table `master_tahunbuku` --- - -CREATE TABLE IF NOT EXISTS `master_tahunbuku` ( - `tahunbuku_id` int(11) NOT NULL AUTO_INCREMENT, - `nama_tahun` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `tgl_mulai` date NOT NULL, - `tgl_akhir` date NOT NULL, - `active` tinyint(1) DEFAULT NULL, - PRIMARY KEY (`tahunbuku_id`), - UNIQUE KEY `nama_tahun` (`nama_tahun`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ; - --- --- Dumping data for table `master_tahunbuku` --- - -INSERT INTO `master_tahunbuku` (`tahunbuku_id`, `nama_tahun`, `tgl_mulai`, `tgl_akhir`, `active`) VALUES -(1, '2014', '2014-01-01', '2014-12-31', 0), -(2, '2015', '2015-01-01', '2015-12-31', 1), -(3, '2016', '2016-01-01', '2016-12-31', 0); - --- -------------------------------------------------------- - --- --- Table structure for table `menuapp` --- - -CREATE TABLE IF NOT EXISTS `menuapp` ( - `menu_id` int(11) NOT NULL AUTO_INCREMENT, - `nama` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `href` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `icon` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `css` varchar(30) COLLATE utf8_unicode_ci NOT NULL, - `sub` varchar(35) COLLATE utf8_unicode_ci NOT NULL, - `parent` int(11) DEFAULT NULL, - `urutan` int(11) DEFAULT NULL, - `groups` text COLLATE utf8_unicode_ci, - `active` tinyint(1) DEFAULT NULL, - PRIMARY KEY (`menu_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=75 ; - --- --- Dumping data for table `menuapp` --- - -INSERT INTO `menuapp` (`menu_id`, `nama`, `href`, `icon`, `css`, `sub`, `parent`, `urutan`, `groups`, `active`) VALUES -(1, 'Dashboard', '.', '', 'index', '', 0, 1, 'a:8:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSI";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:9:"MARKETING";i:6;s:20:"Operasional & Keuang";i:7;s:6:"TELLER";}', 1), -(2, 'Parameter', 'root', '', 'param', '', 0, 2, 'a:4:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:7:"MANAGER";i:3;s:20:"Operasional & Keuang";}', 1), -(3, 'Akuntansi', 'root', ' ', 'akun', '', 0, 6, 'a:3:{i:0;s:5:"Admin";i:1;s:9:"AKUNTANSI";i:2;s:20:"Operasional & Keuang";}', 1), -(4, 'Data dasar', 'j', '', 'base', '', 0, 3, 'a:7:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSi";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:20:"Operasional & Keuang";i:6;s:6:"TELLER";}', 1), -(5, 'Transaksi Teller', 'j', '', 'transaksiumum', '', 0, 4, 'a:1:{i:0;s:6:"TELLER";}', 1), -(6, 'Transaksi Umum', '[removed];', '', 'transaksikas', '', 0, 5, 'a:4:{i:0;s:5:"Admin";i:1;s:9:"AKUNTANSI";i:2;s:20:"Operasional & Keuang";i:3;s:6:"TELLER";}', 1), -(60, 'Distribusi Profit', 'param/distribusiprofit', '', 'param', 'distribusiprofit', 2, 11, 'a:3:{i:0;s:5:"Admin";i:1;s:7:"MANAGER";i:2;s:20:"Operasional & Keuang";}', 1), -(8, 'Monitor', 'javascript:;', '', 'monitor', '', 0, 8, 'a:8:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSi";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:9:"MARKETING";i:6;s:20:"Operasional & Keuang";i:7;s:6:"TELLER";}', 1), -(9, 'Otomasi', '[removed];', '', 'tools', '', 0, 9, 'a:4:{i:0;s:5:"Admin";i:1;s:9:"AKUNTANSi";i:2;s:2:"CS";i:3;s:20:"Operasional & Keuang";}', 1), -(11, 'Wewenang', 'param/user', '', 'param', 'user', 2, 1, 'a:3:{i:0;s:5:"Admin";i:1;s:7:"MANAGER";i:2;s:20:"Operasional & Keuang";}', 1), -(13, 'Pegawai', 'param/pegawai', '', 'param', 'pegawai', 2, 4, 'a:3:{i:0;s:5:"Admin";i:1;s:7:"MANAGER";i:2;s:20:"Operasional & Keuang";}', 1), -(64, 'Sampul tabungan', 'setting/sampultab', '', 'setting', 'sampultab', 61, 3, 'a:2:{i:0;s:5:"Admin";i:1;s:20:"Operasional & Keuang";}', 1), -(14, 'Tentang BMT', 'param/bmt', '', 'param', 'bmt', 2, 5, 'a:3:{i:0;s:5:"Admin";i:1;s:7:"MANAGER";i:2;s:20:"Operasional & Keuang";}', 1), -(15, 'List Akun', 'param/listakun', '', 'param', 'listakun', 2, 6, 'a:3:{i:0;s:5:"Admin";i:1;s:7:"MANAGER";i:2;s:20:"Operasional & Keuang";}', 1), -(16, 'Nasabah', 'param/nasabah', '', 'param', 'nasabah', 2, 7, 'a:3:{i:0;s:5:"Admin";i:1;s:7:"MANAGER";i:2;s:20:"Operasional & Keuang";}', 1), -(17, 'Tabungan', 'param/tabungan', '', 'param', 'tabungan', 2, 8, 'a:3:{i:0;s:5:"Admin";i:1;s:7:"MANAGER";i:2;s:20:"Operasional & Keuang";}', 1), -(18, 'Pembiayaan', 'param/pembiayaan', '', 'param', 'pembiayaan', 2, 9, 'a:3:{i:0;s:5:"Admin";i:1;s:7:"MANAGER";i:2;s:20:"Operasional & Keuang";}', 1), -(19, 'Deposito', 'param/deposito', '', 'param', 'deposito', 2, 10, 'a:3:{i:0;s:5:"Admin";i:1;s:7:"MANAGER";i:2;s:20:"Operasional & Keuang";}', 1), -(20, 'Masukkan Jurnal', 'akunting/jurnal', '', 'akun', 'jurnal', 3, 1, 'a:3:{i:0;s:5:"Admin";i:1;s:9:"AKUNTANSI";i:2;s:20:"Operasional & Keuang";}', 1), -(21, 'Jurnal umum', 'akunting/posting', '', 'akun', 'posting', 3, 2, 'a:3:{i:0;s:5:"Admin";i:1;s:9:"AKUNTANSI";i:2;s:20:"Operasional & Keuang";}', 1), -(22, 'Laporan Neraca', 'akunting/neraca', '', 'akun', 'neraca', 3, 3, 'a:3:{i:0;s:5:"Admin";i:1;s:9:"AKUNTANSI";i:2;s:20:"Operasional & Keuang";}', 1), -(23, 'Laporan Laba Rugi', 'akunting/labarugi', '', 'akun', 'labarugi', 3, 4, 'a:3:{i:0;s:5:"Admin";i:1;s:9:"AKUNTANSI";i:2;s:20:"Operasional & Keuang";}', 1), -(24, 'Nasabah', 'base/nasabah', '', 'base', 'nasabah', 4, 1, 'a:6:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:2:"CS";i:3;s:7:"MANAGER";i:4;s:20:"Operasional & Keuang";i:5;s:6:"TELLER";}', 1), -(25, 'Tabungan', 'base/tabungan', '', 'base', 'tabungan', 4, 2, 'a:6:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:2:"CS";i:3;s:7:"MANAGER";i:4;s:9:"MARKETING";i:5;s:6:"TELLER";}', 1), -(26, 'Jaminan', 'base/jaminan', '', 'base', 'jaminan', 4, 3, 'a:6:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:2:"CS";i:3;s:7:"MANAGER";i:4;s:9:"MARKETING";i:5;s:6:"TELLER";}', 1), -(27, 'Pembiayaan', 'base/pembiayaan', '', 'base', 'pembiayaan', 4, 4, 'a:6:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:2:"CS";i:3;s:7:"MANAGER";i:4;s:20:"Operasional & Keuang";i:5;s:6:"TELLER";}', 1), -(28, 'Deposito', 'base/deposito', '', 'base', 'deposito', 4, 5, 'a:6:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:2:"CS";i:3;s:7:"MANAGER";i:4;s:20:"Operasional & Keuang";i:5;s:6:"TELLER";}', 1), -(29, 'Setor Tunai', 'setortunai', '', 'transaksiumum', 'setortunai', 5, 1, 'a:1:{i:0;s:6:"TELLER";}', 1), -(30, 'Tarik Tunai', 'tariktunai', '', 'transaksiumum', 'tariktunai', 5, 2, 'a:1:{i:0;s:6:"TELLER";}', 1), -(31, 'Setor Tunai Deposito', 'setordeposito', '', 'transaksiumum', 'setordeposito', 5, 3, 'a:1:{i:0;s:6:"TELLER";}', 1), -(32, 'Pencairan Deposito', 'pencairandeposito', '', 'transaksiumum', 'pencairandeposito', 5, 4, 'a:1:{i:0;s:6:"TELLER";}', 1), -(33, 'Pencairan Pembiayaan', 'pencairanpembiayaan', '', 'transaksiumum', 'pencairanpembiayaan', 5, 5, 'a:1:{i:0;s:6:"TELLER";}', 1), -(34, 'Setor Angsuran', 'angsuran', '', 'transaksiumum', 'angsuran', 5, 6, 'a:1:{i:0;s:6:"TELLER";}', 1), -(35, 'Laporan Mutasi', 'lapmutasi', '', 'transaksiumum', 'lapmutasi', 5, 7, 'a:1:{i:0;s:6:"TELLER";}', 1), -(36, 'Hapus Transaksi', 'hapustransaksi', '', 'transaksiumum', 'hapustransaksi', 5, 8, 'a:1:{i:0;s:6:"TELLER";}', 1), -(37, 'Kas keluar / masuk', 'trans/kaskeluarmasuk', '', 'transaksikas', 'kaskeluarmasuk', 6, 1, 'a:4:{i:0;s:5:"Admin";i:1;s:9:"AKUNTANSI";i:2;s:20:"Operasional & Keuang";i:3;s:6:"TELLER";}', 1), -(39, 'Selisih Kurang', 'trans/selisihkuranglebih', '', 'transaksikas', 'selisihkuranglebih', 6, 2, 'a:4:{i:0;s:5:"Admin";i:1;s:9:"AKUNTANSI";i:2;s:20:"Operasional & Keuang";i:3;s:6:"TELLER";}', 1), -(57, 'Report Transaksi', 'trans/reporttransaksi', '', 'transaksikas', 'reporttransaksi', 6, 4, 'a:3:{i:0;s:9:"AKUNTANSI";i:1;s:20:"Operasional & Keuang";i:2;s:6:"TELLER";}', 1), -(58, 'Plugin', '#', '', 'plugin', '', 0, 11, 'a:8:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSi";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:9:"MARKETING";i:6;s:20:"Operasional & Keuang";i:7;s:6:"TELLER";}', 1), -(59, 'Installed plugins', 'plugin/install', '', 'plugin', 'install', 58, 1, 'a:1:{i:0;s:5:"Admin";}', 1), -(73, 'Hello', '/plugin/view/main/hello', NULL, 'plugin', 'hello', 58, 1, 'a:1:{i:0;s:5:"Admin";}', 1), -(74, 'Migrasi', '/plugin/view/main/migrasi', NULL, 'plugin', 'migrasi', 58, 2, 'a:1:{i:0;s:5:"Admin";}', 1), -(61, 'Setting', 'javascript:;', '', 'setting', '', 0, 10, 'a:2:{i:0;s:5:"Admin";i:1;s:20:"Operasional & Keuang";}', 1), -(65, 'Tema tampilan', 'setting/theme', '', 'setting', 'theme', 61, 4, 'a:2:{i:0;s:5:"Admin";i:1;s:20:"Operasional & Keuang";}', 1), -(67, 'Tentang AKSIOMA', 'help', '', 'help', 'help', 66, 1, 'a:8:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSI";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:9:"MARKETING";i:6;s:20:"Operasional & Keuang";i:7;s:6:"TELLER";}', 1), -(68, 'Info Pegadaian Syariah', 'pegadaian', '', 'help', 'pegadaian', 66, 2, 'a:8:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSI";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:9:"MARKETING";i:6;s:20:"Operasional & Keuang";i:7;s:6:"TELLER";}', 1), -(45, 'Cetak Tabungan', 'monitor/cetaktabungan', '', 'monitor', 'cetaktabungan', 5, 9, 'a:3:{i:0;s:10:"ACCOUNTING";i:1;s:5:"Admin";i:2;s:6:"TELLER";}', 1), -(46, 'Aktivasi Tabungan', 'monitor/aktivasitabungan', '', 'monitor', 'aktivasitabungan', 4, 6, 'a:4:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:2:"CS";i:3;s:20:"Operasional & Keuang";}', 1), -(47, 'Tabungan', 'monitor/listtabungan', '', 'monitor', 'listtabungan', 8, 3, 'a:8:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSi";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:9:"MARKETING";i:6;s:20:"Operasional & Keuang";i:7;s:6:"TELLER";}', 1), -(48, 'Pembiayaan', 'monitor/pembiayaan', '', 'monitor', 'pembiayaan', 8, 4, 'a:8:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSi";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:9:"MARKETING";i:6;s:20:"Operasional & Keuang";i:7;s:6:"TELLER";}', 1), -(49, 'NPF', 'monitor/npf', '', 'monitor', 'npf', 8, 6, 'a:7:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSi";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:9:"MARKETING";i:6;s:20:"Operasional & Keuang";}', 1), -(63, 'Cetak tabungan', 'setting/cetaktabungan', '', 'setting', 'cetaktabungan', 61, 2, 'a:2:{i:0;s:5:"Admin";i:1;s:20:"Operasional & Keuang";}', 1), -(50, 'Deposito', 'monitor/deposito', '', 'monitor', 'deposito', 8, 5, 'a:8:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSi";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:9:"MARKETING";i:6;s:20:"Operasional & Keuang";i:7;s:6:"TELLER";}', 1), -(66, 'Bantuan', '#', '', 'help', '', 0, 12, 'a:8:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSI";i:3;s:2:"CS";i:4;s:7:"MANAGER";i:5;s:9:"MARKETING";i:6;s:20:"Operasional & Keuang";i:7;s:6:"TELLER";}', 1), -(51, 'Data cadangan', 'tool/backupdata', '', 'tools', 'backupdata', 9, 1, 'a:3:{i:0;s:5:"Admin";i:1;s:9:"AKUNTANSi";i:2;s:2:"CS";}', 1), -(52, 'Perhitungan Bagi Hasil', 'tool/hitungbasil', '', 'tools', 'hitungbasil', 9, 2, 'a:3:{i:0;s:5:"Admin";i:1;s:2:"CS";i:2;s:20:"Operasional & Keuang";}', 1), -(62, 'Logo', 'setting/logo', '', 'setting', 'logo', 61, 1, 'a:1:{i:0;s:5:"Admin";}', 1), -(54, 'Informasi Basil', '#', '', 'tools', 'informasibasil', 9, 3, 'a:1:{i:0;s:5:"Admin";}', 0), -(55, 'Kesehatan', '#', '', 'tools', 'kesehatan', 9, 4, 'a:1:{i:0;s:5:"Admin";}', 0), -(56, 'Kolektibilitas', 'param/kolektibilitas', '', 'param', 'kolektibilitas', 2, 11, 'a:3:{i:0;s:5:"Admin";i:1;s:7:"MANAGER";i:2;s:20:"Operasional & Keuang";}', 1), -(69, 'Report Teller', 'trans/reportteller', '', 'transaksikas', 'reportteller', 6, 5, 'a:4:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSI";i:3;s:6:"TELLER";}', 1), -(70, 'Transaksi Lain', 'trans/transaksilain', '', 'transaksikas', 'transaksilain', 6, 3, 'a:6:{i:0;s:9:"ADM LEGAL";i:1;s:5:"Admin";i:2;s:9:"AKUNTANSI";i:3;s:7:"MANAGER";i:4;s:9:"MARKETING";i:5;s:6:"TELLER";}', 1); - --- -------------------------------------------------------- - --- --- Table structure for table `pegawai` --- - -CREATE TABLE IF NOT EXISTS `pegawai` ( - `pegawai_id` int(11) NOT NULL AUTO_INCREMENT, - `nip` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `id_jabatan` int(11) DEFAULT NULL, - `nama_pegawai` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `nama_panggilan` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, - `tpt_lhr` varchar(50) COLLATE utf8_unicode_ci NOT NULL, - `tgl_lhr` date NOT NULL, - `jns_klmn` char(1) COLLATE utf8_unicode_ci NOT NULL, - `agama` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, - `status` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, - `alamat` text COLLATE utf8_unicode_ci, - `kota` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `telepon` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `pendidikan` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `noktp` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `keterangan` text COLLATE utf8_unicode_ci, - PRIMARY KEY (`pegawai_id`), - UNIQUE KEY `nip` (`nip`), - UNIQUE KEY `namapanggilan` (`nama_panggilan`), - KEY `FK_pegawai` (`id_jabatan`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=9 ; - --- --- Dumping data for table `pegawai` --- - -INSERT INTO `pegawai` (`pegawai_id`, `nip`, `id_jabatan`, `nama_pegawai`, `nama_panggilan`, `tpt_lhr`, `tgl_lhr`, `jns_klmn`, `agama`, `status`, `alamat`, `kota`, `telepon`, `pendidikan`, `noktp`, `keterangan`) VALUES -(1, 'ADM', 1, 'Admin', 'Admin', '-', '2009-07-31', '1', '1', '1', '-', '-', '', '', '-', ''), -(2, 'PEG002', 4, 'cs', 'csaaa', 'Bekasi', '2009-06-07', '1', '1', '2', 'Jl. Gelatik', 'Jkt', '', '', '32332.A.31232', 'OK DEH'), -(3, 'BBH0102001', 4, 'SAIDAH', 'SAIDAH', 'BEKASI', '1994-12-14', '2', '1', '1', 'Jl Muara Gembong', 'BEKASI', '', '', '1232134123', ''), -(5, 'PEG001', 5, 'teller', 'teller', 'Jakarta', '2009-01-07', '2', '1', '1', 'Jl. Jeruk', 'Jkt', '', '', '123.90.ABS', ''), -(6, 'PEG004', 2, 'adm', 'adm', 'Jakarta', '1980-08-09', '2', '1', '1', '-', '-', '', '', '32324324', ''), -(7, 'BBH0103001', 4, 'akunting', 'akunting', 'jakarta', '2015-05-26', '1', '1', '1', 'dsds', 'dwsds', '13432423', 'fdf', '4324324234', 'erwerw'), -(8, 'BBH0101001', 3, 'Manager', 'manager', 'jakarta', '2015-05-26', '1', '1', '1', 'adfsdf', 'dsfsdf', '331423432', 'sdfsfsfd', '2312312', 'vsdvfsd'); - --- -------------------------------------------------------- - --- --- Table structure for table `pendapatan` --- - -CREATE TABLE IF NOT EXISTS `pendapatan` ( - `pendapatan_id` int(11) NOT NULL AUTO_INCREMENT, - `kode` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `range_pendapatan` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`pendapatan_id`), - UNIQUE KEY `kode` (`kode`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=8 ; - --- --- Dumping data for table `pendapatan` --- - -INSERT INTO `pendapatan` (`pendapatan_id`, `kode`, `range_pendapatan`) VALUES -(1, '1', '>0 - 200.000'), -(2, '2', '>200.000 - 500.000'), -(3, '3', '>500.000 - 1.000.000'), -(4, '4', '>1.000.000 - 2.000.000'), -(5, '5', '>2.000.000 - 5.000.000'), -(6, '6', '>5.000.000 - 10.000.000'), -(7, '7', '>10.000.000'); - --- -------------------------------------------------------- - --- --- Table structure for table `plugin` --- - -CREATE TABLE IF NOT EXISTS `plugin` ( - `plugin_id` int(11) NOT NULL AUTO_INCREMENT, - `name_plugin` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `desc` text CHARACTER SET utf8 COLLATE utf8_unicode_ci, - `path` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `status` int(11) DEFAULT '0', - PRIMARY KEY (`plugin_id`), - UNIQUE KEY `name` (`name_plugin`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; - --- --- Dumping data for table `plugin` --- - -INSERT INTO `plugin` (`plugin_id`, `name_plugin`, `desc`, `path`, `status`) VALUES -(5, 'hello', 'hello', '/Users/edisuwoto/Documents/webdev/aksioma_1.0/assets/plugin/hello/', 1), -(6, 'migrasi', 'migrasi', '/Users/edisuwoto/Documents/webdev/aksioma_1.0/assets/plugin/migrasi/', 1); - --- -------------------------------------------------------- - --- --- Table structure for table `provinsi` --- - -CREATE TABLE IF NOT EXISTS `provinsi` ( - `namaProvinsi` varchar(100) COLLATE latin1_general_ci NOT NULL, - `kodeBPS` int(11) NOT NULL, - PRIMARY KEY (`kodeBPS`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; - --- --- Dumping data for table `provinsi` --- - -INSERT INTO `provinsi` (`namaProvinsi`, `kodeBPS`) VALUES -('NANGGROE ACEH DARUSSALAM', 11), -('SUMATERA UTARA', 12), -('SUMATERA BARAT', 13), -('RIAU', 14), -('JAMBI', 15), -('SUMATERA SELATAN', 16), -('BENGKULU', 17), -('LAMPUNG', 18), -('KEPULAUAN BANGKA BELITUNG', 19), -('KEPULAUAN RIAU', 21), -('DKI JAKARTA', 31), -('JAWA BARAT', 32), -('JAWA TENGAH', 33), -('DI YOGYAKARTA', 34), -('JAWA TIMUR', 35), -('BANTEN', 36), -('BALI', 51), -('NUSA TENGGARA BARAT', 52), -('NUSA TENGGARA TIMUR', 53), -('KALIMANTAN BARAT', 61), -('KALIMANTAN TENGAH', 62), -('KALIMANTAN SELATAN', 63), -('KALIMANTAN TIMUR', 64), -('SULAWESI UTARA', 71), -('SULAWESI TENGAH', 72), -('SULAWESI SELATAN', 73), -('SULAWESI TENGGARA', 74), -('GORONTALO', 75), -('SULAWESI BARAT', 76), -('MALUKU', 81), -('MALUKU UTARA', 82), -('PAPUA BARAT', 91), -('PAPUA', 94); - --- -------------------------------------------------------- - --- --- Table structure for table `sektor_pekerjaan` --- - -CREATE TABLE IF NOT EXISTS `sektor_pekerjaan` ( - `pekerjaan_id` int(11) NOT NULL AUTO_INCREMENT, - `kode` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nama` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`pekerjaan_id`), - UNIQUE KEY `kode` (`kode`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=11 ; - --- --- Dumping data for table `sektor_pekerjaan` --- - -INSERT INTO `sektor_pekerjaan` (`pekerjaan_id`, `kode`, `nama`) VALUES -(1, '1', 'PERTANIAN, KEHUTANAN, DAN SARANA PERTANIAN'), -(2, '2', 'PERTAMBANGAN'), -(3, '3', 'INDUSTRI PENGOLAHAN'), -(4, '4', 'LISTRIK, GAS, DAN AIR'), -(5, '5', 'KONSTRUKSI'), -(6, '6', 'PERDAGANGAN, RESTORAN, DAN HOTEL'), -(7, '7', 'PENGANGKUTAN, PERGUDANGAN, DAN KOMUNIKASI'), -(8, '8', 'JASA-JASA DUNIA USAHA'), -(9, '9', 'JASA-JASA SOSIAL/MASYARAKAT'), -(10, '10', 'LAIN-LAIN'); - --- -------------------------------------------------------- - --- --- Table structure for table `setting` --- - -CREATE TABLE IF NOT EXISTS `setting` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `logo` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set1` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set2` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set3` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set4` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set5` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set6` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set7` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set8` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set9` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set10` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set11` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `set12` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ; - --- --- Dumping data for table `setting` --- - -INSERT INTO `setting` (`id`, `logo`, `set1`, `set2`, `set3`, `set4`, `set5`, `set6`, `set7`, `set8`, `set9`, `set10`, `set11`, `set12`) VALUES -(1, 'assets/img/logoc.png', '10', '10', '5', '10', '5', '10', '10', '10', '10', '0.4', '25', '7'); - --- -------------------------------------------------------- - --- --- Table structure for table `setupapp` --- - -CREATE TABLE IF NOT EXISTS `setupapp` ( - `set_app_id` int(11) NOT NULL AUTO_INCREMENT, - `name_setup` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `value` text COLLATE utf8_unicode_ci, - PRIMARY KEY (`set_app_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=14 ; - --- --- Dumping data for table `setupapp` --- - -INSERT INTO `setupapp` (`set_app_id`, `name_setup`, `value`) VALUES -(1, 'tema', 'south-street'), -(2, 'temamenuorder', 'ui-darkness'), -(3, 'temadapurmakan', 'ui-darkness'), -(4, 'temadapurminum', 'ui-darkness'), -(5, 'temakasir', 'ui-darkness'), -(6, 'meja', '24'), -(7, 'limitperiode', '30'), -(8, 'pelayan', 'a:2:{i:0;a:2:{s:2:"id";s:1:"2";s:4:"nama";s:6:"waiter";}i:1;a:2:{s:2:"id";s:1:"3";s:4:"nama";s:7:"waiterx";}}'), -(9, 'outlet', 'Karaoke '), -(10, 'alamat', 'Roko Bekasi Regensi 1 No 12'), -(11, 'telp', '88335681'), -(12, 'fax', '88335681'), -(13, 'vkkasir', '1'); - --- -------------------------------------------------------- - --- --- Table structure for table `status_pekerjaan` --- - -CREATE TABLE IF NOT EXISTS `status_pekerjaan` ( - `status_id` int(11) NOT NULL AUTO_INCREMENT, - `kode` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nama` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`status_id`), - UNIQUE KEY `kode` (`kode`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ; - --- --- Dumping data for table `status_pekerjaan` --- - -INSERT INTO `status_pekerjaan` (`status_id`, `kode`, `nama`) VALUES -(1, '1', 'PEGAWAI TETAP'), -(2, '2', 'PEGAWAI KONTRAK'), -(3, '3', 'LAIN-LAIN'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_accounttemp` --- - -CREATE TABLE IF NOT EXISTS `tb_accounttemp` ( - `accounttrans_id` int(11) NOT NULL AUTO_INCREMENT, - `accounttrans_listid` int(11) NOT NULL, - `accounttrans_date` date NOT NULL, - `accounttrans_code` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `accounttrans_type` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `accounttrans_desc` varchar(50) COLLATE latin1_general_ci DEFAULT NULL, - `accounttrans_value` decimal(16,2) NOT NULL DEFAULT '0.00', - `accounttrans_curency` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - `accounttrans_posted` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - `accounttrans_direct` int(11) NOT NULL DEFAULT '0', - `accounttrans_ref` int(11) NOT NULL DEFAULT '0', - `accounttrans_user` int(11) NOT NULL, - `create_date` datetime NOT NULL, - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - PRIMARY KEY (`accounttrans_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=27 ; - --- --- Dumping data for table `tb_accounttemp` --- - -INSERT INTO `tb_accounttemp` (`accounttrans_id`, `accounttrans_listid`, `accounttrans_date`, `accounttrans_code`, `accounttrans_type`, `accounttrans_desc`, `accounttrans_value`, `accounttrans_curency`, `accounttrans_posted`, `accounttrans_direct`, `accounttrans_ref`, `accounttrans_user`, `create_date`, `create_by`, `last_update`, `update_by`) VALUES -(1, 568, '2015-07-13', '01-568', '02', 'setoran modal', 100000000.00, '0', '1', 0, 0, 0, '2015-07-13 13:16:23', 'admin', '2015-07-13 20:16:23', 'admin'), -(2, 264, '2015-07-13', '01-264', '01', 'setoran modal', 100000000.00, '0', '1', 0, 0, 0, '2015-07-13 13:16:23', 'admin', '2015-07-13 20:16:23', 'admin'), -(3, 416, '2015-07-13', '02-416', '01', 'pendapatan adm', 50000.00, '0', '1', 0, 0, 0, '2015-07-13 13:20:23', 'admin', '2015-07-13 20:20:23', 'admin'), -(4, 568, '2015-07-13', '02-568', '02', 'pendapatan adm', 50000.00, '0', '1', 0, 0, 0, '2015-07-13 13:20:23', 'admin', '2015-07-13 20:20:23', 'admin'), -(26, 476, '2015-09-02', '888-476', '01', 'saldo', 1.00, '0', '0', 0, 0, 0, '2015-09-02 12:59:34', 'admin', '2015-09-02 19:59:34', 'admin'), -(25, 20, '2015-09-02', '888-20', '02', 'saldo', 1.00, '0', '0', 0, 0, 0, '2015-09-02 12:59:34', 'admin', '2015-09-02 19:59:34', 'admin'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_accounttrans` --- - -CREATE TABLE IF NOT EXISTS `tb_accounttrans` ( - `accounttrans_id` int(11) NOT NULL AUTO_INCREMENT, - `accounttrans_listid` int(11) NOT NULL, - `accounttrans_date` date NOT NULL, - `accounttrans_code` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `accounttrans_type` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `accounttrans_desc` varchar(50) COLLATE latin1_general_ci DEFAULT NULL, - `accounttrans_value` decimal(16,2) NOT NULL DEFAULT '0.00', - `accounttrans_curency` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - `accounttrans_direct` int(11) NOT NULL DEFAULT '0', - `accounttrans_ref` int(11) NOT NULL DEFAULT '0', - `accounttrans_user` int(11) NOT NULL, - `create_date` datetime NOT NULL, - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - PRIMARY KEY (`accounttrans_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ; - --- --- Dumping data for table `tb_accounttrans` --- - -INSERT INTO `tb_accounttrans` (`accounttrans_id`, `accounttrans_listid`, `accounttrans_date`, `accounttrans_code`, `accounttrans_type`, `accounttrans_desc`, `accounttrans_value`, `accounttrans_curency`, `accounttrans_direct`, `accounttrans_ref`, `accounttrans_user`, `create_date`, `create_by`, `last_update`, `update_by`) VALUES -(1, 568, '2015-07-13', '01-568', '02', 'setoran modal', 100000000.00, '0', 0, 0, 0, '2015-07-13 13:16:43', 'admin', '2015-07-13 20:16:43', 'admin'), -(2, 264, '2015-07-13', '01-264', '01', 'setoran modal', 100000000.00, '0', 0, 0, 0, '2015-07-13 13:16:43', 'admin', '2015-07-13 20:16:43', 'admin'), -(3, 416, '2015-07-13', '02-416', '01', 'pendapatan adm', 50000.00, '0', 0, 0, 0, '2015-07-13 13:20:36', 'admin', '2015-07-13 20:20:36', 'admin'), -(4, 568, '2015-07-13', '02-568', '02', 'pendapatan adm', 50000.00, '0', 0, 0, 0, '2015-07-13 13:20:36', 'admin', '2015-07-13 20:20:36', 'admin'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_akunpendapatan` --- - -CREATE TABLE IF NOT EXISTS `tb_akunpendapatan` ( - `akunpendapatan_id` int(11) NOT NULL AUTO_INCREMENT, - `kelompok` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `nama_produk` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `akun` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - PRIMARY KEY (`akunpendapatan_id`), - UNIQUE KEY `produk` (`nama_produk`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ; - --- --- Dumping data for table `tb_akunpendapatan` --- - -INSERT INTO `tb_akunpendapatan` (`akunpendapatan_id`, `kelompok`, `nama_produk`, `akun`) VALUES -(1, 'PENDAPATAN', 'PIUTANG MURABAHAH', '288'), -(2, 'PENDAPATAN', 'PEMBIAYAAN MUDHARABAH', '315'), -(4, 'PENDAPATAN', 'PEMBIAYAAN MUSYAROKAH', '319'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_akunperhimpunan` --- - -CREATE TABLE IF NOT EXISTS `tb_akunperhimpunan` ( - `perhimpunan_id` int(11) NOT NULL AUTO_INCREMENT, - `kelompok` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `nama_produk` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `akun` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - PRIMARY KEY (`perhimpunan_id`), - UNIQUE KEY `produk` (`nama_produk`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=6 ; - --- --- Dumping data for table `tb_akunperhimpunan` --- - -INSERT INTO `tb_akunperhimpunan` (`perhimpunan_id`, `kelompok`, `nama_produk`, `akun`) VALUES -(1, 'SIMPANAN & INVESTASI BERJANGKA', 'TITIPAN ANGGOTA', '203'), -(2, 'SIMPANAN & INVESTASI BERJANGKA', 'INVESTASI 1 BL', '257'), -(3, 'SIMPANAN & INVESTASI BERJANGKA', 'INVESTASI 3 BL', '258'), -(4, 'SIMPANAN & INVESTASI BERJANGKA', 'INVESTASI 6 BL', '259'), -(5, ' SIMPANAN & INVESTASI BERJANGKA', 'INVESTASI 12 BL', '260'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_basil` --- - -CREATE TABLE IF NOT EXISTS `tb_basil` ( - `basil_id` int(11) NOT NULL AUTO_INCREMENT, - `start_date` date NOT NULL, - `end_date` date NOT NULL, - `basil_code` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `basil_type` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `basil_ref` int(11) NOT NULL, - `basil_rek` varchar(50) COLLATE latin1_general_ci DEFAULT NULL, - `basil_value` decimal(16,2) NOT NULL DEFAULT '0.00', - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `status` int(11) NOT NULL, - PRIMARY KEY (`basil_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ; - --- --- Dumping data for table `tb_basil` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `tb_basiltrans` --- - -CREATE TABLE IF NOT EXISTS `tb_basiltrans` ( - `basiltrans_id` int(11) NOT NULL AUTO_INCREMENT, - `tanggal` date NOT NULL, - `start_date` date NOT NULL, - `end_date` date NOT NULL, - `basiltrans_code` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `basiltrans_type` int(11) NOT NULL, - `kode_produk` int(11) NOT NULL, - `basiltrans_rek` varchar(50) COLLATE latin1_general_ci DEFAULT NULL, - `basiltrans_value` decimal(16,2) NOT NULL DEFAULT '0.00', - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `status` int(11) NOT NULL, - PRIMARY KEY (`basiltrans_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ; - --- --- Dumping data for table `tb_basiltrans` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `tb_basilwadiah` --- - -CREATE TABLE IF NOT EXISTS `tb_basilwadiah` ( - `basilwadiah_id` int(11) NOT NULL AUTO_INCREMENT, - `tanggal` date NOT NULL, - `start_date` date NOT NULL, - `end_date` date NOT NULL, - `basilwadiah_rek` varchar(50) COLLATE latin1_general_ci DEFAULT NULL, - `basilwadiah_type` int(11) NOT NULL, - `basilwadiah_code` int(11) NOT NULL, - `basilwadiah_value` decimal(16,2) NOT NULL DEFAULT '0.00', - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `status` int(11) NOT NULL, - PRIMARY KEY (`basilwadiah_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ; - --- --- Dumping data for table `tb_basilwadiah` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `tb_deposito` --- - -CREATE TABLE IF NOT EXISTS `tb_deposito` ( - `deposito_id` int(11) NOT NULL AUTO_INCREMENT, - `tgl_dibuka` date NOT NULL, - `nomor_rekening` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_ref` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_nasabah` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nama_produk` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_bilyet` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nominal` decimal(16,2) NOT NULL, - `jatuh_tempo` date NOT NULL, - `jenis_relasi` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `sumber_dana` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `administrasi` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `dijaminkan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `pph` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `pencairan` varchar(25) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - `aro` varchar(25) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - `zakat` varchar(25) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - `nisbah_tambahan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `basil_tunai` varchar(25) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - `rekening_basil` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - PRIMARY KEY (`deposito_id`), - UNIQUE KEY `nomorrekening` (`nomor_rekening`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ; - --- --- Dumping data for table `tb_deposito` --- - -INSERT INTO `tb_deposito` (`deposito_id`, `tgl_dibuka`, `nomor_rekening`, `nomor_ref`, `nomor_nasabah`, `nama_produk`, `nomor_bilyet`, `nominal`, `jatuh_tempo`, `jenis_relasi`, `sumber_dana`, `administrasi`, `dijaminkan`, `pph`, `pencairan`, `aro`, `zakat`, `nisbah_tambahan`, `basil_tunai`, `rekening_basil`, `create_by`, `last_update`, `update_by`, `status`) VALUES -(1, '2015-07-13', '110100001', '', '01000001', '11', '', 0.00, '2015-08-01', NULL, '', '', '', '', '0', '0', '', '', '0', '', 'admin', '2015-07-13 20:09:58', 'admin', '0'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_jaminan` --- - -CREATE TABLE IF NOT EXISTS `tb_jaminan` ( - `jaminan_id` int(11) NOT NULL AUTO_INCREMENT, - `nomor_jaminan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_rekening` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `Jenis_jaminan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `rekening_tab_deposito` varchar(30) COLLATE latin1_general_ci NOT NULL, - `pemilik` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `no_rek_bpkb_sert` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `stnk_hgb` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `luas_tanah` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `lain_lain` varchar(200) COLLATE latin1_general_ci NOT NULL, - `nilai_jaminan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `inspeksi_terakhir` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `inspeksi_oleh` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `keterangan` text COLLATE latin1_general_ci, - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - PRIMARY KEY (`jaminan_id`), - UNIQUE KEY `nomorjaminan` (`nomor_jaminan`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ; - --- --- Dumping data for table `tb_jaminan` --- - -INSERT INTO `tb_jaminan` (`jaminan_id`, `nomor_jaminan`, `nomor_rekening`, `Jenis_jaminan`, `rekening_tab_deposito`, `pemilik`, `no_rek_bpkb_sert`, `stnk_hgb`, `luas_tanah`, `lain_lain`, `nilai_jaminan`, `inspeksi_terakhir`, `inspeksi_oleh`, `keterangan`, `create_by`, `last_update`, `update_by`, `status`) VALUES -(1, '01000001', '410100001', '02', '110100001', '', '', '', '', '', '2000000', '', '', '', 'admin', '2015-07-13 20:13:51', 'admin', '0'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_nasabah` --- - -CREATE TABLE IF NOT EXISTS `tb_nasabah` ( - `nasabah_id` int(11) NOT NULL AUTO_INCREMENT, - `code_wilayah` varchar(11) COLLATE latin1_general_ci DEFAULT NULL, - `tgl_masuk` date NOT NULL, - `nomor_nasabah` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nama` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nama_pangilan` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `tempat_lahir` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `tanggal_lahir` date NOT NULL, - `jenis_kelamin` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `agama` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `pendidikan` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nama_ibu_kandung` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `status_marital` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `nama_istri_suami` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `jumlah_anak` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `jenis_identitas` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `nomor_identitas` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `berlaku_identitas` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `warga_negara` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nama_waris` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `hubungan_waris` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `jenis_identitas_waris` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_identitas_waris` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `berlaku_identitas_waris` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `alamat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `rtrw` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `propinsi` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kabupaten` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kecamatan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kode_pos` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `telpon_rumah` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `telpon_kantor` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `hp` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `email` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nama_perusahaan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `bidang_pekerjaan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `alamat_pekerjaan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `propinsi_pekerjaan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kabupaten_pekerjaan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kecamatan_pekerjaan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kode_pos_pekerjaan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `atasan_langsung` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `posisi_jabatan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `status_pekerjaan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `penghasilan_tetap` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `penghasilan_tamb` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `bidang_usaha` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `usaha_saldoratarata` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `usaha_jlhkaryawan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `usaha_pendapatanpertahun` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `usaha_pemilik` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `alamat_usaha` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `propinsi_usaha` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kabupaten_usaha` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kecamatan_usaha` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kode_pos_usaha` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nama_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `hubungan_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `alamat_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `rtrw_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `propinsi_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kabupaten_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kecamatan_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `kode_pos_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `telpon_rumah_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `telpon_kantor_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `hp_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `email_kerabat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - PRIMARY KEY (`nasabah_id`), - UNIQUE KEY `nomornasabah` (`nomor_nasabah`), - KEY `FK_wilayah` (`code_wilayah`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ; - --- --- Dumping data for table `tb_nasabah` --- - -INSERT INTO `tb_nasabah` (`nasabah_id`, `code_wilayah`, `tgl_masuk`, `nomor_nasabah`, `nama`, `nama_pangilan`, `tempat_lahir`, `tanggal_lahir`, `jenis_kelamin`, `agama`, `pendidikan`, `nama_ibu_kandung`, `status_marital`, `nama_istri_suami`, `jumlah_anak`, `jenis_identitas`, `nomor_identitas`, `berlaku_identitas`, `warga_negara`, `nama_waris`, `hubungan_waris`, `jenis_identitas_waris`, `nomor_identitas_waris`, `berlaku_identitas_waris`, `alamat`, `rtrw`, `propinsi`, `kabupaten`, `kecamatan`, `kode_pos`, `telpon_rumah`, `telpon_kantor`, `hp`, `email`, `nama_perusahaan`, `bidang_pekerjaan`, `alamat_pekerjaan`, `propinsi_pekerjaan`, `kabupaten_pekerjaan`, `kecamatan_pekerjaan`, `kode_pos_pekerjaan`, `atasan_langsung`, `posisi_jabatan`, `status_pekerjaan`, `penghasilan_tetap`, `penghasilan_tamb`, `bidang_usaha`, `usaha_saldoratarata`, `usaha_jlhkaryawan`, `usaha_pendapatanpertahun`, `usaha_pemilik`, `alamat_usaha`, `propinsi_usaha`, `kabupaten_usaha`, `kecamatan_usaha`, `kode_pos_usaha`, `nama_kerabat`, `hubungan_kerabat`, `alamat_kerabat`, `rtrw_kerabat`, `propinsi_kerabat`, `kabupaten_kerabat`, `kecamatan_kerabat`, `kode_pos_kerabat`, `telpon_rumah_kerabat`, `telpon_kantor_kerabat`, `hp_kerabat`, `email_kerabat`, `create_by`, `last_update`, `update_by`, `status`) VALUES -(1, '01', '2015-07-13', '01000001', 'Edi SUwoto', 'Edi', 'Bojonegoro', '1979-07-16', '1', '1', '1', '', '1', '', '', '1', '', '', '1', '', '0', '1', '', '', '', '', '0', NULL, NULL, '', '', '', '', '', '', '0', '', '0', NULL, NULL, '', '', '', '0', '0', '0', '0', '', '', '', '', '', '0', NULL, NULL, '', '', '0', '', '', '0', NULL, NULL, '', '', '', '', '', 'admin', '2015-07-13 20:05:20', 'admin', '0'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_pembiayaan` --- - -CREATE TABLE IF NOT EXISTS `tb_pembiayaan` ( - `pembiayaan_id` int(11) NOT NULL AUTO_INCREMENT, - `tgl_dibuka` date NOT NULL, - `nomor_rekening` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_ao` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_nasabah` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_jaminan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_akad` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `tgl_akad` date NOT NULL, - `jatuh_tempo` date NOT NULL, - `jenis_pembiayaan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `jumlah_pengajuan` double DEFAULT NULL, - `modal` double DEFAULT NULL, - `nisbah_bank` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nisbah_nasabah` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `pinjaman` double NOT NULL, - `harga_pokok` double DEFAULT '0', - `marjin` double DEFAULT '0', - `harga_jual` double DEFAULT '0', - `uang_muka` double DEFAULT NULL, - `lama_angsuran` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `type_angsuran` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `mulai_angsuran` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `selesai_angsuran` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `biaya_adm` double DEFAULT NULL, - `biaya_materai` double DEFAULT NULL, - `peruntukan_pembiayaan` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `keterangan` text COLLATE latin1_general_ci, - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - PRIMARY KEY (`pembiayaan_id`), - UNIQUE KEY `nomorrekening` (`nomor_rekening`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ; - --- --- Dumping data for table `tb_pembiayaan` --- - -INSERT INTO `tb_pembiayaan` (`pembiayaan_id`, `tgl_dibuka`, `nomor_rekening`, `nomor_ao`, `nomor_nasabah`, `nomor_jaminan`, `nomor_akad`, `tgl_akad`, `jatuh_tempo`, `jenis_pembiayaan`, `jumlah_pengajuan`, `modal`, `nisbah_bank`, `nisbah_nasabah`, `pinjaman`, `harga_pokok`, `marjin`, `harga_jual`, `uang_muka`, `lama_angsuran`, `type_angsuran`, `mulai_angsuran`, `selesai_angsuran`, `biaya_adm`, `biaya_materai`, `peruntukan_pembiayaan`, `keterangan`, `create_by`, `last_update`, `update_by`, `status`) VALUES -(1, '2015-07-13', '410100001', 'PEG001', '01000001', NULL, '', '0000-00-00', '2015-11-02', '41', 2000000, 0, '', '', 0, 2000000, 200000, 2200000, 0, '16', 'MINGGU', '2015-07-13', '', NULL, NULL, NULL, NULL, 'admin', '2015-07-13 20:12:57', 'admin', '0'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_pembiayaandetail` --- - -CREATE TABLE IF NOT EXISTS `tb_pembiayaandetail` ( - `pembiayaandetail_id` int(11) NOT NULL AUTO_INCREMENT, - `id_pembiayaan` int(11) NOT NULL, - `tgl_angsuran` date NOT NULL, - `pokok` decimal(16,2) DEFAULT NULL, - `margin` decimal(16,2) DEFAULT NULL, - `jumlah` decimal(16,2) DEFAULT NULL, - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - PRIMARY KEY (`pembiayaandetail_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=17 ; - --- --- Dumping data for table `tb_pembiayaandetail` --- - -INSERT INTO `tb_pembiayaandetail` (`pembiayaandetail_id`, `id_pembiayaan`, `tgl_angsuran`, `pokok`, `margin`, `jumlah`, `create_by`, `last_update`, `update_by`, `status`) VALUES -(1, 1, '2015-07-19', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(2, 1, '2015-07-26', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(3, 1, '2015-08-02', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(4, 1, '2015-08-09', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(5, 1, '2015-08-16', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(6, 1, '2015-08-23', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(7, 1, '2015-08-30', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(8, 1, '2015-09-06', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(9, 1, '2015-09-13', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(10, 1, '2015-09-20', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(11, 1, '2015-09-27', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(12, 1, '2015-10-04', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(13, 1, '2015-10-11', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(14, 1, '2015-10-18', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(15, 1, '2015-10-25', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'), -(16, 1, '2015-11-01', 125000.00, 12500.00, 137500.00, 'admin', '2015-07-13 20:12:57', 'admin', '0'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_pph` --- - -CREATE TABLE IF NOT EXISTS `tb_pph` ( - `pph_id` int(11) NOT NULL AUTO_INCREMENT, - `tanggal` date NOT NULL, - `pph_rek` varchar(50) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL, - `pph_value` decimal(16,2) NOT NULL DEFAULT '0.00', - `create_by` varchar(20) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `status` int(11) NOT NULL, - PRIMARY KEY (`pph_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; - --- --- Dumping data for table `tb_pph` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `tb_tabungan` --- - -CREATE TABLE IF NOT EXISTS `tb_tabungan` ( - `tabungan_id` int(11) NOT NULL AUTO_INCREMENT, - `tgl_dibuka` date NOT NULL, - `nomor_rekening` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_fo` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_nasabah` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `jenis_simpanan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `sumber_dana` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `tujuan_pembukaan` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `zakat` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `administrasi` varchar(20) COLLATE latin1_general_ci DEFAULT NULL, - `pph` varchar(20) COLLATE latin1_general_ci NOT NULL, - `dijaminkan` varchar(10) COLLATE latin1_general_ci NOT NULL, - `blockir` varchar(30) COLLATE latin1_general_ci NOT NULL, - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - PRIMARY KEY (`tabungan_id`), - UNIQUE KEY `nomorrekening` (`nomor_rekening`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ; - --- --- Dumping data for table `tb_tabungan` --- - -INSERT INTO `tb_tabungan` (`tabungan_id`, `tgl_dibuka`, `nomor_rekening`, `nomor_fo`, `nomor_nasabah`, `jenis_simpanan`, `sumber_dana`, `tujuan_pembukaan`, `zakat`, `administrasi`, `pph`, `dijaminkan`, `blockir`, `create_by`, `last_update`, `update_by`, `status`) VALUES -(1, '2015-07-13', '210100001', 'PEG001', '01000001', '21', '', '', '', '', '', 'TIDAK', 'Unblock', 'admin', '2015-07-13 20:06:44', 'admin', '0'); - --- -------------------------------------------------------- - --- --- Table structure for table `tb_tabunganriwayat` --- - -CREATE TABLE IF NOT EXISTS `tb_tabunganriwayat` ( - `tabunganriwayat_id` int(11) NOT NULL AUTO_INCREMENT, - `tgl_proses` date NOT NULL, - `nomor_rekening` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `nomor_ref` varchar(35) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `alasan` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `create_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `update_by` varchar(20) COLLATE latin1_general_ci NOT NULL, - `active` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - PRIMARY KEY (`tabunganriwayat_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2 ; - --- --- Dumping data for table `tb_tabunganriwayat` --- - - --- -------------------------------------------------------- - --- --- Table structure for table `tb_zakat` --- - -CREATE TABLE IF NOT EXISTS `tb_zakat` ( - `zakat_id` int(11) NOT NULL AUTO_INCREMENT, - `tanggal` date NOT NULL, - `start_date` date NOT NULL, - `end_date` date NOT NULL, - `zakat_rek` varchar(50) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL, - `zakat_value` decimal(16,2) NOT NULL DEFAULT '0.00', - `create_by` varchar(20) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL, - `last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `status` int(11) NOT NULL, - PRIMARY KEY (`zakat_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; - --- --- Dumping data for table `tb_zakat` --- - -INSERT INTO `tb_zakat` (`zakat_id`, `tanggal`, `start_date`, `end_date`, `zakat_rek`, `zakat_value`, `create_by`, `last_update`, `status`) VALUES -(1, '2015-06-23', '0000-00-00', '0000-00-00', '210100001', 277.78, 'admin', '2015-06-23 20:10:58', 0); - --- -------------------------------------------------------- - --- --- Table structure for table `users` --- - -CREATE TABLE IF NOT EXISTS `users` ( - `user_id` int(11) NOT NULL AUTO_INCREMENT, - `id_group` int(11) DEFAULT NULL, - `username` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `password` tinytext COLLATE utf8_unicode_ci, - `id_pegawai` int(11) DEFAULT NULL, - `terdaftar` datetime DEFAULT NULL, - `last_login` datetime DEFAULT NULL, - `from_host` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `active` tinyint(1) DEFAULT NULL, - PRIMARY KEY (`user_id`), - UNIQUE KEY `username` (`username`), - KEY `FK_users` (`id_group`), - KEY `FK_users_peg` (`id_pegawai`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=15 ; - --- --- Dumping data for table `users` --- - -INSERT INTO `users` (`user_id`, `id_group`, `username`, `password`, `id_pegawai`, `terdaftar`, `last_login`, `from_host`, `active`) VALUES -(1, 1, 'admin', 'BFPAJAhhiwq+SKLkVzs75ZfOZ9UUj0g7sgAf6zpjbxaOIxm58Q/ai2djVLmq6jkJTDxJoUljWIjjNI5IBnapcw==', 1, '2009-06-17 23:17:11', '2016-06-20 12:41:52', 'localhost', 1), -(5, 3, 'teller', 'sWC4ILjmFzdaQG934qKOnv/hO0EhHdc+pb9KHyCq6sbo5pnfnmtZPr+3WpwTt+MpN2gogaaSjefoLY47ytMNqg==', 5, '2009-07-10 22:40:32', '2016-06-20 12:34:46', 'localhost', 1), -(6, 8, 'adm', 'DxifgckI1uiEaEmPVTvLRNC4PzHyORmiCHX1Ay77ScT/ifxKN7v5ytlQ3yo6Pgrm/D2WeARVnTOjvZL87AHNWg==', 6, '2009-07-11 23:27:11', '2010-12-01 11:11:24', 'edi-PC', 1), -(9, 9, 'operasional', 'jmroNg974d2zQJIt/A6KMEJUWTAgwbruRiziYrQ39I8v6h2Cf5H/6jdBt49R0+WOcNra64f993HMMB5yVU4sVw==', 3, '2014-12-22 21:10:52', '2015-05-26 11:10:02', 'localhost', 1), -(10, 4, 'NASIR', 'RuMHiGf/6OGnyW6kCd8pw3ic0QN7FZTCEAI85/TaHuQ/nFmeiCszLh4vKY2GW+JvNMy64/u9JOhMSOThW67aiQ==', 0, '2015-03-28 23:42:43', '0000-00-00 00:00:00', '-', 1), -(11, 10, 'akunting', '6O4na2526oKEp/PsD321/dmzxdhJwTE9Pr2lcVJ9VkiO/xhQVfBIkF7uYIHrLlNXdPi1e9hiy3yrU+xVEa75Rg==', 0, '2015-05-26 08:32:31', '0000-00-00 00:00:00', '-', 1), -(12, 10, 'akuntansi', 'DXWM4UizQuygsKGyTPItz9SvSd5LI8aSVDQCFIIgjWMYPCO1rpHAIrNRjvT6Vuz9u8b5ibz+KmDu53RDj3PnOQ==', 7, '2015-05-26 09:08:23', '2016-06-20 12:25:53', 'localhost', 1), -(13, 11, 'manager', 'yUe6e5OkbUdFZqO9GmqkwEfPKjcA0TQCEiofooLa4YUl1urfdUYJjZmOj1ChB6q+rj4IIqQd3HzCYKKb/p8uNw==', 8, '2015-05-26 09:13:27', '2015-05-26 09:22:09', 'WIE_ADLAN-PC', 1), -(14, 5, 'cs', 'aw8LGtGg7tVZv8DeOgxr2gUd7wf6N0t0WYZ5Nl2tA4fwYq6iVZDuJjyAJlNjgZG9D1iWa2tm5J1A+nLqlcs8Hg==', 2, '2015-05-26 09:20:45', '2015-05-26 10:55:03', 'localhost', 1); diff --git a/index.php b/index.php old mode 100755 new mode 100644 index 1b4d197..7b31be4 --- a/index.php +++ b/index.php @@ -1,119 +1,266 @@ =')) { + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); + } else { + error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); + } + break; + + default: + header('HTTP/1.1 503 Service Unavailable.', true, 503); + echo 'The application environment is not set correctly.'; + exit(1); // EXIT_ERROR +} /* -|--------------------------------------------------------------- -| APPLICATION FOLDER NAME -|--------------------------------------------------------------- -| -| If you want this front controller to use a different "application" -| folder then the default one you can set its name here. The folder -| can also be renamed or relocated anywhere on your server. -| For more info please see the user guide: -| http://codeigniter.com/user_guide/general/managing_apps.html -| -| -| NO TRAILING SLASH! -| -*/ - $application_folder = "application"; + *--------------------------------------------------------------- + * SYSTEM FOLDER NAME + *--------------------------------------------------------------- + * + * This variable must contain the name of your "system" folder. + * Include the path if the folder is not in the same directory + * as this file. + */ + $system_path = 'system'; /* -|=============================================================== -| END OF USER CONFIGURABLE SETTINGS -|=============================================================== -*/ + *--------------------------------------------------------------- + * APPLICATION FOLDER NAME + *--------------------------------------------------------------- + * + * If you want this front controller to use a different "application" + * folder than the default one you can set its name here. The folder + * can also be renamed or relocated anywhere on your server. If + * you do, use a full server path. For more info please see the user guide: + * http://codeigniter.com/user_guide/general/managing_apps.html + * + * NO TRAILING SLASH! + */ + $application_folder = 'application'; +/* + *--------------------------------------------------------------- + * VIEW FOLDER NAME + *--------------------------------------------------------------- + * + * If you want to move the view folder out of the application + * folder set the path to the folder here. The folder can be renamed + * and relocated anywhere on your server. If blank, it will default + * to the standard location inside your application folder. If you + * do move this, use the full server path to this folder. + * + * NO TRAILING SLASH! + */ + $view_folder = ''; /* -|--------------------------------------------------------------- -| SET THE SERVER PATH -|--------------------------------------------------------------- -| -| Let's attempt to determine the full-server path to the "system" -| folder in order to reduce the possibility of path problems. -| Note: We only attempt this if the user hasn't specified a -| full server path. -| -*/ -if (strpos($system_folder, '/') === FALSE) -{ - if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE) - { - $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder; - } -} -else -{ - // Swap directory separators to Unix style for consistency - $system_folder = str_replace("\\", "/", $system_folder); -} + * -------------------------------------------------------------------- + * DEFAULT CONTROLLER + * -------------------------------------------------------------------- + * + * Normally you will set your default controller in the routes.php file. + * You can, however, force a custom routing by hard-coding a + * specific controller class/function here. For most applications, you + * WILL NOT set your routing here, but it's an option for those + * special instances where you might want to override the standard + * routing in a specific front controller that shares a common CI installation. + * + * IMPORTANT: If you set the routing here, NO OTHER controller will be + * callable. In essence, this preference limits your application to ONE + * specific controller. Leave the function name blank if you need + * to call functions dynamically via the URI. + * + * Un-comment the $routing array below to use this feature + */ + // The directory name, relative to the "controllers" folder. Leave blank + // if your controller is not in a sub-folder within the "controllers" folder + // $routing['directory'] = ''; + + // The controller class file name. Example: mycontroller + // $routing['controller'] = ''; + + // The controller function you wish to be called. + // $routing['function'] = ''; /* -|--------------------------------------------------------------- -| DEFINE APPLICATION CONSTANTS -|--------------------------------------------------------------- -| -| EXT - The file extension. Typically ".php" -| FCPATH - The full server path to THIS file -| SELF - The name of THIS file (typically "index.php") -| BASEPATH - The full server path to the "system" folder -| APPPATH - The full server path to the "application" folder -| -*/ -define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION)); -define('FCPATH', __FILE__); -define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); -define('BASEPATH', $system_folder.'/'); - -if (is_dir($application_folder)) -{ - define('APPPATH', $application_folder.'/'); -} -else -{ - if ($application_folder == '') - { - $application_folder = 'application'; - } - - define('APPPATH', BASEPATH.$application_folder.'/'); -} + * ------------------------------------------------------------------- + * CUSTOM CONFIG VALUES + * ------------------------------------------------------------------- + * + * The $assign_to_config array below will be passed dynamically to the + * config class when initialized. This allows you to set custom config + * items or override any default config values found in the config.php file. + * This can be handy as it permits you to share one application between + * multiple front controller files, with each file containing different + * config values. + * + * Un-comment the $assign_to_config array below to use this feature + */ + // $assign_to_config['name_of_config_item'] = 'value of config item'; + +// -------------------------------------------------------------------- +// END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE +// -------------------------------------------------------------------- + +/* + * --------------------------------------------------------------- + * Resolve the system path for increased reliability + * --------------------------------------------------------------- + */ + + // Set the current directory correctly for CLI requests + if (defined('STDIN')) { + chdir(dirname(__FILE__)); + } + + if (($_temp = realpath($system_path)) !== false) { + $system_path = $_temp.'/'; + } else { + // Ensure there's a trailing slash + $system_path = rtrim($system_path, '/').'/'; + } + + // Is the system path correct? + if (!is_dir($system_path)) { + header('HTTP/1.1 503 Service Unavailable.', true, 503); + echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME); + exit(3); // EXIT_CONFIG + } + +/* + * ------------------------------------------------------------------- + * Now that we know the path, set the main path constants + * ------------------------------------------------------------------- + */ + // The name of THIS file + define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); + + // Path to the system folder + define('BASEPATH', str_replace('\\', '/', $system_path)); + + // Path to the front controller (this file) + define('FCPATH', dirname(__FILE__).'/'); + + // Name of the "system folder" + define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/')); + + // The path to the "application" folder + if (is_dir($application_folder)) { + if (($_temp = realpath($application_folder)) !== false) { + $application_folder = $_temp; + } + + define('APPPATH', $application_folder.DIRECTORY_SEPARATOR); + } else { + if (!is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR)) { + header('HTTP/1.1 503 Service Unavailable.', true, 503); + echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.self; + exit(3); // EXIT_CONFIG + } + + define('APPPATH', BASEPATH.$application_folder.DIRECTORY_SEPARATOR); + } + + // The path to the "views" folder + if (!is_dir($view_folder)) { + if (!empty($view_folder) && is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR)) { + $view_folder = APPPATH.$view_folder; + } elseif (!is_dir(APPPATH.'views'.DIRECTORY_SEPARATOR)) { + header('HTTP/1.1 503 Service Unavailable.', true, 503); + echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.self; + exit(3); // EXIT_CONFIG + } else { + $view_folder = APPPATH.'views'; + } + } + + if (($_temp = realpath($view_folder)) !== false) { + $view_folder = $_temp.DIRECTORY_SEPARATOR; + } else { + $view_folder = rtrim($view_folder, '/\\').DIRECTORY_SEPARATOR; + } + + define('VIEWPATH', $view_folder); /* -|--------------------------------------------------------------- -| LOAD THE FRONT CONTROLLER -|--------------------------------------------------------------- -| -| And away we go... -| -*/ -require_once BASEPATH.'codeigniter/CodeIgniter'.EXT; - -/* End of file index.php */ -/* Location: ./index.php */ + * -------------------------------------------------------------------- + * LOAD THE BOOTSTRAP FILE + * -------------------------------------------------------------------- + * + * And away we go... + */ +date_default_timezone_set('Asia/Jakarta'); +require_once BASEPATH.'core/CodeIgniter.php'; diff --git a/license.txt b/license.txt old mode 100755 new mode 100644 index 4cc6551..b8b0825 --- a/license.txt +++ b/license.txt @@ -1,52 +1,21 @@ -Copyright (c) 2008, EllisLab, Inc. -All rights reserved. - -This license is a legal agreement between you and EllisLab Inc. for the use -of CodeIgniter Software (the "Software"). By obtaining the Software you -agree to comply with the terms and conditions of this license. - -PERMITTED USE -You are permitted to use, copy, modify, and distribute the Software and its -documentation, with or without modification, for any purpose, provided that -the following conditions are met: - -1. A copy of this license agreement must be included with the distribution. - -2. Redistributions of source code must retain the above copyright notice in - all source code files. - -3. Redistributions in binary form must reproduce the above copyright notice - in the documentation and/or other materials provided with the distribution. - -4. Any files that have been modified must carry notices stating the nature - of the change and the names of those who changed them. - -5. Products derived from the Software must include an acknowledgment that - they are derived from CodeIgniter in their documentation and/or other - materials provided with the distribution. - -6. Products derived from the Software may not be called "CodeIgniter", - nor may "CodeIgniter" appear in their name, without prior written - permission from EllisLab, Inc. - - -INDEMNITY -You agree to indemnify and hold harmless the authors of the Software and -any contributors for any direct, indirect, incidental, or consequential -third-party claims, actions or suits, as well as any related expenses, -liabilities, damages, settlements or fees arising from your use or misuse -of the Software, or a violation of any terms of this license. - -DISCLAIMER OF WARRANTY -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR -IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF QUALITY, PERFORMANCE, -NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - -LIMITATIONS OF LIABILITY -YOU ASSUME ALL RISK ASSOCIATED WITH THE INSTALLATION AND USE OF THE SOFTWARE. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS OF THE SOFTWARE BE LIABLE -FOR CLAIMS, DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION -WITH THE SOFTWARE. LICENSE HOLDERS ARE SOLELY RESPONSIBLE FOR DETERMINING THE -APPROPRIATENESS OF USE AND ASSUME ALL RISKS ASSOCIATED WITH ITS USE, INCLUDING -BUT NOT LIMITED TO THE RISKS OF PROGRAM ERRORS, DAMAGE TO EQUIPMENT, LOSS OF -DATA OR SOFTWARE PROGRAMS, OR UNAVAILABILITY OR INTERRUPTION OF OPERATIONS. +The MIT License (MIT) + +Copyright (c) 2014 - 2015, British Columbia Institute of Technology + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e83db14 --- /dev/null +++ b/readme.md @@ -0,0 +1,52 @@ +## CI with Eloqent ORM + +### guide +#### 1. edit composer.json +```json +{ + "require": { + "php": ">=5.4.0", + "illuminate/database": "*" + }, +} +``` +```shell +$ composer install +``` +#### 2. edit appliction/config/config.php +```php +$config['composer_autoload'] = APPPATH.'../vendor/autoload.php'; +``` +#### 3. add file appliction/helper/eloquent_helper.php +```php +defined('BASEPATH') OR exit('No direct script access allowed'); + +use Illuminate\Database\Capsule\Manager as Capsule; + +// require the ci database config +require_once APPPATH.'config/database.php'; + +// Eloquent ORM +$capsule = new Capsule; + +$capsule->addConnection( + array( + 'driver' => 'mysql', + 'host' => $db['default']['hostname'], + 'database' => $db['default']['database'], + 'username' => $db['default']['username'], + 'password' => $db['default']['password'], + 'charset' => $db['default']['char_set'], + 'collation' => $db['default']['dbcollat'], + 'prefix' => $db['default']['dbprefix'] + ) +); +//boot Eloquent +$capsule->bootEloquent(); +``` +#### 4.edit appliction/config/autoload.php +```php +$autoload['helper'] = array('eloquent'); +``` + +### now you can use the Eloquent in ci framework \ No newline at end of file diff --git a/readme.rst b/readme.rst new file mode 100644 index 0000000..a8c4f00 --- /dev/null +++ b/readme.rst @@ -0,0 +1,70 @@ +################### +What is CodeIgniter +################### + +CodeIgniter is an Application Development Framework - a toolkit - for people +who build web sites using PHP. Its goal is to enable you to develop projects +much faster than you could if you were writing code from scratch, by providing +a rich set of libraries for commonly needed tasks, as well as a simple +interface and logical structure to access these libraries. CodeIgniter lets +you creatively focus on your project by minimizing the amount of code needed +for a given task. + +******************* +Release Information +******************* + +This repo contains in-development code for future releases. To download the +latest stable release please visit the `CodeIgniter Downloads +`_ page. + +************************** +Changelog and New Features +************************** + +You can find a list of all changes for each release in the `user +guide change log `_. + +******************* +Server Requirements +******************* + +PHP version 5.4 or newer is recommended. + +It should work on 5.2.4 as well, but we strongly advise you NOT to run +such old versions of PHP, because of potential security and performance +issues, as well as missing features. + +************ +Installation +************ + +Please see the `installation section `_ +of the CodeIgniter User Guide. + +******* +License +******* + +Please see the `license +agreement `_. + +********* +Resources +********* + +- `User Guide `_ +- `Language File Translations `_ +- `Community Forums `_ +- `Community Wiki `_ +- `Community IRC `_ + +Report security issues to our `Security Panel `_ +or via our `page on HackerOne `_, thank you. + +*************** +Acknowledgement +*************** + +The CodeIgniter team would like to thank EllisLab, all the +contributors to the CodeIgniter project and you, the CodeIgniter user. \ No newline at end of file diff --git a/system/.htaccess b/system/.htaccess new file mode 100644 index 0000000..97c65d2 --- /dev/null +++ b/system/.htaccess @@ -0,0 +1,6 @@ + + Require all denied + + + Deny from all + \ No newline at end of file diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php new file mode 100644 index 0000000..014220a --- /dev/null +++ b/system/core/Benchmark.php @@ -0,0 +1,133 @@ +marker[$name] = microtime(TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Elapsed time + * + * Calculates the time difference between two marked points. + * + * If the first parameter is empty this function instead returns the + * {elapsed_time} pseudo-variable. This permits the full system + * execution time to be shown in a template. The output class will + * swap the real value for this variable. + * + * @param string $point1 A particular marked point + * @param string $point2 A particular marked point + * @param int $decimals Number of decimal places + * + * @return string Calculated elapsed time on success, + * an '{elapsed_string}' if $point1 is empty + * or an empty string if $point1 is not found. + */ + public function elapsed_time($point1 = '', $point2 = '', $decimals = 4) + { + if ($point1 === '') + { + return '{elapsed_time}'; + } + + if ( ! isset($this->marker[$point1])) + { + return ''; + } + + if ( ! isset($this->marker[$point2])) + { + $this->marker[$point2] = microtime(TRUE); + } + + return number_format($this->marker[$point2] - $this->marker[$point1], $decimals); + } + + // -------------------------------------------------------------------- + + /** + * Memory Usage + * + * Simply returns the {memory_usage} marker. + * + * This permits it to be put it anywhere in a template + * without the memory being calculated until the end. + * The output class will swap the real value for this variable. + * + * @return string '{memory_usage}' + */ + public function memory_usage() + { + return '{memory_usage}'; + } + +} diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php new file mode 100644 index 0000000..8aecc0a --- /dev/null +++ b/system/core/CodeIgniter.php @@ -0,0 +1,559 @@ + '_ENV', 'G' => '_GET', 'P' => '_POST', 'C' => '_COOKIE', 'S' => '_SERVER') as $key => $superglobal) + { + if (strpos($_registered, $key) === FALSE) + { + continue; + } + + foreach (array_keys($$superglobal) as $var) + { + if (isset($GLOBALS[$var]) && ! in_array($var, $_protected, TRUE)) + { + $GLOBALS[$var] = NULL; + } + } + } + } +} + + +/* + * ------------------------------------------------------ + * Define a custom error handler so we can log PHP errors + * ------------------------------------------------------ + */ + set_error_handler('_error_handler'); + set_exception_handler('_exception_handler'); + register_shutdown_function('_shutdown_handler'); + +/* + * ------------------------------------------------------ + * Set the subclass_prefix + * ------------------------------------------------------ + * + * Normally the "subclass_prefix" is set in the config file. + * The subclass prefix allows CI to know if a core class is + * being extended via a library in the local application + * "libraries" folder. Since CI allows config items to be + * overridden via data set in the main index.php file, + * before proceeding we need to know if a subclass_prefix + * override exists. If so, we will set this value now, + * before any classes are loaded + * Note: Since the config file data is cached it doesn't + * hurt to load it here. + */ + if ( ! empty($assign_to_config['subclass_prefix'])) + { + get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix'])); + } + +/* + * ------------------------------------------------------ + * Should we use a Composer autoloader? + * ------------------------------------------------------ + */ + if ($composer_autoload = config_item('composer_autoload')) + { + if ($composer_autoload === TRUE) + { + file_exists(APPPATH.'vendor/autoload.php') + ? require_once(APPPATH.'vendor/autoload.php') + : log_message('error', '$config[\'composer_autoload\'] is set to TRUE but '.APPPATH.'vendor/autoload.php was not found.'); + } + elseif (file_exists($composer_autoload)) + { + require_once($composer_autoload); + } + else + { + log_message('error', 'Could not find the specified $config[\'composer_autoload\'] path: '.$composer_autoload); + } + } + +/* + * ------------------------------------------------------ + * Start the timer... tick tock tick tock... + * ------------------------------------------------------ + */ + $BM =& load_class('Benchmark', 'core'); + $BM->mark('total_execution_time_start'); + $BM->mark('loading_time:_base_classes_start'); + +/* + * ------------------------------------------------------ + * Instantiate the hooks class + * ------------------------------------------------------ + */ + $EXT =& load_class('Hooks', 'core'); + +/* + * ------------------------------------------------------ + * Is there a "pre_system" hook? + * ------------------------------------------------------ + */ + $EXT->call_hook('pre_system'); + +/* + * ------------------------------------------------------ + * Instantiate the config class + * ------------------------------------------------------ + * + * Note: It is important that Config is loaded first as + * most other classes depend on it either directly or by + * depending on another class that uses it. + * + */ + $CFG =& load_class('Config', 'core'); + + // Do we have any manually set config items in the index.php file? + if (isset($assign_to_config) && is_array($assign_to_config)) + { + foreach ($assign_to_config as $key => $value) + { + $CFG->set_item($key, $value); + } + } + +/* + * ------------------------------------------------------ + * Important charset-related stuff + * ------------------------------------------------------ + * + * Configure mbstring and/or iconv if they are enabled + * and set MB_ENABLED and ICONV_ENABLED constants, so + * that we don't repeatedly do extension_loaded() or + * function_exists() calls. + * + * Note: UTF-8 class depends on this. It used to be done + * in it's constructor, but it's _not_ class-specific. + * + */ + $charset = strtoupper(config_item('charset')); + ini_set('default_charset', $charset); + + if (extension_loaded('mbstring')) + { + define('MB_ENABLED', TRUE); + // mbstring.internal_encoding is deprecated starting with PHP 5.6 + // and it's usage triggers E_DEPRECATED messages. + @ini_set('mbstring.internal_encoding', $charset); + // This is required for mb_convert_encoding() to strip invalid characters. + // That's utilized by CI_Utf8, but it's also done for consistency with iconv. + mb_substitute_character('none'); + } + else + { + define('MB_ENABLED', FALSE); + } + + // There's an ICONV_IMPL constant, but the PHP manual says that using + // iconv's predefined constants is "strongly discouraged". + if (extension_loaded('iconv')) + { + define('ICONV_ENABLED', TRUE); + // iconv.internal_encoding is deprecated starting with PHP 5.6 + // and it's usage triggers E_DEPRECATED messages. + @ini_set('iconv.internal_encoding', $charset); + } + else + { + define('ICONV_ENABLED', FALSE); + } + + if (is_php('5.6')) + { + ini_set('php.internal_encoding', $charset); + } + +/* + * ------------------------------------------------------ + * Load compatibility features + * ------------------------------------------------------ + */ + + require_once(BASEPATH.'core/compat/mbstring.php'); + require_once(BASEPATH.'core/compat/hash.php'); + require_once(BASEPATH.'core/compat/password.php'); + require_once(BASEPATH.'core/compat/standard.php'); + +/* + * ------------------------------------------------------ + * Instantiate the UTF-8 class + * ------------------------------------------------------ + */ + $UNI =& load_class('Utf8', 'core'); + +/* + * ------------------------------------------------------ + * Instantiate the URI class + * ------------------------------------------------------ + */ + $URI =& load_class('URI', 'core'); + +/* + * ------------------------------------------------------ + * Instantiate the routing class and set the routing + * ------------------------------------------------------ + */ + $RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL); + +/* + * ------------------------------------------------------ + * Instantiate the output class + * ------------------------------------------------------ + */ + $OUT =& load_class('Output', 'core'); + +/* + * ------------------------------------------------------ + * Is there a valid cache file? If so, we're done... + * ------------------------------------------------------ + */ + if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE) + { + exit; + } + +/* + * ----------------------------------------------------- + * Load the security class for xss and csrf support + * ----------------------------------------------------- + */ + $SEC =& load_class('Security', 'core'); + +/* + * ------------------------------------------------------ + * Load the Input class and sanitize globals + * ------------------------------------------------------ + */ + $IN =& load_class('Input', 'core'); + +/* + * ------------------------------------------------------ + * Load the Language class + * ------------------------------------------------------ + */ + $LANG =& load_class('Lang', 'core'); + +/* + * ------------------------------------------------------ + * Load the app controller and local controller + * ------------------------------------------------------ + * + */ + // Load the base controller class + require_once BASEPATH.'core/Controller.php'; + + /** + * Reference to the CI_Controller method. + * + * Returns current CI instance object + * + * @return CI_Controller + */ + function &get_instance() + { + return CI_Controller::get_instance(); + } + + if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php')) + { + require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'; + } + + // Set a mark point for benchmarking + $BM->mark('loading_time:_base_classes_end'); + +/* + * ------------------------------------------------------ + * Sanity checks + * ------------------------------------------------------ + * + * The Router class has already validated the request, + * leaving us with 3 options here: + * + * 1) an empty class name, if we reached the default + * controller, but it didn't exist; + * 2) a query string which doesn't go through a + * file_exists() check + * 3) a regular request for a non-existing page + * + * We handle all of these as a 404 error. + * + * Furthermore, none of the methods in the app controller + * or the loader class can be called via the URI, nor can + * controller methods that begin with an underscore. + */ + + $e404 = FALSE; + $class = ucfirst($RTR->class); + $method = $RTR->method; + + if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php')) + { + $e404 = TRUE; + } + else + { + require_once(APPPATH.'controllers/'.$RTR->directory.$class.'.php'); + + if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method)) + { + $e404 = TRUE; + } + elseif (method_exists($class, '_remap')) + { + $params = array($method, array_slice($URI->rsegments, 2)); + $method = '_remap'; + } + elseif ( ! method_exists($class, $method)) + { + $e404 = TRUE; + } + /** + * DO NOT CHANGE THIS, NOTHING ELSE WORKS! + * + * - method_exists() returns true for non-public methods, which passes the previous elseif + * - is_callable() returns false for PHP 4-style constructors, even if there's a __construct() + * - method_exists($class, '__construct') won't work because CI_Controller::__construct() is inherited + * - People will only complain if this doesn't work, even though it is documented that it shouldn't. + * + * ReflectionMethod::isConstructor() is the ONLY reliable check, + * knowing which method will be executed as a constructor. + */ + elseif ( ! is_callable(array($class, $method))) + { + $reflection = new ReflectionMethod($class, $method); + if ( ! $reflection->isPublic() OR $reflection->isConstructor()) + { + $e404 = TRUE; + } + } + } + + if ($e404) + { + if ( ! empty($RTR->routes['404_override'])) + { + if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $error_class, $error_method) !== 2) + { + $error_method = 'index'; + } + + $error_class = ucfirst($error_class); + + if ( ! class_exists($error_class, FALSE)) + { + if (file_exists(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php')) + { + require_once(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php'); + $e404 = ! class_exists($error_class, FALSE); + } + // Were we in a directory? If so, check for a global override + elseif ( ! empty($RTR->directory) && file_exists(APPPATH.'controllers/'.$error_class.'.php')) + { + require_once(APPPATH.'controllers/'.$error_class.'.php'); + if (($e404 = ! class_exists($error_class, FALSE)) === FALSE) + { + $RTR->directory = ''; + } + } + } + else + { + $e404 = FALSE; + } + } + + // Did we reset the $e404 flag? If so, set the rsegments, starting from index 1 + if ( ! $e404) + { + $class = $error_class; + $method = $error_method; + + $URI->rsegments = array( + 1 => $class, + 2 => $method + ); + } + else + { + show_404($RTR->directory.$class.'/'.$method); + } + } + + if ($method !== '_remap') + { + $params = array_slice($URI->rsegments, 2); + } + +/* + * ------------------------------------------------------ + * Is there a "pre_controller" hook? + * ------------------------------------------------------ + */ + $EXT->call_hook('pre_controller'); + +/* + * ------------------------------------------------------ + * Instantiate the requested controller + * ------------------------------------------------------ + */ + // Mark a start point so we can benchmark the controller + $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); + + $CI = new $class(); + +/* + * ------------------------------------------------------ + * Is there a "post_controller_constructor" hook? + * ------------------------------------------------------ + */ + $EXT->call_hook('post_controller_constructor'); + +/* + * ------------------------------------------------------ + * Call the requested method + * ------------------------------------------------------ + */ + call_user_func_array(array(&$CI, $method), $params); + + // Mark a benchmark end point + $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); + +/* + * ------------------------------------------------------ + * Is there a "post_controller" hook? + * ------------------------------------------------------ + */ + $EXT->call_hook('post_controller'); + +/* + * ------------------------------------------------------ + * Send the final rendered output to the browser + * ------------------------------------------------------ + */ + if ($EXT->call_hook('display_override') === FALSE) + { + $OUT->_display(); + } + +/* + * ------------------------------------------------------ + * Is there a "post_system" hook? + * ------------------------------------------------------ + */ + $EXT->call_hook('post_system'); diff --git a/system/core/Common.php b/system/core/Common.php new file mode 100644 index 0000000..624b5a9 --- /dev/null +++ b/system/core/Common.php @@ -0,0 +1,849 @@ +='); + } + + return $_is_php[$version]; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('is_really_writable')) +{ + /** + * Tests for file writability + * + * is_writable() returns TRUE on Windows servers when you really can't write to + * the file, based on the read-only attribute. is_writable() is also unreliable + * on Unix servers if safe_mode is on. + * + * @link https://bugs.php.net/bug.php?id=54709 + * @param string + * @return bool + */ + function is_really_writable($file) + { + // If we're on a Unix server with safe_mode off we call is_writable + if (DIRECTORY_SEPARATOR === '/' && (is_php('5.4') OR ! ini_get('safe_mode'))) + { + return is_writable($file); + } + + /* For Windows servers and safe_mode "on" installations we'll actually + * write a file then read it. Bah... + */ + if (is_dir($file)) + { + $file = rtrim($file, '/').'/'.md5(mt_rand()); + if (($fp = @fopen($file, 'ab')) === FALSE) + { + return FALSE; + } + + fclose($fp); + @chmod($file, 0777); + @unlink($file); + return TRUE; + } + elseif ( ! is_file($file) OR ($fp = @fopen($file, 'ab')) === FALSE) + { + return FALSE; + } + + fclose($fp); + return TRUE; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('load_class')) +{ + /** + * Class registry + * + * This function acts as a singleton. If the requested class does not + * exist it is instantiated and set to a static variable. If it has + * previously been instantiated the variable is returned. + * + * @param string the class name being requested + * @param string the directory where the class should be found + * @param mixed an optional argument to pass to the class constructor + * @return object + */ + function &load_class($class, $directory = 'libraries', $param = NULL) + { + static $_classes = array(); + + // Does the class exist? If so, we're done... + if (isset($_classes[$class])) + { + return $_classes[$class]; + } + + $name = FALSE; + + // Look for the class first in the local application/libraries folder + // then in the native system/libraries folder + foreach (array(APPPATH, BASEPATH) as $path) + { + if (file_exists($path.$directory.'/'.$class.'.php')) + { + $name = 'CI_'.$class; + + if (class_exists($name, FALSE) === FALSE) + { + require_once($path.$directory.'/'.$class.'.php'); + } + + break; + } + } + + // Is the request a class extension? If so we load it too + if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php')) + { + $name = config_item('subclass_prefix').$class; + + if (class_exists($name, FALSE) === FALSE) + { + require_once(APPPATH.$directory.'/'.$name.'.php'); + } + } + + // Did we find the class? + if ($name === FALSE) + { + // Note: We use exit() rather than show_error() in order to avoid a + // self-referencing loop with the Exceptions class + set_status_header(503); + echo 'Unable to locate the specified class: '.$class.'.php'; + exit(5); // EXIT_UNK_CLASS + } + + // Keep track of what we just loaded + is_loaded($class); + + $_classes[$class] = isset($param) + ? new $name($param) + : new $name(); + return $_classes[$class]; + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('is_loaded')) +{ + /** + * Keeps track of which libraries have been loaded. This function is + * called by the load_class() function above + * + * @param string + * @return array + */ + function &is_loaded($class = '') + { + static $_is_loaded = array(); + + if ($class !== '') + { + $_is_loaded[strtolower($class)] = $class; + } + + return $_is_loaded; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('get_config')) +{ + /** + * Loads the main config.php file + * + * This function lets us grab the config file even if the Config class + * hasn't been instantiated yet + * + * @param array + * @return array + */ + function &get_config(Array $replace = array()) + { + static $config; + + if (empty($config)) + { + $file_path = APPPATH.'config/config.php'; + $found = FALSE; + if (file_exists($file_path)) + { + $found = TRUE; + require($file_path); + } + + // Is the config file in the environment folder? + if (file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) + { + require($file_path); + } + elseif ( ! $found) + { + set_status_header(503); + echo 'The configuration file does not exist.'; + exit(3); // EXIT_CONFIG + } + + // Does the $config array exist in the file? + if ( ! isset($config) OR ! is_array($config)) + { + set_status_header(503); + echo 'Your config file does not appear to be formatted correctly.'; + exit(3); // EXIT_CONFIG + } + } + + // Are any values being dynamically added or replaced? + foreach ($replace as $key => $val) + { + $config[$key] = $val; + } + + return $config; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('config_item')) +{ + /** + * Returns the specified config item + * + * @param string + * @return mixed + */ + function config_item($item) + { + static $_config; + + if (empty($_config)) + { + // references cannot be directly assigned to static variables, so we use an array + $_config[0] =& get_config(); + } + + return isset($_config[0][$item]) ? $_config[0][$item] : NULL; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('get_mimes')) +{ + /** + * Returns the MIME types array from config/mimes.php + * + * @return array + */ + function &get_mimes() + { + static $_mimes; + + if (empty($_mimes)) + { + $_mimes = file_exists(APPPATH.'config/mimes.php') + ? include(APPPATH.'config/mimes.php') + : array(); + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + { + $_mimes = array_merge($_mimes, include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')); + } + } + + return $_mimes; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('is_https')) +{ + /** + * Is HTTPS? + * + * Determines if the application is accessed via an encrypted + * (HTTPS) connection. + * + * @return bool + */ + function is_https() + { + if ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') + { + return TRUE; + } + elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https') + { + return TRUE; + } + elseif ( ! empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') + { + return TRUE; + } + + return FALSE; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('is_cli')) +{ + + /** + * Is CLI? + * + * Test to see if a request was made from the command line. + * + * @return bool + */ + function is_cli() + { + return (PHP_SAPI === 'cli' OR defined('STDIN')); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('show_error')) +{ + /** + * Error Handler + * + * This function lets us invoke the exception class and + * display errors using the standard error template located + * in application/views/errors/error_general.php + * This function will send the error page directly to the + * browser and exit. + * + * @param string + * @param int + * @param string + * @return void + */ + function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') + { + $status_code = abs($status_code); + if ($status_code < 100) + { + $exit_status = $status_code + 9; // 9 is EXIT__AUTO_MIN + $status_code = 500; + } + else + { + $exit_status = 1; // EXIT_ERROR + } + + $_error =& load_class('Exceptions', 'core'); + echo $_error->show_error($heading, $message, 'error_general', $status_code); + exit($exit_status); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('show_404')) +{ + /** + * 404 Page Handler + * + * This function is similar to the show_error() function above + * However, instead of the standard error template it displays + * 404 errors. + * + * @param string + * @param bool + * @return void + */ + function show_404($page = '', $log_error = TRUE) + { + $_error =& load_class('Exceptions', 'core'); + $_error->show_404($page, $log_error); + exit(4); // EXIT_UNKNOWN_FILE + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('log_message')) +{ + /** + * Error Logging Interface + * + * We use this as a simple mechanism to access the logging + * class and send messages to be logged. + * + * @param string the error level: 'error', 'debug' or 'info' + * @param string the error message + * @return void + */ + function log_message($level, $message) + { + static $_log; + + if ($_log === NULL) + { + // references cannot be directly assigned to static variables, so we use an array + $_log[0] =& load_class('Log', 'core'); + } + + $_log[0]->write_log($level, $message); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('set_status_header')) +{ + /** + * Set HTTP Status Header + * + * @param int the status code + * @param string + * @return void + */ + function set_status_header($code = 200, $text = '') + { + if (is_cli()) + { + return; + } + + if (empty($code) OR ! is_numeric($code)) + { + show_error('Status codes must be numeric', 500); + } + + if (empty($text)) + { + is_int($code) OR $code = (int) $code; + $stati = array( + 100 => 'Continue', + 101 => 'Switching Protocols', + + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + 307 => 'Temporary Redirect', + + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + 422 => 'Unprocessable Entity', + 426 => 'Upgrade Required', + 428 => 'Precondition Required', + 429 => 'Too Many Requests', + 431 => 'Request Header Fields Too Large', + + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 511 => 'Network Authentication Required', + ); + + if (isset($stati[$code])) + { + $text = $stati[$code]; + } + else + { + show_error('No status text available. Please check your status code number or supply your own message text.', 500); + } + } + + if (strpos(PHP_SAPI, 'cgi') === 0) + { + header('Status: '.$code.' '.$text, TRUE); + return; + } + + $server_protocol = (isset($_SERVER['SERVER_PROTOCOL']) && in_array($_SERVER['SERVER_PROTOCOL'], array('HTTP/1.0', 'HTTP/1.1', 'HTTP/2'), TRUE)) + ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; + header($server_protocol.' '.$code.' '.$text, TRUE, $code); + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('_error_handler')) +{ + /** + * Error Handler + * + * This is the custom error handler that is declared at the (relative) + * top of CodeIgniter.php. The main reason we use this is to permit + * PHP errors to be logged in our own log files since the user may + * not have access to server logs. Since this function effectively + * intercepts PHP errors, however, we also need to display errors + * based on the current error_reporting level. + * We do that with the use of a PHP error template. + * + * @param int $severity + * @param string $message + * @param string $filepath + * @param int $line + * @return void + */ + function _error_handler($severity, $message, $filepath, $line) + { + $is_error = (((E_ERROR | E_PARSE | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $severity) === $severity); + + // When an error occurred, set the status header to '500 Internal Server Error' + // to indicate to the client something went wrong. + // This can't be done within the $_error->show_php_error method because + // it is only called when the display_errors flag is set (which isn't usually + // the case in a production environment) or when errors are ignored because + // they are above the error_reporting threshold. + if ($is_error) + { + set_status_header(500); + } + + // Should we ignore the error? We'll get the current error_reporting + // level and add its bits with the severity bits to find out. + if (($severity & error_reporting()) !== $severity) + { + return; + } + + $_error =& load_class('Exceptions', 'core'); + $_error->log_exception($severity, $message, $filepath, $line); + + // Should we display the error? + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) + { + $_error->show_php_error($severity, $message, $filepath, $line); + } + + // If the error is fatal, the execution of the script should be stopped because + // errors can't be recovered from. Halting the script conforms with PHP's + // default error handling. See http://www.php.net/manual/en/errorfunc.constants.php + if ($is_error) + { + exit(1); // EXIT_ERROR + } + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('_exception_handler')) +{ + /** + * Exception Handler + * + * Sends uncaught exceptions to the logger and displays them + * only if display_errors is On so that they don't show up in + * production environments. + * + * @param Exception $exception + * @return void + */ + function _exception_handler($exception) + { + $_error =& load_class('Exceptions', 'core'); + $_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine()); + + is_cli() OR set_status_header(500); + // Should we display the error? + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) + { + $_error->show_exception($exception); + } + + exit(1); // EXIT_ERROR + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('_shutdown_handler')) +{ + /** + * Shutdown Handler + * + * This is the shutdown handler that is declared at the top + * of CodeIgniter.php. The main reason we use this is to simulate + * a complete custom exception handler. + * + * E_STRICT is purposively neglected because such events may have + * been caught. Duplication or none? None is preferred for now. + * + * @link http://insomanic.me.uk/post/229851073/php-trick-catching-fatal-errors-e-error-with-a + * @return void + */ + function _shutdown_handler() + { + $last_error = error_get_last(); + if (isset($last_error) && + ($last_error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) + { + _error_handler($last_error['type'], $last_error['message'], $last_error['file'], $last_error['line']); + } + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('remove_invisible_characters')) +{ + /** + * Remove Invisible Characters + * + * This prevents sandwiching null characters + * between ascii characters, like Java\0script. + * + * @param string + * @param bool + * @return string + */ + function remove_invisible_characters($str, $url_encoded = TRUE) + { + $non_displayables = array(); + + // every control character except newline (dec 10), + // carriage return (dec 13) and horizontal tab (dec 09) + if ($url_encoded) + { + $non_displayables[] = '/%0[0-8bcef]/i'; // url encoded 00-08, 11, 12, 14, 15 + $non_displayables[] = '/%1[0-9a-f]/i'; // url encoded 16-31 + $non_displayables[] = '/%7f/i'; // url encoded 127 + } + + $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 + + do + { + $str = preg_replace($non_displayables, '', $str, -1, $count); + } + while ($count); + + return $str; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('html_escape')) +{ + /** + * Returns HTML escaped variable. + * + * @param mixed $var The input string or array of strings to be escaped. + * @param bool $double_encode $double_encode set to FALSE prevents escaping twice. + * @return mixed The escaped string or array of strings as a result. + */ + function html_escape($var, $double_encode = TRUE) + { + if (empty($var)) + { + return $var; + } + + if (is_array($var)) + { + foreach (array_keys($var) as $key) + { + $var[$key] = html_escape($var[$key], $double_encode); + } + + return $var; + } + + return htmlspecialchars($var, ENT_QUOTES, config_item('charset'), $double_encode); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('_stringify_attributes')) +{ + /** + * Stringify attributes for use in HTML tags. + * + * Helper function used to convert a string, array, or object + * of attributes to a string. + * + * @param mixed string, array, object + * @param bool + * @return string + */ + function _stringify_attributes($attributes, $js = FALSE) + { + $atts = NULL; + + if (empty($attributes)) + { + return $atts; + } + + if (is_string($attributes)) + { + return ' '.$attributes; + } + + $attributes = (array) $attributes; + + foreach ($attributes as $key => $val) + { + $atts .= ($js) ? $key.'='.$val.',' : ' '.$key.'="'.$val.'"'; + } + + return rtrim($atts, ','); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('function_usable')) +{ + /** + * Function usable + * + * Executes a function_exists() check, and if the Suhosin PHP + * extension is loaded - checks whether the function that is + * checked might be disabled in there as well. + * + * This is useful as function_exists() will return FALSE for + * functions disabled via the *disable_functions* php.ini + * setting, but not for *suhosin.executor.func.blacklist* and + * *suhosin.executor.disable_eval*. These settings will just + * terminate script execution if a disabled function is executed. + * + * The above described behavior turned out to be a bug in Suhosin, + * but even though a fix was committed for 0.9.34 on 2012-02-12, + * that version is yet to be released. This function will therefore + * be just temporary, but would probably be kept for a few years. + * + * @link http://www.hardened-php.net/suhosin/ + * @param string $function_name Function to check for + * @return bool TRUE if the function exists and is safe to call, + * FALSE otherwise. + */ + function function_usable($function_name) + { + static $_suhosin_func_blacklist; + + if (function_exists($function_name)) + { + if ( ! isset($_suhosin_func_blacklist)) + { + $_suhosin_func_blacklist = extension_loaded('suhosin') + ? explode(',', trim(ini_get('suhosin.executor.func.blacklist'))) + : array(); + } + + return ! in_array($function_name, $_suhosin_func_blacklist, TRUE); + } + + return FALSE; + } +} diff --git a/system/core/Config.php b/system/core/Config.php new file mode 100644 index 0000000..fc6c30f --- /dev/null +++ b/system/core/Config.php @@ -0,0 +1,379 @@ +config =& get_config(); + + // Set the base_url automatically if none was provided + if (empty($this->config['base_url'])) + { + if (isset($_SERVER['SERVER_ADDR'])) + { + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) + { + $server_addr = '['.$_SERVER['SERVER_ADDR'].']'; + } + else + { + $server_addr = $_SERVER['SERVER_ADDR']; + } + + $base_url = (is_https() ? 'https' : 'http').'://'.$server_addr + .substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); + } + else + { + $base_url = 'http://localhost/'; + } + + $this->set_item('base_url', $base_url); + } + + log_message('info', 'Config Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Load Config File + * + * @param string $file Configuration file name + * @param bool $use_sections Whether configuration values should be loaded into their own section + * @param bool $fail_gracefully Whether to just return FALSE or display an error message + * @return bool TRUE if the file was loaded correctly or FALSE on failure + */ + public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { + $file = ($file === '') ? 'config' : str_replace('.php', '', $file); + $loaded = FALSE; + + foreach ($this->_config_paths as $path) + { + foreach (array($file, ENVIRONMENT.DIRECTORY_SEPARATOR.$file) as $location) + { + $file_path = $path.'config/'.$location.'.php'; + if (in_array($file_path, $this->is_loaded, TRUE)) + { + return TRUE; + } + + if ( ! file_exists($file_path)) + { + continue; + } + + include($file_path); + + if ( ! isset($config) OR ! is_array($config)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + + show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.'); + } + + if ($use_sections === TRUE) + { + $this->config[$file] = isset($this->config[$file]) + ? array_merge($this->config[$file], $config) + : $config; + } + else + { + $this->config = array_merge($this->config, $config); + } + + $this->is_loaded[] = $file_path; + $config = NULL; + $loaded = TRUE; + log_message('debug', 'Config file loaded: '.$file_path); + } + } + + if ($loaded === TRUE) + { + return TRUE; + } + elseif ($fail_gracefully === TRUE) + { + return FALSE; + } + + show_error('The configuration file '.$file.'.php does not exist.'); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a config file item + * + * @param string $item Config item name + * @param string $index Index name + * @return string|null The configuration item or NULL if the item doesn't exist + */ + public function item($item, $index = '') + { + if ($index == '') + { + return isset($this->config[$item]) ? $this->config[$item] : NULL; + } + + return isset($this->config[$index], $this->config[$index][$item]) ? $this->config[$index][$item] : NULL; + } + + // -------------------------------------------------------------------- + + /** + * Fetch a config file item with slash appended (if not empty) + * + * @param string $item Config item name + * @return string|null The configuration item or NULL if the item doesn't exist + */ + public function slash_item($item) + { + if ( ! isset($this->config[$item])) + { + return NULL; + } + elseif (trim($this->config[$item]) === '') + { + return ''; + } + + return rtrim($this->config[$item], '/').'/'; + } + + // -------------------------------------------------------------------- + + /** + * Site URL + * + * Returns base_url . index_page [. uri_string] + * + * @uses CI_Config::_uri_string() + * + * @param string|string[] $uri URI string or an array of segments + * @param string $protocol + * @return string + */ + public function site_url($uri = '', $protocol = NULL) + { + $base_url = $this->slash_item('base_url'); + + if (isset($protocol)) + { + // For protocol-relative links + if ($protocol === '') + { + $base_url = substr($base_url, strpos($base_url, '//')); + } + else + { + $base_url = $protocol.substr($base_url, strpos($base_url, '://')); + } + } + + if (empty($uri)) + { + return $base_url.$this->item('index_page'); + } + + $uri = $this->_uri_string($uri); + + if ($this->item('enable_query_strings') === FALSE) + { + $suffix = isset($this->config['url_suffix']) ? $this->config['url_suffix'] : ''; + + if ($suffix !== '') + { + if (($offset = strpos($uri, '?')) !== FALSE) + { + $uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset); + } + else + { + $uri .= $suffix; + } + } + + return $base_url.$this->slash_item('index_page').$uri; + } + elseif (strpos($uri, '?') === FALSE) + { + $uri = '?'.$uri; + } + + return $base_url.$this->item('index_page').$uri; + } + + // ------------------------------------------------------------- + + /** + * Base URL + * + * Returns base_url [. uri_string] + * + * @uses CI_Config::_uri_string() + * + * @param string|string[] $uri URI string or an array of segments + * @param string $protocol + * @return string + */ + public function base_url($uri = '', $protocol = NULL) + { + $base_url = $this->slash_item('base_url'); + + if (isset($protocol)) + { + // For protocol-relative links + if ($protocol === '') + { + $base_url = substr($base_url, strpos($base_url, '//')); + } + else + { + $base_url = $protocol.substr($base_url, strpos($base_url, '://')); + } + } + + return $base_url.$this->_uri_string($uri); + } + + // ------------------------------------------------------------- + + /** + * Build URI string + * + * @used-by CI_Config::site_url() + * @used-by CI_Config::base_url() + * + * @param string|string[] $uri URI string or an array of segments + * @return string + */ + protected function _uri_string($uri) + { + if ($this->item('enable_query_strings') === FALSE) + { + is_array($uri) && $uri = implode('/', $uri); + return ltrim($uri, '/'); + } + elseif (is_array($uri)) + { + return http_build_query($uri); + } + + return $uri; + } + + // -------------------------------------------------------------------- + + /** + * System URL + * + * @deprecated 3.0.0 Encourages insecure practices + * @return string + */ + public function system_url() + { + $x = explode('/', preg_replace('|/*(.+?)/*$|', '\\1', BASEPATH)); + return $this->slash_item('base_url').end($x).'/'; + } + + // -------------------------------------------------------------------- + + /** + * Set a config file item + * + * @param string $item Config item key + * @param string $value Config item value + * @return void + */ + public function set_item($item, $value) + { + $this->config[$item] = $value; + } + +} diff --git a/system/core/Controller.php b/system/core/Controller.php new file mode 100644 index 0000000..e25b847 --- /dev/null +++ b/system/core/Controller.php @@ -0,0 +1,103 @@ + $class) + { + $this->$var =& load_class($class); + } + + $this->load =& load_class('Loader', 'core'); + $this->load->initialize(); + log_message('info', 'Controller Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Get the CI singleton + * + * @static + * @return object + */ + public static function &get_instance() + { + return self::$instance; + } + +} diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php new file mode 100644 index 0000000..90ff1ab --- /dev/null +++ b/system/core/Exceptions.php @@ -0,0 +1,274 @@ + 'Error', + E_WARNING => 'Warning', + E_PARSE => 'Parsing Error', + E_NOTICE => 'Notice', + E_CORE_ERROR => 'Core Error', + E_CORE_WARNING => 'Core Warning', + E_COMPILE_ERROR => 'Compile Error', + E_COMPILE_WARNING => 'Compile Warning', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Runtime Notice' + ); + + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + $this->ob_level = ob_get_level(); + // Note: Do not log messages from this constructor. + } + + // -------------------------------------------------------------------- + + /** + * Exception Logger + * + * Logs PHP generated error messages + * + * @param int $severity Log level + * @param string $message Error message + * @param string $filepath File path + * @param int $line Line number + * @return void + */ + public function log_exception($severity, $message, $filepath, $line) + { + $severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity; + log_message('error', 'Severity: '.$severity.' --> '.$message.' '.$filepath.' '.$line); + } + + // -------------------------------------------------------------------- + + /** + * 404 Error Handler + * + * @uses CI_Exceptions::show_error() + * + * @param string $page Page URI + * @param bool $log_error Whether to log the error + * @return void + */ + public function show_404($page = '', $log_error = TRUE) + { + if (is_cli()) + { + $heading = 'Not Found'; + $message = 'The controller/method pair you requested was not found.'; + } + else + { + $heading = '404 Page Not Found'; + $message = 'The page you requested was not found.'; + } + + // By default we log this, but allow a dev to skip it + if ($log_error) + { + log_message('error', $heading.': '.$page); + } + + echo $this->show_error($heading, $message, 'error_404', 404); + exit(4); // EXIT_UNKNOWN_FILE + } + + // -------------------------------------------------------------------- + + /** + * General Error Page + * + * Takes an error message as input (either as a string or an array) + * and displays it using the specified template. + * + * @param string $heading Page heading + * @param string|string[] $message Error message + * @param string $template Template name + * @param int $status_code (default: 500) + * + * @return string Error page output + */ + public function show_error($heading, $message, $template = 'error_general', $status_code = 500) + { + $templates_path = config_item('error_views_path'); + if (empty($templates_path)) + { + $templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR; + } + + if (is_cli()) + { + $message = "\t".(is_array($message) ? implode("\n\t", $message) : $message); + $template = 'cli'.DIRECTORY_SEPARATOR.$template; + } + else + { + set_status_header($status_code); + $message = '

    '.(is_array($message) ? implode('

    ', $message) : $message).'

    '; + $template = 'html'.DIRECTORY_SEPARATOR.$template; + } + + if (ob_get_level() > $this->ob_level + 1) + { + ob_end_flush(); + } + ob_start(); + include($templates_path.$template.'.php'); + $buffer = ob_get_contents(); + ob_end_clean(); + return $buffer; + } + + // -------------------------------------------------------------------- + + public function show_exception($exception) + { + $templates_path = config_item('error_views_path'); + if (empty($templates_path)) + { + $templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR; + } + + $message = $exception->getMessage(); + if (empty($message)) + { + $message = '(null)'; + } + + if (is_cli()) + { + $templates_path .= 'cli'.DIRECTORY_SEPARATOR; + } + else + { + $templates_path .= 'html'.DIRECTORY_SEPARATOR; + } + + if (ob_get_level() > $this->ob_level + 1) + { + ob_end_flush(); + } + + ob_start(); + include($templates_path.'error_exception.php'); + $buffer = ob_get_contents(); + ob_end_clean(); + echo $buffer; + } + + // -------------------------------------------------------------------- + + /** + * Native PHP error handler + * + * @param int $severity Error level + * @param string $message Error message + * @param string $filepath File path + * @param int $line Line number + * @return void + */ + public function show_php_error($severity, $message, $filepath, $line) + { + $templates_path = config_item('error_views_path'); + if (empty($templates_path)) + { + $templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR; + } + + $severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity; + + // For safety reasons we don't show the full file path in non-CLI requests + if ( ! is_cli()) + { + $filepath = str_replace('\\', '/', $filepath); + if (FALSE !== strpos($filepath, '/')) + { + $x = explode('/', $filepath); + $filepath = $x[count($x)-2].'/'.end($x); + } + + $template = 'html'.DIRECTORY_SEPARATOR.'error_php'; + } + else + { + $template = 'cli'.DIRECTORY_SEPARATOR.'error_php'; + } + + if (ob_get_level() > $this->ob_level + 1) + { + ob_end_flush(); + } + ob_start(); + include($templates_path.$template.'.php'); + $buffer = ob_get_contents(); + ob_end_clean(); + echo $buffer; + } + +} diff --git a/system/core/Hooks.php b/system/core/Hooks.php new file mode 100644 index 0000000..6236dd4 --- /dev/null +++ b/system/core/Hooks.php @@ -0,0 +1,266 @@ +item('enable_hooks') === FALSE) + { + return; + } + + // Grab the "hooks" definition file. + if (file_exists(APPPATH.'config/hooks.php')) + { + include(APPPATH.'config/hooks.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/hooks.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'); + } + + // If there are no hooks, we're done. + if ( ! isset($hook) OR ! is_array($hook)) + { + return; + } + + $this->hooks =& $hook; + $this->enabled = TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Call Hook + * + * Calls a particular hook. Called by CodeIgniter.php. + * + * @uses CI_Hooks::_run_hook() + * + * @param string $which Hook name + * @return bool TRUE on success or FALSE on failure + */ + public function call_hook($which = '') + { + if ( ! $this->enabled OR ! isset($this->hooks[$which])) + { + return FALSE; + } + + if (is_array($this->hooks[$which]) && ! isset($this->hooks[$which]['function'])) + { + foreach ($this->hooks[$which] as $val) + { + $this->_run_hook($val); + } + } + else + { + $this->_run_hook($this->hooks[$which]); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Run Hook + * + * Runs a particular hook + * + * @param array $data Hook details + * @return bool TRUE on success or FALSE on failure + */ + protected function _run_hook($data) + { + // Closures/lambda functions and array($object, 'method') callables + if (is_callable($data)) + { + is_array($data) + ? $data[0]->{$data[1]}() + : $data(); + + return TRUE; + } + elseif ( ! is_array($data)) + { + return FALSE; + } + + // ----------------------------------- + // Safety - Prevents run-away loops + // ----------------------------------- + + // If the script being called happens to have the same + // hook call within it a loop can happen + if ($this->_in_progress === TRUE) + { + return; + } + + // ----------------------------------- + // Set file path + // ----------------------------------- + + if ( ! isset($data['filepath'], $data['filename'])) + { + return FALSE; + } + + $filepath = APPPATH.$data['filepath'].'/'.$data['filename']; + + if ( ! file_exists($filepath)) + { + return FALSE; + } + + // Determine and class and/or function names + $class = empty($data['class']) ? FALSE : $data['class']; + $function = empty($data['function']) ? FALSE : $data['function']; + $params = isset($data['params']) ? $data['params'] : ''; + + if (empty($function)) + { + return FALSE; + } + + // Set the _in_progress flag + $this->_in_progress = TRUE; + + // Call the requested class and/or function + if ($class !== FALSE) + { + // The object is stored? + if (isset($this->_objects[$class])) + { + if (method_exists($this->_objects[$class], $function)) + { + $this->_objects[$class]->$function($params); + } + else + { + return $this->_in_progress = FALSE; + } + } + else + { + class_exists($class, FALSE) OR require_once($filepath); + + if ( ! class_exists($class, FALSE) OR ! method_exists($class, $function)) + { + return $this->_in_progress = FALSE; + } + + // Store the object and execute the method + $this->_objects[$class] = new $class(); + $this->_objects[$class]->$function($params); + } + } + else + { + function_exists($function) OR require_once($filepath); + + if ( ! function_exists($function)) + { + return $this->_in_progress = FALSE; + } + + $function($params); + } + + $this->_in_progress = FALSE; + return TRUE; + } + +} diff --git a/system/core/Input.php b/system/core/Input.php new file mode 100644 index 0000000..30b31d0 --- /dev/null +++ b/system/core/Input.php @@ -0,0 +1,895 @@ +_allow_get_array = (config_item('allow_get_array') !== FALSE); + $this->_enable_xss = (config_item('global_xss_filtering') === TRUE); + $this->_enable_csrf = (config_item('csrf_protection') === TRUE); + $this->_standardize_newlines = (bool) config_item('standardize_newlines'); + + $this->security =& load_class('Security', 'core'); + + // Do we need the UTF-8 class? + if (UTF8_ENABLED === TRUE) + { + $this->uni =& load_class('Utf8', 'core'); + } + + // Sanitize global arrays + $this->_sanitize_globals(); + + // CSRF Protection check + if ($this->_enable_csrf === TRUE && ! is_cli()) + { + $this->security->csrf_verify(); + } + + log_message('info', 'Input Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Fetch from array + * + * Internal method used to retrieve values from global arrays. + * + * @param array &$array $_GET, $_POST, $_COOKIE, $_SERVER, etc. + * @param mixed $index Index for item to be fetched from $array + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + protected function _fetch_from_array(&$array, $index = NULL, $xss_clean = NULL) + { + is_bool($xss_clean) OR $xss_clean = $this->_enable_xss; + + // If $index is NULL, it means that the whole $array is requested + isset($index) OR $index = array_keys($array); + + // allow fetching multiple keys at once + if (is_array($index)) + { + $output = array(); + foreach ($index as $key) + { + $output[$key] = $this->_fetch_from_array($array, $key, $xss_clean); + } + + return $output; + } + + if (isset($array[$index])) + { + $value = $array[$index]; + } + elseif (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) // Does the index contain array notation + { + $value = $array; + for ($i = 0; $i < $count; $i++) + { + $key = trim($matches[0][$i], '[]'); + if ($key === '') // Empty notation will return the value as array + { + break; + } + + if (isset($value[$key])) + { + $value = $value[$key]; + } + else + { + return NULL; + } + } + } + else + { + return NULL; + } + + return ($xss_clean === TRUE) + ? $this->security->xss_clean($value) + : $value; + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the GET array + * + * @param mixed $index Index for item to be fetched from $_GET + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function get($index = NULL, $xss_clean = NULL) + { + return $this->_fetch_from_array($_GET, $index, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the POST array + * + * @param mixed $index Index for item to be fetched from $_POST + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function post($index = NULL, $xss_clean = NULL) + { + return $this->_fetch_from_array($_POST, $index, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from POST data with fallback to GET + * + * @param string $index Index for item to be fetched from $_POST or $_GET + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function post_get($index, $xss_clean = NULL) + { + return isset($_POST[$index]) + ? $this->post($index, $xss_clean) + : $this->get($index, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from GET data with fallback to POST + * + * @param string $index Index for item to be fetched from $_GET or $_POST + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function get_post($index, $xss_clean = NULL) + { + return isset($_GET[$index]) + ? $this->get($index, $xss_clean) + : $this->post($index, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the COOKIE array + * + * @param mixed $index Index for item to be fetched from $_COOKIE + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function cookie($index = NULL, $xss_clean = NULL) + { + return $this->_fetch_from_array($_COOKIE, $index, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the SERVER array + * + * @param mixed $index Index for item to be fetched from $_SERVER + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function server($index, $xss_clean = NULL) + { + return $this->_fetch_from_array($_SERVER, $index, $xss_clean); + } + + // ------------------------------------------------------------------------ + + /** + * Fetch an item from the php://input stream + * + * Useful when you need to access PUT, DELETE or PATCH request data. + * + * @param string $index Index for item to be fetched + * @param bool $xss_clean Whether to apply XSS filtering + * @return mixed + */ + public function input_stream($index = NULL, $xss_clean = NULL) + { + // Prior to PHP 5.6, the input stream can only be read once, + // so we'll need to check if we have already done that first. + if ( ! is_array($this->_input_stream)) + { + // $this->raw_input_stream will trigger __get(). + parse_str($this->raw_input_stream, $this->_input_stream); + is_array($this->_input_stream) OR $this->_input_stream = array(); + } + + return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean); + } + + // ------------------------------------------------------------------------ + + /** + * Set cookie + * + * Accepts an arbitrary number of parameters (up to 7) or an associative + * array in the first parameter containing all the values. + * + * @param string|mixed[] $name Cookie name or an array containing parameters + * @param string $value Cookie value + * @param int $expire Cookie expiration time in seconds + * @param string $domain Cookie domain (e.g.: '.yourdomain.com') + * @param string $path Cookie path (default: '/') + * @param string $prefix Cookie name prefix + * @param bool $secure Whether to only transfer cookies via SSL + * @param bool $httponly Whether to only makes the cookie accessible via HTTP (no javascript) + * @return void + */ + public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL) + { + if (is_array($name)) + { + // always leave 'name' in last place, as the loop will break otherwise, due to $$item + foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name') as $item) + { + if (isset($name[$item])) + { + $$item = $name[$item]; + } + } + } + + if ($prefix === '' && config_item('cookie_prefix') !== '') + { + $prefix = config_item('cookie_prefix'); + } + + if ($domain == '' && config_item('cookie_domain') != '') + { + $domain = config_item('cookie_domain'); + } + + if ($path === '/' && config_item('cookie_path') !== '/') + { + $path = config_item('cookie_path'); + } + + $secure = ($secure === NULL && config_item('cookie_secure') !== NULL) + ? (bool) config_item('cookie_secure') + : (bool) $secure; + + $httponly = ($httponly === NULL && config_item('cookie_httponly') !== NULL) + ? (bool) config_item('cookie_httponly') + : (bool) $httponly; + + if ( ! is_numeric($expire)) + { + $expire = time() - 86500; + } + else + { + $expire = ($expire > 0) ? time() + $expire : 0; + } + + setcookie($prefix.$name, $value, $expire, $path, $domain, $secure, $httponly); + } + + // -------------------------------------------------------------------- + + /** + * Fetch the IP Address + * + * Determines and validates the visitor's IP address. + * + * @return string IP address + */ + public function ip_address() + { + if ($this->ip_address !== FALSE) + { + return $this->ip_address; + } + + $proxy_ips = config_item('proxy_ips'); + if ( ! empty($proxy_ips) && ! is_array($proxy_ips)) + { + $proxy_ips = explode(',', str_replace(' ', '', $proxy_ips)); + } + + $this->ip_address = $this->server('REMOTE_ADDR'); + + if ($proxy_ips) + { + foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header) + { + if (($spoof = $this->server($header)) !== NULL) + { + // Some proxies typically list the whole chain of IP + // addresses through which the client has reached us. + // e.g. client_ip, proxy_ip1, proxy_ip2, etc. + sscanf($spoof, '%[^,]', $spoof); + + if ( ! $this->valid_ip($spoof)) + { + $spoof = NULL; + } + else + { + break; + } + } + } + + if ($spoof) + { + for ($i = 0, $c = count($proxy_ips); $i < $c; $i++) + { + // Check if we have an IP address or a subnet + if (strpos($proxy_ips[$i], '/') === FALSE) + { + // An IP address (and not a subnet) is specified. + // We can compare right away. + if ($proxy_ips[$i] === $this->ip_address) + { + $this->ip_address = $spoof; + break; + } + + continue; + } + + // We have a subnet ... now the heavy lifting begins + isset($separator) OR $separator = $this->valid_ip($this->ip_address, 'ipv6') ? ':' : '.'; + + // If the proxy entry doesn't match the IP protocol - skip it + if (strpos($proxy_ips[$i], $separator) === FALSE) + { + continue; + } + + // Convert the REMOTE_ADDR IP address to binary, if needed + if ( ! isset($ip, $sprintf)) + { + if ($separator === ':') + { + // Make sure we're have the "full" IPv6 format + $ip = explode(':', + str_replace('::', + str_repeat(':', 9 - substr_count($this->ip_address, ':')), + $this->ip_address + ) + ); + + for ($j = 0; $j < 8; $j++) + { + $ip[$j] = intval($ip[$j], 16); + } + + $sprintf = '%016b%016b%016b%016b%016b%016b%016b%016b'; + } + else + { + $ip = explode('.', $this->ip_address); + $sprintf = '%08b%08b%08b%08b'; + } + + $ip = vsprintf($sprintf, $ip); + } + + // Split the netmask length off the network address + sscanf($proxy_ips[$i], '%[^/]/%d', $netaddr, $masklen); + + // Again, an IPv6 address is most likely in a compressed form + if ($separator === ':') + { + $netaddr = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr)); + for ($j = 0; $j < 8; $j++) + { + $netaddr[$j] = intval($netaddr[$j], 16); + } + } + else + { + $netaddr = explode('.', $netaddr); + } + + // Convert to binary and finally compare + if (strncmp($ip, vsprintf($sprintf, $netaddr), $masklen) === 0) + { + $this->ip_address = $spoof; + break; + } + } + } + } + + if ( ! $this->valid_ip($this->ip_address)) + { + return $this->ip_address = '0.0.0.0'; + } + + return $this->ip_address; + } + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * @param string $ip IP address + * @param string $which IP protocol: 'ipv4' or 'ipv6' + * @return bool + */ + public function valid_ip($ip, $which = '') + { + switch (strtolower($which)) + { + case 'ipv4': + $which = FILTER_FLAG_IPV4; + break; + case 'ipv6': + $which = FILTER_FLAG_IPV6; + break; + default: + $which = NULL; + break; + } + + return (bool) filter_var($ip, FILTER_VALIDATE_IP, $which); + } + + // -------------------------------------------------------------------- + + /** + * Fetch User Agent string + * + * @return string|null User Agent string or NULL if it doesn't exist + */ + public function user_agent($xss_clean = NULL) + { + return $this->_fetch_from_array($_SERVER, 'HTTP_USER_AGENT', $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Sanitize Globals + * + * Internal method serving for the following purposes: + * + * - Unsets $_GET data, if query strings are not enabled + * - Cleans POST, COOKIE and SERVER data + * - Standardizes newline characters to PHP_EOL + * + * @return void + */ + protected function _sanitize_globals() + { + // Is $_GET data allowed? If not we'll set the $_GET to an empty array + if ($this->_allow_get_array === FALSE) + { + $_GET = array(); + } + elseif (is_array($_GET)) + { + foreach ($_GET as $key => $val) + { + $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + + // Clean $_POST Data + if (is_array($_POST)) + { + foreach ($_POST as $key => $val) + { + $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + + // Clean $_COOKIE Data + if (is_array($_COOKIE)) + { + // Also get rid of specially treated cookies that might be set by a server + // or silly application, that are of no use to a CI application anyway + // but that when present will trip our 'Disallowed Key Characters' alarm + // http://www.ietf.org/rfc/rfc2109.txt + // note that the key names below are single quoted strings, and are not PHP variables + unset( + $_COOKIE['$Version'], + $_COOKIE['$Path'], + $_COOKIE['$Domain'] + ); + + foreach ($_COOKIE as $key => $val) + { + if (($cookie_key = $this->_clean_input_keys($key)) !== FALSE) + { + $_COOKIE[$cookie_key] = $this->_clean_input_data($val); + } + else + { + unset($_COOKIE[$key]); + } + } + } + + // Sanitize PHP_SELF + $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']); + + log_message('debug', 'Global POST, GET and COOKIE data sanitized'); + } + + // -------------------------------------------------------------------- + + /** + * Clean Input Data + * + * Internal method that aids in escaping data and + * standardizing newline characters to PHP_EOL. + * + * @param string|string[] $str Input string(s) + * @return string + */ + protected function _clean_input_data($str) + { + if (is_array($str)) + { + $new_array = array(); + foreach (array_keys($str) as $key) + { + $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($str[$key]); + } + return $new_array; + } + + /* We strip slashes if magic quotes is on to keep things consistent + + NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and + it will probably not exist in future versions at all. + */ + if ( ! is_php('5.4') && get_magic_quotes_gpc()) + { + $str = stripslashes($str); + } + + // Clean UTF-8 if supported + if (UTF8_ENABLED === TRUE) + { + $str = $this->uni->clean_string($str); + } + + // Remove control characters + $str = remove_invisible_characters($str, FALSE); + + // Standardize newlines if needed + if ($this->_standardize_newlines === TRUE) + { + return preg_replace('/(?:\r\n|[\r\n])/', PHP_EOL, $str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Clean Keys + * + * Internal method that helps to prevent malicious users + * from trying to exploit keys we make sure that keys are + * only named with alpha-numeric text and a few other items. + * + * @param string $str Input string + * @param bool $fatal Whether to terminate script exection + * or to return FALSE if an invalid + * key is encountered + * @return string|bool + */ + protected function _clean_input_keys($str, $fatal = TRUE) + { + if ( ! preg_match('/^[a-z0-9:_\/|-]+$/i', $str)) + { + if ($fatal === TRUE) + { + return FALSE; + } + else + { + set_status_header(503); + echo 'Disallowed Key Characters.'; + exit(7); // EXIT_USER_INPUT + } + } + + // Clean UTF-8 if supported + if (UTF8_ENABLED === TRUE) + { + return $this->uni->clean_string($str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Request Headers + * + * @param bool $xss_clean Whether to apply XSS filtering + * @return array + */ + public function request_headers($xss_clean = FALSE) + { + // If header is already defined, return it immediately + if ( ! empty($this->headers)) + { + return $this->_fetch_from_array($this->headers, NULL, $xss_clean); + } + + // In Apache, you can simply call apache_request_headers() + if (function_exists('apache_request_headers')) + { + $this->headers = apache_request_headers(); + } + else + { + isset($_SERVER['CONTENT_TYPE']) && $this->headers['Content-Type'] = $_SERVER['CONTENT_TYPE']; + + foreach ($_SERVER as $key => $val) + { + if (sscanf($key, 'HTTP_%s', $header) === 1) + { + // take SOME_HEADER and turn it into Some-Header + $header = str_replace('_', ' ', strtolower($header)); + $header = str_replace(' ', '-', ucwords($header)); + + $this->headers[$header] = $_SERVER[$key]; + } + } + } + + return $this->_fetch_from_array($this->headers, NULL, $xss_clean); + } + + // -------------------------------------------------------------------- + + /** + * Get Request Header + * + * Returns the value of a single member of the headers class member + * + * @param string $index Header name + * @param bool $xss_clean Whether to apply XSS filtering + * @return string|null The requested header on success or NULL on failure + */ + public function get_request_header($index, $xss_clean = FALSE) + { + static $headers; + + if ( ! isset($headers)) + { + empty($this->headers) && $this->request_headers(); + foreach ($this->headers as $key => $value) + { + $headers[strtolower($key)] = $value; + } + } + + $index = strtolower($index); + + if ( ! isset($headers[$index])) + { + return NULL; + } + + return ($xss_clean === TRUE) + ? $this->security->xss_clean($headers[$index]) + : $headers[$index]; + } + + // -------------------------------------------------------------------- + + /** + * Is AJAX request? + * + * Test to see if a request contains the HTTP_X_REQUESTED_WITH header. + * + * @return bool + */ + public function is_ajax_request() + { + return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); + } + + // -------------------------------------------------------------------- + + /** + * Is CLI request? + * + * Test to see if a request was made from the command line. + * + * @deprecated 3.0.0 Use is_cli() instead + * @return bool + */ + public function is_cli_request() + { + return is_cli(); + } + + // -------------------------------------------------------------------- + + /** + * Get Request Method + * + * Return the request method + * + * @param bool $upper Whether to return in upper or lower case + * (default: FALSE) + * @return string + */ + public function method($upper = FALSE) + { + return ($upper) + ? strtoupper($this->server('REQUEST_METHOD')) + : strtolower($this->server('REQUEST_METHOD')); + } + + // ------------------------------------------------------------------------ + + /** + * Magic __get() + * + * Allows read access to protected properties + * + * @param string $name + * @return mixed + */ + public function __get($name) + { + if ($name === 'raw_input_stream') + { + isset($this->_raw_input_stream) OR $this->_raw_input_stream = file_get_contents('php://input'); + return $this->_raw_input_stream; + } + elseif ($name === 'ip_address') + { + return $this->ip_address; + } + } + +} diff --git a/system/core/Lang.php b/system/core/Lang.php new file mode 100644 index 0000000..2c8654d --- /dev/null +++ b/system/core/Lang.php @@ -0,0 +1,203 @@ +load($value, $idiom, $return, $add_suffix, $alt_path); + } + + return; + } + + $langfile = str_replace('.php', '', $langfile); + + if ($add_suffix === TRUE) + { + $langfile = preg_replace('/_lang$/', '', $langfile).'_lang'; + } + + $langfile .= '.php'; + + if (empty($idiom) OR ! preg_match('/^[a-z_-]+$/i', $idiom)) + { + $config =& get_config(); + $idiom = empty($config['language']) ? 'english' : $config['language']; + } + + if ($return === FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom) + { + return; + } + + // Load the base file, so any others found can override it + $basepath = BASEPATH.'language/'.$idiom.'/'.$langfile; + if (($found = file_exists($basepath)) === TRUE) + { + include($basepath); + } + + // Do we have an alternative path to look in? + if ($alt_path !== '') + { + $alt_path .= 'language/'.$idiom.'/'.$langfile; + if (file_exists($alt_path)) + { + include($alt_path); + $found = TRUE; + } + } + else + { + foreach (get_instance()->load->get_package_paths(TRUE) as $package_path) + { + $package_path .= 'language/'.$idiom.'/'.$langfile; + if ($basepath !== $package_path && file_exists($package_path)) + { + include($package_path); + $found = TRUE; + break; + } + } + } + + if ($found !== TRUE) + { + show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile); + } + + if ( ! isset($lang) OR ! is_array($lang)) + { + log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); + + if ($return === TRUE) + { + return array(); + } + return; + } + + if ($return === TRUE) + { + return $lang; + } + + $this->is_loaded[$langfile] = $idiom; + $this->language = array_merge($this->language, $lang); + + log_message('info', 'Language file loaded: language/'.$idiom.'/'.$langfile); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Language line + * + * Fetches a single line of text from the language array + * + * @param string $line Language line key + * @param bool $log_errors Whether to log an error message if the line is not found + * @return string Translation + */ + public function line($line, $log_errors = TRUE) + { + $value = isset($this->language[$line]) ? $this->language[$line] : FALSE; + + // Because killer robots like unicorns! + if ($value === FALSE && $log_errors === TRUE) + { + log_message('error', 'Could not find the language line "'.$line.'"'); + } + + return $value; + } + +} diff --git a/system/core/Loader.php b/system/core/Loader.php new file mode 100644 index 0000000..14888e4 --- /dev/null +++ b/system/core/Loader.php @@ -0,0 +1,1415 @@ + TRUE); + + /** + * List of paths to load libraries from + * + * @var array + */ + protected $_ci_library_paths = array(APPPATH, BASEPATH); + + /** + * List of paths to load models from + * + * @var array + */ + protected $_ci_model_paths = array(APPPATH); + + /** + * List of paths to load helpers from + * + * @var array + */ + protected $_ci_helper_paths = array(APPPATH, BASEPATH); + + /** + * List of cached variables + * + * @var array + */ + protected $_ci_cached_vars = array(); + + /** + * List of loaded classes + * + * @var array + */ + protected $_ci_classes = array(); + + /** + * List of loaded models + * + * @var array + */ + protected $_ci_models = array(); + + /** + * List of loaded helpers + * + * @var array + */ + protected $_ci_helpers = array(); + + /** + * List of class name mappings + * + * @var array + */ + protected $_ci_varmap = array( + 'unit_test' => 'unit', + 'user_agent' => 'agent' + ); + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * Sets component load paths, gets the initial output buffering level. + * + * @return void + */ + public function __construct() + { + $this->_ci_ob_level = ob_get_level(); + $this->_ci_classes =& is_loaded(); + + log_message('info', 'Loader Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initializer + * + * @todo Figure out a way to move this to the constructor + * without breaking *package_path*() methods. + * @uses CI_Loader::_ci_autoloader() + * @used-by CI_Controller::__construct() + * @return void + */ + public function initialize() + { + $this->_ci_autoloader(); + } + + // -------------------------------------------------------------------- + + /** + * Is Loaded + * + * A utility method to test if a class is in the self::$_ci_classes array. + * + * @used-by Mainly used by Form Helper function _get_validation_object(). + * + * @param string $class Class name to check for + * @return string|bool Class object name if loaded or FALSE + */ + public function is_loaded($class) + { + return array_search(ucfirst($class), $this->_ci_classes, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Library Loader + * + * Loads and instantiates libraries. + * Designed to be called from application controllers. + * + * @param mixed $library Library name + * @param array $params Optional parameters to pass to the library class constructor + * @param string $object_name An optional object name to assign to + * @return object + */ + public function library($library, $params = NULL, $object_name = NULL) + { + if (empty($library)) + { + return $this; + } + elseif (is_array($library)) + { + foreach ($library as $key => $value) + { + if (is_int($key)) + { + $this->library($value, $params); + } + else + { + $this->library($key, $params, $value); + } + } + + return $this; + } + + if ($params !== NULL && ! is_array($params)) + { + $params = NULL; + } + + $this->_ci_load_library($library, $params, $object_name); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Model Loader + * + * Loads and instantiates models. + * + * @param mixed $model Model name + * @param string $name An optional object name to assign to + * @param bool $db_conn An optional database connection configuration to initialize + * @return object + */ + public function model($model, $name = '', $db_conn = FALSE) + { + if (empty($model)) + { + return $this; + } + elseif (is_array($model)) + { + foreach ($model as $key => $value) + { + is_int($key) ? $this->model($value, '', $db_conn) : $this->model($key, $value, $db_conn); + } + + return $this; + } + + $path = ''; + + // Is the model in a sub-folder? If so, parse out the filename and path. + if (($last_slash = strrpos($model, '/')) !== FALSE) + { + // The path is in front of the last slash + $path = substr($model, 0, ++$last_slash); + + // And the model name behind it + $model = substr($model, $last_slash); + } + + if (empty($name)) + { + $name = $model; + } + + if (in_array($name, $this->_ci_models, TRUE)) + { + return $this; + } + + $CI =& get_instance(); + if (isset($CI->$name)) + { + throw new RuntimeException('The model name you are loading is the name of a resource that is already being used: '.$name); + } + + if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE)) + { + if ($db_conn === TRUE) + { + $db_conn = ''; + } + + $this->database($db_conn, FALSE, TRUE); + } + + // Note: All of the code under this condition used to be just: + // + // load_class('Model', 'core'); + // + // However, load_class() instantiates classes + // to cache them for later use and that prevents + // MY_Model from being an abstract class and is + // sub-optimal otherwise anyway. + if ( ! class_exists('CI_Model', FALSE)) + { + $app_path = APPPATH.'core'.DIRECTORY_SEPARATOR; + if (file_exists($app_path.'Model.php')) + { + require_once($app_path.'Model.php'); + if ( ! class_exists('CI_Model', FALSE)) + { + throw new RuntimeException($app_path."Model.php exists, but doesn't declare class CI_Model"); + } + + log_message('info', 'CI_Model class loaded'); + } + elseif ( ! class_exists('CI_Model', FALSE)) + { + require_once(BASEPATH.'core'.DIRECTORY_SEPARATOR.'Model.php'); + } + + $class = config_item('subclass_prefix').'Model'; + if (file_exists($app_path.$class.'.php')) + { + require_once($app_path.$class.'.php'); + if ( ! class_exists($class, FALSE)) + { + throw new RuntimeException($app_path.$class.".php exists, but doesn't declare class ".$class); + } + + log_message('info', config_item('subclass_prefix').'Model class loaded'); + } + } + + $model = ucfirst($model); + if ( ! class_exists($model, FALSE)) + { + foreach ($this->_ci_model_paths as $mod_path) + { + if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) + { + continue; + } + + require_once($mod_path.'models/'.$path.$model.'.php'); + if ( ! class_exists($model, FALSE)) + { + throw new RuntimeException($mod_path."models/".$path.$model.".php exists, but doesn't declare class ".$model); + } + + break; + } + + if ( ! class_exists($model, FALSE)) + { + throw new RuntimeException('Unable to locate the model you have specified: '.$model); + } + } + elseif ( ! is_subclass_of($model, 'CI_Model')) + { + throw new RuntimeException("Class ".$model." already exists and doesn't extend CI_Model"); + } + + $this->_ci_models[] = $name; + $model = new $model(); + $CI->$name = $model; + log_message('info', 'Model "'.get_class($model).'" initialized'); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Database Loader + * + * @param mixed $params Database configuration options + * @param bool $return Whether to return the database object + * @param bool $query_builder Whether to enable Query Builder + * (overrides the configuration setting) + * + * @return object|bool Database object if $return is set to TRUE, + * FALSE on failure, CI_Loader instance in any other case + */ + public function database($params = '', $return = FALSE, $query_builder = NULL) + { + // Grab the super object + $CI =& get_instance(); + + // Do we even need to load the database class? + if ($return === FALSE && $query_builder === NULL && isset($CI->db) && is_object($CI->db) && ! empty($CI->db->conn_id)) + { + return FALSE; + } + + require_once(BASEPATH.'database/DB.php'); + + if ($return === TRUE) + { + return DB($params, $query_builder); + } + + // Initialize the db variable. Needed to prevent + // reference errors with some configurations + $CI->db = ''; + + // Load the DB class + $CI->db =& DB($params, $query_builder); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Load the Database Utilities Class + * + * @param object $db Database object + * @param bool $return Whether to return the DB Utilities class object or not + * @return object + */ + public function dbutil($db = NULL, $return = FALSE) + { + $CI =& get_instance(); + + if ( ! is_object($db) OR ! ($db instanceof CI_DB)) + { + class_exists('CI_DB', FALSE) OR $this->database(); + $db =& $CI->db; + } + + require_once(BASEPATH.'database/DB_utility.php'); + require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_utility.php'); + $class = 'CI_DB_'.$db->dbdriver.'_utility'; + + if ($return === TRUE) + { + return new $class($db); + } + + $CI->dbutil = new $class($db); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Load the Database Forge Class + * + * @param object $db Database object + * @param bool $return Whether to return the DB Forge class object or not + * @return object + */ + public function dbforge($db = NULL, $return = FALSE) + { + $CI =& get_instance(); + if ( ! is_object($db) OR ! ($db instanceof CI_DB)) + { + class_exists('CI_DB', FALSE) OR $this->database(); + $db =& $CI->db; + } + + require_once(BASEPATH.'database/DB_forge.php'); + require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_forge.php'); + + if ( ! empty($db->subdriver)) + { + $driver_path = BASEPATH.'database/drivers/'.$db->dbdriver.'/subdrivers/'.$db->dbdriver.'_'.$db->subdriver.'_forge.php'; + if (file_exists($driver_path)) + { + require_once($driver_path); + $class = 'CI_DB_'.$db->dbdriver.'_'.$db->subdriver.'_forge'; + } + } + else + { + $class = 'CI_DB_'.$db->dbdriver.'_forge'; + } + + if ($return === TRUE) + { + return new $class($db); + } + + $CI->dbforge = new $class($db); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * View Loader + * + * Loads "view" files. + * + * @param string $view View name + * @param array $vars An associative array of data + * to be extracted for use in the view + * @param bool $return Whether to return the view output + * or leave it to the Output class + * @return object|string + */ + public function view($view, $vars = array(), $return = FALSE) + { + return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return)); + } + + // -------------------------------------------------------------------- + + /** + * Generic File Loader + * + * @param string $path File path + * @param bool $return Whether to return the file output + * @return object|string + */ + public function file($path, $return = FALSE) + { + return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); + } + + // -------------------------------------------------------------------- + + /** + * Set Variables + * + * Once variables are set they become available within + * the controller class and its "view" files. + * + * @param array|object|string $vars + * An associative array or object containing values + * to be set, or a value's name if string + * @param string $val Value to set, only used if $vars is a string + * @return object + */ + public function vars($vars, $val = '') + { + $vars = is_string($vars) + ? array($vars => $val) + : $this->_ci_prepare_view_vars($vars); + + foreach ($vars as $key => $val) + { + $this->_ci_cached_vars[$key] = $val; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Clear Cached Variables + * + * Clears the cached variables. + * + * @return CI_Loader + */ + public function clear_vars() + { + $this->_ci_cached_vars = array(); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get Variable + * + * Check if a variable is set and retrieve it. + * + * @param string $key Variable name + * @return mixed The variable or NULL if not found + */ + public function get_var($key) + { + return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL; + } + + // -------------------------------------------------------------------- + + /** + * Get Variables + * + * Retrieves all loaded variables. + * + * @return array + */ + public function get_vars() + { + return $this->_ci_cached_vars; + } + + // -------------------------------------------------------------------- + + /** + * Helper Loader + * + * @param string|string[] $helpers Helper name(s) + * @return object + */ + public function helper($helpers = array()) + { + is_array($helpers) OR $helpers = array($helpers); + foreach ($helpers as &$helper) + { + $filename = basename($helper); + $filepath = ($filename === $helper) ? '' : substr($helper, 0, strlen($helper) - strlen($filename)); + $filename = strtolower(preg_replace('#(_helper)?(\.php)?$#i', '', $filename)).'_helper'; + $helper = $filepath.$filename; + + if (isset($this->_ci_helpers[$helper])) + { + continue; + } + + // Is this a helper extension request? + $ext_helper = config_item('subclass_prefix').$filename; + $ext_loaded = FALSE; + foreach ($this->_ci_helper_paths as $path) + { + if (file_exists($path.'helpers/'.$ext_helper.'.php')) + { + include_once($path.'helpers/'.$ext_helper.'.php'); + $ext_loaded = TRUE; + } + } + + // If we have loaded extensions - check if the base one is here + if ($ext_loaded === TRUE) + { + $base_helper = BASEPATH.'helpers/'.$helper.'.php'; + if ( ! file_exists($base_helper)) + { + show_error('Unable to load the requested file: helpers/'.$helper.'.php'); + } + + include_once($base_helper); + $this->_ci_helpers[$helper] = TRUE; + log_message('info', 'Helper loaded: '.$helper); + continue; + } + + // No extensions found ... try loading regular helpers and/or overrides + foreach ($this->_ci_helper_paths as $path) + { + if (file_exists($path.'helpers/'.$helper.'.php')) + { + include_once($path.'helpers/'.$helper.'.php'); + + $this->_ci_helpers[$helper] = TRUE; + log_message('info', 'Helper loaded: '.$helper); + break; + } + } + + // unable to load the helper + if ( ! isset($this->_ci_helpers[$helper])) + { + show_error('Unable to load the requested file: helpers/'.$helper.'.php'); + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Load Helpers + * + * An alias for the helper() method in case the developer has + * written the plural form of it. + * + * @uses CI_Loader::helper() + * @param string|string[] $helpers Helper name(s) + * @return object + */ + public function helpers($helpers = array()) + { + return $this->helper($helpers); + } + + // -------------------------------------------------------------------- + + /** + * Language Loader + * + * Loads language files. + * + * @param string|string[] $files List of language file names to load + * @param string Language name + * @return object + */ + public function language($files, $lang = '') + { + get_instance()->lang->load($files, $lang); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Config Loader + * + * Loads a config file (an alias for CI_Config::load()). + * + * @uses CI_Config::load() + * @param string $file Configuration file name + * @param bool $use_sections Whether configuration values should be loaded into their own section + * @param bool $fail_gracefully Whether to just return FALSE or display an error message + * @return bool TRUE if the file was loaded correctly or FALSE on failure + */ + public function config($file, $use_sections = FALSE, $fail_gracefully = FALSE) + { + return get_instance()->config->load($file, $use_sections, $fail_gracefully); + } + + // -------------------------------------------------------------------- + + /** + * Driver Loader + * + * Loads a driver library. + * + * @param string|string[] $library Driver name(s) + * @param array $params Optional parameters to pass to the driver + * @param string $object_name An optional object name to assign to + * + * @return object|bool Object or FALSE on failure if $library is a string + * and $object_name is set. CI_Loader instance otherwise. + */ + public function driver($library, $params = NULL, $object_name = NULL) + { + if (is_array($library)) + { + foreach ($library as $key => $value) + { + if (is_int($key)) + { + $this->driver($value, $params); + } + else + { + $this->driver($key, $params, $value); + } + } + + return $this; + } + elseif (empty($library)) + { + return FALSE; + } + + if ( ! class_exists('CI_Driver_Library', FALSE)) + { + // We aren't instantiating an object here, just making the base class available + require BASEPATH.'libraries/Driver.php'; + } + + // We can save the loader some time since Drivers will *always* be in a subfolder, + // and typically identically named to the library + if ( ! strpos($library, '/')) + { + $library = ucfirst($library).'/'.$library; + } + + return $this->library($library, $params, $object_name); + } + + // -------------------------------------------------------------------- + + /** + * Add Package Path + * + * Prepends a parent path to the library, model, helper and config + * path arrays. + * + * @see CI_Loader::$_ci_library_paths + * @see CI_Loader::$_ci_model_paths + * @see CI_Loader::$_ci_helper_paths + * @see CI_Config::$_config_paths + * + * @param string $path Path to add + * @param bool $view_cascade (default: TRUE) + * @return object + */ + public function add_package_path($path, $view_cascade = TRUE) + { + $path = rtrim($path, '/').'/'; + + array_unshift($this->_ci_library_paths, $path); + array_unshift($this->_ci_model_paths, $path); + array_unshift($this->_ci_helper_paths, $path); + + $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths; + + // Add config file path + $config =& $this->_ci_get_component('config'); + $config->_config_paths[] = $path; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get Package Paths + * + * Return a list of all package paths. + * + * @param bool $include_base Whether to include BASEPATH (default: FALSE) + * @return array + */ + public function get_package_paths($include_base = FALSE) + { + return ($include_base === TRUE) ? $this->_ci_library_paths : $this->_ci_model_paths; + } + + // -------------------------------------------------------------------- + + /** + * Remove Package Path + * + * Remove a path from the library, model, helper and/or config + * path arrays if it exists. If no path is provided, the most recently + * added path will be removed removed. + * + * @param string $path Path to remove + * @return object + */ + public function remove_package_path($path = '') + { + $config =& $this->_ci_get_component('config'); + + if ($path === '') + { + array_shift($this->_ci_library_paths); + array_shift($this->_ci_model_paths); + array_shift($this->_ci_helper_paths); + array_shift($this->_ci_view_paths); + array_pop($config->_config_paths); + } + else + { + $path = rtrim($path, '/').'/'; + foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var) + { + if (($key = array_search($path, $this->{$var})) !== FALSE) + { + unset($this->{$var}[$key]); + } + } + + if (isset($this->_ci_view_paths[$path.'views/'])) + { + unset($this->_ci_view_paths[$path.'views/']); + } + + if (($key = array_search($path, $config->_config_paths)) !== FALSE) + { + unset($config->_config_paths[$key]); + } + } + + // make sure the application default paths are still in the array + $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH))); + $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH))); + $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH))); + $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE)); + $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH))); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Internal CI Data Loader + * + * Used to load views and files. + * + * Variables are prefixed with _ci_ to avoid symbol collision with + * variables made available to view files. + * + * @used-by CI_Loader::view() + * @used-by CI_Loader::file() + * @param array $_ci_data Data to load + * @return object + */ + protected function _ci_load($_ci_data) + { + // Set the default data variables + foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) + { + $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE; + } + + $file_exists = FALSE; + + // Set the path to the requested file + if (is_string($_ci_path) && $_ci_path !== '') + { + $_ci_x = explode('/', $_ci_path); + $_ci_file = end($_ci_x); + } + else + { + $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); + $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view; + + foreach ($this->_ci_view_paths as $_ci_view_file => $cascade) + { + if (file_exists($_ci_view_file.$_ci_file)) + { + $_ci_path = $_ci_view_file.$_ci_file; + $file_exists = TRUE; + break; + } + + if ( ! $cascade) + { + break; + } + } + } + + if ( ! $file_exists && ! file_exists($_ci_path)) + { + show_error('Unable to load the requested file: '.$_ci_file); + } + + // This allows anything loaded using $this->load (views, files, etc.) + // to become accessible from within the Controller and Model functions. + $_ci_CI =& get_instance(); + foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) + { + if ( ! isset($this->$_ci_key)) + { + $this->$_ci_key =& $_ci_CI->$_ci_key; + } + } + + /* + * Extract and cache variables + * + * You can either set variables using the dedicated $this->load->vars() + * function or via the second parameter of this function. We'll merge + * the two types and cache them so that views that are embedded within + * other views can have access to these variables. + */ + empty($_ci_vars) OR $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); + extract($this->_ci_cached_vars); + + /* + * Buffer the output + * + * We buffer the output for two reasons: + * 1. Speed. You get a significant speed boost. + * 2. So that the final rendered template can be post-processed by + * the output class. Why do we need post processing? For one thing, + * in order to show the elapsed page load time. Unless we can + * intercept the content right before it's sent to the browser and + * then stop the timer it won't be accurate. + */ + ob_start(); + + // If the PHP installation does not support short tags we'll + // do a little string replacement, changing the short tags + // to standard PHP echo statements. + if ( ! is_php('5.4') && ! ini_get('short_open_tag') && config_item('rewrite_short_tags') === TRUE) + { + echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace(' $this->_ci_ob_level + 1) + { + ob_end_flush(); + } + else + { + $_ci_CI->output->append_output(ob_get_contents()); + @ob_end_clean(); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Internal CI Library Loader + * + * @used-by CI_Loader::library() + * @uses CI_Loader::_ci_init_library() + * + * @param string $class Class name to load + * @param mixed $params Optional parameters to pass to the class constructor + * @param string $object_name Optional object name to assign to + * @return void + */ + protected function _ci_load_library($class, $params = NULL, $object_name = NULL) + { + // Get the class name, and while we're at it trim any slashes. + // The directory path can be included as part of the class name, + // but we don't want a leading slash + $class = str_replace('.php', '', trim($class, '/')); + + // Was the path included with the class name? + // We look for a slash to determine this + if (($last_slash = strrpos($class, '/')) !== FALSE) + { + // Extract the path + $subdir = substr($class, 0, ++$last_slash); + + // Get the filename from the path + $class = substr($class, $last_slash); + } + else + { + $subdir = ''; + } + + $class = ucfirst($class); + + // Is this a stock library? There are a few special conditions if so ... + if (file_exists(BASEPATH.'libraries/'.$subdir.$class.'.php')) + { + return $this->_ci_load_stock_library($class, $subdir, $params, $object_name); + } + + // Safety: Was the class already loaded by a previous call? + if (class_exists($class, FALSE)) + { + $property = $object_name; + if (empty($property)) + { + $property = strtolower($class); + isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property]; + } + + $CI =& get_instance(); + if (isset($CI->$property)) + { + log_message('debug', $class.' class already loaded. Second attempt ignored.'); + return; + } + + return $this->_ci_init_library($class, '', $params, $object_name); + } + + // Let's search for the requested library file and load it. + foreach ($this->_ci_library_paths as $path) + { + // BASEPATH has already been checked for + if ($path === BASEPATH) + { + continue; + } + + $filepath = $path.'libraries/'.$subdir.$class.'.php'; + // Does the file exist? No? Bummer... + if ( ! file_exists($filepath)) + { + continue; + } + + include_once($filepath); + return $this->_ci_init_library($class, '', $params, $object_name); + } + + // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? + if ($subdir === '') + { + return $this->_ci_load_library($class.'/'.$class, $params, $object_name); + } + + // If we got this far we were unable to find the requested class. + log_message('error', 'Unable to load the requested class: '.$class); + show_error('Unable to load the requested class: '.$class); + } + + // -------------------------------------------------------------------- + + /** + * Internal CI Stock Library Loader + * + * @used-by CI_Loader::_ci_load_library() + * @uses CI_Loader::_ci_init_library() + * + * @param string $library_name Library name to load + * @param string $file_path Path to the library filename, relative to libraries/ + * @param mixed $params Optional parameters to pass to the class constructor + * @param string $object_name Optional object name to assign to + * @return void + */ + protected function _ci_load_stock_library($library_name, $file_path, $params, $object_name) + { + $prefix = 'CI_'; + + if (class_exists($prefix.$library_name, FALSE)) + { + if (class_exists(config_item('subclass_prefix').$library_name, FALSE)) + { + $prefix = config_item('subclass_prefix'); + } + + $property = $object_name; + if (empty($property)) + { + $property = strtolower($library_name); + isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property]; + } + + $CI =& get_instance(); + if ( ! isset($CI->$property)) + { + return $this->_ci_init_library($library_name, $prefix, $params, $object_name); + } + + log_message('debug', $library_name.' class already loaded. Second attempt ignored.'); + return; + } + + $paths = $this->_ci_library_paths; + array_pop($paths); // BASEPATH + array_pop($paths); // APPPATH (needs to be the first path checked) + array_unshift($paths, APPPATH); + + foreach ($paths as $path) + { + if (file_exists($path = $path.'libraries/'.$file_path.$library_name.'.php')) + { + // Override + include_once($path); + if (class_exists($prefix.$library_name, FALSE)) + { + return $this->_ci_init_library($library_name, $prefix, $params, $object_name); + } + + log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name); + } + } + + include_once(BASEPATH.'libraries/'.$file_path.$library_name.'.php'); + + // Check for extensions + $subclass = config_item('subclass_prefix').$library_name; + foreach ($paths as $path) + { + if (file_exists($path = $path.'libraries/'.$file_path.$subclass.'.php')) + { + include_once($path); + if (class_exists($subclass, FALSE)) + { + $prefix = config_item('subclass_prefix'); + break; + } + + log_message('debug', $path.' exists, but does not declare '.$subclass); + } + } + + return $this->_ci_init_library($library_name, $prefix, $params, $object_name); + } + + // -------------------------------------------------------------------- + + /** + * Internal CI Library Instantiator + * + * @used-by CI_Loader::_ci_load_stock_library() + * @used-by CI_Loader::_ci_load_library() + * + * @param string $class Class name + * @param string $prefix Class name prefix + * @param array|null|bool $config Optional configuration to pass to the class constructor: + * FALSE to skip; + * NULL to search in config paths; + * array containing configuration data + * @param string $object_name Optional object name to assign to + * @return void + */ + protected function _ci_init_library($class, $prefix, $config = FALSE, $object_name = NULL) + { + // Is there an associated config file for this class? Note: these should always be lowercase + if ($config === NULL) + { + // Fetch the config paths containing any package paths + $config_component = $this->_ci_get_component('config'); + + if (is_array($config_component->_config_paths)) + { + $found = FALSE; + foreach ($config_component->_config_paths as $path) + { + // We test for both uppercase and lowercase, for servers that + // are case-sensitive with regard to file names. Load global first, + // override with environment next + if (file_exists($path.'config/'.strtolower($class).'.php')) + { + include($path.'config/'.strtolower($class).'.php'); + $found = TRUE; + } + elseif (file_exists($path.'config/'.ucfirst(strtolower($class)).'.php')) + { + include($path.'config/'.ucfirst(strtolower($class)).'.php'); + $found = TRUE; + } + + if (file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php')) + { + include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'); + $found = TRUE; + } + elseif (file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) + { + include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'); + $found = TRUE; + } + + // Break on the first found configuration, thus package + // files are not overridden by default paths + if ($found === TRUE) + { + break; + } + } + } + } + + $class_name = $prefix.$class; + + // Is the class name valid? + if ( ! class_exists($class_name, FALSE)) + { + log_message('error', 'Non-existent class: '.$class_name); + show_error('Non-existent class: '.$class_name); + } + + // Set the variable name we will assign the class to + // Was a custom class name supplied? If so we'll use it + if (empty($object_name)) + { + $object_name = strtolower($class); + if (isset($this->_ci_varmap[$object_name])) + { + $object_name = $this->_ci_varmap[$object_name]; + } + } + + // Don't overwrite existing properties + $CI =& get_instance(); + if (isset($CI->$object_name)) + { + if ($CI->$object_name instanceof $class_name) + { + log_message('debug', $class_name." has already been instantiated as '".$object_name."'. Second attempt aborted."); + return; + } + + show_error("Resource '".$object_name."' already exists and is not a ".$class_name." instance."); + } + + // Save the class name and object name + $this->_ci_classes[$object_name] = $class; + + // Instantiate the class + $CI->$object_name = isset($config) + ? new $class_name($config) + : new $class_name(); + } + + // -------------------------------------------------------------------- + + /** + * CI Autoloader + * + * Loads component listed in the config/autoload.php file. + * + * @used-by CI_Loader::initialize() + * @return void + */ + protected function _ci_autoloader() + { + if (file_exists(APPPATH.'config/autoload.php')) + { + include(APPPATH.'config/autoload.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'); + } + + if ( ! isset($autoload)) + { + return; + } + + // Autoload packages + if (isset($autoload['packages'])) + { + foreach ($autoload['packages'] as $package_path) + { + $this->add_package_path($package_path); + } + } + + // Load any custom config file + if (count($autoload['config']) > 0) + { + foreach ($autoload['config'] as $val) + { + $this->config($val); + } + } + + // Autoload helpers and languages + foreach (array('helper', 'language') as $type) + { + if (isset($autoload[$type]) && count($autoload[$type]) > 0) + { + $this->$type($autoload[$type]); + } + } + + // Autoload drivers + if (isset($autoload['drivers'])) + { + $this->driver($autoload['drivers']); + } + + // Load libraries + if (isset($autoload['libraries']) && count($autoload['libraries']) > 0) + { + // Load the database driver. + if (in_array('database', $autoload['libraries'])) + { + $this->database(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); + } + + // Load all other libraries + $this->library($autoload['libraries']); + } + + // Autoload models + if (isset($autoload['model'])) + { + $this->model($autoload['model']); + } + } + + // -------------------------------------------------------------------- + + /** + * Prepare variables for _ci_vars, to be later extract()-ed inside views + * + * Converts objects to associative arrays and filters-out internal + * variable names (i.e. keys prefixed with '_ci_'). + * + * @param mixed $vars + * @return array + */ + protected function _ci_prepare_view_vars($vars) + { + if ( ! is_array($vars)) + { + $vars = is_object($vars) + ? get_object_vars($vars) + : array(); + } + + foreach (array_keys($vars) as $key) + { + if (strncmp($key, '_ci_', 4) === 0) + { + unset($vars[$key]); + } + } + + return $vars; + } + + // -------------------------------------------------------------------- + + /** + * CI Component getter + * + * Get a reference to a specific library or model. + * + * @param string $component Component name + * @return bool + */ + protected function &_ci_get_component($component) + { + $CI =& get_instance(); + return $CI->$component; + } +} diff --git a/system/core/Log.php b/system/core/Log.php new file mode 100644 index 0000000..f37726e --- /dev/null +++ b/system/core/Log.php @@ -0,0 +1,296 @@ + 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); + + /** + * mbstring.func_overload flag + * + * @var bool + */ + protected static $func_overload; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + $config =& get_config(); + + isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + + $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; + $this->_file_ext = (isset($config['log_file_extension']) && $config['log_file_extension'] !== '') + ? ltrim($config['log_file_extension'], '.') : 'php'; + + file_exists($this->_log_path) OR mkdir($this->_log_path, 0755, TRUE); + + if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path)) + { + $this->_enabled = FALSE; + } + + if (is_numeric($config['log_threshold'])) + { + $this->_threshold = (int) $config['log_threshold']; + } + elseif (is_array($config['log_threshold'])) + { + $this->_threshold = 0; + $this->_threshold_array = array_flip($config['log_threshold']); + } + + if ( ! empty($config['log_date_format'])) + { + $this->_date_fmt = $config['log_date_format']; + } + + if ( ! empty($config['log_file_permissions']) && is_int($config['log_file_permissions'])) + { + $this->_file_permissions = $config['log_file_permissions']; + } + } + + // -------------------------------------------------------------------- + + /** + * Write Log File + * + * Generally this function will be called using the global log_message() function + * + * @param string $level The error level: 'error', 'debug' or 'info' + * @param string $msg The error message + * @return bool + */ + public function write_log($level, $msg) + { + if ($this->_enabled === FALSE) + { + return FALSE; + } + + $level = strtoupper($level); + + if (( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + && ! isset($this->_threshold_array[$this->_levels[$level]])) + { + return FALSE; + } + + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.'.$this->_file_ext; + $message = ''; + + if ( ! file_exists($filepath)) + { + $newfile = TRUE; + // Only add protection to php files + if ($this->_file_ext === 'php') + { + $message .= "\n\n"; + } + } + + if ( ! $fp = @fopen($filepath, 'ab')) + { + return FALSE; + } + + flock($fp, LOCK_EX); + + // Instantiating DateTime with microseconds appended to initial date is needed for proper support of this format + if (strpos($this->_date_fmt, 'u') !== FALSE) + { + $microtime_full = microtime(TRUE); + $microtime_short = sprintf("%06d", ($microtime_full - floor($microtime_full)) * 1000000); + $date = new DateTime(date('Y-m-d H:i:s.'.$microtime_short, $microtime_full)); + $date = $date->format($this->_date_fmt); + } + else + { + $date = date($this->_date_fmt); + } + + $message .= $this->_format_line($level, $date, $msg); + + for ($written = 0, $length = self::strlen($message); $written < $length; $written += $result) + { + if (($result = fwrite($fp, self::substr($message, $written))) === FALSE) + { + break; + } + } + + flock($fp, LOCK_UN); + fclose($fp); + + if (isset($newfile) && $newfile === TRUE) + { + chmod($filepath, $this->_file_permissions); + } + + return is_int($result); + } + + // -------------------------------------------------------------------- + + /** + * Format the log line. + * + * This is for extensibility of log formatting + * If you want to change the log format, extend the CI_Log class and override this method + * + * @param string $level The error level + * @param string $date Formatted date string + * @param string $message The log message + * @return string Formatted log line with a new line character at the end + */ + protected function _format_line($level, $date, $message) + { + return $level.' - '.$date.' --> '.$message.PHP_EOL; + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe strlen() + * + * @param string $str + * @return int + */ + protected static function strlen($str) + { + return (self::$func_overload) + ? mb_strlen($str, '8bit') + : strlen($str); + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe substr() + * + * @param string $str + * @param int $start + * @param int $length + * @return string + */ + protected static function substr($str, $start, $length = NULL) + { + if (self::$func_overload) + { + // mb_substr($str, $start, null, '8bit') returns an empty + // string on PHP 5.3 + isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start); + return mb_substr($str, $start, $length, '8bit'); + } + + return isset($length) + ? substr($str, $start, $length) + : substr($str, $start); + } +} diff --git a/system/core/Model.php b/system/core/Model.php new file mode 100644 index 0000000..0aadbcd --- /dev/null +++ b/system/core/Model.php @@ -0,0 +1,76 @@ +$key; + } + +} diff --git a/system/core/Output.php b/system/core/Output.php new file mode 100644 index 0000000..64e7ee1 --- /dev/null +++ b/system/core/Output.php @@ -0,0 +1,842 @@ +_zlib_oc = (bool) ini_get('zlib.output_compression'); + $this->_compress_output = ( + $this->_zlib_oc === FALSE + && config_item('compress_output') === TRUE + && extension_loaded('zlib') + ); + + isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + + // Get mime types for later + $this->mimes =& get_mimes(); + + log_message('info', 'Output Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Get Output + * + * Returns the current output string. + * + * @return string + */ + public function get_output() + { + return $this->final_output; + } + + // -------------------------------------------------------------------- + + /** + * Set Output + * + * Sets the output string. + * + * @param string $output Output data + * @return CI_Output + */ + public function set_output($output) + { + $this->final_output = $output; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Append Output + * + * Appends data onto the output string. + * + * @param string $output Data to append + * @return CI_Output + */ + public function append_output($output) + { + $this->final_output .= $output; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Header + * + * Lets you set a server header which will be sent with the final output. + * + * Note: If a file is cached, headers will not be sent. + * @todo We need to figure out how to permit headers to be cached. + * + * @param string $header Header + * @param bool $replace Whether to replace the old header value, if already set + * @return CI_Output + */ + public function set_header($header, $replace = TRUE) + { + // If zlib.output_compression is enabled it will compress the output, + // but it will not modify the content-length header to compensate for + // the reduction, causing the browser to hang waiting for more data. + // We'll just skip content-length in those cases. + if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) === 0) + { + return $this; + } + + $this->headers[] = array($header, $replace); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Content-Type Header + * + * @param string $mime_type Extension of the file we're outputting + * @param string $charset Character set (default: NULL) + * @return CI_Output + */ + public function set_content_type($mime_type, $charset = NULL) + { + if (strpos($mime_type, '/') === FALSE) + { + $extension = ltrim($mime_type, '.'); + + // Is this extension supported? + if (isset($this->mimes[$extension])) + { + $mime_type =& $this->mimes[$extension]; + + if (is_array($mime_type)) + { + $mime_type = current($mime_type); + } + } + } + + $this->mime_type = $mime_type; + + if (empty($charset)) + { + $charset = config_item('charset'); + } + + $header = 'Content-Type: '.$mime_type + .(empty($charset) ? '' : '; charset='.$charset); + + $this->headers[] = array($header, TRUE); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get Current Content-Type Header + * + * @return string 'text/html', if not already set + */ + public function get_content_type() + { + for ($i = 0, $c = count($this->headers); $i < $c; $i++) + { + if (sscanf($this->headers[$i][0], 'Content-Type: %[^;]', $content_type) === 1) + { + return $content_type; + } + } + + return 'text/html'; + } + + // -------------------------------------------------------------------- + + /** + * Get Header + * + * @param string $header + * @return string + */ + public function get_header($header) + { + // Combine headers already sent with our batched headers + $headers = array_merge( + // We only need [x][0] from our multi-dimensional array + array_map('array_shift', $this->headers), + headers_list() + ); + + if (empty($headers) OR empty($header)) + { + return NULL; + } + + // Count backwards, in order to get the last matching header + for ($c = count($headers) - 1; $c > -1; $c--) + { + if (strncasecmp($header, $headers[$c], $l = self::strlen($header)) === 0) + { + return trim(self::substr($headers[$c], $l+1)); + } + } + + return NULL; + } + + // -------------------------------------------------------------------- + + /** + * Set HTTP Status Header + * + * As of version 1.7.2, this is an alias for common function + * set_status_header(). + * + * @param int $code Status code (default: 200) + * @param string $text Optional message + * @return CI_Output + */ + public function set_status_header($code = 200, $text = '') + { + set_status_header($code, $text); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Enable/disable Profiler + * + * @param bool $val TRUE to enable or FALSE to disable + * @return CI_Output + */ + public function enable_profiler($val = TRUE) + { + $this->enable_profiler = is_bool($val) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Profiler Sections + * + * Allows override of default/config settings for + * Profiler section display. + * + * @param array $sections Profiler sections + * @return CI_Output + */ + public function set_profiler_sections($sections) + { + if (isset($sections['query_toggle_count'])) + { + $this->_profiler_sections['query_toggle_count'] = (int) $sections['query_toggle_count']; + unset($sections['query_toggle_count']); + } + + foreach ($sections as $section => $enable) + { + $this->_profiler_sections[$section] = ($enable !== FALSE); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache + * + * @param int $time Cache expiration time in minutes + * @return CI_Output + */ + public function cache($time) + { + $this->cache_expiration = is_numeric($time) ? $time : 0; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Display Output + * + * Processes and sends finalized output data to the browser along + * with any server headers and profile data. It also stops benchmark + * timers so the page rendering speed and memory usage can be shown. + * + * Note: All "view" data is automatically put into $this->final_output + * by controller class. + * + * @uses CI_Output::$final_output + * @param string $output Output data override + * @return void + */ + public function _display($output = '') + { + // Note: We use load_class() because we can't use $CI =& get_instance() + // since this function is sometimes called by the caching mechanism, + // which happens before the CI super object is available. + $BM =& load_class('Benchmark', 'core'); + $CFG =& load_class('Config', 'core'); + + // Grab the super object if we can. + if (class_exists('CI_Controller', FALSE)) + { + $CI =& get_instance(); + } + + // -------------------------------------------------------------------- + + // Set the output data + if ($output === '') + { + $output =& $this->final_output; + } + + // -------------------------------------------------------------------- + + // Do we need to write a cache file? Only if the controller does not have its + // own _output() method and we are not dealing with a cache file, which we + // can determine by the existence of the $CI object above + if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output')) + { + $this->_write_cache($output); + } + + // -------------------------------------------------------------------- + + // Parse out the elapsed time and memory usage, + // then swap the pseudo-variables with the data + + $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); + + if ($this->parse_exec_vars === TRUE) + { + $memory = round(memory_get_usage() / 1024 / 1024, 2).'MB'; + $output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output); + } + + // -------------------------------------------------------------------- + + // Is compression requested? + if (isset($CI) // This means that we're not serving a cache file, if we were, it would already be compressed + && $this->_compress_output === TRUE + && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) + { + ob_start('ob_gzhandler'); + } + + // -------------------------------------------------------------------- + + // Are there any server headers to send? + if (count($this->headers) > 0) + { + foreach ($this->headers as $header) + { + @header($header[0], $header[1]); + } + } + + // -------------------------------------------------------------------- + + // Does the $CI object exist? + // If not we know we are dealing with a cache file so we'll + // simply echo out the data and exit. + if ( ! isset($CI)) + { + if ($this->_compress_output === TRUE) + { + if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) + { + header('Content-Encoding: gzip'); + header('Content-Length: '.self::strlen($output)); + } + else + { + // User agent doesn't support gzip compression, + // so we'll have to decompress our cache + $output = gzinflate(self::substr($output, 10, -8)); + } + } + + echo $output; + log_message('info', 'Final output sent to browser'); + log_message('debug', 'Total execution time: '.$elapsed); + return; + } + + // -------------------------------------------------------------------- + + // Do we need to generate profile data? + // If so, load the Profile class and run it. + if ($this->enable_profiler === TRUE) + { + $CI->load->library('profiler'); + if ( ! empty($this->_profiler_sections)) + { + $CI->profiler->set_sections($this->_profiler_sections); + } + + // If the output data contains closing and tags + // we will remove them and add them back after we insert the profile data + $output = preg_replace('|.*?|is', '', $output, -1, $count).$CI->profiler->run(); + if ($count > 0) + { + $output .= ''; + } + } + + // Does the controller contain a function named _output()? + // If so send the output there. Otherwise, echo it. + if (method_exists($CI, '_output')) + { + $CI->_output($output); + } + else + { + echo $output; // Send it to the browser! + } + + log_message('info', 'Final output sent to browser'); + log_message('debug', 'Total execution time: '.$elapsed); + } + + // -------------------------------------------------------------------- + + /** + * Write Cache + * + * @param string $output Output data to cache + * @return void + */ + public function _write_cache($output) + { + $CI =& get_instance(); + $path = $CI->config->item('cache_path'); + $cache_path = ($path === '') ? APPPATH.'cache/' : $path; + + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) + { + log_message('error', 'Unable to write cache file: '.$cache_path); + return; + } + + $uri = $CI->config->item('base_url') + .$CI->config->item('index_page') + .$CI->uri->uri_string(); + + if (($cache_query_string = $CI->config->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING'])) + { + if (is_array($cache_query_string)) + { + $uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string))); + } + else + { + $uri .= '?'.$_SERVER['QUERY_STRING']; + } + } + + $cache_path .= md5($uri); + + if ( ! $fp = @fopen($cache_path, 'w+b')) + { + log_message('error', 'Unable to write cache file: '.$cache_path); + return; + } + + if ( ! flock($fp, LOCK_EX)) + { + log_message('error', 'Unable to secure a file lock for file at: '.$cache_path); + fclose($fp); + return; + } + + // If output compression is enabled, compress the cache + // itself, so that we don't have to do that each time + // we're serving it + if ($this->_compress_output === TRUE) + { + $output = gzencode($output); + + if ($this->get_header('content-type') === NULL) + { + $this->set_content_type($this->mime_type); + } + } + + $expire = time() + ($this->cache_expiration * 60); + + // Put together our serialized info. + $cache_info = serialize(array( + 'expire' => $expire, + 'headers' => $this->headers + )); + + $output = $cache_info.'ENDCI--->'.$output; + + for ($written = 0, $length = self::strlen($output); $written < $length; $written += $result) + { + if (($result = fwrite($fp, self::substr($output, $written))) === FALSE) + { + break; + } + } + + flock($fp, LOCK_UN); + fclose($fp); + + if ( ! is_int($result)) + { + @unlink($cache_path); + log_message('error', 'Unable to write the complete cache content at: '.$cache_path); + return; + } + + chmod($cache_path, 0640); + log_message('debug', 'Cache file written: '.$cache_path); + + // Send HTTP cache-control headers to browser to match file cache settings. + $this->set_cache_header($_SERVER['REQUEST_TIME'], $expire); + } + + // -------------------------------------------------------------------- + + /** + * Update/serve cached output + * + * @uses CI_Config + * @uses CI_URI + * + * @param object &$CFG CI_Config class instance + * @param object &$URI CI_URI class instance + * @return bool TRUE on success or FALSE on failure + */ + public function _display_cache(&$CFG, &$URI) + { + $cache_path = ($CFG->item('cache_path') === '') ? APPPATH.'cache/' : $CFG->item('cache_path'); + + // Build the file path. The file name is an MD5 hash of the full URI + $uri = $CFG->item('base_url').$CFG->item('index_page').$URI->uri_string; + + if (($cache_query_string = $CFG->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING'])) + { + if (is_array($cache_query_string)) + { + $uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string))); + } + else + { + $uri .= '?'.$_SERVER['QUERY_STRING']; + } + } + + $filepath = $cache_path.md5($uri); + + if ( ! file_exists($filepath) OR ! $fp = @fopen($filepath, 'rb')) + { + return FALSE; + } + + flock($fp, LOCK_SH); + + $cache = (filesize($filepath) > 0) ? fread($fp, filesize($filepath)) : ''; + + flock($fp, LOCK_UN); + fclose($fp); + + // Look for embedded serialized file info. + if ( ! preg_match('/^(.*)ENDCI--->/', $cache, $match)) + { + return FALSE; + } + + $cache_info = unserialize($match[1]); + $expire = $cache_info['expire']; + + $last_modified = filemtime($filepath); + + // Has the file expired? + if ($_SERVER['REQUEST_TIME'] >= $expire && is_really_writable($cache_path)) + { + // If so we'll delete it. + @unlink($filepath); + log_message('debug', 'Cache file has expired. File deleted.'); + return FALSE; + } + + // Send the HTTP cache control headers + $this->set_cache_header($last_modified, $expire); + + // Add headers from cache file. + foreach ($cache_info['headers'] as $header) + { + $this->set_header($header[0], $header[1]); + } + + // Display the cache + $this->_display(self::substr($cache, self::strlen($match[0]))); + log_message('debug', 'Cache file is current. Sending it to browser.'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete cache + * + * @param string $uri URI string + * @return bool + */ + public function delete_cache($uri = '') + { + $CI =& get_instance(); + $cache_path = $CI->config->item('cache_path'); + if ($cache_path === '') + { + $cache_path = APPPATH.'cache/'; + } + + if ( ! is_dir($cache_path)) + { + log_message('error', 'Unable to find cache path: '.$cache_path); + return FALSE; + } + + if (empty($uri)) + { + $uri = $CI->uri->uri_string(); + + if (($cache_query_string = $CI->config->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING'])) + { + if (is_array($cache_query_string)) + { + $uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string))); + } + else + { + $uri .= '?'.$_SERVER['QUERY_STRING']; + } + } + } + + $cache_path .= md5($CI->config->item('base_url').$CI->config->item('index_page').ltrim($uri, '/')); + + if ( ! @unlink($cache_path)) + { + log_message('error', 'Unable to delete cache file for '.$uri); + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Header + * + * Set the HTTP headers to match the server-side file cache settings + * in order to reduce bandwidth. + * + * @param int $last_modified Timestamp of when the page was last modified + * @param int $expiration Timestamp of when should the requested page expire from cache + * @return void + */ + public function set_cache_header($last_modified, $expiration) + { + $max_age = $expiration - $_SERVER['REQUEST_TIME']; + + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) + { + $this->set_status_header(304); + exit; + } + + header('Pragma: public'); + header('Cache-Control: max-age='.$max_age.', public'); + header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT'); + header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT'); + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe strlen() + * + * @param string $str + * @return int + */ + protected static function strlen($str) + { + return (self::$func_overload) + ? mb_strlen($str, '8bit') + : strlen($str); + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe substr() + * + * @param string $str + * @param int $start + * @param int $length + * @return string + */ + protected static function substr($str, $start, $length = NULL) + { + if (self::$func_overload) + { + // mb_substr($str, $start, null, '8bit') returns an empty + // string on PHP 5.3 + isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start); + return mb_substr($str, $start, $length, '8bit'); + } + + return isset($length) + ? substr($str, $start, $length) + : substr($str, $start); + } +} diff --git a/system/core/Router.php b/system/core/Router.php new file mode 100644 index 0000000..90b69d0 --- /dev/null +++ b/system/core/Router.php @@ -0,0 +1,515 @@ +config =& load_class('Config', 'core'); + $this->uri =& load_class('URI', 'core'); + + $this->enable_query_strings = ( ! is_cli() && $this->config->item('enable_query_strings') === TRUE); + + // If a directory override is configured, it has to be set before any dynamic routing logic + is_array($routing) && isset($routing['directory']) && $this->set_directory($routing['directory']); + $this->_set_routing(); + + // Set any routing overrides that may exist in the main index file + if (is_array($routing)) + { + empty($routing['controller']) OR $this->set_class($routing['controller']); + empty($routing['function']) OR $this->set_method($routing['function']); + } + + log_message('info', 'Router Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Set route mapping + * + * Determines what should be served based on the URI request, + * as well as any "routes" that have been set in the routing config file. + * + * @return void + */ + protected function _set_routing() + { + // Load the routes.php file. It would be great if we could + // skip this for enable_query_strings = TRUE, but then + // default_controller would be empty ... + if (file_exists(APPPATH.'config/routes.php')) + { + include(APPPATH.'config/routes.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); + } + + // Validate & get reserved routes + if (isset($route) && is_array($route)) + { + isset($route['default_controller']) && $this->default_controller = $route['default_controller']; + isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes']; + unset($route['default_controller'], $route['translate_uri_dashes']); + $this->routes = $route; + } + + // Are query strings enabled in the config file? Normally CI doesn't utilize query strings + // since URI segments are more search-engine friendly, but they can optionally be used. + // If this feature is enabled, we will gather the directory/class/method a little differently + if ($this->enable_query_strings) + { + // If the directory is set at this time, it means an override exists, so skip the checks + if ( ! isset($this->directory)) + { + $_d = $this->config->item('directory_trigger'); + $_d = isset($_GET[$_d]) ? trim($_GET[$_d], " \t\n\r\0\x0B/") : ''; + + if ($_d !== '') + { + $this->uri->filter_uri($_d); + $this->set_directory($_d); + } + } + + $_c = trim($this->config->item('controller_trigger')); + if ( ! empty($_GET[$_c])) + { + $this->uri->filter_uri($_GET[$_c]); + $this->set_class($_GET[$_c]); + + $_f = trim($this->config->item('function_trigger')); + if ( ! empty($_GET[$_f])) + { + $this->uri->filter_uri($_GET[$_f]); + $this->set_method($_GET[$_f]); + } + + $this->uri->rsegments = array( + 1 => $this->class, + 2 => $this->method + ); + } + else + { + $this->_set_default_controller(); + } + + // Routing rules don't apply to query strings and we don't need to detect + // directories, so we're done here + return; + } + + // Is there anything to parse? + if ($this->uri->uri_string !== '') + { + $this->_parse_routes(); + } + else + { + $this->_set_default_controller(); + } + } + + // -------------------------------------------------------------------- + + /** + * Set request route + * + * Takes an array of URI segments as input and sets the class/method + * to be called. + * + * @used-by CI_Router::_parse_routes() + * @param array $segments URI segments + * @return void + */ + protected function _set_request($segments = array()) + { + $segments = $this->_validate_request($segments); + // If we don't have any segments left - try the default controller; + // WARNING: Directories get shifted out of the segments array! + if (empty($segments)) + { + $this->_set_default_controller(); + return; + } + + if ($this->translate_uri_dashes === TRUE) + { + $segments[0] = str_replace('-', '_', $segments[0]); + if (isset($segments[1])) + { + $segments[1] = str_replace('-', '_', $segments[1]); + } + } + + $this->set_class($segments[0]); + if (isset($segments[1])) + { + $this->set_method($segments[1]); + } + else + { + $segments[1] = 'index'; + } + + array_unshift($segments, NULL); + unset($segments[0]); + $this->uri->rsegments = $segments; + } + + // -------------------------------------------------------------------- + + /** + * Set default controller + * + * @return void + */ + protected function _set_default_controller() + { + if (empty($this->default_controller)) + { + show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.'); + } + + // Is the method being specified? + if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) + { + $method = 'index'; + } + + if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php')) + { + // This will trigger 404 later + return; + } + + $this->set_class($class); + $this->set_method($method); + + // Assign routed segments, index starting from 1 + $this->uri->rsegments = array( + 1 => $class, + 2 => $method + ); + + log_message('debug', 'No URI present. Default controller set.'); + } + + // -------------------------------------------------------------------- + + /** + * Validate request + * + * Attempts validate the URI request and determine the controller path. + * + * @used-by CI_Router::_set_request() + * @param array $segments URI segments + * @return mixed URI segments + */ + protected function _validate_request($segments) + { + $c = count($segments); + $directory_override = isset($this->directory); + + // Loop through our segments and return as soon as a controller + // is found or when such a directory doesn't exist + while ($c-- > 0) + { + $test = $this->directory + .ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]); + + if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') + && $directory_override === FALSE + && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0]) + ) + { + $this->set_directory(array_shift($segments), TRUE); + continue; + } + + return $segments; + } + + // This means that all segments were actually directories + return $segments; + } + + // -------------------------------------------------------------------- + + /** + * Parse Routes + * + * Matches any routes that may exist in the config/routes.php file + * against the URI to determine if the class/method need to be remapped. + * + * @return void + */ + protected function _parse_routes() + { + // Turn the segment array into a URI string + $uri = implode('/', $this->uri->segments); + + // Get HTTP verb + $http_verb = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'cli'; + + // Loop through the route array looking for wildcards + foreach ($this->routes as $key => $val) + { + // Check if route format is using HTTP verbs + if (is_array($val)) + { + $val = array_change_key_case($val, CASE_LOWER); + if (isset($val[$http_verb])) + { + $val = $val[$http_verb]; + } + else + { + continue; + } + } + + // Convert wildcards to RegEx + $key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key); + + // Does the RegEx match? + if (preg_match('#^'.$key.'$#', $uri, $matches)) + { + // Are we using callbacks to process back-references? + if ( ! is_string($val) && is_callable($val)) + { + // Remove the original string from the matches array. + array_shift($matches); + + // Execute the callback using the values in matches as its parameters. + $val = call_user_func_array($val, $matches); + } + // Are we using the default routing method for back-references? + elseif (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) + { + $val = preg_replace('#^'.$key.'$#', $val, $uri); + } + + $this->_set_request(explode('/', $val)); + return; + } + } + + // If we got this far it means we didn't encounter a + // matching route so we'll set the site default route + $this->_set_request(array_values($this->uri->segments)); + } + + // -------------------------------------------------------------------- + + /** + * Set class name + * + * @param string $class Class name + * @return void + */ + public function set_class($class) + { + $this->class = str_replace(array('/', '.'), '', $class); + } + + // -------------------------------------------------------------------- + + /** + * Fetch the current class + * + * @deprecated 3.0.0 Read the 'class' property instead + * @return string + */ + public function fetch_class() + { + return $this->class; + } + + // -------------------------------------------------------------------- + + /** + * Set method name + * + * @param string $method Method name + * @return void + */ + public function set_method($method) + { + $this->method = $method; + } + + // -------------------------------------------------------------------- + + /** + * Fetch the current method + * + * @deprecated 3.0.0 Read the 'method' property instead + * @return string + */ + public function fetch_method() + { + return $this->method; + } + + // -------------------------------------------------------------------- + + /** + * Set directory name + * + * @param string $dir Directory name + * @param bool $append Whether we're appending rather than setting the full value + * @return void + */ + public function set_directory($dir, $append = FALSE) + { + if ($append !== TRUE OR empty($this->directory)) + { + $this->directory = str_replace('.', '', trim($dir, '/')).'/'; + } + else + { + $this->directory .= str_replace('.', '', trim($dir, '/')).'/'; + } + } + + // -------------------------------------------------------------------- + + /** + * Fetch directory + * + * Feches the sub-directory (if any) that contains the requested + * controller class. + * + * @deprecated 3.0.0 Read the 'directory' property instead + * @return string + */ + public function fetch_directory() + { + return $this->directory; + } + +} diff --git a/system/core/Security.php b/system/core/Security.php new file mode 100644 index 0000000..6a81faf --- /dev/null +++ b/system/core/Security.php @@ -0,0 +1,1091 @@ +', '<', '>', + "'", '"', '&', '$', '#', + '{', '}', '[', ']', '=', + ';', '?', '%20', '%22', + '%3c', // < + '%253c', // < + '%3e', // > + '%0e', // > + '%28', // ( + '%29', // ) + '%2528', // ( + '%26', // & + '%24', // $ + '%3f', // ? + '%3b', // ; + '%3d' // = + ); + + /** + * Character set + * + * Will be overridden by the constructor. + * + * @var string + */ + public $charset = 'UTF-8'; + + /** + * XSS Hash + * + * Random Hash for protecting URLs. + * + * @var string + */ + protected $_xss_hash; + + /** + * CSRF Hash + * + * Random hash for Cross Site Request Forgery protection cookie + * + * @var string + */ + protected $_csrf_hash; + + /** + * CSRF Expire time + * + * Expiration time for Cross Site Request Forgery protection cookie. + * Defaults to two hours (in seconds). + * + * @var int + */ + protected $_csrf_expire = 7200; + + /** + * CSRF Token name + * + * Token name for Cross Site Request Forgery protection cookie. + * + * @var string + */ + protected $_csrf_token_name = 'ci_csrf_token'; + + /** + * CSRF Cookie name + * + * Cookie name for Cross Site Request Forgery protection cookie. + * + * @var string + */ + protected $_csrf_cookie_name = 'ci_csrf_token'; + + /** + * List of never allowed strings + * + * @var array + */ + protected $_never_allowed_str = array( + 'document.cookie' => '[removed]', + '(document).cookie' => '[removed]', + 'document.write' => '[removed]', + '(document).write' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[', + '' => '<comment>', + '<%' => '<%' + ); + + /** + * List of never allowed regex replacements + * + * @var array + */ + protected $_never_allowed_regex = array( + 'javascript\s*:', + '(\(?document\)?|\(?window\)?(\.document)?)\.(location|on\w*)', + 'expression\s*(\(|&\#40;)', // CSS and IE + 'vbscript\s*:', // IE, surprise! + 'wscript\s*:', // IE + 'jscript\s*:', // IE + 'vbs\s*:', // IE + 'Redirect\s+30\d', + "([\"'])?data\s*:[^\\1]*?base64[^\\1]*?,[^\\1]*?\\1?" + ); + + /** + * Class constructor + * + * @return void + */ + public function __construct() + { + // Is CSRF protection enabled? + if (config_item('csrf_protection')) + { + // CSRF config + foreach (array('csrf_expire', 'csrf_token_name', 'csrf_cookie_name') as $key) + { + if (NULL !== ($val = config_item($key))) + { + $this->{'_'.$key} = $val; + } + } + + // Append application specific cookie prefix + if ($cookie_prefix = config_item('cookie_prefix')) + { + $this->_csrf_cookie_name = $cookie_prefix.$this->_csrf_cookie_name; + } + + // Set the CSRF hash + $this->_csrf_set_hash(); + } + + $this->charset = strtoupper(config_item('charset')); + + log_message('info', 'Security Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * CSRF Verify + * + * @return CI_Security + */ + public function csrf_verify() + { + // If it's not a POST request we will set the CSRF cookie + if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST') + { + return $this->csrf_set_cookie(); + } + + // Check if URI has been whitelisted from CSRF checks + if ($exclude_uris = config_item('csrf_exclude_uris')) + { + $uri = load_class('URI', 'core'); + foreach ($exclude_uris as $excluded) + { + if (preg_match('#^'.$excluded.'$#i'.(UTF8_ENABLED ? 'u' : ''), $uri->uri_string())) + { + return $this; + } + } + } + + // Check CSRF token validity, but don't error on mismatch just yet - we'll want to regenerate + $valid = isset($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name]) + && is_string($_POST[$this->_csrf_token_name]) && is_string($_COOKIE[$this->_csrf_cookie_name]) + && hash_equals($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name]); + + // We kill this since we're done and we don't want to pollute the _POST array + unset($_POST[$this->_csrf_token_name]); + + // Regenerate on every submission? + if (config_item('csrf_regenerate')) + { + // Nothing should last forever + unset($_COOKIE[$this->_csrf_cookie_name]); + $this->_csrf_hash = NULL; + } + + $this->_csrf_set_hash(); + $this->csrf_set_cookie(); + + if ($valid !== TRUE) + { + $this->csrf_show_error(); + } + + log_message('info', 'CSRF token verified'); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * CSRF Set Cookie + * + * @codeCoverageIgnore + * @return CI_Security + */ + public function csrf_set_cookie() + { + $expire = time() + $this->_csrf_expire; + $secure_cookie = (bool) config_item('cookie_secure'); + + if ($secure_cookie && ! is_https()) + { + return FALSE; + } + + setcookie( + $this->_csrf_cookie_name, + $this->_csrf_hash, + $expire, + config_item('cookie_path'), + config_item('cookie_domain'), + $secure_cookie, + config_item('cookie_httponly') + ); + log_message('info', 'CSRF cookie sent'); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Show CSRF Error + * + * @return void + */ + public function csrf_show_error() + { + show_error('The action you have requested is not allowed.', 403); + } + + // -------------------------------------------------------------------- + + /** + * Get CSRF Hash + * + * @see CI_Security::$_csrf_hash + * @return string CSRF hash + */ + public function get_csrf_hash() + { + return $this->_csrf_hash; + } + + // -------------------------------------------------------------------- + + /** + * Get CSRF Token Name + * + * @see CI_Security::$_csrf_token_name + * @return string CSRF token name + */ + public function get_csrf_token_name() + { + return $this->_csrf_token_name; + } + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * Sanitizes data so that Cross Site Scripting Hacks can be + * prevented. This method does a fair amount of work but + * it is extremely thorough, designed to prevent even the + * most obscure XSS attempts. Nothing is ever 100% foolproof, + * of course, but I haven't been able to get anything passed + * the filter. + * + * Note: Should only be used to deal with data upon submission. + * It's not something that should be used for general + * runtime processing. + * + * @link http://channel.bitflux.ch/wiki/XSS_Prevention + * Based in part on some code and ideas from Bitflux. + * + * @link http://ha.ckers.org/xss.html + * To help develop this script I used this great list of + * vulnerabilities along with a few other hacks I've + * harvested from examining vulnerabilities in other programs. + * + * @param string|string[] $str Input data + * @param bool $is_image Whether the input is an image + * @return string + */ + public function xss_clean($str, $is_image = FALSE) + { + // Is the string an array? + if (is_array($str)) + { + foreach ($str as $key => &$value) + { + $str[$key] = $this->xss_clean($value); + } + + return $str; + } + + // Remove Invisible Characters + $str = remove_invisible_characters($str); + + /* + * URL Decode + * + * Just in case stuff like this is submitted: + * + * Google + * + * Note: Use rawurldecode() so it does not remove plus signs + */ + if (stripos($str, '%') !== false) + { + do + { + $oldstr = $str; + $str = rawurldecode($str); + $str = preg_replace_callback('#%(?:\s*[0-9a-f]){2,}#i', array($this, '_urldecodespaces'), $str); + } + while ($oldstr !== $str); + unset($oldstr); + } + + /* + * Convert character entities to ASCII + * + * This permits our tests below to work reliably. + * We only convert entities that are within tags since + * these are the ones that will pose security problems. + */ + $str = preg_replace_callback("/[^a-z0-9>]+[a-z0-9]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); + $str = preg_replace_callback('/<\w+.*/si', array($this, '_decode_entity'), $str); + + // Remove Invisible Characters Again! + $str = remove_invisible_characters($str); + + /* + * Convert all tabs to spaces + * + * This prevents strings like this: ja vascript + * NOTE: we deal with spaces between characters later. + * NOTE: preg_replace was found to be amazingly slow here on + * large blocks of data, so we use str_replace. + */ + $str = str_replace("\t", ' ', $str); + + // Capture converted string for later comparison + $converted_string = $str; + + // Remove Strings that are never allowed + $str = $this->_do_never_allowed($str); + + /* + * Makes PHP tags safe + * + * Note: XML tags are inadvertently replaced too: + * + * '), array('<?', '?>'), $str); + } + + /* + * Compact any exploded words + * + * This corrects words like: j a v a s c r i p t + * These words are compacted back to their correct state. + */ + $words = array( + 'javascript', 'expression', 'vbscript', 'jscript', 'wscript', + 'vbs', 'script', 'base64', 'applet', 'alert', 'document', + 'write', 'cookie', 'window', 'confirm', 'prompt', 'eval' + ); + + foreach ($words as $word) + { + $word = implode('\s*', str_split($word)).'\s*'; + + // We only want to do this when it is followed by a non-word character + // That way valid stuff like "dealer to" does not become "dealerto" + $str = preg_replace_callback('#('.substr($word, 0, -3).')(\W)#is', array($this, '_compact_exploded_words'), $str); + } + + /* + * Remove disallowed Javascript in links or img tags + * We used to do some version comparisons and use of stripos(), + * but it is dog slow compared to these simplified non-capturing + * preg_match(), especially if the pattern exists in the string + * + * Note: It was reported that not only space characters, but all in + * the following pattern can be parsed as separators between a tag name + * and its attributes: [\d\s"\'`;,\/\=\(\x00\x0B\x09\x0C] + * ... however, remove_invisible_characters() above already strips the + * hex-encoded ones, so we'll skip them below. + */ + do + { + $original = $str; + + if (preg_match('/]+([^>]*?)(?:>|$)#si', array($this, '_js_link_removal'), $str); + } + + if (preg_match('/]*?)(?:\s?/?>|$)#si', array($this, '_js_img_removal'), $str); + } + + if (preg_match('/script|xss/i', $str)) + { + $str = preg_replace('##si', '[removed]', $str); + } + } + while ($original !== $str); + unset($original); + + /* + * Sanitize naughty HTML elements + * + * If a tag containing any of the words in the list + * below is found, the tag gets converted to entities. + * + * So this: + * Becomes: <blink> + */ + $pattern = '#' + .'<((?/*\s*)((?[a-z0-9]+)(?=[^a-z0-9]|$)|.+)' // tag start and name, followed by a non-tag character + .'[^\s\042\047a-z0-9>/=]*' // a valid attribute character immediately after the tag would count as a separator + // optional attributes + .'(?(?:[\s\042\047/=]*' // non-attribute characters, excluding > (tag close) for obvious reasons + .'[^\s\042\047>/=]+' // attribute characters + // optional attribute-value + .'(?:\s*=' // attribute-value separator + .'(?:[^\s\042\047=><`]+|\s*\042[^\042]*\042|\s*\047[^\047]*\047|\s*(?U:[^\s\042\047=><`]*))' // single, double or non-quoted value + .')?' // end optional attribute-value group + .')*)' // end optional attributes group + .'[^>]*)(?\>)?#isS'; + + // Note: It would be nice to optimize this for speed, BUT + // only matching the naughty elements here results in + // false positives and in turn - vulnerabilities! + do + { + $old_str = $str; + $str = preg_replace_callback($pattern, array($this, '_sanitize_naughty_html'), $str); + } + while ($old_str !== $str); + unset($old_str); + + /* + * Sanitize naughty scripting elements + * + * Similar to above, only instead of looking for + * tags it looks for PHP and JavaScript commands + * that are disallowed. Rather than removing the + * code, it simply converts the parenthesis to entities + * rendering the code un-executable. + * + * For example: eval('some code') + * Becomes: eval('some code') + */ + $str = preg_replace( + '#(alert|prompt|confirm|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', + '\\1\\2(\\3)', + $str + ); + + // Same thing, but for "tag functions" (e.g. eval`some code`) + // See https://github.com/bcit-ci/CodeIgniter/issues/5420 + $str = preg_replace( + '#(alert|prompt|confirm|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)`(.*?)`#si', + '\\1\\2`\\3`', + $str + ); + + // Final clean up + // This adds a bit of extra precaution in case + // something got through the above filters + $str = $this->_do_never_allowed($str); + + /* + * Images are Handled in a Special Way + * - Essentially, we want to know that after all of the character + * conversion is done whether any unwanted, likely XSS, code was found. + * If not, we return TRUE, as the image is clean. + * However, if the string post-conversion does not matched the + * string post-removal of XSS, then it fails, as there was unwanted XSS + * code found and removed/changed during processing. + */ + if ($is_image === TRUE) + { + return ($str === $converted_string); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * XSS Hash + * + * Generates the XSS hash if needed and returns it. + * + * @see CI_Security::$_xss_hash + * @return string XSS hash + */ + public function xss_hash() + { + if ($this->_xss_hash === NULL) + { + $rand = $this->get_random_bytes(16); + $this->_xss_hash = ($rand === FALSE) + ? md5(uniqid(mt_rand(), TRUE)) + : bin2hex($rand); + } + + return $this->_xss_hash; + } + + // -------------------------------------------------------------------- + + /** + * Get random bytes + * + * @param int $length Output length + * @return string + */ + public function get_random_bytes($length) + { + if (empty($length) OR ! ctype_digit((string) $length)) + { + return FALSE; + } + + if (function_exists('random_bytes')) + { + try + { + // The cast is required to avoid TypeError + return random_bytes((int) $length); + } + catch (Exception $e) + { + // If random_bytes() can't do the job, we can't either ... + // There's no point in using fallbacks. + log_message('error', $e->getMessage()); + return FALSE; + } + } + + // Unfortunately, none of the following PRNGs is guaranteed to exist ... + if (defined('MCRYPT_DEV_URANDOM') && ($output = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)) !== FALSE) + { + return $output; + } + + + if (is_readable('/dev/urandom') && ($fp = fopen('/dev/urandom', 'rb')) !== FALSE) + { + // Try not to waste entropy ... + is_php('5.4') && stream_set_chunk_size($fp, $length); + $output = fread($fp, $length); + fclose($fp); + if ($output !== FALSE) + { + return $output; + } + } + + if (function_exists('openssl_random_pseudo_bytes')) + { + return openssl_random_pseudo_bytes($length); + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * HTML Entities Decode + * + * A replacement for html_entity_decode() + * + * The reason we are not using html_entity_decode() by itself is because + * while it is not technically correct to leave out the semicolon + * at the end of an entity most browsers will still interpret the entity + * correctly. html_entity_decode() does not convert entities without + * semicolons, so we are left with our own little solution here. Bummer. + * + * @link http://php.net/html-entity-decode + * + * @param string $str Input + * @param string $charset Character set + * @return string + */ + public function entity_decode($str, $charset = NULL) + { + if (strpos($str, '&') === FALSE) + { + return $str; + } + + static $_entities; + + isset($charset) OR $charset = $this->charset; + $flag = is_php('5.4') + ? ENT_COMPAT | ENT_HTML5 + : ENT_COMPAT; + + if ( ! isset($_entities)) + { + $_entities = array_map('strtolower', get_html_translation_table(HTML_ENTITIES, $flag, $charset)); + + // If we're not on PHP 5.4+, add the possibly dangerous HTML 5 + // entities to the array manually + if ($flag === ENT_COMPAT) + { + $_entities[':'] = ':'; + $_entities['('] = '('; + $_entities[')'] = ')'; + $_entities["\n"] = ' '; + $_entities["\t"] = ' '; + } + } + + do + { + $str_compare = $str; + + // Decode standard entities, avoiding false positives + if (preg_match_all('/&[a-z]{2,}(?![a-z;])/i', $str, $matches)) + { + $replace = array(); + $matches = array_unique(array_map('strtolower', $matches[0])); + foreach ($matches as &$match) + { + if (($char = array_search($match.';', $_entities, TRUE)) !== FALSE) + { + $replace[$match] = $char; + } + } + + $str = str_replace(array_keys($replace), array_values($replace), $str); + } + + // Decode numeric & UTF16 two byte entities + $str = html_entity_decode( + preg_replace('/(&#(?:x0*[0-9a-f]{2,5}(?![0-9a-f;])|(?:0*\d{2,4}(?![0-9;]))))/iS', '$1;', $str), + $flag, + $charset + ); + + if ($flag === ENT_COMPAT) + { + $str = str_replace(array_values($_entities), array_keys($_entities), $str); + } + } + while ($str_compare !== $str); + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Sanitize Filename + * + * @param string $str Input file name + * @param bool $relative_path Whether to preserve paths + * @return string + */ + public function sanitize_filename($str, $relative_path = FALSE) + { + $bad = $this->filename_bad_chars; + + if ( ! $relative_path) + { + $bad[] = './'; + $bad[] = '/'; + } + + $str = remove_invisible_characters($str, FALSE); + + do + { + $old = $str; + $str = str_replace($bad, '', $str); + } + while ($old !== $str); + + return stripslashes($str); + } + + // ---------------------------------------------------------------- + + /** + * Strip Image Tags + * + * @param string $str + * @return string + */ + public function strip_image_tags($str) + { + return preg_replace( + array( + '##i', + '#`]+)).*?\>#i' + ), + '\\2', + $str + ); + } + + // ---------------------------------------------------------------- + + /** + * URL-decode taking spaces into account + * + * @see https://github.com/bcit-ci/CodeIgniter/issues/4877 + * @param array $matches + * @return string + */ + protected function _urldecodespaces($matches) + { + $input = $matches[0]; + $nospaces = preg_replace('#\s+#', '', $input); + return ($nospaces === $input) + ? $input + : rawurldecode($nospaces); + } + + // ---------------------------------------------------------------- + + /** + * Compact Exploded Words + * + * Callback method for xss_clean() to remove whitespace from + * things like 'j a v a s c r i p t'. + * + * @used-by CI_Security::xss_clean() + * @param array $matches + * @return string + */ + protected function _compact_exploded_words($matches) + { + return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; + } + + // -------------------------------------------------------------------- + + /** + * Sanitize Naughty HTML + * + * Callback method for xss_clean() to remove naughty HTML elements. + * + * @used-by CI_Security::xss_clean() + * @param array $matches + * @return string + */ + protected function _sanitize_naughty_html($matches) + { + static $naughty_tags = array( + 'alert', 'area', 'prompt', 'confirm', 'applet', 'audio', 'basefont', 'base', 'behavior', 'bgsound', + 'blink', 'body', 'embed', 'expression', 'form', 'frameset', 'frame', 'head', 'html', 'ilayer', + 'iframe', 'input', 'button', 'select', 'isindex', 'layer', 'link', 'meta', 'keygen', 'object', + 'plaintext', 'style', 'script', 'textarea', 'title', 'math', 'video', 'svg', 'xml', 'xss' + ); + + static $evil_attributes = array( + 'on\w+', 'style', 'xmlns', 'formaction', 'form', 'xlink:href', 'FSCommand', 'seekSegmentTime' + ); + + // First, escape unclosed tags + if (empty($matches['closeTag'])) + { + return '<'.$matches[1]; + } + // Is the element that we caught naughty? If so, escape it + elseif (in_array(strtolower($matches['tagName']), $naughty_tags, TRUE)) + { + return '<'.$matches[1].'>'; + } + // For other tags, see if their attributes are "evil" and strip those + elseif (isset($matches['attributes'])) + { + // We'll store the already filtered attributes here + $attributes = array(); + + // Attribute-catching pattern + $attributes_pattern = '#' + .'(?[^\s\042\047>/=]+)' // attribute characters + // optional attribute-value + .'(?:\s*=(?[^\s\042\047=><`]+|\s*\042[^\042]*\042|\s*\047[^\047]*\047|\s*(?U:[^\s\042\047=><`]*)))' // attribute-value separator + .'#i'; + + // Blacklist pattern for evil attribute names + $is_evil_pattern = '#^('.implode('|', $evil_attributes).')$#i'; + + // Each iteration filters a single attribute + do + { + // Strip any non-alpha characters that may precede an attribute. + // Browsers often parse these incorrectly and that has been a + // of numerous XSS issues we've had. + $matches['attributes'] = preg_replace('#^[^a-z]+#i', '', $matches['attributes']); + + if ( ! preg_match($attributes_pattern, $matches['attributes'], $attribute, PREG_OFFSET_CAPTURE)) + { + // No (valid) attribute found? Discard everything else inside the tag + break; + } + + if ( + // Is it indeed an "evil" attribute? + preg_match($is_evil_pattern, $attribute['name'][0]) + // Or does it have an equals sign, but no value and not quoted? Strip that too! + OR (trim($attribute['value'][0]) === '') + ) + { + $attributes[] = 'xss=removed'; + } + else + { + $attributes[] = $attribute[0][0]; + } + + $matches['attributes'] = substr($matches['attributes'], $attribute[0][1] + strlen($attribute[0][0])); + } + while ($matches['attributes'] !== ''); + + $attributes = empty($attributes) + ? '' + : ' '.implode(' ', $attributes); + return '<'.$matches['slash'].$matches['tagName'].$attributes.'>'; + } + + return $matches[0]; + } + + // -------------------------------------------------------------------- + + /** + * JS Link Removal + * + * Callback method for xss_clean() to sanitize links. + * + * This limits the PCRE backtracks, making it more performance friendly + * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in + * PHP 5.2+ on link-heavy strings. + * + * @used-by CI_Security::xss_clean() + * @param array $match + * @return string + */ + protected function _js_link_removal($match) + { + return str_replace( + $match[1], + preg_replace( + '#href=.*?(?:(?:alert|prompt|confirm)(?:\(|&\#40;|`|&\#96;)|javascript:|livescript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|_filter_attributes($match[1]) + ), + $match[0] + ); + } + + // -------------------------------------------------------------------- + + /** + * JS Image Removal + * + * Callback method for xss_clean() to sanitize image tags. + * + * This limits the PCRE backtracks, making it more performance friendly + * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in + * PHP 5.2+ on image tag heavy strings. + * + * @used-by CI_Security::xss_clean() + * @param array $match + * @return string + */ + protected function _js_img_removal($match) + { + return str_replace( + $match[1], + preg_replace( + '#src=.*?(?:(?:alert|prompt|confirm|eval)(?:\(|&\#40;|`|&\#96;)|javascript:|livescript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|_filter_attributes($match[1]) + ), + $match[0] + ); + } + + // -------------------------------------------------------------------- + + /** + * Attribute Conversion + * + * @used-by CI_Security::xss_clean() + * @param array $match + * @return string + */ + protected function _convert_attribute($match) + { + return str_replace(array('>', '<', '\\'), array('>', '<', '\\\\'), $match[0]); + } + + // -------------------------------------------------------------------- + + /** + * Filter Attributes + * + * Filters tag attributes for consistency and safety. + * + * @used-by CI_Security::_js_img_removal() + * @used-by CI_Security::_js_link_removal() + * @param string $str + * @return string + */ + protected function _filter_attributes($str) + { + $out = ''; + if (preg_match_all('#\s*[a-z\-]+\s*=\s*(\042|\047)([^\\1]*?)\\1#is', $str, $matches)) + { + foreach ($matches[0] as $match) + { + $out .= preg_replace('#/\*.*?\*/#s', '', $match); + } + } + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * HTML Entity Decode Callback + * + * @used-by CI_Security::xss_clean() + * @param array $match + * @return string + */ + protected function _decode_entity($match) + { + // Protect GET variables in URLs + // 901119URL5918AMP18930PROTECT8198 + $match = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-/]+)|i', $this->xss_hash().'\\1=\\2', $match[0]); + + // Decode, then un-protect URL GET vars + return str_replace( + $this->xss_hash(), + '&', + $this->entity_decode($match, $this->charset) + ); + } + + // -------------------------------------------------------------------- + + /** + * Do Never Allowed + * + * @used-by CI_Security::xss_clean() + * @param string + * @return string + */ + protected function _do_never_allowed($str) + { + $str = str_replace(array_keys($this->_never_allowed_str), $this->_never_allowed_str, $str); + + foreach ($this->_never_allowed_regex as $regex) + { + $str = preg_replace('#'.$regex.'#is', '[removed]', $str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Set CSRF Hash and Cookie + * + * @return string + */ + protected function _csrf_set_hash() + { + if ($this->_csrf_hash === NULL) + { + // If the cookie exists we will use its value. + // We don't necessarily want to regenerate it with + // each page load since a page could contain embedded + // sub-pages causing this feature to fail + if (isset($_COOKIE[$this->_csrf_cookie_name]) && is_string($_COOKIE[$this->_csrf_cookie_name]) + && preg_match('#^[0-9a-f]{32}$#iS', $_COOKIE[$this->_csrf_cookie_name]) === 1) + { + return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; + } + + $rand = $this->get_random_bytes(16); + $this->_csrf_hash = ($rand === FALSE) + ? md5(uniqid(mt_rand(), TRUE)) + : bin2hex($rand); + } + + return $this->_csrf_hash; + } + +} diff --git a/system/core/URI.php b/system/core/URI.php new file mode 100644 index 0000000..a8b98ae --- /dev/null +++ b/system/core/URI.php @@ -0,0 +1,643 @@ +config =& load_class('Config', 'core'); + + // If query strings are enabled, we don't need to parse any segments. + // However, they don't make sense under CLI. + if (is_cli() OR $this->config->item('enable_query_strings') !== TRUE) + { + $this->_permitted_uri_chars = $this->config->item('permitted_uri_chars'); + + // If it's a CLI request, ignore the configuration + if (is_cli()) + { + $uri = $this->_parse_argv(); + } + else + { + $protocol = $this->config->item('uri_protocol'); + empty($protocol) && $protocol = 'REQUEST_URI'; + + switch ($protocol) + { + case 'AUTO': // For BC purposes only + case 'REQUEST_URI': + $uri = $this->_parse_request_uri(); + break; + case 'QUERY_STRING': + $uri = $this->_parse_query_string(); + break; + case 'PATH_INFO': + default: + $uri = isset($_SERVER[$protocol]) + ? $_SERVER[$protocol] + : $this->_parse_request_uri(); + break; + } + } + + $this->_set_uri_string($uri); + } + + log_message('info', 'URI Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Set URI String + * + * @param string $str + * @return void + */ + protected function _set_uri_string($str) + { + // Filter out control characters and trim slashes + $this->uri_string = trim(remove_invisible_characters($str, FALSE), '/'); + + if ($this->uri_string !== '') + { + // Remove the URL suffix, if present + if (($suffix = (string) $this->config->item('url_suffix')) !== '') + { + $slen = strlen($suffix); + + if (substr($this->uri_string, -$slen) === $suffix) + { + $this->uri_string = substr($this->uri_string, 0, -$slen); + } + } + + $this->segments[0] = NULL; + // Populate the segments array + foreach (explode('/', trim($this->uri_string, '/')) as $val) + { + $val = trim($val); + // Filter segments for security + $this->filter_uri($val); + + if ($val !== '') + { + $this->segments[] = $val; + } + } + + unset($this->segments[0]); + } + } + + // -------------------------------------------------------------------- + + /** + * Parse REQUEST_URI + * + * Will parse REQUEST_URI and automatically detect the URI from it, + * while fixing the query string if necessary. + * + * @return string + */ + protected function _parse_request_uri() + { + if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])) + { + return ''; + } + + // parse_url() returns false if no host is present, but the path or query string + // contains a colon followed by a number + $uri = parse_url('http://dummy'.$_SERVER['REQUEST_URI']); + $query = isset($uri['query']) ? $uri['query'] : ''; + $uri = isset($uri['path']) ? $uri['path'] : ''; + + if (isset($_SERVER['SCRIPT_NAME'][0])) + { + if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) + { + $uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME'])); + } + elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) + { + $uri = (string) substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); + } + } + + // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct + // URI is found, and also fixes the QUERY_STRING server var and $_GET array. + if (trim($uri, '/') === '' && strncmp($query, '/', 1) === 0) + { + $query = explode('?', $query, 2); + $uri = $query[0]; + $_SERVER['QUERY_STRING'] = isset($query[1]) ? $query[1] : ''; + } + else + { + $_SERVER['QUERY_STRING'] = $query; + } + + parse_str($_SERVER['QUERY_STRING'], $_GET); + + if ($uri === '/' OR $uri === '') + { + return '/'; + } + + // Do some final cleaning of the URI and return it + return $this->_remove_relative_directory($uri); + } + + // -------------------------------------------------------------------- + + /** + * Parse QUERY_STRING + * + * Will parse QUERY_STRING and automatically detect the URI from it. + * + * @return string + */ + protected function _parse_query_string() + { + $uri = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + + if (trim($uri, '/') === '') + { + return ''; + } + elseif (strncmp($uri, '/', 1) === 0) + { + $uri = explode('?', $uri, 2); + $_SERVER['QUERY_STRING'] = isset($uri[1]) ? $uri[1] : ''; + $uri = $uri[0]; + } + + parse_str($_SERVER['QUERY_STRING'], $_GET); + + return $this->_remove_relative_directory($uri); + } + + // -------------------------------------------------------------------- + + /** + * Parse CLI arguments + * + * Take each command line argument and assume it is a URI segment. + * + * @return string + */ + protected function _parse_argv() + { + $args = array_slice($_SERVER['argv'], 1); + return $args ? implode('/', $args) : ''; + } + + // -------------------------------------------------------------------- + + /** + * Remove relative directory (../) and multi slashes (///) + * + * Do some final cleaning of the URI and return it, currently only used in self::_parse_request_uri() + * + * @param string $uri + * @return string + */ + protected function _remove_relative_directory($uri) + { + $uris = array(); + $tok = strtok($uri, '/'); + while ($tok !== FALSE) + { + if (( ! empty($tok) OR $tok === '0') && $tok !== '..') + { + $uris[] = $tok; + } + $tok = strtok('/'); + } + + return implode('/', $uris); + } + + // -------------------------------------------------------------------- + + /** + * Filter URI + * + * Filters segments for malicious characters. + * + * @param string $str + * @return void + */ + public function filter_uri(&$str) + { + if ( ! empty($str) && ! empty($this->_permitted_uri_chars) && ! preg_match('/^['.$this->_permitted_uri_chars.']+$/i'.(UTF8_ENABLED ? 'u' : ''), $str)) + { + show_error('The URI you submitted has disallowed characters.', 400); + } + } + + // -------------------------------------------------------------------- + + /** + * Fetch URI Segment + * + * @see CI_URI::$segments + * @param int $n Index + * @param mixed $no_result What to return if the segment index is not found + * @return mixed + */ + public function segment($n, $no_result = NULL) + { + return isset($this->segments[$n]) ? $this->segments[$n] : $no_result; + } + + // -------------------------------------------------------------------- + + /** + * Fetch URI "routed" Segment + * + * Returns the re-routed URI segment (assuming routing rules are used) + * based on the index provided. If there is no routing, will return + * the same result as CI_URI::segment(). + * + * @see CI_URI::$rsegments + * @see CI_URI::segment() + * @param int $n Index + * @param mixed $no_result What to return if the segment index is not found + * @return mixed + */ + public function rsegment($n, $no_result = NULL) + { + return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result; + } + + // -------------------------------------------------------------------- + + /** + * URI to assoc + * + * Generates an associative array of URI data starting at the supplied + * segment index. For example, if this is your URI: + * + * example.com/user/search/name/joe/location/UK/gender/male + * + * You can use this method to generate an array with this prototype: + * + * array ( + * name => joe + * location => UK + * gender => male + * ) + * + * @param int $n Index (default: 3) + * @param array $default Default values + * @return array + */ + public function uri_to_assoc($n = 3, $default = array()) + { + return $this->_uri_to_assoc($n, $default, 'segment'); + } + + // -------------------------------------------------------------------- + + /** + * Routed URI to assoc + * + * Identical to CI_URI::uri_to_assoc(), only it uses the re-routed + * segment array. + * + * @see CI_URI::uri_to_assoc() + * @param int $n Index (default: 3) + * @param array $default Default values + * @return array + */ + public function ruri_to_assoc($n = 3, $default = array()) + { + return $this->_uri_to_assoc($n, $default, 'rsegment'); + } + + // -------------------------------------------------------------------- + + /** + * Internal URI-to-assoc + * + * Generates a key/value pair from the URI string or re-routed URI string. + * + * @used-by CI_URI::uri_to_assoc() + * @used-by CI_URI::ruri_to_assoc() + * @param int $n Index (default: 3) + * @param array $default Default values + * @param string $which Array name ('segment' or 'rsegment') + * @return array + */ + protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') + { + if ( ! is_numeric($n)) + { + return $default; + } + + if (isset($this->keyval[$which], $this->keyval[$which][$n])) + { + return $this->keyval[$which][$n]; + } + + $total_segments = "total_{$which}s"; + $segment_array = "{$which}_array"; + + if ($this->$total_segments() < $n) + { + return (count($default) === 0) + ? array() + : array_fill_keys($default, NULL); + } + + $segments = array_slice($this->$segment_array(), ($n - 1)); + $i = 0; + $lastval = ''; + $retval = array(); + foreach ($segments as $seg) + { + if ($i % 2) + { + $retval[$lastval] = $seg; + } + else + { + $retval[$seg] = NULL; + $lastval = $seg; + } + + $i++; + } + + if (count($default) > 0) + { + foreach ($default as $val) + { + if ( ! array_key_exists($val, $retval)) + { + $retval[$val] = NULL; + } + } + } + + // Cache the array for reuse + isset($this->keyval[$which]) OR $this->keyval[$which] = array(); + $this->keyval[$which][$n] = $retval; + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Assoc to URI + * + * Generates a URI string from an associative array. + * + * @param array $array Input array of key/value pairs + * @return string URI string + */ + public function assoc_to_uri($array) + { + $temp = array(); + foreach ((array) $array as $key => $val) + { + $temp[] = $key; + $temp[] = $val; + } + + return implode('/', $temp); + } + + // -------------------------------------------------------------------- + + /** + * Slash segment + * + * Fetches an URI segment with a slash. + * + * @param int $n Index + * @param string $where Where to add the slash ('trailing' or 'leading') + * @return string + */ + public function slash_segment($n, $where = 'trailing') + { + return $this->_slash_segment($n, $where, 'segment'); + } + + // -------------------------------------------------------------------- + + /** + * Slash routed segment + * + * Fetches an URI routed segment with a slash. + * + * @param int $n Index + * @param string $where Where to add the slash ('trailing' or 'leading') + * @return string + */ + public function slash_rsegment($n, $where = 'trailing') + { + return $this->_slash_segment($n, $where, 'rsegment'); + } + + // -------------------------------------------------------------------- + + /** + * Internal Slash segment + * + * Fetches an URI Segment and adds a slash to it. + * + * @used-by CI_URI::slash_segment() + * @used-by CI_URI::slash_rsegment() + * + * @param int $n Index + * @param string $where Where to add the slash ('trailing' or 'leading') + * @param string $which Array name ('segment' or 'rsegment') + * @return string + */ + protected function _slash_segment($n, $where = 'trailing', $which = 'segment') + { + $leading = $trailing = '/'; + + if ($where === 'trailing') + { + $leading = ''; + } + elseif ($where === 'leading') + { + $trailing = ''; + } + + return $leading.$this->$which($n).$trailing; + } + + // -------------------------------------------------------------------- + + /** + * Segment Array + * + * @return array CI_URI::$segments + */ + public function segment_array() + { + return $this->segments; + } + + // -------------------------------------------------------------------- + + /** + * Routed Segment Array + * + * @return array CI_URI::$rsegments + */ + public function rsegment_array() + { + return $this->rsegments; + } + + // -------------------------------------------------------------------- + + /** + * Total number of segments + * + * @return int + */ + public function total_segments() + { + return count($this->segments); + } + + // -------------------------------------------------------------------- + + /** + * Total number of routed segments + * + * @return int + */ + public function total_rsegments() + { + return count($this->rsegments); + } + + // -------------------------------------------------------------------- + + /** + * Fetch URI string + * + * @return string CI_URI::$uri_string + */ + public function uri_string() + { + return $this->uri_string; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Re-routed URI string + * + * @return string + */ + public function ruri_string() + { + return ltrim(load_class('Router', 'core')->directory, '/').implode('/', $this->rsegments); + } + +} diff --git a/system/core/Utf8.php b/system/core/Utf8.php new file mode 100644 index 0000000..9ee63e9 --- /dev/null +++ b/system/core/Utf8.php @@ -0,0 +1,164 @@ +is_ascii($str) === FALSE) + { + if (MB_ENABLED) + { + $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8'); + } + elseif (ICONV_ENABLED) + { + $str = @iconv('UTF-8', 'UTF-8//IGNORE', $str); + } + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Remove ASCII control characters + * + * Removes all ASCII control characters except horizontal tabs, + * line feeds, and carriage returns, as all others can cause + * problems in XML. + * + * @param string $str String to clean + * @return string + */ + public function safe_ascii_for_xml($str) + { + return remove_invisible_characters($str, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Convert to UTF-8 + * + * Attempts to convert a string to UTF-8. + * + * @param string $str Input string + * @param string $encoding Input encoding + * @return string $str encoded in UTF-8 or FALSE on failure + */ + public function convert_to_utf8($str, $encoding) + { + if (MB_ENABLED) + { + return mb_convert_encoding($str, 'UTF-8', $encoding); + } + elseif (ICONV_ENABLED) + { + return @iconv($encoding, 'UTF-8', $str); + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Is ASCII? + * + * Tests if a string is standard 7-bit ASCII or not. + * + * @param string $str String to check + * @return bool + */ + public function is_ascii($str) + { + return (preg_match('/[^\x00-\x7F]/S', $str) === 0); + } + +} diff --git a/system/core/compat/hash.php b/system/core/compat/hash.php new file mode 100644 index 0000000..8f5510c --- /dev/null +++ b/system/core/compat/hash.php @@ -0,0 +1,254 @@ + 32, + 'haval128,3' => 128, + 'haval160,3' => 128, + 'haval192,3' => 128, + 'haval224,3' => 128, + 'haval256,3' => 128, + 'haval128,4' => 128, + 'haval160,4' => 128, + 'haval192,4' => 128, + 'haval224,4' => 128, + 'haval256,4' => 128, + 'haval128,5' => 128, + 'haval160,5' => 128, + 'haval192,5' => 128, + 'haval224,5' => 128, + 'haval256,5' => 128, + 'md2' => 16, + 'md4' => 64, + 'md5' => 64, + 'ripemd128' => 64, + 'ripemd160' => 64, + 'ripemd256' => 64, + 'ripemd320' => 64, + 'salsa10' => 64, + 'salsa20' => 64, + 'sha1' => 64, + 'sha224' => 64, + 'sha256' => 64, + 'sha384' => 128, + 'sha512' => 128, + 'snefru' => 32, + 'snefru256' => 32, + 'tiger128,3' => 64, + 'tiger160,3' => 64, + 'tiger192,3' => 64, + 'tiger128,4' => 64, + 'tiger160,4' => 64, + 'tiger192,4' => 64, + 'whirlpool' => 64 + ); + + if (isset($block_sizes[$algo], $password[$block_sizes[$algo]])) + { + $password = hash($algo, $password, TRUE); + } + + $hash = ''; + // Note: Blocks are NOT 0-indexed + for ($bc = (int) ceil($length / $hash_length), $bi = 1; $bi <= $bc; $bi++) + { + $key = $derived_key = hash_hmac($algo, $salt.pack('N', $bi), $password, TRUE); + for ($i = 1; $i < $iterations; $i++) + { + $derived_key ^= $key = hash_hmac($algo, $key, $password, TRUE); + } + + $hash .= $derived_key; + } + + // This is not RFC-compatible, but we're aiming for natural PHP compatibility + if ( ! $raw_output) + { + $hash = bin2hex($hash); + } + + return defined('MB_OVERLOAD_STRING') + ? mb_substr($hash, 0, $length, '8bit') + : substr($hash, 0, $length); + } +} diff --git a/bmt-system/application/helpers/index.html b/system/core/compat/index.html old mode 100755 new mode 100644 similarity index 81% rename from bmt-system/application/helpers/index.html rename to system/core/compat/index.html index c942a79..b702fbc --- a/bmt-system/application/helpers/index.html +++ b/system/core/compat/index.html @@ -1,3 +1,4 @@ + 403 Forbidden @@ -7,4 +8,4 @@

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/core/compat/mbstring.php b/system/core/compat/mbstring.php new file mode 100644 index 0000000..552e727 --- /dev/null +++ b/system/core/compat/mbstring.php @@ -0,0 +1,149 @@ + 0, 'algoName' => 'unknown', 'options' => array()) + : array('algo' => 1, 'algoName' => 'bcrypt', 'options' => array('cost' => $hash)); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('password_hash')) +{ + /** + * password_hash() + * + * @link http://php.net/password_hash + * @param string $password + * @param int $algo + * @param array $options + * @return mixed + */ + function password_hash($password, $algo, array $options = array()) + { + static $func_overload; + isset($func_overload) OR $func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + + if ($algo !== 1) + { + trigger_error('password_hash(): Unknown hashing algorithm: '.(int) $algo, E_USER_WARNING); + return NULL; + } + + if (isset($options['cost']) && ($options['cost'] < 4 OR $options['cost'] > 31)) + { + trigger_error('password_hash(): Invalid bcrypt cost parameter specified: '.(int) $options['cost'], E_USER_WARNING); + return NULL; + } + + if (isset($options['salt']) && ($saltlen = ($func_overload ? mb_strlen($options['salt'], '8bit') : strlen($options['salt']))) < 22) + { + trigger_error('password_hash(): Provided salt is too short: '.$saltlen.' expecting 22', E_USER_WARNING); + return NULL; + } + elseif ( ! isset($options['salt'])) + { + if (function_exists('random_bytes')) + { + try + { + $options['salt'] = random_bytes(16); + } + catch (Exception $e) + { + log_message('error', 'compat/password: Error while trying to use random_bytes(): '.$e->getMessage()); + return FALSE; + } + } + elseif (defined('MCRYPT_DEV_URANDOM')) + { + $options['salt'] = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM); + } + elseif (DIRECTORY_SEPARATOR === '/' && (is_readable($dev = '/dev/arandom') OR is_readable($dev = '/dev/urandom'))) + { + if (($fp = fopen($dev, 'rb')) === FALSE) + { + log_message('error', 'compat/password: Unable to open '.$dev.' for reading.'); + return FALSE; + } + + // Try not to waste entropy ... + is_php('5.4') && stream_set_chunk_size($fp, 16); + + $options['salt'] = ''; + for ($read = 0; $read < 16; $read = ($func_overload) ? mb_strlen($options['salt'], '8bit') : strlen($options['salt'])) + { + if (($read = fread($fp, 16 - $read)) === FALSE) + { + log_message('error', 'compat/password: Error while reading from '.$dev.'.'); + return FALSE; + } + $options['salt'] .= $read; + } + + fclose($fp); + } + elseif (function_exists('openssl_random_pseudo_bytes')) + { + $is_secure = NULL; + $options['salt'] = openssl_random_pseudo_bytes(16, $is_secure); + if ($is_secure !== TRUE) + { + log_message('error', 'compat/password: openssl_random_pseudo_bytes() set the $cryto_strong flag to FALSE'); + return FALSE; + } + } + else + { + log_message('error', 'compat/password: No CSPRNG available.'); + return FALSE; + } + + $options['salt'] = str_replace('+', '.', rtrim(base64_encode($options['salt']), '=')); + } + elseif ( ! preg_match('#^[a-zA-Z0-9./]+$#D', $options['salt'])) + { + $options['salt'] = str_replace('+', '.', rtrim(base64_encode($options['salt']), '=')); + } + + isset($options['cost']) OR $options['cost'] = 10; + + return (strlen($password = crypt($password, sprintf('$2y$%02d$%s', $options['cost'], $options['salt']))) === 60) + ? $password + : FALSE; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('password_needs_rehash')) +{ + /** + * password_needs_rehash() + * + * @link http://php.net/password_needs_rehash + * @param string $hash + * @param int $algo + * @param array $options + * @return bool + */ + function password_needs_rehash($hash, $algo, array $options = array()) + { + $info = password_get_info($hash); + + if ($algo !== $info['algo']) + { + return TRUE; + } + elseif ($algo === 1) + { + $options['cost'] = isset($options['cost']) ? (int) $options['cost'] : 10; + return ($info['options']['cost'] !== $options['cost']); + } + + // Odd at first glance, but according to a comment in PHP's own unit tests, + // because it is an unknown algorithm - it's valid and therefore doesn't + // need rehashing. + return FALSE; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('password_verify')) +{ + /** + * password_verify() + * + * @link http://php.net/password_verify + * @param string $password + * @param string $hash + * @return bool + */ + function password_verify($password, $hash) + { + if (strlen($hash) !== 60 OR strlen($password = crypt($password, $hash)) !== 60) + { + return FALSE; + } + + $compare = 0; + for ($i = 0; $i < 60; $i++) + { + $compare |= (ord($password[$i]) ^ ord($hash[$i])); + } + + return ($compare === 0); + } +} diff --git a/system/core/compat/standard.php b/system/core/compat/standard.php new file mode 100644 index 0000000..2c528fd --- /dev/null +++ b/system/core/compat/standard.php @@ -0,0 +1,182 @@ + 403 Forbidden @@ -7,4 +8,4 @@

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/database/DB.php b/system/database/DB.php new file mode 100644 index 0000000..02e0e1d --- /dev/null +++ b/system/database/DB.php @@ -0,0 +1,218 @@ +load->get_package_paths() as $path) + { + if ($path !== APPPATH) + { + if (file_exists($file_path = $path.'config/'.ENVIRONMENT.'/database.php')) + { + include($file_path); + } + elseif (file_exists($file_path = $path.'config/database.php')) + { + include($file_path); + } + } + } + } + + if ( ! isset($db) OR count($db) === 0) + { + show_error('No database connection settings were found in the database config file.'); + } + + if ($params !== '') + { + $active_group = $params; + } + + if ( ! isset($active_group)) + { + show_error('You have not specified a database connection group via $active_group in your config/database.php file.'); + } + elseif ( ! isset($db[$active_group])) + { + show_error('You have specified an invalid database connection group ('.$active_group.') in your config/database.php file.'); + } + + $params = $db[$active_group]; + } + elseif (is_string($params)) + { + /** + * Parse the URL from the DSN string + * Database settings can be passed as discreet + * parameters or as a data source name in the first + * parameter. DSNs must have this prototype: + * $dsn = 'driver://username:password@hostname/database'; + */ + if (($dsn = @parse_url($params)) === FALSE) + { + show_error('Invalid DB Connection String'); + } + + $params = array( + 'dbdriver' => $dsn['scheme'], + 'hostname' => isset($dsn['host']) ? rawurldecode($dsn['host']) : '', + 'port' => isset($dsn['port']) ? rawurldecode($dsn['port']) : '', + 'username' => isset($dsn['user']) ? rawurldecode($dsn['user']) : '', + 'password' => isset($dsn['pass']) ? rawurldecode($dsn['pass']) : '', + 'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : '' + ); + + // Were additional config items set? + if (isset($dsn['query'])) + { + parse_str($dsn['query'], $extra); + + foreach ($extra as $key => $val) + { + if (is_string($val) && in_array(strtoupper($val), array('TRUE', 'FALSE', 'NULL'))) + { + $val = var_export($val, TRUE); + } + + $params[$key] = $val; + } + } + } + + // No DB specified yet? Beat them senseless... + if (empty($params['dbdriver'])) + { + show_error('You have not selected a database type to connect to.'); + } + + // Load the DB classes. Note: Since the query builder class is optional + // we need to dynamically create a class that extends proper parent class + // based on whether we're using the query builder class or not. + if ($query_builder_override !== NULL) + { + $query_builder = $query_builder_override; + } + // Backwards compatibility work-around for keeping the + // $active_record config variable working. Should be + // removed in v3.1 + elseif ( ! isset($query_builder) && isset($active_record)) + { + $query_builder = $active_record; + } + + require_once(BASEPATH.'database/DB_driver.php'); + + if ( ! isset($query_builder) OR $query_builder === TRUE) + { + require_once(BASEPATH.'database/DB_query_builder.php'); + if ( ! class_exists('CI_DB', FALSE)) + { + /** + * CI_DB + * + * Acts as an alias for both CI_DB_driver and CI_DB_query_builder. + * + * @see CI_DB_query_builder + * @see CI_DB_driver + */ + class CI_DB extends CI_DB_query_builder { } + } + } + elseif ( ! class_exists('CI_DB', FALSE)) + { + /** + * @ignore + */ + class CI_DB extends CI_DB_driver { } + } + + // Load the DB driver + $driver_file = BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'; + + file_exists($driver_file) OR show_error('Invalid DB driver'); + require_once($driver_file); + + // Instantiate the DB adapter + $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; + $DB = new $driver($params); + + // Check for a subdriver + if ( ! empty($DB->subdriver)) + { + $driver_file = BASEPATH.'database/drivers/'.$DB->dbdriver.'/subdrivers/'.$DB->dbdriver.'_'.$DB->subdriver.'_driver.php'; + + if (file_exists($driver_file)) + { + require_once($driver_file); + $driver = 'CI_DB_'.$DB->dbdriver.'_'.$DB->subdriver.'_driver'; + $DB = new $driver($params); + } + } + + $DB->initialize(); + return $DB; +} diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php new file mode 100644 index 0000000..afcfc4c --- /dev/null +++ b/system/database/DB_cache.php @@ -0,0 +1,221 @@ +CI and load the file helper since we use it a lot + $this->CI =& get_instance(); + $this->db =& $db; + $this->CI->load->helper('file'); + + $this->check_path(); + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @param string $path Path to the cache directory + * @return bool + */ + public function check_path($path = '') + { + if ($path === '') + { + if ($this->db->cachedir === '') + { + return $this->db->cache_off(); + } + + $path = $this->db->cachedir; + } + + // Add a trailing slash to the path if needed + $path = realpath($path) + ? rtrim(realpath($path), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR + : rtrim($path, '/').'/'; + + if ( ! is_dir($path)) + { + log_message('debug', 'DB cache path error: '.$path); + + // If the path is wrong we'll turn off caching + return $this->db->cache_off(); + } + + if ( ! is_really_writable($path)) + { + log_message('debug', 'DB cache dir not writable: '.$path); + + // If the path is not really writable we'll turn off caching + return $this->db->cache_off(); + } + + $this->db->cachedir = $path; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Retrieve a cached query + * + * The URI being requested will become the name of the cache sub-folder. + * An MD5 hash of the SQL statement will become the cache file name. + * + * @param string $sql + * @return string + */ + public function read($sql) + { + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); + + if ( ! is_file($filepath) OR FALSE === ($cachedata = file_get_contents($filepath))) + { + return FALSE; + } + + return unserialize($cachedata); + } + + // -------------------------------------------------------------------- + + /** + * Write a query to a cache file + * + * @param string $sql + * @param object $object + * @return bool + */ + public function write($sql, $object) + { + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; + $filename = md5($sql); + + if ( ! is_dir($dir_path) && ! @mkdir($dir_path, 0750)) + { + return FALSE; + } + + if (write_file($dir_path.$filename, serialize($object)) === FALSE) + { + return FALSE; + } + + chmod($dir_path.$filename, 0640); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete cache files within a particular directory + * + * @param string $segment_one + * @param string $segment_two + * @return void + */ + public function delete($segment_one = '', $segment_two = '') + { + if ($segment_one === '') + { + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + } + + if ($segment_two === '') + { + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + } + + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; + delete_files($dir_path, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Delete all existing cache files + * + * @return void + */ + public function delete_all() + { + delete_files($this->db->cachedir, TRUE, TRUE); + } + +} diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php new file mode 100644 index 0000000..5ae0442 --- /dev/null +++ b/system/database/DB_driver.php @@ -0,0 +1,1985 @@ + $val) + { + $this->$key = $val; + } + } + + log_message('info', 'Database Driver Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Database Settings + * + * @return bool + */ + public function initialize() + { + /* If an established connection is available, then there's + * no need to connect and select the database. + * + * Depending on the database driver, conn_id can be either + * boolean TRUE, a resource or an object. + */ + if ($this->conn_id) + { + return TRUE; + } + + // ---------------------------------------------------------------- + + // Connect to the database and set the connection ID + $this->conn_id = $this->db_connect($this->pconnect); + + // No connection resource? Check if there is a failover else throw an error + if ( ! $this->conn_id) + { + // Check if there is a failover set + if ( ! empty($this->failover) && is_array($this->failover)) + { + // Go over all the failovers + foreach ($this->failover as $failover) + { + // Replace the current settings with those of the failover + foreach ($failover as $key => $val) + { + $this->$key = $val; + } + + // Try to connect + $this->conn_id = $this->db_connect($this->pconnect); + + // If a connection is made break the foreach loop + if ($this->conn_id) + { + break; + } + } + } + + // We still don't have a connection? + if ( ! $this->conn_id) + { + log_message('error', 'Unable to connect to the database'); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_connect'); + } + + return FALSE; + } + } + + // Now we set the character set and that's all + return $this->db_set_charset($this->char_set); + } + + // -------------------------------------------------------------------- + + /** + * DB connect + * + * This is just a dummy method that all drivers will override. + * + * @return mixed + */ + public function db_connect() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @return mixed + */ + public function db_pconnect() + { + return $this->db_connect(TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout. + * + * This is just a dummy method to allow drivers without such + * functionality to not declare it, while others will override it. + * + * @return void + */ + public function reconnect() + { + } + + // -------------------------------------------------------------------- + + /** + * Select database + * + * This is just a dummy method to allow drivers without such + * functionality to not declare it, while others will override it. + * + * @return bool + */ + public function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Last error + * + * @return array + */ + public function error() + { + return array('code' => NULL, 'message' => NULL); + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string + * @return bool + */ + public function db_set_charset($charset) + { + if (method_exists($this, '_db_set_charset') && ! $this->_db_set_charset($charset)) + { + log_message('error', 'Unable to set database connection charset: '.$charset); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_set_charset', $charset); + } + + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * The name of the platform in use (mysql, mssql, etc...) + * + * @return string + */ + public function platform() + { + return $this->dbdriver; + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * Returns a string containing the version of the database being used. + * Most drivers will override this method. + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if (FALSE === ($sql = $this->_version())) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; + } + + $query = $this->query($sql)->row(); + return $this->data_cache['version'] = $query->ver; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @return string + */ + protected function _version() + { + return 'SELECT VERSION() AS ver'; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * Accepts an SQL string as input and returns a result object upon + * successful execution of a "read" type query. Returns boolean TRUE + * upon successful execution of a "write" type query. Returns boolean + * FALSE upon failure, and if the $db_debug variable is set to TRUE + * will raise an error. + * + * @param string $sql + * @param array $binds = FALSE An array of binding data + * @param bool $return_object = NULL + * @return mixed + */ + public function query($sql, $binds = FALSE, $return_object = NULL) + { + if ($sql === '') + { + log_message('error', 'Invalid query: '.$sql); + return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE; + } + elseif ( ! is_bool($return_object)) + { + $return_object = ! $this->is_write_type($sql); + } + + // Verify table prefix and replace if necessary + if ($this->dbprefix !== '' && $this->swap_pre !== '' && $this->dbprefix !== $this->swap_pre) + { + $sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql); + } + + // Compile binds if needed + if ($binds !== FALSE) + { + $sql = $this->compile_binds($sql, $binds); + } + + // Is query caching enabled? If the query is a "read type" + // we will load the caching class and return the previously + // cached query if it exists + if ($this->cache_on === TRUE && $return_object === TRUE && $this->_cache_init()) + { + $this->load_rdriver(); + if (FALSE !== ($cache = $this->CACHE->read($sql))) + { + return $cache; + } + } + + // Save the query for debugging + if ($this->save_queries === TRUE) + { + $this->queries[] = $sql; + } + + // Start the Query Timer + $time_start = microtime(TRUE); + + // Run the Query + if (FALSE === ($this->result_id = $this->simple_query($sql))) + { + if ($this->save_queries === TRUE) + { + $this->query_times[] = 0; + } + + // This will trigger a rollback if transactions are being used + if ($this->_trans_depth !== 0) + { + $this->_trans_status = FALSE; + } + + // Grab the error now, as we might run some additional queries before displaying the error + $error = $this->error(); + + // Log errors + log_message('error', 'Query error: '.$error['message'].' - Invalid query: '.$sql); + + if ($this->db_debug) + { + // We call this function in order to roll-back queries + // if transactions are enabled. If we don't call this here + // the error message will trigger an exit, causing the + // transactions to remain in limbo. + while ($this->_trans_depth !== 0) + { + $trans_depth = $this->_trans_depth; + $this->trans_complete(); + if ($trans_depth === $this->_trans_depth) + { + log_message('error', 'Database: Failure during an automated transaction commit/rollback!'); + break; + } + } + + // Display errors + return $this->display_error(array('Error Number: '.$error['code'], $error['message'], $sql)); + } + + return FALSE; + } + + // Stop and aggregate the query time results + $time_end = microtime(TRUE); + $this->benchmark += $time_end - $time_start; + + if ($this->save_queries === TRUE) + { + $this->query_times[] = $time_end - $time_start; + } + + // Increment the query counter + $this->query_count++; + + // Will we have a result object instantiated? If not - we'll simply return TRUE + if ($return_object !== TRUE) + { + // If caching is enabled we'll auto-cleanup any existing files related to this particular URI + if ($this->cache_on === TRUE && $this->cache_autodel === TRUE && $this->_cache_init()) + { + $this->CACHE->delete(); + } + + return TRUE; + } + + // Load and instantiate the result driver + $driver = $this->load_rdriver(); + $RES = new $driver($this); + + // Is query caching enabled? If so, we'll serialize the + // result object and save it to a cache file. + if ($this->cache_on === TRUE && $this->_cache_init()) + { + // We'll create a new instance of the result object + // only without the platform specific driver since + // we can't use it with cached data (the query result + // resource ID won't be any good once we've cached the + // result object, so we'll have to compile the data + // and save it) + $CR = new CI_DB_result($this); + $CR->result_object = $RES->result_object(); + $CR->result_array = $RES->result_array(); + $CR->num_rows = $RES->num_rows(); + + // Reset these since cached objects can not utilize resource IDs. + $CR->conn_id = NULL; + $CR->result_id = NULL; + + $this->CACHE->write($sql, $CR); + } + + return $RES; + } + + // -------------------------------------------------------------------- + + /** + * Load the result drivers + * + * @return string the name of the result class + */ + public function load_rdriver() + { + $driver = 'CI_DB_'.$this->dbdriver.'_result'; + + if ( ! class_exists($driver, FALSE)) + { + require_once(BASEPATH.'database/DB_result.php'); + require_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php'); + } + + return $driver; + } + + // -------------------------------------------------------------------- + + /** + * Simple Query + * This is a simplified version of the query() function. Internally + * we only use it when running transaction commands since they do + * not require all the features of the main query() function. + * + * @param string the sql query + * @return mixed + */ + public function simple_query($sql) + { + if ( ! $this->conn_id) + { + if ( ! $this->initialize()) + { + return FALSE; + } + } + + return $this->_execute($sql); + } + + // -------------------------------------------------------------------- + + /** + * Disable Transactions + * This permits transactions to be disabled at run-time. + * + * @return void + */ + public function trans_off() + { + $this->trans_enabled = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Enable/disable Transaction Strict Mode + * + * When strict mode is enabled, if you are running multiple groups of + * transactions, if one group fails all subsequent groups will be + * rolled back. + * + * If strict mode is disabled, each group is treated autonomously, + * meaning a failure of one group will not affect any others + * + * @param bool $mode = TRUE + * @return void + */ + public function trans_strict($mode = TRUE) + { + $this->trans_strict = is_bool($mode) ? $mode : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Start Transaction + * + * @param bool $test_mode = FALSE + * @return bool + */ + public function trans_start($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + + return $this->trans_begin($test_mode); + } + + // -------------------------------------------------------------------- + + /** + * Complete Transaction + * + * @return bool + */ + public function trans_complete() + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + + // The query() function will set this flag to FALSE in the event that a query failed + if ($this->_trans_status === FALSE OR $this->_trans_failure === TRUE) + { + $this->trans_rollback(); + + // If we are NOT running in strict mode, we will reset + // the _trans_status flag so that subsequent groups of + // transactions will be permitted. + if ($this->trans_strict === FALSE) + { + $this->_trans_status = TRUE; + } + + log_message('debug', 'DB Transaction Failure'); + return FALSE; + } + + return $this->trans_commit(); + } + + // -------------------------------------------------------------------- + + /** + * Lets you retrieve the transaction flag to determine if it has failed + * + * @return bool + */ + public function trans_status() + { + return $this->_trans_status; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @param bool $test_mode + * @return bool + */ + public function trans_begin($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + // When transactions are nested we only begin/commit/rollback the outermost ones + elseif ($this->_trans_depth > 0) + { + $this->_trans_depth++; + return TRUE; + } + + // Reset the transaction failure flag. + // If the $test_mode flag is set to TRUE transactions will be rolled back + // even if the queries produce a successful result. + $this->_trans_failure = ($test_mode === TRUE); + + if ($this->_trans_begin()) + { + $this->_trans_status = TRUE; + $this->_trans_depth++; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + public function trans_commit() + { + if ( ! $this->trans_enabled OR $this->_trans_depth === 0) + { + return FALSE; + } + // When transactions are nested we only begin/commit/rollback the outermost ones + elseif ($this->_trans_depth > 1 OR $this->_trans_commit()) + { + $this->_trans_depth--; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + public function trans_rollback() + { + if ( ! $this->trans_enabled OR $this->_trans_depth === 0) + { + return FALSE; + } + // When transactions are nested we only begin/commit/rollback the outermost ones + elseif ($this->_trans_depth > 1 OR $this->_trans_rollback()) + { + $this->_trans_depth--; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Compile Bindings + * + * @param string the sql statement + * @param array an array of bind data + * @return string + */ + public function compile_binds($sql, $binds) + { + if (empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE) + { + return $sql; + } + elseif ( ! is_array($binds)) + { + $binds = array($binds); + $bind_count = 1; + } + else + { + // Make sure we're using numeric keys + $binds = array_values($binds); + $bind_count = count($binds); + } + + // We'll need the marker length later + $ml = strlen($this->bind_marker); + + // Make sure not to replace a chunk inside a string that happens to match the bind marker + if ($c = preg_match_all("/'[^']*'|\"[^\"]*\"/i", $sql, $matches)) + { + $c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', + str_replace($matches[0], + str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]), + $sql, $c), + $matches, PREG_OFFSET_CAPTURE); + + // Bind values' count must match the count of markers in the query + if ($bind_count !== $c) + { + return $sql; + } + } + elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count) + { + return $sql; + } + + do + { + $c--; + $escaped_value = $this->escape($binds[$c]); + if (is_array($escaped_value)) + { + $escaped_value = '('.implode(',', $escaped_value).')'; + } + $sql = substr_replace($sql, $escaped_value, $matches[0][$c][1], $ml); + } + while ($c !== 0); + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX|MERGE)\s/i', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Calculate the aggregate query elapsed time + * + * @param int The number of decimal places + * @return string + */ + public function elapsed_time($decimals = 6) + { + return number_format($this->benchmark, $decimals); + } + + // -------------------------------------------------------------------- + + /** + * Returns the total number of queries + * + * @return int + */ + public function total_queries() + { + return $this->query_count; + } + + // -------------------------------------------------------------------- + + /** + * Returns the last query that was executed + * + * @return string + */ + public function last_query() + { + return end($this->queries); + } + + // -------------------------------------------------------------------- + + /** + * "Smart" Escape String + * + * Escapes data based on type + * Sets boolean and null types + * + * @param string + * @return mixed + */ + public function escape($str) + { + if (is_array($str)) + { + $str = array_map(array(&$this, 'escape'), $str); + return $str; + } + elseif (is_string($str) OR (is_object($str) && method_exists($str, '__toString'))) + { + return "'".$this->escape_str($str)."'"; + } + elseif (is_bool($str)) + { + return ($str === FALSE) ? 0 : 1; + } + elseif ($str === NULL) + { + return 'NULL'; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @param string|string[] $str Input string + * @param bool $like Whether or not the string will be used in a LIKE condition + * @return string + */ + public function escape_str($str, $like = FALSE) + { + if (is_array($str)) + { + foreach ($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + + $str = $this->_escape_str($str); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + return str_replace( + array($this->_like_escape_chr, '%', '_'), + array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), + $str + ); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Escape LIKE String + * + * Calls the individual driver for platform + * specific escaping for LIKE conditions + * + * @param string|string[] + * @return mixed + */ + public function escape_like_str($str) + { + return $this->escape_str($str, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return str_replace("'", "''", remove_invisible_characters($str, FALSE)); + } + + // -------------------------------------------------------------------- + + /** + * Primary + * + * Retrieves the primary key. It assumes that the row in the first + * position is the primary key + * + * @param string $table Table name + * @return string + */ + public function primary($table) + { + $fields = $this->list_fields($table); + return is_array($fields) ? current($fields) : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @param string + * @return int + */ + public function count_all($table = '') + { + if ($table === '') + { + return 0; + } + + $query = $this->query($this->_count_string.$this->escape_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE)); + if ($query->num_rows() === 0) + { + return 0; + } + + $query = $query->row(); + $this->_reset_select(); + return (int) $query->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Returns an array of table names + * + * @param string $constrain_by_prefix = FALSE + * @return array + */ + public function list_tables($constrain_by_prefix = FALSE) + { + // Is there a cached result? + if (isset($this->data_cache['table_names'])) + { + return $this->data_cache['table_names']; + } + + if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; + } + + $this->data_cache['table_names'] = array(); + $query = $this->query($sql); + + foreach ($query->result_array() as $row) + { + // Do we know from which column to get the table name? + if ( ! isset($key)) + { + if (isset($row['table_name'])) + { + $key = 'table_name'; + } + elseif (isset($row['TABLE_NAME'])) + { + $key = 'TABLE_NAME'; + } + else + { + /* We have no other choice but to just get the first element's key. + * Due to array_shift() accepting its argument by reference, if + * E_STRICT is on, this would trigger a warning. So we'll have to + * assign it first. + */ + $key = array_keys($row); + $key = array_shift($key); + } + } + + $this->data_cache['table_names'][] = $row[$key]; + } + + return $this->data_cache['table_names']; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular table exists + * + * @param string $table_name + * @return bool + */ + public function table_exists($table_name) + { + return in_array($this->protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables()); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * @param string $table Table name + * @return array + */ + public function list_fields($table) + { + if (FALSE === ($sql = $this->_list_columns($table))) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; + } + + $query = $this->query($sql); + $fields = array(); + + foreach ($query->result_array() as $row) + { + // Do we know from where to get the column's name? + if ( ! isset($key)) + { + if (isset($row['column_name'])) + { + $key = 'column_name'; + } + elseif (isset($row['COLUMN_NAME'])) + { + $key = 'COLUMN_NAME'; + } + else + { + // We have no other choice but to just get the first element's key. + $key = key($row); + } + } + + $fields[] = $row[$key]; + } + + return $fields; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular field exists + * + * @param string + * @param string + * @return bool + */ + public function field_exists($field_name, $table_name) + { + return in_array($field_name, $this->list_fields($table_name)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table the table name + * @return array + */ + public function field_data($table) + { + $query = $this->query($this->_field_data($this->protect_identifiers($table, TRUE, NULL, FALSE))); + return ($query) ? $query->field_data() : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @param mixed + * @return mixed + */ + public function escape_identifiers($item) + { + if ($this->_escape_char === '' OR empty($item) OR in_array($item, $this->_reserved_identifiers)) + { + return $item; + } + elseif (is_array($item)) + { + foreach ($item as $key => $value) + { + $item[$key] = $this->escape_identifiers($value); + } + + return $item; + } + // Avoid breaking functions and literal values inside queries + elseif (ctype_digit($item) OR $item[0] === "'" OR ($this->_escape_char !== '"' && $item[0] === '"') OR strpos($item, '(') !== FALSE) + { + return $item; + } + + static $preg_ec = array(); + + if (empty($preg_ec)) + { + if (is_array($this->_escape_char)) + { + $preg_ec = array( + preg_quote($this->_escape_char[0], '/'), + preg_quote($this->_escape_char[1], '/'), + $this->_escape_char[0], + $this->_escape_char[1] + ); + } + else + { + $preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char, '/'); + $preg_ec[2] = $preg_ec[3] = $this->_escape_char; + } + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?\./i', $preg_ec[2].'$1'.$preg_ec[3].'.', $item); + } + } + + return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?(\.)?/i', $preg_ec[2].'$1'.$preg_ec[3].'$2', $item); + } + + // -------------------------------------------------------------------- + + /** + * Generate an insert string + * + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @return string + */ + public function insert_string($table, $data) + { + $fields = $values = array(); + + foreach ($data as $key => $val) + { + $fields[] = $this->escape_identifiers($key); + $values[] = $this->escape($val); + } + + return $this->_insert($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + protected function _insert($table, $keys, $values) + { + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; + } + + // -------------------------------------------------------------------- + + /** + * Generate an update string + * + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @param mixed the "where" statement + * @return string + */ + public function update_string($table, $data, $where) + { + if (empty($where)) + { + return FALSE; + } + + $this->where($where); + + $fields = array(); + foreach ($data as $key => $val) + { + $fields[$this->protect_identifiers($key)] = $this->escape($val); + } + + $sql = $this->_update($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields); + $this->_reset_write(); + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string the table name + * @param array the update data + * @return string + */ + protected function _update($table, $values) + { + foreach ($values as $key => $val) + { + $valstr[] = $key.' = '.$val; + } + + return 'UPDATE '.$table.' SET '.implode(', ', $valstr) + .$this->_compile_wh('qb_where') + .$this->_compile_order_by() + .($this->qb_limit !== FALSE ? ' LIMIT '.$this->qb_limit : ''); + } + + // -------------------------------------------------------------------- + + /** + * Tests whether the string has an SQL operator + * + * @param string + * @return bool + */ + protected function _has_operator($str) + { + return (bool) preg_match('/(<|>|!|=|\sIS NULL|\sIS NOT NULL|\sEXISTS|\sBETWEEN|\sLIKE|\sIN\s*\(|\s)/i', trim($str)); + } + + // -------------------------------------------------------------------- + + /** + * Returns the SQL string operator + * + * @param string + * @return string + */ + protected function _get_operator($str) + { + static $_operators; + + if (empty($_operators)) + { + $_les = ($this->_like_escape_str !== '') + ? '\s+'.preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr)), '/') + : ''; + $_operators = array( + '\s*(?:<|>|!)?=\s*', // =, <=, >=, != + '\s*<>?\s*', // <, <> + '\s*>\s*', // > + '\s+IS NULL', // IS NULL + '\s+IS NOT NULL', // IS NOT NULL + '\s+EXISTS\s*\(.*\)', // EXISTS(sql) + '\s+NOT EXISTS\s*\(.*\)', // NOT EXISTS(sql) + '\s+BETWEEN\s+', // BETWEEN value AND value + '\s+IN\s*\(.*\)', // IN(list) + '\s+NOT IN\s*\(.*\)', // NOT IN (list) + '\s+LIKE\s+\S.*('.$_les.')?', // LIKE 'expr'[ ESCAPE '%s'] + '\s+NOT LIKE\s+\S.*('.$_les.')?' // NOT LIKE 'expr'[ ESCAPE '%s'] + ); + + } + + return preg_match('/'.implode('|', $_operators).'/i', $str, $match) + ? $match[0] : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Enables a native PHP function to be run, using a platform agnostic wrapper. + * + * @param string $function Function name + * @return mixed + */ + public function call_function($function) + { + $driver = ($this->dbdriver === 'postgre') ? 'pg_' : $this->dbdriver.'_'; + + if (FALSE === strpos($driver, $function)) + { + $function = $driver.$function; + } + + if ( ! function_exists($function)) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; + } + + return (func_num_args() > 1) + ? call_user_func_array($function, array_slice(func_get_args(), 1)) + : call_user_func($function); + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @param string the path to the cache directory + * @return void + */ + public function cache_set_path($path = '') + { + $this->cachedir = $path; + } + + // -------------------------------------------------------------------- + + /** + * Enable Query Caching + * + * @return bool cache_on value + */ + public function cache_on() + { + return $this->cache_on = TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Disable Query Caching + * + * @return bool cache_on value + */ + public function cache_off() + { + return $this->cache_on = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Delete the cache files associated with a particular URI + * + * @param string $segment_one = '' + * @param string $segment_two = '' + * @return bool + */ + public function cache_delete($segment_one = '', $segment_two = '') + { + return $this->_cache_init() + ? $this->CACHE->delete($segment_one, $segment_two) + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Delete All cache files + * + * @return bool + */ + public function cache_delete_all() + { + return $this->_cache_init() + ? $this->CACHE->delete_all() + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Initialize the Cache Class + * + * @return bool + */ + protected function _cache_init() + { + if ( ! class_exists('CI_DB_Cache', FALSE)) + { + require_once(BASEPATH.'database/DB_cache.php'); + } + elseif (is_object($this->CACHE)) + { + return TRUE; + } + + $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + public function close() + { + if ($this->conn_id) + { + $this->_close(); + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * This method would be overridden by most of the drivers. + * + * @return void + */ + protected function _close() + { + $this->conn_id = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Display an error message + * + * @param string the error message + * @param string any "swap" values + * @param bool whether to localize the message + * @return string sends the application/views/errors/error_db.php template + */ + public function display_error($error = '', $swap = '', $native = FALSE) + { + $LANG =& load_class('Lang', 'core'); + $LANG->load('db'); + + $heading = $LANG->line('db_error_heading'); + + if ($native === TRUE) + { + $message = (array) $error; + } + else + { + $message = is_array($error) ? $error : array(str_replace('%s', $swap, $LANG->line($error))); + } + + // Find the most likely culprit of the error by going through + // the backtrace until the source file is no longer in the + // database folder. + $trace = debug_backtrace(); + foreach ($trace as $call) + { + if (isset($call['file'], $call['class'])) + { + // We'll need this on Windows, as APPPATH and BASEPATH will always use forward slashes + if (DIRECTORY_SEPARATOR !== '/') + { + $call['file'] = str_replace('\\', '/', $call['file']); + } + + if (strpos($call['file'], BASEPATH.'database') === FALSE && strpos($call['class'], 'Loader') === FALSE) + { + // Found it - use a relative path for safety + $message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']); + $message[] = 'Line Number: '.$call['line']; + break; + } + } + } + + $error =& load_class('Exceptions', 'core'); + echo $error->show_error($heading, $message, 'error_db'); + exit(8); // EXIT_DATABASE + } + + // -------------------------------------------------------------------- + + /** + * Protect Identifiers + * + * This function is used extensively by the Query Builder class, and by + * a couple functions in this class. + * It takes a column or table name (optionally with an alias) and inserts + * the table prefix onto it. Some logic is necessary in order to deal with + * column names that include the path. Consider a query like this: + * + * SELECT hostname.database.table.column AS c FROM hostname.database.table + * + * Or a query with aliasing: + * + * SELECT m.member_id, m.member_name FROM members AS m + * + * Since the column name can include up to four segments (host, DB, table, column) + * or also have an alias prefix, we need to do a bit of work to figure this out and + * insert the table prefix (if it exists) in the proper position, and escape only + * the correct identifiers. + * + * @param string + * @param bool + * @param mixed + * @param bool + * @return string + */ + public function protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) + { + if ( ! is_bool($protect_identifiers)) + { + $protect_identifiers = $this->_protect_identifiers; + } + + if (is_array($item)) + { + $escaped_array = array(); + foreach ($item as $k => $v) + { + $escaped_array[$this->protect_identifiers($k)] = $this->protect_identifiers($v, $prefix_single, $protect_identifiers, $field_exists); + } + + return $escaped_array; + } + + // This is basically a bug fix for queries that use MAX, MIN, etc. + // If a parenthesis is found we know that we do not need to + // escape the data or add a prefix. There's probably a more graceful + // way to deal with this, but I'm not thinking of it -- Rick + // + // Added exception for single quotes as well, we don't want to alter + // literal strings. -- Narf + if (strcspn($item, "()'") !== strlen($item)) + { + return $item; + } + + // Convert tabs or multiple spaces into single spaces + $item = preg_replace('/\s+/', ' ', trim($item)); + + // If the item has an alias declaration we remove it and set it aside. + // Note: strripos() is used in order to support spaces in table names + if ($offset = strripos($item, ' AS ')) + { + $alias = ($protect_identifiers) + ? substr($item, $offset, 4).$this->escape_identifiers(substr($item, $offset + 4)) + : substr($item, $offset); + $item = substr($item, 0, $offset); + } + elseif ($offset = strrpos($item, ' ')) + { + $alias = ($protect_identifiers) + ? ' '.$this->escape_identifiers(substr($item, $offset + 1)) + : substr($item, $offset); + $item = substr($item, 0, $offset); + } + else + { + $alias = ''; + } + + // Break the string apart if it contains periods, then insert the table prefix + // in the correct location, assuming the period doesn't indicate that we're dealing + // with an alias. While we're at it, we will escape the components + if (strpos($item, '.') !== FALSE) + { + $parts = explode('.', $item); + + // Does the first segment of the exploded item match + // one of the aliases previously identified? If so, + // we have nothing more to do other than escape the item + // + // NOTE: The ! empty() condition prevents this method + // from breaking when QB isn't enabled. + if ( ! empty($this->qb_aliased_tables) && in_array($parts[0], $this->qb_aliased_tables)) + { + if ($protect_identifiers === TRUE) + { + foreach ($parts as $key => $val) + { + if ( ! in_array($val, $this->_reserved_identifiers)) + { + $parts[$key] = $this->escape_identifiers($val); + } + } + + $item = implode('.', $parts); + } + + return $item.$alias; + } + + // Is there a table prefix defined in the config file? If not, no need to do anything + if ($this->dbprefix !== '') + { + // We now add the table prefix based on some logic. + // Do we have 4 segments (hostname.database.table.column)? + // If so, we add the table prefix to the column name in the 3rd segment. + if (isset($parts[3])) + { + $i = 2; + } + // Do we have 3 segments (database.table.column)? + // If so, we add the table prefix to the column name in 2nd position + elseif (isset($parts[2])) + { + $i = 1; + } + // Do we have 2 segments (table.column)? + // If so, we add the table prefix to the column name in 1st segment + else + { + $i = 0; + } + + // This flag is set when the supplied $item does not contain a field name. + // This can happen when this function is being called from a JOIN. + if ($field_exists === FALSE) + { + $i++; + } + + // dbprefix may've already been applied, with or without the identifier escaped + $ec = '(?'.preg_quote(is_array($this->_escape_char) ? $this->_escape_char[0] : $this->_escape_char).')?'; + isset($ec[0]) && $ec .= '?'; // Just in case someone has disabled escaping by forcing an empty escape character + + // Verify table prefix and replace if necessary + if ($this->swap_pre !== '' && preg_match('#^'.$ec.preg_quote($this->swap_pre).'#', $parts[$i])) + { + $parts[$i] = preg_replace('#^'.$ec.preg_quote($this->swap_pre).'(\S+?)#', '\\1'.$this->dbprefix.'\\2', $parts[$i]); + } + // We only add the table prefix if it does not already exist + else + { + preg_match('#^'.$ec.preg_quote($this->dbprefix).'#', $parts[$i]) OR $parts[$i] = $this->dbprefix.$parts[$i]; + } + + // Put the parts back together + $item = implode('.', $parts); + } + + if ($protect_identifiers === TRUE) + { + $item = $this->escape_identifiers($item); + } + + return $item.$alias; + } + + // Is there a table prefix? If not, no need to insert it + if ($this->dbprefix !== '') + { + // Verify table prefix and replace if necessary + if ($this->swap_pre !== '' && strpos($item, $this->swap_pre) === 0) + { + $item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item); + } + // Do we prefix an item with no segments? + elseif ($prefix_single === TRUE && strpos($item, $this->dbprefix) !== 0) + { + $item = $this->dbprefix.$item; + } + } + + if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers)) + { + $item = $this->escape_identifiers($item); + } + + return $item.$alias; + } + + // -------------------------------------------------------------------- + + /** + * Dummy method that allows Query Builder class to be disabled + * and keep count_all() working. + * + * @return void + */ + protected function _reset_select() + { + } + +} diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php new file mode 100644 index 0000000..85b58fd --- /dev/null +++ b/system/database/DB_forge.php @@ -0,0 +1,1033 @@ +db =& $db; + log_message('info', 'Database Forge Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name + * @return bool + */ + public function create_database($db_name) + { + if ($this->_create_database === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + elseif ( ! $this->db->query(sprintf($this->_create_database, $this->db->escape_identifiers($db_name), $this->db->char_set, $this->db->dbcollat))) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + if ( ! empty($this->db->data_cache['db_names'])) + { + $this->db->data_cache['db_names'][] = $db_name; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name + * @return bool + */ + public function drop_database($db_name) + { + if ($this->_drop_database === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + elseif ( ! $this->db->query(sprintf($this->_drop_database, $this->db->escape_identifiers($db_name)))) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + if ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($db_name), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Add Key + * + * @param string $key + * @param bool $primary + * @return CI_DB_forge + */ + public function add_key($key, $primary = FALSE) + { + // DO NOT change this! This condition is only applicable + // for PRIMARY keys because you can only have one such, + // and therefore all fields you add to it will be included + // in the same, composite PRIMARY KEY. + // + // It's not the same for regular indexes. + if ($primary === TRUE && is_array($key)) + { + foreach ($key as $one) + { + $this->add_key($one, $primary); + } + + return $this; + } + + if ($primary === TRUE) + { + $this->primary_keys[] = $key; + } + else + { + $this->keys[] = $key; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Add Field + * + * @param array $field + * @return CI_DB_forge + */ + public function add_field($field) + { + if (is_string($field)) + { + if ($field === 'id') + { + $this->add_field(array( + 'id' => array( + 'type' => 'INT', + 'constraint' => 9, + 'auto_increment' => TRUE + ) + )); + $this->add_key('id', TRUE); + } + else + { + if (strpos($field, ' ') === FALSE) + { + show_error('Field information is required for that operation.'); + } + + $this->fields[] = $field; + } + } + + if (is_array($field)) + { + $this->fields = array_merge($this->fields, $field); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @param string $table Table name + * @param bool $if_not_exists Whether to add IF NOT EXISTS condition + * @param array $attributes Associative array of table attributes + * @return bool + */ + public function create_table($table, $if_not_exists = FALSE, array $attributes = array()) + { + if ($table === '') + { + show_error('A table name is required for that operation.'); + } + else + { + $table = $this->db->dbprefix.$table; + } + + if (count($this->fields) === 0) + { + show_error('Field information is required.'); + } + + $sql = $this->_create_table($table, $if_not_exists, $attributes); + + if (is_bool($sql)) + { + $this->_reset(); + if ($sql === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + } + + if (($result = $this->db->query($sql)) !== FALSE) + { + if (isset($this->db->data_cache['table_names'])) + { + $this->db->data_cache['table_names'][] = $table; + } + + // Most databases don't support creating indexes from within the CREATE TABLE statement + if ( ! empty($this->keys)) + { + for ($i = 0, $sqls = $this->_process_indexes($table), $c = count($sqls); $i < $c; $i++) + { + $this->db->query($sqls[$i]); + } + } + } + + $this->_reset(); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @param string $table Table name + * @param bool $if_not_exists Whether to add 'IF NOT EXISTS' condition + * @param array $attributes Associative array of table attributes + * @return mixed + */ + protected function _create_table($table, $if_not_exists, $attributes) + { + if ($if_not_exists === TRUE && $this->_create_table_if === FALSE) + { + if ($this->db->table_exists($table)) + { + return TRUE; + } + + $if_not_exists = FALSE; + } + + $sql = ($if_not_exists) + ? sprintf($this->_create_table_if, $this->db->escape_identifiers($table)) + : 'CREATE TABLE'; + + $columns = $this->_process_fields(TRUE); + for ($i = 0, $c = count($columns); $i < $c; $i++) + { + $columns[$i] = ($columns[$i]['_literal'] !== FALSE) + ? "\n\t".$columns[$i]['_literal'] + : "\n\t".$this->_process_column($columns[$i]); + } + + $columns = implode(',', $columns) + .$this->_process_primary_keys($table); + + // Are indexes created from within the CREATE TABLE statement? (e.g. in MySQL) + if ($this->_create_table_keys === TRUE) + { + $columns .= $this->_process_indexes($table); + } + + // _create_table will usually have the following format: "%s %s (%s\n)" + $sql = sprintf($this->_create_table.'%s', + $sql, + $this->db->escape_identifiers($table), + $columns, + $this->_create_table_attr($attributes) + ); + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * CREATE TABLE attributes + * + * @param array $attributes Associative array of table attributes + * @return string + */ + protected function _create_table_attr($attributes) + { + $sql = ''; + + foreach (array_keys($attributes) as $key) + { + if (is_string($key)) + { + $sql .= ' '.strtoupper($key).' '.$attributes[$key]; + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @param string $table_name Table name + * @param bool $if_exists Whether to add an IF EXISTS condition + * @return bool + */ + public function drop_table($table_name, $if_exists = FALSE) + { + if ($table_name === '') + { + return ($this->db->db_debug) ? $this->db->display_error('db_table_name_required') : FALSE; + } + + if (($query = $this->_drop_table($this->db->dbprefix.$table_name, $if_exists)) === TRUE) + { + return TRUE; + } + + $query = $this->db->query($query); + + // Update table list cache + if ($query && ! empty($this->db->data_cache['table_names'])) + { + $key = array_search(strtolower($this->db->dbprefix.$table_name), array_map('strtolower', $this->db->data_cache['table_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['table_names'][$key]); + } + } + + return $query; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * Generates a platform-specific DROP TABLE string + * + * @param string $table Table name + * @param bool $if_exists Whether to add an IF EXISTS condition + * @return mixed (Returns a platform-specific DROP table string, or TRUE to indicate there's nothing to do) + */ + protected function _drop_table($table, $if_exists) + { + $sql = 'DROP TABLE'; + + if ($if_exists) + { + if ($this->_drop_table_if === FALSE) + { + if ( ! $this->db->table_exists($table)) + { + return TRUE; + } + } + else + { + $sql = sprintf($this->_drop_table_if, $this->db->escape_identifiers($table)); + } + } + + return $sql.' '.$this->db->escape_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * Rename Table + * + * @param string $table_name Old table name + * @param string $new_table_name New table name + * @return bool + */ + public function rename_table($table_name, $new_table_name) + { + if ($table_name === '' OR $new_table_name === '') + { + show_error('A table name is required for that operation.'); + return FALSE; + } + elseif ($this->_rename_table === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + $result = $this->db->query(sprintf($this->_rename_table, + $this->db->escape_identifiers($this->db->dbprefix.$table_name), + $this->db->escape_identifiers($this->db->dbprefix.$new_table_name)) + ); + + if ($result && ! empty($this->db->data_cache['table_names'])) + { + $key = array_search(strtolower($this->db->dbprefix.$table_name), array_map('strtolower', $this->db->data_cache['table_names']), TRUE); + if ($key !== FALSE) + { + $this->db->data_cache['table_names'][$key] = $this->db->dbprefix.$new_table_name; + } + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Column Add + * + * @todo Remove deprecated $_after option in 3.1+ + * @param string $table Table name + * @param array $field Column definition + * @param string $_after Column for AFTER clause (deprecated) + * @return bool + */ + public function add_column($table, $field, $_after = NULL) + { + // Work-around for literal column definitions + is_array($field) OR $field = array($field); + + foreach (array_keys($field) as $k) + { + // Backwards-compatibility work-around for MySQL/CUBRID AFTER clause (remove in 3.1+) + if ($_after !== NULL && is_array($field[$k]) && ! isset($field[$k]['after'])) + { + $field[$k]['after'] = $_after; + } + + $this->add_field(array($k => $field[$k])); + } + + $sqls = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->_process_fields()); + $this->_reset(); + if ($sqls === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + for ($i = 0, $c = count($sqls); $i < $c; $i++) + { + if ($this->db->query($sqls[$i]) === FALSE) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Column Drop + * + * @param string $table Table name + * @param string $column_name Column name + * @return bool + */ + public function drop_column($table, $column_name) + { + $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); + if ($sql === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Column Modify + * + * @param string $table Table name + * @param string $field Column definition + * @return bool + */ + public function modify_column($table, $field) + { + // Work-around for literal column definitions + is_array($field) OR $field = array($field); + + foreach (array_keys($field) as $k) + { + $this->add_field(array($k => $field[$k])); + } + + if (count($this->fields) === 0) + { + show_error('Field information is required.'); + } + + $sqls = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->_process_fields()); + $this->_reset(); + if ($sqls === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + for ($i = 0, $c = count($sqls); $i < $c; $i++) + { + if ($this->db->query($sqls[$i]) === FALSE) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '; + + // DROP has everything it needs now. + if ($alter_type === 'DROP') + { + return $sql.'DROP COLUMN '.$this->db->escape_identifiers($field); + } + + $sql .= ($alter_type === 'ADD') + ? 'ADD ' + : $alter_type.' COLUMN '; + + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + $sqls[] = $sql + .($field[$i]['_literal'] !== FALSE ? $field[$i]['_literal'] : $this->_process_column($field[$i])); + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Process fields + * + * @param bool $create_table + * @return array + */ + protected function _process_fields($create_table = FALSE) + { + $fields = array(); + + foreach ($this->fields as $key => $attributes) + { + if (is_int($key) && ! is_array($attributes)) + { + $fields[] = array('_literal' => $attributes); + continue; + } + + $attributes = array_change_key_case($attributes, CASE_UPPER); + + if ($create_table === TRUE && empty($attributes['TYPE'])) + { + continue; + } + + isset($attributes['TYPE']) && $this->_attr_type($attributes); + + $field = array( + 'name' => $key, + 'new_name' => isset($attributes['NAME']) ? $attributes['NAME'] : NULL, + 'type' => isset($attributes['TYPE']) ? $attributes['TYPE'] : NULL, + 'length' => '', + 'unsigned' => '', + 'null' => NULL, + 'unique' => '', + 'default' => '', + 'auto_increment' => '', + '_literal' => FALSE + ); + + isset($attributes['TYPE']) && $this->_attr_unsigned($attributes, $field); + + if ($create_table === FALSE) + { + if (isset($attributes['AFTER'])) + { + $field['after'] = $attributes['AFTER']; + } + elseif (isset($attributes['FIRST'])) + { + $field['first'] = (bool) $attributes['FIRST']; + } + } + + $this->_attr_default($attributes, $field); + + if (isset($attributes['NULL'])) + { + if ($attributes['NULL'] === TRUE) + { + $field['null'] = empty($this->_null) ? '' : ' '.$this->_null; + } + else + { + $field['null'] = ' NOT NULL'; + } + } + elseif ($create_table === TRUE) + { + $field['null'] = ' NOT NULL'; + } + + $this->_attr_auto_increment($attributes, $field); + $this->_attr_unique($attributes, $field); + + if (isset($attributes['COMMENT'])) + { + $field['comment'] = $this->db->escape($attributes['COMMENT']); + } + + if (isset($attributes['TYPE']) && ! empty($attributes['CONSTRAINT'])) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'ENUM': + case 'SET': + $attributes['CONSTRAINT'] = $this->db->escape($attributes['CONSTRAINT']); + default: + $field['length'] = is_array($attributes['CONSTRAINT']) + ? '('.implode(',', $attributes['CONSTRAINT']).')' + : '('.$attributes['CONSTRAINT'].')'; + break; + } + } + + $fields[] = $field; + } + + return $fields; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['default'] + .$field['null'] + .$field['auto_increment'] + .$field['unique']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + // Usually overridden by drivers + } + + // -------------------------------------------------------------------- + + /** + * Field attribute UNSIGNED + * + * Depending on the _unsigned property value: + * + * - TRUE will always set $field['unsigned'] to 'UNSIGNED' + * - FALSE will always set $field['unsigned'] to '' + * - array(TYPE) will set $field['unsigned'] to 'UNSIGNED', + * if $attributes['TYPE'] is found in the array + * - array(TYPE => UTYPE) will change $field['type'], + * from TYPE to UTYPE in case of a match + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_unsigned(&$attributes, &$field) + { + if (empty($attributes['UNSIGNED']) OR $attributes['UNSIGNED'] !== TRUE) + { + return; + } + + // Reset the attribute in order to avoid issues if we do type conversion + $attributes['UNSIGNED'] = FALSE; + + if (is_array($this->_unsigned)) + { + foreach (array_keys($this->_unsigned) as $key) + { + if (is_int($key) && strcasecmp($attributes['TYPE'], $this->_unsigned[$key]) === 0) + { + $field['unsigned'] = ' UNSIGNED'; + return; + } + elseif (is_string($key) && strcasecmp($attributes['TYPE'], $key) === 0) + { + $field['type'] = $key; + return; + } + } + + return; + } + + $field['unsigned'] = ($this->_unsigned === TRUE) ? ' UNSIGNED' : ''; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute DEFAULT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_default(&$attributes, &$field) + { + if ($this->_default === FALSE) + { + return; + } + + if (array_key_exists('DEFAULT', $attributes)) + { + if ($attributes['DEFAULT'] === NULL) + { + $field['default'] = empty($this->_null) ? '' : $this->_default.$this->_null; + + // Override the NULL attribute if that's our default + $attributes['NULL'] = TRUE; + $field['null'] = empty($this->_null) ? '' : ' '.$this->_null; + } + else + { + $field['default'] = $this->_default.$this->db->escape($attributes['DEFAULT']); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute UNIQUE + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_unique(&$attributes, &$field) + { + if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) + { + $field['unique'] = ' UNIQUE'; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' AUTO_INCREMENT'; + } + } + + // -------------------------------------------------------------------- + + /** + * Process primary keys + * + * @param string $table Table name + * @return string + */ + protected function _process_primary_keys($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->primary_keys); $i < $c; $i++) + { + if ( ! isset($this->fields[$this->primary_keys[$i]])) + { + unset($this->primary_keys[$i]); + } + } + + if (count($this->primary_keys) > 0) + { + $sql .= ",\n\tCONSTRAINT ".$this->db->escape_identifiers('pk_'.$table) + .' PRIMARY KEY('.implode(', ', $this->db->escape_identifiers($this->primary_keys)).')'; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table Table name + * @return string[] list of SQL statements + */ + protected function _process_indexes($table) + { + $sqls = array(); + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sqls[] = 'CREATE INDEX '.$this->db->escape_identifiers($table.'_'.implode('_', $this->keys[$i])) + .' ON '.$this->db->escape_identifiers($table) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).');'; + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Reset + * + * Resets table creation vars + * + * @return void + */ + protected function _reset() + { + $this->fields = $this->keys = $this->primary_keys = array(); + } + +} diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php new file mode 100644 index 0000000..f35b9fd --- /dev/null +++ b/system/database/DB_query_builder.php @@ -0,0 +1,2808 @@ +_protect_identifiers; + + foreach ($select as $val) + { + $val = trim($val); + + if ($val !== '') + { + $this->qb_select[] = $val; + $this->qb_no_escape[] = $escape; + + if ($this->qb_caching === TRUE) + { + $this->qb_cache_select[] = $val; + $this->qb_cache_exists[] = 'select'; + $this->qb_cache_no_escape[] = $escape; + } + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Select Max + * + * Generates a SELECT MAX(field) portion of a query + * + * @param string the field + * @param string an alias + * @return CI_DB_query_builder + */ + public function select_max($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'MAX'); + } + + // -------------------------------------------------------------------- + + /** + * Select Min + * + * Generates a SELECT MIN(field) portion of a query + * + * @param string the field + * @param string an alias + * @return CI_DB_query_builder + */ + public function select_min($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'MIN'); + } + + // -------------------------------------------------------------------- + + /** + * Select Average + * + * Generates a SELECT AVG(field) portion of a query + * + * @param string the field + * @param string an alias + * @return CI_DB_query_builder + */ + public function select_avg($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'AVG'); + } + + // -------------------------------------------------------------------- + + /** + * Select Sum + * + * Generates a SELECT SUM(field) portion of a query + * + * @param string the field + * @param string an alias + * @return CI_DB_query_builder + */ + public function select_sum($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'SUM'); + } + + // -------------------------------------------------------------------- + + /** + * SELECT [MAX|MIN|AVG|SUM]() + * + * @used-by select_max() + * @used-by select_min() + * @used-by select_avg() + * @used-by select_sum() + * + * @param string $select Field name + * @param string $alias + * @param string $type + * @return CI_DB_query_builder + */ + protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') + { + if ( ! is_string($select) OR $select === '') + { + $this->display_error('db_invalid_query'); + } + + $type = strtoupper($type); + + if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM'))) + { + show_error('Invalid function type: '.$type); + } + + if ($alias === '') + { + $alias = $this->_create_alias_from_table(trim($select)); + } + + $sql = $type.'('.$this->protect_identifiers(trim($select)).') AS '.$this->escape_identifiers(trim($alias)); + + $this->qb_select[] = $sql; + $this->qb_no_escape[] = NULL; + + if ($this->qb_caching === TRUE) + { + $this->qb_cache_select[] = $sql; + $this->qb_cache_exists[] = 'select'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Determines the alias name based on the table + * + * @param string $item + * @return string + */ + protected function _create_alias_from_table($item) + { + if (strpos($item, '.') !== FALSE) + { + $item = explode('.', $item); + return end($item); + } + + return $item; + } + + // -------------------------------------------------------------------- + + /** + * DISTINCT + * + * Sets a flag which tells the query string compiler to add DISTINCT + * + * @param bool $val + * @return CI_DB_query_builder + */ + public function distinct($val = TRUE) + { + $this->qb_distinct = is_bool($val) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * From + * + * Generates the FROM portion of the query + * + * @param mixed $from can be a string or array + * @return CI_DB_query_builder + */ + public function from($from) + { + foreach ((array) $from as $val) + { + if (strpos($val, ',') !== FALSE) + { + foreach (explode(',', $val) as $v) + { + $v = trim($v); + $this->_track_aliases($v); + + $this->qb_from[] = $v = $this->protect_identifiers($v, TRUE, NULL, FALSE); + + if ($this->qb_caching === TRUE) + { + $this->qb_cache_from[] = $v; + $this->qb_cache_exists[] = 'from'; + } + } + } + else + { + $val = trim($val); + + // Extract any aliases that might exist. We use this information + // in the protect_identifiers to know whether to add a table prefix + $this->_track_aliases($val); + + $this->qb_from[] = $val = $this->protect_identifiers($val, TRUE, NULL, FALSE); + + if ($this->qb_caching === TRUE) + { + $this->qb_cache_from[] = $val; + $this->qb_cache_exists[] = 'from'; + } + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * JOIN + * + * Generates the JOIN portion of the query + * + * @param string + * @param string the join condition + * @param string the type of join + * @param string whether not to try to escape identifiers + * @return CI_DB_query_builder + */ + public function join($table, $cond, $type = '', $escape = NULL) + { + if ($type !== '') + { + $type = strtoupper(trim($type)); + + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) + { + $type = ''; + } + else + { + $type .= ' '; + } + } + + // Extract any aliases that might exist. We use this information + // in the protect_identifiers to know whether to add a table prefix + $this->_track_aliases($table); + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + if ( ! $this->_has_operator($cond)) + { + $cond = ' USING ('.($escape ? $this->escape_identifiers($cond) : $cond).')'; + } + elseif ($escape === FALSE) + { + $cond = ' ON '.$cond; + } + else + { + // Split multiple conditions + if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) + { + $conditions = array(); + $joints = $joints[0]; + array_unshift($joints, array('', 0)); + + for ($i = count($joints) - 1, $pos = strlen($cond); $i >= 0; $i--) + { + $joints[$i][1] += strlen($joints[$i][0]); // offset + $conditions[$i] = substr($cond, $joints[$i][1], $pos - $joints[$i][1]); + $pos = $joints[$i][1] - strlen($joints[$i][0]); + $joints[$i] = $joints[$i][0]; + } + } + else + { + $conditions = array($cond); + $joints = array(''); + } + + $cond = ' ON '; + for ($i = 0, $c = count($conditions); $i < $c; $i++) + { + $operator = $this->_get_operator($conditions[$i]); + $cond .= $joints[$i]; + $cond .= preg_match("/(\(*)?([\[\]\w\.'-]+)".preg_quote($operator)."(.*)/i", $conditions[$i], $match) + ? $match[1].$this->protect_identifiers($match[2]).$operator.$this->protect_identifiers($match[3]) + : $conditions[$i]; + } + } + + // Do we want to escape the table name? + if ($escape === TRUE) + { + $table = $this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // Assemble the JOIN statement + $this->qb_join[] = $join = $type.'JOIN '.$table.$cond; + + if ($this->qb_caching === TRUE) + { + $this->qb_cache_join[] = $join; + $this->qb_cache_exists[] = 'join'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * WHERE + * + * Generates the WHERE portion of the query. + * Separates multiple calls with 'AND'. + * + * @param mixed + * @param mixed + * @param bool + * @return CI_DB_query_builder + */ + public function where($key, $value = NULL, $escape = NULL) + { + return $this->_wh('qb_where', $key, $value, 'AND ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR WHERE + * + * Generates the WHERE portion of the query. + * Separates multiple calls with 'OR'. + * + * @param mixed + * @param mixed + * @param bool + * @return CI_DB_query_builder + */ + public function or_where($key, $value = NULL, $escape = NULL) + { + return $this->_wh('qb_where', $key, $value, 'OR ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * WHERE, HAVING + * + * @used-by where() + * @used-by or_where() + * @used-by having() + * @used-by or_having() + * + * @param string $qb_key 'qb_where' or 'qb_having' + * @param mixed $key + * @param mixed $value + * @param string $type + * @param bool $escape + * @return CI_DB_query_builder + */ + protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = NULL) + { + $qb_cache_key = ($qb_key === 'qb_having') ? 'qb_cache_having' : 'qb_cache_where'; + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + // If the escape value was not set will base it on the global setting + is_bool($escape) OR $escape = $this->_protect_identifiers; + + foreach ($key as $k => $v) + { + $prefix = (count($this->$qb_key) === 0 && count($this->$qb_cache_key) === 0) + ? $this->_group_get_type('') + : $this->_group_get_type($type); + + if ($v !== NULL) + { + if ($escape === TRUE) + { + $v = $this->escape($v); + } + + if ( ! $this->_has_operator($k)) + { + $k .= ' = '; + } + } + elseif ( ! $this->_has_operator($k)) + { + // value appears not to have been set, assign the test to IS NULL + $k .= ' IS NULL'; + } + elseif (preg_match('/\s*(!?=|<>|\sIS(?:\s+NOT)?\s)\s*$/i', $k, $match, PREG_OFFSET_CAPTURE)) + { + $k = substr($k, 0, $match[0][1]).($match[1][0] === '=' ? ' IS NULL' : ' IS NOT NULL'); + } + + ${$qb_key} = array('condition' => $prefix.$k, 'value' => $v, 'escape' => $escape); + $this->{$qb_key}[] = ${$qb_key}; + if ($this->qb_caching === TRUE) + { + $this->{$qb_cache_key}[] = ${$qb_key}; + $this->qb_cache_exists[] = substr($qb_key, 3); + } + + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * WHERE IN + * + * Generates a WHERE field IN('item', 'item') SQL query, + * joined with 'AND' if appropriate. + * + * @param string $key The field to search + * @param array $values The values searched on + * @param bool $escape + * @return CI_DB_query_builder + */ + public function where_in($key = NULL, $values = NULL, $escape = NULL) + { + return $this->_where_in($key, $values, FALSE, 'AND ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR WHERE IN + * + * Generates a WHERE field IN('item', 'item') SQL query, + * joined with 'OR' if appropriate. + * + * @param string $key The field to search + * @param array $values The values searched on + * @param bool $escape + * @return CI_DB_query_builder + */ + public function or_where_in($key = NULL, $values = NULL, $escape = NULL) + { + return $this->_where_in($key, $values, FALSE, 'OR ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * WHERE NOT IN + * + * Generates a WHERE field NOT IN('item', 'item') SQL query, + * joined with 'AND' if appropriate. + * + * @param string $key The field to search + * @param array $values The values searched on + * @param bool $escape + * @return CI_DB_query_builder + */ + public function where_not_in($key = NULL, $values = NULL, $escape = NULL) + { + return $this->_where_in($key, $values, TRUE, 'AND ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR WHERE NOT IN + * + * Generates a WHERE field NOT IN('item', 'item') SQL query, + * joined with 'OR' if appropriate. + * + * @param string $key The field to search + * @param array $values The values searched on + * @param bool $escape + * @return CI_DB_query_builder + */ + public function or_where_not_in($key = NULL, $values = NULL, $escape = NULL) + { + return $this->_where_in($key, $values, TRUE, 'OR ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * Internal WHERE IN + * + * @used-by where_in() + * @used-by or_where_in() + * @used-by where_not_in() + * @used-by or_where_not_in() + * + * @param string $key The field to search + * @param array $values The values searched on + * @param bool $not If the statement would be IN or NOT IN + * @param string $type + * @param bool $escape + * @return CI_DB_query_builder + */ + protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ', $escape = NULL) + { + if ($key === NULL OR $values === NULL) + { + return $this; + } + + if ( ! is_array($values)) + { + $values = array($values); + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + $not = ($not) ? ' NOT' : ''; + + if ($escape === TRUE) + { + $where_in = array(); + foreach ($values as $value) + { + $where_in[] = $this->escape($value); + } + } + else + { + $where_in = array_values($values); + } + + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) + ? $this->_group_get_type('') + : $this->_group_get_type($type); + + $where_in = array( + 'condition' => $prefix.$key.$not.' IN('.implode(', ', $where_in).')', + 'value' => NULL, + 'escape' => $escape + ); + + $this->qb_where[] = $where_in; + if ($this->qb_caching === TRUE) + { + $this->qb_cache_where[] = $where_in; + $this->qb_cache_exists[] = 'where'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * LIKE + * + * Generates a %LIKE% portion of the query. + * Separates multiple calls with 'AND'. + * + * @param mixed $field + * @param string $match + * @param string $side + * @param bool $escape + * @return CI_DB_query_builder + */ + public function like($field, $match = '', $side = 'both', $escape = NULL) + { + return $this->_like($field, $match, 'AND ', $side, '', $escape); + } + + // -------------------------------------------------------------------- + + /** + * NOT LIKE + * + * Generates a NOT LIKE portion of the query. + * Separates multiple calls with 'AND'. + * + * @param mixed $field + * @param string $match + * @param string $side + * @param bool $escape + * @return CI_DB_query_builder + */ + public function not_like($field, $match = '', $side = 'both', $escape = NULL) + { + return $this->_like($field, $match, 'AND ', $side, 'NOT', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR LIKE + * + * Generates a %LIKE% portion of the query. + * Separates multiple calls with 'OR'. + * + * @param mixed $field + * @param string $match + * @param string $side + * @param bool $escape + * @return CI_DB_query_builder + */ + public function or_like($field, $match = '', $side = 'both', $escape = NULL) + { + return $this->_like($field, $match, 'OR ', $side, '', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR NOT LIKE + * + * Generates a NOT LIKE portion of the query. + * Separates multiple calls with 'OR'. + * + * @param mixed $field + * @param string $match + * @param string $side + * @param bool $escape + * @return CI_DB_query_builder + */ + public function or_not_like($field, $match = '', $side = 'both', $escape = NULL) + { + return $this->_like($field, $match, 'OR ', $side, 'NOT', $escape); + } + + // -------------------------------------------------------------------- + + /** + * Internal LIKE + * + * @used-by like() + * @used-by or_like() + * @used-by not_like() + * @used-by or_not_like() + * + * @param mixed $field + * @param string $match + * @param string $type + * @param string $side + * @param string $not + * @param bool $escape + * @return CI_DB_query_builder + */ + protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '', $escape = NULL) + { + if ( ! is_array($field)) + { + $field = array($field => $match); + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + // lowercase $side in case somebody writes e.g. 'BEFORE' instead of 'before' (doh) + $side = strtolower($side); + + foreach ($field as $k => $v) + { + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) + ? $this->_group_get_type('') : $this->_group_get_type($type); + + if ($escape === TRUE) + { + $v = $this->escape_like_str($v); + } + + switch ($side) + { + case 'none': + $v = "'{$v}'"; + break; + case 'before': + $v = "'%{$v}'"; + break; + case 'after': + $v = "'{$v}%'"; + break; + case 'both': + default: + $v = "'%{$v}%'"; + break; + } + + // some platforms require an escape sequence definition for LIKE wildcards + if ($escape === TRUE && $this->_like_escape_str !== '') + { + $v .= sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + $qb_where = array('condition' => "{$prefix} {$k} {$not} LIKE {$v}", 'value' => NULL, 'escape' => $escape); + $this->qb_where[] = $qb_where; + if ($this->qb_caching === TRUE) + { + $this->qb_cache_where[] = $qb_where; + $this->qb_cache_exists[] = 'where'; + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group. + * + * @param string $not (Internal use only) + * @param string $type (Internal use only) + * @return CI_DB_query_builder + */ + public function group_start($not = '', $type = 'AND ') + { + $type = $this->_group_get_type($type); + + $this->qb_where_group_started = TRUE; + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type; + $where = array( + 'condition' => $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' (', + 'value' => NULL, + 'escape' => FALSE + ); + + $this->qb_where[] = $where; + if ($this->qb_caching) + { + $this->qb_cache_where[] = $where; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but ORs the group + * + * @return CI_DB_query_builder + */ + public function or_group_start() + { + return $this->group_start('', 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but NOTs the group + * + * @return CI_DB_query_builder + */ + public function not_group_start() + { + return $this->group_start('NOT ', 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but OR NOTs the group + * + * @return CI_DB_query_builder + */ + public function or_not_group_start() + { + return $this->group_start('NOT ', 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Ends a query group + * + * @return CI_DB_query_builder + */ + public function group_end() + { + $this->qb_where_group_started = FALSE; + $where = array( + 'condition' => str_repeat(' ', $this->qb_where_group_count--).')', + 'value' => NULL, + 'escape' => FALSE + ); + + $this->qb_where[] = $where; + if ($this->qb_caching) + { + $this->qb_cache_where[] = $where; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Group_get_type + * + * @used-by group_start() + * @used-by _like() + * @used-by _wh() + * @used-by _where_in() + * + * @param string $type + * @return string + */ + protected function _group_get_type($type) + { + if ($this->qb_where_group_started) + { + $type = ''; + $this->qb_where_group_started = FALSE; + } + + return $type; + } + + // -------------------------------------------------------------------- + + /** + * GROUP BY + * + * @param string $by + * @param bool $escape + * @return CI_DB_query_builder + */ + public function group_by($by, $escape = NULL) + { + is_bool($escape) OR $escape = $this->_protect_identifiers; + + if (is_string($by)) + { + $by = ($escape === TRUE) + ? explode(',', $by) + : array($by); + } + + foreach ($by as $val) + { + $val = trim($val); + + if ($val !== '') + { + $val = array('field' => $val, 'escape' => $escape); + + $this->qb_groupby[] = $val; + if ($this->qb_caching === TRUE) + { + $this->qb_cache_groupby[] = $val; + $this->qb_cache_exists[] = 'groupby'; + } + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * HAVING + * + * Separates multiple calls with 'AND'. + * + * @param string $key + * @param string $value + * @param bool $escape + * @return CI_DB_query_builder + */ + public function having($key, $value = NULL, $escape = NULL) + { + return $this->_wh('qb_having', $key, $value, 'AND ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR HAVING + * + * Separates multiple calls with 'OR'. + * + * @param string $key + * @param string $value + * @param bool $escape + * @return CI_DB_query_builder + */ + public function or_having($key, $value = NULL, $escape = NULL) + { + return $this->_wh('qb_having', $key, $value, 'OR ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY + * + * @param string $orderby + * @param string $direction ASC, DESC or RANDOM + * @param bool $escape + * @return CI_DB_query_builder + */ + public function order_by($orderby, $direction = '', $escape = NULL) + { + $direction = strtoupper(trim($direction)); + + if ($direction === 'RANDOM') + { + $direction = ''; + + // Do we have a seed value? + $orderby = ctype_digit((string) $orderby) + ? sprintf($this->_random_keyword[1], $orderby) + : $this->_random_keyword[0]; + } + elseif (empty($orderby)) + { + return $this; + } + elseif ($direction !== '') + { + $direction = in_array($direction, array('ASC', 'DESC'), TRUE) ? ' '.$direction : ''; + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + if ($escape === FALSE) + { + $qb_orderby[] = array('field' => $orderby, 'direction' => $direction, 'escape' => FALSE); + } + else + { + $qb_orderby = array(); + foreach (explode(',', $orderby) as $field) + { + $qb_orderby[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE)) + ? array('field' => ltrim(substr($field, 0, $match[0][1])), 'direction' => ' '.$match[1][0], 'escape' => TRUE) + : array('field' => trim($field), 'direction' => $direction, 'escape' => TRUE); + } + } + + $this->qb_orderby = array_merge($this->qb_orderby, $qb_orderby); + if ($this->qb_caching === TRUE) + { + $this->qb_cache_orderby = array_merge($this->qb_cache_orderby, $qb_orderby); + $this->qb_cache_exists[] = 'orderby'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * @param int $value LIMIT value + * @param int $offset OFFSET value + * @return CI_DB_query_builder + */ + public function limit($value, $offset = 0) + { + is_null($value) OR $this->qb_limit = (int) $value; + empty($offset) OR $this->qb_offset = (int) $offset; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the OFFSET value + * + * @param int $offset OFFSET value + * @return CI_DB_query_builder + */ + public function offset($offset) + { + empty($offset) OR $this->qb_offset = (int) $offset; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * LIMIT string + * + * Generates a platform-specific LIMIT clause. + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + return $sql.' LIMIT '.($this->qb_offset ? $this->qb_offset.', ' : '').(int) $this->qb_limit; + } + + // -------------------------------------------------------------------- + + /** + * The "set" function. + * + * Allows key/value pairs to be set for inserting or updating + * + * @param mixed + * @param string + * @param bool + * @return CI_DB_query_builder + */ + public function set($key, $value = '', $escape = NULL) + { + $key = $this->_object_to_array($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + foreach ($key as $k => $v) + { + $this->qb_set[$this->protect_identifiers($k, FALSE, $escape)] = ($escape) + ? $this->escape($v) : $v; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get SELECT query string + * + * Compiles a SELECT query string and returns the sql. + * + * @param string the table name to select from (optional) + * @param bool TRUE: resets QB values; FALSE: leave QB values alone + * @return string + */ + public function get_compiled_select($table = '', $reset = TRUE) + { + if ($table !== '') + { + $this->_track_aliases($table); + $this->from($table); + } + + $select = $this->_compile_select(); + + if ($reset === TRUE) + { + $this->_reset_select(); + } + + return $select; + } + + // -------------------------------------------------------------------- + + /** + * Get + * + * Compiles the select statement based on the other functions called + * and runs the query + * + * @param string the table + * @param string the limit clause + * @param string the offset clause + * @return CI_DB_result + */ + public function get($table = '', $limit = NULL, $offset = NULL) + { + if ($table !== '') + { + $this->_track_aliases($table); + $this->from($table); + } + + if ( ! empty($limit)) + { + $this->limit($limit, $offset); + } + + $result = $this->query($this->_compile_select()); + $this->_reset_select(); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * "Count All Results" query + * + * Generates a platform-specific query string that counts all records + * returned by an Query Builder query. + * + * @param string + * @param bool the reset clause + * @return int + */ + public function count_all_results($table = '', $reset = TRUE) + { + if ($table !== '') + { + $this->_track_aliases($table); + $this->from($table); + } + + // ORDER BY usage is often problematic here (most notably + // on Microsoft SQL Server) and ultimately unnecessary + // for selecting COUNT(*) ... + $qb_orderby = $this->qb_orderby; + $qb_cache_orderby = $this->qb_cache_orderby; + $this->qb_orderby = $this->qb_cache_orderby = array(); + + $result = ($this->qb_distinct === TRUE OR ! empty($this->qb_groupby) OR ! empty($this->qb_cache_groupby) OR $this->qb_limit OR $this->qb_offset) + ? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results") + : $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows'))); + + if ($reset === TRUE) + { + $this->_reset_select(); + } + else + { + $this->qb_orderby = $qb_orderby; + $this->qb_cache_orderby = $qb_cache_orderby; + } + + if ($result->num_rows() === 0) + { + return 0; + } + + $row = $result->row(); + return (int) $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * get_where() + * + * Allows the where clause, limit and offset to be added directly + * + * @param string $table + * @param string $where + * @param int $limit + * @param int $offset + * @return CI_DB_result + */ + public function get_where($table = '', $where = NULL, $limit = NULL, $offset = NULL) + { + if ($table !== '') + { + $this->from($table); + } + + if ($where !== NULL) + { + $this->where($where); + } + + if ( ! empty($limit)) + { + $this->limit($limit, $offset); + } + + $result = $this->query($this->_compile_select()); + $this->_reset_select(); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Insert_Batch + * + * Compiles batch insert strings and runs the queries + * + * @param string $table Table to insert into + * @param array $set An associative array of insert values + * @param bool $escape Whether to escape values and identifiers + * @return int Number of rows inserted or FALSE on failure + */ + public function insert_batch($table, $set = NULL, $escape = NULL, $batch_size = 100) + { + if ($set === NULL) + { + if (empty($this->qb_set)) + { + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; + } + } + else + { + if (empty($set)) + { + return ($this->db_debug) ? $this->display_error('insert_batch() called with no data') : FALSE; + } + + $this->set_insert_batch($set, '', $escape); + } + + if (strlen($table) === 0) + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + + // Batch this baby + $affected_rows = 0; + for ($i = 0, $total = count($this->qb_set); $i < $total; $i += $batch_size) + { + if ($this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, $escape, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, $batch_size)))) + { + $affected_rows += $this->affected_rows(); + } + } + + $this->_reset_write(); + return $affected_rows; + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _insert_batch($table, $keys, $values) + { + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); + } + + // -------------------------------------------------------------------- + + /** + * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts + * + * @param mixed + * @param string + * @param bool + * @return CI_DB_query_builder + */ + public function set_insert_batch($key, $value = '', $escape = NULL) + { + $key = $this->_object_to_array_batch($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + $keys = array_keys($this->_object_to_array(reset($key))); + sort($keys); + + foreach ($key as $row) + { + $row = $this->_object_to_array($row); + if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0) + { + // batch function above returns an error on an empty array + $this->qb_set[] = array(); + return; + } + + ksort($row); // puts $row in the same order as our keys + + if ($escape !== FALSE) + { + $clean = array(); + foreach ($row as $value) + { + $clean[] = $this->escape($value); + } + + $row = $clean; + } + + $this->qb_set[] = '('.implode(',', $row).')'; + } + + foreach ($keys as $k) + { + $this->qb_keys[] = $this->protect_identifiers($k, FALSE, $escape); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get INSERT query string + * + * Compiles an insert query and returns the sql + * + * @param string the table to insert into + * @param bool TRUE: reset QB values; FALSE: leave QB values alone + * @return string + */ + public function get_compiled_insert($table = '', $reset = TRUE) + { + if ($this->_validate_insert($table) === FALSE) + { + return FALSE; + } + + $sql = $this->_insert( + $this->protect_identifiers( + $this->qb_from[0], TRUE, NULL, FALSE + ), + array_keys($this->qb_set), + array_values($this->qb_set) + ); + + if ($reset === TRUE) + { + $this->_reset_write(); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Insert + * + * Compiles an insert string and runs the query + * + * @param string the table to insert data into + * @param array an associative array of insert values + * @param bool $escape Whether to escape values and identifiers + * @return bool TRUE on success, FALSE on failure + */ + public function insert($table = '', $set = NULL, $escape = NULL) + { + if ($set !== NULL) + { + $this->set($set, '', $escape); + } + + if ($this->_validate_insert($table) === FALSE) + { + return FALSE; + } + + $sql = $this->_insert( + $this->protect_identifiers( + $this->qb_from[0], TRUE, $escape, FALSE + ), + array_keys($this->qb_set), + array_values($this->qb_set) + ); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Validate Insert + * + * This method is used by both insert() and get_compiled_insert() to + * validate that the there data is actually being set and that table + * has been chosen to be inserted into. + * + * @param string the table to insert data into + * @return string + */ + protected function _validate_insert($table = '') + { + if (count($this->qb_set) === 0) + { + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; + } + + if ($table !== '') + { + $this->qb_from[0] = $table; + } + elseif ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Replace + * + * Compiles an replace into string and runs the query + * + * @param string the table to replace data into + * @param array an associative array of insert values + * @return bool TRUE on success, FALSE on failure + */ + public function replace($table = '', $set = NULL) + { + if ($set !== NULL) + { + $this->set($set); + } + + if (count($this->qb_set) === 0) + { + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; + } + + if ($table === '') + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + + $sql = $this->_replace($this->protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->qb_set), array_values($this->qb_set)); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Replace statement + * + * Generates a platform-specific replace string from the supplied data + * + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + protected function _replace($table, $keys, $values) + { + return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * Note: This is only used (and overridden) by MySQL and CUBRID. + * + * @return string + */ + protected function _from_tables() + { + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + + /** + * Get UPDATE query string + * + * Compiles an update query and returns the sql + * + * @param string the table to update + * @param bool TRUE: reset QB values; FALSE: leave QB values alone + * @return string + */ + public function get_compiled_update($table = '', $reset = TRUE) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if ($this->_validate_update($table) === FALSE) + { + return FALSE; + } + + $sql = $this->_update($this->qb_from[0], $this->qb_set); + + if ($reset === TRUE) + { + $this->_reset_write(); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * UPDATE + * + * Compiles an update string and runs the query. + * + * @param string $table + * @param array $set An associative array of update values + * @param mixed $where + * @param int $limit + * @return bool TRUE on success, FALSE on failure + */ + public function update($table = '', $set = NULL, $where = NULL, $limit = NULL) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if ($set !== NULL) + { + $this->set($set); + } + + if ($this->_validate_update($table) === FALSE) + { + return FALSE; + } + + if ($where !== NULL) + { + $this->where($where); + } + + if ( ! empty($limit)) + { + $this->limit($limit); + } + + $sql = $this->_update($this->qb_from[0], $this->qb_set); + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Validate Update + * + * This method is used by both update() and get_compiled_update() to + * validate that data is actually being set and that a table has been + * chosen to be update. + * + * @param string the table to update data on + * @return bool + */ + protected function _validate_update($table) + { + if (count($this->qb_set) === 0) + { + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; + } + + if ($table !== '') + { + $this->qb_from = array($this->protect_identifiers($table, TRUE, NULL, FALSE)); + } + elseif ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Update_Batch + * + * Compiles an update string and runs the query + * + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param string the where key + * @return int number of rows affected or FALSE on failure + */ + public function update_batch($table, $set = NULL, $index = NULL, $batch_size = 100) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if ($index === NULL) + { + return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE; + } + + if ($set === NULL) + { + if (empty($this->qb_set_ub)) + { + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; + } + } + else + { + if (empty($set)) + { + return ($this->db_debug) ? $this->display_error('update_batch() called with no data') : FALSE; + } + + $this->set_update_batch($set, $index); + } + + if (strlen($table) === 0) + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + + // Batch this baby + $affected_rows = 0; + for ($i = 0, $total = count($this->qb_set_ub); $i < $total; $i += $batch_size) + { + if ($this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set_ub, $i, $batch_size), $index))) + { + $affected_rows += $this->affected_rows(); + } + + $this->qb_where = array(); + } + + $this->_reset_write(); + return $affected_rows; + } + + // -------------------------------------------------------------------- + + /** + * Update_Batch statement + * + * Generates a platform-specific batch update string from the supplied data + * + * @param string $table Table name + * @param array $values Update data + * @param string $index WHERE key + * @return string + */ + protected function _update_batch($table, $values, $index) + { + $ids = array(); + foreach ($values as $key => $val) + { + $ids[] = $val[$index]['value']; + + foreach (array_keys($val) as $field) + { + if ($field !== $index) + { + $final[$val[$field]['field']][] = 'WHEN '.$val[$index]['field'].' = '.$val[$index]['value'].' THEN '.$val[$field]['value']; + } + } + } + + $cases = ''; + foreach ($final as $k => $v) + { + $cases .= $k." = CASE \n" + .implode("\n", $v)."\n" + .'ELSE '.$k.' END, '; + } + + $this->where($val[$index]['field'].' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); + } + + // -------------------------------------------------------------------- + + /** + * The "set_update_batch" function. Allows key/value pairs to be set for batch updating + * + * @param array + * @param string + * @param bool + * @return CI_DB_query_builder + */ + public function set_update_batch($key, $index = '', $escape = NULL) + { + $key = $this->_object_to_array_batch($key); + + if ( ! is_array($key)) + { + // @todo error + } + + is_bool($escape) OR $escape = $this->_protect_identifiers; + + foreach ($key as $k => $v) + { + $index_set = FALSE; + $clean = array(); + foreach ($v as $k2 => $v2) + { + if ($k2 === $index) + { + $index_set = TRUE; + } + + $clean[$k2] = array( + 'field' => $this->protect_identifiers($k2, FALSE, $escape), + 'value' => ($escape === FALSE ? $v2 : $this->escape($v2)) + ); + } + + if ($index_set === FALSE) + { + return $this->display_error('db_batch_missing_index'); + } + + $this->qb_set_ub[] = $clean; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Empty Table + * + * Compiles a delete string and runs "DELETE FROM table" + * + * @param string the table to empty + * @return bool TRUE on success, FALSE on failure + */ + public function empty_table($table = '') + { + if ($table === '') + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + else + { + $table = $this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + $sql = $this->_delete($table); + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Truncate + * + * Compiles a truncate string and runs the query + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @param string the table to truncate + * @return bool TRUE on success, FALSE on failure + */ + public function truncate($table = '') + { + if ($table === '') + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + else + { + $table = $this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + $sql = $this->_truncate($table); + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the truncate() command, + * then this method maps to 'DELETE FROM table' + * + * @param string the table name + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Get DELETE query string + * + * Compiles a delete query string and returns the sql + * + * @param string the table to delete from + * @param bool TRUE: reset QB values; FALSE: leave QB values alone + * @return string + */ + public function get_compiled_delete($table = '', $reset = TRUE) + { + $this->return_delete_sql = TRUE; + $sql = $this->delete($table, '', NULL, $reset); + $this->return_delete_sql = FALSE; + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * Compiles a delete string and runs the query + * + * @param mixed the table(s) to delete from. String or array + * @param mixed the where clause + * @param mixed the limit clause + * @param bool + * @return mixed + */ + public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if ($table === '') + { + if ( ! isset($this->qb_from[0])) + { + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; + } + + $table = $this->qb_from[0]; + } + elseif (is_array($table)) + { + empty($where) && $reset_data = FALSE; + + foreach ($table as $single_table) + { + $this->delete($single_table, $where, $limit, $reset_data); + } + + return; + } + else + { + $table = $this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + if ($where !== '') + { + $this->where($where); + } + + if ( ! empty($limit)) + { + $this->limit($limit); + } + + if (count($this->qb_where) === 0) + { + return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE; + } + + $sql = $this->_delete($table); + if ($reset_data) + { + $this->_reset_write(); + } + + return ($this->return_delete_sql === TRUE) ? $sql : $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string the table name + * @return string + */ + protected function _delete($table) + { + return 'DELETE FROM '.$table.$this->_compile_wh('qb_where') + .($this->qb_limit !== FALSE ? ' LIMIT '.$this->qb_limit : ''); + } + + // -------------------------------------------------------------------- + + /** + * DB Prefix + * + * Prepends a database prefix if one exists in configuration + * + * @param string the table + * @return string + */ + public function dbprefix($table = '') + { + if ($table === '') + { + $this->display_error('db_table_name_required'); + } + + return $this->dbprefix.$table; + } + + // -------------------------------------------------------------------- + + /** + * Set DB Prefix + * + * Set's the DB Prefix to something new without needing to reconnect + * + * @param string the prefix + * @return string + */ + public function set_dbprefix($prefix = '') + { + return $this->dbprefix = $prefix; + } + + // -------------------------------------------------------------------- + + /** + * Track Aliases + * + * Used to track SQL statements written with aliased tables. + * + * @param string The table to inspect + * @return string + */ + protected function _track_aliases($table) + { + if (is_array($table)) + { + foreach ($table as $t) + { + $this->_track_aliases($t); + } + return; + } + + // Does the string contain a comma? If so, we need to separate + // the string into discreet statements + if (strpos($table, ',') !== FALSE) + { + return $this->_track_aliases(explode(',', $table)); + } + + // if a table alias is used we can recognize it by a space + if (strpos($table, ' ') !== FALSE) + { + // if the alias is written with the AS keyword, remove it + $table = preg_replace('/\s+AS\s+/i', ' ', $table); + + // Grab the alias + $table = trim(strrchr($table, ' ')); + + // Store the alias, if it doesn't already exist + if ( ! in_array($table, $this->qb_aliased_tables, TRUE)) + { + $this->qb_aliased_tables[] = $table; + if ($this->qb_caching === TRUE && ! in_array($table, $this->qb_cache_aliased_tables, TRUE)) + { + $this->qb_cache_aliased_tables[] = $table; + $this->qb_cache_exists[] = 'aliased_tables'; + } + } + } + } + + // -------------------------------------------------------------------- + + /** + * Compile the SELECT statement + * + * Generates a query string based on which functions were used. + * Should not be called directly. + * + * @param bool $select_override + * @return string + */ + protected function _compile_select($select_override = FALSE) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + // Write the "select" portion of the query + if ($select_override !== FALSE) + { + $sql = $select_override; + } + else + { + $sql = ( ! $this->qb_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + if (count($this->qb_select) === 0) + { + $sql .= '*'; + } + else + { + // Cycle through the "select" portion of the query and prep each column name. + // The reason we protect identifiers here rather than in the select() function + // is because until the user calls the from() function we don't know if there are aliases + foreach ($this->qb_select as $key => $val) + { + $no_escape = isset($this->qb_no_escape[$key]) ? $this->qb_no_escape[$key] : NULL; + $this->qb_select[$key] = $this->protect_identifiers($val, FALSE, $no_escape); + } + + $sql .= implode(', ', $this->qb_select); + } + } + + // Write the "FROM" portion of the query + if (count($this->qb_from) > 0) + { + $sql .= "\nFROM ".$this->_from_tables(); + } + + // Write the "JOIN" portion of the query + if (count($this->qb_join) > 0) + { + $sql .= "\n".implode("\n", $this->qb_join); + } + + $sql .= $this->_compile_wh('qb_where') + .$this->_compile_group_by() + .$this->_compile_wh('qb_having') + .$this->_compile_order_by(); // ORDER BY + + // LIMIT + if ($this->qb_limit !== FALSE OR $this->qb_offset) + { + return $this->_limit($sql."\n"); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Compile WHERE, HAVING statements + * + * Escapes identifiers in WHERE and HAVING statements at execution time. + * + * Required so that aliases are tracked properly, regardless of whether + * where(), or_where(), having(), or_having are called prior to from(), + * join() and dbprefix is added only if needed. + * + * @param string $qb_key 'qb_where' or 'qb_having' + * @return string SQL statement + */ + protected function _compile_wh($qb_key) + { + if (count($this->$qb_key) > 0) + { + for ($i = 0, $c = count($this->$qb_key); $i < $c; $i++) + { + // Is this condition already compiled? + if (is_string($this->{$qb_key}[$i])) + { + continue; + } + elseif ($this->{$qb_key}[$i]['escape'] === FALSE) + { + $this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition'].(isset($this->{$qb_key}[$i]['value']) ? ' '.$this->{$qb_key}[$i]['value'] : ''); + continue; + } + + // Split multiple conditions + $conditions = preg_split( + '/((?:^|\s+)AND\s+|(?:^|\s+)OR\s+)/i', + $this->{$qb_key}[$i]['condition'], + -1, + PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY + ); + + for ($ci = 0, $cc = count($conditions); $ci < $cc; $ci++) + { + if (($op = $this->_get_operator($conditions[$ci])) === FALSE + OR ! preg_match('/^(\(?)(.*)('.preg_quote($op, '/').')\s*(.*(? '(test <= foo)', /* the whole thing */ + // 1 => '(', /* optional */ + // 2 => 'test', /* the field name */ + // 3 => ' <= ', /* $op */ + // 4 => 'foo', /* optional, if $op is e.g. 'IS NULL' */ + // 5 => ')' /* optional */ + // ); + + if ( ! empty($matches[4])) + { + $this->_is_literal($matches[4]) OR $matches[4] = $this->protect_identifiers(trim($matches[4])); + $matches[4] = ' '.$matches[4]; + } + + $conditions[$ci] = $matches[1].$this->protect_identifiers(trim($matches[2])) + .' '.trim($matches[3]).$matches[4].$matches[5]; + } + + $this->{$qb_key}[$i] = implode('', $conditions).(isset($this->{$qb_key}[$i]['value']) ? ' '.$this->{$qb_key}[$i]['value'] : ''); + } + + return ($qb_key === 'qb_having' ? "\nHAVING " : "\nWHERE ") + .implode("\n", $this->$qb_key); + } + + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Compile GROUP BY + * + * Escapes identifiers in GROUP BY statements at execution time. + * + * Required so that aliases are tracked properly, regardless of whether + * group_by() is called prior to from(), join() and dbprefix is added + * only if needed. + * + * @return string SQL statement + */ + protected function _compile_group_by() + { + if (count($this->qb_groupby) > 0) + { + for ($i = 0, $c = count($this->qb_groupby); $i < $c; $i++) + { + // Is it already compiled? + if (is_string($this->qb_groupby[$i])) + { + continue; + } + + $this->qb_groupby[$i] = ($this->qb_groupby[$i]['escape'] === FALSE OR $this->_is_literal($this->qb_groupby[$i]['field'])) + ? $this->qb_groupby[$i]['field'] + : $this->protect_identifiers($this->qb_groupby[$i]['field']); + } + + return "\nGROUP BY ".implode(', ', $this->qb_groupby); + } + + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Compile ORDER BY + * + * Escapes identifiers in ORDER BY statements at execution time. + * + * Required so that aliases are tracked properly, regardless of whether + * order_by() is called prior to from(), join() and dbprefix is added + * only if needed. + * + * @return string SQL statement + */ + protected function _compile_order_by() + { + if (empty($this->qb_orderby)) + { + return ''; + } + + for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++) + { + if (is_string($this->qb_orderby[$i])) + { + continue; + } + + if ($this->qb_orderby[$i]['escape'] !== FALSE && ! $this->_is_literal($this->qb_orderby[$i]['field'])) + { + $this->qb_orderby[$i]['field'] = $this->protect_identifiers($this->qb_orderby[$i]['field']); + } + + $this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction']; + } + + return "\nORDER BY ".implode(', ', $this->qb_orderby); + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @param object + * @return array + */ + protected function _object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + // There are some built in keys we need to ignore for this conversion + if ( ! is_object($val) && ! is_array($val) && $key !== '_parent_name') + { + $array[$key] = $val; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @param object + * @return array + */ + protected function _object_to_array_batch($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + $out = get_object_vars($object); + $fields = array_keys($out); + + foreach ($fields as $val) + { + // There are some built in keys we need to ignore for this conversion + if ($val !== '_parent_name') + { + $i = 0; + foreach ($out[$val] as $data) + { + $array[$i++][$val] = $data; + } + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Start Cache + * + * Starts QB caching + * + * @return CI_DB_query_builder + */ + public function start_cache() + { + $this->qb_caching = TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Stop Cache + * + * Stops QB caching + * + * @return CI_DB_query_builder + */ + public function stop_cache() + { + $this->qb_caching = FALSE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Flush Cache + * + * Empties the QB cache + * + * @return CI_DB_query_builder + */ + public function flush_cache() + { + $this->_reset_run(array( + 'qb_cache_select' => array(), + 'qb_cache_from' => array(), + 'qb_cache_join' => array(), + 'qb_cache_where' => array(), + 'qb_cache_groupby' => array(), + 'qb_cache_having' => array(), + 'qb_cache_orderby' => array(), + 'qb_cache_set' => array(), + 'qb_cache_exists' => array(), + 'qb_cache_no_escape' => array(), + 'qb_cache_aliased_tables' => array() + )); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Merge Cache + * + * When called, this function merges any cached QB arrays with + * locally called ones. + * + * @return void + */ + protected function _merge_cache() + { + if (count($this->qb_cache_exists) === 0) + { + return; + } + elseif (in_array('select', $this->qb_cache_exists, TRUE)) + { + $qb_no_escape = $this->qb_cache_no_escape; + } + + foreach (array_unique($this->qb_cache_exists) as $val) // select, from, etc. + { + $qb_variable = 'qb_'.$val; + $qb_cache_var = 'qb_cache_'.$val; + $qb_new = $this->$qb_cache_var; + + for ($i = 0, $c = count($this->$qb_variable); $i < $c; $i++) + { + if ( ! in_array($this->{$qb_variable}[$i], $qb_new, TRUE)) + { + $qb_new[] = $this->{$qb_variable}[$i]; + if ($val === 'select') + { + $qb_no_escape[] = $this->qb_no_escape[$i]; + } + } + } + + $this->$qb_variable = $qb_new; + if ($val === 'select') + { + $this->qb_no_escape = $qb_no_escape; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Is literal + * + * Determines if a string represents a literal value or a field name + * + * @param string $str + * @return bool + */ + protected function _is_literal($str) + { + $str = trim($str); + + if (empty($str) OR ctype_digit($str) OR (string) (float) $str === $str OR in_array(strtoupper($str), array('TRUE', 'FALSE'), TRUE)) + { + return TRUE; + } + + static $_str; + + if (empty($_str)) + { + $_str = ($this->_escape_char !== '"') + ? array('"', "'") : array("'"); + } + + return in_array($str[0], $_str, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Reset Query Builder values. + * + * Publicly-visible method to reset the QB values. + * + * @return CI_DB_query_builder + */ + public function reset_query() + { + $this->_reset_select(); + $this->_reset_write(); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Resets the query builder values. Called by the get() function + * + * @param array An array of fields to reset + * @return void + */ + protected function _reset_run($qb_reset_items) + { + foreach ($qb_reset_items as $item => $default_value) + { + $this->$item = $default_value; + } + } + + // -------------------------------------------------------------------- + + /** + * Resets the query builder values. Called by the get() function + * + * @return void + */ + protected function _reset_select() + { + $this->_reset_run(array( + 'qb_select' => array(), + 'qb_from' => array(), + 'qb_join' => array(), + 'qb_where' => array(), + 'qb_groupby' => array(), + 'qb_having' => array(), + 'qb_orderby' => array(), + 'qb_aliased_tables' => array(), + 'qb_no_escape' => array(), + 'qb_distinct' => FALSE, + 'qb_limit' => FALSE, + 'qb_offset' => FALSE + )); + } + + // -------------------------------------------------------------------- + + /** + * Resets the query builder "write" values. + * + * Called by the insert() update() insert_batch() update_batch() and delete() functions + * + * @return void + */ + protected function _reset_write() + { + $this->_reset_run(array( + 'qb_set' => array(), + 'qb_set_ub' => array(), + 'qb_from' => array(), + 'qb_join' => array(), + 'qb_where' => array(), + 'qb_orderby' => array(), + 'qb_keys' => array(), + 'qb_limit' => FALSE + )); + } + +} diff --git a/system/database/DB_result.php b/system/database/DB_result.php new file mode 100644 index 0000000..ed5252d --- /dev/null +++ b/system/database/DB_result.php @@ -0,0 +1,665 @@ +conn_id = $driver_object->conn_id; + $this->result_id = $driver_object->result_id; + } + + // -------------------------------------------------------------------- + + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + if (is_int($this->num_rows)) + { + return $this->num_rows; + } + elseif (count($this->result_array) > 0) + { + return $this->num_rows = count($this->result_array); + } + elseif (count($this->result_object) > 0) + { + return $this->num_rows = count($this->result_object); + } + + return $this->num_rows = count($this->result_array()); + } + + // -------------------------------------------------------------------- + + /** + * Query result. Acts as a wrapper function for the following functions. + * + * @param string $type 'object', 'array' or a custom class name + * @return array + */ + public function result($type = 'object') + { + if ($type === 'array') + { + return $this->result_array(); + } + elseif ($type === 'object') + { + return $this->result_object(); + } + + return $this->custom_result_object($type); + } + + // -------------------------------------------------------------------- + + /** + * Custom query result. + * + * @param string $class_name + * @return array + */ + public function custom_result_object($class_name) + { + if (isset($this->custom_result_object[$class_name])) + { + return $this->custom_result_object[$class_name]; + } + elseif ( ! $this->result_id OR $this->num_rows === 0) + { + return array(); + } + + // Don't fetch the result set again if we already have it + $_data = NULL; + if (($c = count($this->result_array)) > 0) + { + $_data = 'result_array'; + } + elseif (($c = count($this->result_object)) > 0) + { + $_data = 'result_object'; + } + + if ($_data !== NULL) + { + for ($i = 0; $i < $c; $i++) + { + $this->custom_result_object[$class_name][$i] = new $class_name(); + + foreach ($this->{$_data}[$i] as $key => $value) + { + $this->custom_result_object[$class_name][$i]->$key = $value; + } + } + + return $this->custom_result_object[$class_name]; + } + + is_null($this->row_data) OR $this->data_seek(0); + $this->custom_result_object[$class_name] = array(); + + while ($row = $this->_fetch_object($class_name)) + { + $this->custom_result_object[$class_name][] = $row; + } + + return $this->custom_result_object[$class_name]; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @return array + */ + public function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + + // In the event that query caching is on, the result_id variable + // will not be a valid resource so we'll simply return an empty + // array. + if ( ! $this->result_id OR $this->num_rows === 0) + { + return array(); + } + + if (($c = count($this->result_array)) > 0) + { + for ($i = 0; $i < $c; $i++) + { + $this->result_object[$i] = (object) $this->result_array[$i]; + } + + return $this->result_object; + } + + is_null($this->row_data) OR $this->data_seek(0); + while ($row = $this->_fetch_object()) + { + $this->result_object[] = $row; + } + + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @return array + */ + public function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // In the event that query caching is on, the result_id variable + // will not be a valid resource so we'll simply return an empty + // array. + if ( ! $this->result_id OR $this->num_rows === 0) + { + return array(); + } + + if (($c = count($this->result_object)) > 0) + { + for ($i = 0; $i < $c; $i++) + { + $this->result_array[$i] = (array) $this->result_object[$i]; + } + + return $this->result_array; + } + + is_null($this->row_data) OR $this->data_seek(0); + while ($row = $this->_fetch_assoc()) + { + $this->result_array[] = $row; + } + + return $this->result_array; + } + + // -------------------------------------------------------------------- + + /** + * Row + * + * A wrapper method. + * + * @param mixed $n + * @param string $type 'object' or 'array' + * @return mixed + */ + public function row($n = 0, $type = 'object') + { + if ( ! is_numeric($n)) + { + // We cache the row data for subsequent uses + is_array($this->row_data) OR $this->row_data = $this->row_array(0); + + // array_key_exists() instead of isset() to allow for NULL values + if (empty($this->row_data) OR ! array_key_exists($n, $this->row_data)) + { + return NULL; + } + + return $this->row_data[$n]; + } + + if ($type === 'object') return $this->row_object($n); + elseif ($type === 'array') return $this->row_array($n); + + return $this->custom_row_object($n, $type); + } + + // -------------------------------------------------------------------- + + /** + * Assigns an item into a particular column slot + * + * @param mixed $key + * @param mixed $value + * @return void + */ + public function set_row($key, $value = NULL) + { + // We cache the row data for subsequent uses + if ( ! is_array($this->row_data)) + { + $this->row_data = $this->row_array(0); + } + + if (is_array($key)) + { + foreach ($key as $k => $v) + { + $this->row_data[$k] = $v; + } + return; + } + + if ($key !== '' && $value !== NULL) + { + $this->row_data[$key] = $value; + } + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - custom object version + * + * @param int $n + * @param string $type + * @return object + */ + public function custom_row_object($n, $type) + { + isset($this->custom_result_object[$type]) OR $this->custom_result_object[$type] = $this->custom_result_object($type); + + if (count($this->custom_result_object[$type]) === 0) + { + return NULL; + } + + if ($n !== $this->current_row && isset($this->custom_result_object[$type][$n])) + { + $this->current_row = $n; + } + + return $this->custom_result_object[$type][$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - object version + * + * @param int $n + * @return object + */ + public function row_object($n = 0) + { + $result = $this->result_object(); + if (count($result) === 0) + { + return NULL; + } + + if ($n !== $this->current_row && isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - array version + * + * @param int $n + * @return array + */ + public function row_array($n = 0) + { + $result = $this->result_array(); + if (count($result) === 0) + { + return NULL; + } + + if ($n !== $this->current_row && isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "first" row + * + * @param string $type + * @return mixed + */ + public function first_row($type = 'object') + { + $result = $this->result($type); + return (count($result) === 0) ? NULL : $result[0]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "last" row + * + * @param string $type + * @return mixed + */ + public function last_row($type = 'object') + { + $result = $this->result($type); + return (count($result) === 0) ? NULL : $result[count($result) - 1]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "next" row + * + * @param string $type + * @return mixed + */ + public function next_row($type = 'object') + { + $result = $this->result($type); + if (count($result) === 0) + { + return NULL; + } + + return isset($result[$this->current_row + 1]) + ? $result[++$this->current_row] + : NULL; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "previous" row + * + * @param string $type + * @return mixed + */ + public function previous_row($type = 'object') + { + $result = $this->result($type); + if (count($result) === 0) + { + return NULL; + } + + if (isset($result[$this->current_row - 1])) + { + --$this->current_row; + } + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns an unbuffered row and move pointer to next row + * + * @param string $type 'array', 'object' or a custom class name + * @return mixed + */ + public function unbuffered_row($type = 'object') + { + if ($type === 'array') + { + return $this->_fetch_assoc(); + } + elseif ($type === 'object') + { + return $this->_fetch_object(); + } + + return $this->_fetch_object($type); + } + + // -------------------------------------------------------------------- + + /** + * The following methods are normally overloaded by the identically named + * methods in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver. + * These functions are primarily here to prevent undefined function errors + * when a cached result object is in use. They are not otherwise fully + * operational due to the unavailability of the database resource IDs with + * cached results. + */ + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * Overridden by driver result classes. + * + * @return int + */ + public function num_fields() + { + return 0; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names. + * + * Overridden by driver result classes. + * + * @return array + */ + public function list_fields() + { + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data. + * + * Overridden by driver result classes. + * + * @return array + */ + public function field_data() + { + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * Overridden by driver result classes. + * + * @return void + */ + public function free_result() + { + $this->result_id = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * Overridden by driver result classes. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array. + * + * Overridden by driver result classes. + * + * @return array + */ + protected function _fetch_assoc() + { + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object. + * + * Overridden by driver result classes. + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return new $class_name(); + } + +} diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php new file mode 100644 index 0000000..6642fda --- /dev/null +++ b/system/database/DB_utility.php @@ -0,0 +1,424 @@ +db =& $db; + log_message('info', 'Database Utility Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @return array + */ + public function list_databases() + { + // Is there a cached result? + if (isset($this->db->data_cache['db_names'])) + { + return $this->db->data_cache['db_names']; + } + elseif ($this->_list_databases === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + $this->db->data_cache['db_names'] = array(); + + $query = $this->db->query($this->_list_databases); + if ($query === FALSE) + { + return $this->db->data_cache['db_names']; + } + + for ($i = 0, $query = $query->result_array(), $c = count($query); $i < $c; $i++) + { + $this->db->data_cache['db_names'][] = current($query[$i]); + } + + return $this->db->data_cache['db_names']; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular database exists + * + * @param string $database_name + * @return bool + */ + public function database_exists($database_name) + { + return in_array($database_name, $this->list_databases()); + } + + // -------------------------------------------------------------------- + + /** + * Optimize Table + * + * @param string $table_name + * @return mixed + */ + public function optimize_table($table_name) + { + if ($this->_optimize_table === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + $query = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name))); + if ($query !== FALSE) + { + $query = $query->result_array(); + return current($query); + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Optimize Database + * + * @return mixed + */ + public function optimize_database() + { + if ($this->_optimize_table === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + $result = array(); + foreach ($this->db->list_tables() as $table_name) + { + $res = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name))); + if (is_bool($res)) + { + return $res; + } + + // Build the result array... + $res = $res->result_array(); + $res = current($res); + $key = str_replace($this->db->database.'.', '', current($res)); + $keys = array_keys($res); + unset($res[$keys[0]]); + + $result[$key] = $res; + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Repair Table + * + * @param string $table_name + * @return mixed + */ + public function repair_table($table_name) + { + if ($this->_repair_table === FALSE) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; + } + + $query = $this->db->query(sprintf($this->_repair_table, $this->db->escape_identifiers($table_name))); + if (is_bool($query)) + { + return $query; + } + + $query = $query->result_array(); + return current($query); + } + + // -------------------------------------------------------------------- + + /** + * Generate CSV from a query result object + * + * @param object $query Query result object + * @param string $delim Delimiter (default: ,) + * @param string $newline Newline character (default: \n) + * @param string $enclosure Enclosure (default: ") + * @return string + */ + public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"') + { + if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) + { + show_error('You must submit a valid result object'); + } + + $out = ''; + // First generate the headings from the table column names + foreach ($query->list_fields() as $name) + { + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; + } + + $out = substr($out, 0, -strlen($delim)).$newline; + + // Next blast through the result array and build out the rows + while ($row = $query->unbuffered_row('array')) + { + $line = array(); + foreach ($row as $item) + { + $line[] = $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure; + } + $out .= implode($delim, $line).$newline; + } + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Generate XML data from a query result object + * + * @param object $query Query result object + * @param array $params Any preferences + * @return string + */ + public function xml_from_result($query, $params = array()) + { + if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) + { + show_error('You must submit a valid result object'); + } + + // Set our default values + foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) + { + if ( ! isset($params[$key])) + { + $params[$key] = $val; + } + } + + // Create variables for convenience + extract($params); + + // Load the xml helper + get_instance()->load->helper('xml'); + + // Generate the result + $xml = '<'.$root.'>'.$newline; + while ($row = $query->unbuffered_row()) + { + $xml .= $tab.'<'.$element.'>'.$newline; + foreach ($row as $key => $val) + { + $xml .= $tab.$tab.'<'.$key.'>'.xml_convert($val).''.$newline; + } + $xml .= $tab.''.$newline; + } + + return $xml.''.$newline; + } + + // -------------------------------------------------------------------- + + /** + * Database Backup + * + * @param array $params + * @return string + */ + public function backup($params = array()) + { + // If the parameters have not been submitted as an + // array then we know that it is simply the table + // name, which is a valid short cut. + if (is_string($params)) + { + $params = array('tables' => $params); + } + + // Set up our default preferences + $prefs = array( + 'tables' => array(), + 'ignore' => array(), + 'filename' => '', + 'format' => 'gzip', // gzip, zip, txt + 'add_drop' => TRUE, + 'add_insert' => TRUE, + 'newline' => "\n", + 'foreign_key_checks' => TRUE + ); + + // Did the user submit any preferences? If so set them.... + if (count($params) > 0) + { + foreach ($prefs as $key => $val) + { + if (isset($params[$key])) + { + $prefs[$key] = $params[$key]; + } + } + } + + // Are we backing up a complete database or individual tables? + // If no table names were submitted we'll fetch the entire table list + if (count($prefs['tables']) === 0) + { + $prefs['tables'] = $this->db->list_tables(); + } + + // Validate the format + if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) + { + $prefs['format'] = 'txt'; + } + + // Is the encoder supported? If not, we'll either issue an + // error or use plain text depending on the debug settings + if (($prefs['format'] === 'gzip' && ! function_exists('gzencode')) + OR ($prefs['format'] === 'zip' && ! function_exists('gzcompress'))) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsupported_compression'); + } + + $prefs['format'] = 'txt'; + } + + // Was a Zip file requested? + if ($prefs['format'] === 'zip') + { + // Set the filename if not provided (only needed with Zip files) + if ($prefs['filename'] === '') + { + $prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database) + .date('Y-m-d_H-i', time()).'.sql'; + } + else + { + // If they included the .zip file extension we'll remove it + if (preg_match('|.+?\.zip$|', $prefs['filename'])) + { + $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); + } + + // Tack on the ".sql" file extension if needed + if ( ! preg_match('|.+?\.sql$|', $prefs['filename'])) + { + $prefs['filename'] .= '.sql'; + } + } + + // Load the Zip class and output it + $CI =& get_instance(); + $CI->load->library('zip'); + $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $CI->zip->get_zip(); + } + elseif ($prefs['format'] === 'txt') // Was a text file requested? + { + return $this->_backup($prefs); + } + elseif ($prefs['format'] === 'gzip') // Was a Gzip file requested? + { + return gzencode($this->_backup($prefs)); + } + + return; + } + +} diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php new file mode 100644 index 0000000..b3b436f --- /dev/null +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -0,0 +1,405 @@ +dsn, $matches)) + { + if (stripos($matches[2], 'autocommit=off') !== FALSE) + { + $this->auto_commit = FALSE; + } + } + else + { + // If no port is defined by the user, use the default value + empty($this->port) OR $this->port = 33000; + } + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches)) + { + $func = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url'; + return ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '') + ? $func($this->dsn, $this->username, $this->password) + : $func($this->dsn); + } + + $func = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect'; + return ($this->username !== '') + ? $func($this->hostname, $this->port, $this->database, $this->username, $this->password) + : $func($this->hostname, $this->port, $this->database); + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @return void + */ + public function reconnect() + { + if (cubrid_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + return ( ! $this->conn_id OR ($version = cubrid_get_server_info($this->conn_id)) === FALSE) + ? FALSE + : $this->data_cache['version'] = $version; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + return cubrid_query($sql, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + if (($autocommit = cubrid_get_autocommit($this->conn_id)) === NULL) + { + return FALSE; + } + elseif ($autocommit === TRUE) + { + return cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if ( ! cubrid_commit($this->conn_id)) + { + return FALSE; + } + + if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) + { + return cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if ( ! cubrid_rollback($this->conn_id)) + { + return FALSE; + } + + if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id)) + { + cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return cubrid_real_escape_string($str, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return cubrid_affected_rows(); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return cubrid_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SHOW TABLES'; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + + sscanf($query[$i]->Type, '%[a-z](%d)', + $retval[$i]->type, + $retval[$i]->max_length + ); + + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => cubrid_errno($this->conn_id), 'message' => cubrid_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + cubrid_close($this->conn_id); + } + +} diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php new file mode 100644 index 0000000..69b53dd --- /dev/null +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -0,0 +1,230 @@ + 'INTEGER', + 'SMALLINT' => 'INTEGER', + 'INT' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'BIGINT' => 'NUMERIC', + 'FLOAT' => 'DOUBLE', + 'REAL' => 'DOUBLE' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $sqls[] = $sql.' CHANGE '.$field[$i]['_literal']; + } + else + { + $alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE '; + $sqls[] = $sql.$alter_type.$this->_process_column($field[$i]); + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .$extra_clause; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'LONGTEXT': + $attributes['TYPE'] = 'STRING'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table (ignored) + * @return string + */ + protected function _process_indexes($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; + } + + $this->keys = array(); + + return $sql; + } + +} diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php new file mode 100644 index 0000000..75d7025 --- /dev/null +++ b/system/database/drivers/cubrid/cubrid_result.php @@ -0,0 +1,177 @@ +num_rows) + ? $this->num_rows + : $this->num_rows = cubrid_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return cubrid_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + return cubrid_column_names($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = cubrid_field_name($this->result_id, $i); + $retval[$i]->type = cubrid_field_type($this->result_id, $i); + $retval[$i]->max_length = cubrid_field_len($this->result_id, $i); + $retval[$i]->primary_key = (int) (strpos(cubrid_field_flags($this->result_id, $i), 'primary_key') !== FALSE); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id) OR + (get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id)))) + { + cubrid_close_request($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return cubrid_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return cubrid_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return cubrid_fetch_object($this->result_id, $class_name); + } + +} diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php new file mode 100644 index 0000000..ccf794b --- /dev/null +++ b/system/database/drivers/cubrid/cubrid_utility.php @@ -0,0 +1,79 @@ +db->data_cache['db_names'])) + { + return $this->db->data_cache['db_names']; + } + + return $this->db->data_cache['db_names'] = cubrid_list_dbs($this->db->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * CUBRID Export + * + * @param array Preferences + * @return mixed + */ + protected function _backup($params = array()) + { + // No SQL based support in CUBRID as of version 8.4.0. Database or + // table backup can be performed using CUBRID Manager + // database administration tool. + return $this->db->display_error('db_unsupported_feature'); + } +} diff --git a/bmt-system/application/index.html b/system/database/drivers/cubrid/index.html old mode 100755 new mode 100644 similarity index 81% rename from bmt-system/application/index.html rename to system/database/drivers/cubrid/index.html index c942a79..b702fbc --- a/bmt-system/application/index.html +++ b/system/database/drivers/cubrid/index.html @@ -1,3 +1,4 @@ + 403 Forbidden @@ -7,4 +8,4 @@

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/database/drivers/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php new file mode 100644 index 0000000..27e87d4 --- /dev/null +++ b/system/database/drivers/ibase/ibase_driver.php @@ -0,0 +1,413 @@ +hostname.':'.$this->database, $this->username, $this->password, $this->char_set) + : ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if (($service = ibase_service_attach($this->hostname, $this->username, $this->password))) + { + $this->data_cache['version'] = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); + + // Don't keep the service open + ibase_service_detach($service); + return $this->data_cache['version']; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + return ibase_query(isset($this->_ibase_trans) ? $this->_ibase_trans : $this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + if (($trans_handle = ibase_trans($this->conn_id)) === FALSE) + { + return FALSE; + } + + $this->_ibase_trans = $trans_handle; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if (ibase_commit($this->_ibase_trans)) + { + $this->_ibase_trans = NULL; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if (ibase_rollback($this->_ibase_trans)) + { + $this->_ibase_trans = NULL; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return ibase_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @param string $generator_name + * @param int $inc_by + * @return int + */ + public function insert_id($generator_name, $inc_by = 0) + { + //If a generator hasn't been used before it will return 0 + return ibase_gen_id('"'.$generator_name.'"', $inc_by); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT TRIM("RDB$RELATION_NAME") AS TABLE_NAME FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\''; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql.' AND TRIM("RDB$RELATION_NAME") AS TABLE_NAME LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT TRIM("RDB$FIELD_NAME") AS COLUMN_NAME FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "rfields"."RDB$FIELD_NAME" AS "name", + CASE "fields"."RDB$FIELD_TYPE" + WHEN 7 THEN \'SMALLINT\' + WHEN 8 THEN \'INTEGER\' + WHEN 9 THEN \'QUAD\' + WHEN 10 THEN \'FLOAT\' + WHEN 11 THEN \'DFLOAT\' + WHEN 12 THEN \'DATE\' + WHEN 13 THEN \'TIME\' + WHEN 14 THEN \'CHAR\' + WHEN 16 THEN \'INT64\' + WHEN 27 THEN \'DOUBLE\' + WHEN 35 THEN \'TIMESTAMP\' + WHEN 37 THEN \'VARCHAR\' + WHEN 40 THEN \'CSTRING\' + WHEN 261 THEN \'BLOB\' + ELSE NULL + END AS "type", + "fields"."RDB$FIELD_LENGTH" AS "max_length", + "rfields"."RDB$DEFAULT_VALUE" AS "default" + FROM "RDB$RELATION_FIELDS" "rfields" + JOIN "RDB$FIELDS" "fields" ON "rfields"."RDB$FIELD_SOURCE" = "fields"."RDB$FIELD_NAME" + WHERE "rfields"."RDB$RELATION_NAME" = '.$this->escape($table).' + ORDER BY "rfields"."RDB$FIELD_POSITION"'; + + return (($query = $this->query($sql)) !== FALSE) + ? $query->result_object() + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => ibase_errcode(), 'message' => ibase_errmsg()); + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + // Limit clause depends on if Interbase or Firebird + if (stripos($this->version(), 'firebird') !== FALSE) + { + $select = 'FIRST '.$this->qb_limit + .($this->qb_offset ? ' SKIP '.$this->qb_offset : ''); + } + else + { + $select = 'ROWS ' + .($this->qb_offset ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit); + } + + return preg_replace('`SELECT`i', 'SELECT '.$select, $sql, 1); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + ibase_close($this->conn_id); + } + +} diff --git a/system/database/drivers/ibase/ibase_forge.php b/system/database/drivers/ibase/ibase_forge.php new file mode 100644 index 0000000..29a3acf --- /dev/null +++ b/system/database/drivers/ibase/ibase_forge.php @@ -0,0 +1,251 @@ + 'INTEGER', + 'INTEGER' => 'INT64', + 'FLOAT' => 'DOUBLE PRECISION' + ); + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name + * @return bool + */ + public function create_database($db_name) + { + // Firebird databases are flat files, so a path is required + + // Hostname is needed for remote access + empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name; + + return parent::create_database('"'.$db_name.'"'); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name (ignored) + * @return bool + */ + public function drop_database($db_name) + { + if ( ! ibase_drop_db($this->conn_id)) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + elseif ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + return FALSE; + } + + if (isset($field[$i]['type'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identififers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; + } + + if ( ! empty($field[$i]['default'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET DEFAULT '.$field[$i]['default']; + } + + if (isset($field[$i]['null'])) + { + $sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = ' + .($field[$i]['null'] === TRUE ? 'NULL' : '1') + .' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name']) + .' AND "RDB$RELATION_NAME" = '.$this->db->escape($table); + } + + if ( ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'].$field['length'] + .$field['null'] + .$field['unique'] + .$field['default']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INT': + $attributes['TYPE'] = 'INTEGER'; + return; + case 'BIGINT': + $attributes['TYPE'] = 'INT64'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported + } + +} diff --git a/system/database/drivers/ibase/ibase_result.php b/system/database/drivers/ibase/ibase_result.php new file mode 100644 index 0000000..8653097 --- /dev/null +++ b/system/database/drivers/ibase/ibase_result.php @@ -0,0 +1,161 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++) + { + $info = ibase_field_info($this->result_id, $i); + $field_names[] = $info['name']; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $info = ibase_field_info($this->result_id, $i); + + $retval[$i] = new stdClass(); + $retval[$i]->name = $info['name']; + $retval[$i]->type = $info['type']; + $retval[$i]->max_length = $info['length']; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + ibase_free_result($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + $row = ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS); + + if ($class_name === 'stdClass' OR ! $row) + { + return $row; + } + + $class_name = new $class_name(); + foreach ($row as $key => $value) + { + $class_name->$key = $value; + } + + return $class_name; + } + +} diff --git a/system/database/drivers/ibase/ibase_utility.php b/system/database/drivers/ibase/ibase_utility.php new file mode 100644 index 0000000..a808749 --- /dev/null +++ b/system/database/drivers/ibase/ibase_utility.php @@ -0,0 +1,69 @@ +db->hostname, $this->db->username, $this->db->password)) + { + $res = ibase_backup($service, $this->db->database, $filename.'.fbk'); + + // Close the service connection + ibase_service_detach($service); + return $res; + } + + return FALSE; + } + +} diff --git a/bmt-system/application/language/english/index.html b/system/database/drivers/ibase/index.html old mode 100755 new mode 100644 similarity index 81% rename from bmt-system/application/language/english/index.html rename to system/database/drivers/ibase/index.html index c942a79..b702fbc --- a/bmt-system/application/language/english/index.html +++ b/system/database/drivers/ibase/index.html @@ -1,3 +1,4 @@ + 403 Forbidden @@ -7,4 +8,4 @@

    Directory access is forbidden.

    - \ No newline at end of file + diff --git a/system/database/drivers/index.html b/system/database/drivers/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/mssql/index.html b/system/database/drivers/mssql/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/mssql/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php new file mode 100644 index 0000000..e197cfb --- /dev/null +++ b/system/database/drivers/mssql/mssql_driver.php @@ -0,0 +1,518 @@ +port)) + { + $this->hostname .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port; + } + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + $this->conn_id = ($persistent) + ? mssql_pconnect($this->hostname, $this->username, $this->password) + : mssql_connect($this->hostname, $this->username, $this->password); + + if ( ! $this->conn_id) + { + return FALSE; + } + + // ---------------------------------------------------------------- + + // Select the DB... assuming a database name is specified in the config file + if ($this->database !== '' && ! $this->db_select()) + { + log_message('error', 'Unable to select database: '.$this->database); + + return ($this->db_debug === TRUE) + ? $this->display_error('db_unable_to_select', $this->database) + : FALSE; + } + + // Determine how identifiers are escaped + $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi'); + $query = $query->row_array(); + $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi']; + $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']'); + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + // Note: Escaping is required in the event that the DB name + // contains reserved characters. + if (mssql_select_db('['.$database.']', $this->conn_id)) + { + $this->database = $database; + $this->data_cache = array(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return mixed resource if rows are returned, bool otherwise + */ + protected function _execute($sql) + { + return mssql_query($sql, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return $this->simple_query('BEGIN TRAN'); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return $this->simple_query('COMMIT TRAN'); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return $this->simple_query('ROLLBACK TRAN'); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * Returns the last id created in the Identity column. + * + * @return string + */ + public function insert_id() + { + $query = version_compare($this->version(), '8', '>=') + ? 'SELECT SCOPE_IDENTITY() AS last_id' + : 'SELECT @@IDENTITY AS last_id'; + + $query = $this->query($query); + $query = $query->row(); + return $query->last_id; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string $charset + * @return bool + */ + protected function _db_set_charset($charset) + { + return (ini_set('mssql.charset', $charset) !== FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @return string + */ + protected function _version() + { + return "SELECT SERVERPROPERTY('ProductVersion') AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT '.$this->escape_identifiers('name') + .' FROM '.$this->escape_identifiers('sysobjects') + .' WHERE '.$this->escape_identifiers('type')." = 'U'"; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql.' ORDER BY '.$this->escape_identifiers('name'); + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT COLUMN_NAME + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + $retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION; + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + // We need this because the error info is discarded by the + // server the first time you request it, and query() already + // calls error() once for logging purposes when a query fails. + static $error = array('code' => 0, 'message' => NULL); + + $message = mssql_get_last_message(); + if ( ! empty($message)) + { + $error['code'] = $this->query('SELECT @@ERROR AS code')->row()->code; + $error['message'] = $message; + } + + return $error; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE TABLE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + $limit = $this->qb_offset + $this->qb_limit; + + // As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported, + // however an ORDER BY clause is required for it to work + if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby)) + { + $orderby = $this->_compile_order_by(); + + // We have to strip the ORDER BY clause + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); + + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + ."\n\n) ".$this->escape_identifiers('CI_subquery') + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; + } + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + // Multiple-value inserts are only supported as of SQL Server 2008 + if (version_compare($this->version(), '10', '>=')) + { + return parent::_insert_batch($table, $keys, $values); + } + + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + mssql_close($this->conn_id); + } + +} diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php new file mode 100644 index 0000000..07b93c2 --- /dev/null +++ b/system/database/drivers/mssql/mssql_forge.php @@ -0,0 +1,151 @@ + 'SMALLINT', + 'SMALLINT' => 'INT', + 'INT' => 'BIGINT', + 'REAL' => 'FLOAT' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN '; + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + $sqls[] = $sql.$this->_process_column($field[$i]); + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE) + { + unset($attributes['CONSTRAINT']); + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INTEGER': + $attributes['TYPE'] = 'INT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' IDENTITY(1,1)'; + } + } + +} diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php new file mode 100644 index 0000000..5d7d3be --- /dev/null +++ b/system/database/drivers/mssql/mssql_result.php @@ -0,0 +1,198 @@ +num_rows) + ? $this->num_rows + : $this->num_rows = mssql_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return mssql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + mssql_field_seek($this->result_id, 0); + while ($field = mssql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field = mssql_fetch_field($this->result_id, $i); + + $retval[$i] = new stdClass(); + $retval[$i]->name = $field->name; + $retval[$i]->type = $field->type; + $retval[$i]->max_length = $field->max_length; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + mssql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return mssql_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return mssql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + $row = mssql_fetch_object($this->result_id); + + if ($class_name === 'stdClass' OR ! $row) + { + return $row; + } + + $class_name = new $class_name(); + foreach ($row as $key => $value) + { + $class_name->$key = $value; + } + + return $class_name; + } + +} diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php new file mode 100644 index 0000000..5c9941a --- /dev/null +++ b/system/database/drivers/mssql/mssql_utility.php @@ -0,0 +1,77 @@ +db->display_error('db_unsupported_feature'); + } + +} diff --git a/system/database/drivers/mysql/index.html b/system/database/drivers/mysql/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/mysql/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php new file mode 100644 index 0000000..440715a --- /dev/null +++ b/system/database/drivers/mysql/mysql_driver.php @@ -0,0 +1,494 @@ +port)) + { + $this->hostname .= ':'.$this->port; + } + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + $client_flags = ($this->compress === FALSE) ? 0 : MYSQL_CLIENT_COMPRESS; + + if ($this->encrypt === TRUE) + { + $client_flags = $client_flags | MYSQL_CLIENT_SSL; + } + + // Error suppression is necessary mostly due to PHP 5.5+ issuing E_DEPRECATED messages + $this->conn_id = ($persistent === TRUE) + ? mysql_pconnect($this->hostname, $this->username, $this->password, $client_flags) + : mysql_connect($this->hostname, $this->username, $this->password, TRUE, $client_flags); + + // ---------------------------------------------------------------- + + // Select the DB... assuming a database name is specified in the config file + if ($this->database !== '' && ! $this->db_select()) + { + log_message('error', 'Unable to select database: '.$this->database); + + return ($this->db_debug === TRUE) + ? $this->display_error('db_unable_to_select', $this->database) + : FALSE; + } + + if (isset($this->stricton) && is_resource($this->conn_id)) + { + if ($this->stricton) + { + $this->simple_query('SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'); + } + else + { + $this->simple_query( + 'SET SESSION sql_mode = + REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( + @@sql_mode, + "STRICT_ALL_TABLES,", ""), + ",STRICT_ALL_TABLES", ""), + "STRICT_ALL_TABLES", ""), + "STRICT_TRANS_TABLES,", ""), + ",STRICT_TRANS_TABLES", ""), + "STRICT_TRANS_TABLES", "")' + ); + } + } + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @return void + */ + public function reconnect() + { + if (mysql_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + if (mysql_select_db($database, $this->conn_id)) + { + $this->database = $database; + $this->data_cache = array(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string $charset + * @return bool + */ + protected function _db_set_charset($charset) + { + return mysql_set_charset($charset, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if ( ! $this->conn_id OR ($version = mysql_get_server_info($this->conn_id)) === FALSE) + { + return FALSE; + } + + return $this->data_cache['version'] = $version; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return mixed + */ + protected function _execute($sql) + { + return mysql_query($this->_prep_query($sql), $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @param string $sql an SQL query + * @return string + */ + protected function _prep_query($sql) + { + // mysql_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack + // modifies the query so that it a proper number of affected rows is returned. + if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + return trim($sql).' WHERE 1=1'; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + $this->simple_query('SET AUTOCOMMIT=0'); + return $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if ($this->simple_query('COMMIT')) + { + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if ($this->simple_query('ROLLBACK')) + { + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return mysql_real_escape_string($str, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return mysql_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return mysql_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + + sscanf($query[$i]->Type, '%[a-z](%d)', + $retval[$i]->type, + $retval[$i]->max_length + ); + + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => mysql_errno($this->conn_id), 'message' => mysql_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + // Error suppression to avoid annoying E_WARNINGs in cases + // where the connection has already been closed for some reason. + @mysql_close($this->conn_id); + } + +} diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php new file mode 100644 index 0000000..b69aa36 --- /dev/null +++ b/system/database/drivers/mysql/mysql_forge.php @@ -0,0 +1,243 @@ +db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET')) + { + $sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set; + } + + if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE')) + { + $sql .= ' COLLATE = '.$this->db->dbcollat; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP') + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $field[$i] = ($alter_type === 'ADD') + ? "\n\tADD ".$field[$i]['_literal'] + : "\n\tMODIFY ".$field[$i]['_literal']; + } + else + { + if ($alter_type === 'ADD') + { + $field[$i]['_literal'] = "\n\tADD "; + } + else + { + $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; + } + + $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]); + } + } + + return array($sql.implode(',', $field)); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .(empty($field['comment']) ? '' : ' COMMENT '.$field['comment']) + .$extra_clause; + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table (ignored) + * @return string + */ + protected function _process_indexes($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; + } + + $this->keys = array(); + + return $sql; + } + +} diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php new file mode 100644 index 0000000..842d7d3 --- /dev/null +++ b/system/database/drivers/mysql/mysql_result.php @@ -0,0 +1,199 @@ +num_rows = mysql_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + return $this->num_rows; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return mysql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + mysql_field_seek($this->result_id, 0); + while ($field = mysql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = mysql_field_name($this->result_id, $i); + $retval[$i]->type = mysql_field_type($this->result_id, $i); + $retval[$i]->max_length = mysql_field_len($this->result_id, $i); + $retval[$i]->primary_key = (int) (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') !== FALSE); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + mysql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return $this->num_rows + ? mysql_data_seek($this->result_id, $n) + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return mysql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return mysql_fetch_object($this->result_id, $class_name); + } + +} diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php new file mode 100644 index 0000000..a548929 --- /dev/null +++ b/system/database/drivers/mysql/mysql_utility.php @@ -0,0 +1,211 @@ +db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table)); + + // No result means the table name was invalid + if ($query === FALSE) + { + continue; + } + + // Write out the table schema + $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; + + if ($add_drop === TRUE) + { + $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline; + } + + $i = 0; + $result = $query->result_array(); + foreach ($result[0] as $val) + { + if ($i++ % 2) + { + $output .= $val.';'.$newline.$newline; + } + } + + // If inserts are not needed we're done... + if ($add_insert === FALSE) + { + continue; + } + + // Grab all the data from the current table + $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table)); + + if ($query->num_rows() === 0) + { + continue; + } + + // Fetch the field names and determine if the field is an + // integer type. We use this info to decide whether to + // surround the data with quotes or not + + $i = 0; + $field_str = ''; + $is_int = array(); + while ($field = mysql_fetch_field($query->result_id)) + { + // Most versions of MySQL store timestamp as a string + $is_int[$i] = in_array(strtolower(mysql_field_type($query->result_id, $i)), + array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'), + TRUE); + + // Create a string of field names + $field_str .= $this->db->escape_identifiers($field->name).', '; + $i++; + } + + // Trim off the end comma + $field_str = preg_replace('/, $/' , '', $field_str); + + // Build the insert string + foreach ($query->result_array() as $row) + { + $val_str = ''; + + $i = 0; + foreach ($row as $v) + { + // Is the value NULL? + if ($v === NULL) + { + $val_str .= 'NULL'; + } + else + { + // Escape the data if it's not an integer + $val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v; + } + + // Append a comma + $val_str .= ', '; + $i++; + } + + // Remove the comma at the end of the string + $val_str = preg_replace('/, $/' , '', $val_str); + + // Build the INSERT string + $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline; + } + + $output .= $newline.$newline; + } + + // Do we need to include a statement to re-enable foreign key checks? + if ($foreign_key_checks === FALSE) + { + $output .= 'SET foreign_key_checks = 1;'.$newline; + } + + return $output; + } + +} diff --git a/system/database/drivers/mysqli/index.html b/system/database/drivers/mysqli/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/mysqli/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php new file mode 100644 index 0000000..0ca0f48 --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -0,0 +1,546 @@ +hostname[0] === '/') + { + $hostname = NULL; + $port = NULL; + $socket = $this->hostname; + } + else + { + $hostname = ($persistent === TRUE) + ? 'p:'.$this->hostname : $this->hostname; + $port = empty($this->port) ? NULL : $this->port; + $socket = NULL; + } + + $client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0; + $this->_mysqli = mysqli_init(); + + $this->_mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10); + + if (isset($this->stricton)) + { + if ($this->stricton) + { + $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'); + } + else + { + $this->_mysqli->options(MYSQLI_INIT_COMMAND, + 'SET SESSION sql_mode = + REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( + @@sql_mode, + "STRICT_ALL_TABLES,", ""), + ",STRICT_ALL_TABLES", ""), + "STRICT_ALL_TABLES", ""), + "STRICT_TRANS_TABLES,", ""), + ",STRICT_TRANS_TABLES", ""), + "STRICT_TRANS_TABLES", "")' + ); + } + } + + if (is_array($this->encrypt)) + { + $ssl = array(); + empty($this->encrypt['ssl_key']) OR $ssl['key'] = $this->encrypt['ssl_key']; + empty($this->encrypt['ssl_cert']) OR $ssl['cert'] = $this->encrypt['ssl_cert']; + empty($this->encrypt['ssl_ca']) OR $ssl['ca'] = $this->encrypt['ssl_ca']; + empty($this->encrypt['ssl_capath']) OR $ssl['capath'] = $this->encrypt['ssl_capath']; + empty($this->encrypt['ssl_cipher']) OR $ssl['cipher'] = $this->encrypt['ssl_cipher']; + + if (isset($this->encrypt['ssl_verify'])) + { + $client_flags |= MYSQLI_CLIENT_SSL; + + if ($this->encrypt['ssl_verify']) + { + defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') && $this->_mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE); + } + // Apparently (when it exists), setting MYSQLI_OPT_SSL_VERIFY_SERVER_CERT + // to FALSE didn't do anything, so PHP 5.6.16 introduced yet another + // constant ... + // + // https://secure.php.net/ChangeLog-5.php#5.6.16 + // https://bugs.php.net/bug.php?id=68344 + elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT')) + { + $client_flags |= MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT; + } + } + + if ( ! empty($ssl)) + { + $client_flags |= MYSQLI_CLIENT_SSL; + $this->_mysqli->ssl_set( + isset($ssl['key']) ? $ssl['key'] : NULL, + isset($ssl['cert']) ? $ssl['cert'] : NULL, + isset($ssl['ca']) ? $ssl['ca'] : NULL, + isset($ssl['capath']) ? $ssl['capath'] : NULL, + isset($ssl['cipher']) ? $ssl['cipher'] : NULL + ); + } + } + + if ($this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags)) + { + // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails + if ( + ($client_flags & MYSQLI_CLIENT_SSL) + && version_compare($this->_mysqli->client_info, '5.7.3', '<=') + && empty($this->_mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value) + ) + { + $this->_mysqli->close(); + $message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!'; + log_message('error', $message); + return ($this->db_debug) ? $this->display_error($message, '', TRUE) : FALSE; + } + + return $this->_mysqli; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @return void + */ + public function reconnect() + { + if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + if ($this->conn_id->select_db($database)) + { + $this->database = $database; + $this->data_cache = array(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string $charset + * @return bool + */ + protected function _db_set_charset($charset) + { + return $this->conn_id->set_charset($charset); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + return $this->data_cache['version'] = $this->conn_id->server_info; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return mixed + */ + protected function _execute($sql) + { + return $this->conn_id->query($this->_prep_query($sql)); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @param string $sql an SQL query + * @return string + */ + protected function _prep_query($sql) + { + // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack + // modifies the query so that it a proper number of affected rows is returned. + if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + return trim($sql).' WHERE 1=1'; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + $this->conn_id->autocommit(FALSE); + return is_php('5.5') + ? $this->conn_id->begin_transaction() + : $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if ($this->conn_id->commit()) + { + $this->conn_id->autocommit(TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if ($this->conn_id->rollback()) + { + $this->conn_id->autocommit(TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return $this->conn_id->real_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return $this->conn_id->affected_rows; + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return $this->conn_id->insert_id; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + + sscanf($query[$i]->Type, '%[a-z](%d)', + $retval[$i]->type, + $retval[$i]->max_length + ); + + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + if ( ! empty($this->_mysqli->connect_errno)) + { + return array( + 'code' => $this->_mysqli->connect_errno, + 'message' => $this->_mysqli->connect_error + ); + } + + return array('code' => $this->conn_id->errno, 'message' => $this->conn_id->error); + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + $this->conn_id->close(); + } + +} diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php new file mode 100644 index 0000000..92b1e94 --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -0,0 +1,244 @@ +db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET')) + { + $sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set; + } + + if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE')) + { + $sql .= ' COLLATE = '.$this->db->dbcollat; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP') + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $field[$i] = ($alter_type === 'ADD') + ? "\n\tADD ".$field[$i]['_literal'] + : "\n\tMODIFY ".$field[$i]['_literal']; + } + else + { + if ($alter_type === 'ADD') + { + $field[$i]['_literal'] = "\n\tADD "; + } + else + { + $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; + } + + $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]); + } + } + + return array($sql.implode(',', $field)); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .(empty($field['comment']) ? '' : ' COMMENT '.$field['comment']) + .$extra_clause; + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table (ignored) + * @return string + */ + protected function _process_indexes($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; + } + + $this->keys = array(); + + return $sql; + } + +} diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php new file mode 100644 index 0000000..0856eca --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -0,0 +1,232 @@ +num_rows) + ? $this->num_rows + : $this->num_rows = $this->result_id->num_rows; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return $this->result_id->field_count; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + $this->result_id->field_seek(0); + while ($field = $this->result_id->fetch_field()) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + $field_data = $this->result_id->fetch_fields(); + for ($i = 0, $c = count($field_data); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $field_data[$i]->name; + $retval[$i]->type = static::_get_field_type($field_data[$i]->type); + $retval[$i]->max_length = $field_data[$i]->max_length; + $retval[$i]->primary_key = (int) ($field_data[$i]->flags & MYSQLI_PRI_KEY_FLAG); + $retval[$i]->default = $field_data[$i]->def; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Get field type + * + * Extracts field type info from the bitflags returned by + * mysqli_result::fetch_fields() + * + * @used-by CI_DB_mysqli_result::field_data() + * @param int $type + * @return string + */ + private static function _get_field_type($type) + { + static $map; + isset($map) OR $map = array( + MYSQLI_TYPE_DECIMAL => 'decimal', + MYSQLI_TYPE_BIT => 'bit', + MYSQLI_TYPE_TINY => 'tinyint', + MYSQLI_TYPE_SHORT => 'smallint', + MYSQLI_TYPE_INT24 => 'mediumint', + MYSQLI_TYPE_LONG => 'int', + MYSQLI_TYPE_LONGLONG => 'bigint', + MYSQLI_TYPE_FLOAT => 'float', + MYSQLI_TYPE_DOUBLE => 'double', + MYSQLI_TYPE_TIMESTAMP => 'timestamp', + MYSQLI_TYPE_DATE => 'date', + MYSQLI_TYPE_TIME => 'time', + MYSQLI_TYPE_DATETIME => 'datetime', + MYSQLI_TYPE_YEAR => 'year', + MYSQLI_TYPE_NEWDATE => 'date', + MYSQLI_TYPE_INTERVAL => 'interval', + MYSQLI_TYPE_ENUM => 'enum', + MYSQLI_TYPE_SET => 'set', + MYSQLI_TYPE_TINY_BLOB => 'tinyblob', + MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob', + MYSQLI_TYPE_BLOB => 'blob', + MYSQLI_TYPE_LONG_BLOB => 'longblob', + MYSQLI_TYPE_STRING => 'char', + MYSQLI_TYPE_VAR_STRING => 'varchar', + MYSQLI_TYPE_GEOMETRY => 'geometry' + ); + + return isset($map[$type]) ? $map[$type] : $type; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_object($this->result_id)) + { + $this->result_id->free(); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return $this->result_id->data_seek($n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return $this->result_id->fetch_assoc(); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return $this->result_id->fetch_object($class_name); + } + +} diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php new file mode 100644 index 0000000..6064246 --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -0,0 +1,211 @@ +db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table)); + + // No result means the table name was invalid + if ($query === FALSE) + { + continue; + } + + // Write out the table schema + $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; + + if ($add_drop === TRUE) + { + $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline; + } + + $i = 0; + $result = $query->result_array(); + foreach ($result[0] as $val) + { + if ($i++ % 2) + { + $output .= $val.';'.$newline.$newline; + } + } + + // If inserts are not needed we're done... + if ($add_insert === FALSE) + { + continue; + } + + // Grab all the data from the current table + $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table)); + + if ($query->num_rows() === 0) + { + continue; + } + + // Fetch the field names and determine if the field is an + // integer type. We use this info to decide whether to + // surround the data with quotes or not + + $i = 0; + $field_str = ''; + $is_int = array(); + while ($field = $query->result_id->fetch_field()) + { + // Most versions of MySQL store timestamp as a string + $is_int[$i] = in_array($field->type, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_INT24, MYSQLI_TYPE_LONG), TRUE); + + // Create a string of field names + $field_str .= $this->db->escape_identifiers($field->name).', '; + $i++; + } + + // Trim off the end comma + $field_str = preg_replace('/, $/' , '', $field_str); + + // Build the insert string + foreach ($query->result_array() as $row) + { + $val_str = ''; + + $i = 0; + foreach ($row as $v) + { + // Is the value NULL? + if ($v === NULL) + { + $val_str .= 'NULL'; + } + else + { + // Escape the data if it's not an integer + $val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v; + } + + // Append a comma + $val_str .= ', '; + $i++; + } + + // Remove the comma at the end of the string + $val_str = preg_replace('/, $/' , '', $val_str); + + // Build the INSERT string + $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline; + } + + $output .= $newline.$newline; + } + + // Do we need to include a statement to re-enable foreign key checks? + if ($foreign_key_checks === FALSE) + { + $output .= 'SET foreign_key_checks = 1;'.$newline; + } + + return $output; + } + +} diff --git a/system/database/drivers/oci8/index.html b/system/database/drivers/oci8/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/oci8/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php new file mode 100644 index 0000000..a825c4a --- /dev/null +++ b/system/database/drivers/oci8/oci8_driver.php @@ -0,0 +1,701 @@ + '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS + // Easy Connect string (Oracle 10g+) + 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i', + 'in' => '/^[a-z0-9$_]+$/i' // Instance name (defined in tnsnames.ora) + ); + + /* Space characters don't have any effect when actually + * connecting, but can be a hassle while validating the DSN. + */ + $this->dsn = str_replace(array("\n", "\r", "\t", ' '), '', $this->dsn); + + if ($this->dsn !== '') + { + foreach ($valid_dsns as $regexp) + { + if (preg_match($regexp, $this->dsn)) + { + return; + } + } + } + + // Legacy support for TNS in the hostname configuration field + $this->hostname = str_replace(array("\n", "\r", "\t", ' '), '', $this->hostname); + if (preg_match($valid_dsns['tns'], $this->hostname)) + { + $this->dsn = $this->hostname; + return; + } + elseif ($this->hostname !== '' && strpos($this->hostname, '/') === FALSE && strpos($this->hostname, ':') === FALSE + && (( ! empty($this->port) && ctype_digit($this->port)) OR $this->database !== '')) + { + /* If the hostname field isn't empty, doesn't contain + * ':' and/or '/' and if port and/or database aren't + * empty, then the hostname field is most likely indeed + * just a hostname. Therefore we'll try and build an + * Easy Connect string from these 3 settings, assuming + * that the database field is a service name. + */ + $this->dsn = $this->hostname + .(( ! empty($this->port) && ctype_digit($this->port)) ? ':'.$this->port : '') + .($this->database !== '' ? '/'.ltrim($this->database, '/') : ''); + + if (preg_match($valid_dsns['ec'], $this->dsn)) + { + return; + } + } + + /* At this point, we can only try and validate the hostname and + * database fields separately as DSNs. + */ + if (preg_match($valid_dsns['ec'], $this->hostname) OR preg_match($valid_dsns['in'], $this->hostname)) + { + $this->dsn = $this->hostname; + return; + } + + $this->database = str_replace(array("\n", "\r", "\t", ' '), '', $this->database); + foreach ($valid_dsns as $regexp) + { + if (preg_match($regexp, $this->database)) + { + return; + } + } + + /* Well - OK, an empty string should work as well. + * PHP will try to use environment variables to + * determine which Oracle instance to connect to. + */ + $this->dsn = ''; + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + $func = ($persistent === TRUE) ? 'oci_pconnect' : 'oci_connect'; + return empty($this->char_set) + ? $func($this->username, $this->password, $this->dsn) + : $func($this->username, $this->password, $this->dsn, $this->char_set); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if ( ! $this->conn_id OR ($version_string = oci_server_version($this->conn_id)) === FALSE) + { + return FALSE; + } + elseif (preg_match('#Release\s(\d+(?:\.\d+)+)#', $version_string, $match)) + { + return $this->data_cache['version'] = $match[1]; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + /* Oracle must parse the query before it is run. All of the actions with + * the query are based on the statement id returned by oci_parse(). + */ + if ($this->_reset_stmt_id === TRUE) + { + $this->stmt_id = oci_parse($this->conn_id, $sql); + } + + oci_set_prefetch($this->stmt_id, 1000); + return oci_execute($this->stmt_id, $this->commit_mode); + } + + // -------------------------------------------------------------------- + + /** + * Get cursor. Returns a cursor from the database + * + * @return resource + */ + public function get_cursor() + { + return $this->curs_id = oci_new_cursor($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Stored Procedure. Executes a stored procedure + * + * @param string package name in which the stored procedure is in + * @param string stored procedure name to execute + * @param array parameters + * @return mixed + * + * params array keys + * + * KEY OPTIONAL NOTES + * name no the name of the parameter should be in : format + * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * this should be a reference to a variable + * type yes the type of the parameter + * length yes the max size of the parameter + */ + public function stored_procedure($package, $procedure, array $params) + { + if ($package === '' OR $procedure === '') + { + log_message('error', 'Invalid query: '.$package.'.'.$procedure); + return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE; + } + + // Build the query string + $sql = 'BEGIN '.$package.'.'.$procedure.'('; + + $have_cursor = FALSE; + foreach ($params as $param) + { + $sql .= $param['name'].','; + + if (isset($param['type']) && $param['type'] === OCI_B_CURSOR) + { + $have_cursor = TRUE; + } + } + $sql = trim($sql, ',').'); END;'; + + $this->_reset_stmt_id = FALSE; + $this->stmt_id = oci_parse($this->conn_id, $sql); + $this->_bind_params($params); + $result = $this->query($sql, FALSE, $have_cursor); + $this->_reset_stmt_id = TRUE; + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Bind parameters + * + * @param array $params + * @return void + */ + protected function _bind_params($params) + { + if ( ! is_array($params) OR ! is_resource($this->stmt_id)) + { + return; + } + + foreach ($params as $param) + { + foreach (array('name', 'value', 'type', 'length') as $val) + { + if ( ! isset($param[$val])) + { + $param[$val] = ''; + } + } + + oci_bind_by_name($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); + } + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + $this->commit_mode = OCI_NO_AUTO_COMMIT; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + $this->commit_mode = OCI_COMMIT_ON_SUCCESS; + + return oci_commit($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + $this->commit_mode = OCI_COMMIT_ON_SUCCESS; + return oci_rollback($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return oci_num_rows($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + // not supported in oracle + return $this->display_error('db_unsupported_function'); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"'; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + if (strpos($table, '.') !== FALSE) + { + sscanf($table, '%[^.].%s', $owner, $table); + } + else + { + $owner = $this->username; + } + + return 'SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS + WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).' + AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (strpos($table, '.') !== FALSE) + { + sscanf($table, '%[^.].%s', $owner, $table); + } + else + { + $owner = $this->username; + } + + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHAR_LENGTH, DATA_PRECISION, DATA_LENGTH, DATA_DEFAULT, NULLABLE + FROM ALL_TAB_COLUMNS + WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).' + AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + + $length = ($query[$i]->CHAR_LENGTH > 0) + ? $query[$i]->CHAR_LENGTH : $query[$i]->DATA_PRECISION; + if ($length === NULL) + { + $length = $query[$i]->DATA_LENGTH; + } + $retval[$i]->max_length = $length; + + $default = $query[$i]->DATA_DEFAULT; + if ($default === NULL && $query[$i]->NULLABLE === 'N') + { + $default = ''; + } + $retval[$i]->default = $default; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + // oci_error() returns an array that already contains + // 'code' and 'message' keys, but it can return false + // if there was no error .... + if (is_resource($this->curs_id)) + { + $error = oci_error($this->curs_id); + } + elseif (is_resource($this->stmt_id)) + { + $error = oci_error($this->stmt_id); + } + elseif (is_resource($this->conn_id)) + { + $error = oci_error($this->conn_id); + } + else + { + $error = oci_error(); + } + + return is_array($error) + ? $error + : array('code' => '', 'message' => ''); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _insert_batch($table, $keys, $values) + { + $keys = implode(', ', $keys); + $sql = "INSERT ALL\n"; + + for ($i = 0, $c = count($values); $i < $c; $i++) + { + $sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n"; + } + + return $sql.'SELECT * FROM dual'; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE TABLE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + $this->where('rownum <= ',$this->qb_limit, FALSE); + $this->qb_limit = FALSE; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + if (version_compare($this->version(), '12.1', '>=')) + { + // OFFSET-FETCH can be used only with the ORDER BY clause + empty($this->qb_orderby) && $sql .= ' ORDER BY 1'; + + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; + } + + $this->limit_used = TRUE; + return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')' + .($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1) : ''); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + oci_close($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * We need to reset our $limit_used hack flag, so it doesn't propagate + * to subsequent queries. + * + * @return void + */ + protected function _reset_select() + { + $this->limit_used = FALSE; + parent::_reset_select(); + } +} diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php new file mode 100644 index 0000000..58f3c39 --- /dev/null +++ b/system/database/drivers/oci8/oci8_forge.php @@ -0,0 +1,194 @@ +db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $field[$i] = "\n\t".$field[$i]['_literal']; + } + else + { + $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]); + + if ( ! empty($field[$i]['comment'])) + { + $sqls[] = 'COMMENT ON COLUMN ' + .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name']) + .' IS '.$field[$i]['comment']; + } + + if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + + $field[$i] = "\n\t".$field[$i]['_literal']; + } + } + + $sql .= ' '.$alter_type.' '; + $sql .= (count($field) === 1) + ? $field[0] + : '('.implode(',', $field).')'; + + // RENAME COLUMN must be executed after MODIFY + array_unshift($sqls, $sql); + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported - sequences and triggers must be used instead + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'INT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'BIGINT': + $attributes['TYPE'] = 'NUMBER'; + return; + default: return; + } + } +} diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php new file mode 100644 index 0000000..3da49aa --- /dev/null +++ b/system/database/drivers/oci8/oci8_result.php @@ -0,0 +1,229 @@ +stmt_id = $driver_object->stmt_id; + $this->curs_id = $driver_object->curs_id; + $this->limit_used = $driver_object->limit_used; + $this->commit_mode =& $driver_object->commit_mode; + $driver_object->stmt_id = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + $count = oci_num_fields($this->stmt_id); + + // if we used a limit we subtract it + return ($this->limit_used) ? $count - 1 : $count; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) + { + $field_names[] = oci_field_name($this->stmt_id, $c); + } + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) + { + $F = new stdClass(); + $F->name = oci_field_name($this->stmt_id, $c); + $F->type = oci_field_type($this->stmt_id, $c); + $F->max_length = oci_field_size($this->stmt_id, $c); + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + oci_free_statement($this->result_id); + $this->result_id = FALSE; + } + + if (is_resource($this->stmt_id)) + { + oci_free_statement($this->stmt_id); + } + + if (is_resource($this->curs_id)) + { + oci_cancel($this->curs_id); + $this->curs_id = NULL; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; + return oci_fetch_assoc($id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + $row = ($this->curs_id) + ? oci_fetch_object($this->curs_id) + : oci_fetch_object($this->stmt_id); + + if ($class_name === 'stdClass' OR ! $row) + { + return $row; + } + + $class_name = new $class_name(); + foreach ($row as $key => $value) + { + $class_name->$key = $value; + } + + return $class_name; + } + +} diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php new file mode 100644 index 0000000..3a7261c --- /dev/null +++ b/system/database/drivers/oci8/oci8_utility.php @@ -0,0 +1,68 @@ +db->display_error('db_unsupported_feature'); + } + +} diff --git a/system/database/drivers/odbc/index.html b/system/database/drivers/odbc/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/odbc/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php new file mode 100644 index 0000000..72289bf --- /dev/null +++ b/system/database/drivers/odbc/odbc_driver.php @@ -0,0 +1,425 @@ +dsn)) + { + $this->dsn = $this->hostname; + } + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + return ($persistent === TRUE) + ? odbc_pconnect($this->dsn, $this->username, $this->password) + : odbc_connect($this->dsn, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Compile Bindings + * + * @param string $sql SQL statement + * @param array $binds An array of values to bind + * @return string + */ + public function compile_binds($sql, $binds) + { + if (empty($binds) OR empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE) + { + return $sql; + } + elseif ( ! is_array($binds)) + { + $binds = array($binds); + $bind_count = 1; + } + else + { + // Make sure we're using numeric keys + $binds = array_values($binds); + $bind_count = count($binds); + } + + // We'll need the marker length later + $ml = strlen($this->bind_marker); + + // Make sure not to replace a chunk inside a string that happens to match the bind marker + if ($c = preg_match_all("/'[^']*'|\"[^\"]*\"/i", $sql, $matches)) + { + $c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', + str_replace($matches[0], + str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]), + $sql, $c), + $matches, PREG_OFFSET_CAPTURE); + + // Bind values' count must match the count of markers in the query + if ($bind_count !== $c) + { + return $sql; + } + } + elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count) + { + return $sql; + } + + if ($this->bind_marker !== '?') + { + do + { + $c--; + $sql = substr_replace($sql, '?', $matches[0][$c][1], $ml); + } + while ($c !== 0); + } + + if (FALSE !== ($this->odbc_result = odbc_prepare($this->conn_id, $sql))) + { + $this->binds = array_values($binds); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + if ( ! isset($this->odbc_result)) + { + return odbc_exec($this->conn_id, $sql); + } + elseif ($this->odbc_result === FALSE) + { + return FALSE; + } + + if (TRUE === ($success = odbc_execute($this->odbc_result, $this->binds))) + { + // For queries that return result sets, return the result_id resource on success + $this->is_write_type($sql) OR $success = $this->odbc_result; + } + + $this->odbc_result = NULL; + $this->binds = array(); + + return $success; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return odbc_autocommit($this->conn_id, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if (odbc_commit($this->conn_id)) + { + odbc_autocommit($this->conn_id, TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if (odbc_rollback($this->conn_id)) + { + odbc_autocommit($this->conn_id, TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + $this->display_error('db_unsupported_feature'); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return odbc_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return bool + */ + public function insert_id() + { + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'"; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @param string $table + * @return string + */ + protected function _field_data($table) + { + return 'SELECT TOP 1 FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + odbc_close($this->conn_id); + } +} diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php new file mode 100644 index 0000000..05f9c76 --- /dev/null +++ b/system/database/drivers/odbc/odbc_forge.php @@ -0,0 +1,86 @@ +num_rows)) + { + return $this->num_rows; + } + elseif (($this->num_rows = odbc_num_rows($this->result_id)) !== -1) + { + return $this->num_rows; + } + + // Work-around for ODBC subdrivers that don't support num_rows() + if (count($this->result_array) > 0) + { + return $this->num_rows = count($this->result_array); + } + elseif (count($this->result_object) > 0) + { + return $this->num_rows = count($this->result_object); + } + + return $this->num_rows = count($this->result_array()); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return odbc_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + $num_fields = $this->num_fields(); + + if ($num_fields > 0) + { + for ($i = 1; $i <= $num_fields; $i++) + { + $field_names[] = odbc_field_name($this->result_id, $i); + } + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index); + $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index); + $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index); + $retval[$i]->primary_key = 0; + $retval[$i]->default = ''; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + odbc_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return odbc_fetch_array($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + $row = odbc_fetch_object($this->result_id); + + if ($class_name === 'stdClass' OR ! $row) + { + return $row; + } + + $class_name = new $class_name(); + foreach ($row as $key => $value) + { + $class_name->$key = $value; + } + + return $class_name; + } + +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('odbc_fetch_array')) +{ + /** + * ODBC Fetch array + * + * Emulates the native odbc_fetch_array() function when + * it is not available (odbc_fetch_array() requires unixODBC) + * + * @param resource &$result + * @param int $rownumber + * @return array + */ + function odbc_fetch_array(&$result, $rownumber = 1) + { + $rs = array(); + if ( ! odbc_fetch_into($result, $rs, $rownumber)) + { + return FALSE; + } + + $rs_assoc = array(); + foreach ($rs as $k => $v) + { + $field_name = odbc_field_name($result, $k+1); + $rs_assoc[$field_name] = $v; + } + + return $rs_assoc; + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('odbc_fetch_object')) +{ + /** + * ODBC Fetch object + * + * Emulates the native odbc_fetch_object() function when + * it is not available. + * + * @param resource &$result + * @param int $rownumber + * @return object + */ + function odbc_fetch_object(&$result, $rownumber = 1) + { + $rs = array(); + if ( ! odbc_fetch_into($result, $rs, $rownumber)) + { + return FALSE; + } + + $rs_object = new stdClass(); + foreach ($rs as $k => $v) + { + $field_name = odbc_field_name($result, $k+1); + $rs_object->$field_name = $v; + } + + return $rs_object; + } +} diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php new file mode 100644 index 0000000..7872010 --- /dev/null +++ b/system/database/drivers/odbc/odbc_utility.php @@ -0,0 +1,63 @@ +db->display_error('db_unsupported_feature'); + } + +} diff --git a/system/database/drivers/pdo/index.html b/system/database/drivers/pdo/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/pdo/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php new file mode 100644 index 0000000..c5d120f --- /dev/null +++ b/system/database/drivers/pdo/pdo_driver.php @@ -0,0 +1,329 @@ +dsn, $match) && count($match) === 2) + { + // If there is a minimum valid dsn string pattern found, we're done + // This is for general PDO users, who tend to have a full DSN string. + $this->subdriver = $match[1]; + return; + } + // Legacy support for DSN specified in the hostname field + elseif (preg_match('/([^:]+):/', $this->hostname, $match) && count($match) === 2) + { + $this->dsn = $this->hostname; + $this->hostname = NULL; + $this->subdriver = $match[1]; + return; + } + elseif (in_array($this->subdriver, array('mssql', 'sybase'), TRUE)) + { + $this->subdriver = 'dblib'; + } + elseif ($this->subdriver === '4D') + { + $this->subdriver = '4d'; + } + elseif ( ! in_array($this->subdriver, array('4d', 'cubrid', 'dblib', 'firebird', 'ibm', 'informix', 'mysql', 'oci', 'odbc', 'pgsql', 'sqlite', 'sqlsrv'), TRUE)) + { + log_message('error', 'PDO: Invalid or non-existent subdriver'); + + if ($this->db_debug) + { + show_error('Invalid or non-existent PDO subdriver'); + } + } + + $this->dsn = NULL; + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + if ($persistent === TRUE) + { + $this->options[PDO::ATTR_PERSISTENT] = TRUE; + } + + try + { + return new PDO($this->dsn, $this->username, $this->password, $this->options); + } + catch (PDOException $e) + { + if ($this->db_debug && empty($this->failover)) + { + $this->display_error($e->getMessage(), '', TRUE); + } + + return FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + // Not all subdrivers support the getAttribute() method + try + { + return $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION); + } + catch (PDOException $e) + { + return parent::version(); + } + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql SQL query + * @return mixed + */ + protected function _execute($sql) + { + return $this->conn_id->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return $this->conn_id->beginTransaction(); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return $this->conn_id->commit(); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return $this->conn_id->rollBack(); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + // Escape the string + $str = $this->conn_id->quote($str); + + // If there are duplicated quotes, trim them away + return ($str[0] === "'") + ? substr($str, 1, -1) + : $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return is_object($this->result_id) ? $this->result_id->rowCount() : 0; + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @param string $name + * @return int + */ + public function insert_id($name = NULL) + { + return $this->conn_id->lastInsertId($name); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @param string $table + * @return string + */ + protected function _field_data($table) + { + return 'SELECT TOP 1 * FROM '.$this->protect_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + $error = array('code' => '00000', 'message' => ''); + $pdo_error = $this->conn_id->errorInfo(); + + if (empty($pdo_error[0])) + { + return $error; + } + + $error['code'] = isset($pdo_error[1]) ? $pdo_error[0].'/'.$pdo_error[1] : $pdo_error[0]; + if (isset($pdo_error[2])) + { + $error['message'] = $pdo_error[2]; + } + + return $error; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE TABLE '.$table; + } + +} diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php new file mode 100644 index 0000000..e512d3d --- /dev/null +++ b/system/database/drivers/pdo/pdo_forge.php @@ -0,0 +1,65 @@ +num_rows)) + { + return $this->num_rows; + } + elseif (count($this->result_array) > 0) + { + return $this->num_rows = count($this->result_array); + } + elseif (count($this->result_object) > 0) + { + return $this->num_rows = count($this->result_object); + } + elseif (($num_rows = $this->result_id->rowCount()) > 0) + { + return $this->num_rows = $num_rows; + } + + return $this->num_rows = count($this->result_array()); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return $this->result_id->columnCount(); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return bool + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + // Might trigger an E_WARNING due to not all subdrivers + // supporting getColumnMeta() + $field_names[$i] = @$this->result_id->getColumnMeta($i); + $field_names[$i] = $field_names[$i]['name']; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + try + { + $retval = array(); + + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field = $this->result_id->getColumnMeta($i); + + $retval[$i] = new stdClass(); + $retval[$i]->name = $field['name']; + $retval[$i]->type = isset($field['native_type']) ? $field['native_type'] : null; + $retval[$i]->max_length = ($field['len'] > 0) ? $field['len'] : NULL; + $retval[$i]->primary_key = (int) ( ! empty($field['flags']) && in_array('primary_key', $field['flags'], TRUE)); + } + + return $retval; + } + catch (Exception $e) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsupported_feature'); + } + + return FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_object($this->result_id)) + { + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return $this->result_id->fetch(PDO::FETCH_ASSOC); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return $this->result_id->fetchObject($class_name); + } + +} diff --git a/system/database/drivers/pdo/pdo_utility.php b/system/database/drivers/pdo/pdo_utility.php new file mode 100644 index 0000000..6c40cf3 --- /dev/null +++ b/system/database/drivers/pdo/pdo_utility.php @@ -0,0 +1,63 @@ +db->display_error('db_unsupported_feature'); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/index.html b/system/database/drivers/pdo/subdrivers/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php new file mode 100644 index 0000000..2e39bb2 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php @@ -0,0 +1,200 @@ +dsn)) + { + $this->dsn = '4D:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + empty($this->port) OR $this->dsn .= ';port='.$this->port; + empty($this->database) OR $this->dsn .= ';dbname='.$this->database; + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + } + elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 3) === FALSE) + { + $this->dsn .= ';charset='.$this->char_set; + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT '.$this->escape_identifiers('TABLE_NAME').' FROM '.$this->escape_identifiers('_USER_TABLES'); + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' WHERE '.$this->escape_identifiers('TABLE_NAME')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT '.$this->escape_identifiers('COLUMN_NAME').' FROM '.$this->escape_identifiers('_USER_COLUMNS') + .' WHERE '.$this->escape_identifiers('TABLE_NAME').' = '.$this->escape($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @param string $table + * @return string + */ + protected function _field_data($table) + { + return 'SELECT * FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' LIMIT 1'; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : ''); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php b/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php new file mode 100644 index 0000000..306150b --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_4d_forge.php @@ -0,0 +1,217 @@ + 'INT', + 'SMALLINT' => 'INT', + 'INT' => 'INT64', + 'INT32' => 'INT64' + ); + + /** + * DEFAULT value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_default = FALSE; + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + // No method of modifying columns is supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'].$field['length'] + .$field['null'] + .$field['unique'] + .$field['auto_increment']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INTEGER': + $attributes['TYPE'] = 'INT'; + return; + case 'BIGINT': + $attributes['TYPE'] = 'INT64'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute UNIQUE + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_unique(&$attributes, &$field) + { + if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) + { + $field['unique'] = ' UNIQUE'; + + // UNIQUE must be used with NOT NULL + $field['null'] = ' NOT NULL'; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) + { + if (stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' AUTO_INCREMENT'; + } + elseif (strcasecmp($field['type'], 'UUID') === 0) + { + $field['auto_increment'] = ' AUTO_GENERATE'; + } + } + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php new file mode 100644 index 0000000..9a6b643 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php @@ -0,0 +1,209 @@ +dsn)) + { + $this->dsn = 'cubrid:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + empty($this->port) OR $this->dsn .= ';port='.$this->port; + empty($this->database) OR $this->dsn .= ';dbname='.$this->database; + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SHOW TABLES'; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + + sscanf($query[$i]->Type, '%[a-z](%d)', + $retval[$i]->type, + $retval[$i]->max_length + ); + + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php new file mode 100644 index 0000000..f2ee3f5 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php @@ -0,0 +1,230 @@ + 'INTEGER', + 'SMALLINT' => 'INTEGER', + 'INT' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'BIGINT' => 'NUMERIC', + 'FLOAT' => 'DOUBLE', + 'REAL' => 'DOUBLE' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $sqls[] = $sql.' CHANGE '.$field[$i]['_literal']; + } + else + { + $alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE '; + $sqls[] = $sql.$alter_type.$this->_process_column($field[$i]); + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .$extra_clause; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'LONGTEXT': + $attributes['TYPE'] = 'STRING'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table (ignored) + * @return string + */ + protected function _process_indexes($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; + } + + $this->keys = array(); + + return $sql; + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php new file mode 100644 index 0000000..09dbdf0 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -0,0 +1,353 @@ +dsn)) + { + $this->dsn = $params['subdriver'].':host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + if ( ! empty($this->port)) + { + $this->dsn .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port; + } + + empty($this->database) OR $this->dsn .= ';dbname='.$this->database; + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + empty($this->appname) OR $this->dsn .= ';appname='.$this->appname; + } + else + { + if ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE) + { + $this->dsn .= ';charset='.$this->char_set; + } + + $this->subdriver = 'dblib'; + } + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + if ($persistent === TRUE) + { + log_message('debug', "dblib driver doesn't support persistent connections"); + } + + $this->conn_id = parent::db_connect(FALSE); + + if ( ! is_object($this->conn_id)) + { + return $this->conn_id; + } + + // Determine how identifiers are escaped + $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi'); + $query = $query->row_array(); + $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi']; + $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']'); + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT '.$this->escape_identifiers('name') + .' FROM '.$this->escape_identifiers('sysobjects') + .' WHERE '.$this->escape_identifiers('type')." = 'U'"; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql.' ORDER BY '.$this->escape_identifiers('name'); + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT COLUMN_NAME + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + $retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION; + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + $limit = $this->qb_offset + $this->qb_limit; + + // As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported, + // however an ORDER BY clause is required for it to work + if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby)) + { + $orderby = $this->_compile_order_by(); + + // We have to strip the ORDER BY clause + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); + + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + ."\n\n) ".$this->escape_identifiers('CI_subquery') + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; + } + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + // Multiple-value inserts are only supported as of SQL Server 2008 + if (version_compare($this->version(), '10', '>=')) + { + return parent::_insert_batch($table, $keys, $values); + } + + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + return $this->data_cache['version'] = $this->conn_id->query("SELECT SERVERPROPERTY('ProductVersion') AS ver")->fetchColumn(0); + } +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php new file mode 100644 index 0000000..f38ac99 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php @@ -0,0 +1,149 @@ + 'SMALLINT', + 'SMALLINT' => 'INT', + 'INT' => 'BIGINT', + 'REAL' => 'FLOAT' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN '; + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + $sqls[] = $sql.$this->_process_column($field[$i]); + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE) + { + unset($attributes['CONSTRAINT']); + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INTEGER': + $attributes['TYPE'] = 'INT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' IDENTITY(1,1)'; + } + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php new file mode 100644 index 0000000..2c49f12 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php @@ -0,0 +1,279 @@ +dsn)) + { + $this->dsn = 'firebird:'; + + if ( ! empty($this->database)) + { + $this->dsn .= 'dbname='.$this->database; + } + elseif ( ! empty($this->hostname)) + { + $this->dsn .= 'dbname='.$this->hostname; + } + + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + empty($this->role) OR $this->dsn .= ';role='.$this->role; + } + elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 9) === FALSE) + { + $this->dsn .= ';charset='.$this->char_set; + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "RDB$RELATION_NAME" FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\''; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql.' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT "RDB$FIELD_NAME" FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "rfields"."RDB$FIELD_NAME" AS "name", + CASE "fields"."RDB$FIELD_TYPE" + WHEN 7 THEN \'SMALLINT\' + WHEN 8 THEN \'INTEGER\' + WHEN 9 THEN \'QUAD\' + WHEN 10 THEN \'FLOAT\' + WHEN 11 THEN \'DFLOAT\' + WHEN 12 THEN \'DATE\' + WHEN 13 THEN \'TIME\' + WHEN 14 THEN \'CHAR\' + WHEN 16 THEN \'INT64\' + WHEN 27 THEN \'DOUBLE\' + WHEN 35 THEN \'TIMESTAMP\' + WHEN 37 THEN \'VARCHAR\' + WHEN 40 THEN \'CSTRING\' + WHEN 261 THEN \'BLOB\' + ELSE NULL + END AS "type", + "fields"."RDB$FIELD_LENGTH" AS "max_length", + "rfields"."RDB$DEFAULT_VALUE" AS "default" + FROM "RDB$RELATION_FIELDS" "rfields" + JOIN "RDB$FIELDS" "fields" ON "rfields"."RDB$FIELD_SOURCE" = "fields"."RDB$FIELD_NAME" + WHERE "rfields"."RDB$RELATION_NAME" = '.$this->escape($table).' + ORDER BY "rfields"."RDB$FIELD_POSITION"'; + + return (($query = $this->query($sql)) !== FALSE) + ? $query->result_object() + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + // Limit clause depends on if Interbase or Firebird + if (stripos($this->version(), 'firebird') !== FALSE) + { + $select = 'FIRST '.$this->qb_limit + .($this->qb_offset > 0 ? ' SKIP '.$this->qb_offset : ''); + } + else + { + $select = 'ROWS ' + .($this->qb_offset > 0 ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit); + } + + return preg_replace('`SELECT`i', 'SELECT '.$select, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php new file mode 100644 index 0000000..eceb597 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php @@ -0,0 +1,237 @@ + 'INTEGER', + 'INTEGER' => 'INT64', + 'FLOAT' => 'DOUBLE PRECISION' + ); + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name + * @return string + */ + public function create_database($db_name) + { + // Firebird databases are flat files, so a path is required + + // Hostname is needed for remote access + empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name; + + return parent::create_database('"'.$db_name.'"'); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name (ignored) + * @return bool + */ + public function drop_database($db_name) + { + if ( ! ibase_drop_db($this->conn_id)) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + elseif ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + return FALSE; + } + + if (isset($field[$i]['type'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; + } + + if ( ! empty($field[$i]['default'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET '.$field[$i]['default']; + } + + if (isset($field[$i]['null'])) + { + $sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = ' + .($field[$i]['null'] === TRUE ? 'NULL' : '1') + .' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name']) + .' AND "RDB$RELATION_NAME" = '.$this->db->escape($table); + } + + if ( ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'].$field['length'] + .$field['null'] + .$field['unique'] + .$field['default']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INT': + $attributes['TYPE'] = 'INTEGER'; + return; + case 'BIGINT': + $attributes['TYPE'] = 'INT64'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php new file mode 100644 index 0000000..00654d7 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php @@ -0,0 +1,244 @@ +dsn)) + { + $this->dsn = 'ibm:'; + + // Pre-defined DSN + if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT)) + { + if (isset($this->DSN)) + { + $this->dsn .= 'DSN='.$this->DSN; + } + elseif ( ! empty($this->database)) + { + $this->dsn .= 'DSN='.$this->database; + } + + return; + } + + $this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';'; + + if (isset($this->DATABASE)) + { + $this->dsn .= 'DATABASE='.$this->DATABASE.';'; + } + elseif ( ! empty($this->database)) + { + $this->dsn .= 'DATABASE='.$this->database.';'; + } + + if (isset($this->HOSTNAME)) + { + $this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';'; + } + else + { + $this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';'); + } + + if (isset($this->PORT)) + { + $this->dsn .= 'PORT='.$this->port.';'; + } + elseif ( ! empty($this->port)) + { + $this->dsn .= ';PORT='.$this->port.';'; + } + + $this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;'); + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "tabname" FROM "syscat"."tables" + WHERE "type" = \'T\' AND LOWER("tabschema") = '.$this->escape(strtolower($this->database)); + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' AND "tabname" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return array + */ + protected function _list_columns($table = '') + { + return 'SELECT "colname" FROM "syscat"."columns" + WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).' + AND LOWER("tabname") = '.$this->escape(strtolower($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "colname" AS "name", "typename" AS "type", "default" AS "default", "length" AS "max_length", + CASE "keyseq" WHEN NULL THEN 0 ELSE 1 END AS "primary_key" + FROM "syscat"."columns" + WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).' + AND LOWER("tabname") = '.$this->escape(strtolower($table)).' + ORDER BY "colno"'; + + return (($query = $this->query($sql)) !== FALSE) + ? $query->result_object() + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + $sql .= ' FETCH FIRST '.($this->qb_limit + $this->qb_offset).' ROWS ONLY'; + + return ($this->qb_offset) + ? 'SELECT * FROM ('.$sql.') WHERE rownum > '.$this->qb_offset + : $sql; + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php new file mode 100644 index 0000000..99d75b6 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php @@ -0,0 +1,154 @@ + 'INTEGER', + 'INT' => 'BIGINT', + 'INTEGER' => 'BIGINT' + ); + + /** + * DEFAULT value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_default = FALSE; + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'CHANGE') + { + $alter_type = 'MODIFY'; + } + + return parent::_alter_table($alter_type, $table, $field); + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute UNIQUE + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_unique(&$attributes, &$field) + { + if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) + { + $field['unique'] = ' UNIQUE'; + + // UNIQUE must be used with NOT NULL + $field['null'] = ' NOT NULL'; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php new file mode 100644 index 0000000..114eb74 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php @@ -0,0 +1,309 @@ +dsn)) + { + $this->dsn = 'informix:'; + + // Pre-defined DSN + if (empty($this->hostname) && empty($this->host) && empty($this->port) && empty($this->service)) + { + if (isset($this->DSN)) + { + $this->dsn .= 'DSN='.$this->DSN; + } + elseif ( ! empty($this->database)) + { + $this->dsn .= 'DSN='.$this->database; + } + + return; + } + + if (isset($this->host)) + { + $this->dsn .= 'host='.$this->host; + } + else + { + $this->dsn .= 'host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + } + + if (isset($this->service)) + { + $this->dsn .= '; service='.$this->service; + } + elseif ( ! empty($this->port)) + { + $this->dsn .= '; service='.$this->port; + } + + empty($this->database) OR $this->dsn .= '; database='.$this->database; + empty($this->server) OR $this->dsn .= '; server='.$this->server; + + $this->dsn .= '; protocol='.(isset($this->protocol) ? $this->protocol : 'onsoctcp') + .'; EnableScrollableCursors=1'; + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "tabname" FROM "systables" + WHERE "tabid" > 99 AND "tabtype" = \'T\' AND LOWER("owner") = '.$this->escape(strtolower($this->username)); + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' AND "tabname" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + if (strpos($table, '.') !== FALSE) + { + sscanf($table, '%[^.].%s', $owner, $table); + } + else + { + $owner = $this->username; + } + + return 'SELECT "colname" FROM "systables", "syscolumns" + WHERE "systables"."tabid" = "syscolumns"."tabid" + AND "systables"."tabtype" = \'T\' + AND LOWER("systables"."owner") = '.$this->escape(strtolower($owner)).' + AND LOWER("systables"."tabname") = '.$this->escape(strtolower($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "syscolumns"."colname" AS "name", + CASE "syscolumns"."coltype" + WHEN 0 THEN \'CHAR\' + WHEN 1 THEN \'SMALLINT\' + WHEN 2 THEN \'INTEGER\' + WHEN 3 THEN \'FLOAT\' + WHEN 4 THEN \'SMALLFLOAT\' + WHEN 5 THEN \'DECIMAL\' + WHEN 6 THEN \'SERIAL\' + WHEN 7 THEN \'DATE\' + WHEN 8 THEN \'MONEY\' + WHEN 9 THEN \'NULL\' + WHEN 10 THEN \'DATETIME\' + WHEN 11 THEN \'BYTE\' + WHEN 12 THEN \'TEXT\' + WHEN 13 THEN \'VARCHAR\' + WHEN 14 THEN \'INTERVAL\' + WHEN 15 THEN \'NCHAR\' + WHEN 16 THEN \'NVARCHAR\' + WHEN 17 THEN \'INT8\' + WHEN 18 THEN \'SERIAL8\' + WHEN 19 THEN \'SET\' + WHEN 20 THEN \'MULTISET\' + WHEN 21 THEN \'LIST\' + WHEN 22 THEN \'Unnamed ROW\' + WHEN 40 THEN \'LVARCHAR\' + WHEN 41 THEN \'BLOB/CLOB/BOOLEAN\' + WHEN 4118 THEN \'Named ROW\' + ELSE "syscolumns"."coltype" + END AS "type", + "syscolumns"."collength" as "max_length", + CASE "sysdefaults"."type" + WHEN \'L\' THEN "sysdefaults"."default" + ELSE NULL + END AS "default" + FROM "syscolumns", "systables", "sysdefaults" + WHERE "syscolumns"."tabid" = "systables"."tabid" + AND "systables"."tabid" = "sysdefaults"."tabid" + AND "syscolumns"."colno" = "sysdefaults"."colno" + AND "systables"."tabtype" = \'T\' + AND LOWER("systables"."owner") = '.$this->escape(strtolower($this->username)).' + AND LOWER("systables"."tabname") = '.$this->escape(strtolower($table)).' + ORDER BY "syscolumns"."colno"'; + + return (($query = $this->query($sql)) !== FALSE) + ? $query->result_object() + : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE TABLE ONLY '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql $SQL Query + * @return string + */ + protected function _limit($sql) + { + $select = 'SELECT '.($this->qb_offset ? 'SKIP '.$this->qb_offset : '').'FIRST '.$this->qb_limit.' '; + return preg_replace('/^(SELECT\s)/i', $select, $sql, 1); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php b/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php new file mode 100644 index 0000000..1f4bcd1 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_informix_forge.php @@ -0,0 +1,163 @@ + 'INTEGER', + 'INT' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'REAL' => 'DOUBLE PRECISION', + 'SMALLFLOAT' => 'DOUBLE PRECISION' + ); + + /** + * DEFAULT value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_default = ', '; + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'CHANGE') + { + $alter_type = 'MODIFY'; + } + + return parent::_alter_table($alter_type, $table, $field); + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'BYTE': + case 'TEXT': + case 'BLOB': + case 'CLOB': + $attributes['UNIQUE'] = FALSE; + if (isset($attributes['DEFAULT'])) + { + unset($attributes['DEFAULT']); + } + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute UNIQUE + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_unique(&$attributes, &$field) + { + if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) + { + $field['unique'] = ' UNIQUE CONSTRAINT '.$this->db->escape_identifiers($field['name']); + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php new file mode 100644 index 0000000..73b88bc --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -0,0 +1,379 @@ +dsn)) + { + $this->dsn = 'mysql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + empty($this->port) OR $this->dsn .= ';port='.$this->port; + empty($this->database) OR $this->dsn .= ';dbname='.$this->database; + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + } + elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE) + { + $this->dsn .= ';charset='.$this->char_set; + } + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + if (isset($this->stricton)) + { + if ($this->stricton) + { + $sql = 'CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'; + } + else + { + $sql = 'REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( + @@sql_mode, + "STRICT_ALL_TABLES,", ""), + ",STRICT_ALL_TABLES", ""), + "STRICT_ALL_TABLES", ""), + "STRICT_TRANS_TABLES,", ""), + ",STRICT_TRANS_TABLES", ""), + "STRICT_TRANS_TABLES", "")'; + } + + if ( ! empty($sql)) + { + if (empty($this->options[PDO::MYSQL_ATTR_INIT_COMMAND])) + { + $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode = '.$sql; + } + else + { + $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', @@session.sql_mode = '.$sql; + } + } + } + + if ($this->compress === TRUE) + { + $this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE; + } + + if (is_array($this->encrypt)) + { + $ssl = array(); + empty($this->encrypt['ssl_key']) OR $ssl[PDO::MYSQL_ATTR_SSL_KEY] = $this->encrypt['ssl_key']; + empty($this->encrypt['ssl_cert']) OR $ssl[PDO::MYSQL_ATTR_SSL_CERT] = $this->encrypt['ssl_cert']; + empty($this->encrypt['ssl_ca']) OR $ssl[PDO::MYSQL_ATTR_SSL_CA] = $this->encrypt['ssl_ca']; + empty($this->encrypt['ssl_capath']) OR $ssl[PDO::MYSQL_ATTR_SSL_CAPATH] = $this->encrypt['ssl_capath']; + empty($this->encrypt['ssl_cipher']) OR $ssl[PDO::MYSQL_ATTR_SSL_CIPHER] = $this->encrypt['ssl_cipher']; + + if (defined('PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT') && isset($this->encrypt['ssl_verify'])) + { + $ssl[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = $this->encrypt['ssl_verify']; + } + + // DO NOT use array_merge() here! + // It re-indexes numeric keys and the PDO_MYSQL_ATTR_SSL_* constants are integers. + empty($ssl) OR $this->options += $ssl; + } + + // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails + if ( + ($pdo = parent::db_connect($persistent)) !== FALSE + && ! empty($ssl) + && version_compare($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), '5.7.3', '<=') + && empty($pdo->query("SHOW STATUS LIKE 'ssl_cipher'")->fetchObject()->Value) + ) + { + $message = 'PDO_MYSQL was configured for an SSL connection, but got an unencrypted connection instead!'; + log_message('error', $message); + return ($this->db_debug) ? $this->display_error($message, '', TRUE) : FALSE; + } + + return $pdo; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + if (FALSE !== $this->simple_query('USE '.$this->escape_identifiers($database))) + { + $this->database = $database; + $this->data_cache = array(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + $this->conn_id->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); + return $this->conn_id->beginTransaction(); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + if ($this->conn_id->commit()) + { + $this->conn_id->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + if ($this->conn_id->rollBack()) + { + $this->conn_id->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SHOW TABLES FROM '.$this->_escape_char.$this->database.$this->_escape_char; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + + sscanf($query[$i]->Type, '%[a-z](%d)', + $retval[$i]->type, + $retval[$i]->max_length + ); + + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php new file mode 100644 index 0000000..01595a6 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php @@ -0,0 +1,256 @@ +db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET')) + { + $sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set; + } + + if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE')) + { + $sql .= ' COLLATE = '.$this->db->dbcollat; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP') + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $field[$i] = ($alter_type === 'ADD') + ? "\n\tADD ".$field[$i]['_literal'] + : "\n\tMODIFY ".$field[$i]['_literal']; + } + else + { + if ($alter_type === 'ADD') + { + $field[$i]['_literal'] = "\n\tADD "; + } + else + { + $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; + } + + $field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]); + } + } + + return array($sql.implode(',', $field)); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .(empty($field['comment']) ? '' : ' COMMENT '.$field['comment']) + .$extra_clause; + } + + // -------------------------------------------------------------------- + + /** + * Process indexes + * + * @param string $table (ignored) + * @return string + */ + protected function _process_indexes($table) + { + $sql = ''; + + for ($i = 0, $c = count($this->keys); $i < $c; $i++) + { + if (is_array($this->keys[$i])) + { + for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) + { + if ( ! isset($this->fields[$this->keys[$i][$i2]])) + { + unset($this->keys[$i][$i2]); + continue; + } + } + } + elseif ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; + } + + $this->keys = array(); + + return $sql; + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php new file mode 100644 index 0000000..dba4958 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php @@ -0,0 +1,326 @@ +dsn)) + { + $this->dsn = 'oci:dbname='; + + // Oracle has a slightly different PDO DSN format (Easy Connect), + // which also supports pre-defined DSNs. + if (empty($this->hostname) && empty($this->port)) + { + $this->dsn .= $this->database; + } + else + { + $this->dsn .= '//'.(empty($this->hostname) ? '127.0.0.1' : $this->hostname) + .(empty($this->port) ? '' : ':'.$this->port).'/'; + + empty($this->database) OR $this->dsn .= $this->database; + } + + empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; + } + elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 4) === FALSE) + { + $this->dsn .= ';charset='.$this->char_set; + } + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + $version_string = parent::version(); + if (preg_match('#Release\s(?\d+(?:\.\d+)+)#', $version_string, $match)) + { + return $this->data_cache['version'] = $match[1]; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"'; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + if (strpos($table, '.') !== FALSE) + { + sscanf($table, '%[^.].%s', $owner, $table); + } + else + { + $owner = $this->username; + } + + return 'SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS + WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).' + AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (strpos($table, '.') !== FALSE) + { + sscanf($table, '%[^.].%s', $owner, $table); + } + else + { + $owner = $this->username; + } + + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHAR_LENGTH, DATA_PRECISION, DATA_LENGTH, DATA_DEFAULT, NULLABLE + FROM ALL_TAB_COLUMNS + WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).' + AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + + $length = ($query[$i]->CHAR_LENGTH > 0) + ? $query[$i]->CHAR_LENGTH : $query[$i]->DATA_PRECISION; + if ($length === NULL) + { + $length = $query[$i]->DATA_LENGTH; + } + $retval[$i]->max_length = $length; + + $default = $query[$i]->DATA_DEFAULT; + if ($default === NULL && $query[$i]->NULLABLE === 'N') + { + $default = ''; + } + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _insert_batch($table, $keys, $values) + { + $keys = implode(', ', $keys); + $sql = "INSERT ALL\n"; + + for ($i = 0, $c = count($values); $i < $c; $i++) + { + $sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n"; + } + + return $sql.'SELECT * FROM dual'; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + $this->where('rownum <= ',$this->qb_limit, FALSE); + $this->qb_limit = FALSE; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + if (version_compare($this->version(), '12.1', '>=')) + { + // OFFSET-FETCH can be used only with the ORDER BY clause + empty($this->qb_orderby) && $sql .= ' ORDER BY 1'; + + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; + } + + return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')' + .($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1): ''); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php new file mode 100644 index 0000000..b5d3eb1 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php @@ -0,0 +1,183 @@ +db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + $field[$i] = "\n\t".$field[$i]['_literal']; + } + else + { + $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]); + + if ( ! empty($field[$i]['comment'])) + { + $sqls[] = 'COMMENT ON COLUMN ' + .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name']) + .' IS '.$field[$i]['comment']; + } + + if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + } + } + + $sql .= ' '.$alter_type.' '; + $sql .= (count($field) === 1) + ? $field[0] + : '('.implode(',', $field).')'; + + // RENAME COLUMN must be executed after MODIFY + array_unshift($sqls, $sql); + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + // Not supported - sequences and triggers must be used instead + } + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'INT': + $attributes['TYPE'] = 'NUMBER'; + return; + case 'BIGINT': + $attributes['TYPE'] = 'NUMBER'; + return; + default: return; + } + } +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php new file mode 100644 index 0000000..93a6420 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php @@ -0,0 +1,229 @@ +dsn)) + { + $this->dsn = 'odbc:'; + + // Pre-defined DSN + if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT)) + { + if (isset($this->DSN)) + { + $this->dsn .= 'DSN='.$this->DSN; + } + elseif ( ! empty($this->database)) + { + $this->dsn .= 'DSN='.$this->database; + } + + return; + } + + // If the DSN is not pre-configured - try to build an IBM DB2 connection string + $this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';'; + + if (isset($this->DATABASE)) + { + $this->dsn .= 'DATABASE='.$this->DATABASE.';'; + } + elseif ( ! empty($this->database)) + { + $this->dsn .= 'DATABASE='.$this->database.';'; + } + + if (isset($this->HOSTNAME)) + { + $this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';'; + } + else + { + $this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';'); + } + + if (isset($this->PORT)) + { + $this->dsn .= 'PORT='.$this->port.';'; + } + elseif ( ! empty($this->port)) + { + $this->dsn .= ';PORT='.$this->port.';'; + } + + $this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;'); + } + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + $this->display_error('db_unsupported_feature'); + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'"; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT column_name FROM information_schema.columns WHERE table_name = '.$this->escape($table); + } +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php new file mode 100644 index 0000000..47226d7 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php @@ -0,0 +1,70 @@ +dsn)) + { + $this->dsn = 'pgsql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + empty($this->port) OR $this->dsn .= ';port='.$this->port; + empty($this->database) OR $this->dsn .= ';dbname='.$this->database; + + if ( ! empty($this->username)) + { + $this->dsn .= ';user='.$this->username; + empty($this->password) OR $this->dsn .= ';password='.$this->password; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + $this->conn_id = parent::db_connect($persistent); + + if (is_object($this->conn_id) && ! empty($this->schema)) + { + $this->simple_query('SET search_path TO '.$this->schema.',public'); + } + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @param string $name + * @return int + */ + public function insert_id($name = NULL) + { + if ($name === NULL && version_compare($this->version(), '8.1', '>=')) + { + $query = $this->query('SELECT LASTVAL() AS ins_id'); + $query = $query->row(); + return $query->ins_id; + } + + return $this->conn_id->lastInsertId($name); + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); + } + + // -------------------------------------------------------------------- + + /** + * "Smart" Escape String + * + * Escapes data based on type + * + * @param string $str + * @return mixed + */ + public function escape($str) + { + if (is_bool($str)) + { + return ($str) ? 'TRUE' : 'FALSE'; + } + + return parent::escape($str); + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY + * + * @param string $orderby + * @param string $direction ASC, DESC or RANDOM + * @param bool $escape + * @return object + */ + public function order_by($orderby, $direction = '', $escape = NULL) + { + $direction = strtoupper(trim($direction)); + if ($direction === 'RANDOM') + { + if ( ! is_float($orderby) && ctype_digit((string) $orderby)) + { + $orderby = ($orderby > 1) + ? (float) '0.'.$orderby + : (float) $orderby; + } + + if (is_float($orderby)) + { + $this->simple_query('SET SEED '.$orderby); + } + + $orderby = $this->_random_keyword[0]; + $direction = ''; + $escape = FALSE; + } + + return parent::order_by($orderby, $direction, $escape); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'"; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql.' AND "table_name" LIKE \'' + .$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT "column_name" + FROM "information_schema"."columns" + WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default" + FROM "information_schema"."columns" + WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->column_name; + $retval[$i]->type = $query[$i]->data_type; + $retval[$i]->max_length = ($query[$i]->character_maximum_length > 0) ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision; + $retval[$i]->default = $query[$i]->column_default; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Update_Batch statement + * + * Generates a platform-specific batch update string from the supplied data + * + * @param string $table Table name + * @param array $values Update data + * @param string $index WHERE key + * @return string + */ + protected function _update_batch($table, $values, $index) + { + $ids = array(); + foreach ($values as $key => $val) + { + $ids[] = $val[$index]['value']; + + foreach (array_keys($val) as $field) + { + if ($field !== $index) + { + $final[$val[$field]['field']][] = 'WHEN '.$val[$index]['value'].' THEN '.$val[$field]['value']; + } + } + } + + $cases = ''; + foreach ($final as $k => $v) + { + $cases .= $k.' = (CASE '.$val[$index]['field']."\n" + .implode("\n", $v)."\n" + .'ELSE '.$k.' END), '; + } + + $this->where($val[$index]['field'].' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : ''); + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php new file mode 100644 index 0000000..a4ccff4 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php @@ -0,0 +1,210 @@ + 'INTEGER', + 'SMALLINT' => 'INTEGER', + 'INT' => 'BIGINT', + 'INT4' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'INT8' => 'NUMERIC', + 'BIGINT' => 'NUMERIC', + 'REAL' => 'DOUBLE PRECISION', + 'FLOAT' => 'DOUBLE PRECISION' + ); + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param object &$db Database object + * @return void + */ + public function __construct(&$db) + { + parent::__construct($db); + + if (version_compare($this->db->version(), '9.0', '>')) + { + $this->create_table_if = 'CREATE TABLE IF NOT EXISTS'; + } + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + return FALSE; + } + + if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; + } + + if ( ! empty($field[$i]['default'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET '.$field[$i]['default']; + } + + if (isset($field[$i]['null'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .(trim($field[$i]['null']) === $this->_null ? ' DROP NOT NULL' : ' SET NOT NULL'); + } + + if ( ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + + if ( ! empty($field[$i]['comment'])) + { + $sqls[] = 'COMMENT ON COLUMN ' + .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name']) + .' IS '.$field[$i]['comment']; + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + // Reset field lengths for data types that don't support it + if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE) + { + $attributes['CONSTRAINT'] = NULL; + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) + { + $field['type'] = ($field['type'] === 'NUMERIC') + ? 'BIGSERIAL' + : 'SERIAL'; + } + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php new file mode 100644 index 0000000..f55d9a6 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php @@ -0,0 +1,213 @@ +dsn)) + { + $this->dsn = 'sqlite:'; + + if (empty($this->database) && empty($this->hostname)) + { + $this->database = ':memory:'; + } + + $this->database = empty($this->database) ? $this->hostname : $this->database; + } + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\''; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + return $sql.' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * @param string $table Table name + * @return array + */ + public function list_fields($table) + { + if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $fields = array(); + foreach ($result->result_array() as $row) + { + $fields[] = $row['name']; + } + + return $fields; + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $query = $query->result_array(); + if (empty($query)) + { + return FALSE; + } + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]['name']; + $retval[$i]->type = $query[$i]['type']; + $retval[$i]->max_length = NULL; + $retval[$i]->default = $query[$i]['dflt_value']; + $retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Replace statement + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _replace($table, $keys, $values) + { + return 'INSERT OR '.parent::_replace($table, $keys, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php new file mode 100644 index 0000000..545b2a3 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php @@ -0,0 +1,238 @@ +db->version(), '3.3', '<')) + { + $this->_create_table_if = FALSE; + $this->_drop_table_if = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name (ignored) + * @return bool + */ + public function create_database($db_name) + { + // In SQLite, a database is created when you connect to the database. + // We'll return TRUE so that an error isn't generated + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name (ignored) + * @return bool + */ + public function drop_database($db_name) + { + // In SQLite, a database is dropped when we delete a file + if (file_exists($this->db->database)) + { + // We need to close the pseudo-connection first + $this->db->close(); + if ( ! @unlink($this->db->database)) + { + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + elseif ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP' OR $alter_type === 'CHANGE') + { + // drop_column(): + // BEGIN TRANSACTION; + // CREATE TEMPORARY TABLE t1_backup(a,b); + // INSERT INTO t1_backup SELECT a,b FROM t1; + // DROP TABLE t1; + // CREATE TABLE t1(a,b); + // INSERT INTO t1 SELECT a,b FROM t1_backup; + // DROP TABLE t1_backup; + // COMMIT; + + return FALSE; + } + + return parent::_alter_table($alter_type, $table, $field); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'] + .$field['auto_increment'] + .$field['null'] + .$field['unique'] + .$field['default']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'ENUM': + case 'SET': + $attributes['TYPE'] = 'TEXT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['type'] = 'INTEGER PRIMARY KEY'; + $field['default'] = ''; + $field['null'] = ''; + $field['unique'] = ''; + $field['auto_increment'] = ' AUTOINCREMENT'; + + $this->primary_keys = array(); + } + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php new file mode 100644 index 0000000..84109ae --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -0,0 +1,369 @@ +dsn)) + { + $this->dsn = 'sqlsrv:Server='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname); + + empty($this->port) OR $this->dsn .= ','.$this->port; + empty($this->database) OR $this->dsn .= ';Database='.$this->database; + + // Some custom options + + if (isset($this->QuotedId)) + { + $this->dsn .= ';QuotedId='.$this->QuotedId; + $this->_quoted_identifier = (bool) $this->QuotedId; + } + + if (isset($this->ConnectionPooling)) + { + $this->dsn .= ';ConnectionPooling='.$this->ConnectionPooling; + } + + if ($this->encrypt === TRUE) + { + $this->dsn .= ';Encrypt=1'; + } + + if (isset($this->TraceOn)) + { + $this->dsn .= ';TraceOn='.$this->TraceOn; + } + + if (isset($this->TrustServerCertificate)) + { + $this->dsn .= ';TrustServerCertificate='.$this->TrustServerCertificate; + } + + empty($this->APP) OR $this->dsn .= ';APP='.$this->APP; + empty($this->Failover_Partner) OR $this->dsn .= ';Failover_Partner='.$this->Failover_Partner; + empty($this->LoginTimeout) OR $this->dsn .= ';LoginTimeout='.$this->LoginTimeout; + empty($this->MultipleActiveResultSets) OR $this->dsn .= ';MultipleActiveResultSets='.$this->MultipleActiveResultSets; + empty($this->TraceFile) OR $this->dsn .= ';TraceFile='.$this->TraceFile; + empty($this->WSID) OR $this->dsn .= ';WSID='.$this->WSID; + } + elseif (preg_match('/QuotedId=(0|1)/', $this->dsn, $match)) + { + $this->_quoted_identifier = (bool) $match[1]; + } + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + if ( ! empty($this->char_set) && preg_match('/utf[^8]*8/i', $this->char_set)) + { + $this->options[PDO::SQLSRV_ENCODING_UTF8] = 1; + } + + $this->conn_id = parent::db_connect($persistent); + + if ( ! is_object($this->conn_id) OR is_bool($this->_quoted_identifier)) + { + return $this->conn_id; + } + + // Determine how identifiers are escaped + $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi'); + $query = $query->row_array(); + $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi']; + $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']'); + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT '.$this->escape_identifiers('name') + .' FROM '.$this->escape_identifiers('sysobjects') + .' WHERE '.$this->escape_identifiers('type')." = 'U'"; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql.' ORDER BY '.$this->escape_identifiers('name'); + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT COLUMN_NAME + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + $retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION; + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + // As of SQL Server 2012 (11.0.*) OFFSET is supported + if (version_compare($this->version(), '11', '>=')) + { + // SQL Server OFFSET-FETCH can be used only with the ORDER BY clause + empty($this->qb_orderby) && $sql .= ' ORDER BY 1'; + + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; + } + + $limit = $this->qb_offset + $this->qb_limit; + + // An ORDER BY clause is required for ROW_NUMBER() to work + if ($this->qb_offset && ! empty($this->qb_orderby)) + { + $orderby = $this->_compile_order_by(); + + // We have to strip the ORDER BY clause + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); + + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + ."\n\n) ".$this->escape_identifiers('CI_subquery') + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; + } + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + // Multiple-value inserts are only supported as of SQL Server 2008 + if (version_compare($this->version(), '10', '>=')) + { + return parent::_insert_batch($table, $keys, $values); + } + + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + +} diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php new file mode 100644 index 0000000..b23c6d4 --- /dev/null +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php @@ -0,0 +1,149 @@ + 'SMALLINT', + 'SMALLINT' => 'INT', + 'INT' => 'BIGINT', + 'REAL' => 'FLOAT' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN '; + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + $sqls[] = $sql.$this->_process_column($field[$i]); + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE) + { + unset($attributes['CONSTRAINT']); + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INTEGER': + $attributes['TYPE'] = 'INT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' IDENTITY(1,1)'; + } + } + +} diff --git a/system/database/drivers/postgre/index.html b/system/database/drivers/postgre/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/postgre/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php new file mode 100644 index 0000000..5ce2761 --- /dev/null +++ b/system/database/drivers/postgre/postgre_driver.php @@ -0,0 +1,619 @@ +dsn)) + { + return; + } + + $this->dsn === '' OR $this->dsn = ''; + + if (strpos($this->hostname, '/') !== FALSE) + { + // If UNIX sockets are used, we shouldn't set a port + $this->port = ''; + } + + $this->hostname === '' OR $this->dsn = 'host='.$this->hostname.' '; + + if ( ! empty($this->port) && ctype_digit($this->port)) + { + $this->dsn .= 'port='.$this->port.' '; + } + + if ($this->username !== '') + { + $this->dsn .= 'user='.$this->username.' '; + + /* An empty password is valid! + * + * $db['password'] = NULL must be done in order to ignore it. + */ + $this->password === NULL OR $this->dsn .= "password='".$this->password."' "; + } + + $this->database === '' OR $this->dsn .= 'dbname='.$this->database.' '; + + /* We don't have these options as elements in our standard configuration + * array, but they might be set by parse_url() if the configuration was + * provided via string. Example: + * + * postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1 + */ + foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key) + { + if (isset($this->$key) && is_string($this->$key) && $this->$key !== '') + { + $this->dsn .= $key."='".$this->$key."' "; + } + } + + $this->dsn = rtrim($this->dsn); + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $persistent + * @return resource + */ + public function db_connect($persistent = FALSE) + { + $this->conn_id = ($persistent === TRUE) + ? pg_pconnect($this->dsn) + : pg_connect($this->dsn); + + if ($this->conn_id !== FALSE) + { + if ($persistent === TRUE + && pg_connection_status($this->conn_id) === PGSQL_CONNECTION_BAD + && pg_ping($this->conn_id) === FALSE + ) + { + return FALSE; + } + + empty($this->schema) OR $this->simple_query('SET search_path TO '.$this->schema.',public'); + } + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @return void + */ + public function reconnect() + { + if (pg_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string $charset + * @return bool + */ + protected function _db_set_charset($charset) + { + return (pg_set_client_encoding($this->conn_id, $charset) === 0); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if ( ! $this->conn_id OR ($pg_version = pg_version($this->conn_id)) === FALSE) + { + return FALSE; + } + + /* If PHP was compiled with PostgreSQL lib versions earlier + * than 7.4, pg_version() won't return the server version + * and so we'll have to fall back to running a query in + * order to get it. + */ + return (isset($pg_version['server']) && preg_match('#^(\d+\.\d+)#', $pg_version['server'], $match)) + ? $this->data_cache['version'] = $match[1] + : parent::version(); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + return pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return (bool) pg_query($this->conn_id, 'BEGIN'); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return (bool) pg_query($this->conn_id, 'COMMIT'); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return (bool) pg_query($this->conn_id, 'ROLLBACK'); + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return pg_escape_string($this->conn_id, $str); + } + + // -------------------------------------------------------------------- + + /** + * "Smart" Escape String + * + * Escapes data based on type + * + * @param string $str + * @return mixed + */ + public function escape($str) + { + if (is_php('5.4.4') && (is_string($str) OR (is_object($str) && method_exists($str, '__toString')))) + { + return pg_escape_literal($this->conn_id, $str); + } + elseif (is_bool($str)) + { + return ($str) ? 'TRUE' : 'FALSE'; + } + + return parent::escape($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return string + */ + public function insert_id() + { + $v = $this->version(); + + $table = (func_num_args() > 0) ? func_get_arg(0) : NULL; + $column = (func_num_args() > 1) ? func_get_arg(1) : NULL; + + if ($table === NULL && $v >= '8.1') + { + $sql = 'SELECT LASTVAL() AS ins_id'; + } + elseif ($table !== NULL) + { + if ($column !== NULL && $v >= '8.0') + { + $sql = 'SELECT pg_get_serial_sequence(\''.$table."', '".$column."') AS seq"; + $query = $this->query($sql); + $query = $query->row(); + $seq = $query->seq; + } + else + { + // seq_name passed in table parameter + $seq = $table; + } + + $sql = 'SELECT CURRVAL(\''.$seq."') AS ins_id"; + } + else + { + return pg_last_oid($this->result_id); + } + + $query = $this->query($sql); + $query = $query->row(); + return (int) $query->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'"; + + if ($prefix_limit !== FALSE && $this->dbprefix !== '') + { + return $sql.' AND "table_name" LIKE \'' + .$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT "column_name" + FROM "information_schema"."columns" + WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default" + FROM "information_schema"."columns" + WHERE LOWER("table_name") = '.$this->escape(strtolower($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->column_name; + $retval[$i]->type = $query[$i]->data_type; + $retval[$i]->max_length = ($query[$i]->character_maximum_length > 0) ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision; + $retval[$i]->default = $query[$i]->column_default; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => '', 'message' => pg_last_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY + * + * @param string $orderby + * @param string $direction ASC, DESC or RANDOM + * @param bool $escape + * @return object + */ + public function order_by($orderby, $direction = '', $escape = NULL) + { + $direction = strtoupper(trim($direction)); + if ($direction === 'RANDOM') + { + if ( ! is_float($orderby) && ctype_digit((string) $orderby)) + { + $orderby = ($orderby > 1) + ? (float) '0.'.$orderby + : (float) $orderby; + } + + if (is_float($orderby)) + { + $this->simple_query('SET SEED '.$orderby); + } + + $orderby = $this->_random_keyword[0]; + $direction = ''; + $escape = FALSE; + } + + return parent::order_by($orderby, $direction, $escape); + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Update_Batch statement + * + * Generates a platform-specific batch update string from the supplied data + * + * @param string $table Table name + * @param array $values Update data + * @param string $index WHERE key + * @return string + */ + protected function _update_batch($table, $values, $index) + { + $ids = array(); + foreach ($values as $key => $val) + { + $ids[] = $val[$index]['value']; + + foreach (array_keys($val) as $field) + { + if ($field !== $index) + { + $final[$val[$field]['field']][] = 'WHEN '.$val[$index]['value'].' THEN '.$val[$field]['value']; + } + } + } + + $cases = ''; + foreach ($final as $k => $v) + { + $cases .= $k.' = (CASE '.$val[$index]['field']."\n" + .implode("\n", $v)."\n" + .'ELSE '.$k.' END), '; + } + + $this->where($val[$index]['field'].' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : ''); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + pg_close($this->conn_id); + } + +} diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php new file mode 100644 index 0000000..481e222 --- /dev/null +++ b/system/database/drivers/postgre/postgre_forge.php @@ -0,0 +1,205 @@ + 'INTEGER', + 'SMALLINT' => 'INTEGER', + 'INT' => 'BIGINT', + 'INT4' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'INT8' => 'NUMERIC', + 'BIGINT' => 'NUMERIC', + 'REAL' => 'DOUBLE PRECISION', + 'FLOAT' => 'DOUBLE PRECISION' + ); + + /** + * NULL value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_null = 'NULL'; + + // -------------------------------------------------------------------- + + /** + * Class constructor + * + * @param object &$db Database object + * @return void + */ + public function __construct(&$db) + { + parent::__construct($db); + + if (version_compare($this->db->version(), '9.0', '>')) + { + $this->create_table_if = 'CREATE TABLE IF NOT EXISTS'; + } + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) + { + return FALSE; + } + + if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; + } + + if ( ! empty($field[$i]['default'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET '.$field[$i]['default']; + } + + if (isset($field[$i]['null'])) + { + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .(trim($field[$i]['null']) === $this->_null ? ' DROP NOT NULL' : ' SET NOT NULL'); + } + + if ( ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); + } + + if ( ! empty($field[$i]['comment'])) + { + $sqls[] = 'COMMENT ON COLUMN ' + .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name']) + .' IS '.$field[$i]['comment']; + } + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + // Reset field lengths for data types that don't support it + if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE) + { + $attributes['CONSTRAINT'] = NULL; + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) + { + $field['type'] = ($field['type'] === 'NUMERIC') + ? 'BIGSERIAL' + : 'SERIAL'; + } + } + +} diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php new file mode 100644 index 0000000..b0054dd --- /dev/null +++ b/system/database/drivers/postgre/postgre_result.php @@ -0,0 +1,182 @@ +num_rows) + ? $this->num_rows + : $this->num_rows = pg_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return pg_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field_names[] = pg_field_name($this->result_id, $i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = pg_field_name($this->result_id, $i); + $retval[$i]->type = pg_field_type($this->result_id, $i); + $retval[$i]->max_length = pg_field_size($this->result_id, $i); + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + pg_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return pg_result_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return pg_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return pg_fetch_object($this->result_id, NULL, $class_name); + } + +} diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php new file mode 100644 index 0000000..450aa36 --- /dev/null +++ b/system/database/drivers/postgre/postgre_utility.php @@ -0,0 +1,78 @@ +db->display_error('db_unsupported_feature'); + } +} diff --git a/system/database/drivers/sqlite/index.html b/system/database/drivers/sqlite/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/sqlite/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php new file mode 100644 index 0000000..aec3d74 --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -0,0 +1,330 @@ +database, 0666, $error) + : sqlite_open($this->database, 0666, $error); + + isset($error) && log_message('error', $error); + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + return isset($this->data_cache['version']) + ? $this->data_cache['version'] + : $this->data_cache['version'] = sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + return $this->is_write_type($sql) + ? sqlite_exec($this->conn_id, $sql) + : sqlite_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return $this->simple_query('BEGIN TRANSACTION'); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return $this->simple_query('COMMIT'); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return $this->simple_query('ROLLBACK'); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependant string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return sqlite_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return sqlite_changes($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return sqlite_last_insert_rowid($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT name FROM sqlite_master WHERE type='table'"; + + if ($prefix_limit !== FALSE && $this->dbprefix != '') + { + return $sql." AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return bool + */ + protected function _list_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $query = $query->result_array(); + if (empty($query)) + { + return FALSE; + } + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]['name']; + $retval[$i]->type = $query[$i]['type']; + $retval[$i]->max_length = NULL; + $retval[$i]->default = $query[$i]['dflt_value']; + $retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occured. + * + * @return array + */ + public function error() + { + $error = array('code' => sqlite_last_error($this->conn_id)); + $error['message'] = sqlite_error_string($error['code']); + return $error; + } + + // -------------------------------------------------------------------- + + /** + * Replace statement + * + * Generates a platform-specific replace string from the supplied data + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _replace($table, $keys, $values) + { + return 'INSERT OR '.parent::_replace($table, $keys, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this function maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + sqlite_close($this->conn_id); + } + +} diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php new file mode 100644 index 0000000..6aa9c61 --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -0,0 +1,205 @@ +db->database) OR ! @unlink($this->db->database)) + { + return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + elseif ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @todo implement drop_column(), modify_column() + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP' OR $alter_type === 'CHANGE') + { + // drop_column(): + // BEGIN TRANSACTION; + // CREATE TEMPORARY TABLE t1_backup(a,b); + // INSERT INTO t1_backup SELECT a,b FROM t1; + // DROP TABLE t1; + // CREATE TABLE t1(a,b); + // INSERT INTO t1 SELECT a,b FROM t1_backup; + // DROP TABLE t1_backup; + // COMMIT; + + return FALSE; + } + + return parent::_alter_table($alter_type, $table, $field); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'] + .$field['auto_increment'] + .$field['null'] + .$field['unique'] + .$field['default']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'ENUM': + case 'SET': + $attributes['TYPE'] = 'TEXT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['type'] = 'INTEGER PRIMARY KEY'; + $field['default'] = ''; + $field['null'] = ''; + $field['unique'] = ''; + $field['auto_increment'] = ' AUTOINCREMENT'; + + $this->primary_keys = array(); + } + } + +} diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php new file mode 100644 index 0000000..30c93a2 --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -0,0 +1,164 @@ +num_rows) + ? $this->num_rows + : $this->num_rows = @sqlite_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return @sqlite_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field_names[$i] = sqlite_field_name($this->result_id, $i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = sqlite_field_name($this->result_id, $i); + $retval[$i]->type = NULL; + $retval[$i]->max_length = NULL; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n + * @return bool + */ + public function data_seek($n = 0) + { + return sqlite_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return sqlite_fetch_array($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return sqlite_fetch_object($this->result_id, $class_name); + } + +} diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php new file mode 100644 index 0000000..2c7f809 --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -0,0 +1,61 @@ +db->display_error('db_unsupported_feature'); + } + +} diff --git a/system/database/drivers/sqlite3/index.html b/system/database/drivers/sqlite3/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/sqlite3/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php new file mode 100644 index 0000000..5d057ba --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -0,0 +1,344 @@ +password) + ? new SQLite3($this->database) + : new SQLite3($this->database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password); + } + catch (Exception $e) + { + return FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + $version = SQLite3::version(); + return $this->data_cache['version'] = $version['versionString']; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @todo Implement use of SQLite3::querySingle(), if needed + * @param string $sql + * @return mixed SQLite3Result object or bool + */ + protected function _execute($sql) + { + return $this->is_write_type($sql) + ? $this->conn_id->exec($sql) + : $this->conn_id->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return $this->conn_id->exec('BEGIN TRANSACTION'); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return $this->conn_id->exec('END TRANSACTION'); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return $this->conn_id->exec('ROLLBACK'); + } + + // -------------------------------------------------------------------- + + /** + * Platform-dependent string escape + * + * @param string + * @return string + */ + protected function _escape_str($str) + { + return $this->conn_id->escapeString($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return $this->conn_id->changes(); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return $this->conn_id->lastInsertRowID(); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool $prefix_limit + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' + .(($prefix_limit !== FALSE && $this->dbprefix != '') + ? ' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix).'%\' '.sprintf($this->_like_escape_str, $this->_like_escape_chr) + : ''); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * @param string $table Table name + * @return array + */ + public function list_fields($table) + { + if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $fields = array(); + foreach ($result->result_array() as $row) + { + $fields[] = $row['name']; + } + + return $fields; + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) + { + return FALSE; + } + + $query = $query->result_array(); + if (empty($query)) + { + return FALSE; + } + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]['name']; + $retval[$i]->type = $query[$i]['type']; + $retval[$i]->max_length = NULL; + $retval[$i]->default = $query[$i]['dflt_value']; + $retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + return array('code' => $this->conn_id->lastErrorCode(), 'message' => $this->conn_id->lastErrorMsg()); + } + + // -------------------------------------------------------------------- + + /** + * Replace statement + * + * Generates a platform-specific replace string from the supplied data + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string + */ + protected function _replace($table, $keys, $values) + { + return 'INSERT OR '.parent::_replace($table, $keys, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + $this->conn_id->close(); + } + +} diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php new file mode 100644 index 0000000..4019a95 --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -0,0 +1,225 @@ +db->version(), '3.3', '<')) + { + $this->_create_table_if = FALSE; + $this->_drop_table_if = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @param string $db_name + * @return bool + */ + public function create_database($db_name) + { + // In SQLite, a database is created when you connect to the database. + // We'll return TRUE so that an error isn't generated + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string $db_name (ignored) + * @return bool + */ + public function drop_database($db_name) + { + // In SQLite, a database is dropped when we delete a file + if (file_exists($this->db->database)) + { + // We need to close the pseudo-connection first + $this->db->close(); + if ( ! @unlink($this->db->database)) + { + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + elseif ( ! empty($this->db->data_cache['db_names'])) + { + $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE); + if ($key !== FALSE) + { + unset($this->db->data_cache['db_names'][$key]); + } + } + + return TRUE; + } + + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @todo implement drop_column(), modify_column() + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if ($alter_type === 'DROP' OR $alter_type === 'CHANGE') + { + // drop_column(): + // BEGIN TRANSACTION; + // CREATE TEMPORARY TABLE t1_backup(a,b); + // INSERT INTO t1_backup SELECT a,b FROM t1; + // DROP TABLE t1; + // CREATE TABLE t1(a,b); + // INSERT INTO t1 SELECT a,b FROM t1_backup; + // DROP TABLE t1_backup; + // COMMIT; + + return FALSE; + } + + return parent::_alter_table($alter_type, $table, $field); + } + + // -------------------------------------------------------------------- + + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + return $this->db->escape_identifiers($field['name']) + .' '.$field['type'] + .$field['auto_increment'] + .$field['null'] + .$field['unique'] + .$field['default']; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + switch (strtoupper($attributes['TYPE'])) + { + case 'ENUM': + case 'SET': + $attributes['TYPE'] = 'TEXT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['type'] = 'INTEGER PRIMARY KEY'; + $field['default'] = ''; + $field['null'] = ''; + $field['unique'] = ''; + $field['auto_increment'] = ' AUTOINCREMENT'; + + $this->primary_keys = array(); + } + } + +} diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php new file mode 100644 index 0000000..d656fed --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -0,0 +1,194 @@ +result_id->numColumns(); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field_names[] = $this->result_id->columnName($i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + static $data_types = array( + SQLITE3_INTEGER => 'integer', + SQLITE3_FLOAT => 'float', + SQLITE3_TEXT => 'text', + SQLITE3_BLOB => 'blob', + SQLITE3_NULL => 'null' + ); + + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $this->result_id->columnName($i); + + $type = $this->result_id->columnType($i); + $retval[$i]->type = isset($data_types[$type]) ? $data_types[$type] : $type; + + $retval[$i]->max_length = NULL; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_object($this->result_id)) + { + $this->result_id->finalize(); + $this->result_id = NULL; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return $this->result_id->fetchArray(SQLITE3_ASSOC); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + // No native support for fetching rows as objects + if (($row = $this->result_id->fetchArray(SQLITE3_ASSOC)) === FALSE) + { + return FALSE; + } + elseif ($class_name === 'stdClass') + { + return (object) $row; + } + + $class_name = new $class_name(); + foreach (array_keys($row) as $key) + { + $class_name->$key = $row[$key]; + } + + return $class_name; + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero. + * + * @param int $n (ignored) + * @return array + */ + public function data_seek($n = 0) + { + // Only resetting to the start of the result set is supported + return ($n > 0) ? FALSE : $this->result_id->reset(); + } + +} diff --git a/system/database/drivers/sqlite3/sqlite3_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php new file mode 100644 index 0000000..1bdf3ae --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_utility.php @@ -0,0 +1,61 @@ +db->display_error('db_unsupported_feature'); + } + +} diff --git a/system/database/drivers/sqlsrv/index.html b/system/database/drivers/sqlsrv/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/drivers/sqlsrv/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php new file mode 100644 index 0000000..a22a8b3 --- /dev/null +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -0,0 +1,543 @@ +scrollable === NULL) + { + $this->scrollable = defined('SQLSRV_CURSOR_CLIENT_BUFFERED') + ? SQLSRV_CURSOR_CLIENT_BUFFERED + : FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Database connection + * + * @param bool $pooling + * @return resource + */ + public function db_connect($pooling = FALSE) + { + $charset = in_array(strtolower($this->char_set), array('utf-8', 'utf8'), TRUE) + ? 'UTF-8' : SQLSRV_ENC_CHAR; + + $connection = array( + 'UID' => empty($this->username) ? '' : $this->username, + 'PWD' => empty($this->password) ? '' : $this->password, + 'Database' => $this->database, + 'ConnectionPooling' => ($pooling === TRUE) ? 1 : 0, + 'CharacterSet' => $charset, + 'Encrypt' => ($this->encrypt === TRUE) ? 1 : 0, + 'ReturnDatesAsStrings' => 1 + ); + + // If the username and password are both empty, assume this is a + // 'Windows Authentication Mode' connection. + if (empty($connection['UID']) && empty($connection['PWD'])) + { + unset($connection['UID'], $connection['PWD']); + } + + if (FALSE !== ($this->conn_id = sqlsrv_connect($this->hostname, $connection))) + { + // Determine how identifiers are escaped + $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi'); + $query = $query->row_array(); + $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi']; + $this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']'); + } + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + if ($this->_execute('USE '.$this->escape_identifiers($database))) + { + $this->database = $database; + $this->data_cache = array(); + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string $sql an SQL query + * @return resource + */ + protected function _execute($sql) + { + return ($this->scrollable === FALSE OR $this->is_write_type($sql)) + ? sqlsrv_query($this->conn_id, $sql) + : sqlsrv_query($this->conn_id, $sql, NULL, array('Scrollable' => $this->scrollable)); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + protected function _trans_begin() + { + return sqlsrv_begin_transaction($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + protected function _trans_commit() + { + return sqlsrv_commit($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + protected function _trans_rollback() + { + return sqlsrv_rollback($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return sqlsrv_rows_affected($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * Returns the last id created in the Identity column. + * + * @return string + */ + public function insert_id() + { + return $this->query('SELECT SCOPE_IDENTITY() AS insert_id')->row()->insert_id; + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if ( ! $this->conn_id OR ($info = sqlsrv_server_info($this->conn_id)) === FALSE) + { + return FALSE; + } + + return $this->data_cache['version'] = $info['SQLServerVersion']; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool + * @return string $prefix_limit + */ + protected function _list_tables($prefix_limit = FALSE) + { + $sql = 'SELECT '.$this->escape_identifiers('name') + .' FROM '.$this->escape_identifiers('sysobjects') + .' WHERE '.$this->escape_identifiers('type')." = 'U'"; + + if ($prefix_limit === TRUE && $this->dbprefix !== '') + { + $sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_escape_like_str, $this->_escape_like_chr); + } + + return $sql.' ORDER BY '.$this->escape_identifiers('name'); + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string $table + * @return string + */ + protected function _list_columns($table = '') + { + return 'SELECT COLUMN_NAME + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @param string $table + * @return array + */ + public function field_data($table) + { + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT + FROM INFORMATION_SCHEMA.Columns + WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table)); + + if (($query = $this->query($sql)) === FALSE) + { + return FALSE; + } + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + $retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION; + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Returns an array containing code and message of the last + * database error that has occurred. + * + * @return array + */ + public function error() + { + $error = array('code' => '00000', 'message' => ''); + $sqlsrv_errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); + + if ( ! is_array($sqlsrv_errors)) + { + return $error; + } + + $sqlsrv_error = array_shift($sqlsrv_errors); + if (isset($sqlsrv_error['SQLSTATE'])) + { + $error['code'] = isset($sqlsrv_error['code']) ? $sqlsrv_error['SQLSTATE'].'/'.$sqlsrv_error['code'] : $sqlsrv_error['SQLSTATE']; + } + elseif (isset($sqlsrv_error['code'])) + { + $error['code'] = $sqlsrv_error['code']; + } + + if (isset($sqlsrv_error['message'])) + { + $error['message'] = $sqlsrv_error['message']; + } + + return $error; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string $table + * @param array $values + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the TRUNCATE statement, + * then this method maps to 'DELETE FROM table' + * + * @param string $table + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE TABLE '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string $table + * @return string + */ + protected function _delete($table) + { + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + } + + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * LIMIT + * + * Generates a platform-specific LIMIT clause + * + * @param string $sql SQL Query + * @return string + */ + protected function _limit($sql) + { + // As of SQL Server 2012 (11.0.*) OFFSET is supported + if (version_compare($this->version(), '11', '>=')) + { + // SQL Server OFFSET-FETCH can be used only with the ORDER BY clause + empty($this->qb_orderby) && $sql .= ' ORDER BY 1'; + + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; + } + + $limit = $this->qb_offset + $this->qb_limit; + + // An ORDER BY clause is required for ROW_NUMBER() to work + if ($this->qb_offset && ! empty($this->qb_orderby)) + { + $orderby = $this->_compile_order_by(); + + // We have to strip the ORDER BY clause + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); + + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + ."\n\n) ".$this->escape_identifiers('CI_subquery') + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; + } + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string $table Table name + * @param array $keys INSERT keys + * @param array $values INSERT values + * @return string|bool + */ + protected function _insert_batch($table, $keys, $values) + { + // Multiple-value inserts are only supported as of SQL Server 2008 + if (version_compare($this->version(), '10', '>=')) + { + return parent::_insert_batch($table, $keys, $values); + } + + return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + sqlsrv_close($this->conn_id); + } + +} diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php new file mode 100644 index 0000000..90c3120 --- /dev/null +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -0,0 +1,149 @@ + 'SMALLINT', + 'SMALLINT' => 'INT', + 'INT' => 'BIGINT', + 'REAL' => 'FLOAT' + ); + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN '; + $sqls = array(); + for ($i = 0, $c = count($field); $i < $c; $i++) + { + $sqls[] = $sql.$this->_process_column($field[$i]); + } + + return $sqls; + } + + // -------------------------------------------------------------------- + + /** + * Field attribute TYPE + * + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void + */ + protected function _attr_type(&$attributes) + { + if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE) + { + unset($attributes['CONSTRAINT']); + } + + switch (strtoupper($attributes['TYPE'])) + { + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'INTEGER': + $attributes['TYPE'] = 'INT'; + return; + default: return; + } + } + + // -------------------------------------------------------------------- + + /** + * Field attribute AUTO_INCREMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE) + { + $field['auto_increment'] = ' IDENTITY(1,1)'; + } + } + +} diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php new file mode 100644 index 0000000..e2649c6 --- /dev/null +++ b/system/database/drivers/sqlsrv/sqlsrv_result.php @@ -0,0 +1,193 @@ +scrollable = $driver_object->scrollable; + } + + // -------------------------------------------------------------------- + + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + // sqlsrv_num_rows() doesn't work with the FORWARD and DYNAMIC cursors (FALSE is the same as FORWARD) + if ( ! in_array($this->scrollable, array(FALSE, SQLSRV_CURSOR_FORWARD, SQLSRV_CURSOR_DYNAMIC), TRUE)) + { + return parent::num_rows(); + } + + return is_int($this->num_rows) + ? $this->num_rows + : $this->num_rows = sqlsrv_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return @sqlsrv_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field) + { + $field_names[] = $field['Name']; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + foreach (sqlsrv_field_metadata($this->result_id) as $i => $field) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $field['Name']; + $retval[$i]->type = $field['Type']; + $retval[$i]->max_length = $field['Size']; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_resource($this->result_id)) + { + sqlsrv_free_stmt($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @param string $class_name + * @return object + */ + protected function _fetch_object($class_name = 'stdClass') + { + return sqlsrv_fetch_object($this->result_id, $class_name); + } + +} diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php new file mode 100644 index 0000000..6dd01a9 --- /dev/null +++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php @@ -0,0 +1,77 @@ +db->display_error('db_unsupported_feature'); + } + +} diff --git a/system/database/index.html b/system/database/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/database/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/system/fonts/index.html b/system/fonts/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/system/fonts/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/bmt-system/fonts/texb.ttf b/system/fonts/texb.ttf old mode 100755 new mode 100644 similarity index 51% rename from bmt-system/fonts/texb.ttf rename to system/fonts/texb.ttf index a7aa646..383c88b Binary files a/bmt-system/fonts/texb.ttf and b/system/fonts/texb.ttf differ diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php new file mode 100644 index 0000000..cb7eca6 --- /dev/null +++ b/system/helpers/array_helper.php @@ -0,0 +1,115 @@ + '', + 'img_path' => '', + 'img_url' => '', + 'img_width' => '150', + 'img_height' => '30', + 'font_path' => '', + 'expiration' => 7200, + 'word_length' => 8, + 'font_size' => 16, + 'img_id' => '', + 'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', + 'colors' => array( + 'background' => array(255,255,255), + 'border' => array(153,102,102), + 'text' => array(204,153,153), + 'grid' => array(255,182,182) + ) + ); + + foreach ($defaults as $key => $val) + { + if ( ! is_array($data) && empty($$key)) + { + $$key = $val; + } + else + { + $$key = isset($data[$key]) ? $data[$key] : $val; + } + } + + if ($img_path === '' OR $img_url === '' + OR ! is_dir($img_path) OR ! is_really_writable($img_path) + OR ! extension_loaded('gd')) + { + return FALSE; + } + + // ----------------------------------- + // Remove old images + // ----------------------------------- + + $now = microtime(TRUE); + + $current_dir = @opendir($img_path); + while ($filename = @readdir($current_dir)) + { + if (in_array(substr($filename, -4), array('.jpg', '.png')) + && (str_replace(array('.jpg', '.png'), '', $filename) + $expiration) < $now) + { + @unlink($img_path.$filename); + } + } + + @closedir($current_dir); + + // ----------------------------------- + // Do we have a "word" yet? + // ----------------------------------- + + if (empty($word)) + { + $word = ''; + $pool_length = strlen($pool); + $rand_max = $pool_length - 1; + + // PHP7 or a suitable polyfill + if (function_exists('random_int')) + { + try + { + for ($i = 0; $i < $word_length; $i++) + { + $word .= $pool[random_int(0, $rand_max)]; + } + } + catch (Exception $e) + { + // This means fallback to the next possible + // alternative to random_int() + $word = ''; + } + } + } + + if (empty($word)) + { + // Nobody will have a larger character pool than + // 256 characters, but let's handle it just in case ... + // + // No, I do not care that the fallback to mt_rand() can + // handle it; if you trigger this, you're very obviously + // trying to break it. -- Narf + if ($pool_length > 256) + { + return FALSE; + } + + // We'll try using the operating system's PRNG first, + // which we can access through CI_Security::get_random_bytes() + $security = get_instance()->security; + + // To avoid numerous get_random_bytes() calls, we'll + // just try fetching as much bytes as we need at once. + if (($bytes = $security->get_random_bytes($pool_length)) !== FALSE) + { + $byte_index = $word_index = 0; + while ($word_index < $word_length) + { + // Do we have more random data to use? + // It could be exhausted by previous iterations + // ignoring bytes higher than $rand_max. + if ($byte_index === $pool_length) + { + // No failures should be possible if the + // first get_random_bytes() call didn't + // return FALSE, but still ... + for ($i = 0; $i < 5; $i++) + { + if (($bytes = $security->get_random_bytes($pool_length)) === FALSE) + { + continue; + } + + $byte_index = 0; + break; + } + + if ($bytes === FALSE) + { + // Sadly, this means fallback to mt_rand() + $word = ''; + break; + } + } + + list(, $rand_index) = unpack('C', $bytes[$byte_index++]); + if ($rand_index > $rand_max) + { + continue; + } + + $word .= $pool[$rand_index]; + $word_index++; + } + } + } + + if (empty($word)) + { + for ($i = 0; $i < $word_length; $i++) + { + $word .= $pool[mt_rand(0, $rand_max)]; + } + } + elseif ( ! is_string($word)) + { + $word = (string) $word; + } + + // ----------------------------------- + // Determine angle and position + // ----------------------------------- + $length = strlen($word); + $angle = ($length >= 6) ? mt_rand(-($length-6), ($length-6)) : 0; + $x_axis = mt_rand(6, (360/$length)-16); + $y_axis = ($angle >= 0) ? mt_rand($img_height, $img_width) : mt_rand(6, $img_height); + + // Create image + // PHP.net recommends imagecreatetruecolor(), but it isn't always available + $im = function_exists('imagecreatetruecolor') + ? imagecreatetruecolor($img_width, $img_height) + : imagecreate($img_width, $img_height); + + // ----------------------------------- + // Assign colors + // ---------------------------------- + + is_array($colors) OR $colors = $defaults['colors']; + + foreach (array_keys($defaults['colors']) as $key) + { + // Check for a possible missing value + is_array($colors[$key]) OR $colors[$key] = $defaults['colors'][$key]; + $colors[$key] = imagecolorallocate($im, $colors[$key][0], $colors[$key][1], $colors[$key][2]); + } + + // Create the rectangle + ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $colors['background']); + + // ----------------------------------- + // Create the spiral pattern + // ----------------------------------- + $theta = 1; + $thetac = 7; + $radius = 16; + $circles = 20; + $points = 32; + + for ($i = 0, $cp = ($circles * $points) - 1; $i < $cp; $i++) + { + $theta += $thetac; + $rad = $radius * ($i / $points); + $x = ($rad * cos($theta)) + $x_axis; + $y = ($rad * sin($theta)) + $y_axis; + $theta += $thetac; + $rad1 = $radius * (($i + 1) / $points); + $x1 = ($rad1 * cos($theta)) + $x_axis; + $y1 = ($rad1 * sin($theta)) + $y_axis; + imageline($im, $x, $y, $x1, $y1, $colors['grid']); + $theta -= $thetac; + } + + // ----------------------------------- + // Write the text + // ----------------------------------- + + $use_font = ($font_path !== '' && file_exists($font_path) && function_exists('imagettftext')); + if ($use_font === FALSE) + { + ($font_size > 5) && $font_size = 5; + $x = mt_rand(0, $img_width / ($length / 3)); + $y = 0; + } + else + { + ($font_size > 30) && $font_size = 30; + $x = mt_rand(0, $img_width / ($length / 1.5)); + $y = $font_size + 2; + } + + for ($i = 0; $i < $length; $i++) + { + if ($use_font === FALSE) + { + $y = mt_rand(0 , $img_height / 2); + imagestring($im, $font_size, $x, $y, $word[$i], $colors['text']); + $x += ($font_size * 2); + } + else + { + $y = mt_rand($img_height / 2, $img_height - 3); + imagettftext($im, $font_size, $angle, $x, $y, $colors['text'], $font_path, $word[$i]); + $x += $font_size; + } + } + + // Create the border + imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $colors['border']); + + // ----------------------------------- + // Generate the image + // ----------------------------------- + $img_url = rtrim($img_url, '/').'/'; + + if (function_exists('imagejpeg')) + { + $img_filename = $now.'.jpg'; + imagejpeg($im, $img_path.$img_filename); + } + elseif (function_exists('imagepng')) + { + $img_filename = $now.'.png'; + imagepng($im, $img_path.$img_filename); + } + else + { + return FALSE; + } + + $img = ' '; + ImageDestroy($im); + + return array('word' => $word, 'time' => $now, 'image' => $img, 'filename' => $img_filename); + } +} diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php new file mode 100644 index 0000000..b9c2cb6 --- /dev/null +++ b/system/helpers/cookie_helper.php @@ -0,0 +1,113 @@ +input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure, $httponly); + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('get_cookie')) +{ + /** + * Fetch an item from the COOKIE array + * + * @param string + * @param bool + * @return mixed + */ + function get_cookie($index, $xss_clean = NULL) + { + is_bool($xss_clean) OR $xss_clean = (config_item('global_xss_filtering') === TRUE); + $prefix = isset($_COOKIE[$index]) ? '' : config_item('cookie_prefix'); + return get_instance()->input->cookie($prefix.$index, $xss_clean); + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('delete_cookie')) +{ + /** + * Delete a COOKIE + * + * @param mixed + * @param string the cookie domain. Usually: .yourdomain.com + * @param string the cookie path + * @param string the cookie prefix + * @return void + */ + function delete_cookie($name, $domain = '', $path = '/', $prefix = '') + { + set_cookie($name, '', '', $domain, $path, $prefix); + } +} diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php new file mode 100644 index 0000000..5c660e2 --- /dev/null +++ b/system/helpers/date_helper.php @@ -0,0 +1,742 @@ +format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second); + + return mktime($hour, $minute, $second, $month, $day, $year); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('mdate')) +{ + /** + * Convert MySQL Style Datecodes + * + * This function is identical to PHPs date() function, + * except that it allows date codes to be formatted using + * the MySQL style, where each code letter is preceded + * with a percent sign: %Y %m %d etc... + * + * The benefit of doing dates this way is that you don't + * have to worry about escaping your text letters that + * match the date codes. + * + * @param string + * @param int + * @return int + */ + function mdate($datestr = '', $time = '') + { + if ($datestr === '') + { + return ''; + } + elseif (empty($time)) + { + $time = now(); + } + + $datestr = str_replace( + '%\\', + '', + preg_replace('/([a-z]+?){1}/i', '\\\\\\1', $datestr) + ); + + return date($datestr, $time); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('standard_date')) +{ + /** + * Standard Date + * + * Returns a date formatted according to the submitted standard. + * + * As of PHP 5.2, the DateTime extension provides constants that + * serve for the exact same purpose and are used with date(). + * + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 Use PHP's native date() instead. + * @link http://www.php.net/manual/en/class.datetime.php#datetime.constants.types + * + * @example date(DATE_RFC822, now()); // default + * @example date(DATE_W3C, $time); // a different format and time + * + * @param string $fmt = 'DATE_RFC822' the chosen format + * @param int $time = NULL Unix timestamp + * @return string + */ + function standard_date($fmt = 'DATE_RFC822', $time = NULL) + { + if (empty($time)) + { + $time = now(); + } + + // Procedural style pre-defined constants from the DateTime extension + if (strpos($fmt, 'DATE_') !== 0 OR defined($fmt) === FALSE) + { + return FALSE; + } + + return date(constant($fmt), $time); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('timespan')) +{ + /** + * Timespan + * + * Returns a span of seconds in this format: + * 10 days 14 hours 36 minutes 47 seconds + * + * @param int a number of seconds + * @param int Unix timestamp + * @param int a number of display units + * @return string + */ + function timespan($seconds = 1, $time = '', $units = 7) + { + $CI =& get_instance(); + $CI->lang->load('date'); + + is_numeric($seconds) OR $seconds = 1; + is_numeric($time) OR $time = time(); + is_numeric($units) OR $units = 7; + + $seconds = ($time <= $seconds) ? 1 : $time - $seconds; + + $str = array(); + $years = floor($seconds / 31557600); + + if ($years > 0) + { + $str[] = $years.' '.$CI->lang->line($years > 1 ? 'date_years' : 'date_year'); + } + + $seconds -= $years * 31557600; + $months = floor($seconds / 2629743); + + if (count($str) < $units && ($years > 0 OR $months > 0)) + { + if ($months > 0) + { + $str[] = $months.' '.$CI->lang->line($months > 1 ? 'date_months' : 'date_month'); + } + + $seconds -= $months * 2629743; + } + + $weeks = floor($seconds / 604800); + + if (count($str) < $units && ($years > 0 OR $months > 0 OR $weeks > 0)) + { + if ($weeks > 0) + { + $str[] = $weeks.' '.$CI->lang->line($weeks > 1 ? 'date_weeks' : 'date_week'); + } + + $seconds -= $weeks * 604800; + } + + $days = floor($seconds / 86400); + + if (count($str) < $units && ($months > 0 OR $weeks > 0 OR $days > 0)) + { + if ($days > 0) + { + $str[] = $days.' '.$CI->lang->line($days > 1 ? 'date_days' : 'date_day'); + } + + $seconds -= $days * 86400; + } + + $hours = floor($seconds / 3600); + + if (count($str) < $units && ($days > 0 OR $hours > 0)) + { + if ($hours > 0) + { + $str[] = $hours.' '.$CI->lang->line($hours > 1 ? 'date_hours' : 'date_hour'); + } + + $seconds -= $hours * 3600; + } + + $minutes = floor($seconds / 60); + + if (count($str) < $units && ($days > 0 OR $hours > 0 OR $minutes > 0)) + { + if ($minutes > 0) + { + $str[] = $minutes.' '.$CI->lang->line($minutes > 1 ? 'date_minutes' : 'date_minute'); + } + + $seconds -= $minutes * 60; + } + + if (count($str) === 0) + { + $str[] = $seconds.' '.$CI->lang->line($seconds > 1 ? 'date_seconds' : 'date_second'); + } + + return implode(', ', $str); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('days_in_month')) +{ + /** + * Number of days in a month + * + * Takes a month/year as input and returns the number of days + * for the given month/year. Takes leap years into consideration. + * + * @param int a numeric month + * @param int a numeric year + * @return int + */ + function days_in_month($month = 0, $year = '') + { + if ($month < 1 OR $month > 12) + { + return 0; + } + elseif ( ! is_numeric($year) OR strlen($year) !== 4) + { + $year = date('Y'); + } + + if (defined('CAL_GREGORIAN')) + { + return cal_days_in_month(CAL_GREGORIAN, $month, $year); + } + + if ($year >= 1970) + { + return (int) date('t', mktime(12, 0, 0, $month, 1, $year)); + } + + if ($month == 2) + { + if ($year % 400 === 0 OR ($year % 4 === 0 && $year % 100 !== 0)) + { + return 29; + } + } + + $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + return $days_in_month[$month - 1]; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('local_to_gmt')) +{ + /** + * Converts a local Unix timestamp to GMT + * + * @param int Unix timestamp + * @return int + */ + function local_to_gmt($time = '') + { + if ($time === '') + { + $time = time(); + } + + return mktime( + gmdate('G', $time), + gmdate('i', $time), + gmdate('s', $time), + gmdate('n', $time), + gmdate('j', $time), + gmdate('Y', $time) + ); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('gmt_to_local')) +{ + /** + * Converts GMT time to a localized value + * + * Takes a Unix timestamp (in GMT) as input, and returns + * at the local value based on the timezone and DST setting + * submitted + * + * @param int Unix timestamp + * @param string timezone + * @param bool whether DST is active + * @return int + */ + function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) + { + if ($time === '') + { + return now(); + } + + $time += timezones($timezone) * 3600; + + return ($dst === TRUE) ? $time + 3600 : $time; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('mysql_to_unix')) +{ + /** + * Converts a MySQL Timestamp to Unix + * + * @param int MySQL timestamp YYYY-MM-DD HH:MM:SS + * @return int Unix timstamp + */ + function mysql_to_unix($time = '') + { + // We'll remove certain characters for backward compatibility + // since the formatting changed with MySQL 4.1 + // YYYY-MM-DD HH:MM:SS + + $time = str_replace(array('-', ':', ' '), '', $time); + + // YYYYMMDDHHMMSS + return mktime( + substr($time, 8, 2), + substr($time, 10, 2), + substr($time, 12, 2), + substr($time, 4, 2), + substr($time, 6, 2), + substr($time, 0, 4) + ); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('unix_to_human')) +{ + /** + * Unix to "Human" + * + * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM + * + * @param int Unix timestamp + * @param bool whether to show seconds + * @param string format: us or euro + * @return string + */ + function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') + { + $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; + + if ($fmt === 'us') + { + $r .= date('h', $time).':'.date('i', $time); + } + else + { + $r .= date('H', $time).':'.date('i', $time); + } + + if ($seconds) + { + $r .= ':'.date('s', $time); + } + + if ($fmt === 'us') + { + return $r.' '.date('A', $time); + } + + return $r; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('human_to_unix')) +{ + /** + * Convert "human" date to GMT + * + * Reverses the above process + * + * @param string format: us or euro + * @return int + */ + function human_to_unix($datestr = '') + { + if ($datestr === '') + { + return FALSE; + } + + $datestr = preg_replace('/\040+/', ' ', trim($datestr)); + + if ( ! preg_match('/^(\d{2}|\d{4})\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr)) + { + return FALSE; + } + + sscanf($datestr, '%d-%d-%d %s %s', $year, $month, $day, $time, $ampm); + sscanf($time, '%d:%d:%d', $hour, $min, $sec); + isset($sec) OR $sec = 0; + + if (isset($ampm)) + { + $ampm = strtolower($ampm); + + if ($ampm[0] === 'p' && $hour < 12) + { + $hour += 12; + } + elseif ($ampm[0] === 'a' && $hour === 12) + { + $hour = 0; + } + } + + return mktime($hour, $min, $sec, $month, $day, $year); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('nice_date')) +{ + /** + * Turns many "reasonably-date-like" strings into something + * that is actually useful. This only works for dates after unix epoch. + * + * @deprecated 3.1.3 Use DateTime::createFromFormat($input_format, $input)->format($output_format); + * @param string The terribly formatted date-like string + * @param string Date format to return (same as php date function) + * @return string + */ + function nice_date($bad_date = '', $format = FALSE) + { + if (empty($bad_date)) + { + return 'Unknown'; + } + elseif (empty($format)) + { + $format = 'U'; + } + + // Date like: YYYYMM + if (preg_match('/^\d{6}$/i', $bad_date)) + { + if (in_array(substr($bad_date, 0, 2), array('19', '20'))) + { + $year = substr($bad_date, 0, 4); + $month = substr($bad_date, 4, 2); + } + else + { + $month = substr($bad_date, 0, 2); + $year = substr($bad_date, 2, 4); + } + + return date($format, strtotime($year.'-'.$month.'-01')); + } + + // Date Like: YYYYMMDD + if (preg_match('/^\d{8}$/i', $bad_date, $matches)) + { + return DateTime::createFromFormat('Ymd', $bad_date)->format($format); + } + + // Date Like: MM-DD-YYYY __or__ M-D-YYYY (or anything in between) + if (preg_match('/^(\d{1,2})-(\d{1,2})-(\d{4})$/i', $bad_date, $matches)) + { + return date($format, strtotime($matches[3].'-'.$matches[1].'-'.$matches[2])); + } + + // Any other kind of string, when converted into UNIX time, + // produces "0 seconds after epoc..." is probably bad... + // return "Invalid Date". + if (date('U', strtotime($bad_date)) === '0') + { + return 'Invalid Date'; + } + + // It's probably a valid-ish date format already + return date($format, strtotime($bad_date)); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('timezone_menu')) +{ + /** + * Timezone Menu + * + * Generates a drop-down menu of timezones. + * + * @param string timezone + * @param string classname + * @param string menu name + * @param mixed attributes + * @return string + */ + function timezone_menu($default = 'UTC', $class = '', $name = 'timezones', $attributes = '') + { + $CI =& get_instance(); + $CI->lang->load('date'); + + $default = ($default === 'GMT') ? 'UTC' : $default; + + $menu = ''; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('timezones')) +{ + /** + * Timezones + * + * Returns an array of timezones. This is a helper function + * for various other ones in this library + * + * @param string timezone + * @return string + */ + function timezones($tz = '') + { + // Note: Don't change the order of these even though + // some items appear to be in the wrong order + + $zones = array( + 'UM12' => -12, + 'UM11' => -11, + 'UM10' => -10, + 'UM95' => -9.5, + 'UM9' => -9, + 'UM8' => -8, + 'UM7' => -7, + 'UM6' => -6, + 'UM5' => -5, + 'UM45' => -4.5, + 'UM4' => -4, + 'UM35' => -3.5, + 'UM3' => -3, + 'UM2' => -2, + 'UM1' => -1, + 'UTC' => 0, + 'UP1' => +1, + 'UP2' => +2, + 'UP3' => +3, + 'UP35' => +3.5, + 'UP4' => +4, + 'UP45' => +4.5, + 'UP5' => +5, + 'UP55' => +5.5, + 'UP575' => +5.75, + 'UP6' => +6, + 'UP65' => +6.5, + 'UP7' => +7, + 'UP8' => +8, + 'UP875' => +8.75, + 'UP9' => +9, + 'UP95' => +9.5, + 'UP10' => +10, + 'UP105' => +10.5, + 'UP11' => +11, + 'UP115' => +11.5, + 'UP12' => +12, + 'UP1275' => +12.75, + 'UP13' => +13, + 'UP14' => +14 + ); + + if ($tz === '') + { + return $zones; + } + + return isset($zones[$tz]) ? $zones[$tz] : 0; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('date_range')) +{ + /** + * Date range + * + * Returns a list of dates within a specified period. + * + * @param int unix_start UNIX timestamp of period start date + * @param int unix_end|days UNIX timestamp of period end date + * or interval in days. + * @param mixed is_unix Specifies whether the second parameter + * is a UNIX timestamp or a day interval + * - TRUE or 'unix' for a timestamp + * - FALSE or 'days' for an interval + * @param string date_format Output date format, same as in date() + * @return array + */ + function date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y-m-d') + { + if ($unix_start == '' OR $mixed == '' OR $format == '') + { + return FALSE; + } + + $is_unix = ! ( ! $is_unix OR $is_unix === 'days'); + + // Validate input and try strtotime() on invalid timestamps/intervals, just in case + if ( ( ! ctype_digit((string) $unix_start) && ($unix_start = @strtotime($unix_start)) === FALSE) + OR ( ! ctype_digit((string) $mixed) && ($is_unix === FALSE OR ($mixed = @strtotime($mixed)) === FALSE)) + OR ($is_unix === TRUE && $mixed < $unix_start)) + { + return FALSE; + } + + if ($is_unix && ($unix_start == $mixed OR date($format, $unix_start) === date($format, $mixed))) + { + return array(date($format, $unix_start)); + } + + $range = array(); + + $from = new DateTime(); + $from->setTimestamp($unix_start); + + if ($is_unix) + { + $arg = new DateTime(); + $arg->setTimestamp($mixed); + } + else + { + $arg = (int) $mixed; + } + + $period = new DatePeriod($from, new DateInterval('P1D'), $arg); + foreach ($period as $date) + { + $range[] = $date->format($format); + } + + /* If a period end date was passed to the DatePeriod constructor, it might not + * be in our results. Not sure if this is a bug or it's just possible because + * the end date might actually be less than 24 hours away from the previously + * generated DateTime object, but either way - we have to append it manually. + */ + if ( ! is_int($arg) && $range[count($range) - 1] !== $arg->format($format)) + { + $range[] = $arg->format($format); + } + + return $range; + } +} diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php new file mode 100644 index 0000000..73777bf --- /dev/null +++ b/system/helpers/directory_helper.php @@ -0,0 +1,101 @@ + 0) && is_dir($source_dir.$file)) + { + $filedata[$file] = directory_map($source_dir.$file, $new_depth, $hidden); + } + else + { + $filedata[] = $file; + } + } + + closedir($fp); + return $filedata; + } + + return FALSE; + } +} diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php new file mode 100644 index 0000000..d8e30ae --- /dev/null +++ b/system/helpers/download_helper.php @@ -0,0 +1,158 @@ + 0) + ? @rmdir($path) + : TRUE; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('get_filenames')) +{ + /** + * Get Filenames + * + * Reads the specified directory and builds an array containing the filenames. + * Any sub-folders contained within the specified path are read as well. + * + * @param string path to source + * @param bool whether to include the path as part of the filename + * @param bool internal variable to determine recursion status - do not use in calls + * @return array + */ + function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) + { + static $_filedata = array(); + + if ($fp = @opendir($source_dir)) + { + // reset the array and make sure $source_dir has a trailing slash on the initial call + if ($_recursion === FALSE) + { + $_filedata = array(); + $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + } + + while (FALSE !== ($file = readdir($fp))) + { + if (is_dir($source_dir.$file) && $file[0] !== '.') + { + get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); + } + elseif ($file[0] !== '.') + { + $_filedata[] = ($include_path === TRUE) ? $source_dir.$file : $file; + } + } + + closedir($fp); + return $_filedata; + } + + return FALSE; + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('get_dir_file_info')) +{ + /** + * Get Directory File Information + * + * Reads the specified directory and builds an array containing the filenames, + * filesize, dates, and permissions + * + * Any sub-folders contained within the specified path are read as well. + * + * @param string path to source + * @param bool Look only at the top level directory specified? + * @param bool internal variable to determine recursion status - do not use in calls + * @return array + */ + function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) + { + static $_filedata = array(); + $relative_path = $source_dir; + + if ($fp = @opendir($source_dir)) + { + // reset the array and make sure $source_dir has a trailing slash on the initial call + if ($_recursion === FALSE) + { + $_filedata = array(); + $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + } + + // Used to be foreach (scandir($source_dir, 1) as $file), but scandir() is simply not as fast + while (FALSE !== ($file = readdir($fp))) + { + if (is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE) + { + get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); + } + elseif ($file[0] !== '.') + { + $_filedata[$file] = get_file_info($source_dir.$file); + $_filedata[$file]['relative_path'] = $relative_path; + } + } + + closedir($fp); + return $_filedata; + } + + return FALSE; + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('get_file_info')) +{ + /** + * Get File Info + * + * Given a file and path, returns the name, path, size, date modified + * Second parameter allows you to explicitly declare what information you want returned + * Options are: name, server_path, size, date, readable, writable, executable, fileperms + * Returns FALSE if the file cannot be found. + * + * @param string path to file + * @param mixed array or comma separated string of information returned + * @return array + */ + function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date')) + { + if ( ! file_exists($file)) + { + return FALSE; + } + + if (is_string($returned_values)) + { + $returned_values = explode(',', $returned_values); + } + + foreach ($returned_values as $key) + { + switch ($key) + { + case 'name': + $fileinfo['name'] = basename($file); + break; + case 'server_path': + $fileinfo['server_path'] = $file; + break; + case 'size': + $fileinfo['size'] = filesize($file); + break; + case 'date': + $fileinfo['date'] = filemtime($file); + break; + case 'readable': + $fileinfo['readable'] = is_readable($file); + break; + case 'writable': + $fileinfo['writable'] = is_really_writable($file); + break; + case 'executable': + $fileinfo['executable'] = is_executable($file); + break; + case 'fileperms': + $fileinfo['fileperms'] = fileperms($file); + break; + } + } + + return $fileinfo; + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('get_mime_by_extension')) +{ + /** + * Get Mime by Extension + * + * Translates a file extension into a mime type based on config/mimes.php. + * Returns FALSE if it can't determine the type, or open the mime config file + * + * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience + * It should NOT be trusted, and should certainly NOT be used for security + * + * @param string $filename File name + * @return string + */ + function get_mime_by_extension($filename) + { + static $mimes; + + if ( ! is_array($mimes)) + { + $mimes = get_mimes(); + + if (empty($mimes)) + { + return FALSE; + } + } + + $extension = strtolower(substr(strrchr($filename, '.'), 1)); + + if (isset($mimes[$extension])) + { + return is_array($mimes[$extension]) + ? current($mimes[$extension]) // Multiple mime types, just give the first one + : $mimes[$extension]; + } + + return FALSE; + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('symbolic_permissions')) +{ + /** + * Symbolic Permissions + * + * Takes a numeric value representing a file's permissions and returns + * standard symbolic notation representing that value + * + * @param int $perms Permissions + * @return string + */ + function symbolic_permissions($perms) + { + if (($perms & 0xC000) === 0xC000) + { + $symbolic = 's'; // Socket + } + elseif (($perms & 0xA000) === 0xA000) + { + $symbolic = 'l'; // Symbolic Link + } + elseif (($perms & 0x8000) === 0x8000) + { + $symbolic = '-'; // Regular + } + elseif (($perms & 0x6000) === 0x6000) + { + $symbolic = 'b'; // Block special + } + elseif (($perms & 0x4000) === 0x4000) + { + $symbolic = 'd'; // Directory + } + elseif (($perms & 0x2000) === 0x2000) + { + $symbolic = 'c'; // Character special + } + elseif (($perms & 0x1000) === 0x1000) + { + $symbolic = 'p'; // FIFO pipe + } + else + { + $symbolic = 'u'; // Unknown + } + + // Owner + $symbolic .= (($perms & 0x0100) ? 'r' : '-') + .(($perms & 0x0080) ? 'w' : '-') + .(($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); + + // Group + $symbolic .= (($perms & 0x0020) ? 'r' : '-') + .(($perms & 0x0010) ? 'w' : '-') + .(($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); + + // World + $symbolic .= (($perms & 0x0004) ? 'r' : '-') + .(($perms & 0x0002) ? 'w' : '-') + .(($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); + + return $symbolic; + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('octal_permissions')) +{ + /** + * Octal Permissions + * + * Takes a numeric value representing a file's permissions and returns + * a three character string representing the file's octal permissions + * + * @param int $perms Permissions + * @return string + */ + function octal_permissions($perms) + { + return substr(sprintf('%o', $perms), -3); + } +} diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php new file mode 100644 index 0000000..5910d8e --- /dev/null +++ b/system/helpers/form_helper.php @@ -0,0 +1,1055 @@ +config->site_url($CI->uri->uri_string()); + } + // If an action is not a full URL then turn it into one + elseif (strpos($action, '://') === FALSE) + { + $action = $CI->config->site_url($action); + } + + $attributes = _attributes_to_string($attributes); + + if (stripos($attributes, 'method=') === FALSE) + { + $attributes .= ' method="post"'; + } + + if (stripos($attributes, 'accept-charset=') === FALSE) + { + $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"'; + } + + $form = '
    \n"; + + if (is_array($hidden)) + { + foreach ($hidden as $name => $value) + { + $form .= ''."\n"; + } + } + + // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites + if ($CI->config->item('csrf_protection') === TRUE && strpos($action, $CI->config->base_url()) !== FALSE && ! stripos($form, 'method="get"')) + { + // Prepend/append random-length "white noise" around the CSRF + // token input, as a form of protection against BREACH attacks + if (FALSE !== ($noise = $CI->security->get_random_bytes(1))) + { + list(, $noise) = unpack('c', $noise); + } + else + { + $noise = mt_rand(-128, 127); + } + + // Prepend if $noise has a negative value, append if positive, do nothing for zero + $prepend = $append = ''; + if ($noise < 0) + { + $prepend = str_repeat(" ", abs($noise)); + } + elseif ($noise > 0) + { + $append = str_repeat(" ", $noise); + } + + $form .= sprintf( + '%s%s%s', + $prepend, + $CI->security->get_csrf_token_name(), + $CI->security->get_csrf_hash(), + $append, + "\n" + ); + } + + return $form; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_open_multipart')) +{ + /** + * Form Declaration - Multipart type + * + * Creates the opening portion of the form, but with "multipart/form-data". + * + * @param string the URI segments of the form destination + * @param array a key/value pair of attributes + * @param array a key/value pair hidden data + * @return string + */ + function form_open_multipart($action = '', $attributes = array(), $hidden = array()) + { + if (is_string($attributes)) + { + $attributes .= ' enctype="multipart/form-data"'; + } + else + { + $attributes['enctype'] = 'multipart/form-data'; + } + + return form_open($action, $attributes, $hidden); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_hidden')) +{ + /** + * Hidden Input Field + * + * Generates hidden fields. You can pass a simple key/value string or + * an associative array with multiple values. + * + * @param mixed $name Field name + * @param string $value Field value + * @param bool $recursing + * @return string + */ + function form_hidden($name, $value = '', $recursing = FALSE) + { + static $form; + + if ($recursing === FALSE) + { + $form = "\n"; + } + + if (is_array($name)) + { + foreach ($name as $key => $val) + { + form_hidden($key, $val, TRUE); + } + + return $form; + } + + if ( ! is_array($value)) + { + $form .= '\n"; + } + else + { + foreach ($value as $k => $v) + { + $k = is_int($k) ? '' : $k; + form_hidden($name.'['.$k.']', $v, TRUE); + } + } + + return $form; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_input')) +{ + /** + * Text Input Field + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_input($data = '', $value = '', $extra = '') + { + $defaults = array( + 'type' => 'text', + 'name' => is_array($data) ? '' : $data, + 'value' => $value + ); + + return '\n"; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_password')) +{ + /** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_password($data = '', $value = '', $extra = '') + { + is_array($data) OR $data = array('name' => $data); + $data['type'] = 'password'; + return form_input($data, $value, $extra); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_upload')) +{ + /** + * Upload Field + * + * Identical to the input function but adds the "file" type + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_upload($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'file', 'name' => ''); + is_array($data) OR $data = array('name' => $data); + $data['type'] = 'file'; + + return '\n"; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_textarea')) +{ + /** + * Textarea field + * + * @param mixed $data + * @param string $value + * @param mixed $extra + * @return string + */ + function form_textarea($data = '', $value = '', $extra = '') + { + $defaults = array( + 'name' => is_array($data) ? '' : $data, + 'cols' => '40', + 'rows' => '10' + ); + + if ( ! is_array($data) OR ! isset($data['value'])) + { + $val = $value; + } + else + { + $val = $data['value']; + unset($data['value']); // textareas don't use the value attribute + } + + return '\n"; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_multiselect')) +{ + /** + * Multi-select menu + * + * @param string + * @param array + * @param mixed + * @param mixed + * @return string + */ + function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '') + { + $extra = _attributes_to_string($extra); + if (stripos($extra, 'multiple') === FALSE) + { + $extra .= ' multiple="multiple"'; + } + + return form_dropdown($name, $options, $selected, $extra); + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('form_dropdown')) +{ + /** + * Drop-down Menu + * + * @param mixed $data + * @param mixed $options + * @param mixed $selected + * @param mixed $extra + * @return string + */ + function form_dropdown($data = '', $options = array(), $selected = array(), $extra = '') + { + $defaults = array(); + + if (is_array($data)) + { + if (isset($data['selected'])) + { + $selected = $data['selected']; + unset($data['selected']); // select tags don't have a selected attribute + } + + if (isset($data['options'])) + { + $options = $data['options']; + unset($data['options']); // select tags don't use an options attribute + } + } + else + { + $defaults = array('name' => $data); + } + + is_array($selected) OR $selected = array($selected); + is_array($options) OR $options = array($options); + + // If no selected state was submitted we will attempt to set it automatically + if (empty($selected)) + { + if (is_array($data)) + { + if (isset($data['name'], $_POST[$data['name']])) + { + $selected = array($_POST[$data['name']]); + } + } + elseif (isset($_POST[$data])) + { + $selected = array($_POST[$data]); + } + } + + $extra = _attributes_to_string($extra); + + $multiple = (count($selected) > 1 && stripos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; + + $form = '\n"; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_checkbox')) +{ + /** + * Checkbox Field + * + * @param mixed + * @param string + * @param bool + * @param mixed + * @return string + */ + function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') + { + $defaults = array('type' => 'checkbox', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); + + if (is_array($data) && array_key_exists('checked', $data)) + { + $checked = $data['checked']; + + if ($checked == FALSE) + { + unset($data['checked']); + } + else + { + $data['checked'] = 'checked'; + } + } + + if ($checked == TRUE) + { + $defaults['checked'] = 'checked'; + } + else + { + unset($defaults['checked']); + } + + return '\n"; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_radio')) +{ + /** + * Radio Button + * + * @param mixed + * @param string + * @param bool + * @param mixed + * @return string + */ + function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') + { + is_array($data) OR $data = array('name' => $data); + $data['type'] = 'radio'; + + return form_checkbox($data, $value, $checked, $extra); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_submit')) +{ + /** + * Submit Button + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_submit($data = '', $value = '', $extra = '') + { + $defaults = array( + 'type' => 'submit', + 'name' => is_array($data) ? '' : $data, + 'value' => $value + ); + + return '\n"; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_reset')) +{ + /** + * Reset Button + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_reset($data = '', $value = '', $extra = '') + { + $defaults = array( + 'type' => 'reset', + 'name' => is_array($data) ? '' : $data, + 'value' => $value + ); + + return '\n"; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_button')) +{ + /** + * Form Button + * + * @param mixed + * @param string + * @param mixed + * @return string + */ + function form_button($data = '', $content = '', $extra = '') + { + $defaults = array( + 'name' => is_array($data) ? '' : $data, + 'type' => 'button' + ); + + if (is_array($data) && isset($data['content'])) + { + $content = $data['content']; + unset($data['content']); // content is not an attribute + } + + return '\n"; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_label')) +{ + /** + * Form Label Tag + * + * @param string The text to appear onscreen + * @param string The id the label applies to + * @param mixed Additional attributes + * @return string + */ + function form_label($label_text = '', $id = '', $attributes = array()) + { + + $label = ''.$label_text.''; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_fieldset')) +{ + /** + * Fieldset Tag + * + * Used to produce
    text. To close fieldset + * use form_fieldset_close() + * + * @param string The legend text + * @param array Additional attributes + * @return string + */ + function form_fieldset($legend_text = '', $attributes = array()) + { + $fieldset = '\n"; + if ($legend_text !== '') + { + return $fieldset.''.$legend_text."\n"; + } + + return $fieldset; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_fieldset_close')) +{ + /** + * Fieldset Close Tag + * + * @param string + * @return string + */ + function form_fieldset_close($extra = '') + { + return '
    '.$extra; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_close')) +{ + /** + * Form Close Tag + * + * @param string + * @return string + */ + function form_close($extra = '') + { + return ''.$extra; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('form_prep')) +{ + /** + * Form Prep + * + * Formats text so that it can be safely placed in a form field in the event it has HTML tags. + * + * @deprecated 3.0.0 An alias for html_escape() + * @param string|string[] $str Value to escape + * @return string|string[] Escaped values + */ + function form_prep($str) + { + return html_escape($str, TRUE); + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('set_value')) +{ + /** + * Form Value + * + * Grabs a value from the POST array for the specified field so you can + * re-populate an input field or textarea. If Form Validation + * is active it retrieves the info from the validation class + * + * @param string $field Field name + * @param string $default Default value + * @param bool $html_escape Whether to escape HTML special characters or not + * @return string + */ + function set_value($field, $default = '', $html_escape = TRUE) + { + $CI =& get_instance(); + + $value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) + ? $CI->form_validation->set_value($field, $default) + : $CI->input->post($field, FALSE); + + isset($value) OR $value = $default; + return ($html_escape) ? html_escape($value) : $value; + } +} + +// ------------------------------------------------------------------------ + +if ( ! function_exists('set_select')) +{ + /** + * Set Select + * + * Let's you set the selected value of a