diff --git a/.gitignore b/.gitignore index 599468937..b27451708 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .htaccess +bin /nbproject/ /vendor/* !/vendor/FHC-vendor diff --git a/application/cache/index.html b/application/cache/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/cache/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/application/config/autoload.php b/application/config/autoload.php new file mode 100755 index 000000000..817617a9b --- /dev/null +++ b/application/config/autoload.php @@ -0,0 +1,131 @@ + 'ua'); +*/ +//$autoload['libraries'] = array(); +$autoload['libraries'] = array('database'); + +/* +| ------------------------------------------------------------------- +| Auto-load Drivers +| ------------------------------------------------------------------- +| These classes are located in system/libraries/ or in your +| application/libraries/ directory, but are also placed inside their +| own subdirectory and they extend the CI_Driver_Library class. They +| offer multiple interchangeable driver options. +| +| Prototype: +| +| $autoload['drivers'] = array('cache'); +*/ +$autoload['drivers'] = array(); + +/* +| ------------------------------------------------------------------- +| Auto-load Helper Files +| ------------------------------------------------------------------- +| Prototype: +| +| $autoload['helper'] = array('url', 'file'); +*/ +//$autoload['helper'] = array(); +$autoload['helper'] = array('url'); + +/* +| ------------------------------------------------------------------- +| Auto-load Config files +| ------------------------------------------------------------------- +| Prototype: +| +| $autoload['config'] = array('config1', 'config2'); +| +| NOTE: This item is intended for use ONLY if you have created custom +| config files. Otherwise, leave it blank. +| +*/ +$autoload['config'] = array(); + +/* +| ------------------------------------------------------------------- +| Auto-load Language files +| ------------------------------------------------------------------- +| Prototype: +| +| $autoload['language'] = array('lang1', 'lang2'); +| +| NOTE: Do not include the "_lang" part of your file. For example +| "codeigniter_lang.php" would be referenced as array('codeigniter'); +| +*/ +$autoload['language'] = array(); + +/* +| ------------------------------------------------------------------- +| Auto-load Models +| ------------------------------------------------------------------- +| Prototype: +| +| $autoload['model'] = array('first_model', 'second_model'); +| +| You can also supply an alternative model name to be assigned +| in the controller: +| +| $autoload['model'] = array('first_model' => 'first'); +*/ +$autoload['model'] = array(); diff --git a/application/config/config.php b/application/config/config.php new file mode 100755 index 000000000..fba741d58 --- /dev/null +++ b/application/config/config.php @@ -0,0 +1,504 @@ +]+$/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'] = 0; + +/* +|-------------------------------------------------------------------------- +| Error Logging Directory Path +|-------------------------------------------------------------------------- +| +| Leave this BLANK unless you would like to set something other than the default +| application/logs/ directory. Use a full server path with trailing slash. +| +*/ +$config['log_path'] = ''; + +/* +|-------------------------------------------------------------------------- +| Log File Extension +|-------------------------------------------------------------------------- +| +| The default filename extension for log files. The default 'php' allows for +| protecting the log files via basic scripting, when they are to be stored +| under a publicly accessible directory. +| +| Note: Leaving it blank will default to 'php'. +| +*/ +$config['log_file_extension'] = ''; + +/* +|-------------------------------------------------------------------------- +| Log File Permissions +|-------------------------------------------------------------------------- +| +| The file system permissions to be applied on newly created log files. +| +| IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal +| integer notation (i.e. 0700, 0644, etc.) +*/ +$config['log_file_permissions'] = 0644; + +/* +|-------------------------------------------------------------------------- +| Date Format for Logs +|-------------------------------------------------------------------------- +| +| Each item that is logged has an associated date. You can use PHP date +| codes to set your own date formatting +| +*/ +$config['log_date_format'] = 'Y-m-d H:i:s'; + +/* +|-------------------------------------------------------------------------- +| Error Views Directory Path +|-------------------------------------------------------------------------- +| +| Leave this BLANK unless you would like to set something other than the default +| application/views/errors/ directory. Use a full server path with trailing slash. +| +*/ +$config['error_views_path'] = ''; + +/* +|-------------------------------------------------------------------------- +| Cache Directory Path +|-------------------------------------------------------------------------- +| +| Leave this BLANK unless you would like to set something other than the default +| application/cache/ directory. Use a full server path with trailing slash. +| +*/ +$config['cache_path'] = ''; + +/* +|-------------------------------------------------------------------------- +| Cache Include Query String +|-------------------------------------------------------------------------- +| +| Whether to take the URL query string into consideration when generating +| output cache files. Valid options are: +| +| FALSE = Disabled +| TRUE = Enabled, take all query parameters into account. +| Please be aware that this may result in numerous cache +| files generated for the same page over and over again. +| array('q') = Enabled, but only take into account the specified list +| of query parameters. +| +*/ +$config['cache_query_string'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Encryption Key +|-------------------------------------------------------------------------- +| +| If you use the Encryption class, you must set an encryption key. +| See the user guide for more info. +| +| http://codeigniter.com/user_guide/libraries/encryption.html +| +*/ +$config['encryption_key'] = ''; + +/* +|-------------------------------------------------------------------------- +| Session Variables +|-------------------------------------------------------------------------- +| +| 'sess_driver' +| +| The storage driver to use: files, database, redis, memcached +| +| 'sess_cookie_name' +| +| The session cookie name, must contain only [0-9a-z_-] characters +| +| 'sess_expiration' +| +| The number of SECONDS you want the session to last. +| Setting to 0 (zero) means expire when the browser is closed. +| +| 'sess_save_path' +| +| The location to save sessions to, driver dependent. +| +| For the 'files' driver, it's a path to a writable directory. +| WARNING: Only absolute paths are supported! +| +| For the 'database' driver, it's a table name. +| Please read up the manual for the format with other session drivers. +| +| IMPORTANT: You are REQUIRED to set a valid save path! +| +| 'sess_match_ip' +| +| Whether to match the user's IP address when reading the session data. +| +| 'sess_time_to_update' +| +| How many seconds between CI regenerating the session ID. +| +| 'sess_regenerate_destroy' +| +| Whether to destroy session data associated with the old session ID +| when auto-regenerating the session ID. When set to FALSE, the data +| will be later deleted by the garbage collector. +| +| Other session cookie settings are shared with the rest of the application, +| except for 'cookie_prefix' and 'cookie_httponly', which are ignored here. +| +*/ +$config['sess_driver'] = 'files'; +$config['sess_cookie_name'] = 'ci_session'; +$config['sess_expiration'] = 7200; +$config['sess_save_path'] = NULL; +$config['sess_match_ip'] = FALSE; +$config['sess_time_to_update'] = 300; +$config['sess_regenerate_destroy'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Cookie Related Variables +|-------------------------------------------------------------------------- +| +| 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions +| 'cookie_domain' = Set to .your-domain.com for site-wide cookies +| 'cookie_path' = Typically will be a forward slash +| 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists. +| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript) +| +| Note: These settings (with the exception of 'cookie_prefix' and +| 'cookie_httponly') will also affect sessions. +| +*/ +$config['cookie_prefix'] = ''; +$config['cookie_domain'] = ''; +$config['cookie_path'] = '/'; +$config['cookie_secure'] = FALSE; +$config['cookie_httponly'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Standardize newlines +|-------------------------------------------------------------------------- +| +| Determines whether to standardize newline characters in input data, +| meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value. +| +| 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 100755 index 000000000..48283e223 --- /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( + 'dsn' => '', + 'hostname' => DB_HOST, + 'username' => DB_USER, + 'password' => DB_PASSWORD, + 'database' => DB_NAME, + 'dbdriver' => 'postgre', + 'dbprefix' => '', + 'pconnect' => DB_CONNECT_PERSISTENT, + 'db_debug' => (ENVIRONMENT !== 'production'), + 'cache_on' => FALSE, + 'cachedir' => '', + 'char_set' => 'utf8', + 'dbcollat' => 'utf8_general_ci', + 'swap_pre' => '', + 'encrypt' => FALSE, + 'compress' => FALSE, + 'stricton' => FALSE, + 'failover' => array(), + 'save_queries' => TRUE +); + +$db['wawi'] = array( + 'dsn' => '', + 'hostname' => DB_HOST, + 'username' => DB_USER, + 'password' => DB_PASSWORD, + 'database' => DB_NAME, + 'dbschema' => 'wawi', + 'dbdriver' => 'postgre', + 'dbprefix' => '', + 'pconnect' => DB_CONNECT_PERSISTENT, + 'db_debug' => (ENVIRONMENT !== 'production'), + '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 100755 index 000000000..59a7991e3 --- /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 100755 index 000000000..ac406e3d4 --- /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/grocery_crud.php b/application/config/grocery_crud.php new file mode 100644 index 000000000..57caddd15 --- /dev/null +++ b/application/config/grocery_crud.php @@ -0,0 +1,35 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/application/config/memcached.php b/application/config/memcached.php new file mode 100755 index 000000000..55949a66c --- /dev/null +++ b/application/config/memcached.php @@ -0,0 +1,19 @@ + 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 100755 index 000000000..840fa7a40 --- /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'] = 20160101010103; + +/* +|-------------------------------------------------------------------------- +| Migration Type +|-------------------------------------------------------------------------- +| +| Migration file names may be based on a sequential identifier or on +| a timestamp. Options are: +| +| 'sequential' = Sequential migration naming (001_add_blog.php) +| 'timestamp' = Timestamp migration naming (20121031104401_add_blog.php) +| Use timestamp format YYYYMMDDHHIISS. +| +| Note: If this configuration value is missing the Migration library +| defaults to 'sequential' for backward compatibility with CI2. +| +*/ +$config['migration_type'] = 'timestamp'; + +/* +|-------------------------------------------------------------------------- +| Migrations table +|-------------------------------------------------------------------------- +| +| This is the name of the table that will store the current migrations state. +| When migrations runs it will store in a database table which migration +| level the system is at. It then compares the migration level in this +| table to the $config['migration_version'] if they are not the same it +| will migrate up. This must be set. +| +*/ +$config['migration_table'] = 'ci_migrations'; + +/* +|-------------------------------------------------------------------------- +| Auto Migrate To Latest +|-------------------------------------------------------------------------- +| +| If this is set to TRUE when you load the migrations class and have +| $config['migration_enabled'] set to TRUE the system will auto migrate +| to your latest migration (whatever $config['migration_version'] is +| set to). This way you do not have to call migrations anywhere else +| in your code to have the latest migration. +| +*/ +$config['migration_auto_latest'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Migrations 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 100755 index 000000000..1f591ba6b --- /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 000000000..229036a0f --- /dev/null +++ b/application/config/pagination.php @@ -0,0 +1,37 @@ +'; + +$config['first_link'] = 'First'; +$config['first_tag_open'] = '
  • '; +$config['first_tag_close'] = '
  • '; + +$config['last_link'] = 'Last'; +$config['last_tag_open'] = '
  • '; +$config['last_tag_close'] = '
  • '; + +$config['next_link'] = 'Next'; +$config['next_tag_open'] = '
  • '; +$config['next_tag_close'] = '
  • '; + +$config['prev_link'] = 'Prev'; +$config['prev_tag_open'] = '
  • '; +$config['prev_tag_close'] = '
  • '; + +$config['cur_tag_open'] = '
  • '; +$config['cur_tag_close'] = '
  • '; + +$config['num_tag_open'] = '
  • '; +$config['num_tag_close'] = '
  • '; + + +/* End of file pagination.php */ +/* Location: ./application/config/pagination.php */ diff --git a/application/config/profiler.php b/application/config/profiler.php new file mode 100755 index 000000000..b30204e16 --- /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 a 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. +| +| e.g: +| +| $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'; + +/* +|-------------------------------------------------------------------------- +| Override auth types for specfic 'class/method/HTTP method' +|-------------------------------------------------------------------------- +| +| example: +| +| $config['auth_override_class_method_http']['deals']['view']['get'] = 'none'; +| $config['auth_override_class_method_http']['deals']['insert']['post'] = 'none'; +| $config['auth_override_class_method_http']['deals']['*']['options'] = 'none'; +*/ + +// ---Uncomment list line for the wildard unit test +// $config['auth_override_class_method_http']['wildcard_test_cases']['*']['options'] = 'basic'; + +/* +|-------------------------------------------------------------------------- +| REST Login Usernames +|-------------------------------------------------------------------------- +| +| Array of usernames and passwords for login, if ldap is configured this is ignored +| +*/ +$config['rest_valid_logins'] = ['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 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 with a comma separated +| list of IP addresses +| +| e.g: '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 the REST server from blacklisted IP addresses +| +| Usage: +| 1. Set to TRUE and add any IP address to 'rest_ip_blacklist' +| +*/ +$config['rest_ip_blacklist_enabled'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| REST IP Blacklist +|-------------------------------------------------------------------------- +| +| Prevent connections from the following IP addresses +| +| e.g: '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 +| +*/ +$config['rest_database_group'] = 'default'; + +/* +|-------------------------------------------------------------------------- +| REST API Keys Table Name +|-------------------------------------------------------------------------- +| +| The table name in your database that stores API keys +| +*/ +$config['rest_keys_table'] = 'ci_apikey'; + +/* +|-------------------------------------------------------------------------- +| REST Enable Keys +|-------------------------------------------------------------------------- +| +| When set to TRUE, the REST API will look for a column name called 'key'. +| If no key is provided, the request will result in an error. To override the +| column name see 'rest_key_column' +| +| Default table schema: +| 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'] = TRUE; + +/* +|-------------------------------------------------------------------------- +| REST Table Key Column Name +|-------------------------------------------------------------------------- +| +| If not using the default table schema in 'rest_enable_keys', specify the +| column name to match e.g. my_key +| +*/ +$config['rest_key_column'] = 'key'; + +/* +|-------------------------------------------------------------------------- +| REST API Limits method +|-------------------------------------------------------------------------- +| +| Specify the method used to limit the API calls +| +| Available methods are : +| $config['rest_limits_method'] = 'API_KEY'; // Put a limit per api key +| $config['rest_limits_method'] = 'METHOD_NAME'; // Put a limit on method calls +| $config['rest_limits_method'] = 'ROUTED_URL'; // Put a limit on the routed URL +| +*/ +$config['rest_limits_method'] = 'ROUTED_URL'; + +/* +|-------------------------------------------------------------------------- +| REST Key Length +|-------------------------------------------------------------------------- +| +| Length of the created keys. Check your default database schema on the +| maximum length allowed +| +| Note: The maximum length is 40 +| +*/ +$config['rest_key_length'] = 40; + +/* +|-------------------------------------------------------------------------- +| REST API Key Variable +|-------------------------------------------------------------------------- +| +| Custom header to specify the API key + +| Note: Custom headers with the X- prefix are deprecated as of +| 2012/06/12. See RFC 6648 specification for more details +| +*/ +$config['rest_key_name'] = 'WSP-API-KEY'; + +/* +|-------------------------------------------------------------------------- +| REST Enable Logging +|-------------------------------------------------------------------------- +| +| When set to TRUE, the REST API will log actions based on the column names 'key', 'date', +| 'time' and 'ip_address'. This is a general rule that can be overridden in the +| $this->method array for each controller +| +| Default table schema: +| 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` VARCHAR(1) NOT NULL, +| `response_code` smallint(3) DEFAULT '0', +| PRIMARY KEY (`id`) +| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +| +*/ +$config['rest_enable_logging'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| REST API Logs Table Name +|-------------------------------------------------------------------------- +| +| If not using the default table schema in 'rest_enable_logging', specify the +| table name to match e.g. my_logs +| +*/ +$config['rest_logs_table'] = 'logs'; + +/* +|-------------------------------------------------------------------------- +| REST Method Access Control +|-------------------------------------------------------------------------- +| When set to TRUE, the REST API will check the access table to see if +| the API key can access that controller. 'rest_enable_keys' must be enabled +| to use this +| +| Default table schema: +| 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 Access Table Name +|-------------------------------------------------------------------------- +| +| If not using the default table schema in 'rest_enable_access', specify the +| table name to match e.g. my_access +| +*/ +$config['rest_access_table'] = 'access'; + +/* +|-------------------------------------------------------------------------- +| REST API Param Log Format +|-------------------------------------------------------------------------- +| +| When set to TRUE, the REST API log parameters will be stored in the database as JSON +| Set to FALSE to log as serialized PHP +| +*/ +$config['rest_logs_json_params'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| REST Enable Limits +|-------------------------------------------------------------------------- +| +| When set to TRUE, the REST API 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 +| +| Default table schema: +| 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 the limits within the controller's __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 API Limits Table Name +|-------------------------------------------------------------------------- +| +| If not using the default table schema in 'rest_enable_limits', specify the +| table name to match e.g. my_limits +| +*/ +$config['rest_limits_table'] = 'limits'; + +/* +|-------------------------------------------------------------------------- +| 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 +| +*/ +$config['rest_ignore_http_accept'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| REST AJAX Only +|-------------------------------------------------------------------------- +| +| Set to TRUE to allow AJAX requests only. Set to FALSE to accept HTTP requests +| +| Note: If set to TRUE and the request is not AJAX, a 505 response with the +| error message 'Only AJAX requests are accepted.' will be returned. +| +| Hint: This is good for production environments +| +*/ +$config['rest_ajax_only'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| REST Language File +|-------------------------------------------------------------------------- +| +| Language file to load from the language directory +| +*/ +$config['rest_language'] = 'english'; diff --git a/application/config/routes.php b/application/config/routes.php new file mode 100755 index 000000000..d76591bb8 --- /dev/null +++ b/application/config/routes.php @@ -0,0 +1,56 @@ + my_controller/index +| my-controller/my-method -> my_controller/my_method +*/ +$route['person/(:any)'] = 'person/view/$1'; +$route['person'] = 'person'; +$route['default_controller'] = 'welcome'; +$route['404_override'] = ''; +$route['translate_uri_dashes'] = FALSE; diff --git a/application/config/smileys.php b/application/config/smileys.php new file mode 100755 index 000000000..1eeba4776 --- /dev/null +++ b/application/config/smileys.php @@ -0,0 +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', '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 100755 index 000000000..1129dbacd --- /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/application/controllers/Examples.php b/application/controllers/Examples.php new file mode 100644 index 000000000..da0d6353c --- /dev/null +++ b/application/controllers/Examples.php @@ -0,0 +1,248 @@ +load->database(); + $this->load->helper('url'); + + $this->load->library('grocery_CRUD'); + } + + public function _example_output($output = null) + { + $this->load->view('example.php',$output); + } + + public function offices() + { + $output = $this->grocery_crud->render(); + + $this->_example_output($output); + } + + public function index() + { + $this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array())); + } + + public function offices_management() + { + try{ + $crud = new grocery_CRUD(); + + $crud->set_theme('datatables'); + $crud->set_table('offices'); + $crud->set_subject('Office'); + $crud->required_fields('city'); + $crud->columns('city','country','phone','addressLine1','postalCode'); + + $output = $crud->render(); + + $this->_example_output($output); + + }catch(Exception $e){ + show_error($e->getMessage().' --- '.$e->getTraceAsString()); + } + } + + public function employees_management() + { + $crud = new grocery_CRUD(); + + $crud->set_theme('datatables'); + $crud->set_table('employees'); + $crud->set_relation('officeCode','offices','city'); + $crud->display_as('officeCode','Office City'); + $crud->set_subject('Employee'); + + $crud->required_fields('lastName'); + + $crud->set_field_upload('file_url','assets/uploads/files'); + + $output = $crud->render(); + + $this->_example_output($output); + } + + public function customers_management() + { + $crud = new grocery_CRUD(); + + $crud->set_table('customers'); + $crud->columns('customerName','contactLastName','phone','city','country','salesRepEmployeeNumber','creditLimit'); + $crud->display_as('salesRepEmployeeNumber','from Employeer') + ->display_as('customerName','Name') + ->display_as('contactLastName','Last Name'); + $crud->set_subject('Customer'); + $crud->set_relation('salesRepEmployeeNumber','employees','lastName'); + + $output = $crud->render(); + + $this->_example_output($output); + } + + public function orders_management() + { + $crud = new grocery_CRUD(); + + $crud->set_relation('customerNumber','customers','{contactLastName} {contactFirstName}'); + $crud->display_as('customerNumber','Customer'); + $crud->set_table('orders'); + $crud->set_subject('Order'); + $crud->unset_add(); + $crud->unset_delete(); + + $output = $crud->render(); + + $this->_example_output($output); + } + + public function products_management() + { + $crud = new grocery_CRUD(); + + $crud->set_table('products'); + $crud->set_subject('Product'); + $crud->unset_columns('productDescription'); + $crud->callback_column('buyPrice',array($this,'valueToEuro')); + + $output = $crud->render(); + + $this->_example_output($output); + } + + public function valueToEuro($value, $row) + { + return $value.' €'; + } + + public function film_management() + { + $crud = new grocery_CRUD(); + + $crud->set_table('film'); + $crud->set_relation_n_n('actors', 'film_actor', 'actor', 'film_id', 'actor_id', 'fullname','priority'); + $crud->set_relation_n_n('category', 'film_category', 'category', 'film_id', 'category_id', 'name'); + $crud->unset_columns('special_features','description','actors'); + + $crud->fields('title', 'description', 'actors' , 'category' ,'release_year', 'rental_duration', 'rental_rate', 'length', 'replacement_cost', 'rating', 'special_features'); + + $output = $crud->render(); + + $this->_example_output($output); + } + + public function film_management_twitter_bootstrap() + { + try{ + $crud = new grocery_CRUD(); + + $crud->set_theme('twitter-bootstrap'); + $crud->set_table('film'); + $crud->set_relation_n_n('actors', 'film_actor', 'actor', 'film_id', 'actor_id', 'fullname','priority'); + $crud->set_relation_n_n('category', 'film_category', 'category', 'film_id', 'category_id', 'name'); + $crud->unset_columns('special_features','description','actors'); + + $crud->fields('title', 'description', 'actors' , 'category' ,'release_year', 'rental_duration', 'rental_rate', 'length', 'replacement_cost', 'rating', 'special_features'); + + $output = $crud->render(); + $this->_example_output($output); + + }catch(Exception $e){ + show_error($e->getMessage().' --- '.$e->getTraceAsString()); + } + } + + function multigrids() + { + $this->config->load('grocery_crud'); + $this->config->set_item('grocery_crud_dialog_forms',true); + $this->config->set_item('grocery_crud_default_per_page',10); + + $output1 = $this->offices_management2(); + + $output2 = $this->employees_management2(); + + $output3 = $this->customers_management2(); + + $js_files = $output1->js_files + $output2->js_files + $output3->js_files; + $css_files = $output1->css_files + $output2->css_files + $output3->css_files; + $output = "

    List 1

    ".$output1->output."

    List 2

    ".$output2->output."

    List 3

    ".$output3->output; + + $this->_example_output((object)array( + 'js_files' => $js_files, + 'css_files' => $css_files, + 'output' => $output + )); + } + + public function offices_management2() + { + $crud = new grocery_CRUD(); + $crud->set_table('offices'); + $crud->set_subject('Office'); + + $crud->set_crud_url_path(site_url(strtolower(__CLASS__."/".__FUNCTION__)),site_url(strtolower(__CLASS__."/multigrids"))); + + $output = $crud->render(); + + if($crud->getState() != 'list') { + $this->_example_output($output); + } else { + return $output; + } + } + + public function employees_management2() + { + $crud = new grocery_CRUD(); + + $crud->set_theme('datatables'); + $crud->set_table('employees'); + $crud->set_relation('officeCode','offices','city'); + $crud->display_as('officeCode','Office City'); + $crud->set_subject('Employee'); + + $crud->required_fields('lastName'); + + $crud->set_field_upload('file_url','assets/uploads/files'); + + $crud->set_crud_url_path(site_url(strtolower(__CLASS__."/".__FUNCTION__)),site_url(strtolower(__CLASS__."/multigrids"))); + + $output = $crud->render(); + + if($crud->getState() != 'list') { + $this->_example_output($output); + } else { + return $output; + } + } + + public function customers_management2() + { + $crud = new grocery_CRUD(); + + $crud->set_table('customers'); + $crud->columns('customerName','contactLastName','phone','city','country','salesRepEmployeeNumber','creditLimit'); + $crud->display_as('salesRepEmployeeNumber','from Employeer') + ->display_as('customerName','Name') + ->display_as('contactLastName','Last Name'); + $crud->set_subject('Customer'); + $crud->set_relation('salesRepEmployeeNumber','employees','lastName'); + + $crud->set_crud_url_path(site_url(strtolower(__CLASS__."/".__FUNCTION__)),site_url(strtolower(__CLASS__."/multigrids"))); + + $output = $crud->render(); + + if($crud->getState() != 'list') { + $this->_example_output($output); + } else { + return $output; + } + } + +} \ No newline at end of file diff --git a/application/controllers/Main.php b/application/controllers/Main.php new file mode 100755 index 000000000..c4e0461cd --- /dev/null +++ b/application/controllers/Main.php @@ -0,0 +1,45 @@ +load->database(); + $this->load->helper('url'); + /* ------------------ */ + + $this->load->library('grocery_CRUD'); + + } + + public function index() + { + echo "

    Welcome to the world of Codeigniter

    ";//Just an example to ensure that we get into the function + die(); + } + + public function prestudent() + { + $this->grocery_crud->set_table('tbl_prestudent'); + $output = $this->grocery_crud->render(); + + echo "
    ";
    +        print_r($output);
    +        echo "
    "; + die(); + + $this->_example_output($output); + } + + function _example_output($output = null) + + { + $this->load->view('our_template.php',$output); + } +} + +/* End of file main.php */ +/* Location: ./application/controllers/main.php */ diff --git a/application/controllers/Migrate.php b/application/controllers/Migrate.php new file mode 100644 index 000000000..b29fd6f65 --- /dev/null +++ b/application/controllers/Migrate.php @@ -0,0 +1,16 @@ +load->library('migration'); + + if ($this->migration->current() === FALSE) + { + show_error($this->migration->error_string()); + } + } + +} diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php new file mode 100755 index 000000000..3fade84dd --- /dev/null +++ b/application/controllers/Pages.php @@ -0,0 +1,7 @@ +load->model('person_model'); + } + + public function index() + { + $data['person'] = $this->person_model->get_personen(); + $data['title'] = 'Personen Archiv'; + + $this->load->view('templates/header', $data); + $this->load->view('person/index', $data); + $this->load->view('templates/footer'); + } + + public function view($slug = NULL) + { + $data['person_item'] = $this->person_model->get_personen($slug); + if (empty($data['person_item'])) + { + show_404(); + } + + $data['title'] = $data['person_item']->titelpre; + + $this->load->view('templates/header', $data); + $this->load->view('person/view', $data); + $this->load->view('templates/footer'); + } +} diff --git a/application/controllers/Rest_server.php b/application/controllers/Rest_server.php new file mode 100644 index 000000000..698bca3bd --- /dev/null +++ b/application/controllers/Rest_server.php @@ -0,0 +1,40 @@ + ZipComp: First Compute Request +* ZipCmd <-- ZipComp: First Compute Response +* +* ZipCmd -> ZipComp: Second Compute Request +* ZipCmd <-- ZipComp: Second Compute Response +* +* @enduml +* --> +* +* @return some value on success. +*/ + +defined('BASEPATH') OR exit('No direct script access allowed'); + +/** + * @class Rest_server + * @brief Rest Server Controller + * + * A more detailed class description. +*/ +class Rest_server extends CI_Controller { + + public function index() + { + $this->load->helper('url'); + + $this->load->view('rest_server'); + } +} diff --git a/application/controllers/Studiengang.php b/application/controllers/Studiengang.php new file mode 100644 index 000000000..e4a4765c0 --- /dev/null +++ b/application/controllers/Studiengang.php @@ -0,0 +1,167 @@ +load->model('studiengang_model'); + $this->load->library('form_validation'); + } + + public function index() + { + $keyword = ''; + $this->load->library('pagination'); + + $config['base_url'] = base_url() . 'studiengang/index/'; + $config['total_rows'] = $this->studiengang_model->total_rows(); + $config['per_page'] = 10; + $config['uri_segment'] = 3; + $config['suffix'] = '.html'; + $config['first_url'] = base_url() . 'studiengang.html'; + $this->pagination->initialize($config); + + $start = $this->uri->segment(3, 0); + $studiengang = $this->studiengang_model->index_limit($config['per_page'], $start); + + $data = array( + 'studiengang_data' => $studiengang, + 'keyword' => $keyword, + 'pagination' => $this->pagination->create_links(), + 'total_rows' => $config['total_rows'], + 'start' => $start, + ); + + $this->load->view('tbl_studiengang_list', $data); + } + + public function search() + { + $keyword = $this->uri->segment(3, $this->input->post('keyword', TRUE)); + $this->load->library('pagination'); + + if ($this->uri->segment(2)=='search') { + $config['base_url'] = base_url() . 'studiengang/search/' . $keyword; + } else { + $config['base_url'] = base_url() . 'studiengang/index/'; + } + + $config['total_rows'] = $this->studiengang_model->search_total_rows($keyword); + $config['per_page'] = 10; + $config['uri_segment'] = 4; + $config['suffix'] = '.html'; + $config['first_url'] = base_url() . 'studiengang/search/'.$keyword.'.html'; + $this->pagination->initialize($config); + + $start = $this->uri->segment(4, 0); + $studiengang = $this->studiengang_model->search_index_limit($config['per_page'], $start, $keyword); + + $data = array( + 'studiengang_data' => $studiengang, + 'keyword' => $keyword, + 'pagination' => $this->pagination->create_links(), + 'total_rows' => $config['total_rows'], + 'start' => $start, + ); + $this->load->view('tbl_studiengang_list', $data); + } + + public function read($id) + { + $row = $this->studiengang_model->get_by_id($id); + if ($row) { + $data = array( + ); + $this->load->view('tbl_studiengang_read', $data); + } else { + $this->session->set_flashdata('message', 'Record Not Found'); + redirect(site_url('studiengang')); + } + } + + public function create() + { + $data = array( + 'button' => 'Create', + 'action' => site_url('studiengang/create_action'), + ); + $this->load->view('tbl_studiengang_form', $data); + } + + public function create_action() + { + $this->_rules(); + + if ($this->form_validation->run() == FALSE) { + $this->create(); + } else { + $data = array( + ); + + $this->studiengang_model->insert($data); + $this->session->set_flashdata('message', 'Create Record Success'); + redirect(site_url('studiengang')); + } + } + + public function update($id) + { + $row = $this->studiengang_model->get_by_id($id); + + if ($row) { + $data = array( + 'button' => 'Update', + 'action' => site_url('studiengang/update_action'), + ); + $this->load->view('tbl_studiengang_form', $data); + } else { + $this->session->set_flashdata('message', 'Record Not Found'); + redirect(site_url('studiengang')); + } + } + + public function update_action() + { + $this->_rules(); + + if ($this->form_validation->run() == FALSE) { + $this->update($this->input->post('', TRUE)); + } else { + $data = array( + ); + + $this->studiengang_model->update($this->input->post('', TRUE), $data); + $this->session->set_flashdata('message', 'Update Record Success'); + redirect(site_url('studiengang')); + } + } + + public function delete($id) + { + $row = $this->studiengang_model->get_by_id($id); + + if ($row) { + $this->studiengang_model->delete($id); + $this->session->set_flashdata('message', 'Delete Record Success'); + redirect(site_url('studiengang')); + } else { + $this->session->set_flashdata('message', 'Record Not Found'); + redirect(site_url('studiengang')); + } + } + + public function _rules() + { + + $this->form_validation->set_rules('', '', 'trim'); + $this->form_validation->set_error_delimiters('', ''); + } + +}; + +/* End of file Studiengang.php */ +/* Location: ./application/controllers/Studiengang.php */ \ No newline at end of file diff --git a/application/controllers/Welcome.php b/application/controllers/Welcome.php new file mode 100755 index 000000000..34535ef05 --- /dev/null +++ b/application/controllers/Welcome.php @@ -0,0 +1,25 @@ + + * @see http://codeigniter.com/user_guide/general/urls.html + */ + public function index() + { + $this->load->view('welcome_message'); + } +} diff --git a/application/controllers/index.html b/application/controllers/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/controllers/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/controllers/rdf/Basic.php b/application/controllers/rdf/Basic.php new file mode 100644 index 000000000..b6fc1a32d --- /dev/null +++ b/application/controllers/rdf/Basic.php @@ -0,0 +1,66 @@ +load->library(array('rdf')); + $this->load->helper(array('form', 'url')); + + } + public function index() + { + + $this->load->library('Rdf'); + + $d['title'] = ''; + + + $d['content']= $this->load->view('rdf/basic',$d,true); + $this->load->view('home',$d); + } + public function sparql() + { + + $this->load->library('Rdf'); + + $d['title'] = ''; + + + $d['content']= $this->load->view('rdf/basic_sparql',$d,true); + $this->load->view('home',$d); + } + public function foafinfo() + { + + $this->load->library('Rdf'); + + + + $d['title'] = ''; + + + $d['content']= $this->load->view('rdf/foafinfo',$d,true); + $this->load->view('home',$d); + } + public function foafmaker() + { + + $d['title'] = ''; + + + $d['content']= $this->load->view('rdf/foafmaker',$d,true); + $this->load->view('home',$d); + } + public function converter() + { + + $d['title'] = ''; + + $d['content']= $this->load->view('rdf/converter',$d,true); + $this->load->view('home',$d); + } +} diff --git a/application/core/index.html b/application/core/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/core/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/helpers/index.html b/application/helpers/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/helpers/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/hooks/index.html b/application/hooks/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/hooks/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/index.html b/application/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/language/english/index.html b/application/language/english/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/language/english/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/language/index.html b/application/language/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/language/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/libraries/Grocery_CRUD.php b/application/libraries/Grocery_CRUD.php new file mode 100755 index 000000000..53df38ed8 --- /dev/null +++ b/application/libraries/Grocery_CRUD.php @@ -0,0 +1,5585 @@ + + */ + +// ------------------------------------------------------------------------ + +/** + * grocery Field Types + * + * The types of the fields and the default reactions + * + * @package grocery CRUD + * @author John Skoumbourdis + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt + * @link http://www.grocerycrud.com/documentation + */ +class grocery_CRUD_Field_Types +{ + /** + * Gets the field types of the main table. + * @return array + */ + public function get_field_types() + { + if ($this->field_types !== null) { + return $this->field_types; + } + + $types = array(); + foreach($this->basic_model->get_field_types_basic_table() as $field_info) + { + $field_info->required = !empty($this->required_fields) && in_array($field_info->name,$this->required_fields) ? true : false; + + $field_info->display_as = + isset($this->display_as[$field_info->name]) ? + $this->display_as[$field_info->name] : + ucfirst(str_replace("_"," ",$field_info->name)); + + if($this->change_field_type !== null && isset($this->change_field_type[$field_info->name])) + { + $field_type = $this->change_field_type[$field_info->name]; + + if (isset($this->relation[$field_info->name])) { + $field_info->crud_type = "relation_".$field_type->type; + } + elseif (isset($this->upload_fields[$field_info->name])) { + $field_info->crud_type = "upload_file_".$field_type->type; + } else { + $field_info->crud_type = $field_type->type; + $field_info->extras = $field_type->extras; + } + + $real_type = $field_info->crud_type; + } + elseif(isset($this->relation[$field_info->name])) + { + $real_type = 'relation'; + $field_info->crud_type = 'relation'; + } + elseif(isset($this->upload_fields[$field_info->name])) + { + $real_type = 'upload_file'; + $field_info->crud_type = 'upload_file'; + } + else + { + $real_type = $this->get_type($field_info); + $field_info->crud_type = $real_type; + } + + switch ($real_type) { + case 'text': + if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) + $field_info->extras = false; + else + $field_info->extras = 'text_editor'; + break; + + case 'relation': + case 'relation_readonly': + $field_info->extras = $this->relation[$field_info->name]; + break; + + case 'upload_file': + case 'upload_file_readonly': + $field_info->extras = $this->upload_fields[$field_info->name]; + break; + + default: + if(empty($field_info->extras)) + $field_info->extras = false; + break; + } + + $types[$field_info->name] = $field_info; + } + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_extras) + { + $is_read_only = $this->change_field_type !== null + && isset($this->change_field_type[$field_name]) + && $this->change_field_type[$field_name]->type == 'readonly' + ? true : false; + $field_info = (object)array(); + $field_info->name = $field_name; + $field_info->crud_type = $is_read_only ? 'readonly' : 'relation_n_n'; + $field_info->extras = $field_extras; + $field_info->required = !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false;; + $field_info->display_as = + isset($this->display_as[$field_name]) ? + $this->display_as[$field_name] : + ucfirst(str_replace("_"," ",$field_name)); + + $types[$field_name] = $field_info; + } + } + + if(!empty($this->add_fields)) + foreach($this->add_fields as $field_object) + { + $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; + + if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD + { + $extras = false; + if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) + { + $field_type = $this->change_field_type[$field_name]; + $extras = $field_type->extras; + } + + $field_info = (object)array( + 'name' => $field_name, + 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? + $this->change_field_type[$field_name]->type : + 'string', + 'display_as' => isset($this->display_as[$field_name]) ? + $this->display_as[$field_name] : + ucfirst(str_replace("_"," ",$field_name)), + 'required' => !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false, + 'extras' => $extras + ); + + $types[$field_name] = $field_info; + } + } + + if(!empty($this->edit_fields)) + foreach($this->edit_fields as $field_object) + { + $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; + + if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD + { + $extras = false; + if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) + { + $field_type = $this->change_field_type[$field_name]; + $extras = $field_type->extras; + } + + $field_info = (object)array( + 'name' => $field_name, + 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? + $this->change_field_type[$field_name]->type : + 'string', + 'display_as' => isset($this->display_as[$field_name]) ? + $this->display_as[$field_name] : + ucfirst(str_replace("_"," ",$field_name)), + 'required' => in_array($field_name,$this->required_fields) ? true : false, + 'extras' => $extras + ); + + $types[$field_name] = $field_info; + } + } + + $this->field_types = $types; + + return $this->field_types; + } + + public function get_primary_key() + { + return $this->basic_model->get_primary_key(); + } + + /** + * Get the html input for the specific field with the + * current value + * + * @param object $field_info + * @param string $value + * @return object + */ + protected function get_field_input($field_info, $value = null) + { + $real_type = $field_info->crud_type; + + $types_array = array( + 'integer', + 'text', + 'true_false', + 'string', + 'date', + 'datetime', + 'enum', + 'set', + 'relation', + 'relation_readonly', + 'relation_n_n', + 'upload_file', + 'upload_file_readonly', + 'hidden', + 'password', + 'readonly', + 'dropdown', + 'multiselect' + ); + + if (in_array($real_type,$types_array)) { + /* A quick way to go to an internal method of type $this->get_{type}_input . + * For example if the real type is integer then we will use the method + * $this->get_integer_input + * */ + $field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value); + } + else + { + $field_info->input = $this->get_string_input($field_info,$value); + } + + return $field_info; + } + + protected function change_list_value($field_info, $value = null) + { + $real_type = $field_info->crud_type; + + switch ($real_type) { + case 'hidden': + case 'invisible': + case 'integer': + + break; + case 'true_false': + if(is_array($field_info->extras) && array_key_exists($value,$field_info->extras)) { + $value = $field_info->extras[$value]; + } else if(isset($this->default_true_false_text[$value])) { + $value = $this->default_true_false_text[$value]; + } + break; + case 'string': + $value = $this->character_limiter($value,$this->character_limiter,"..."); + break; + case 'text': + $value = $this->character_limiter(strip_tags($value),$this->character_limiter,"..."); + break; + case 'date': + if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') + { + list($year,$month,$day) = explode("-",$value); + + $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); + } + else + { + $value = ''; + } + break; + case 'datetime': + if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') + { + list($year,$month,$day) = explode("-",$value); + list($hours,$minutes) = explode(":",substr($value,11)); + + $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); + } + else + { + $value = ''; + } + break; + case 'enum': + $value = $this->character_limiter($value,$this->character_limiter,"..."); + break; + + case 'multiselect': + $value_as_array = array(); + foreach(explode(",",$value) as $row_value) + { + $value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value; + } + $value = implode(",",$value_as_array); + break; + + case 'relation_n_n': + $value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"..."); + break; + + case 'password': + $value = '******'; + break; + + case 'dropdown': + $value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; + break; + + case 'upload_file': + if(empty($value)) + { + $value = ""; + } + else + { + $is_image = !empty($value) && + ( substr($value,-4) == '.jpg' + || substr($value,-4) == '.png' + || substr($value,-5) == '.jpeg' + || substr($value,-4) == '.gif' + || substr($value,-5) == '.tiff') + ? true : false; + + $file_url = base_url().$field_info->extras->upload_path."/$value"; + + $file_url_anchor = ''; + } + else + { + $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); + } + $file_url_anchor .= ''; + + $value = $file_url_anchor; + } + break; + + default: + $value = $this->character_limiter($value,$this->character_limiter,"..."); + break; + } + + return $value; + } + + /** + * Character Limiter of codeigniter (I just don't want to load the helper ) + * + * Limits the string based on the character count. Preserves complete words + * so the character count may not be exactly as specified. + * + * @access public + * @param string + * @param integer + * @param string the end character. Usually an ellipsis + * @return string + */ + function character_limiter($str, $n = 500, $end_char = '…') + { + if (strlen($str) < $n) + { + return $str; + } + + // a bit complicated, but faster than preg_replace with \s+ + $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); + + if (strlen($str) <= $n) + { + return $str; + } + + $out = ''; + foreach (explode(' ', trim($str)) as $val) + { + $out .= $val.' '; + + if (strlen($out) >= $n) + { + $out = trim($out); + return (strlen($out) === strlen($str)) ? $out : $out.$end_char; + } + } + } + + protected function get_type($db_type) + { + $type = false; + if(!empty($db_type->type)) + { + switch ($db_type->type) { + case '1': + case '3': + case 'int': + case 'tinyint': + case 'mediumint': + case 'longint': + if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) + $type = 'true_false'; + else + $type = 'integer'; + break; + case '254': + case 'string': + case 'enum': + if($db_type->db_type != 'enum') + $type = 'string'; + else + $type = 'enum'; + break; + case 'set': + if($db_type->db_type != 'set') + $type = 'string'; + else + $type = 'set'; + break; + case '252': + case 'blob': + case 'text': + case 'mediumtext': + case 'longtext': + $type = 'text'; + break; + case '10': + case 'date': + $type = 'date'; + break; + case '12': + case 'datetime': + case 'timestamp': + $type = 'datetime'; + break; + } + } + return $type; + } +} + +// ------------------------------------------------------------------------ + +/** + * Grocery Model Driver + * + * Drives the model - I'ts so easy like you drive a bicycle :-) + * + * @package grocery CRUD + * @author John Skoumbourdis + * @version 1.5.2 + * @link http://www.grocerycrud.com/documentation + */ +class grocery_CRUD_Model_Driver extends grocery_CRUD_Field_Types +{ + /** + * @var grocery_CRUD_Model + */ + public $basic_model = null; + + protected function set_default_Model() + { + $ci = &get_instance(); + $ci->load->model('grocery_CRUD_Model'); + + $this->basic_model = new grocery_CRUD_Model(); + } + + protected function get_total_results() + { + if(!empty($this->where)) + foreach($this->where as $where) + $this->basic_model->where($where[0],$where[1],$where[2]); + + if(!empty($this->or_where)) + foreach($this->or_where as $or_where) + $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); + + if(!empty($this->like)) + foreach($this->like as $like) + $this->basic_model->like($like[0],$like[1],$like[2]); + + if(!empty($this->or_like)) + foreach($this->or_like as $or_like) + $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); + + if(!empty($this->having)) + foreach($this->having as $having) + $this->basic_model->having($having[0],$having[1],$having[2]); + + if(!empty($this->or_having)) + foreach($this->or_having as $or_having) + $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); + + if(!empty($this->relation)) + foreach($this->relation as $relation) + $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); + + if(!empty($this->relation_n_n)) + { + $columns = $this->get_columns(); + foreach($columns as $column) + { + //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. + if(isset($this->relation_n_n[$column->field_name])) + { + $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); + } + } + + } + + return $this->basic_model->get_total_results(); + } + + public function set_model($model_name) + { + $ci = &get_instance(); + $ci->load->model('grocery_CRUD_Model'); + + $ci->load->model($model_name); + + $temp = explode('/',$model_name); + krsort($temp); + foreach($temp as $t) + { + $real_model_name = $t; + break; + } + + $this->basic_model = $ci->$real_model_name; + } + + protected function set_ajax_list_queries($state_info = null) + { + if(!empty($state_info->per_page)) + { + if(empty($state_info->page) || !is_numeric($state_info->page) ) + $this->limit($state_info->per_page); + else + { + $limit_page = ( ($state_info->page-1) * $state_info->per_page ); + $this->limit($state_info->per_page, $limit_page); + } + } + + if(!empty($state_info->order_by)) + { + $this->order_by($state_info->order_by[0],$state_info->order_by[1]); + } + + if(!empty($state_info->search)) + { + if (!empty($this->relation)) { + foreach ($this->relation as $relation_name => $relation_values) { + $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values); + } + } + + if (is_array($state_info->search)) { + foreach ($state_info->search as $search_field => $search_text) { + + + if (isset($temp_relation[$search_field])) { + if (is_array($temp_relation[$search_field])) { + foreach ($temp_relation[$search_field] as $relation_field) { + $this->or_like($relation_field , $search_text); + } + } else { + $this->like($temp_relation[$search_field] , $search_text); + } + } elseif(isset($this->relation_n_n[$search_field])) { + $escaped_text = $this->basic_model->escape_str($search_text); + $this->having($search_field." LIKE '%".$escaped_text."%'"); + } else { + $this->like($search_field, $search_text); + } + + + + } + } elseif ($state_info->search->field !== null) { + if (isset($temp_relation[$state_info->search->field])) { + if (is_array($temp_relation[$state_info->search->field])) { + foreach ($temp_relation[$state_info->search->field] as $search_field) { + $this->or_like($search_field , $state_info->search->text); + } + } else { + $this->like($temp_relation[$state_info->search->field] , $state_info->search->text); + } + } elseif(isset($this->relation_n_n[$state_info->search->field])) { + $escaped_text = $this->basic_model->escape_str($state_info->search->text); + $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); + } else { + $this->like($state_info->search->field , $state_info->search->text); + } + } + else + { + $columns = $this->get_columns(); + + $search_text = $state_info->search->text; + + if(!empty($this->where)) + foreach($this->where as $where) + $this->basic_model->having($where[0],$where[1],$where[2]); + + foreach($columns as $column) + { + if(isset($temp_relation[$column->field_name])) + { + if(is_array($temp_relation[$column->field_name])) + { + foreach($temp_relation[$column->field_name] as $search_field) + { + $this->or_like($search_field, $search_text); + } + } + else + { + $this->or_like($temp_relation[$column->field_name], $search_text); + } + } + elseif(isset($this->relation_n_n[$column->field_name])) + { + //@todo have a where for the relation_n_n statement + } + else + { + $this->or_like($column->field_name, $search_text); + } + } + } + } + } + + protected function table_exists($table_name = null) + { + if($this->basic_model->db_table_exists($table_name)) + return true; + return false; + } + + protected function get_relation_array($relation_info, $primary_key_value = null, $limit = null) + { + list($field_name , $related_table , $related_field_title, $where_clause, $order_by) = $relation_info; + + if($primary_key_value !== null) + { + $primary_key = $this->basic_model->get_primary_key($related_table); + + //A where clause with the primary key is enough to take the selected key row + $where_clause = array($primary_key => $primary_key_value); + } + + $relation_array = $this->basic_model->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit); + + return $relation_array; + } + + protected function get_relation_total_rows($relation_info) + { + list($field_name , $related_table , $related_field_title, $where_clause) = $relation_info; + + $relation_array = $this->basic_model->get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause); + + return $relation_array; + } + + protected function db_insert_validation() + { + $validation_result = (object)array('success'=>false); + + $field_types = $this->get_field_types(); + $required_fields = $this->required_fields; + $unique_fields = $this->_unique_fields; + $add_fields = $this->get_add_fields(); + + if(!empty($required_fields)) + { + foreach($add_fields as $add_field) + { + $field_name = $add_field->field_name; + if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) + { + $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); + } + } + } + + /** Checking for unique fields. If the field value is not unique then + * return a validation error straight away, if not continue... */ + if(!empty($unique_fields)) + { + $form_validation = $this->form_validation(); + + foreach($add_fields as $add_field) + { + $field_name = $add_field->field_name; + if(in_array( $field_name, $unique_fields) ) + { + $form_validation->set_rules( $field_name, + $field_types[$field_name]->display_as, + 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); + } + } + + if(!$form_validation->run()) + { + $validation_result->error_message = $form_validation->error_string(); + $validation_result->error_fields = $form_validation->_error_array; + + return $validation_result; + } + } + + if(!empty($this->validation_rules)) + { + $form_validation = $this->form_validation(); + + $add_fields = $this->get_add_fields(); + + foreach($add_fields as $add_field) + { + $field_name = $add_field->field_name; + if(isset($this->validation_rules[$field_name])) + { + $rule = $this->validation_rules[$field_name]; + $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); + } + } + + if($form_validation->run()) + { + $validation_result->success = true; + } + else + { + $validation_result->error_message = $form_validation->error_string(); + $validation_result->error_fields = $form_validation->_error_array; + } + } + else + { + $validation_result->success = true; + } + + return $validation_result; + } + + protected function form_validation() + { + if($this->form_validation === null) + { + $this->form_validation = new grocery_CRUD_Form_validation(); + $ci = &get_instance(); + $ci->load->library('form_validation'); + $ci->form_validation = $this->form_validation; + } + return $this->form_validation; + } + + protected function db_update_validation() + { + $validation_result = (object)array('success'=>false); + + $field_types = $this->get_field_types(); + $required_fields = $this->required_fields; + $unique_fields = $this->_unique_fields; + $edit_fields = $this->get_edit_fields(); + + if(!empty($required_fields)) + { + foreach($edit_fields as $edit_field) + { + $field_name = $edit_field->field_name; + if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) + { + $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); + } + } + } + + + /** Checking for unique fields. If the field value is not unique then + * return a validation error straight away, if not continue... */ + if(!empty($unique_fields)) + { + $form_validation = $this->form_validation(); + + $form_validation_check = false; + + foreach($edit_fields as $edit_field) + { + $field_name = $edit_field->field_name; + if(in_array( $field_name, $unique_fields) ) + { + $state_info = $this->getStateInfo(); + $primary_key = $this->get_primary_key(); + $field_name_value = $_POST[$field_name]; + + $this->basic_model->where($primary_key,$state_info->primary_key); + $row = $this->basic_model->get_row(); + + if(!isset($row->$field_name)) { + throw new Exception("The field name doesn't exist in the database. ". + "Please use the unique fields only for fields ". + "that exist in the database"); + } + + $previous_field_name_value = $row->$field_name; + + if(!empty($previous_field_name_value) && $previous_field_name_value != $field_name_value) { + $form_validation->set_rules( $field_name, + $field_types[$field_name]->display_as, + 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); + + $form_validation_check = true; + } + } + } + + if($form_validation_check && !$form_validation->run()) + { + $validation_result->error_message = $form_validation->error_string(); + $validation_result->error_fields = $form_validation->_error_array; + + return $validation_result; + } + } + + if(!empty($this->validation_rules)) + { + $form_validation = $this->form_validation(); + + $edit_fields = $this->get_edit_fields(); + + foreach($edit_fields as $edit_field) + { + $field_name = $edit_field->field_name; + if(isset($this->validation_rules[$field_name])) + { + $rule = $this->validation_rules[$field_name]; + $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); + } + } + + if($form_validation->run()) + { + $validation_result->success = true; + } + else + { + $validation_result->error_message = $form_validation->error_string(); + $validation_result->error_fields = $form_validation->_error_array; + } + } + else + { + $validation_result->success = true; + } + + return $validation_result; + } + + protected function db_insert($state_info) + { + $validation_result = $this->db_insert_validation(); + + if($validation_result->success) + { + $post_data = $state_info->unwrapped_data; + + $add_fields = $this->get_add_fields(); + + if($this->callback_insert === null) + { + if($this->callback_before_insert !== null) + { + $callback_return = call_user_func($this->callback_before_insert, $post_data); + + if(!empty($callback_return) && is_array($callback_return)) + $post_data = $callback_return; + elseif($callback_return === false) + return false; + } + + $insert_data = array(); + $types = $this->get_field_types(); + foreach($add_fields as $num_row => $field) + { + /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ + if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) + { + $post_data[$field->field_name] = array(); + } + + if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) + { + if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) + { + $insert_data[$field->field_name] = null; + } + elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') + { + $insert_data[$field->field_name] = null; + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') + { + $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') + { + //This empty if statement is to make sure that a readonly field will never inserted/updated + } + elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) + { + $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ + $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). + substr($post_data[$field->field_name],10); + } + else + { + $insert_data[$field->field_name] = $post_data[$field->field_name]; + } + } + } + + $insert_result = $this->basic_model->db_insert($insert_data); + + if($insert_result !== false) + { + $insert_primary_key = $insert_result; + } + else + { + return false; + } + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_info) + { + $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; + $this->db_relation_n_n_update($field_info, $relation_data ,$insert_primary_key); + } + } + + if($this->callback_after_insert !== null) + { + $callback_return = call_user_func($this->callback_after_insert, $post_data, $insert_primary_key); + + if($callback_return === false) + { + return false; + } + + } + }else + { + $callback_return = call_user_func($this->callback_insert, $post_data); + + if($callback_return === false) + { + return false; + } + } + + if(isset($insert_primary_key)) + return $insert_primary_key; + else + return true; + } + + return false; + + } + + protected function db_update($state_info) + { + $validation_result = $this->db_update_validation(); + + $edit_fields = $this->get_edit_fields(); + + if($validation_result->success) + { + $post_data = $state_info->unwrapped_data; + $primary_key = $state_info->primary_key; + + if($this->callback_update === null) + { + if($this->callback_before_update !== null) + { + $callback_return = call_user_func($this->callback_before_update, $post_data, $primary_key); + + if(!empty($callback_return) && is_array($callback_return)) + { + $post_data = $callback_return; + } + elseif($callback_return === false) + { + return false; + } + + } + + $update_data = array(); + $types = $this->get_field_types(); + foreach($edit_fields as $num_row => $field) + { + /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ + if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) + { + $post_data[$field->field_name] = array(); + } + + if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) + { + if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) + { + $update_data[$field->field_name] = null; + } + elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') + { + $update_data[$field->field_name] = null; + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') + { + $update_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') + { + //This empty if statement is to make sure that a readonly field will never inserted/updated + } + elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) + { + $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; + } + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ + $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). + substr($post_data[$field->field_name],10); + } + else + { + $update_data[$field->field_name] = $post_data[$field->field_name]; + } + } + } + + if($this->basic_model->db_update($update_data, $primary_key) === false) + { + return false; + } + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_info) + { + if ( $this->unset_edit_fields !== null + && is_array($this->unset_edit_fields) + && in_array($field_name,$this->unset_edit_fields) + ) { + continue; + } + + $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; + $this->db_relation_n_n_update($field_info, $relation_data ,$primary_key); + } + } + + if($this->callback_after_update !== null) + { + $callback_return = call_user_func($this->callback_after_update, $post_data, $primary_key); + + if($callback_return === false) + { + return false; + } + + } + } + else + { + $callback_return = call_user_func($this->callback_update, $post_data, $primary_key); + + if($callback_return === false) + { + return false; + } + } + + return true; + } + else + { + return false; + } + } + + protected function _convert_date_to_sql_date($date) + { + $date = substr($date,0,10); + if(preg_match('/\d{4}-\d{2}-\d{2}/',$date)) + { + //If it's already a sql-date don't convert it! + return $date; + }elseif(empty($date)) + { + return ''; + } + + $date_array = preg_split( '/[-\.\/ ]/', $date); + if($this->php_date_format == 'd/m/Y') + { + $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2])); + } + elseif($this->php_date_format == 'm/d/Y') + { + $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2])); + } + else + { + $sql_date = $date; + } + + return $sql_date; + } + + protected function _get_field_names_to_search(array $relation_values) + { + if(!strstr($relation_values[2],'{')) + return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; + else + { + $relation_values[2] = ' '.$relation_values[2].' '; + $temp1 = explode('{',$relation_values[2]); + unset($temp1[0]); + + $field_names_array = array(); + foreach($temp1 as $field) + list($field_names_array[]) = explode('}',$field); + + return $field_names_array; + } + } + + protected function _unique_join_name($field_name) + { + return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not a number + } + + protected function _unique_field_name($field_name) + { + return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not a number + } + + protected function db_multiple_delete($state_info) + { + foreach ($state_info->ids as $delete_id) { + $result = $this->db_delete((object)array('primary_key' => $delete_id)); + if (!$result) { + return false; + } + } + + return true; + } + + protected function db_delete($state_info) + { + $primary_key_value = $state_info->primary_key; + + if($this->callback_delete === null) + { + if($this->callback_before_delete !== null) + { + $callback_return = call_user_func($this->callback_before_delete, $primary_key_value); + + if($callback_return === false) + { + return false; + } + + } + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_info) + { + $this->db_relation_n_n_delete( $field_info, $primary_key_value ); + } + } + + $delete_result = $this->basic_model->db_delete($primary_key_value); + + if($delete_result === false) + { + return false; + } + + if($this->callback_after_delete !== null) + { + $callback_return = call_user_func($this->callback_after_delete, $primary_key_value); + + if($callback_return === false) + { + return false; + } + + } + } + else + { + $callback_return = call_user_func($this->callback_delete, $primary_key_value); + + if($callback_return === false) + { + return false; + } + } + + return true; + } + + protected function db_relation_n_n_update($field_info, $post_data , $primary_key_value) + { + $this->basic_model->db_relation_n_n_update($field_info, $post_data , $primary_key_value); + } + + protected function db_relation_n_n_delete($field_info, $primary_key_value) + { + $this->basic_model->db_relation_n_n_delete($field_info, $primary_key_value); + } + + protected function get_list() + { + if(!empty($this->order_by)) + $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); + + if(!empty($this->where)) + foreach($this->where as $where) + $this->basic_model->where($where[0],$where[1],$where[2]); + + if(!empty($this->or_where)) + foreach($this->or_where as $or_where) + $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); + + if(!empty($this->like)) + foreach($this->like as $like) + $this->basic_model->like($like[0],$like[1],$like[2]); + + if(!empty($this->or_like)) + foreach($this->or_like as $or_like) + $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); + + if(!empty($this->having)) + foreach($this->having as $having) + $this->basic_model->having($having[0],$having[1],$having[2]); + + if(!empty($this->or_having)) + foreach($this->or_having as $or_having) + $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); + + if(!empty($this->relation)) + foreach($this->relation as $relation) + $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); + + if(!empty($this->relation_n_n)) + { + $columns = $this->get_columns(); + foreach($columns as $column) + { + //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. + if(isset($this->relation_n_n[$column->field_name])) + { + $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); + } + } + + } + + if($this->theme_config['crud_paging'] === true) + { + if($this->limit === null) + { + $default_per_page = $this->config->default_per_page; + if(is_numeric($default_per_page) && $default_per_page >1) + { + $this->basic_model->limit($default_per_page); + } + else + { + $this->basic_model->limit(10); + } + } + else + { + $this->basic_model->limit($this->limit[0],$this->limit[1]); + } + } + + $results = $this->basic_model->get_list(); + + return $results; + } + + protected function get_edit_values($primary_key_value) + { + $values = $this->basic_model->get_edit_values($primary_key_value); + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_info) + { + $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); + } + } + + return $values; + } + + protected function get_relation_n_n_selection_array($primary_key_value, $field_info) + { + return $this->basic_model->get_relation_n_n_selection_array($primary_key_value, $field_info); + } + + protected function get_relation_n_n_unselected_array($field_info, $selected_values) + { + return $this->basic_model->get_relation_n_n_unselected_array($field_info, $selected_values); + } + + protected function set_basic_db_table($table_name = null) + { + $this->basic_model->set_basic_table($table_name); + } + + protected function upload_file($state_info) + { + if(isset($this->upload_fields[$state_info->field_name]) ) + { + if($this->callback_upload === null) + { + if($this->callback_before_upload !== null) + { + $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); + + if($callback_before_upload_response === false) + return false; + elseif(is_string($callback_before_upload_response)) + return $callback_before_upload_response; + } + + $upload_info = $this->upload_fields[$state_info->field_name]; + + header('Pragma: no-cache'); + header('Cache-Control: private, no-cache'); + header('Content-Disposition: inline; filename="files.json"'); + header('X-Content-Type-Options: nosniff'); + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); + header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); + + $allowed_files = $this->config->file_upload_allow_file_types; + + $reg_exp = ''; + if(!empty($upload_info->allowed_file_types)){ + $reg_exp = '/(\\.|\\/)('.$upload_info->allowed_file_types.')$/i'; + }else{ + $reg_exp = '/(\\.|\\/)('.$allowed_files.')$/i'; + } + + $max_file_size_ui = $this->config->file_upload_max_file_size; + $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); + + $options = array( + 'upload_dir' => $upload_info->upload_path.'/', + 'param_name' => $this->_unique_field_name($state_info->field_name), + 'upload_url' => base_url().$upload_info->upload_path.'/', + 'accept_file_types' => $reg_exp, + 'max_file_size' => $max_file_size_bytes + ); + $upload_handler = new UploadHandler($options); + $upload_handler->default_config_path = $this->default_config_path; + $uploader_response = $upload_handler->post(); + + if(is_array($uploader_response)) + { + foreach($uploader_response as &$response) + { + unset($response->delete_url); + unset($response->delete_type); + } + } + + if($this->callback_after_upload !== null) + { + $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response , $this->upload_fields[$state_info->field_name] , $_FILES ); + + if($callback_after_upload_response === false) + return false; + elseif(is_string($callback_after_upload_response)) + return $callback_after_upload_response; + elseif(is_array($callback_after_upload_response)) + $uploader_response = $callback_after_upload_response; + } + + return $uploader_response; + } + else + { + $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name] ); + + if($upload_response === false) + { + return false; + } + else + { + return $upload_response; + } + } + } + else + { + return false; + } + } + + protected function delete_file($state_info) + { + + if(isset($state_info->field_name) && isset($this->upload_fields[$state_info->field_name])) + { + $upload_info = $this->upload_fields[$state_info->field_name]; + + if(file_exists("{$upload_info->upload_path}/{$state_info->file_name}")) + { + if( unlink("{$upload_info->upload_path}/{$state_info->file_name}") ) + { + $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); + + return true; + } + else + { + return false; + } + } + else + { + $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); + return true; + } + } + else + { + return false; + } + } + + protected function ajax_relation($state_info) + { + if(!isset($this->relation[$state_info->field_name])) + return false; + + list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; + + return $this->basic_model->get_ajax_relation_array($state_info->search, $field_name, $related_table, $related_field_title, $where_clause, $order_by); + } +} + + +/** + * PHP grocery CRUD + * + * LICENSE + * + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. + * Please see the corresponding license file for details of these licenses. + * You are free to use, modify and distribute this software, but all copyright information must remain. + * + * @package grocery CRUD + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt + * @author John Skoumbourdis + */ + +// ------------------------------------------------------------------------ + +/** + * PHP grocery Layout + * + * Here you manage all the HTML Layout + * + * @package grocery CRUD + * @author John Skoumbourdis + * @version 1.5.2 + */ +class grocery_CRUD_Layout extends grocery_CRUD_Model_Driver +{ + private $theme_path = null; + private $views_as_string = ''; + private $echo_and_die = false; + protected $theme = null; + protected $default_true_false_text = array('inactive' , 'active'); + + protected $css_files = array(); + protected $js_files = array(); + protected $js_lib_files = array(); + protected $js_config_files = array(); + + protected function set_basic_Layout() + { + if(!file_exists($this->theme_path.$this->theme.'/views/list_template.php')) + { + throw new Exception('The template does not exist. Please check your files and try again.', 12); + die(); + } + } + + protected function showList($ajax = false, $state_info = null) + { + $data = $this->get_common_data(); + + $data->order_by = $this->order_by; + + $data->types = $this->get_field_types(); + + $data->list = $this->get_list(); + $data->list = $this->change_list($data->list , $data->types); + $data->list = $this->change_list_add_actions($data->list); + + $data->total_results = $this->get_total_results(); + + $data->columns = $this->get_columns(); + + $data->success_message = $this->get_success_message_at_list($state_info); + + $data->primary_key = $this->get_primary_key(); + $data->add_url = $this->getAddUrl(); + $data->edit_url = $this->getEditUrl(); + $data->delete_url = $this->getDeleteUrl(); + $data->delete_multiple_url = $this->getDeleteMultipleUrl(); + $data->read_url = $this->getReadUrl(); + $data->ajax_list_url = $this->getAjaxListUrl(); + $data->ajax_list_info_url = $this->getAjaxListInfoUrl(); + $data->export_url = $this->getExportToExcelUrl(); + $data->print_url = $this->getPrintUrl(); + $data->actions = $this->actions; + $data->unique_hash = $this->get_method_hash(); + $data->order_by = $this->order_by; + + $data->unset_add = $this->unset_add; + $data->unset_edit = $this->unset_edit; + $data->unset_read = $this->unset_read; + $data->unset_delete = $this->unset_delete; + $data->unset_export = $this->unset_export; + $data->unset_print = $this->unset_print; + + $default_per_page = $this->config->default_per_page; + $data->paging_options = $this->config->paging_options; + $data->default_per_page = is_numeric($default_per_page) && $default_per_page >1 && in_array($default_per_page,$data->paging_options)? $default_per_page : 25; + + if($data->list === false) + { + throw new Exception('It is impossible to get data. Please check your model and try again.', 13); + $data->list = array(); + } + + foreach($data->list as $num_row => $row) + { + $data->list[$num_row]->primary_key_value = $row->{$data->primary_key}; + $data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key}; + $data->list[$num_row]->delete_url = $data->delete_url.'/'.$row->{$data->primary_key}; + $data->list[$num_row]->read_url = $data->read_url.'/'.$row->{$data->primary_key}; + } + + if(!$ajax) + { + $this->_add_js_vars(array('dialog_forms' => $this->config->dialog_forms)); + + $data->list_view = $this->_theme_view('list.php',$data,true); + $this->_theme_view('list_template.php',$data); + } + else + { + $this->set_echo_and_die(); + $this->_theme_view('list.php',$data); + } + } + + protected function exportToExcel($state_info = null) + { + $data = $this->get_common_data(); + + $data->order_by = $this->order_by; + $data->types = $this->get_field_types(); + + $data->list = $this->get_list(); + $data->list = $this->change_list($data->list , $data->types); + $data->list = $this->change_list_add_actions($data->list); + + $data->total_results = $this->get_total_results(); + + $data->columns = $this->get_columns(); + $data->primary_key = $this->get_primary_key(); + + @ob_end_clean(); + $this->_export_to_excel($data); + } + + protected function _export_to_excel($data) + { + /** + * No need to use an external library here. The only bad thing without using external library is that Microsoft Excel is complaining + * that the file is in a different format than specified by the file extension. If you press "Yes" everything will be just fine. + * */ + + $string_to_export = ""; + foreach($data->columns as $column){ + $string_to_export .= $column->display_as."\t"; + } + $string_to_export .= "\n"; + + foreach($data->list as $num_row => $row){ + foreach($data->columns as $column){ + $string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t"; + } + $string_to_export .= "\n"; + } + + // Convert to UTF-16LE and Prepend BOM + $string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8'); + + $filename = "export-".date("Y-m-d_H:i:s").".xls"; + + header('Content-type: application/vnd.ms-excel;charset=UTF-16LE'); + header('Content-Disposition: attachment; filename='.$filename); + header("Cache-Control: no-cache"); + echo $string_to_export; + die(); + } + + protected function print_webpage($state_info = null) + { + $data = $this->get_common_data(); + + $data->order_by = $this->order_by; + $data->types = $this->get_field_types(); + + $data->list = $this->get_list(); + $data->list = $this->change_list($data->list , $data->types); + $data->list = $this->change_list_add_actions($data->list); + + $data->total_results = $this->get_total_results(); + + $data->columns = $this->get_columns(); + $data->primary_key = $this->get_primary_key(); + + @ob_end_clean(); + $this->_print_webpage($data); + } + + protected function _print_webpage($data) + { + $string_to_print = ""; + $string_to_print .= ""; + + echo $string_to_print; + die(); + } + + protected function _trim_export_string($value) + { + $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); + return strip_tags(str_replace(array("\t","\n","\r"),"",$value)); + } + + protected function _trim_print_string($value) + { + $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); + + //If the value has only spaces and nothing more then add the whitespace html character + if(str_replace(" ","",$value) == "") + $value = " "; + + return strip_tags($value); + } + + protected function set_echo_and_die() + { + $this->echo_and_die = true; + } + + protected function unset_echo_and_die() + { + $this->echo_and_die = false; + } + + protected function showListInfo() + { + $this->set_echo_and_die(); + + $total_results = (int)$this->get_total_results(); + @ob_end_clean(); + echo json_encode(array('total_results' => $total_results)); + die(); + } + + protected function change_list_add_actions($list) + { + if(empty($this->actions)) + return $list; + + $primary_key = $this->get_primary_key(); + + foreach($list as $num_row => $row) + { + $actions_urls = array(); + foreach($this->actions as $unique_id => $action) + { + if(!empty($action->url_callback)) + { + $actions_urls[$unique_id] = call_user_func($action->url_callback, $row->$primary_key, $row); + } + else + { + $actions_urls[$unique_id] = + $action->url_has_http ? + $action->link_url.$row->$primary_key : + site_url($action->link_url.'/'.$row->$primary_key); + } + } + $row->action_urls = $actions_urls; + } + + return $list; + } + + protected function change_list($list,$types) + { + $primary_key = $this->get_primary_key(); + $has_callbacks = !empty($this->callback_column) ? true : false; + $output_columns = $this->get_columns(); + foreach($list as $num_row => $row) + { + foreach($output_columns as $column) + { + $field_name = $column->field_name; + $field_value = isset( $row->{$column->field_name} ) ? $row->{$column->field_name} : null; + if( $has_callbacks && isset($this->callback_column[$field_name]) ) + $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); + elseif(isset($types[$field_name])) + $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); + else + $list[$num_row]->$field_name = $field_value; + } + } + + return $list; + } + + protected function showAddForm() + { + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); + + $data = $this->get_common_data(); + $data->types = $this->get_field_types(); + + $data->list_url = $this->getListUrl(); + $data->insert_url = $this->getInsertUrl(); + $data->validation_url = $this->getValidationInsertUrl(); + $data->input_fields = $this->get_add_input_fields(); + + $data->fields = $this->get_add_fields(); + $data->hidden_fields = $this->get_add_hidden_fields(); + $data->unset_back_to_list = $this->unset_back_to_list; + $data->unique_hash = $this->get_method_hash(); + $data->is_ajax = $this->_is_ajax(); + + $this->_theme_view('add.php',$data); + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); + + $this->_get_ajax_results(); + } + + protected function showEditForm($state_info) + { + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); + + $data = $this->get_common_data(); + $data->types = $this->get_field_types(); + + $data->field_values = $this->get_edit_values($state_info->primary_key); + + $data->add_url = $this->getAddUrl(); + + $data->list_url = $this->getListUrl(); + $data->update_url = $this->getUpdateUrl($state_info); + $data->delete_url = $this->getDeleteUrl($state_info); + $data->read_url = $this->getReadUrl($state_info->primary_key); + $data->input_fields = $this->get_edit_input_fields($data->field_values); + $data->unique_hash = $this->get_method_hash(); + + $data->fields = $this->get_edit_fields(); + $data->hidden_fields = $this->get_edit_hidden_fields(); + $data->unset_back_to_list = $this->unset_back_to_list; + + $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); + $data->is_ajax = $this->_is_ajax(); + + $this->_theme_view('edit.php',$data); + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); + + $this->_get_ajax_results(); + } + + protected function showReadForm($state_info) + { + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); + + $data = $this->get_common_data(); + $data->types = $this->get_field_types(); + + $data->field_values = $this->get_edit_values($state_info->primary_key); + + $data->add_url = $this->getAddUrl(); + + $data->list_url = $this->getListUrl(); + $data->update_url = $this->getUpdateUrl($state_info); + $data->delete_url = $this->getDeleteUrl($state_info); + $data->read_url = $this->getReadUrl($state_info->primary_key); + $data->input_fields = $this->get_read_input_fields($data->field_values); + $data->unique_hash = $this->get_method_hash(); + + $data->fields = $this->get_read_fields(); + $data->hidden_fields = $this->get_edit_hidden_fields(); + $data->unset_back_to_list = $this->unset_back_to_list; + + $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); + $data->is_ajax = $this->_is_ajax(); + + $this->_theme_view('read.php',$data); + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); + + $this->_get_ajax_results(); + } + + protected function delete_layout($delete_result = true) + { + @ob_end_clean(); + if($delete_result === false) + { + $error_message = '

    '.$this->l('delete_error_message').'

    '; + + echo json_encode(array('success' => $delete_result ,'error_message' => $error_message)); + } + else + { + $success_message = '

    '.$this->l('delete_success_message').'

    '; + + echo json_encode(array('success' => true , 'success_message' => $success_message)); + } + $this->set_echo_and_die(); + } + + protected function get_success_message_at_list($field_info = null) + { + if($field_info !== null && isset($field_info->success_message) && $field_info->success_message) + { + if(!empty($field_info->primary_key) && !$this->unset_edit) + { + return $this->l('insert_success_message')." ".$this->l('form_edit')." {$this->subject} "; + } + else + { + return $this->l('insert_success_message'); + } + } + else + { + return null; + } + } + + protected function insert_layout($insert_result = false) + { + @ob_end_clean(); + if($insert_result === false) + { + echo json_encode(array('success' => false)); + } + else + { + $success_message = '

    '.$this->l('insert_success_message'); + + if(!$this->unset_back_to_list && !empty($insert_result) && !$this->unset_edit) + { + $success_message .= " ".$this->l('form_edit')." {$this->subject} "; + + if (!$this->_is_ajax()) { + $success_message .= $this->l('form_or'); + } + } + + if(!$this->unset_back_to_list && !$this->_is_ajax()) + { + $success_message .= " ".$this->l('form_go_back_to_list').""; + } + + $success_message .= '

    '; + + echo json_encode(array( + 'success' => true , + 'insert_primary_key' => $insert_result, + 'success_message' => $success_message, + 'success_list_url' => $this->getListSuccessUrl($insert_result) + )); + } + $this->set_echo_and_die(); + } + + protected function validation_layout($validation_result) + { + @ob_end_clean(); + echo json_encode($validation_result); + $this->set_echo_and_die(); + } + + protected function upload_layout($upload_result, $field_name) + { + @ob_end_clean(); + if($upload_result !== false && !is_string($upload_result) && empty($upload_result[0]->error)) + { + echo json_encode( + (object)array( + 'success' => true, + 'files' => $upload_result + )); + } + else + { + $result = (object)array('success' => false); + if(is_string($upload_result)) + $result->message = $upload_result; + if(!empty($upload_result[0]->error)) + $result->message = $upload_result[0]->error; + + echo json_encode($result); + } + + $this->set_echo_and_die(); + } + + protected function delete_file_layout($upload_result) + { + @ob_end_clean(); + if($upload_result !== false) + { + echo json_encode( (object)array( 'success' => true ) ); + } + else + { + echo json_encode((object)array('success' => false)); + } + + $this->set_echo_and_die(); + } + + public function set_css($css_file) + { + $this->css_files[sha1($css_file)] = base_url().$css_file; + } + + public function set_js($js_file) + { + $this->js_files[sha1($js_file)] = base_url().$js_file; + } + + public function set_js_lib($js_file) + { + $this->js_lib_files[sha1($js_file)] = base_url().$js_file; + $this->js_files[sha1($js_file)] = base_url().$js_file; + } + + public function set_js_config($js_file) + { + $this->js_config_files[sha1($js_file)] = base_url().$js_file; + $this->js_files[sha1($js_file)] = base_url().$js_file; + } + + public function is_IE7() + { + return isset($_SERVER['HTTP_USER_AGENT']) + && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) + ? true : false; + } + + public function get_css_files() + { + return $this->css_files; + } + + public function get_js_files() + { + return $this->js_files; + } + + public function get_js_lib_files() + { + return $this->js_lib_files; + } + + public function get_js_config_files() + { + return $this->js_config_files; + } + + /** + * Load Javascripts + **/ + protected function load_js_fancybox() + { + $this->set_css($this->default_css_path.'/jquery_plugins/fancybox/jquery.fancybox.css'); + + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fancybox-1.3.4.js'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.easing-1.3.pack.js'); + } + + protected function load_js_chosen() + { + $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); + } + + protected function load_js_jqueryui() + { + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); + } + + protected function load_js_uploader() + { + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/file-uploader.css'); + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/jquery.fileupload-ui.css'); + + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/tmpl.min.js'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/load-image.min.js'); + + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.iframe-transport.js'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fileupload.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fileupload.config.js'); + } + + protected function get_layout() + { + $js_files = $this->get_js_files(); + $css_files = $this->get_css_files(); + + $js_lib_files = $this->get_js_lib_files(); + $js_config_files = $this->get_js_config_files(); + + if ($this->unset_jquery) { + unset($js_files[sha1($this->default_javascript_path.'/'.grocery_CRUD::JQUERY)]); + } + + if ($this->unset_jquery_ui) { + unset($css_files[sha1($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS)]); + unset($js_files[sha1($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS)]); + } + + if ($this->unset_bootstrap) { + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.js')]); + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.js')]); + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.min.js')]); + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.min.js')]); + unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.css')]); + unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.min.css')]); + } + + if($this->echo_and_die === false) + { + /** Initialize JavaScript variables */ + $js_vars = array( + 'default_javascript_path' => base_url().$this->default_javascript_path, + 'default_css_path' => base_url().$this->default_css_path, + 'default_texteditor_path' => base_url().$this->default_texteditor_path, + 'default_theme_path' => base_url().$this->default_theme_path, + 'base_url' => base_url() + ); + $this->_add_js_vars($js_vars); + + return (object)array( + 'js_files' => $js_files, + 'js_lib_files' => $js_lib_files, + 'js_config_files' => $js_config_files, + 'css_files' => $css_files, + 'output' => $this->views_as_string, + ); + } + elseif($this->echo_and_die === true) + { + echo $this->views_as_string; + die(); + } + } + + protected function update_layout($update_result = false, $state_info = null) + { + @ob_end_clean(); + if($update_result === false) + { + echo json_encode(array('success' => $update_result)); + } + else + { + $success_message = '

    '.$this->l('update_success_message'); + if(!$this->unset_back_to_list && !$this->_is_ajax()) + { + $success_message .= " ".$this->l('form_go_back_to_list').""; + } + $success_message .= '

    '; + + echo json_encode(array( + 'success' => true , + 'insert_primary_key' => $update_result, + 'success_message' => $success_message, + 'success_list_url' => $this->getListSuccessUrl($state_info->primary_key) + )); + } + $this->set_echo_and_die(); + } + + protected function get_integer_input($field_info,$value) + { + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.numeric.min.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.numeric.config.js'); + $extra_attributes = ''; + if(!empty($field_info->db_max_length)) + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; + $input = ""; + return $input; + } + + protected function get_true_false_input($field_info,$value) + { + $this->set_css($this->default_css_path.'/jquery_plugins/uniform/uniform.default.css'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.uniform.min.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.uniform.config.js'); + + $value_is_null = empty($value) && $value !== '0' && $value !== 0 ? true : false; + + $input = "
    "; + + $true_string = is_array($field_info->extras) && array_key_exists(1,$field_info->extras) ? $field_info->extras[1] : $this->default_true_false_text[1]; + $checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? "checked = 'checked'" : ""; + $input .= " "; + + $false_string = is_array($field_info->extras) && array_key_exists(0,$field_info->extras) ? $field_info->extras[0] : $this->default_true_false_text[0]; + $checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? "checked = 'checked'" : ""; + $input .= ""; + + $input .= "
    "; + + return $input; + } + + protected function get_string_input($field_info,$value) + { + $value = !is_string($value) ? '' : str_replace('"',""",$value); + + $extra_attributes = ''; + if(!empty($field_info->db_max_length)) + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; + $input = ""; + return $input; + } + + protected function get_text_input($field_info,$value) + { + if($field_info->extras == 'text_editor') + { + $editor = $this->config->default_text_editor; + switch ($editor) { + case 'ckeditor': + $this->set_js_lib($this->default_texteditor_path.'/ckeditor/ckeditor.js'); + $this->set_js_lib($this->default_texteditor_path.'/ckeditor/adapters/jquery.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.ckeditor.config.js'); + break; + + case 'tinymce': + $this->set_js_lib($this->default_texteditor_path.'/tiny_mce/jquery.tinymce.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.tine_mce.config.js'); + break; + + case 'markitup': + $this->set_css($this->default_texteditor_path.'/markitup/skins/markitup/style.css'); + $this->set_css($this->default_texteditor_path.'/markitup/sets/default/style.css'); + + $this->set_js_lib($this->default_texteditor_path.'/markitup/jquery.markitup.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.markitup.config.js'); + break; + } + + $class_name = $this->config->text_editor_type == 'minimal' ? 'mini-texteditor' : 'texteditor'; + + $input = ""; + } + else + { + $input = ""; + } + return $input; + } + + protected function get_datetime_input($field_info,$value) + { + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); + $this->set_css($this->default_css_path.'/jquery_plugins/jquery.ui.datetime.css'); + $this->set_css($this->default_css_path.'/jquery_plugins/jquery-ui-timepicker-addon.css'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery-ui-timepicker-addon.js'); + + if($this->language !== 'english') + { + include($this->default_config_path.'/language_alias.php'); + if(array_key_exists($this->language, $language_alias)) + { + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; + if(file_exists($i18n_date_js_file)) + { + $this->set_js_lib($i18n_date_js_file); + } + + $i18n_datetime_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-'.$language_alias[$this->language].'.js'; + if(file_exists($i18n_datetime_js_file)) + { + $this->set_js_lib($i18n_datetime_js_file); + } + } + } + + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery-ui-timepicker-addon.config.js'); + + if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00'){ + list($year,$month,$day) = explode('-',substr($value,0,10)); + $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); + $datetime = $date.substr($value,10); + } + else + { + $datetime = ''; + } + $input = " + ".$this->l('form_button_clear')." + ({$this->ui_date_format}) hh:mm:ss"; + return $input; + } + + protected function get_hidden_input($field_info,$value) + { + if($field_info->extras !== null && $field_info->extras != false) + $value = $field_info->extras; + $input = ""; + return $input; + } + + protected function get_password_input($field_info,$value) + { + $value = !is_string($value) ? '' : $value; + + $extra_attributes = ''; + if(!empty($field_info->db_max_length)) + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; + $input = ""; + return $input; + } + + protected function get_date_input($field_info,$value) + { + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); + + if($this->language !== 'english') + { + include($this->default_config_path.'/language_alias.php'); + if(array_key_exists($this->language, $language_alias)) + { + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; + if(file_exists($i18n_date_js_file)) + { + $this->set_js_lib($i18n_date_js_file); + } + } + } + + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.datepicker.config.js'); + + if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') + { + list($year,$month,$day) = explode('-',substr($value,0,10)); + $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); + } + else + { + $date = ''; + } + + $input = " + ".$this->l('form_button_clear')." (".$this->ui_date_format.")"; + return $input; + } + + protected function get_dropdown_input($field_info,$value) + { + $this->load_js_chosen(); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); + + $input = ""; + return $input; + } + + protected function get_enum_input($field_info,$value) + { + $this->load_js_chosen(); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); + + $input = ""; + return $input; + } + + protected function get_readonly_input($field_info, $value) + { + $read_only_value = " "; + + if (!empty($value) && !is_array($value)) { + $read_only_value = $value; + } elseif (is_array($value)) { + $all_values = array_values($value); + $read_only_value = implode(", ",$all_values); + } + + return '
    '.$read_only_value.'
    '; + } + + protected function get_set_input($field_info,$value) + { + $this->load_js_chosen(); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + + $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); + $selected_values = !empty($value) ? explode(",",$value) : array(); + + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); + $input = ""; + + return $input; + } + + protected function get_multiselect_input($field_info,$value) + { + $this->load_js_chosen(); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + + $options_array = $field_info->extras; + $selected_values = !empty($value) ? explode(",",$value) : array(); + + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); + $input = ""; + + return $input; + } + + protected function get_relation_input($field_info,$value) + { + $this->load_js_chosen(); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + + $ajax_limitation = 10000; + $total_rows = $this->get_relation_total_rows($field_info->extras); + + + //Check if we will use ajax for our queries or just clien-side javascript + $using_ajax = $total_rows > $ajax_limitation ? true : false; + + //We will not use it for now. It is not ready yet. Probably we will have this functionality at version 1.4 + $using_ajax = false; + + //If total rows are more than the limitation, use the ajax plugin + $ajax_or_not_class = $using_ajax ? 'chosen-select' : 'chosen-select'; + + $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); + + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); + $input = ""; + return $input; + } + + protected function get_relation_readonly_input($field_info,$value) + { + $options_array = $this->get_relation_array($field_info->extras); + + $value = isset($options_array[$value]) ? $options_array[$value] : ''; + + return $this->get_readonly_input($field_info, $value); + } + + protected function get_upload_file_readonly_input($field_info,$value) + { + $file = $file_url = base_url().$field_info->extras->upload_path.'/'.$value; + + $value = !empty($value) ? ''.$value.'' : ''; + + return $this->get_readonly_input($field_info, $value); + } + + protected function get_relation_n_n_input($field_info_type, $selected_values) + { + $has_priority_field = !empty($field_info_type->extras->priority_field_relation_table) ? true : false; + $is_ie_7 = isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) ? true : false; + + if($has_priority_field || $is_ie_7) + { + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); + $this->set_css($this->default_css_path.'/jquery_plugins/ui.multiselect.css'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui.multiselect.min.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.multiselect.js'); + + if($this->language !== 'english') + { + include($this->default_config_path.'/language_alias.php'); + if(array_key_exists($this->language, $language_alias)) + { + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/multiselect/ui-multiselect-'.$language_alias[$this->language].'.js'; + if(file_exists($i18n_date_js_file)) + { + $this->set_js_lib($i18n_date_js_file); + } + } + } + } + else + { + $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); + } + + $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); + + $field_info = $this->relation_n_n[$field_info_type->name]; //As we use this function the relation_n_n exists, so don't need to check + $unselected_values = $this->get_relation_n_n_unselected_array($field_info, $selected_values); + + if(empty($unselected_values) && empty($selected_values)) + { + $input = "Please add {$field_info_type->display_as} first"; + } + else + { + $css_class = $has_priority_field || $is_ie_7 ? 'multiselect': 'chosen-multiple-select'; + $width_style = $has_priority_field || $is_ie_7 ? '' : 'width:510px;'; + + $select_title = str_replace('{field_display_as}',$field_info_type->display_as,$this->l('set_relation_title')); + $input = ""; + } + + return $input; + } + + protected function _convert_bytes_ui_to_bytes($bytes_ui) + { + $bytes_ui = str_replace(' ','',$bytes_ui); + if(strstr($bytes_ui,'MB')) + $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; + elseif(strstr($bytes_ui,'KB')) + $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; + elseif(strstr($bytes_ui,'B')) + $bytes = (int)(str_replace('B','',$bytes_ui)); + else + $bytes = (int)($bytes_ui); + + return $bytes; + } + + protected function get_upload_file_input($field_info, $value) + { + $this->load_js_uploader(); + + //Fancybox + $this->load_js_fancybox(); + + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fancybox.config.js'); + + $unique = mt_rand(); + + $allowed_files = $this->config->file_upload_allow_file_types; + $allowed_files_ui = '.'.str_replace('|',',.',$allowed_files); + $max_file_size_ui = $this->config->file_upload_max_file_size; + $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); + + $this->_inline_js(' + var upload_info_'.$unique.' = { + accepted_file_types: /(\\.|\\/)('.$allowed_files.')$/i, + accepted_file_types_ui : "'.$allowed_files_ui.'", + max_file_size: '.$max_file_size_bytes.', + max_file_size_ui: "'.$max_file_size_ui.'" + }; + + var string_upload_file = "'.$this->l('form_upload_a_file').'"; + var string_delete_file = "'.$this->l('string_delete_file').'"; + var string_progress = "'.$this->l('string_progress').'"; + var error_on_uploading = "'.$this->l('error_on_uploading').'"; + var message_prompt_delete_file = "'.$this->l('message_prompt_delete_file').'"; + + var error_max_number_of_files = "'.$this->l('error_max_number_of_files').'"; + var error_accept_file_types = "'.$this->l('error_accept_file_types').'"; + var error_max_file_size = "'.str_replace("{max_file_size}",$max_file_size_ui,$this->l('error_max_file_size')).'"; + var error_min_file_size = "'.$this->l('error_min_file_size').'"; + + var base_url = "'.base_url().'"; + var upload_a_file_string = "'.$this->l('form_upload_a_file').'"; + '); + + $uploader_display_none = empty($value) ? "" : "display:none;"; + $file_display_none = empty($value) ? "display:none;" : ""; + + $is_image = !empty($value) && + ( substr($value,-4) == '.jpg' + || substr($value,-4) == '.png' + || substr($value,-5) == '.jpeg' + || substr($value,-4) == '.gif' + || substr($value,-5) == '.tiff') + ? true : false; + + $image_class = $is_image ? 'image-thumbnail' : ''; + + $input = ' + '.$this->l('form_upload_a_file').' + + + '; + + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/fileuploader.css'); + + $file_url = base_url().$field_info->extras->upload_path.'/'.$value; + + $input .= "
    "; + $input .= "
    "; + $input .= ""; + $input .= "
    "; + $input .= "
    "; + + return $input; + } + + protected function get_add_hidden_fields() + { + return $this->add_hidden_fields; + } + + protected function get_edit_hidden_fields() + { + return $this->edit_hidden_fields; + } + + protected function get_add_input_fields($field_values = null) + { + $fields = $this->get_add_fields(); + $types = $this->get_field_types(); + + $input_fields = array(); + + foreach($fields as $field_num => $field) + { + $field_info = $types[$field->field_name]; + + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; + + if(!isset($this->callback_add_field[$field->field_name])) + { + $field_input = $this->get_field_input($field_info, $field_value); + } + else + { + $field_input = $field_info; + $field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info); + } + + switch ($field_info->crud_type) { + case 'invisible': + unset($this->add_fields[$field_num]); + unset($fields[$field_num]); + continue; + break; + case 'hidden': + $this->add_hidden_fields[] = $field_input; + unset($this->add_fields[$field_num]); + unset($fields[$field_num]); + continue; + break; + } + + $input_fields[$field->field_name] = $field_input; + } + + return $input_fields; + } + + protected function get_edit_input_fields($field_values = null) + { + $fields = $this->get_edit_fields(); + $types = $this->get_field_types(); + + $input_fields = array(); + + foreach($fields as $field_num => $field) + { + $field_info = $types[$field->field_name]; + + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; + if(!isset($this->callback_edit_field[$field->field_name])) + { + $field_input = $this->get_field_input($field_info, $field_value); + } + else + { + $primary_key = $this->getStateInfo()->primary_key; + $field_input = $field_info; + $field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); + } + + switch ($field_info->crud_type) { + case 'invisible': + unset($this->edit_fields[$field_num]); + unset($fields[$field_num]); + continue; + break; + case 'hidden': + $this->edit_hidden_fields[] = $field_input; + unset($this->edit_fields[$field_num]); + unset($fields[$field_num]); + continue; + break; + } + + $input_fields[$field->field_name] = $field_input; + } + + return $input_fields; + } + + protected function get_read_input_fields($field_values = null) + { + $read_fields = $this->get_read_fields(); + + $this->field_types = null; + $this->required_fields = null; + + $read_inputs = array(); + foreach ($read_fields as $field) { + if (!empty($this->change_field_type) + && isset($this->change_field_type[$field->field_name]) + && $this->change_field_type[$field->field_name]->type == 'hidden') { + continue; + } + $this->field_type($field->field_name, 'readonly'); + } + + $fields = $this->get_read_fields(); + $types = $this->get_field_types(); + + $input_fields = array(); + + foreach($fields as $field_num => $field) + { + $field_info = $types[$field->field_name]; + + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; + if(!isset($this->callback_read_field[$field->field_name])) + { + $field_input = $this->get_field_input($field_info, $field_value); + } + else + { + $primary_key = $this->getStateInfo()->primary_key; + $field_input = $field_info; + $field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); + } + + switch ($field_info->crud_type) { + case 'invisible': + unset($this->read_fields[$field_num]); + unset($fields[$field_num]); + continue; + break; + case 'hidden': + $this->read_hidden_fields[] = $field_input; + unset($this->read_fields[$field_num]); + unset($fields[$field_num]); + continue; + break; + } + + $input_fields[$field->field_name] = $field_input; + } + + return $input_fields; + } + + protected function setThemeBasics() + { + $this->theme_path = $this->default_theme_path; + if(substr($this->theme_path,-1) != '/') + $this->theme_path = $this->theme_path.'/'; + + include($this->theme_path.$this->theme.'/config.php'); + + $this->theme_config = $config; + } + + public function set_theme($theme = null) + { + $this->theme = $theme; + + return $this; + } + + protected function _get_ajax_results() + { + //This is a $_POST request rather that $_GET request , because + //Codeigniter doesn't like the $_GET requests so much! + if ($this->_is_ajax()) { + @ob_end_clean(); + $results= (object)array( + 'output' => $this->views_as_string, + 'js_files' => array_values($this->get_js_files()), + 'js_lib_files' => array_values($this->get_js_lib_files()), + 'js_config_files' => array_values($this->get_js_config_files()), + 'css_files' => array_values($this->get_css_files()) + ); + + echo json_encode($results); + die; + } + //else just continue + } + + protected function _is_ajax() + { + return array_key_exists('is_ajax', $_POST) && $_POST['is_ajax'] == 'true' ? true: false; + } + + protected function _theme_view($view, $vars = array(), $return = FALSE) + { + $vars = (is_object($vars)) ? get_object_vars($vars) : $vars; + + $file_exists = FALSE; + + $ext = pathinfo($view, PATHINFO_EXTENSION); + $file = ($ext == '') ? $view.'.php' : $view; + + $view_file = $this->theme_path.$this->theme.'/views/'; + + if (file_exists($view_file.$file)) + { + $path = $view_file.$file; + $file_exists = TRUE; + } + + if ( ! $file_exists) + { + throw new Exception('Unable to load the requested file: '.$file, 16); + } + + extract($vars); + + #region buffering... + ob_start(); + + include($path); + + $buffer = ob_get_contents(); + @ob_end_clean(); + #endregion + + if ($return === TRUE) + { + return $buffer; + } + + $this->views_as_string .= $buffer; + } + + protected function _inline_js($inline_js = '') + { + $this->views_as_string .= "\n"; + } + + protected function _add_js_vars($js_vars = array()) + { + $javascript_as_string = "\n"; + $this->views_as_string .= $javascript_as_string; + } + + protected function get_views_as_string() + { + if(!empty($this->views_as_string)) + return $this->views_as_string; + else + return null; + } +} + + +/** + * PHP grocery CRUD + * + * LICENSE + * + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. + * Please see the corresponding license file for details of these licenses. + * You are free to use, modify and distribute this software, but all copyright information must remain. + * + * @package grocery CRUD + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt + * @author John Skoumbourdis + */ + +// ------------------------------------------------------------------------ + +/** + * PHP grocery States + * + * States of grocery CRUD + * + * @package grocery CRUD + * @author John Skoumbourdis + * @version 1.5.2 + */ +class grocery_CRUD_States extends grocery_CRUD_Layout +{ + const STATE_UNKNOWN = 0; + const STATE_LIST = 1; + const STATE_ADD = 2; + const STATE_EDIT = 3; + const STATE_DELETE = 4; + const STATE_INSERT = 5; + + const STATE_READ = 18; + const STATE_DELETE_MULTIPLE = '19'; + + protected $states = array( + 0 => 'unknown', + 1 => 'list', + 2 => 'add', + 3 => 'edit', + 4 => 'delete', + 5 => 'insert', + 6 => 'update', + 7 => 'ajax_list', + 8 => 'ajax_list_info', + 9 => 'insert_validation', + 10 => 'update_validation', + 11 => 'upload_file', + 12 => 'delete_file', + 13 => 'ajax_relation', + 14 => 'ajax_relation_n_n', + 15 => 'success', + 16 => 'export', + 17 => 'print', + 18 => 'read', + 19 => 'delete_multiple' + ); + + public function getStateInfo() + { + $state_code = $this->getStateCode(); + $segment_object = $this->get_state_info_from_url(); + + $first_parameter = $segment_object->first_parameter; + $second_parameter = $segment_object->second_parameter; + + $state_info = (object)array(); + + switch ($state_code) { + case self::STATE_LIST: + case self::STATE_ADD: + //for now... do nothing! Keeping this switch here in case we need any information at the future. + break; + + case self::STATE_EDIT: + case self::STATE_READ: + if ($first_parameter !== null) { + $state_info = (object) array('primary_key' => $first_parameter); + } else { + throw new Exception('On the state "edit" the Primary key cannot be null', 6); + die(); + } + break; + + case self::STATE_DELETE: + if ($first_parameter !== null) { + $state_info = (object) array('primary_key' => $first_parameter); + } else { + throw new Exception('On the state "delete" the Primary key cannot be null',7); + die(); + } + break; + + case self::STATE_DELETE_MULTIPLE: + if (!empty($_POST) && !empty($_POST['ids']) && is_array($_POST['ids'])) { + $state_info = (object) array('ids' => $_POST['ids']); + } else { + throw new Exception('On the state "Delete Multiple" you need send the ids as a post array.'); + die(); + } + break; + + case self::STATE_INSERT: + if(!empty($_POST)) + { + $state_info = (object)array('unwrapped_data' => $_POST); + } + else + { + throw new Exception('On the state "insert" you must have post data',8); + die(); + } + break; + + case 6: + if(!empty($_POST) && $first_parameter !== null) + { + $state_info = (object)array('primary_key' => $first_parameter,'unwrapped_data' => $_POST); + } + elseif(empty($_POST)) + { + throw new Exception('On the state "update" you must have post data',9); + die(); + } + else + { + throw new Exception('On the state "update" the Primary key cannot be null',10); + die(); + } + break; + + case 7: + case 8: + case 16: //export to excel + case 17: //print + $state_info = (object)array(); + if(!empty($_POST['per_page'])) + { + $state_info->per_page = is_numeric($_POST['per_page']) ? $_POST['per_page'] : null; + } + if(!empty($_POST['page'])) + { + $state_info->page = is_numeric($_POST['page']) ? $_POST['page'] : null; + } + //If we request an export or a print we don't care about what page we are + if($state_code === 16 || $state_code === 17) + { + $state_info->page = 1; + $state_info->per_page = 1000000; //a very big number! + } + if(!empty($_POST['order_by'][0])) + { + $state_info->order_by = $_POST['order_by']; + } + if(!empty($_POST['search_text'])) + { + if(empty($_POST['search_field'])) + { + $search_text = strip_tags($_POST['search_field']); + $state_info->search = (object)array('field' => null , 'text' => $_POST['search_text']); + } + else + { + if (is_array($_POST['search_field'])) { + $search_array = array(); + foreach ($_POST['search_field'] as $search_key => $search_field_name) { + $search_array[$search_field_name] = !empty($_POST['search_text'][$search_key]) ? $_POST['search_text'][$search_key] : ''; + } + $state_info->search = $search_array; + } else { + $state_info->search = (object)array( + 'field' => strip_tags($_POST['search_field']) , + 'text' => $_POST['search_text'] ); + } + } + } + break; + + case 9: + + break; + + case 10: + if($first_parameter !== null) + { + $state_info = (object)array('primary_key' => $first_parameter); + } + break; + + case 11: + $state_info->field_name = $first_parameter; + break; + + case 12: + $state_info->field_name = $first_parameter; + $state_info->file_name = $second_parameter; + break; + + case 13: + $state_info->field_name = $_POST['field_name']; + $state_info->search = $_POST['term']; + break; + + case 14: + $state_info->field_name = $_POST['field_name']; + $state_info->search = $_POST['term']; + break; + + case 15: + $state_info = (object)array( + 'primary_key' => $first_parameter, + 'success_message' => true + ); + break; + } + + return $state_info; + } + + protected function getStateCode() + { + $state_string = $this->get_state_info_from_url()->operation; + + if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) + $state_code = array_search($state_string, $this->states); + else + $state_code = 0; + + return $state_code; + } + + protected function state_url($url = '', $is_list_page = false) + { + //Easy scenario, we had set the crud_url_path + if (!empty($this->crud_url_path)) { + $state_url = !empty($this->list_url_path) && $is_list_page? + $this->list_url_path : + $this->crud_url_path.'/'.$url ; + } else { + //Complicated scenario. The crud_url_path is not specified so we are + //trying to understand what is going on from the URL. + $ci = &get_instance(); + + $segment_object = $this->get_state_info_from_url(); + $method_name = $this->get_method_name(); + $segment_position = $segment_object->segment_position; + + $state_url_array = array(); + + if( sizeof($ci->uri->segments) > 0 ) { + foreach($ci->uri->segments as $num => $value) + { + $state_url_array[$num] = $value; + if($num == ($segment_position - 1)) + break; + } + + if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) //there is a scenario that you don't have the index to your url + $state_url_array[$num+1] = 'index'; + } + + $state_url = site_url(implode('/',$state_url_array).'/'.$url); + } + + return $state_url; + } + + protected function get_state_info_from_url() + { + $ci = &get_instance(); + + $segment_position = count($ci->uri->segments) + 1; + $operation = 'list'; + + $segements = $ci->uri->segments; + foreach($segements as $num => $value) + { + if($value != 'unknown' && in_array($value, $this->states)) + { + $segment_position = (int)$num; + $operation = $value; //I don't have a "break" here because I want to ensure that is the LAST segment with name that is in the array. + } + } + + $function_name = $this->get_method_name(); + + if($function_name == 'index' && !in_array('index',$ci->uri->segments)) + $segment_position++; + + $first_parameter = isset($segements[$segment_position+1]) ? $segements[$segment_position+1] : null; + $second_parameter = isset($segements[$segment_position+2]) ? $segements[$segment_position+2] : null; + + return (object)array('segment_position' => $segment_position, 'operation' => $operation, 'first_parameter' => $first_parameter, 'second_parameter' => $second_parameter); + } + + protected function get_method_hash() + { + $ci = &get_instance(); + + $state_info = $this->get_state_info_from_url(); + $extra_values = $ci->uri->segment($state_info->segment_position - 1) != $this->get_method_name() ? $ci->uri->segment($state_info->segment_position - 1) : ''; + + return $this->crud_url_path !== null + ? md5($this->crud_url_path) + : md5($this->get_controller_name().$this->get_method_name().$extra_values); + } + + protected function get_method_name() + { + $ci = &get_instance(); + return $ci->router->method; + } + + protected function get_controller_name() + { + $ci = &get_instance(); + return $ci->router->class; + } + + public function getState() + { + return $this->states[$this->getStateCode()]; + } + + protected function getListUrl() + { + return $this->state_url('',true); + } + + protected function getAjaxListUrl() + { + return $this->state_url('ajax_list'); + } + + protected function getExportToExcelUrl() + { + return $this->state_url('export'); + } + + protected function getPrintUrl() + { + return $this->state_url('print'); + } + + protected function getAjaxListInfoUrl() + { + return $this->state_url('ajax_list_info'); + } + + protected function getAddUrl() + { + return $this->state_url('add'); + } + + protected function getInsertUrl() + { + return $this->state_url('insert'); + } + + protected function getValidationInsertUrl() + { + return $this->state_url('insert_validation'); + } + + protected function getValidationUpdateUrl($primary_key = null) + { + if($primary_key === null) + return $this->state_url('update_validation'); + else + return $this->state_url('update_validation/'.$primary_key); + } + + protected function getEditUrl($primary_key = null) + { + if($primary_key === null) + return $this->state_url('edit'); + else + return $this->state_url('edit/'.$primary_key); + } + + protected function getReadUrl($primary_key = null) + { + if($primary_key === null) + return $this->state_url('read'); + else + return $this->state_url('read/'.$primary_key); + } + + protected function getUpdateUrl($state_info) + { + return $this->state_url('update/'.$state_info->primary_key); + } + + protected function getDeleteUrl($state_info = null) + { + if (empty($state_info)) { + return $this->state_url('delete'); + } else { + return $this->state_url('delete/'.$state_info->primary_key); + } + } + + protected function getDeleteMultipleUrl() + { + return $this->state_url('delete_multiple'); + } + + protected function getListSuccessUrl($primary_key = null) + { + if(empty($primary_key)) + return $this->state_url('success',true); + else + return $this->state_url('success/'.$primary_key,true); + } + + protected function getUploadUrl($field_name) + { + return $this->state_url('upload_file/'.$field_name); + } + + protected function getFileDeleteUrl($field_name) + { + return $this->state_url('delete_file/'.$field_name); + } + + protected function getAjaxRelationUrl() + { + return $this->state_url('ajax_relation'); + } + + protected function getAjaxRelationManytoManyUrl() + { + return $this->state_url('ajax_relation_n_n'); + } +} + + +/** + * PHP grocery CRUD + * + * LICENSE + * + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. + * Please see the corresponding license file for details of these licenses. + * You are free to use, modify and distribute this software, but all copyright information must remain. + * + * @package grocery CRUD + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt + * @version 1.5.2 + * @author John Skoumbourdis + */ + +// ------------------------------------------------------------------------ + +/** + * PHP grocery CRUD + * + * Creates a full functional CRUD with few lines of code. + * + * @package grocery CRUD + * @author John Skoumbourdis + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt + * @link http://www.grocerycrud.com/documentation + */ +class Grocery_CRUD extends grocery_CRUD_States +{ + /** + * Grocery CRUD version + * + * @var string + */ + const VERSION = "1.5.2"; + + const JQUERY = "jquery-1.11.1.min.js"; + const JQUERY_UI_JS = "jquery-ui-1.10.3.custom.min.js"; + const JQUERY_UI_CSS = "jquery-ui-1.10.1.custom.min.css"; + + protected $state_code = null; + protected $state_info = null; + protected $columns = null; + + private $basic_db_table_checked = false; + private $columns_checked = false; + private $add_fields_checked = false; + private $edit_fields_checked = false; + private $read_fields_checked = false; + + protected $default_theme = 'flexigrid'; + protected $language = null; + protected $lang_strings = array(); + protected $php_date_format = null; + protected $js_date_format = null; + protected $ui_date_format = null; + protected $character_limiter = null; + protected $config = null; + + protected $add_fields = null; + protected $edit_fields = null; + protected $read_fields = null; + protected $add_hidden_fields = array(); + protected $edit_hidden_fields = array(); + protected $field_types = null; + protected $basic_db_table = null; + protected $theme_config = array(); + protected $subject = null; + protected $subject_plural = null; + protected $display_as = array(); + protected $order_by = null; + protected $where = array(); + protected $like = array(); + protected $having = array(); + protected $or_having = array(); + protected $limit = null; + protected $required_fields = array(); + protected $_unique_fields = array(); + protected $validation_rules = array(); + protected $relation = array(); + protected $relation_n_n = array(); + protected $upload_fields = array(); + protected $actions = array(); + + protected $form_validation = null; + protected $change_field_type = null; + protected $primary_keys = array(); + protected $crud_url_path = null; + protected $list_url_path = null; + + /* The unsetters */ + protected $unset_texteditor = array(); + protected $unset_add = false; + protected $unset_edit = false; + protected $unset_delete = false; + protected $unset_read = false; + protected $unset_jquery = false; + protected $unset_jquery_ui = false; + protected $unset_bootstrap = false; + protected $unset_list = false; + protected $unset_export = false; + protected $unset_print = false; + protected $unset_back_to_list = false; + protected $unset_columns = null; + protected $unset_add_fields = null; + protected $unset_edit_fields = null; + protected $unset_read_fields = null; + + /* Callbacks */ + protected $callback_before_insert = null; + protected $callback_after_insert = null; + protected $callback_insert = null; + protected $callback_before_update = null; + protected $callback_after_update = null; + protected $callback_update = null; + protected $callback_before_delete = null; + protected $callback_after_delete = null; + protected $callback_delete = null; + protected $callback_column = array(); + protected $callback_add_field = array(); + protected $callback_edit_field = array(); + protected $callback_upload = null; + protected $callback_before_upload = null; + protected $callback_after_upload = null; + + protected $default_javascript_path = null; //autogenerate, please do not modify + protected $default_css_path = null; //autogenerate, please do not modify + protected $default_texteditor_path = null; //autogenerate, please do not modify + protected $default_theme_path = null; //autogenerate, please do not modify + protected $default_language_path = 'assets/grocery_crud/languages'; + protected $default_config_path = 'assets/grocery_crud/config'; + protected $default_assets_path = 'assets/grocery_crud'; + + /** + * + * Constructor + * + * @access public + */ + public function __construct() + { + + } + + /** + * The displayed columns that user see + * + * @access public + * @param string + * @param array + * @return void + */ + public function columns() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->columns = $args; + + return $this; + } + + + /** + * Set Validation Rules + * + * Important note: If the $field is an array then no automated crud fields will take apart + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_rules($field, $label = '', $rules = '') + { + if(is_string($field)) + { + $this->validation_rules[$field] = array('field' => $field, 'label' => $label, 'rules' => $rules); + }elseif(is_array($field)) + { + foreach($field as $num_field => $field_array) + { + $this->validation_rules[$field_array['field']] = $field_array; + } + } + return $this; + } + + /** + * + * Changes the default field type + * @param string $field + * @param string $type + * @param array|string $extras + */ + public function change_field_type($field , $type, $extras = null) + { + $field_type = (object)array('type' => $type); + + $field_type->extras = $extras; + + $this->change_field_type[$field] = $field_type; + + return $this; + } + + /** + * + * Just an alias to the change_field_type method + * @param string $field + * @param string $type + * @param array|string $extras + */ + public function field_type($field , $type, $extras = null) + { + return $this->change_field_type($field , $type, $extras); + } + + /** + * Change the default primary key for a specific table. + * If the $table_name is NULL then the primary key is for the default table name that we added at the set_table method + * + * @param string $primary_key_field + * @param string $table_name + */ + public function set_primary_key($primary_key_field, $table_name = null) + { + $this->primary_keys[] = array('field_name' => $primary_key_field, 'table_name' => $table_name); + + return $this; + } + + /** + * Unsets the texteditor of the selected fields + * + * @access public + * @param string + * @param array + * @return void + */ + public function unset_texteditor() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + foreach($args as $arg) + { + $this->unset_texteditor[] = $arg; + } + + return $this; + } + + /** + * Unsets just the jquery library from the js. This function can be used if there is already a jquery included + * in the main template. This will avoid all jquery conflicts. + * + * @return void + */ + public function unset_jquery() + { + $this->unset_jquery = true; + + return $this; + } + + /** + * Unsets the jquery UI Javascript and CSS. This function is really useful + * when the jquery UI JavaScript and CSS are already included in the main template. + * This will avoid all jquery UI conflicts. + * + * @return void + */ + public function unset_jquery_ui() + { + $this->unset_jquery_ui = true; + + return $this; + } + + /** + * Unsets just the twitter bootstrap libraries from the js and css. This function can be used if there is already twitter bootstrap files included + * in the main template. If you are already using a bootstrap template then it's not necessary to load the files again. + * + * @return void + */ + public function unset_bootstrap() + { + $this->unset_bootstrap = true; + + return $this; + } + + /** + * Unsets the add operation from the list + * + * @return void + */ + public function unset_add() + { + $this->unset_add = true; + + return $this; + } + + /** + * Unsets the edit operation from the list + * + * @return void + */ + public function unset_edit() + { + $this->unset_edit = true; + + return $this; + } + + /** + * Unsets the delete operation from the list + * + * @return void + */ + public function unset_delete() + { + $this->unset_delete = true; + + return $this; + } + + /** + * Unsets the read operation from the list + * + * @return void + */ + public function unset_read() + { + $this->unset_read = true; + + return $this; + } + + /** + * Just an alias to unset_read + * + * @return void + * */ + public function unset_view() + { + return unset_read(); + } + + /** + * Unsets the export button and functionality from the list + * + * @return void + */ + public function unset_export() + { + $this->unset_export = true; + + return $this; + } + + + /** + * Unsets the print button and functionality from the list + * + * @return void + */ + public function unset_print() + { + $this->unset_print = true; + + return $this; + } + + /** + * Unsets all the operations from the list + * + * @return void + */ + public function unset_operations() + { + $this->unset_add = true; + $this->unset_edit = true; + $this->unset_delete = true; + $this->unset_read = true; + $this->unset_export = true; + $this->unset_print = true; + + return $this; + } + + /** + * Unsets a column from the list + * + * @return void. + */ + public function unset_columns() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->unset_columns = $args; + + return $this; + } + + public function unset_list() + { + $this->unset_list = true; + + return $this; + } + + public function unset_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->unset_add_fields = $args; + $this->unset_edit_fields = $args; + $this->unset_read_fields = $args; + + return $this; + } + + public function unset_add_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->unset_add_fields = $args; + + return $this; + } + + public function unset_edit_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->unset_edit_fields = $args; + + return $this; + } + + public function unset_read_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->unset_read_fields = $args; + + return $this; + } + + + /** + * Unsets everything that has to do with buttons or links with go back to list message + * @access public + * @return void + */ + public function unset_back_to_list() + { + $this->unset_back_to_list = true; + + return $this; + } + + /** + * + * The fields that user will see on add/edit + * + * @access public + * @param string + * @param array + * @return void + */ + public function fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->add_fields = $args; + $this->edit_fields = $args; + + return $this; + } + + /** + * + * The fields that user can see . It is only for the add form + */ + public function add_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->add_fields = $args; + + return $this; + } + + /** + * + * The fields that user can see . It is only for the edit form + */ + public function edit_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->edit_fields = $args; + + return $this; + } + + public function set_read_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) { + $args = $args[0]; + } + + $this->read_fields = $args; + + return $this; + } + + /** + * + * Changes the displaying label of the field + * @param $field_name + * @param $display_as + * @return void + */ + public function display_as($field_name, $display_as = null) + { + if(is_array($field_name)) + { + foreach($field_name as $field => $display_as) + { + $this->display_as[$field] = $display_as; + } + } + elseif($display_as !== null) + { + $this->display_as[$field_name] = $display_as; + } + return $this; + } + + /** + * + * Load the language strings array from the language file + */ + protected function _load_language() + { + if($this->language === null) + { + $this->language = strtolower($this->config->default_language); + } + include($this->default_language_path.'/'.$this->language.'.php'); + + foreach($lang as $handle => $lang_string) + if(!isset($this->lang_strings[$handle])) + $this->lang_strings[$handle] = $lang_string; + + $this->default_true_false_text = array( $this->l('form_inactive') , $this->l('form_active')); + $this->subject = $this->subject === null ? $this->l('list_record') : $this->subject; + + } + + protected function _load_date_format() + { + list($php_day, $php_month, $php_year) = array('d','m','Y'); + list($js_day, $js_month, $js_year) = array('dd','mm','yy'); + list($ui_day, $ui_month, $ui_year) = array($this->l('ui_day'), $this->l('ui_month'), $this->l('ui_year')); + + $date_format = $this->config->date_format; + switch ($date_format) { + case 'uk-date': + $this->php_date_format = "$php_day/$php_month/$php_year"; + $this->js_date_format = "$js_day/$js_month/$js_year"; + $this->ui_date_format = "$ui_day/$ui_month/$ui_year"; + break; + + case 'us-date': + $this->php_date_format = "$php_month/$php_day/$php_year"; + $this->js_date_format = "$js_month/$js_day/$js_year"; + $this->ui_date_format = "$ui_month/$ui_day/$ui_year"; + break; + + case 'sql-date': + default: + $this->php_date_format = "$php_year-$php_month-$php_day"; + $this->js_date_format = "$js_year-$js_month-$js_day"; + $this->ui_date_format = "$ui_year-$ui_month-$ui_day"; + break; + } + } + + /** + * + * Set a language string directly + * @param string $handle + * @param string $string + */ + public function set_lang_string($handle, $lang_string){ + $this->lang_strings[$handle] = $lang_string; + + return $this; + } + + /** + * + * Just an alias to get_lang_string method + * @param string $handle + */ + public function l($handle) + { + return $this->get_lang_string($handle); + } + + /** + * + * Get the language string of the inserted string handle + * @param string $handle + */ + public function get_lang_string($handle) + { + return $this->lang_strings[$handle]; + } + + /** + * + * Simply set the language + * @example english + * @param string $language + */ + public function set_language($language) + { + $this->language = $language; + + return $this; + } + + /** + * + * Enter description here ... + */ + protected function get_columns() + { + if($this->columns_checked === false) + { + $field_types = $this->get_field_types(); + if(empty($this->columns)) + { + $this->columns = array(); + foreach($field_types as $field) + { + if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) + $this->columns[] = $field->name; + } + } + + foreach($this->columns as $col_num => $column) + { + + if(isset($this->relation[$column])) + { + + $new_column = $this->_unique_field_name($this->relation[$column][0]); + $this->columns[$col_num] = $new_column; + + if(isset($this->display_as[$column])) + { + $display_as = $this->display_as[$column]; + unset($this->display_as[$column]); + $this->display_as[$new_column] = $display_as; + } + else + { + $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); + } + + $column = $new_column; + $this->columns[$col_num] = $new_column; + } + else + { + if(!empty($this->relation)) + { + $table_name = $this->get_table(); + foreach($this->relation as $relation) + { + if( $relation[2] == $column ) + { + $new_column = $table_name.'.'.$column; + if(isset($this->display_as[$column])) + { + $display_as = $this->display_as[$column]; + unset($this->display_as[$column]); + $this->display_as[$new_column] = $display_as; + } + else + { + $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); + } + + $column = $new_column; + $this->columns[$col_num] = $new_column; + } + } + } + + } + + if(isset($this->display_as[$column])) + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); + elseif(isset($field_types[$column])) + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); + else + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => + ucfirst(str_replace('_',' ',$column))); + + if(!empty($this->unset_columns) && in_array($column,$this->unset_columns)) + { + unset($this->columns[$col_num]); + } + } + + $this->columns_checked = true; + + } + + return $this->columns; + } + + /** + * + * Enter description here ... + */ + protected function get_add_fields() + { + if($this->add_fields_checked === false) + { + $field_types = $this->get_field_types(); + if(!empty($this->add_fields)) + { + foreach($this->add_fields as $field_num => $field) + { + if(isset($this->display_as[$field])) + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); + elseif(isset($field_types[$field]->display_as)) + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); + else + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); + } + } + else + { + $this->add_fields = array(); + foreach($field_types as $field) + { + //Check if an unset_add_field is initialize for this field name + if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) + continue; + + if( (!isset($field->db_extra) || $field->db_extra != 'auto_increment') ) + { + if(isset($this->display_as[$field->name])) + $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); + else + $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); + } + } + } + + $this->add_fields_checked = true; + } + return $this->add_fields; + } + + /** + * + * Enter description here ... + */ + protected function get_edit_fields() + { + if($this->edit_fields_checked === false) + { + $field_types = $this->get_field_types(); + if(!empty($this->edit_fields)) + { + foreach($this->edit_fields as $field_num => $field) + { + if(isset($this->display_as[$field])) + $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); + else + $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); + } + } + else + { + $this->edit_fields = array(); + foreach($field_types as $field) + { + //Check if an unset_edit_field is initialize for this field name + if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) + continue; + + if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') + { + if(isset($this->display_as[$field->name])) + $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); + else + $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); + } + } + } + + $this->edit_fields_checked = true; + } + return $this->edit_fields; + } + + /** + * + * Enter description here ... + */ + protected function get_read_fields() + { + if($this->read_fields_checked === false) + { + $field_types = $this->get_field_types(); + if(!empty($this->read_fields)) + { + foreach($this->read_fields as $field_num => $field) + { + if(isset($this->display_as[$field])) + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); + else + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); + } + } + else + { + $this->read_fields = array(); + foreach($field_types as $field) + { + //Check if an unset_read_field is initialize for this field name + if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) + continue; + + if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') + { + if(isset($this->display_as[$field->name])) + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); + else + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); + } + } + } + + $this->read_fields_checked = true; + } + return $this->read_fields; + } + + public function order_by($order_by, $direction = 'asc') + { + $this->order_by = array($order_by,$direction); + + return $this; + } + + public function where($key, $value = NULL, $escape = TRUE) + { + $this->where[] = array($key,$value,$escape); + + return $this; + } + + public function or_where($key, $value = NULL, $escape = TRUE) + { + $this->or_where[] = array($key,$value,$escape); + + return $this; + } + + public function like($field, $match = '', $side = 'both') + { + $this->like[] = array($field, $match, $side); + + return $this; + } + + protected function having($key, $value = '', $escape = TRUE) + { + $this->having[] = array($key, $value, $escape); + + return $this; + } + + protected function or_having($key, $value = '', $escape = TRUE) + { + $this->or_having[] = array($key, $value, $escape); + + return $this; + } + + public function or_like($field, $match = '', $side = 'both') + { + $this->or_like[] = array($field, $match, $side); + + return $this; + } + + public function limit($limit, $offset = '') + { + $this->limit = array($limit,$offset); + + return $this; + } + + protected function _initialize_helpers() + { + $ci = &get_instance(); + + $ci->load->helper('url'); + $ci->load->helper('form'); + } + + protected function _initialize_variables() + { + $ci = &get_instance(); + $ci->load->config('grocery_crud'); + + $this->config = (object)array(); + + /** Initialize all the config variables into this object */ + $this->config->default_language = $ci->config->item('grocery_crud_default_language'); + $this->config->date_format = $ci->config->item('grocery_crud_date_format'); + $this->config->default_per_page = $ci->config->item('grocery_crud_default_per_page'); + $this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types'); + $this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size'); + $this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor'); + $this->config->text_editor_type = $ci->config->item('grocery_crud_text_editor_type'); + $this->config->character_limiter = $ci->config->item('grocery_crud_character_limiter'); + $this->config->dialog_forms = $ci->config->item('grocery_crud_dialog_forms'); + $this->config->paging_options = $ci->config->item('grocery_crud_paging_options'); + $this->config->default_theme = $ci->config->item('grocery_crud_default_theme'); + $this->config->environment = $ci->config->item('grocery_crud_environment'); + + /** Initialize default paths */ + $this->default_javascript_path = $this->default_assets_path.'/js'; + $this->default_css_path = $this->default_assets_path.'/css'; + $this->default_texteditor_path = $this->default_assets_path.'/texteditor'; + $this->default_theme_path = $this->default_assets_path.'/themes'; + + $this->character_limiter = $this->config->character_limiter; + + if ($this->character_limiter === 0 || $this->character_limiter === '0') { + $this->character_limiter = 1000000; //a very big number + } elseif($this->character_limiter === null || $this->character_limiter === false) { + $this->character_limiter = 30; //is better to have the number 30 rather than the 0 value + } + + if ($this->theme === null && !empty($this->config->default_theme)) { + $this->set_theme($this->config->default_theme); + } + } + + protected function _set_primary_keys_to_model() + { + if(!empty($this->primary_keys)) + { + foreach($this->primary_keys as $primary_key) + { + $this->basic_model->set_primary_key($primary_key['field_name'],$primary_key['table_name']); + } + } + } + + /** + * Initialize all the required libraries and variables before rendering + */ + protected function pre_render() + { + $this->_initialize_variables(); + $this->_initialize_helpers(); + $this->_load_language(); + $this->state_code = $this->getStateCode(); + + if($this->basic_model === null) + $this->set_default_Model(); + + $this->set_basic_db_table($this->get_table()); + + $this->_load_date_format(); + + $this->_set_primary_keys_to_model(); + } + + /** + * + * Or else ... make it work! The web application takes decision of what to do and show it to the final user. + * Without this function nothing works. Here is the core of grocery CRUD project. + * + * @access public + */ + public function render() + { + $this->pre_render(); + + if( $this->state_code != 0 ) + { + $this->state_info = $this->getStateInfo(); + } + else + { + throw new Exception('The state is unknown , I don\'t know what I will do with your data!', 4); + die(); + } + + switch ($this->state_code) { + case 15://success + case 1://list + if($this->unset_list) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } + + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); + + $this->set_basic_Layout(); + + $state_info = $this->getStateInfo(); + + $this->showList(false,$state_info); + + break; + + case 2://add + if($this->unset_add) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } + + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); + + $this->set_basic_Layout(); + + $this->showAddForm(); + + break; + + case 3://edit + if($this->unset_edit) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } + + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); + + $this->set_basic_Layout(); + + $state_info = $this->getStateInfo(); + + $this->showEditForm($state_info); + + break; + + case 4://delete + if($this->unset_delete) + { + throw new Exception('This user is not allowed to do this operation', 14); + die(); + } + + $state_info = $this->getStateInfo(); + $delete_result = $this->db_delete($state_info); + + $this->delete_layout( $delete_result ); + break; + + case 5://insert + if($this->unset_add) + { + throw new Exception('This user is not allowed to do this operation', 14); + die(); + } + + $state_info = $this->getStateInfo(); + $insert_result = $this->db_insert($state_info); + + $this->insert_layout($insert_result); + break; + + case 6://update + if($this->unset_edit) + { + throw new Exception('This user is not allowed to do this operation', 14); + die(); + } + + $state_info = $this->getStateInfo(); + $update_result = $this->db_update($state_info); + + $this->update_layout( $update_result,$state_info); + break; + + case 7://ajax_list + + if($this->unset_list) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } + + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); + + $this->set_basic_Layout(); + + $state_info = $this->getStateInfo(); + $this->set_ajax_list_queries($state_info); + + $this->showList(true); + + break; + + case 8://ajax_list_info + + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); + + $this->set_basic_Layout(); + + $state_info = $this->getStateInfo(); + $this->set_ajax_list_queries($state_info); + + $this->showListInfo(); + break; + + case 9://insert_validation + + $validation_result = $this->db_insert_validation(); + + $this->validation_layout($validation_result); + break; + + case 10://update_validation + + $validation_result = $this->db_update_validation(); + + $this->validation_layout($validation_result); + break; + + case 11://upload_file + + $state_info = $this->getStateInfo(); + + $upload_result = $this->upload_file($state_info); + + $this->upload_layout($upload_result, $state_info->field_name); + break; + + case 12://delete_file + $state_info = $this->getStateInfo(); + + $delete_file_result = $this->delete_file($state_info); + + $this->delete_file_layout($delete_file_result); + break; + /* + case 13: //ajax_relation + $state_info = $this->getStateInfo(); + + $ajax_relation_result = $this->ajax_relation($state_info); + + $ajax_relation_result[""] = ""; + + echo json_encode($ajax_relation_result); + die(); + break; + + case 14: //ajax_relation_n_n + echo json_encode(array("34" => 'Johnny' , "78" => "Test")); + die(); + break; + */ + case 16: //export to excel + //a big number just to ensure that the table characters will not be cutted. + $this->character_limiter = 1000000; + + if($this->unset_export) + { + throw new Exception('You don\'t have permissions for this operation', 15); + die(); + } + + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); + + $this->set_basic_Layout(); + + $state_info = $this->getStateInfo(); + $this->set_ajax_list_queries($state_info); + $this->exportToExcel($state_info); + break; + + case 17: //print + //a big number just to ensure that the table characters will not be cutted. + $this->character_limiter = 1000000; + + if($this->unset_print) + { + throw new Exception('You don\'t have permissions for this operation', 15); + die(); + } + + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); + + $this->set_basic_Layout(); + + $state_info = $this->getStateInfo(); + $this->set_ajax_list_queries($state_info); + $this->print_webpage($state_info); + break; + + case grocery_CRUD_States::STATE_READ: + if($this->unset_read) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } + + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); + + $this->set_basic_Layout(); + + $state_info = $this->getStateInfo(); + + $this->showReadForm($state_info); + + break; + + case grocery_CRUD_States::STATE_DELETE_MULTIPLE: + + if($this->unset_delete) + { + throw new Exception('This user is not allowed to do this operation'); + die(); + } + + $state_info = $this->getStateInfo(); + $delete_result = $this->db_multiple_delete($state_info); + + $this->delete_layout($delete_result); + + break; + + } + + return $this->get_layout(); + } + + protected function get_common_data() + { + $data = (object)array(); + + $data->subject = $this->subject; + $data->subject_plural = $this->subject_plural; + + return $data; + } + + /** + * + * Enter description here ... + */ + public function callback_before_insert($callback = null) + { + $this->callback_before_insert = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_after_insert($callback = null) + { + $this->callback_after_insert = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_insert($callback = null) + { + $this->callback_insert = $callback; + + return $this; + } + + + /** + * + * Enter description here ... + */ + public function callback_before_update($callback = null) + { + $this->callback_before_update = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_after_update($callback = null) + { + $this->callback_after_update = $callback; + + return $this; + } + + + /** + * + * Enter description here ... + * @param mixed $callback + */ + public function callback_update($callback = null) + { + $this->callback_update = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_before_delete($callback = null) + { + $this->callback_before_delete = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_after_delete($callback = null) + { + $this->callback_after_delete = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_delete($callback = null) + { + $this->callback_delete = $callback; + + return $this; + } + + /** + * + * Enter description here ... + * @param string $column + * @param mixed $callback + */ + public function callback_column($column ,$callback = null) + { + $this->callback_column[$column] = $callback; + + return $this; + } + + /** + * + * Enter description here ... + * @param string $field + * @param mixed $callback + */ + public function callback_field($field, $callback = null) + { + $this->callback_add_field[$field] = $callback; + $this->callback_edit_field[$field] = $callback; + + return $this; + } + + /** + * + * Enter description here ... + * @param string $field + * @param mixed $callback + */ + public function callback_add_field($field, $callback = null) + { + $this->callback_add_field[$field] = $callback; + + return $this; + } + + /** + * + * Enter description here ... + * @param string $field + * @param mixed $callback + */ + public function callback_edit_field($field, $callback = null) + { + $this->callback_edit_field[$field] = $callback; + + return $this; + } + + /** + * + * Callback that replace the default auto uploader + * + * @param mixed $callback + * @return grocery_CRUD + */ + public function callback_upload($callback = null) + { + $this->callback_upload = $callback; + + return $this; + } + + /** + * + * A callback that triggered before the upload functionality. This callback is suggested for validation checks + * @param mixed $callback + * @return grocery_CRUD + */ + public function callback_before_upload($callback = null) + { + $this->callback_before_upload = $callback; + + return $this; + } + + /** + * + * A callback that triggered after the upload functionality + * @param mixed $callback + * @return grocery_CRUD + */ + public function callback_after_upload($callback = null) + { + $this->callback_after_upload = $callback; + + return $this; + + } + + /** + * + * Gets the basic database table of our crud. + * @return string + */ + public function get_table() + { + if($this->basic_db_table_checked) + { + return $this->basic_db_table; + } + elseif( $this->basic_db_table !== null ) + { + if(!$this->table_exists($this->basic_db_table)) + { + throw new Exception('The table name does not exist. Please check you database and try again.',11); + die(); + } + $this->basic_db_table_checked = true; + return $this->basic_db_table; + } + else + { + //Last try , try to find the table from your view / function name!!! Not suggested but it works . + $last_chance_table_name = $this->get_method_name(); + if($this->table_exists($last_chance_table_name)) + { + $this->set_table($last_chance_table_name); + } + $this->basic_db_table_checked = true; + return $this->basic_db_table; + + } + + return false; + } + + /** + * + * The field names of the required fields + */ + public function required_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->required_fields = $args; + + return $this; + } + + /** + * Add the fields that they are as UNIQUE in the database structure + * + * @return grocery_CRUD + */ + public function unique_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->_unique_fields = $args; + + return $this; + } + + /** + * + * Sets the basic database table that we will get our data. + * @param string $table_name + * @return grocery_CRUD + */ + public function set_table($table_name) + { + if(!empty($table_name) && $this->basic_db_table === null) + { + $this->basic_db_table = $table_name; + } + elseif(!empty($table_name)) + { + throw new Exception('You have already insert a table name once...', 1); + } + else + { + throw new Exception('The table name cannot be empty.', 2); + die(); + } + + return $this; + } + + /** + * Set a full URL path to this method. + * + * This method is useful when the path is not specified correctly. + * Especially when we are using routes. + * For example: + * Let's say we have the path http://www.example.com/ however the original url path is + * http://www.example.com/example/index . We have to specify the url so we can have + * all the CRUD operations correctly. + * The url path has to be set from this method like this: + * + * $crud->set_crud_url_path(site_url('example/index')); + * + * + * @param string $crud_url_path + * @param string $list_url_path + * @return grocery_CRUD + */ + public function set_crud_url_path($crud_url_path, $list_url_path = null) + { + $this->crud_url_path = $crud_url_path; + + //If the list_url_path is empty so we are guessing that the list_url_path + //will be the same with crud_url_path + $this->list_url_path = !empty($list_url_path) ? $list_url_path : $crud_url_path; + + return $this; + } + + /** + * + * Set a subject to understand what type of CRUD you use. + * ---------------------------------------------------------------------------------------------- + * Subject_plural: Sets the subject to its plural form. For example the plural + * of "Customer" is "Customers", "Product" is "Products"... e.t.c. + * @example In this CRUD we work with the table db_categories. The $subject will be the 'Category' + * and the $subject_plural will be 'Categories' + * @param string $subject + * @param string $subject_plural + * @return grocery_CRUD + */ + public function set_subject($subject, $subject_plural = null) + { + $this->subject = $subject; + $this->subject_plural = $subject_plural === null ? $subject : $subject_plural; + + return $this; + } + + /** + * + * Enter description here ... + * @param $title + * @param $image_url + * @param $url + * @param $css_class + * @param $url_callback + */ + public function add_action( $label, $image_url = '', $link_url = '', $css_class = '', $url_callback = null) + { + $unique_id = substr($label,0,1).substr(md5($label.$link_url),-8); //The unique id is used for class name so it must begin with a string + + $this->actions[$unique_id] = (object)array( + 'label' => $label, + 'image_url' => $image_url, + 'link_url' => $link_url, + 'css_class' => $css_class, + 'url_callback' => $url_callback, + 'url_has_http' => substr($link_url,0,7) == 'http://' || substr($link_url,0,8) == 'https://' ? true : false + ); + + return $this; + } + + /** + * + * Set a simple 1-n foreign key relation + * @param string $field_name + * @param string $related_table + * @param string $related_title_field + * @param mixed $where_clause + * @param string $order_by + * @return Grocery_CRUD + */ + public function set_relation($field_name , $related_table, $related_title_field, $where_clause = null, $order_by = null) + { + $this->relation[$field_name] = array($field_name, $related_table,$related_title_field, $where_clause, $order_by); + return $this; + } + + /** + * + * Sets a relation with n-n relationship. + * @param string $field_name + * @param string $relation_table + * @param string $selection_table + * @param string $primary_key_alias_to_this_table + * @param string $primary_key_alias_to_selection_table + * @param string $title_field_selection_table + * @param string $priority_field_relation_table + * @param mixed $where_clause + * @return Grocery_CRUD + */ + public function set_relation_n_n($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, $primary_key_alias_to_selection_table , $title_field_selection_table , $priority_field_relation_table = null, $where_clause = null) + { + $this->relation_n_n[$field_name] = + (object)array( + 'field_name' => $field_name, + 'relation_table' => $relation_table, + 'selection_table' => $selection_table, + 'primary_key_alias_to_this_table' => $primary_key_alias_to_this_table, + 'primary_key_alias_to_selection_table' => $primary_key_alias_to_selection_table , + 'title_field_selection_table' => $title_field_selection_table , + 'priority_field_relation_table' => $priority_field_relation_table, + 'where_clause' => $where_clause + ); + + return $this; + } + + /** + * + * Transform a field to an upload field + * + * @param string $field_name + * @param string $upload_path + * @return Grocery_CRUD + */ + public function set_field_upload($field_name, $upload_dir = '', $allowed_file_types = '') + { + $upload_dir = !empty($upload_dir) && substr($upload_dir,-1,1) == '/' + ? substr($upload_dir,0,-1) + : $upload_dir; + $upload_dir = !empty($upload_dir) ? $upload_dir : 'assets/uploads/files'; + + /** Check if the upload Url folder exists. If not then throw an exception **/ + if (!is_dir(FCPATH.$upload_dir)) { + throw new Exception("It seems that the folder \"".FCPATH.$upload_dir."\" for the field name + \"".$field_name."\" doesn't exists. Please create the folder and try again."); + } + + $this->upload_fields[$field_name] = (object) array( + 'field_name' => $field_name, + 'upload_path' => $upload_dir, + 'allowed_file_types' => $allowed_file_types, + 'encrypted_field_name' => $this->_unique_field_name($field_name)); + return $this; + } +} + +if(defined('CI_VERSION')) +{ + $ci = &get_instance(); + $ci->load->library('Form_validation'); + + class grocery_CRUD_Form_validation extends CI_Form_validation{ + + public $CI; + public $_field_data = array(); + public $_config_rules = array(); + public $_error_array = array(); + public $_error_messages = array(); + public $_error_prefix = '

    '; + public $_error_suffix = '

    '; + public $error_string = ''; + public $_safe_form_data = FALSE; + } +} + +/* + * jQuery File Upload Plugin PHP Example 5.5 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2010, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +class UploadHandler +{ + private $options; + public $default_config_path = null; + + function __construct($options=null) { + $this->options = array( + 'script_url' => $this->getFullUrl().'/'.basename(__FILE__), + 'upload_dir' => dirname(__FILE__).'/files/', + 'upload_url' => $this->getFullUrl().'/files/', + 'param_name' => 'files', + // The php.ini settings upload_max_filesize and post_max_size + // take precedence over the following max_file_size setting: + 'max_file_size' => null, + 'min_file_size' => 1, + 'accept_file_types' => '/.+$/i', + 'max_number_of_files' => null, + // Set the following option to false to enable non-multipart uploads: + 'discard_aborted_uploads' => true, + // Set to true to rotate images based on EXIF meta data, if available: + 'orient_image' => false, + 'image_versions' => array( + // Uncomment the following version to restrict the size of + // uploaded images. You can also add additional versions with + // their own upload directories: + /* + 'large' => array( + 'upload_dir' => dirname(__FILE__).'/files/', + 'upload_url' => dirname($_SERVER['PHP_SELF']).'/files/', + 'max_width' => 1920, + 'max_height' => 1200 + ), + + 'thumbnail' => array( + 'upload_dir' => dirname(__FILE__).'/thumbnails/', + 'upload_url' => $this->getFullUrl().'/thumbnails/', + 'max_width' => 80, + 'max_height' => 80 + ) + */ + ) + ); + if ($options) { + // Or else for PHP >= 5.3.0 use: $this->options = array_replace_recursive($this->options, $options); + foreach($options as $option_name => $option) + { + $this->options[$option_name] = $option; + } + } + } + + function getFullUrl() { + return + (isset($_SERVER['HTTPS']) ? 'https://' : 'http://'). + (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' : ''). + (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. + (isset($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] === 443 || + $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). + substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); + } + + private function get_file_object($file_name) { + $file_path = $this->options['upload_dir'].$file_name; + if (is_file($file_path) && $file_name[0] !== '.') { + $file = new stdClass(); + $file->name = $file_name; + $file->size = filesize($file_path); + $file->url = $this->options['upload_url'].rawurlencode($file->name); + foreach($this->options['image_versions'] as $version => $options) { + if (is_file($options['upload_dir'].$file_name)) { + $file->{$version.'_url'} = $options['upload_url'] + .rawurlencode($file->name); + } + } + $file->delete_url = $this->options['script_url'] + .'?file='.rawurlencode($file->name); + $file->delete_type = 'DELETE'; + return $file; + } + return null; + } + + private function get_file_objects() { + return array_values(array_filter(array_map( + array($this, 'get_file_object'), + scandir($this->options['upload_dir']) + ))); + } + + private function create_scaled_image($file_name, $options) { + $file_path = $this->options['upload_dir'].$file_name; + $new_file_path = $options['upload_dir'].$file_name; + list($img_width, $img_height) = @getimagesize($file_path); + if (!$img_width || !$img_height) { + return false; + } + $scale = min( + $options['max_width'] / $img_width, + $options['max_height'] / $img_height + ); + if ($scale > 1) { + $scale = 1; + } + $new_width = $img_width * $scale; + $new_height = $img_height * $scale; + $new_img = @imagecreatetruecolor($new_width, $new_height); + switch (strtolower(substr(strrchr($file_name, '.'), 1))) { + case 'jpg': + case 'jpeg': + $src_img = @imagecreatefromjpeg($file_path); + $write_image = 'imagejpeg'; + break; + case 'gif': + @imagecolortransparent($new_img, @imagecolorallocate($new_img, 0, 0, 0)); + $src_img = @imagecreatefromgif($file_path); + $write_image = 'imagegif'; + break; + case 'png': + @imagecolortransparent($new_img, @imagecolorallocate($new_img, 0, 0, 0)); + @imagealphablending($new_img, false); + @imagesavealpha($new_img, true); + $src_img = @imagecreatefrompng($file_path); + $write_image = 'imagepng'; + break; + default: + $src_img = $image_method = null; + } + $success = $src_img && @imagecopyresampled( + $new_img, + $src_img, + 0, 0, 0, 0, + $new_width, + $new_height, + $img_width, + $img_height + ) && $write_image($new_img, $new_file_path); + // Free up memory (imagedestroy does not delete files): + @imagedestroy($src_img); + @imagedestroy($new_img); + return $success; + } + + private function has_error($uploaded_file, $file, $error) { + if ($error) { + switch($error) { + case UPLOAD_ERR_INI_SIZE: + return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; + break; + case UPLOAD_ERR_PARTIAL: + return 'The uploaded file was only partially uploaded.'; + break; + case UPLOAD_ERR_NO_FILE: + return 'No file was uploaded.'; + break; + case UPLOAD_ERR_CANT_WRITE: + return 'Failed to write file to disk.'; + break; + case UPLOAD_ERR_EXTENSION: + return 'File upload stopped by extension.'; + break; + default: + return $error; + break; + } + } + if (!preg_match($this->options['accept_file_types'], $file->name)) { + return 'acceptFileTypes'; + } + if ($uploaded_file && is_uploaded_file($uploaded_file)) { + $file_size = filesize($uploaded_file); + } else { + $file_size = $_SERVER['CONTENT_LENGTH']; + } + + if ($this->options['max_file_size'] && ( + $file_size > $this->options['max_file_size'] || + $file->size > $this->options['max_file_size']) + ) { + return 'maxFileSize'; + } + if ($this->options['min_file_size'] && + $file_size < $this->options['min_file_size']) { + return 'minFileSize'; + } + if (is_int($this->options['max_number_of_files']) && ( + count($this->get_file_objects()) >= $this->options['max_number_of_files']) + ) { + return 'maxNumberOfFiles'; + } + return $error; + } + + private function trim_file_name($name, $type) { + // Remove path information and dots around the filename, to prevent uploading + // into different directories or replacing hidden system files. + // Also remove control characters and spaces (\x00..\x20) around the filename: + $file_name = trim(basename(stripslashes($name)), ".\x00..\x20"); + // Add missing file extension for known image types: + if (strpos($file_name, '.') === false && + preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) { + $file_name .= '.'.$matches[1]; + } + + //Ensure that we don't have disallowed characters and add a unique id just to ensure that the file name will be unique + $file_name = substr(uniqid(),-5).'-'.$this->_transliterate_characters($file_name); + + //all the characters has to be lowercase + $file_name = strtolower($file_name); + + return $file_name; + } + + private function _transliterate_characters($file_name) + { + include($this->default_config_path.'/translit_chars.php'); + if ( isset($translit_characters)) + { + $file_name = preg_replace(array_keys($translit_characters), array_values($translit_characters), $file_name); + } + + $file_name = preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name); + $file_name = str_replace(" ", "-", $file_name); + + return preg_replace('/\-+/', '-', trim($file_name, '-')); + } + + private function orient_image($file_path) { + $exif = exif_read_data($file_path); + $orientation = intval(@$exif['Orientation']); + if (!in_array($orientation, array(3, 6, 8))) { + return false; + } + $image = @imagecreatefromjpeg($file_path); + switch ($orientation) { + case 3: + $image = @imagerotate($image, 180, 0); + break; + case 6: + $image = @imagerotate($image, 270, 0); + break; + case 8: + $image = @imagerotate($image, 90, 0); + break; + default: + return false; + } + $success = imagejpeg($image, $file_path); + // Free up memory (imagedestroy does not delete files): + @imagedestroy($image); + return $success; + } + + private function handle_file_upload($uploaded_file, $name, $size, $type, $error) { + $file = new stdClass(); + $file->name = $this->trim_file_name($name, $type); + $file->size = intval($size); + $file->type = $type; + $error = $this->has_error($uploaded_file, $file, $error); + if (!$error && $file->name) { + $file_path = $this->options['upload_dir'].$file->name; + $append_file = !$this->options['discard_aborted_uploads'] && + is_file($file_path) && $file->size > filesize($file_path); + clearstatcache(); + if ($uploaded_file && is_uploaded_file($uploaded_file)) { + // multipart/formdata uploads (POST method uploads) + if ($append_file) { + file_put_contents( + $file_path, + fopen($uploaded_file, 'r'), + FILE_APPEND + ); + } else { + move_uploaded_file($uploaded_file, $file_path); + } + } else { + // Non-multipart uploads (PUT method support) + file_put_contents( + $file_path, + fopen('php://input', 'r'), + $append_file ? FILE_APPEND : 0 + ); + } + $file_size = filesize($file_path); + if ($file_size === $file->size) { + if ($this->options['orient_image']) { + $this->orient_image($file_path); + } + $file->url = $this->options['upload_url'].rawurlencode($file->name); + foreach($this->options['image_versions'] as $version => $options) { + if ($this->create_scaled_image($file->name, $options)) { + $file->{$version.'_url'} = $options['upload_url'] + .rawurlencode($file->name); + } + } + } else if ($this->options['discard_aborted_uploads']) { + unlink($file_path); + $file->error = "It seems that this user doesn't have permissions to upload to this folder"; + } + $file->size = $file_size; + $file->delete_url = $this->options['script_url'] + .'?file='.rawurlencode($file->name); + $file->delete_type = 'DELETE'; + } else { + $file->error = $error; + } + return $file; + } + + public function get() { + $file_name = isset($_REQUEST['file']) ? + basename(stripslashes($_REQUEST['file'])) : null; + if ($file_name) { + $info = $this->get_file_object($file_name); + } else { + $info = $this->get_file_objects(); + } + header('Content-type: application/json'); + echo json_encode($info); + } + + public function post() { + if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') { + return $this->delete(); + } + $upload = isset($_FILES[$this->options['param_name']]) ? + $_FILES[$this->options['param_name']] : null; + $info = array(); + if ($upload && is_array($upload['tmp_name'])) { + foreach ($upload['tmp_name'] as $index => $value) { + $info[] = $this->handle_file_upload( + $upload['tmp_name'][$index], + isset($_SERVER['HTTP_X_FILE_NAME']) ? + $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index], + isset($_SERVER['HTTP_X_FILE_SIZE']) ? + $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'][$index], + isset($_SERVER['HTTP_X_FILE_TYPE']) ? + $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'][$index], + $upload['error'][$index] + ); + } + } elseif ($upload || isset($_SERVER['HTTP_X_FILE_NAME'])) { + $info[] = $this->handle_file_upload( + isset($upload['tmp_name']) ? $upload['tmp_name'] : null, + isset($_SERVER['HTTP_X_FILE_NAME']) ? + $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'], + isset($_SERVER['HTTP_X_FILE_SIZE']) ? + $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'], + isset($_SERVER['HTTP_X_FILE_TYPE']) ? + $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'], + isset($upload['error']) ? $upload['error'] : null + ); + } + header('Vary: Accept'); + + $redirect = isset($_REQUEST['redirect']) ? + stripslashes($_REQUEST['redirect']) : null; + if ($redirect) { + header('Location: '.sprintf($redirect, rawurlencode($json))); + return; + } + if (isset($_SERVER['HTTP_ACCEPT']) && + (strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)) { + header('Content-type: application/json'); + } else { + header('Content-type: text/plain'); + } + return $info; + } + + public function delete() { + $file_name = isset($_REQUEST['file']) ? + basename(stripslashes($_REQUEST['file'])) : null; + $file_path = $this->options['upload_dir'].$file_name; + $success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path); + if ($success) { + foreach($this->options['image_versions'] as $version => $options) { + $file = $options['upload_dir'].$file_name; + if (is_file($file)) { + unlink($file); + } + } + } + header('Content-type: application/json'); + echo json_encode($success); + } + +} diff --git a/application/libraries/Rdf.php b/application/libraries/Rdf.php new file mode 100644 index 000000000..76e200fc3 --- /dev/null +++ b/application/libraries/Rdf.php @@ -0,0 +1,18 @@ +image_moo->load("file")->resize(64,40)->save("thumb")->resize(640,480)->save("medium"); + * if ($this->image_moo->errors) print $this->image_moo->display_errors(); + * + * COLOURS! + * Any function that can take a colour as a parameter can take "#RGB", "#RRGGBB" or an array(R,G,B) + * + * image manipulation functions + * ----------------------------------------------------------------------------- + * load($x) - Loads an image file specified by $x - JPG, PNG, GIF supported + * save($x) - Saved the manipulated image (if applicable) to file $x - JPG, PNG, GIF supported + * save_pa($prepend="", $append="", $overwrite=FALSE) - Saves using the original image name but with prepend and append text, e.g. load('moo.jpg')->save_pa('pre_','_app') would save as filename pre_moo_app.jpg + * save_dynamic($filename="") - Saves as a stream output, use filename to return png/jpg/gif etc., default is jpeg + * resize($x,$y,$pad=FALSE) - Proportioanlly resize original image using the bounds $x and $y, if padding is set return image is as defined centralised using BG colour + * resize_crop($x,$y) - Proportioanlly resize original image using the bounds $x and $y but cropped to fill dimensions + * stretch($x,$y) - Take the original image and stretch it to fill new dimensions $x $y + * crop($x1,$y1,$x2,$y2) - Crop the original image using Top left, $x1,$y1 to bottom right $x2,y2. New image size =$x2-x1 x $y2-y1 + * rotate($angle) - Rotates the work image by X degrees, normally 90,180,270 can be any angle.Excess filled with background colour + * load_watermark($filename, $transparent_x=0, $transparent_y=0) - Loads the specified file as the watermark file, if using PNG32/24 use x,y to specify direct positions of colour to use as index + * make_watermark_text($text, $fontfile, $size=16, $colour="#ffffff", $angle=0) - Creates a text watermark + * watermark($position, $offset=8, $abs=FALSE) - Use the loaded watermark, or created text to place a watermark. $position works like NUM PAD key layout, e.g. 7=Top left, 3=Bottom right $offset is the padding/indentation, if $abs is true then use $positiona and $offset as direct values to watermark placement + * border($width,$colour="#000") - Draw a border around the output image X pixels wide in colour specified + * border_3d($width,$rot=0,$opacity=30) - Draw a 3d border (opaque) around the current image $width wise in 0-3 rot positions, $opacity allows you to change how much it effects the picture + * filter($function, $arg1=NULL, $arg2=NULL, $arg3=NULL, $arg4=NULL) -Runs the standard imagefilter GD2 command, see http://www.php.net/manual/en/function.imagefilter.php for details + * round($radius,$invert=FALSE,$corners(array[top left, top right, bottom right, bottom left of true or False)="") default is all on and normal rounding + * shadow($size=4, $direction=3, $colour="#444") - Size in pixels, note that the image will increase by this size, so resize(400,400)->shadoe(4) will give an image 404 pixels in size, Direction works on teh keypad basis like the watermark, so 3 is bottom right, $color if the colour of the shadow. + * ----------------------------------------------------------------------------- + * image helper functions + * display_errors($open = '

    ', $close = '

    ') - Display errors as Ci standard style + * set_jpeg_quality($x) - quality to wrte jpeg files in for save, default 75 (1-100) + * set_watermark_transparency($x) - the opacity of the watermark 1-100, 1-just about see, 100=solid + * check_gd() - Run to see if you server can use this library + * clear_temp() - Call to clear the temp changes using the master image again + * clear() - Clears all images in memory + * ----------------------------------------------------------------------------- + * + * KNOWN BUGS + * make_watermark_text does not deal with rotation angle correctly, box is cropped + * + * TO DO + * + * THANKS + * Matja for poiting out the save_pa bug (should of tested it!) + * Cahva for posting yet another bug in the save_pa (Man I can be silly sometimes!) + * Cole spotting the resize flaw and providing a fix + * + */ + +class Image_moo +{ + // image vars + private $main_image=""; + private $watermark_image; + private $temp_image; + private $jpeg_quality=75; + private $background_colour="#ffffff"; + private $watermark_method; + + // other + private $filename=""; + + // watermark stuff, opacity + private $watermark_transparency=50; + + // reported errors + public $errors=FALSE; + private $error_msg = array(); + + // image info + public $width=0; + public $height=0; + + function Image_moo() + //---------------------------------------------------------------------------------------------------------- + // create stuff here as needed + //---------------------------------------------------------------------------------------------------------- + { + log_message('debug', "Image Moo Class Initialized"); + } + + private function _clear_errors() + //---------------------------------------------------------------------------------------------------------- + // load a resource + //---------------------------------------------------------------------------------------------------------- + { + $this->error_msg = array(); + } + + private function set_error($msg) + //---------------------------------------------------------------------------------------------------------- + // Set an error message + //---------------------------------------------------------------------------------------------------------- + { + $this->errors = TRUE; + $this->error_msg[] = $msg; + } + + public function display_errors($open = '

    ', $close = '

    ') + //---------------------------------------------------------------------------------------------------------- + // returns the errors formatted as needed, same as CI doed + //---------------------------------------------------------------------------------------------------------- + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + return $str; + } + + public function check_gd() + //---------------------------------------------------------------------------------------------------------- + // verification util to see if you can use image_moo + //---------------------------------------------------------------------------------------------------------- + { + if ( ! extension_loaded('gd')) + { + if ( ! dl('gd.so')) + { + $this->set_error('GD library does not appear to be loaded'); + return FALSE; + } + } + if (function_exists('gd_info')) + { + $gdarray = @gd_info(); + $versiontxt = ereg_replace('[[:alpha:][:space:]()]+', '', $gdarray['GD Version']); + $versionparts=explode('.',$versiontxt); + if ($versionparts[0]=="2") + { + return TRUE; + } + else + { + $this->set_error('Requires GD2, this reported as '.$versiontxt); + return FALSE; + } + } + else + { + $this->set_error('Could not verify GD version'); + return FALSE; + } + } + + private function _check_image() + //---------------------------------------------------------------------------------------------------------- + // checks that we have an image loaded + //---------------------------------------------------------------------------------------------------------- + { + if (!is_resource($this->main_image)) + { + $this->set_error("No main image loaded!"); + return FALSE; + } + else + { + return TRUE; + } + } + + function save_dynamic($filename="") + //---------------------------------------------------------------------------------------------------------- + // Saves the temp image as a dynamic image + // e.g. direct output to the browser + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // ok, lets go! + if ($filename=="") $filename=rand(1000,999999).".jpg"; // send as jpeg + $ext = strtoupper(pathinfo($filename, PATHINFO_EXTENSION)); + header("Content-disposition: filename=$filename;"); + header('Content-transfer-Encoding: binary'); + header('Last-modified: '.gmdate('D, d M Y H:i:s')); + switch ($ext) + { + case "GIF" : + header("Content-type: image/gif"); + imagegif($this->temp_image); + return $this; + break; + case "JPG" : + case "JPEG" : + header("Content-type: image/jpeg"); + imagejpeg($this->temp_image, NULL, $this->jpeg_quality); + return $this; + break; + case "PNG" : + header("Content-type: image/png"); + imagepng($this->temp_image); + return $this; + break; + } + $this->set_error('Unable to save, extension not GIF/JPEG/JPG/PNG'); + return $this; + } + + function save_pa($prepend="", $append="", $overwrite=FALSE) + //---------------------------------------------------------------------------------------------------------- + // Saves the temp image as the filename specified, + // overwrite = true of false + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // get current file parts + $parts=pathinfo($this->filename); + + // save + $this->save($parts["dirname"].'/'.$prepend.$parts['filename'].$append.'.'.$parts["extension"], $overwrite); + + return $this; + } + + function save($filename,$overwrite=FALSE) + //---------------------------------------------------------------------------------------------------------- + // Saves the temp image as the filename specified, + // overwrite = true of false + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // check if it already exists + if (!$overwrite) + { + // don't overwrite, so check for file + if (file_exists($filename)) + { + $this->set_error('File exists, overwrite is FALSE, could not save over file '.$filename); + return $this; + } + } + + // find out the type of file to save + $ext = strtoupper(pathinfo($filename, PATHINFO_EXTENSION)); + switch ($ext) + { + case "GIF" : + imagegif($this->temp_image, $filename); + return $this; + break; + case "JPG" : + case "JPEG" : + imagejpeg($this->temp_image, $filename, $this->jpeg_quality); + return $this; + break; + case "PNG" : + imagepng($this->temp_image, $filename); + return $this; + break; + } + + // invalid filetype?! + $this->set_error('Do no know what '.$ext.' filetype is in filename '.$filename); + return $this; + } + + private function _load_image($filename) + //---------------------------------------------------------------------------------------------------------- + // private function to load a resource + //---------------------------------------------------------------------------------------------------------- + { + // check the request file can be located + if (!file_exists($filename)) + { + $this->set_error('Could not locate file '.$filename); + return FALSE; + } + + // get image info about this file + $image_info=getimagesize($filename); + + // load file depending on mimetype + switch ($image_info["mime"]) + { + case "image/gif" : + return imagecreatefromgif($filename); + break; + case "image/jpeg" : + return imagecreatefromjpeg($filename); + break; + case "image/png" : + return imagecreatefrompng($filename); + break; + } + + // invalid filetype?! + $this->set_error('Unable to load '.$filename.' filetype '.$image_info["mime"].'not recognised'); + return FALSE; + } + + public function load($filename) + //---------------------------------------------------------------------------------------------------------- + // Load an image, public function + //---------------------------------------------------------------------------------------------------------- + { + // new image, reset error messages + $this->_clear_errors(); + + // remove temporary image stored + $this->clear_temp(); + + // save filename + $this->filename=$filename; + + // reset width and height + $this->width = 0; + $this->height = 0; + + // load it + $this->main_image = $this->_load_image($filename); + + // no error, then get the dminesions set + if ($this->main_image <> FALSE) + { + $this->width = imageSX($this->main_image); + $this->height = imageSY($this->main_image); + } + + // return the object + return $this; + } + + public function load_watermark($filename, $transparent_x=NULL, $transparent_y=NULL) + //---------------------------------------------------------------------------------------------------------- + // Load an image, public function + //---------------------------------------------------------------------------------------------------------- + { + if(is_resource($this->watermark_image)) imagedestroy($this->watermark_image); + $this->watermark_image = $this->_load_image($filename); + + if(is_resource($this->watermark_image)) + { + $this->watermark_method = 1; + if(($transparent_x <> NULL) AND ($transparent_y <> NULL)) + { + // get the top left corner colour allocation + $tpcolour = imagecolorat($this->watermark_image, $transparent_x, $transparent_y); + + // set this as the transparent colour + imagecolortransparent($this->watermark_image, $tpcolour); + + // $set diff method + $this->watermark_method = 2; + } + } + + // return this object + return $this; + } + + public function set_watermark_transparency($transparency=50) + //---------------------------------------------------------------------------------------------------------- + // Sets the quality that jpeg will be saved at + //---------------------------------------------------------------------------------------------------------- + { + $this->watermark_transparency = $transparency; + return $this; + } + + public function set_background_colour($colour="#ffffff") + //---------------------------------------------------------------------------------------------------------- + // Sets teh background colour to use on rotation and padding for resize + //---------------------------------------------------------------------------------------------------------- + { + $this->background_colour = $this->_html2rgb($colour); + return $this; + } + + public function set_jpeg_quality($quality=75) + //---------------------------------------------------------------------------------------------------------- + // Sets the quality that jpeg will be saved at + //---------------------------------------------------------------------------------------------------------- + { + $this->jpeg_quality = $quality; + return $this; + } + + private function _copy_to_temp_if_needed() + //---------------------------------------------------------------------------------------------------------- + // If temp image is empty, e.g. not resized or done anything then just copy main image + //---------------------------------------------------------------------------------------------------------- + { + if (!is_resource($this->temp_image)) + { + // create a temp based on new dimensions + $this->temp_image = imagecreatetruecolor($this->width, $this->height); + + // check it + if(!is_resource($this->temp_image)) + { + $this->set_error('Unable to create temp image sized '.$this->width.' x '.$this->height); + return FALSE; + } + + // copy image to temp workspace + imagecopy($this->temp_image, $this->main_image, 0, 0, 0, 0, $this->width, $this->height); + } + } + + public function clear() + //---------------------------------------------------------------------------------------------------------- + // clear everything! + //---------------------------------------------------------------------------------------------------------- + { + if(is_resource($this->main_image)) imagedestroy($this->main_image); + if(is_resource($this->watermark_image)) imagedestroy($this->watermark_image); + if(is_resource($this->temp_image)) imagedestroy($this->temp_image); + return $this; + } + + public function clear_temp() + //---------------------------------------------------------------------------------------------------------- + // you may want to revert back to teh original image to work on, e.g. watermark, this clears temp + //---------------------------------------------------------------------------------------------------------- + { + if(is_resource($this->temp_image)) imagedestroy($this->temp_image); + return $this; + } + + public function resize_crop($mw,$mh) + //---------------------------------------------------------------------------------------------------------- + // take main image and resize to tempimage using EXACT boundaries mw,mh (max width and max height) + // this is proportional and crops the image centrally to fit + //---------------------------------------------------------------------------------------------------------- + { + if (!$this->_check_image()) return $this; + + // clear temp image + $this->clear_temp(); + + // create a temp based on new dimensions + $this->temp_image = imagecreatetruecolor($mw,$mh); + + // check it + if(!is_resource($this->temp_image)) + { + $this->set_error('Unable to create temp image sized '.$mw.' x '.$mh); + return $this; + } + + // work out best positions for copy + $wx=$this->width / $mw; + $wy=$this->height / $mh; + if ($wx >= $wy) + { + // use full height + $sy = 0; + $sy2 = $this->height; + + // calcs + $calc_width = $mw * $wy; + $sx = ($this->width - $calc_width) / 2; + $sx2 = $calc_width; + } + else + { + // use full width + $sx = 0; + $sx2 = $this->width; + + // calcs + $calc_height = $mh * $wx; + $sy = ($this->height - $calc_height) / 2; + $sy2 = $calc_height; + } + + // copy section + imagecopyresampled($this->temp_image, $this->main_image, 0, 0, $sx, $sy, $mw, $mh, $sx2, $sy2); + return $this; + } + + public function resize($mw, $mh, $pad=FALSE) + //---------------------------------------------------------------------------------------------------------- + // take main image and resize to tempimage using boundaries mw,mh (max width or max height) + // this is proportional, pad to true will set it in the middle of area size + //---------------------------------------------------------------------------------------------------------- + { + if (!$this->_check_image()) return $this; + + // calc new dimensions + if( $this->width > $mw || $this->height > $mh ) { +// if( $this->width > $this->height ) { could calc wronf - Cole Thorsen swapped to his suggestion + if( ($this->width / $this->height) > ($mw / $mh) ) { + $tnw = $mw; + $tnh = $tnw * $this->height / $this->width; + } else { + $tnh = $mh; + $tnw = $tnh * $this->width / $this->height; + } + } else { + $tnw = $this->width; + $tnh = $this->height; + } + // clear temp image + $this->clear_temp(); + + // create a temp based on new dimensions + if ($pad) + { + $tx = $mw; + $ty = $mh; + $px = ($mw - $tnw) / 2; + $py = ($mh - $tnh) / 2; + } + else + { + $tx = $tnw; + $ty = $tnh; + $px = 0; + $py = 0; + } + $this->temp_image = imagecreatetruecolor($tx,$ty); + + // check it + if(!is_resource($this->temp_image)) + { + $this->set_error('Unable to create temp image sized '.$tx.' x '.$ty); + return $this; + } + + // if padding, fill background + if ($pad) + { + $col = $this->_html2rgb($this->background_colour); + $bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); + imagefilledrectangle($this->temp_image, 0, 0, $tx, $ty, $bg); + } + + // copy resized + imagecopyresampled($this->temp_image, $this->main_image, $px, $py, 0, 0, $tnw, $tnh, $this->width, $this->height); + return $this; + } + + public function stretch($mw,$mh) + //---------------------------------------------------------------------------------------------------------- + // take main image and resize to tempimage using boundaries mw,mh (max width or max height) + // does not retain proportions + //---------------------------------------------------------------------------------------------------------- + { + if (!$this->_check_image()) return $this; + + // clear temp image + $this->clear_temp(); + + // create a temp based on new dimensions + $this->temp_image = imagecreatetruecolor($mw, $mh); + + // check it + if(!is_resource($this->temp_image)) + { + $this->set_error('Unable to create temp image sized '.$mh.' x '.$mw); + return $this; + } + + // copy resized (stethced, proportions not kept); + imagecopyresampled($this->temp_image, $this->main_image, 0, 0, 0, 0, $mw, $mh, $this->width, $this->height); + return $this; + } + + public function crop($x1, $y1, $x2, $y2) + //---------------------------------------------------------------------------------------------------------- + // crop the main image to temp image using coords + //---------------------------------------------------------------------------------------------------------- + { + if (!$this->_check_image()) return $this; + + // clear temp image + $this->clear_temp(); + + // check dimensions + if ($x1 < 0 || $y1 < 0 || $x2 - $x1 > $this->width || $y2 - $y1 > $this->height) + { + $this->set_error('Invalid crop dimensions, either - passed or width/heigh too large '.$x1.'/'.$y1.' x '.$x2.'/'.$y2); + return $this; + } + + // create a temp based on new dimensions + $this->temp_image = imagecreatetruecolor($x2-$x1, $y2-$y1); + + // check it + if(!is_resource($this->temp_image)) + { + $this->set_error('Unable to create temp image sized '.$x2-$x1.' x '.$y2-$y1); + return $this; + } + + // copy cropped portion + imagecopy($this->temp_image, $this->main_image, 0, 0, $x1, $y1, $x2 - $x1, $y2 - $y1); + return $this; + } + + private function _html2rgb($colour) + //---------------------------------------------------------------------------------------------------------- + // convert #aa0011 to a php colour array + //---------------------------------------------------------------------------------------------------------- + { + if (is_array($colour)) + { + if (count($colour)==3) return $colour; // rgb sent as an array so use it + $this->set_error('Colour error, array sent not 3 elements, expected array(r,g,b)'); + return false; + } + if ($colour[0] == '#') + $colour = substr($colour, 1); + + if (strlen($colour) == 6) + { + list($r, $g, $b) = array($colour[0].$colour[1], + $colour[2].$colour[3], + $colour[4].$colour[5]); + } + elseif (strlen($colour) == 3) + { + list($r, $g, $b) = array($colour[0].$colour[0], $colour[1].$colour[1], $colour[2].$colour[2]); + } + else + { + $this->set_error('Colour error, value sent not #RRGGBB or RRGGBB, and not array(r,g,b)'); + return false; + } + + $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); + + return array($r, $g, $b); + } + + public function rotate($angle) + //---------------------------------------------------------------------------------------------------------- + // rotate an image bu 0 / 90 / 180 / 270 degrees + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // set the colour + $col = $this->_html2rgb($$this->background_colour); + $bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); + + // rotate as needed + $this->temp_image = imagerotate($this->temp_image, $angle, $bg); + return $this; + } + + public function make_watermark_text($text, $fontfile, $size=16, $colour="#ffffff", $angle=0) + //---------------------------------------------------------------------------------------------------------- + // create an image from text that can be applied as a watermark + // text is the text to write, $fontile is a ttf file that will be used $size=font size, $colour is the colour of text + //---------------------------------------------------------------------------------------------------------- + { + // check font file can be found + if (!file_exists($fontfile)) + { + $this->set_error('Could not locate font file "'.$fontfile.'"'); + return $this; + } + + // validate we loaded a main image + if (!$this->_check_image()) + { + $remove = TRUE; + // no image loaded so make temp image to use + $this->main_image = imagecreatetruecolor(1000,1000); + } + else + { + $remove = FALSE; + } + + // work out text dimensions + $bbox = imageftbbox($size, $angle, $fontfile, $text); + $bw = abs($bbox[4] - $bbox[0]) + 1; + $bh = abs($bbox[1] - $bbox[5]) + 1; + $bl = $bbox[1]; + + // use this to create watermark image + if(is_resource($this->watermark_image)) imagedestroy($this->watermark_image); + $this->watermark_image = imagecreatetruecolor($bw, $bh); + + // set colours + $col = $this->_html2rgb($colour); + $font_col = imagecolorallocate($this->watermark_image, $col[0], $col[1], $col[2]); + $bg_col = imagecolorallocate($this->watermark_image, 127, 128, 126); + + // set method to use + $this->watermark_method = 2; + + // create bg + imagecolortransparent($this->watermark_image, $bg_col); + imagefilledrectangle($this->watermark_image, 0,0, $bw, $bh, $bg_col); + + // write text to watermark + imagefttext($this->watermark_image, $size, $angle, 0, $bh-$bl, $font_col, $fontfile, $text); + + if ($remove) imagedestroy($this->main_image); + return $this; + } + + public function watermark($position, $offset=8, $abs=FALSE) + //---------------------------------------------------------------------------------------------------------- + // add a watermark to the image + // position works like a keypad e.g. + // 7 8 9 + // 4 5 6 + // 1 2 3 + // offset moves image inwards by x pixels + // if abs is set then $position, $offset = direct placement coords + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // validate we have a watermark + if(!is_resource($this->watermark_image)) + { + $this->set_error("Can't watermark image, no watermark loaded/created"); + return $this; + } + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // get watermark width + $wm_w = imageSX($this->watermark_image); + $wm_h = imageSY($this->watermark_image); + + // get temp widths + $temp_w = imageSX($this->temp_image); + $temp_h = imageSY($this->temp_image); + + // check watermark will fit! + if ($wm_w > $temp_w || $wm_h > $temp_h) + { + $this->set_error("Watermark is larger than image. WM: $wm_w x $wm_h Temp image: $temp_w x $temp_h"); + return $this; + } + + if ($abs) + { + // direct placement + $dest_x = $position; + $dest_y = $offset; + } + else + { + // do X position + switch ($position) + { + // x left + case "7": + case "4": + case "1": + $dest_x = $offset; + break; + // x middle + case "8": + case "5": + case "2": + $dest_x = ($temp_w - $wm_w) /2 ; + break; + // x right + case "9": + case "6": + case "3": + $dest_x = $temp_w - $offset - $wm_w; + break; + default: + $dest_x = $offset; + $this->set_error("Watermark position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); + } + // do y position + switch ($position) + { + // y top + case "7": + case "8": + case "9": + $dest_y = $offset; + break; + // y middle + case "4": + case "5": + case "6": + $dest_y = ($temp_h - $wm_h) /2 ; + break; + // y bottom + case "1": + case "2": + case "3": + $dest_y = $temp_h - $offset - $wm_h; + break; + default: + $dest_y = $offset; + $this->set_error("Watermark position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); + } + + } + + // copy over temp image to desired location + if ($this->watermark_method == 1) + { + // use back methods to do this, taken from php help files + //$this->imagecopymerge_alpha($this->temp_image, $this->watermark_image, $dest_x, $dest_y, 0, 0, $wm_w, $wm_h, $this->watermark_transparency); + + $opacity=$this->watermark_transparency; + + // creating a cut resource + $cut = imagecreatetruecolor($wm_w, $wm_h); + + // copying that section of the background to the cut + imagecopy($cut, $this->temp_image, 0, 0, $dest_x, $dest_y, $wm_w, $wm_h); + + // inverting the opacity + $opacity = 100 - $opacity; + + // placing the watermark now + imagecopy($cut, $this->watermark_image, 0, 0, 0, 0, $wm_w, $wm_h); + imagecopymerge($this->temp_image, $cut, $dest_x, $dest_y, 0, 0, $wm_w, $wm_h, $opacity); + + } + else + { + // use normal with selected transparency colour + imagecopymerge($this->temp_image, $this->watermark_image, $dest_x, $dest_y, 0, 0, $wm_w, $wm_h, $this->watermark_transparency); + } + + return $this; + } + + public function border($width=5,$colour="#000") + //---------------------------------------------------------------------------------------------------------- + // add a solidborder frame, coloured $colour to the image + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // get colour set for temp image + $col = $this->_html2rgb($colour); + $border_col = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); + + // get temp widths + $temp_w = imageSX($this->temp_image); + $temp_h = imageSY($this->temp_image); + + // do border + for($x=0;$x<$width;$x++) + { + imagerectangle($this->temp_image, $x, $x, $temp_w-$x-1, $temp_h-$x-1, $border_col); + } + + // return object + return $this; + } + + public function border_3d($width=5,$rot=0,$opacity=30) + //---------------------------------------------------------------------------------------------------------- + // overlay a black white border to make it look 3d + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // get temp widths + $temp_w = imageSX($this->temp_image); + $temp_h = imageSY($this->temp_image); + + // create temp canvas to merge + $border_image = imagecreatetruecolor($temp_w, $temp_h); + + // create colours + $black = imagecolorallocate($border_image, 0, 0, 0); + $white = imagecolorallocate($border_image, 255, 255, 255); + switch ($rot) + { + case 1 : + $cols=array($white,$black,$white,$black); + break; + case 2 : + $cols=array($black,$black,$white,$white); + break; + case 3 : + $cols=array($black,$white,$black,$white); + break; + default : + $cols=array($white,$white,$black,$black); + } + $bg_col = imagecolorallocate($border_image, 127, 128, 126); + + // create bg + imagecolortransparent($border_image, $bg_col); + imagefilledrectangle($border_image, 0,0, $temp_w, $temp_h, $bg_col); + + // do border + for($x=0;$x<$width;$x++) + { + // top + imageline($border_image, $x, $x, $temp_w-$x-1, $x, $cols[0]); + // left + imageline($border_image, $x, $x, $x, $temp_w-$x-1, $cols[1]); + // bottom + imageline($border_image, $x, $temp_h-$x-1, $temp_w-1-$x, $temp_h-$x-1, $cols[3]); + // right + imageline($border_image, $temp_w-$x-1, $x, $temp_w-$x-1, $temp_h-$x-1, $cols[2]); + } + + // merg with temp image + imagecopymerge($this->temp_image, $border_image, 0, 0, 0, 0, $temp_w, $temp_h, $opacity); + + // clean up + imagedestroy($border_image); + + // return object + return $this; + } + + public function shadow($size=4, $direction=3, $colour="#444") + //---------------------------------------------------------------------------------------------------------- + // add a shadow to an image, this will INCREASE the size of the image + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // get the current size + $sx = imagesx($this->temp_image); + $sy = imagesy($this->temp_image); + + // new image + $bu_image = imagecreatetruecolor($sx, $sy); + + // check it + if(!is_resource($bu_image)) + { + $this->set_error('Unable to create shadow temp image sized '.$this->width.' x '.$this->height); + return FALSE; + } + + // copy the current image to memory + imagecopy($bu_image, $this->temp_image, 0, 0, 0, 0, $sx, $sy); + + imagedestroy($this->temp_image); + $this->temp_image = imagecreatetruecolor($sx+$size, $sy+$size); + + // fill background colour + $col = $this->_html2rgb($this->background_colour); + $bg = imagecolorallocate($this->temp_image, $col[0], $col[1], $col[2]); + imagefilledrectangle($this->temp_image, 0, 0, $sx+$size, $sy+$size, $bg); + + // work out position + // do X position + switch ($direction) + { + // x left + case "7": + case "4": + case "1": + $sh_x = 0; + $pic_x = $size; + break; + // x middle + case "8": + case "5": + case "2": + $sh_x = $size / 2; + $pic_x = $size / 2; + break; + // x right + case "9": + case "6": + case "3": + $sh_x = $size; + $pic_x = 0; + break; + default: + $sh_x = $size; + $pic_x = 0; + $this->set_error("Shadow position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); + } + // do y position + switch ($direction) + { + // y top + case "7": + case "8": + case "9": + $sh_y = 0; + $pic_y = $size; + break; + // y middle + case "4": + case "5": + case "6": + $sh_y = $size / 2; + $pic_y = $size / 2; + break; + // y bottom + case "1": + case "2": + case "3": + $sh_y = $size; + $pic_y = 0; + break; + default: + $sh_y = $size; + $pic_y = 0; + $this->set_error("Shadow position $position not in vlaid range 7,8,9 - 4,5,6 - 1,2,3"); + } + + // create the shadow + $shadowcolour = $this->_html2rgb($colour); + $shadow = imagecolorallocate($this->temp_image, $shadowcolour[0], $shadowcolour[1], $shadowcolour[2]); + imagefilledrectangle($this->temp_image, $sh_x, $sh_y, $sh_x+$sx-1, $sh_y+$sy-1, $shadow); + + // copy current image to correct location + imagecopy($this->temp_image, $bu_image, $pic_x, $pic_y, 0, 0, $sx, $sy); + + // clean up and desstroy temp image + imagedestroy($bu_image); + + //return object + return $this; + } + + public function filter($function, $arg1=NULL, $arg2=NULL, $arg3=NULL, $arg4=NULL) + //---------------------------------------------------------------------------------------------------------- + // allows you to use the inbulit gd2 image filters + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + if (!imagefilter($this->temp_image, $function, $arg1, $arg2, $arg3, $arg4)) + { + $this->set_error("Filter $function failed"); + } + + // return object + return $this; + } + + public function round($radius=5,$invert=False,$corners="") + //---------------------------------------------------------------------------------------------------------- + // adds rounded corners to the output + // using a quarter and rotating as you can end up with odd roudning if you draw a whole and use parts + //---------------------------------------------------------------------------------------------------------- + { + // validate we loaded a main image + if (!$this->_check_image()) return $this; + + // if no operations, copy it for temp save + $this->_copy_to_temp_if_needed(); + + // check input + if ($corners=="") $corners=array(True,True,True,True); + if (!is_array($corners) || count($corners)<>4) + { + $this->set_error("Round failed, expected an array of 4 items round(radius,tl,tr,br,bl)"); + return $this; + } + + // create corner + $corner = imagecreatetruecolor($radius, $radius); + + // turn on aa make it nicer + imageantialias($corner, true); + $col = $this->_html2rgb($this->background_colour); + + // use bg col for corners + $bg = imagecolorallocate($corner, $col[0], $col[1], $col[2]); + + // create our transparent colour + $xparent = imagecolorallocate($corner, 127, 128, 126); + imagecolortransparent($corner, $xparent); + if ($invert) + { + // fill and clear bits + imagefilledrectangle($corner, 0, 0, $radius, $radius, $xparent); + imagefilledellipse($corner, 0, 0, ($radius * 2)-1, ($radius * 2)-1, $bg); + } + else + { + // fill and clear bits + imagefilledrectangle($corner, 0, 0, $radius, $radius, $bg); + imagefilledellipse($corner, $radius, $radius, ($radius * 2) , ($radius * 2) , $xparent); + } + + // get temp widths + $temp_w = imageSX($this->temp_image); + $temp_h = imageSY($this->temp_image); + + // do corners + if ($corners[0]) imagecopymerge($this->temp_image, $corner, 0, 0, 0, 0, $radius, $radius, 100); + $corner = imagerotate($corner, 270, 0); + if ($corners[1]) imagecopymerge($this->temp_image, $corner, $temp_w-$radius, 0, 0, 0, $radius, $radius, 100); + $corner = imagerotate($corner, 270, 0); + if ($corners[2]) imagecopymerge($this->temp_image, $corner, $temp_w-$radius, $temp_h-$radius, 0, 0, $radius, $radius, 100); + $corner = imagerotate($corner, 270, 0); + if ($corners[3]) imagecopymerge($this->temp_image, $corner, 0, $temp_h-$radius, 0, 0, $radius, $radius, 100); + + // return object + return $this; + } + + +} +/* End of file image_moo.php */ +/* Location: .system/application/libraries/image_moo.php */ \ No newline at end of file diff --git a/application/libraries/index.html b/application/libraries/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/libraries/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/logs/index.html b/application/logs/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/logs/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/migrations/20160101010100_init.php b/application/migrations/20160101010100_init.php new file mode 100644 index 000000000..7e6d91d84 --- /dev/null +++ b/application/migrations/20160101010100_init.php @@ -0,0 +1,19 @@ +db->query('CREATE SCHEMA IF NOT EXISTS gis;'); + + } + + public function down() + { + //$this->db->query('DROP SCHEMA IF EXISTS gis;'); + } +} + diff --git a/application/migrations/20160101010101_pk_migrations.php b/application/migrations/20160101010101_pk_migrations.php new file mode 100644 index 000000000..78a5451a5 --- /dev/null +++ b/application/migrations/20160101010101_pk_migrations.php @@ -0,0 +1,21 @@ +db->table_exists('ci_migrations')) + { + $this->db->query('ALTER TABLE ci_migrations ADD CONSTRAINT pk_migrations PRIMARY KEY(version);'); + } + } + + public function down() + { + $this->db->query('ALTER TABLE ci_migrations DROP CONSTRAINT pk_migrations;'); + } +} + diff --git a/application/migrations/20160101010102_add_apikey.php b/application/migrations/20160101010102_add_apikey.php new file mode 100644 index 000000000..58632c167 --- /dev/null +++ b/application/migrations/20160101010102_add_apikey.php @@ -0,0 +1,51 @@ +dbforge->add_field(array( + 'apikey_id' => array( + 'type' => 'INT', + 'constraint' => 5, + 'unsigned' => TRUE, + 'auto_increment' => TRUE + ), + 'key' => array( + 'type' => 'VARCHAR', + 'constraint' => '100', + ), + 'level' => array( + 'type' => 'INT', + 'null' => TRUE, + ), + 'ignore_limits' => array( + 'type' => 'INT', + 'null' => TRUE, + ), + 'date_created' => array( + 'type' => 'DATE', + 'null' => TRUE, + 'default' => 'now()' + ) + )); + $this->dbforge->add_key('apikey_id', TRUE); + if (!$this->db->table_exists('ci_apikey')) + { + $this->dbforge->create_table('ci_apikey'); + } + + if (!$this->db->simple_query("INSERT INTO ci_apikey (key) VALUES ('aufnahme@fhcomplete.org');")) + { + echo "Error DB-Insert!"; + } + } + + public function down() + { + $this->dbforge->drop_table('ci_apikey'); + } +} + diff --git a/application/migrations/20160101010103_create_basedb.php b/application/migrations/20160101010103_create_basedb.php new file mode 100644 index 000000000..43b244c67 --- /dev/null +++ b/application/migrations/20160101010103_create_basedb.php @@ -0,0 +1,33 @@ +load->helper('file'); + $sqlfile = read_file('./system/fhcomplete3.0.sql'); + + if (!$this->db->simple_query($sqlfile)) + { + echo "Error creating Basis DB-Schema!"; + } + } + + public function down() + { + $this->db->simple_query('DROP SCHEMA addon;'); + $this->db->simple_query('DROP SCHEMA bis;'); + $this->db->simple_query('DROP SCHEMA campus;'); + $this->db->simple_query('DROP SCHEMA fue;'); + $this->db->simple_query('DROP SCHEMA kommune;'); + $this->db->simple_query('DROP SCHEMA lehre;'); + $this->db->simple_query('DROP SCHEMA reports;'); + $this->db->simple_query('DROP SCHEMA sync;'); + $this->db->simple_query('DROP SCHEMA system;'); + $this->db->simple_query('DROP SCHEMA testtool;'); + $this->db->simple_query('DROP SCHEMA wawi;'); + } +} + diff --git a/application/models/Person_model.php b/application/models/Person_model.php new file mode 100644 index 000000000..9ff4f17e5 --- /dev/null +++ b/application/models/Person_model.php @@ -0,0 +1,20 @@ +load->database(); + } + + public function get_personen($person_id = FALSE) + { + if ($person_id === FALSE) + { + $query = $this->db->get_where('public.tbl_person', array('vorname' => 'Christian')); + return $query->result_object(); + } + + $query = $this->db->get_where('public.tbl_person', array('person_id' => $person_id)); + return $query->row_object(); + } +} diff --git a/application/models/Studiengang_model.php b/application/models/Studiengang_model.php new file mode 100644 index 000000000..d280a89dd --- /dev/null +++ b/application/models/Studiengang_model.php @@ -0,0 +1,83 @@ +db->order_by($this->id, $this->order); + return $this->db->get($this->table)->result(); + } + + // get data by id + function get_by_id($id) + { + $this->db->where($this->id, $id); + return $this->db->get($this->table)->row(); + } + + // get total rows + function total_rows() { + $this->db->from($this->table); + return $this->db->count_all_results(); + } + + // get data with limit + function index_limit($limit, $start = 0) { + $this->db->order_by($this->id, $this->order); + $this->db->limit($limit, $start); + return $this->db->get($this->table)->result(); + } + + // get search total rows + function search_total_rows($keyword = NULL) { + $this->db->like('', $keyword); + $this->db->from($this->table); + return $this->db->count_all_results(); + } + + // get search data with limit + function search_index_limit($limit, $start = 0, $keyword = NULL) { + $this->db->order_by($this->id, $this->order); + $this->db->like('', $keyword); + $this->db->limit($limit, $start); + return $this->db->get($this->table)->result(); + } + + // insert data + function insert($data) + { + $this->db->insert($this->table, $data); + } + + // update data + function update($id, $data) + { + $this->db->where($this->id, $id); + $this->db->update($this->table, $data); + } + + // delete data + function delete($id) + { + $this->db->where($this->id, $id); + $this->db->delete($this->table); + } + +} + +/* End of file Studiengang_model.php */ +/* Location: ./application/models/Studiengang_model.php */ \ No newline at end of file diff --git a/application/models/grocery_CRUD_model.php b/application/models/grocery_CRUD_model.php new file mode 100755 index 000000000..af811f619 --- /dev/null +++ b/application/models/grocery_CRUD_model.php @@ -0,0 +1,582 @@ + + */ + +// ------------------------------------------------------------------------ + +/** + * Grocery CRUD Model + * + * + * @package grocery CRUD + * @author John Skoumbourdis + * @version 1.5.2 + * @link http://www.grocerycrud.com/documentation + */ +class grocery_CRUD_Model extends CI_Model { + + protected $primary_key = null; + protected $table_name = null; + protected $relation = array(); + protected $relation_n_n = array(); + protected $primary_keys = array(); + + function __construct() + { + parent::__construct(); + } + + function db_table_exists($table_name = null) + { + return $this->db->table_exists($table_name); + } + + function get_list() + { + if($this->table_name === null) + return false; + + $select = "`{$this->table_name}`.*"; + + //set_relation special queries + if(!empty($this->relation)) + { + foreach($this->relation as $relation) + { + list($field_name , $related_table , $related_field_title) = $relation; + $unique_join_name = $this->_unique_join_name($field_name); + $unique_field_name = $this->_unique_field_name($field_name); + + if(strstr($related_field_title,'{')) + { + $related_field_title = str_replace(" "," ",$related_field_title); + $select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name"; + } + else + { + $select .= ", $unique_join_name.$related_field_title AS $unique_field_name"; + } + + if($this->field_exists($related_field_title)) + $select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'"; + } + } + + //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. + if(!empty($this->relation_n_n)) + { + $select = $this->relation_n_n_queries($select); + } + + $this->db->select($select, false); + + $results = $this->db->get($this->table_name)->result(); + + return $results; + } + + public function get_row($table_name = null) + { + $table_name = $table_name === null ? $this->table_name : $table_name; + + return $this->db->get($table_name)->row(); + } + + public function set_primary_key($field_name, $table_name = null) + { + $table_name = $table_name === null ? $this->table_name : $table_name; + + $this->primary_keys[$table_name] = $field_name; + } + + protected function relation_n_n_queries($select) + { + $this_table_primary_key = $this->get_primary_key(); + foreach($this->relation_n_n as $relation_n_n) + { + list($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, + $primary_key_alias_to_selection_table, $title_field_selection_table, $priority_field_relation_table) = array_values((array)$relation_n_n); + + $primary_key_selection_table = $this->get_primary_key($selection_table); + + $field = ""; + $use_template = strpos($title_field_selection_table,'{') !== false; + $field_name_hash = $this->_unique_field_name($title_field_selection_table); + if($use_template) + { + $title_field_selection_table = str_replace(" ", " ", $title_field_selection_table); + $field .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$title_field_selection_table))."')"; + } + else + { + $field .= "$selection_table.$title_field_selection_table"; + } + + //Sorry Codeigniter but you cannot help me with the subquery! + $select .= ", (SELECT GROUP_CONCAT(DISTINCT $field) FROM $selection_table " + ."LEFT JOIN $relation_table ON $relation_table.$primary_key_alias_to_selection_table = $selection_table.$primary_key_selection_table " + ."WHERE $relation_table.$primary_key_alias_to_this_table = `{$this->table_name}`.$this_table_primary_key GROUP BY $relation_table.$primary_key_alias_to_this_table) AS $field_name"; + } + + return $select; + } + + function order_by($order_by , $direction) + { + $this->db->order_by( $order_by , $direction ); + } + + function where($key, $value = NULL, $escape = TRUE) + { + $this->db->where( $key, $value, $escape); + } + + function or_where($key, $value = NULL, $escape = TRUE) + { + $this->db->or_where( $key, $value, $escape); + } + + function having($key, $value = NULL, $escape = TRUE) + { + $this->db->having( $key, $value, $escape); + } + + function or_having($key, $value = NULL, $escape = TRUE) + { + $this->db->or_having( $key, $value, $escape); + } + + function like($field, $match = '', $side = 'both') + { + $this->db->like($field, $match, $side); + } + + function or_like($field, $match = '', $side = 'both') + { + $this->db->or_like($field, $match, $side); + } + + function limit($value, $offset = '') + { + $this->db->limit( $value , $offset ); + } + + function get_total_results() + { + //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. + if(!empty($this->relation_n_n)) + { + $select = "{$this->table_name}.*"; + $select = $this->relation_n_n_queries($select); + + $this->db->select($select,false); + } + + return $this->db->get($this->table_name)->num_rows(); + } + + function set_basic_table($table_name = null) + { + if( !($this->db->table_exists($table_name)) ) + return false; + + $this->table_name = $table_name; + + return true; + } + + function get_edit_values($primary_key_value) + { + $primary_key_field = $this->get_primary_key(); + $this->db->where($primary_key_field,$primary_key_value); + $result = $this->db->get($this->table_name)->row(); + return $result; + } + + function join_relation($field_name , $related_table , $related_field_title) + { + $related_primary_key = $this->get_primary_key($related_table); + + if($related_primary_key !== false) + { + $unique_name = $this->_unique_join_name($field_name); + $this->db->join( $related_table.' as '.$unique_name , "$unique_name.$related_primary_key = {$this->table_name}.$field_name",'left'); + + $this->relation[$field_name] = array($field_name , $related_table , $related_field_title); + + return true; + } + + return false; + } + + function set_relation_n_n_field($field_info) + { + $this->relation_n_n[$field_info->field_name] = $field_info; + } + + protected function _unique_join_name($field_name) + { + return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not with a number + } + + protected function _unique_field_name($field_name) + { + return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not with a number + } + + function get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit = null, $search_like = null) + { + $relation_array = array(); + $field_name_hash = $this->_unique_field_name($field_name); + + $related_primary_key = $this->get_primary_key($related_table); + + $select = "$related_table.$related_primary_key, "; + + if(strstr($related_field_title,'{')) + { + $related_field_title = str_replace(" ", " ", $related_field_title); + $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; + } + else + { + $select .= "$related_table.$related_field_title as $field_name_hash"; + } + + $this->db->select($select,false); + if($where_clause !== null) + $this->db->where($where_clause); + + if($where_clause !== null) + $this->db->where($where_clause); + + if($limit !== null) + $this->db->limit($limit); + + if($search_like !== null) + $this->db->having("$field_name_hash LIKE '%".$this->db->escape_like_str($search_like)."%'"); + + $order_by !== null + ? $this->db->order_by($order_by) + : $this->db->order_by($field_name_hash); + + $results = $this->db->get($related_table)->result(); + + foreach($results as $row) + { + $relation_array[$row->$related_primary_key] = $row->$field_name_hash; + } + + return $relation_array; + } + + function get_ajax_relation_array($search, $field_name , $related_table , $related_field_title, $where_clause, $order_by) + { + return $this->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, 10 , $search); + } + + function get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause) + { + if($where_clause !== null) + $this->db->where($where_clause); + + return $this->db->count_all_results($related_table); + } + + function get_relation_n_n_selection_array($primary_key_value, $field_info) + { + $select = ""; + $related_field_title = $field_info->title_field_selection_table; + $use_template = strpos($related_field_title,'{') !== false;; + $field_name_hash = $this->_unique_field_name($related_field_title); + if($use_template) + { + $related_field_title = str_replace(" ", " ", $related_field_title); + $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; + } + else + { + $select .= "$related_field_title as $field_name_hash"; + } + $this->db->select('*, '.$select,false); + + $selection_primary_key = $this->get_primary_key($field_info->selection_table); + + if(empty($field_info->priority_field_relation_table)) + { + if(!$use_template){ + $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); + } + } + else + { + $this->db->order_by("{$field_info->relation_table}.{$field_info->priority_field_relation_table}"); + } + $this->db->where($field_info->primary_key_alias_to_this_table, $primary_key_value); + $this->db->join( + $field_info->selection_table, + "{$field_info->relation_table}.{$field_info->primary_key_alias_to_selection_table} = {$field_info->selection_table}.{$selection_primary_key}" + ); + $results = $this->db->get($field_info->relation_table)->result(); + + $results_array = array(); + foreach($results as $row) + { + $results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_name_hash}; + } + + return $results_array; + } + + function get_relation_n_n_unselected_array($field_info, $selected_values) + { + $use_where_clause = !empty($field_info->where_clause); + + $select = ""; + $related_field_title = $field_info->title_field_selection_table; + $use_template = strpos($related_field_title,'{') !== false; + $field_name_hash = $this->_unique_field_name($related_field_title); + + if($use_template) + { + $related_field_title = str_replace(" ", " ", $related_field_title); + $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; + } + else + { + $select .= "$related_field_title as $field_name_hash"; + } + $this->db->select('*, '.$select,false); + + if($use_where_clause){ + $this->db->where($field_info->where_clause); + } + + $selection_primary_key = $this->get_primary_key($field_info->selection_table); + if(!$use_template) + $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); + $results = $this->db->get($field_info->selection_table)->result(); + + $results_array = array(); + foreach($results as $row) + { + if(!isset($selected_values[$row->$selection_primary_key])) + $results_array[$row->$selection_primary_key] = $row->{$field_name_hash}; + } + + return $results_array; + } + + function db_relation_n_n_update($field_info, $post_data ,$main_primary_key) + { + $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); + if(!empty($post_data)) + $this->db->where_not_in($field_info->primary_key_alias_to_selection_table , $post_data); + $this->db->delete($field_info->relation_table); + + $counter = 0; + if(!empty($post_data)) + { + foreach($post_data as $primary_key_value) + { + $where_array = array( + $field_info->primary_key_alias_to_this_table => $main_primary_key, + $field_info->primary_key_alias_to_selection_table => $primary_key_value, + ); + + $this->db->where($where_array); + $count = $this->db->from($field_info->relation_table)->count_all_results(); + + if($count == 0) + { + if(!empty($field_info->priority_field_relation_table)) + $where_array[$field_info->priority_field_relation_table] = $counter; + + $this->db->insert($field_info->relation_table, $where_array); + + }elseif($count >= 1 && !empty($field_info->priority_field_relation_table)) + { + $this->db->update( $field_info->relation_table, array($field_info->priority_field_relation_table => $counter) , $where_array); + } + + $counter++; + } + } + } + + function db_relation_n_n_delete($field_info, $main_primary_key) + { + $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); + $this->db->delete($field_info->relation_table); + } + + function get_field_types_basic_table() + { + $db_field_types = array(); + foreach($this->db->query("SHOW COLUMNS FROM `{$this->table_name}`")->result() as $db_field_type) + { + $type = explode("(",$db_field_type->Type); + $db_type = $type[0]; + + if(isset($type[1])) + { + if(substr($type[1],-1) == ')') + { + $length = substr($type[1],0,-1); + } + else + { + list($length) = explode(" ",$type[1]); + $length = substr($length,0,-1); + } + } + else + { + $length = ''; + } + $db_field_types[$db_field_type->Field]['db_max_length'] = $length; + $db_field_types[$db_field_type->Field]['db_type'] = $db_type; + $db_field_types[$db_field_type->Field]['db_null'] = $db_field_type->Null == 'YES' ? true : false; + $db_field_types[$db_field_type->Field]['db_extra'] = $db_field_type->Extra; + } + + $results = $this->db->field_data($this->table_name); + foreach($results as $num => $row) + { + $row = (array)$row; + $results[$num] = (object)( array_merge($row, $db_field_types[$row['name']]) ); + } + + return $results; + } + + function get_field_types($table_name) + { + $results = $this->db->field_data($table_name); + + return $results; + } + + function db_update($post_array, $primary_key_value) + { + $primary_key_field = $this->get_primary_key(); + return $this->db->update($this->table_name,$post_array, array( $primary_key_field => $primary_key_value)); + } + + function db_insert($post_array) + { + $insert = $this->db->insert($this->table_name,$post_array); + if($insert) + { + return $this->db->insert_id(); + } + return false; + } + + function db_delete($primary_key_value) + { + $primary_key_field = $this->get_primary_key(); + + if($primary_key_field === false) + return false; + + $this->db->limit(1); + $this->db->delete($this->table_name,array( $primary_key_field => $primary_key_value)); + if( $this->db->affected_rows() != 1) + return false; + else + return true; + } + + function db_file_delete($field_name, $filename) + { + if( $this->db->update($this->table_name,array($field_name => ''),array($field_name => $filename)) ) + { + return true; + } + else + { + return false; + } + } + + function field_exists($field,$table_name = null) + { + if(empty($table_name)) + { + $table_name = $this->table_name; + } + return $this->db->field_exists($field,$table_name); + } + + function get_primary_key($table_name = null) + { + if($table_name == null) + { + if(isset($this->primary_keys[$this->table_name])) + { + return $this->primary_keys[$this->table_name]; + } + + if(empty($this->primary_key)) + { + $fields = $this->get_field_types_basic_table(); + + foreach($fields as $field) + { + if($field->primary_key == 1) + { + return $field->name; + } + } + + return false; + } + else + { + return $this->primary_key; + } + } + else + { + if(isset($this->primary_keys[$table_name])) + { + return $this->primary_keys[$table_name]; + } + + $fields = $this->get_field_types($table_name); + + foreach($fields as $field) + { + if($field->primary_key == 1) + { + return $field->name; + } + } + + return false; + } + + } + + function escape_str($value) + { + return $this->db->escape_str($value); + } + +} diff --git a/application/models/index.html b/application/models/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/models/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/third_party/index.html b/application/third_party/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/third_party/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/views/errors/cli/error_404.php b/application/views/errors/cli/error_404.php new file mode 100755 index 000000000..6984b61e9 --- /dev/null +++ b/application/views/errors/cli/error_404.php @@ -0,0 +1,8 @@ + + +An uncaught Exception was encountered + +Type: +Message: +Filename: getFile(), "\n"; ?> +Line Number: getLine(); ?> + + + +Backtrace: +getTrace() as $error): ?> + + File: + Line: + Function: + + + + diff --git a/application/views/errors/cli/error_general.php b/application/views/errors/cli/error_general.php new file mode 100755 index 000000000..6984b61e9 --- /dev/null +++ b/application/views/errors/cli/error_general.php @@ -0,0 +1,8 @@ + + +A PHP Error was encountered + +Severity: +Message: +Filename: +Line Number: + + + +Backtrace: + + + File: + Line: + Function: + + + + diff --git a/application/views/errors/cli/index.html b/application/views/errors/cli/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/views/errors/cli/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/views/errors/html/error_404.php b/application/views/errors/html/error_404.php new file mode 100755 index 000000000..756ea9d62 --- /dev/null +++ b/application/views/errors/html/error_404.php @@ -0,0 +1,64 @@ + + + + +404 Page Not Found + + + +
    +

    + +
    + + \ No newline at end of file diff --git a/application/views/errors/html/error_db.php b/application/views/errors/html/error_db.php new file mode 100755 index 000000000..f5a43f638 --- /dev/null +++ b/application/views/errors/html/error_db.php @@ -0,0 +1,64 @@ + + + + +Database Error + + + +
    +

    + +
    + + \ No newline at end of file diff --git a/application/views/errors/html/error_exception.php b/application/views/errors/html/error_exception.php new file mode 100755 index 000000000..87848866a --- /dev/null +++ b/application/views/errors/html/error_exception.php @@ -0,0 +1,32 @@ + + +
    + +

    An uncaught Exception was encountered

    + +

    Type:

    +

    Message:

    +

    Filename: getFile(); ?>

    +

    Line Number: getLine(); ?>

    + + + +

    Backtrace:

    + getTrace() as $error): ?> + + + +

    + File:
    + Line:
    + Function: +

    + + + + + + +
    \ No newline at end of file diff --git a/application/views/errors/html/error_general.php b/application/views/errors/html/error_general.php new file mode 100755 index 000000000..fc3b2ebad --- /dev/null +++ b/application/views/errors/html/error_general.php @@ -0,0 +1,64 @@ + + + + +Error + + + +
    +

    + +
    + + \ No newline at end of file diff --git a/application/views/errors/html/error_php.php b/application/views/errors/html/error_php.php new file mode 100755 index 000000000..b146f9c5b --- /dev/null +++ b/application/views/errors/html/error_php.php @@ -0,0 +1,33 @@ + + +
    + +

    A PHP Error was encountered

    + +

    Severity:

    +

    Message:

    +

    Filename:

    +

    Line Number:

    + + + +

    Backtrace:

    + + + + +

    + File:
    + Line:
    + Function: +

    + + + + + + + +
    \ No newline at end of file diff --git a/application/views/errors/html/index.html b/application/views/errors/html/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/views/errors/html/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/views/errors/index.html b/application/views/errors/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/views/errors/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/views/example.php b/application/views/example.php new file mode 100644 index 000000000..1241c352b --- /dev/null +++ b/application/views/example.php @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + +
    +
    + +
    + + diff --git a/application/views/home.php b/application/views/home.php new file mode 100644 index 000000000..5f2438c2d --- /dev/null +++ b/application/views/home.php @@ -0,0 +1,130 @@ + + + + <?php echo $this->config->item('nama_aplikasi');?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    +
    +
    + +
    +
    +
    + + +
    + +
    +

    © Copyright 2014 -
    Created By : Slamet Nurhadi
    Page rendered in {elapsed_time} seconds

    +
    +
    + + + diff --git a/application/views/index.html b/application/views/index.html new file mode 100755 index 000000000..b702fbc39 --- /dev/null +++ b/application/views/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/views/person/cli/view.php b/application/views/person/cli/view.php new file mode 100644 index 000000000..2163914d8 --- /dev/null +++ b/application/views/person/cli/view.php @@ -0,0 +1,4 @@ +titelpre,"\n"; +echo $person_item->vorname,' '; +echo $person_item->nachname; diff --git a/application/views/person/index.php b/application/views/person/index.php new file mode 100644 index 000000000..576c094a4 --- /dev/null +++ b/application/views/person/index.php @@ -0,0 +1,11 @@ +

    + + + +

    titelpre ?>

    +
    + vorname,' ',$person_item->nachname ?> +
    +

    View Person

    + + diff --git a/application/views/person/view.php b/application/views/person/view.php new file mode 100644 index 000000000..41e4da2ad --- /dev/null +++ b/application/views/person/view.php @@ -0,0 +1,4 @@ +'.$person_item->titelpre.''; +echo $person_item->vorname; +echo $person_item->nachname; diff --git a/application/views/rdf/basic.php b/application/views/rdf/basic.php new file mode 100644 index 000000000..2fd6ed3f7 --- /dev/null +++ b/application/views/rdf/basic.php @@ -0,0 +1,54 @@ + +
    +

    +
    +
    +
    +
    + +
    +
    + + + + + + + + + + + + + + + primaryTopic(); +?> + + + + + + + + + + +
    NameGive NameFamily Name
    get('foaf:name') ?> get('foaf:givenName') ?> get('foaf:familyName') ?>
    + + + +
    \ No newline at end of file diff --git a/application/views/rdf/basic_sparql.php b/application/views/rdf/basic_sparql.php new file mode 100644 index 000000000..91ca04e85 --- /dev/null +++ b/application/views/rdf/basic_sparql.php @@ -0,0 +1,74 @@ + +
    +

    +
    +
    +
    +
    + +
    +
    + + + + + + + + + + + + + + + + +query( + 'SELECT * WHERE {'. + ' ?country rdf:type dbo:Country .'. + ' ?country rdfs:label ?label .'. + ' ?country dc:subject category:Member_states_of_the_United_Nations .'. + ' FILTER ( lang(?label) = "en" )'. + '} ORDER BY ?label' + ); + +?> + Total number of countries: numRows() ?> + + + + + + + + + + + + +
    LabelCountry
    label ?> country ?>
    + + + +
    diff --git a/application/views/rdf/converter.php b/application/views/rdf/converter.php new file mode 100644 index 000000000..b8c0b9ae3 --- /dev/null +++ b/application/views/rdf/converter.php @@ -0,0 +1,112 @@ +
    +

    Converter

    +
    +
    +
    +
    + +
    +
    + + + +load->view('rdf/html_tag_helpers'); + + $input_format_options = array('Guess' => 'guess'); + $output_format_options = array(); + foreach (EasyRdf_Format::getFormats() as $format) { + if ($format->getSerialiserClass()) { + $output_format_options[$format->getLabel()] = $format->getName(); + } + if ($format->getParserClass()) { + $input_format_options[$format->getLabel()] = $format->getName(); + } + } + + // Stupid PHP :( + if (get_magic_quotes_gpc() and isset($_REQUEST['data'])) { + $_REQUEST['data'] = stripslashes($_REQUEST['data']); + } + + // Default to Guess input and Turtle output + if (!isset($_REQUEST['output_format'])) { + $_REQUEST['output_format'] = 'turtle'; + } + if (!isset($_REQUEST['input_format'])) { + $_REQUEST['input_format'] = 'guess'; + } + + // Display the form, if raw option isn't set + if (!isset($_REQUEST['raw'])) { + print "\n"; + print "EasyRdf Converter\n"; + print "\n"; + print "

    EasyRdf Converter

    \n"; + + print "
    \n"; + print form_tag(); + print label_tag('data', 'Input Data: ').'
    '.text_area_tag('data', '', array('cols'=>30, 'rows'=>10)) . "
    \n"; + print label_tag('uri', 'or Uri: ').text_field_tag('uri', 'http://www.dajobe.org/foaf.rdf', array('size'=>80)) . "
    \n"; + print label_tag('input_format', 'Input Format: ').select_tag('input_format', $input_format_options) . "
    \n"; + print label_tag('output_format', 'Output Format: ').select_tag('output_format', $output_format_options) . "
    \n"; + print label_tag('raw', 'Raw Output: ').check_box_tag('raw') . "
    \n"; + print reset_tag() . submit_tag(); + print form_end_tag(); + print "
    \n"; + } + + if (isset($_REQUEST['uri']) or isset($_REQUEST['data'])) { + // Parse the input + $graph = new EasyRdf_Graph($_REQUEST['uri']); + if (empty($_REQUEST['data'])) { + $graph->load($_REQUEST['uri'], $_REQUEST['input_format']); + } else { + $graph->parse($_REQUEST['data'], $_REQUEST['input_format'], $_REQUEST['uri']); + } + + // Lookup the output format + $format = EasyRdf_Format::getFormat($_REQUEST['output_format']); + + // Serialise to the new output format + $output = $graph->serialise($format); + if (!is_scalar($output)) { + $output = var_export($output, true); + } + + // Send the output back to the client + if (isset($_REQUEST['raw'])) { + header('Content-Type: '.$format->getDefaultMimeType()); + print $output; + } else { + print '
    '.htmlspecialchars($output).'
    '; + } + } + + if (!isset($_REQUEST['raw'])) { + print "\n"; + print "\n"; + } + +?> +
    \ No newline at end of file diff --git a/application/views/rdf/foafinfo.php b/application/views/rdf/foafinfo.php new file mode 100644 index 000000000..6ecc554fb --- /dev/null +++ b/application/views/rdf/foafinfo.php @@ -0,0 +1,124 @@ + +
    +

    +
    +
    +
    +
    + +
    +
    + + +
    + +
    + +
    + +
    +
    +
    +
    + +
    +
    +
    +

    FOAF me

    +load->view('rdf/html_tag_helpers'); + + + if(isset($_REQUEST['uri'])): ?> + + + + + + + type() == 'foaf:PersonalProfileDocument'): ?> + primaryTopic(); ?> + type() == 'foaf:Person'): ?> + resource(); ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameHomepage
    get('foaf:name') ?> get('foaf:homepage') ?>
    + + + + +

    Known Person

    + + all('foaf:knows') as $friend) { + $label = $friend->label(); + + if (!$label) { + $label = $friend->getUri(); + } + ?> + + + + + + + + + + isBNode()): ?> + + + + ".link_to_self($label, 'uri='.urlencode($friend)).""; ?> + + + + + + + + + +
    + + + + + + +
    + + + + + + \ No newline at end of file diff --git a/application/views/rdf/foafmaker.php b/application/views/rdf/foafmaker.php new file mode 100644 index 000000000..941d3f5f5 --- /dev/null +++ b/application/views/rdf/foafmaker.php @@ -0,0 +1,121 @@ +
    +

    EasyRdf FOAF Maker Example

    +
    +
    +
    +
    + +
    +
    +load->view('rdf/html_tag_helpers'); + + if (isset($_REQUEST['enable_arc']) && $_REQUEST['enable_arc']) { + require_once "EasyRdf/Serialiser/Arc.php"; + EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Arc'); + EasyRdf_Format::registerSerialiser('posh', 'EasyRdf_Serialiser_Arc'); + EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Arc'); + EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Arc'); + } + + if (isset($_REQUEST['enable_rapper']) && $_REQUEST['enable_rapper']) { + require_once "EasyRdf/Serialiser/Rapper.php"; + EasyRdf_Format::registerSerialiser('dot', 'EasyRdf_Serialiser_Rapper'); + EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Rapper'); + EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Rapper'); + } + + $format_options = array(); + foreach (EasyRdf_Format::getFormats() as $format) { + if ($format->getSerialiserClass()) { + $format_options[$format->getLabel()] = $format->getName(); + } + } +?> + +

    + + 'POST')) ?> + +

    Your Identifier

    +40)) ?>
    + +

    Your details

    +8)) ?>
    +
    +
    +
    +
    +40)) ?>
    + +

    People you know

    +40)) ?>
    +40)) ?>
    +40)) ?>
    +40)) ?>
    + +

    Output

    +Enable Arc 2?
    +Enable Rapper?
    +
    + + + + + +resource($_REQUEST['uri'], 'foaf:Person'); + $me->set('foaf:name', $_REQUEST['title'].' '.$_REQUEST['given_name'].' '.$_REQUEST['family_name']); + if ($_REQUEST['email']) { + $email = $graph->resource("mailto:".$_REQUEST['email']); + $me->add('foaf:mbox', $email); + } + if ($_REQUEST['homepage']) { + $homepage = $graph->resource($_REQUEST['homepage']); + $me->add('foaf:homepage', $homepage); + } + + # 2nd Technique + $graph->addLiteral($_REQUEST['uri'], 'foaf:title', $_REQUEST['title']); + $graph->addLiteral($_REQUEST['uri'], 'foaf:givenname', $_REQUEST['given_name']); + $graph->addLiteral($_REQUEST['uri'], 'foaf:family_name', $_REQUEST['family_name']); + $graph->addLiteral($_REQUEST['uri'], 'foaf:nick', $_REQUEST['nickname']); + + # Add friends + for($i=1; $i<=4; $i++) { + if ($_REQUEST["person_$i"]) { + $person = $graph->resource($_REQUEST["person_$i"]); + $graph->add($me, 'foaf:knows', $person); + } + } + + # Finally output the graph + $data = $graph->serialise($_REQUEST['format']); + if (!is_scalar($data)) { + $data = var_export($data, true); + } + print "
    ".htmlspecialchars($data)."
    "; + } + +?> + +
    \ No newline at end of file diff --git a/application/views/rdf/form.php b/application/views/rdf/form.php new file mode 100644 index 000000000..1f8e447fd --- /dev/null +++ b/application/views/rdf/form.php @@ -0,0 +1,121 @@ +
    +

    EasyRdf FOAF Maker Example

    +
    +
    +
    +
    + +
    +
    +load->view('rdf/html_tag_helpers'); + + if (isset($_REQUEST['enable_arc']) && $_REQUEST['enable_arc']) { + require_once "EasyRdf/Serialiser/Arc.php"; + EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Arc'); + EasyRdf_Format::registerSerialiser('posh', 'EasyRdf_Serialiser_Arc'); + EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Arc'); + EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Arc'); + } + + if (isset($_REQUEST['enable_rapper']) && $_REQUEST['enable_rapper']) { + require_once "EasyRdf/Serialiser/Rapper.php"; + EasyRdf_Format::registerSerialiser('dot', 'EasyRdf_Serialiser_Rapper'); + EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Rapper'); + EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Rapper'); + } + + $format_options = array(); + foreach (EasyRdf_Format::getFormats() as $format) { + if ($format->getSerialiserClass()) { + $format_options[$format->getLabel()] = $format->getName(); + } + } +?> + +

    + + 'POST')) ?> + +

    Your Identifier

    +40)) ?>
    + +

    Your details

    +8)) ?>
    +
    +
    +
    +
    +40)) ?>
    + +

    People you know

    +40)) ?>
    +40)) ?>
    +40)) ?>
    +40)) ?>
    + +

    Output

    +Enable Arc 2?
    +Enable Rapper?
    +
    + + + + + +resource($_REQUEST['uri'], 'foaf:Person'); + $me->set('foaf:name', $_REQUEST['title'].' '.$_REQUEST['given_name'].' '.$_REQUEST['family_name']); + if ($_REQUEST['email']) { + $email = $graph->resource("mailto:".$_REQUEST['email']); + $me->add('foaf:mbox', $email); + } + if ($_REQUEST['homepage']) { + $homepage = $graph->resource($_REQUEST['homepage']); + $me->add('foaf:homepage', $homepage); + } + + # 2nd Technique + $graph->addLiteral($_REQUEST['uri'], 'foaf:title', $_REQUEST['title']); + $graph->addLiteral($_REQUEST['uri'], 'foaf:givenname', $_REQUEST['given_name']); + $graph->addLiteral($_REQUEST['uri'], 'foaf:family_name', $_REQUEST['family_name']); + $graph->addLiteral($_REQUEST['uri'], 'foaf:nick', $_REQUEST['nickname']); + + # Add friends + for($i=1; $i<=4; $i++) { + if ($_REQUEST["person_$i"]) { + $person = $graph->resource($_REQUEST["person_$i"]); + $graph->add($me, 'foaf:knows', $person); + } + } + + # Finally output the graph + $data = $graph->serialise($_REQUEST['format']); + if (!is_scalar($data)) { + $data = var_export($data, true); + } + print "
    ".htmlspecialchars($data)."
    "; + } + +?> + +
    \ No newline at end of file diff --git a/application/views/rdf/html_tag_helpers.php b/application/views/rdf/html_tag_helpers.php new file mode 100644 index 000000000..0cdcdddac --- /dev/null +++ b/application/views/rdf/html_tag_helpers.php @@ -0,0 +1,218 @@ +'foo')); + +echo tag('br'); +echo link_to('Hyperlink', 'http://www.example.com/?a=1&b=2'); +echo tag('br'); + +echo form_tag(); + + echo label_tag('first_name').text_field_tag('first_name', 'Joe').tag('br'); + echo label_tag('password').password_field_tag().tag('br'); + + echo label_tag('radio1_value1', 'Radio 1').radio_button_tag('radio1', 'value1').tag('br'); + echo label_tag('radio1_value2', 'Radio 2').radio_button_tag('radio1', 'value2', true).tag('br'); + echo label_tag('radio1_value3', 'Radio 3').radio_button_tag('radio1', 'value3').tag('br'); + + echo label_tag('check1', 'Check 1').check_box_tag('check1', 'value1').tag('br'); + echo label_tag('check2', 'Check 2').check_box_tag('check2', 'value2', true).tag('br'); + echo label_tag('check3', 'Check 3').check_box_tag('check3', 'value3').tag('br'); + + $options = array('Label 1' => 'value1', 'Label 2' => 'value2', 'Label 3' => 'value3'); + echo label_tag('select1', 'Select Something:'); + echo select_tag('select1', $options, 'value2').tag('br'); + + echo label_tag('textarea1', 'Type Something:'); + echo text_area_tag('textarea1', "Hello World!").tag('br'); + + echo submit_tag(); + +echo form_end_tag(); + +*/ + + +function tag_options($options) +{ + $html = ""; + foreach ($options as $key => $value) { + if ($key and $value) { + $html .= " ".htmlspecialchars($key)."=\"". + htmlspecialchars($value)."\""; + } + } + return $html; +} + +function tag($name, $options = array(), $open = false) +{ + return "<$name".tag_options($options).($open ? ">" : " />"); +} + +function content_tag($name, $content = null, $options = array()) +{ + return "<$name".tag_options($options).">". + htmlspecialchars($content).""; +} + +function link_to($text, $uri = null, $options = array()) +{ + if ($uri == null) $uri = $text; + $options = array_merge(array('href' => $uri), $options); + return content_tag('a', $text, $options); +} + +function link_to_self($text, $query_string, $options = array()) +{ + return link_to($text, $_SERVER['PHP_SELF'].'?'.$query_string, $options); +} + +function image_tag($src, $options = array()) +{ + $options = array_merge(array('src' => $src), $options); + return tag('img', $options); +} + +function input_tag($type, $name, $value = null, $options = array()) +{ + $options = array_merge( + array( + 'type' => $type, + 'name' => $name, + 'id' => $name, + 'value' => $value + ), + $options + ); + return tag('input', $options); +} + +function text_field_tag($name, $default = null, $options = array()) +{ + $value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : $default; + return input_tag('text', $name, $value, $options); +} + +function text_area_tag($name, $default = null, $options = array()) +{ + $content = isset($_REQUEST[$name]) ? $_REQUEST[$name] : $default; + $options = array_merge( + array( + 'name' => $name, + 'id' => $name, + 'cols' => 60, + 'rows' => 5 + ), + $options + ); + return content_tag('textarea', $content, $options); +} + +function hidden_field_tag($name, $default = null, $options = array()) +{ + $value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : $default; + return input_tag('hidden', $name, $value, $options); +} + +function password_field_tag($name = 'password', $default = null, $options = array()) +{ + $value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : $default; + return input_tag('password', $name, $value, $options); +} + +function radio_button_tag($name, $value, $default = false, $options = array()) +{ + if ((isset($_REQUEST[$name]) and $_REQUEST[$name] == $value) or + (!isset($_REQUEST[$name]) and $default)) + { + $options = array_merge(array('checked' => 'checked'), $options); + } + $options = array_merge(array('id' => $name.'_'.$value), $options); + return input_tag('radio', $name, $value, $options); +} + +function check_box_tag($name, $value = '1', $default = false, $options = array()) +{ + if ((isset($_REQUEST[$name]) and $_REQUEST[$name] == $value) or + (!isset($_REQUEST['submit']) and $default)) + { + $options = array_merge(array('checked' => 'checked'),$options); + } + return input_tag('checkbox', $name, $value, $options); +} + +function submit_tag($name = '', $value = 'Submit', $options = array()) +{ + return input_tag('submit', $name, $value, $options); +} + +function reset_tag($name = '', $value = 'Reset', $options = array()) +{ + return input_tag('reset', $name, $value, $options); +} + +function label_tag($name, $text = null, $options = array()) +{ + if ($text == null) { + $text = ucwords(str_replace('_', ' ', $name)).': '; + } + $options = array_merge( + array('for' => $name, 'id' => "label_for_$name"), + $options + ); + return content_tag('label', $text, $options); +} + +function labeled_text_field_tag($name, $default = null, $options = array()) +{ + return label_tag($name).text_field_tag($name, $default, $options); +} + +function select_tag($name, $options, $default = null, $html_options = array()) +{ + $opts = ''; + foreach ($options as $key => $value) { + $arr = array('value' => $value); + if ((isset($_REQUEST[$name]) and $_REQUEST[$name] == $value) or + (!isset($_REQUEST[$name]) and $default == $value)) + { + $arr = array_merge(array('selected' => 'selected'),$arr); + } + $opts .= content_tag('option', $key, $arr); + } + $html_options = array_merge( + array('name' => $name, 'id' => $name), + $html_options + ); + return "$opts"; +} + +function form_tag($uri = null, $options = array()) +{ + if ($uri == null) { + $uri = $_SERVER['PHP_SELF']; + } + $options = array_merge( + array('method' => 'get', 'action' => $uri), + $options + ); + return tag('form', $options, true); +} + +function form_end_tag() +{ + return ""; +} diff --git a/application/views/tbl_studiengang_form.php b/application/views/tbl_studiengang_form.php new file mode 100644 index 000000000..263bce62e --- /dev/null +++ b/application/views/tbl_studiengang_form.php @@ -0,0 +1,20 @@ + + + + harviacode.com - codeigniter crud generator + + + + +

    Tbl_studiengang

    +
    + + + Cancel +
    + + \ No newline at end of file diff --git a/application/views/tbl_studiengang_list.php b/application/views/tbl_studiengang_list.php new file mode 100644 index 000000000..2b9f614cc --- /dev/null +++ b/application/views/tbl_studiengang_list.php @@ -0,0 +1,71 @@ + + + + harviacode.com - codeigniter crud generator + + + + +

    Tbl_studiengang List

    +
    +
    + +
    +
    +
    + session->userdata('message') <> '' ? $this->session->userdata('message') : ''; ?> +
    +
    +
    +
    + + '') + { + ?> + Reset + + +
    +
    +
    + + + + + + + + + + +
    NoAction
    + ),'Read'); + echo ' | '; + echo anchor(site_url('studiengang/update/'.$studiengang->),'Update'); + echo ' | '; + echo anchor(site_url('studiengang/delete/'.$studiengang->),'Delete','onclick="javasciprt: return confirm(\'Are You Sure ?\')"'); + ?> +
    +
    + +
    + +
    +
    + + \ No newline at end of file diff --git a/application/views/tbl_studiengang_read.php b/application/views/tbl_studiengang_read.php new file mode 100644 index 000000000..9f690ef3b --- /dev/null +++ b/application/views/tbl_studiengang_read.php @@ -0,0 +1,18 @@ + + + + harviacode.com - codeigniter crud generator + + + + +

    Tbl_studiengang Read

    + + +
    Cancel
    + + \ No newline at end of file diff --git a/application/views/templates/footer.php b/application/views/templates/footer.php new file mode 100644 index 000000000..5f85cabb0 --- /dev/null +++ b/application/views/templates/footer.php @@ -0,0 +1 @@ + diff --git a/application/views/templates/header.php b/application/views/templates/header.php new file mode 100644 index 000000000..9ab8223f8 --- /dev/null +++ b/application/views/templates/header.php @@ -0,0 +1,11 @@ + + + + + VileSci + + + + diff --git a/application/views/vilesci_frameset.php b/application/views/vilesci_frameset.php new file mode 100644 index 000000000..855bacf69 --- /dev/null +++ b/application/views/vilesci_frameset.php @@ -0,0 +1,13 @@ + + + + + + + + <body bgcolor="#FFFFFF"> + This application works only with a frames-enabled browser.<br /> + <a href="../vilesci/main.php">Use without frames</a> + </body> + + diff --git a/application/views/welcome_message.php b/application/views/welcome_message.php new file mode 100755 index 000000000..f5115630b --- /dev/null +++ b/application/views/welcome_message.php @@ -0,0 +1,89 @@ + + + + + Welcome to CodeIgniter + + + + + +
    +

    Welcome to CodeIgniter!

    + +
    +

    The page you are looking at is being generated dynamically by CodeIgniter.

    + +

    If you would like to edit this page you'll find it located at:

    + application/views/welcome_message.php + +

    The corresponding controller for this page is found at:

    + application/controllers/Welcome.php + +

    If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide.

    +
    + + +
    + + + \ No newline at end of file diff --git a/ci_hack.php b/ci_hack.php new file mode 100755 index 000000000..7baffee0e --- /dev/null +++ b/ci_hack.php @@ -0,0 +1,407 @@ +=')) + { + 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 +} + +/* + *--------------------------------------------------------------- + * 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 = dirname(__FILE__).'/vendor/codeigniter/framework/system'; + +/* + *--------------------------------------------------------------- + * 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 = dirname(__FILE__).'/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 = ''; + + +/* + * -------------------------------------------------------------------- + * 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'] = ''; + + +/* + * ------------------------------------------------------------------- + * 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 BOOTSTRAP FILE + * -------------------------------------------------------------------- + * + * And away we go... + */ +//require_once BASEPATH.'core/CodeIgniter.php'; + +// FH-Complete Hacks for uebergangszeit +function &get_instance() +{ + return CI_Controller::get_instance(); +} +/*require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/CodeIgniter.php'); +*/ +require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/database/DB.php'); +require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Common.php'); +require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Loader.php'); +$loader=new CI_Loader(); +require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Controller.php'); +$controller=new CI_Controller(); +require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Model.php'); +$model=new CI_Model(); + +// Traits +trait db_extra +{ + protected $db_result=null; + + public function db_query($sql) + { + if ($this->db_result=$this->db->simple_query($sql)) + return $this->db_result; + else + { + $this->errormsg.='Abfrage in Datenbank fehlgeschlagen! '.$this->db_last_error(); + return false; + } + } + + public function db_fetch_object($result = null, $i=null) + { + if(is_null($result)) + { + if(is_null($i)) + return pg_fetch_object($this->db_result); + else + return pg_fetch_object($this->db_result, $i); + } + else + { + if(is_null($i)) + return pg_fetch_object($result); + else + return pg_fetch_object($result, $i); + } + } + + public function db_add_param($var, $type=FHC_STRING, $nullable=true) + { + if($var==='' && $type!=FHC_BOOLEAN) + { + if($nullable) + return 'null'; + else + return "''"; + } + + switch($type) + { + case FHC_INTEGER: + $var = $this->db_escape($var); + if(!is_numeric($var) && $var!=='') + die('Invalid Integer Parameter detected:'.$var); + $var = $this->db_null_value($var, false); + break; + + case FHC_BOOLEAN: + if($var===true) + $var='true'; + elseif($var===false) + $var='false'; + elseif($var=='' && $nullable) + $var = 'null'; + else + die('Invalid Boolean Parameter detected'); + break; + + case FHC_STRING: + default: + $var = $this->db_escape($var); + $var = $this->db_null_value($var); + break; + } + return $var; + } + + public function db_escape($var) + { + return pg_escape_string($var); + } + + public function db_null_value($var, $qoute=true) + { + if($qoute) + return ($var!==''?$this->db_qoute($var):'null'); + else + return ($var!==''?$var:'null'); + } + + public function db_parse_bool($var) + { + if($var=='t') + return true; + elseif($var=='f') + return false; + elseif($var=='') + return ''; + else + die('Invalid DB Boolean. Wrong DB-Engine?'); + } +} + diff --git a/index.php b/index.php new file mode 100644 index 000000000..c90d741ef --- /dev/null +++ b/index.php @@ -0,0 +1,310 @@ +=')) + { + 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 +} + +/* + *--------------------------------------------------------------- + * 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 = 'vendor/codeigniter/framework/system'; + +/* + *--------------------------------------------------------------- + * 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 = ''; + + +/* + * -------------------------------------------------------------------- + * 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'] = ''; + + +/* + * ------------------------------------------------------------------- + * 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 BOOTSTRAP FILE + * -------------------------------------------------------------------- + * + * And away we go... + * + */ + +// First load the FHC-Config-Files +require_once 'config/global.config.inc.php'; +require_once 'config/system.config.inc.php'; + +// Now the bootstrap file +require_once BASEPATH.'core/CodeIgniter.php'; + +/* End of file index.php */ +/* Location: ./index.php */