commit a96eaec33b6a9c7e1be471f1e27028bd9f312507 Author: ryanwong Date: Thu Jun 30 05:46:02 2022 -0400 first commit diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..6d7f018 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5657f6e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor \ No newline at end of file diff --git a/D.php b/D.php new file mode 100755 index 0000000..21d4f37 --- /dev/null +++ b/D.php @@ -0,0 +1,86 @@ +' . print_r($data, TRUE) . ''; + } + + /** + * Print r exit + * + * @param [type] $data + * @return void + */ + public static function pe ($data) + { + echo '
' . print_r($data, TRUE) . '
'; + exit; + } + + /** + * Error log + * + * @param [type] $data + * @return void + */ + public static function e ($data) + { + error_log($data); + } + + /** + * Error log printr + * + * @param [type] $data + * @return void + */ + public static function ep ($data) + { + error_log('
' . print_r($data, TRUE) . '
'); + } + + /** + * Error log true/false + * + * @param [type] $data + * @return void + */ + public static function et ($data) + { + error_log(($data) ? 'true': 'false'); + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a4cd33c --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Book Project + +Please perform the following task one by one and commit to git per task. This must all be done today. + +## Tasks + +1. Create db name outlinegurus. The sql file in the root of application. start the project on php -S localhost:9020 + +2. Go to task_2.png . See the terms and condition and privacy policy link. They don't go anywhere. Change those href to https://termly.io/our-terms-of-use/ and https://termly.io/our-privacy-policy/ + +3. Go to task_3.png. Add a column to this ui called year. Add a filter dropdown on top called year and can filter by year. Enable sorting ASC and DESC by year as well. + +4. Go to task_4.png an task_4b.png . Admin login is http://localhost:9020/admin/login admin@manaknight.com a123456. In review model add a database field called private_review as text. Add a column called Private Review in the table. Add PRivate Review filter in the search table above. If you look in task_4.png, add a new textarea to ask for Private review and save it. + +5. Go to task_5.png . The status dropdown doesn't work properly and filter the statuses. the search title says "Tickets Searchzzz" + Change it to Tickets Search. There PHP error when I run this page + +6. Go to task_6.png . When I click export icon, you see status is missing from the export report. Add it back + +7. Go to task_7.png . The Count # for Member account is wrong + +8. http://localhost:9020/admin/professor/0?order_by=id&direction=DESC page is crashing + +9. http://localhost:9020/admin/class/0?order_by=id&direction=DESC page is crashing + +10. http://localhost:9020/admin/school/0?order_by=id&direction=DESC page is not working properly diff --git a/application/.DS_Store b/application/.DS_Store new file mode 100644 index 0000000..ec7e86e Binary files /dev/null and b/application/.DS_Store differ diff --git a/application/config/autoload.php b/application/config/autoload.php new file mode 100755 index 0000000..87d0939 --- /dev/null +++ b/application/config/autoload.php @@ -0,0 +1,135 @@ + 'ua'); +*/ +$autoload['libraries'] = array('session', 'form_validation', 'pagination'); + +/* +| ------------------------------------------------------------------- +| Auto-load Drivers +| ------------------------------------------------------------------- +| These classes are located in system/libraries/ or in your +| application/libraries/ directory, but are also placed inside their +| own subdirectory and they extend the CI_Driver_Library class. They +| offer multiple interchangeable driver options. +| +| Prototype: +| +| $autoload['drivers'] = array('cache'); +| +| You can also supply an alternative property name to be assigned in +| the controller: +| +| $autoload['drivers'] = array('cache' => 'cch'); +| +*/ +$autoload['drivers'] = array(); + +/* +| ------------------------------------------------------------------- +| Auto-load Helper Files +| ------------------------------------------------------------------- +| Prototype: +| +| $autoload['helper'] = array('url', 'file'); +*/ +$autoload['helper'] = array('form', '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(); \ No newline at end of file diff --git a/application/config/config.php b/application/config/config.php new file mode 100755 index 0000000..575c7bd --- /dev/null +++ b/application/config/config.php @@ -0,0 +1,589 @@ +]+$/i +| +| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! +| +*/ +$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; + +/* +|-------------------------------------------------------------------------- +| Enable Query Strings +|-------------------------------------------------------------------------- +| +| By default CodeIgniter uses search-engine friendly segment based URLs: +| example.com/who/what/where/ +| +| You can optionally enable standard query string based URLs: +| example.com?who=me&what=something&where=here +| +| Options are: TRUE or FALSE (boolean) +| +| The other items let you set the query string 'words' that will +| invoke your controllers and its functions: +| example.com/index.php?c=controller&m=function +| +| Please note that some of the helpers won't work as expected when +| this feature is enabled, since CodeIgniter is designed primarily to +| use segment based URLs. +| +*/ +$config['enable_query_strings'] = FALSE; +$config['controller_trigger'] = 'c'; +$config['function_trigger'] = 'm'; +$config['directory_trigger'] = 'd'; + +/* +|-------------------------------------------------------------------------- +| Allow $_GET array +|-------------------------------------------------------------------------- +| +| By default CodeIgniter enables access to the $_GET array. If for some +| reason you would like to disable it, set 'allow_get_array' to FALSE. +| +| WARNING: This feature is DEPRECATED and currently available only +| for backwards compatibility purposes! +| +*/ +$config['allow_get_array'] = TRUE; + +/* +|-------------------------------------------------------------------------- +| Error Logging Threshold +|-------------------------------------------------------------------------- +| +| You can enable error logging by setting a threshold over zero. The +| threshold determines what gets logged. Threshold options are: +| +| 0 = Disables logging, Error logging TURNED OFF +| 1 = Error Messages (including PHP errors) +| 2 = Debug Messages +| 3 = Informational Messages +| 4 = All Messages +| +| You can also pass an array with threshold levels to show individual error types +| +| array(2) = Debug Messages, without Error Messages +| +| For a live site you'll usually only enable Errors (1) to be logged otherwise +| your log files will fill up very fast. +| +*/ +$config['log_threshold'] = 0; + +/* +|-------------------------------------------------------------------------- +| Error Logging Directory Path +|-------------------------------------------------------------------------- +| +| Leave this BLANK unless you would like to set something other than the default +| application/logs/ directory. Use a full server path with trailing slash. +| +*/ +$config['log_path'] = ''; + +/* +|-------------------------------------------------------------------------- +| Log File Extension +|-------------------------------------------------------------------------- +| +| The default filename extension for log files. The default 'php' allows for +| protecting the log files via basic scripting, when they are to be stored +| under a publicly accessible directory. +| +| Note: Leaving it blank will default to 'php'. +| +*/ +$config['log_file_extension'] = ''; + +/* +|-------------------------------------------------------------------------- +| Log File Permissions +|-------------------------------------------------------------------------- +| +| The file system permissions to be applied on newly created log files. +| +| IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal +| integer notation (i.e. 0700, 0644, etc.) +*/ +$config['log_file_permissions'] = 0644; + +/* +|-------------------------------------------------------------------------- +| Date Format for Logs +|-------------------------------------------------------------------------- +| +| Each item that is logged has an associated date. You can use PHP date +| codes to set your own date formatting +| +*/ +$config['log_date_format'] = 'Y-m-d H:i:s'; + +/* +|-------------------------------------------------------------------------- +| Error Views Directory Path +|-------------------------------------------------------------------------- +| +| Leave this BLANK unless you would like to set something other than the default +| application/views/errors/ directory. Use a full server path with trailing slash. +| +*/ +$config['error_views_path'] = ''; + +/* +|-------------------------------------------------------------------------- +| Cache Directory Path +|-------------------------------------------------------------------------- +| +| Leave this BLANK unless you would like to set something other than the default +| application/cache/ directory. Use a full server path with trailing slash. +| +*/ +$config['cache_path'] = ''; + +/* +|-------------------------------------------------------------------------- +| Cache Include Query String +|-------------------------------------------------------------------------- +| +| Whether to take the URL query string into consideration when generating +| output cache files. Valid options are: +| +| FALSE = Disabled +| TRUE = Enabled, take all query parameters into account. +| Please be aware that this may result in numerous cache +| files generated for the same page over and over again. +| array('q') = Enabled, but only take into account the specified list +| of query parameters. +| +*/ +$config['cache_query_string'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Encryption Key +|-------------------------------------------------------------------------- +| +| If you use the Encryption class, you must set an encryption key. +| See the user guide for more info. +| +| https://codeigniter.com/user_guide/libraries/encryption.html +| +*/ +$config['encryption_key'] = '1n4uUX6d1Us3quFXKA7ZmqFIaQVC5MtgXlV9ho8F'; + +/* +|-------------------------------------------------------------------------- +| Session Variables +|-------------------------------------------------------------------------- +| +| 'sess_driver' +| +| The storage driver to use: files, database, redis, memcached +| +| 'sess_cookie_name' +| +| The session cookie name, must contain only [0-9a-z_-] characters +| +| 'sess_expiration' +| +| The number of SECONDS you want the session to last. +| Setting to 0 (zero) means expire when the browser is closed. +| +| 'sess_save_path' +| +| The location to save sessions to, driver dependent. +| +| For the 'files' driver, it's a path to a writable directory. +| WARNING: Only absolute paths are supported! +| +| For the 'database' driver, it's a table name. +| Please read up the manual for the format with other session drivers. +| +| IMPORTANT: You are REQUIRED to set a valid save path! +| +| 'sess_match_ip' +| +| Whether to match the user's IP address when reading the session data. +| +| WARNING: If you're using the database driver, don't forget to update +| your session table's PRIMARY KEY when changing this setting. +| +| 'sess_time_to_update' +| +| How many seconds between CI regenerating the session ID. +| +| 'sess_regenerate_destroy' +| +| Whether to destroy session data associated with the old session ID +| when auto-regenerating the session ID. When set to FALSE, the data +| will be later deleted by the garbage collector. +| +| Other session cookie settings are shared with the rest of the application, +| except for 'cookie_prefix' and 'cookie_httponly', which are ignored here. +| +*/ +$config['sess_save_path'] = sys_get_temp_dir(); +$config['sess_driver'] = 'files'; +$config['sess_cookie_name'] = 'session'; +$config['sess_expiration'] = 86400; +// $config['sess_save_path'] = NULL; +$config['sess_match_ip'] = FALSE; +$config['sess_time_to_update'] = 900; +$config['sess_regenerate_destroy'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Cookie Related Variables +|-------------------------------------------------------------------------- +| +| 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions +| 'cookie_domain' = Set to .your-domain.com for site-wide cookies +| 'cookie_path' = Typically will be a forward slash +| 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists. +| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript) +| +| Note: These settings (with the exception of 'cookie_prefix' and +| 'cookie_httponly') will also affect sessions. +| +*/ +$config['cookie_prefix'] = ''; +$config['cookie_domain'] = ''; +$config['cookie_path'] = '/'; +$config['cookie_secure'] = FALSE; +$config['cookie_httponly'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Standardize newlines +|-------------------------------------------------------------------------- +| +| Determines whether to standardize newline characters in input data, +| meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value. +| +| WARNING: This feature is DEPRECATED and currently available only +| for backwards compatibility purposes! +| +*/ +$config['standardize_newlines'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Global XSS Filtering +|-------------------------------------------------------------------------- +| +| Determines whether the XSS filter is always active when GET, POST or +| COOKIE data is encountered +| +| WARNING: This feature is DEPRECATED and currently available only +| for backwards compatibility purposes! +| +*/ +$config['global_xss_filtering'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| 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'] = TRUE; +$config['csrf_token_name'] = 'c_is_active'; +$config['csrf_cookie_name'] = 'frsc'; +$config['csrf_expire'] = 7200; +$config['csrf_regenerate'] = TRUE; +$config['csrf_exclude_uris'] = array('v1/api.*+','member/login','member/forgot','member/reset/.*','member/register','admin/login','admin/forgot','admin/reset/.*','admin/register'); + +/* +|-------------------------------------------------------------------------- +| 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'] = TRUE; + +/* +|-------------------------------------------------------------------------- +| 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'] = ''; +$config['stripe_publish_key'] = 'pk_test_51IWQUwH8oljXErmdg6L4MhsuB6tDdmumlHFfyNaopty2U27pmRcqMX1c868zn838lGQtU1eYV6bKRSQtMFWf36VT00aNsvnTOE'; +$config['stripe_secret_key'] = 'sk_test_51IWQUwH8oljXErmds28KftkL6o6jYIcPgYbBdfEmCPSuAlIh0fgoS4NADcCmsIZbdQ3p5nbAeCOcGkSmo38U9BIe00BdOenrqo'; +$config['mailgun_key'] = ''; +$config['mail_domain'] = ''; +$config['twilio_phone_number'] = ''; +$config['twilio_sid'] = ''; +$config['twilio_token'] = ''; + +$config['jwt_key'] = ''; +$config['jwt_expire_at'] = 3600; +$config['jwt_refresh_expire_at'] = 7200; +$config['platform_name'] = 'outlinegurus'; + +$config['from_email'] = 'charlie@outlinegurus.com'; +$config['image_upload'] = 's3'; +$config['file_upload'] = 's3'; +$config['upload_byte_size_limit'] = 1000000000; +$config['email_smtp'] = [ + 'protocol' => 'smtp', + 'smtp_name' => 'OutlineGurus', + 'smtp_host' => 'smtp.sendgrid.net', + 'smtp_port' => 587, + 'smtp_user' => 'apikey', + 'smtp_pass' => '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', + 'crlf' => "\r\n", + 'newline' => "\r\n", + 'mailtype' => 'html', + 'charset' => 'utf-8' +]; +$config['stripe_currency'] = 'usd'; +$config['prorate_stripe_subscription'] = '1'; +$config['force_cancel'] = ''; +$config['trial_stripe_subscription'] = ''; +$config['auto_sync_stripe_subscription'] = ''; +$config['stripe_endpoint_secret'] = 'whsec_l6Yct5zQh5jmAqNLCq6PUMzkgzO3mwcg'; +$config['jwt_key'] = '544e68498c28710b10af9dc9c7c9530951438f23'; +$config['jwt_expire_at'] = '3600'; +$config['jwt_refresh_expire_at'] = '7200'; +$config['google_client_id'] = '466040660536-l5pq116jdp6cs3b58a7k4t52f5lpa5se.apps.googleusercontent.com'; +$config['google_client_secret'] = 'W_bYoRhly8pf0XJ1IUsk8wC_'; +$config['google_redirect_uri'] = 'http://localhost:9000/google'; +$config['application_name'] = ''; +$config['facebook_client_id'] = ''; +$config['facebook_client_secret'] = ''; +$config['facebook_redirect_uri'] = ''; +$config['facebook_oath_uri'] = 'https://www.facebook.com/v3.0/dialog/oauth'; +$config['aws_version'] = 'latest'; +$config['aws_region'] = 'us-west-001'; +$config['aws_key'] = '001857ead6a1cd00000000001'; +$config['aws_secret'] = 'K001wUKlT3XNApr3SIMiPf5zfe3/NP8'; +$config['aws_bucket'] = '0845b73e5a9db66a71ec0d10'; +$config['aws_endpoint'] = 'https://outlineguru.s3.us-west-001.backblazeb2.com/'; +$config['default_time_zone'] = 'America/New_York'; diff --git a/application/config/constants.php b/application/config/constants.php new file mode 100755 index 0000000..9d9d46f --- /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' => 'localhost', + 'username' => 'root', + 'password' => 'root', + 'database' => 'outlinegurus', + 'dbdriver' => 'mysqli', + 'dbprefix' => '', + 'pconnect' => FALSE, + 'db_debug' => true, + 'cache_on' => FALSE, + 'cachedir' => '', + 'char_set' => 'utf8', + 'dbcollat' => 'utf8_general_ci', + 'swap_pre' => '', + 'port' => '3306', + '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 0000000..59a7991 --- /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/environment.php b/application/config/environment.php new file mode 100755 index 0000000..35936ae --- /dev/null +++ b/application/config/environment.php @@ -0,0 +1,21 @@ + 'ae', + '/ö|œ/' => 'oe', + '/ü/' => 'ue', + '/Ä/' => 'Ae', + '/Ü/' => 'Ue', + '/Ö/' => 'Oe', + '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ|А/' => 'A', + '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ|а/' => 'a', + '/Б/' => 'B', + '/б/' => 'b', + '/Ç|Ć|Ĉ|Ċ|Č/' => 'C', + '/ç|ć|ĉ|ċ|č/' => 'c', + '/Д/' => 'D', + '/д/' => 'd', + '/Ð|Ď|Đ|Δ/' => 'Dj', + '/ð|ď|đ|δ/' => 'dj', + '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ|Е|Э/' => 'E', + '/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ|е|э/' => 'e', + '/Ф/' => 'F', + '/ф/' => 'f', + '/Ĝ|Ğ|Ġ|Ģ|Γ|Г|Ґ/' => 'G', + '/ĝ|ğ|ġ|ģ|γ|г|ґ/' => 'g', + '/Ĥ|Ħ/' => 'H', + '/ĥ|ħ/' => 'h', + '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị|И|Ы/' => 'I', + '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị|и|ы|ї/' => 'i', + '/Ĵ/' => 'J', + '/ĵ/' => 'j', + '/Ķ|Κ|К/' => 'K', + '/ķ|κ|к/' => 'k', + '/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ|Л/' => 'L', + '/ĺ|ļ|ľ|ŀ|ł|λ|л/' => 'l', + '/М/' => 'M', + '/м/' => 'm', + '/Ñ|Ń|Ņ|Ň|Ν|Н/' => 'N', + '/ñ|ń|ņ|ň|ʼn|ν|н/' => 'n', + '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ|О/' => 'O', + '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ|о/' => 'o', + '/П/' => 'P', + '/п/' => 'p', + '/Ŕ|Ŗ|Ř|Ρ|Р/' => 'R', + '/ŕ|ŗ|ř|ρ|р/' => 'r', + '/Ś|Ŝ|Ş|Ș|Š|Σ|С/' => 'S', + '/ś|ŝ|ş|ș|š|ſ|σ|ς|с/' => 's', + '/Ț|Ţ|Ť|Ŧ|τ|Т/' => 'T', + '/ț|ţ|ť|ŧ|т/' => 't', + '/Þ|þ/' => 'th', + '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự|У/' => 'U', + '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự|у/' => 'u', + '/Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ|Й/' => 'Y', + '/ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ|й/' => 'y', + '/В/' => 'V', + '/в/' => 'v', + '/Ŵ/' => 'W', + '/ŵ/' => 'w', + '/Ź|Ż|Ž|Ζ|З/' => 'Z', + '/ź|ż|ž|ζ|з/' => 'z', + '/Æ|Ǽ/' => 'AE', + '/ß/' => 'ss', + '/IJ/' => 'IJ', + '/ij/' => 'ij', + '/Œ/' => 'OE', + '/ƒ/' => 'f', + '/ξ/' => 'ks', + '/π/' => 'p', + '/β/' => 'v', + '/μ/' => 'm', + '/ψ/' => 'ps', + '/Ё/' => 'Yo', + '/ё/' => 'yo', + '/Є/' => 'Ye', + '/є/' => 'ye', + '/Ї/' => 'Yi', + '/Ж/' => 'Zh', + '/ж/' => 'zh', + '/Х/' => 'Kh', + '/х/' => 'kh', + '/Ц/' => 'Ts', + '/ц/' => 'ts', + '/Ч/' => 'Ch', + '/ч/' => 'ch', + '/Ш/' => 'Sh', + '/ш/' => 'sh', + '/Щ/' => 'Shch', + '/щ/' => 'shch', + '/Ъ|ъ|Ь|ь/' => '', + '/Ю/' => 'Yu', + '/ю/' => 'yu', + '/Я/' => 'Ya', + '/я/' => 'ya' +); diff --git a/application/config/hooks.php b/application/config/hooks.php new file mode 100755 index 0000000..a8f38a5 --- /dev/null +++ b/application/config/hooks.php @@ -0,0 +1,13 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/application/config/migration.php b/application/config/migration.php new file mode 100755 index 0000000..8adeac2 --- /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'] = 20200331104402; + +/* +|-------------------------------------------------------------------------- +| 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 0000000..0176533 --- /dev/null +++ b/application/config/mimes.php @@ -0,0 +1,183 @@ + array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'), + 'cpt' => 'application/mac-compactpro', + 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'), + 'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'), + 'dms' => 'application/octet-stream', + 'lha' => 'application/octet-stream', + 'lzh' => 'application/octet-stream', + 'exe' => array('application/octet-stream', 'application/x-msdownload'), + 'class' => 'application/octet-stream', + 'psd' => array('application/x-photoshop', 'image/vnd.adobe.photoshop'), + 'so' => 'application/octet-stream', + 'sea' => 'application/octet-stream', + 'dll' => 'application/octet-stream', + 'oda' => 'application/oda', + 'pdf' => array('application/pdf', 'application/force-download', 'application/x-download', 'binary/octet-stream'), + 'ai' => array('application/pdf', 'application/postscript'), + 'eps' => 'application/postscript', + 'ps' => 'application/postscript', + 'smi' => 'application/smil', + 'smil' => 'application/smil', + 'mif' => 'application/vnd.mif', + 'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'), + 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint', 'application/vnd.ms-office', 'application/msword'), + 'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/x-zip', 'application/zip'), + 'wbxml' => 'application/wbxml', + 'wmlc' => 'application/wmlc', + 'dcr' => 'application/x-director', + 'dir' => 'application/x-director', + 'dxr' => 'application/x-director', + 'dvi' => 'application/x-dvi', + 'gtar' => 'application/x-gtar', + 'gz' => 'application/x-gzip', + 'gzip' => 'application/x-gzip', + 'php' => array('application/x-httpd-php', 'application/php', 'application/x-php', 'text/php', 'text/x-php', 'application/x-httpd-php-source'), + 'php4' => 'application/x-httpd-php', + 'php3' => 'application/x-httpd-php', + 'phtml' => 'application/x-httpd-php', + 'phps' => 'application/x-httpd-php-source', + 'js' => array('application/x-javascript', 'text/plain'), + 'swf' => 'application/x-shockwave-flash', + 'sit' => 'application/x-stuffit', + 'tar' => 'application/x-tar', + 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'), + 'z' => 'application/x-compress', + 'xhtml' => 'application/xhtml+xml', + 'xht' => 'application/xhtml+xml', + 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'), + 'rar' => array('application/x-rar', 'application/rar', 'application/x-rar-compressed'), + 'mid' => 'audio/midi', + 'midi' => 'audio/midi', + 'mpga' => 'audio/mpeg', + 'mp2' => 'audio/mpeg', + 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'), + 'aif' => array('audio/x-aiff', 'audio/aiff'), + 'aiff' => array('audio/x-aiff', 'audio/aiff'), + 'aifc' => 'audio/x-aiff', + 'ram' => 'audio/x-pn-realaudio', + 'rm' => 'audio/x-pn-realaudio', + 'rpm' => 'audio/x-pn-realaudio-plugin', + 'ra' => 'audio/x-realaudio', + 'rv' => 'video/vnd.rn-realvideo', + 'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'), + 'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'), + 'gif' => 'image/gif', + 'jpeg' => array('image/jpeg', 'image/pjpeg'), + 'jpg' => array('image/jpeg', 'image/pjpeg'), + 'jpe' => array('image/jpeg', 'image/pjpeg'), + 'jp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'j2k' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'jpf' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'jpg2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'jpx' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'jpm' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'mj2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'mjp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), + 'png' => array('image/png', 'image/x-png'), + 'tiff' => 'image/tiff', + 'tif' => 'image/tiff', + 'css' => array('text/css', 'text/plain'), + 'html' => array('text/html', 'text/plain'), + 'htm' => array('text/html', 'text/plain'), + 'shtml' => array('text/html', 'text/plain'), + 'txt' => 'text/plain', + 'text' => 'text/plain', + 'log' => array('text/plain', 'text/x-log'), + 'rtx' => 'text/richtext', + 'rtf' => 'text/rtf', + 'xml' => array('application/xml', 'text/xml', 'text/plain'), + 'xsl' => array('application/xml', 'text/xsl', 'text/xml'), + 'mpeg' => 'video/mpeg', + 'mpg' => 'video/mpeg', + 'mpe' => 'video/mpeg', + 'qt' => 'video/quicktime', + 'mov' => 'video/quicktime', + 'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'), + 'movie' => 'video/x-sgi-movie', + 'doc' => array('application/msword', 'application/vnd.ms-office'), + 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'), + 'dot' => array('application/msword', 'application/vnd.ms-office'), + 'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'), + 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'), + 'word' => array('application/msword', 'application/octet-stream'), + 'xl' => 'application/excel', + 'eml' => 'message/rfc822', + 'json' => array('application/json', 'text/json'), + 'pem' => array('application/x-x509-user-cert', 'application/x-pem-file', 'application/octet-stream'), + 'p10' => array('application/x-pkcs10', 'application/pkcs10'), + 'p12' => 'application/x-pkcs12', + 'p7a' => 'application/x-pkcs7-signature', + 'p7c' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'), + 'p7m' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'), + 'p7r' => 'application/x-pkcs7-certreqresp', + 'p7s' => 'application/pkcs7-signature', + 'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert'), + 'crl' => array('application/pkix-crl', 'application/pkcs-crl'), + 'der' => 'application/x-x509-ca-cert', + 'kdb' => 'application/octet-stream', + 'pgp' => 'application/pgp', + 'gpg' => 'application/gpg-keys', + 'sst' => 'application/octet-stream', + 'csr' => 'application/octet-stream', + 'rsa' => 'application/x-pkcs7', + 'cer' => array('application/pkix-cert', 'application/x-x509-ca-cert'), + '3g2' => 'video/3gpp2', + '3gp' => array('video/3gp', 'video/3gpp'), + 'mp4' => 'video/mp4', + 'm4a' => 'audio/x-m4a', + 'f4v' => array('video/mp4', 'video/x-f4v'), + 'flv' => 'video/x-flv', + 'webm' => 'video/webm', + 'aac' => 'audio/x-acc', + 'm4u' => 'application/vnd.mpegurl', + 'm3u' => 'text/plain', + 'xspf' => 'application/xspf+xml', + 'vlc' => 'application/videolan', + 'wmv' => array('video/x-ms-wmv', 'video/x-ms-asf'), + 'au' => 'audio/x-au', + 'ac3' => 'audio/ac3', + 'flac' => 'audio/x-flac', + 'ogg' => array('audio/ogg', 'video/ogg', 'application/ogg'), + 'kmz' => array('application/vnd.google-earth.kmz', 'application/zip', 'application/x-zip'), + 'kml' => array('application/vnd.google-earth.kml+xml', 'application/xml', 'text/xml'), + 'ics' => 'text/calendar', + 'ical' => 'text/calendar', + 'zsh' => 'text/x-scriptzsh', + '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'), + 'odc' => 'application/vnd.oasis.opendocument.chart', + 'otc' => 'application/vnd.oasis.opendocument.chart-template', + 'odf' => 'application/vnd.oasis.opendocument.formula', + 'otf' => 'application/vnd.oasis.opendocument.formula-template', + 'odg' => 'application/vnd.oasis.opendocument.graphics', + 'otg' => 'application/vnd.oasis.opendocument.graphics-template', + 'odi' => 'application/vnd.oasis.opendocument.image', + 'oti' => 'application/vnd.oasis.opendocument.image-template', + 'odp' => 'application/vnd.oasis.opendocument.presentation', + 'otp' => 'application/vnd.oasis.opendocument.presentation-template', + 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', + 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', + 'odt' => 'application/vnd.oasis.opendocument.text', + 'odm' => 'application/vnd.oasis.opendocument.text-master', + 'ott' => 'application/vnd.oasis.opendocument.text-template', + 'oth' => 'application/vnd.oasis.opendocument.text-web' +); diff --git a/application/config/profiler.php b/application/config/profiler.php new file mode 100755 index 0000000..3db22e3 --- /dev/null +++ b/application/config/profiler.php @@ -0,0 +1,14 @@ + my_controller/index +| my-controller/my-method -> my_controller/my_method +*/ + +$route['v1/api/admin/inventory_gallery_image_list/delete'] = 'Admin/Admin_inventory_gallery_image_list_controller/delete'; +$route['admin/inventory_gallery_image_list/view/(:num)'] = 'Admin/Admin_inventory_gallery_image_list_controller/view/$1'; +$route['admin/inventory_gallery_image_list/edit/(:num)'] = 'Admin/Admin_inventory_gallery_image_list_controller/edit/$1'; +$route['v1/api/admin/inventory_attribute/bulk_delete'] = 'Admin/Admin_inventory_attribute_controller/bulk_delete'; +$route['v1/api/home/load_items_by_category_select'] = 'Guest/Home_controller/load_items_by_category_select'; +$route['admin/inventory_gallery_image_list/(:num)'] = 'Admin/Admin_inventory_gallery_image_list_controller/index/$1'; +$route['v1/api/admin/spreadsheet/api_bulk_delete'] = 'Admin/Admin_spreadsheet_api_controller/api_bulk_delete'; +$route['v1/api/admin/inventory_attribute/delete'] = 'Admin/Admin_inventory_attribute_controller/delete'; +$route['v1/api/admin/attribute_type/bulk_delete'] = 'Admin/Admin_attribute_type_controller/bulk_delete'; +$route['admin/inventory_gallery_image_list/add'] = 'Admin/Admin_inventory_gallery_image_list_controller/add'; +$route['admin/inventory_attribute/view/(:num)'] = 'Admin/Admin_inventory_attribute_controller/view/$1'; +$route['admin/inventory_attribute/edit/(:num)'] = 'Admin/Admin_inventory_attribute_controller/edit/$1'; +$route['v1/api/admin/transaction/bulk_delete'] = 'Admin/Admin_transaction_controller/bulk_delete'; +$route['v1/api/admin/spreadsheet/edit/(:num)'] = 'Admin/Admin_spreadsheet_api_controller/edit/$1'; +$route['v1/api/admin/spreadsheet/bulk_delete'] = 'Admin/Admin_spreadsheet_controller/bulk_delete'; +$route['v1/api/member/user_card/set_default'] = 'Member/Member_user_card_controller/set_default'; +$route['v1/api/admin/test_image/bulk_delete'] = 'Admin/Admin_test_image_controller/bulk_delete'; +$route['v1/api/admin/marketing/bulk_delete'] = 'Admin/Admin_marketing_controller/bulk_delete'; +$route['v1/api/admin/attribute_type/delete'] = 'Admin/Admin_attribute_type_controller/delete'; +$route['admin/inventory_gallery_image_list'] = 'Admin/Admin_inventory_gallery_image_list_controller/index/0'; +$route['v1/api/admin/settings/edit/(:num)'] = 'Admin/Admin_setting_controller/edit/$1'; +$route['v1/api/update_spreadsheet/(:num)'] = 'Admin/Admin_spreadsheet_controller/spreadsheet_data/$1'; +$route['v1/api/member/transaction/delete'] = 'Member/Member_transaction_controller/delete'; +$route['v1/api/get_marketing_slug/(:any)'] = 'Admin/Marketing_controller/generate_marketing_slug/$1'; +$route['member/post_review/(:num)/(:num)'] = 'Member/Member_inventory_controller/post_review/$1/$2'; +$route['admin/inventory_attribute/(:num)'] = 'Admin/Admin_inventory_attribute_controller/index/$1'; +$route['admin/attribute_type/view/(:num)'] = 'Admin/Admin_attribute_type_controller/view/$1'; +$route['admin/attribute_type/edit/(:num)'] = 'Admin/Admin_attribute_type_controller/edit/$1'; +$route['v1/api/admin/transaction/delete'] = 'Admin/Admin_transaction_controller/delete'; +$route['v1/api/admin/spreadsheet/(:num)'] = 'Admin/Admin_spreadsheet_api_controller/index/$1'; +$route['v1/api/admin/delete_order_notes'] = 'Admin/Admin_order_controller/delete_order_notes'; +$route['v1/api/member/user_card/delete'] = 'Member/Member_user_card_controller/delete'; +$route['v1/api/member/inventory/delete'] = 'Member/Member_inventory_controller/delete'; +$route['v1/api/home/get_all_categories'] = 'Guest/Home_controller/get_all_categories'; +$route['v1/api/admin/users/view/(:num)'] = 'Admin/Admin_credential_api_controller/view/$1'; +$route['v1/api/admin/users/edit/(:num)'] = 'Admin/Admin_credential_api_controller/edit/$1'; +$route['v1/api/admin/suggestion/delete'] = 'Admin/Admin_suggestion_controller/delete'; +$route['member/transaction/view/(:num)'] = 'Member/Member_transaction_controller/view/$1'; +$route['member/transaction/edit/(:num)'] = 'Member/Member_transaction_controller/edit/$1'; +$route['admin/suggestion/delete/(:num)'] = 'Admin/Admin_suggestion_controller/delete/$1'; +$route['v1/api/admin/professor/delete'] = 'Admin/Admin_professor_controller/delete'; +$route['v1/api/admin/marketing/delete'] = 'Admin/Admin_marketing_controller/delete'; +$route['v1/api/admin/inventory/delete'] = 'Admin/Admin_inventory_controller/delete'; +$route['v1/api/admin/edit_order_notes'] = 'Admin/Admin_order_controller/edit_order_notes'; +$route['admin/transaction/view/(:num)'] = 'Admin/Admin_transaction_controller/view/$1'; +$route['admin/transaction/edit/(:num)'] = 'Admin/Admin_transaction_controller/edit/$1'; +$route['admin/spreadsheet/edit/(:num)'] = 'Admin/Admin_spreadsheet_controller/edit/$1'; +$route['admin/inventory_attribute/add'] = 'Admin/Admin_inventory_attribute_controller/add'; +$route['v1/api/member/suggestion/add'] = 'Member/Member_inventory_controller/add_suggestion'; +$route['v1/api/admin/textbook/delete'] = 'Admin/Admin_textbook_controller/delete'; +$route['v1/api/admin/spreadsheet/add'] = 'Admin/Admin_spreadsheet_api_controller/add'; +$route['v1/api/admin/sms/view/(:num)'] = 'Admin/Admin_sms_api_controller/view/$1'; +$route['v1/api/admin/sms/edit/(:num)'] = 'Admin/Admin_sms_api_controller/edit/$1'; +$route['v1/api/admin/category/delete'] = 'Admin/Admin_category_controller/delete'; +$route['v1/api/admin/add_order_notes'] = 'Admin/Admin_order_controller/add_order_notes'; +$route['member/purchases/view/(:num)'] = 'Member/Member_purchases_controller/view/$1'; +$route['member/inventory/view/(:num)'] = 'Member/Member_inventory_controller/view/$1'; +$route['admin/test_image/edit/(:num)'] = 'Admin/Admin_test_image_controller/edit/$1'; +$route['admin/suggestion/view/(:num)'] = 'Admin/Admin_suggestion_controller/view/$1'; +$route['admin/contact_us/view/(:num)'] = 'Admin/Admin_contact_us_controller/view/$1'; +$route['v1/api/admin/content/delete'] = 'Admin/Admin_content_controller/delete'; +$route['member/review/(:num)/(:num)'] = 'Member/Member_inventory_controller/review/$1/$2'; +$route['member/dispute_order/(:num)'] = 'Member/Member_inventory_controller/dispute_order'; +$route['admin/ticket/resolve/(:num)'] = 'Admin/Admin_ticket_controller/resolve/$1'; +$route['admin/professor/edit/(:num)'] = 'Admin/Admin_professor_controller/edit/$1'; +$route['admin/marketing/view/(:num)'] = 'Admin/Admin_marketing_controller/view/$1'; +$route['admin/marketing/edit/(:num)'] = 'Admin/Admin_marketing_controller/edit/$1'; +$route['admin/inventory/view/(:num)'] = 'Admin/Admin_inventory_controller/view/$1'; +$route['admin/inventory/edit/(:num)'] = 'Admin/Admin_inventory_controller/edit/$1'; +$route['admin/attribute_type/(:num)'] = 'Admin/Admin_attribute_type_controller/index/$1'; +$route['v1/api/update_sheet/(:num)'] = 'Admin/Admin_spreadsheet_controller/update_sheet/$1'; +$route['v1/api/admin/school/delete'] = 'Admin/Admin_school_controller/delete'; +$route['member/dispute/view/(:num)'] = 'Member/Member_dispute_controller/view/$1'; +$route['admin/textbook/edit/(:num)'] = 'Admin/Admin_textbook_controller/edit/$1'; +$route['admin/review/reject/(:num)'] = 'Admin/Admin_review_controller/reject/$1'; +$route['admin/payout/mark_all_paid'] = 'Admin/Admin_payout_controller/mark_all_paid'; +$route['admin/category/edit/(:num)'] = 'Admin/Admin_category_controller/edit/$1'; +$route['v1/api/member/cart/delete'] = 'Member/Member_cart_controller/delete'; +$route['v1/api/file/import/(:any)'] = 'Guest/Image_controller/file_import/$1'; +$route['v1/api/admin/users/(:num)'] = 'Admin/Admin_credential_api_controller/index/$1'; +$route['v1/api/admin/image/delete'] = 'Admin/Admin_image_controller/delete'; +$route['v1/api/admin/color/delete'] = 'Admin/Admin_color_controller/delete'; +$route['v1/api/admin/class/delete'] = 'Admin/Admin_class_controller/delete'; +$route['member/update_credentials'] = 'Member/Member_profile_controller/update_credentials'; +$route['member/transaction/(:num)'] = 'Member/Member_transaction_controller/index/$1'; +$route['admin/setting/edit/(:num)'] = 'Admin/Admin_setting_controller/edit/$1'; +$route['admin/order/refund/(:num)'] = 'Admin/Admin_order_controller/refund/$1'; +$route['admin/inventory_attribute'] = 'Admin/Admin_inventory_attribute_controller/index/0'; +$route['admin/dispute/edit/(:num)'] = 'Admin/Admin_dispute_controller/edit/$1'; +$route['admin/content/edit/(:num)'] = 'Admin/Admin_content_controller/edit/$1'; +$route['v1/api/admin/spreadsheet'] = 'Admin/Admin_spreadsheet_api_controller/index/0'; +$route['v1/api/admin/cart/delete'] = 'Admin/Admin_cart_controller/delete'; +$route['admin/update_credentials'] = 'Admin/Admin_profile_controller/update_credentials'; +$route['admin/transaction/(:num)'] = 'Admin/Admin_transaction_controller/index/$1'; +$route['admin/spreadsheet/(:num)'] = 'Admin/Admin_spreadsheet_controller/index/$1'; +$route['admin/school/edit/(:num)'] = 'Admin/Admin_school_controller/edit/$1'; +$route['admin/refund/edit/(:num)'] = 'Admin/Admin_refund_controller/edit/$1'; +$route['admin/payout/paid/(:num)'] = 'Admin/Admin_payout_controller/paid/$1'; +$route['admin/emails/view/(:num)'] = 'Admin/Admin_email_controller/view/$1'; +$route['admin/emails/edit/(:num)'] = 'Admin/Admin_email_controller/edit/$1'; +$route['admin/attribute_type/add'] = 'Admin/Admin_attribute_type_controller/add'; +$route['v1/api/admin/tax/delete'] = 'Admin/Admin_tax_controller/delete'; +$route['member/user_card/(:num)'] = 'Member/Member_user_card_controller/index/$1'; +$route['member/purchases/(:num)'] = 'Member/Member_purchases_controller/index/$1'; +$route['member/inventory/(:num)'] = 'Member/Member_inventory_controller/index/$1'; +$route['member/cart/view/(:num)'] = 'Member/Member_cart_controller/view/$1'; +$route['member/cart/edit/(:num)'] = 'Member/Member_cart_controller/edit/$1'; +$route['admin/users/view/(:num)'] = 'Admin/Admin_credential_controller/view/$1'; +$route['admin/users/edit/(:num)'] = 'Admin/Admin_credential_controller/edit/$1'; +$route['admin/test_image/(:num)'] = 'Admin/Admin_test_image_controller/index/$1'; +$route['admin/suggestion/(:num)'] = 'Admin/Admin_suggestion_controller/index/$1'; +$route['admin/order/view/(:num)'] = 'Admin/Admin_order_controller/view/$1'; +$route['admin/image/view/(:num)'] = 'Admin/Admin_image_controller/view/$1'; +$route['admin/contact_us/(:num)'] = 'Admin/Admin_contact_us_controller/index/$1'; +$route['admin/color/view/(:num)'] = 'Admin/Admin_color_controller/view/$1'; +$route['admin/color/edit/(:num)'] = 'Admin/Admin_color_controller/edit/$1'; +$route['admin/class/edit/(:num)'] = 'Admin/Admin_class_controller/edit/$1'; +$route['v1/api/member/purchase'] = 'Member/Member_inventory_controller/purchase'; +$route['v1/api/admin/users/add'] = 'Admin/Admin_credential_api_controller/add'; +$route['member/transaction/add'] = 'Member/Member_transaction_controller/add'; +$route['admin/user_card/(:num)'] = 'Admin/Admin_user_card_controller/index/$1'; +$route['admin/professor/(:num)'] = 'Admin/Admin_professor_controller/index/$1'; +$route['admin/marketing/(:num)'] = 'Admin/Admin_marketing_controller/index/$1'; +$route['admin/inventory/(:num)'] = 'Admin/Admin_inventory_controller/index/$1'; +$route['admin/cart/view/(:num)'] = 'Admin/Admin_cart_controller/view/$1'; +$route['admin/cart/edit/(:num)'] = 'Admin/Admin_cart_controller/edit/$1'; +$route['member/dispute/(:num)'] = 'Member/Member_dispute_controller/index/$1'; +$route['admin/transaction/add'] = 'Admin/Admin_transaction_controller/add'; +$route['admin/textbook/(:num)'] = 'Admin/Admin_textbook_controller/index/$1'; +$route['admin/tax/view/(:num)'] = 'Admin/Admin_tax_controller/view/$1'; +$route['admin/tax/edit/(:num)'] = 'Admin/Admin_tax_controller/edit/$1'; +$route['admin/spreadsheet/add'] = 'Admin/Admin_spreadsheet_controller/add'; +$route['admin/sms/view/(:num)'] = 'Admin/Admin_sms_controller/view/$1'; +$route['admin/sms/edit/(:num)'] = 'Admin/Admin_sms_controller/edit/$1'; +$route['admin/category/(:num)'] = 'Admin/Admin_category_controller/index/$1'; +$route['v1/api/stripe_events'] = 'Admin/Stripe_webhooks_api_controller/index'; +$route['v1/api/image/get_all'] = 'Guest/Image_controller/get_all_images'; +$route['v1/api/assets/(:num)'] = 'Guest/Image_controller/paginate/$1'; +$route['v1/api/admin/sms/add'] = 'Admin/Admin_sms_api_controller/add'; +$route['v1/api/add_inventory'] = 'Member/Member_inventory_controller/add_inventory'; +$route['terms_and_conditions'] = 'Guest/Home_controller/terms_and_conditions'; +$route['member/user_card/add'] = 'Member/Member_user_card_controller/add'; +$route['member/ticket/(:num)'] = 'Member/Member_ticket_controller/index/$1'; +$route['member/inventory/add'] = 'Member/Member_inventory_controller/add'; +$route['admin/test_image/add'] = 'Admin/Admin_test_image_controller/add'; +$route['admin/setting/(:num)'] = 'Admin/Admin_setting_controller/index/$1'; +$route['admin/dispute/(:num)'] = 'Admin/Admin_dispute_controller/index/$1'; +$route['admin/content/(:num)'] = 'Admin/Admin_content_controller/index/$1'; +$route['admin/attribute_type'] = 'Admin/Admin_attribute_type_controller/index/0'; +$route['v1/api/image/upload'] = 'Guest/Image_controller'; +$route['v1/api/autocomplete'] = 'Guest/Home_controller/autocomplete'; +$route['member/sales/(:num)'] = 'Member/Member_sales_controller/index/$1'; +$route['member/reset/(:num)'] = 'Member/Member_reset_controller/index/$1'; +$route['member/post_setting'] = 'Member/Member_inventory_controller/post_setting'; +$route['member/post_dispute'] = 'Member/Member_inventory_controller/post_dispute'; +$route['admin/ticket/(:num)'] = 'Admin/Admin_ticket_controller/index/$1'; +$route['admin/school/(:num)'] = 'Admin/Admin_school_controller/index/$1'; +$route['admin/review/(:num)'] = 'Admin/Admin_review_controller/index/$1'; +$route['admin/refund/(:num)'] = 'Admin/Admin_refund_controller/index/$1'; +$route['admin/professor/add'] = 'Admin/Admin_professor_controller/add'; +$route['admin/payout/(:num)'] = 'Admin/Admin_payout_controller/index/$1'; +$route['admin/marketing/add'] = 'Admin/Admin_marketing_controller/add'; +$route['admin/inventory/add'] = 'Admin/Admin_inventory_controller/add'; +$route['admin/emails/(:num)'] = 'Admin/Admin_email_controller/index/$1'; +$route['v1/api/preview_csv'] = 'Guest/Image_controller/preview_csv'; +$route['v1/api/file/upload'] = 'Guest/Image_controller/file_upload'; +$route['v1/api/admin/users'] = 'Admin/Admin_credential_api_controller/index/0'; +$route['member/transaction'] = 'Member/Member_transaction_controller/index/0'; +$route['member/cart/(:num)'] = 'Member/Member_cart_controller/index/$1'; +$route['admin/users/(:num)'] = 'Admin/Admin_credential_controller/index/$1'; +$route['admin/textbook/add'] = 'Admin/Admin_textbook_controller/add'; +$route['admin/order/(:num)'] = 'Admin/Admin_order_controller/index/$1'; +$route['admin/image/(:num)'] = 'Admin/Admin_image_controller/index/$1'; +$route['admin/color/(:num)'] = 'Admin/Admin_color_controller/index/$1'; +$route['admin/class/(:num)'] = 'Admin/Admin_class_controller/index/$1'; +$route['admin/category/add'] = 'Admin/Admin_category_controller/add'; +$route['v1/api/professors'] = 'Guest/Api_controller/get_professors'; +$route['v1/api/get_review'] = 'Guest/Home_controller/get_review'; +$route['member/credential'] = 'Member/Member_profile_credential_controller'; +$route['admin/transaction'] = 'Admin/Admin_transaction_controller/index/0'; +$route['admin/spreadsheet'] = 'Admin/Admin_spreadsheet_controller/index/0'; +$route['admin/dispute/add'] = 'Admin/Admin_dispute_controller/add'; +$route['admin/content/add'] = 'Admin/Admin_content_controller/add'; +$route['admin/cart/(:num)'] = 'Admin/Admin_cart_controller/index/$1'; +$route['v1/api/textbooks'] = 'Guest/Api_controller/get_textbooks'; +$route['v1/api/admin/sms'] = 'Admin/Admin_sms_api_controller'; +$route['member/user_card'] = 'Member/Member_user_card_controller/index/0'; +$route['member/purchases'] = 'Member/Member_purchases_controller/index/0'; +$route['member/inventory'] = 'Member/Member_inventory_controller/index/0'; +$route['member/dashboard'] = 'Member/Member_dashboard_controller'; +$route['admin/test_image'] = 'Admin/Admin_test_image_controller/index/0'; +$route['admin/tax/(:num)'] = 'Admin/Admin_tax_controller/index/$1'; +$route['admin/suggestion'] = 'Admin/Admin_suggestion_controller/index/0'; +$route['admin/school/add'] = 'Admin/Admin_school_controller/add'; +$route['admin/refund/add'] = 'Admin/Admin_refund_controller/add'; +$route['admin/emails/add'] = 'Admin/Admin_email_controller/add'; +$route['admin/credential'] = 'Admin/Admin_profile_credential_controller'; +$route['admin/contact_us'] = 'Admin/Admin_contact_us_controller/index/0'; +$route['member/register'] = 'Member/Member_register_controller'; +$route['member/cart/add'] = 'Member/Member_cart_controller/add'; +$route['admin/users/add'] = 'Admin/Admin_credential_controller/add'; +$route['admin/user_card'] = 'Admin/Admin_user_card_controller/index/0'; +$route['admin/professor'] = 'Admin/Admin_professor_controller/index/0'; +$route['admin/marketing'] = 'Admin/Admin_marketing_controller/index/0'; +$route['admin/inventory'] = 'Admin/Admin_inventory_controller/index/0'; +$route['admin/image/add'] = 'Admin/Admin_image_controller/add'; +$route['admin/dashboard'] = 'Admin/Admin_dashboard_controller'; +$route['admin/color/add'] = 'Admin/Admin_color_controller/add'; +$route['admin/class/add'] = 'Admin/Admin_class_controller/add'; +$route['v1/api/schools'] = 'Guest/Api_controller/get_schools'; +$route['v1/api/courses'] = 'Guest/Api_controller/get_courses'; +$route['v1/api/contact'] = 'Guest/Home_controller/contact'; +$route['privacy_policy'] = 'Guest/Home_controller/privacy_policy'; +$route['preview/(:num)'] = 'Guest/Home_controller/preview/$1'; +$route['member/setting'] = 'Member/Member_inventory_controller/setting'; +$route['member/profile'] = 'Member/Member_profile_controller'; +$route['member/dispute'] = 'Member/Member_dispute_controller/index/0'; +$route['admin/textbook'] = 'Admin/Admin_textbook_controller/index/0'; +$route['admin/settings'] = 'Admin/Admin_setting_controller/index'; +$route['admin/category'] = 'Admin/Admin_category_controller/index/0'; +$route['admin/cart/add'] = 'Admin/Admin_cart_controller/add'; +$route['v1/api/assets'] = 'Guest/Image_controller/paginate/0'; +$route['member/ticket'] = 'Member/Member_ticket_controller/index/0'; +$route['member/logout'] = 'Member/Member_login_controller/logout'; +$route['member/forgot'] = 'Member/Member_forgot_controller'; +$route['admin/tax/add'] = 'Admin/Admin_tax_controller/add'; +$route['admin/sms/add'] = 'Admin/Admin_sms_controller/add'; +$route['admin/setting'] = 'Admin/Admin_setting_controller/index/0'; +$route['admin/profile'] = 'Admin/Admin_profile_controller'; +$route['admin/dispute'] = 'Admin/Admin_dispute_controller/index/0'; +$route['admin/content'] = 'Admin/Admin_content_controller/index/0'; +$route['member/sales'] = 'Member/Member_sales_controller/index/0'; +$route['member/login'] = 'Member/Member_login_controller'; +$route['health_check'] = 'Health_check_controller/index'; +$route['admin/ticket'] = 'Admin/Admin_ticket_controller/index/0'; +$route['admin/school'] = 'Admin/Admin_school_controller/index/0'; +$route['admin/review'] = 'Admin/Admin_review_controller/index/0'; +$route['admin/refund'] = 'Admin/Admin_refund_controller/index/0'; +$route['admin/payout'] = 'Admin/Admin_payout_controller/index/0'; +$route['admin/logout'] = 'Admin/Admin_login_controller/logout'; +$route['admin/emails'] = 'Admin/Admin_email_controller/index/0'; +$route['member/cart'] = 'Member/Member_cart_controller/index/0'; +$route['admin/users'] = 'Admin/Admin_credential_controller/index/0'; +$route['admin/order'] = 'Admin/Admin_order_controller/index/0'; +$route['admin/login'] = 'Admin/Admin_login_controller'; +$route['admin/image'] = 'Admin/Admin_image_controller/index/0'; +$route['admin/color'] = 'Admin/Admin_color_controller/index/0'; +$route['admin/class'] = 'Admin/Admin_class_controller/index/0'; +$route['buy/(:num)'] = 'Guest/Home_controller/buy/$1'; +$route['admin/cart'] = 'Admin/Admin_cart_controller/index/0'; +$route['member/me'] = 'Member/Member_me_controller/me'; +$route['admin/tax'] = 'Admin/Admin_tax_controller/index/0'; +$route['admin/sms'] = 'Admin/Admin_sms_controller'; +$route['facebook'] = 'Member/Member_social_login_controller/facebook'; +$route['admin/me'] = 'Admin/Admin_me_controller/me'; +$route['a/(:any)'] = 'Admin/Marketing_controller/generate_custom_marketing_page/$1'; +$route['migrate'] = 'Migrate'; +$route['contact'] = 'Guest/Home_controller/contact'; +$route['google'] = 'Member/Member_social_login_controller/google'; +$route['(:num)'] = 'Guest/Home_controller/index/$1'; +$route['about'] = 'Guest/Home_controller/about'; +$route['sell'] = 'Guest/Home_controller/sell'; +$route['buy'] = 'Guest/Home_controller/buy'; + +$route['404_override'] = 'Custom404'; +$route['translate_uri_dashes'] = false; +$route['default_controller'] = 'Welcome/index'; diff --git a/application/config/setting.php b/application/config/setting.php new file mode 100755 index 0000000..7697da1 --- /dev/null +++ b/application/config/setting.php @@ -0,0 +1,20 @@ + '50', + 'payout_percentage_seller' => '20', + 'maintenance' => '0', + 'version' => '1.0.0', + 'copyright' => 'Copyright © 2021 Manaknightdigital Inc. All rights reserved.', + 'license_key' => '', + +); \ No newline at end of file diff --git a/application/config/smileys.php b/application/config/smileys.php new file mode 100755 index 0000000..abf9a89 --- /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 0000000..34a4a38 --- /dev/null +++ b/application/config/user_agents.php @@ -0,0 +1,214 @@ + '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', + 'ia_archiver' => 'Alexa Crawler', + 'MJ12bot' => 'Majestic-12', + 'Uptimebot' => 'Uptimebot' +); diff --git a/application/controllers/.DS_Store b/application/controllers/.DS_Store new file mode 100644 index 0000000..242b9d1 Binary files /dev/null and b/application/controllers/.DS_Store differ diff --git a/application/controllers/Admin/Admin_api_controller.php b/application/controllers/Admin/Admin_api_controller.php new file mode 100755 index 0000000..bd8255e --- /dev/null +++ b/application/controllers/Admin/Admin_api_controller.php @@ -0,0 +1,386 @@ + 'application/json', + 'test' => 'application/json', + 'array' => 'application/json', + 'csv' => 'application/csv', + 'html' => 'text/html', + 'jsonp' => 'application/javascript', + 'php' => 'text/plain', + 'xml' => 'application/xml' + ]; + + public $_format = 'json'; + + protected $_test_mode = FALSE; + + public function __construct() + { + parent::__construct(); + + $this->config->load('setting'); + $this->_setting = $this->config->item('setting'); + + $this->_run_middlewares(); + + $this->load->database(); + + if (!is_null($this->_model_file)) + { + $this->load->model($this->_model_file); + } + } + + protected function _middleware() + { + return [ + 'token', + 'token_acl', + 'maintenance' + ]; + } + + /** + * Set Controller into test mode + * + * @return void + */ + public function set_test_mode () + { + $this->_test_mode = TRUE; + $this->_format = 'test'; + } + + /** + * Render api output + * + * @param mixed $data + * @param number $code + * @return string + */ + public function render($data, $code) + { + http_response_code($code); + header('Content-Type: ' . $this->_supported_formats[$this->_format]); + switch ($this->_format) + { + case 'json': + return $this->output->set_content_type($this->_supported_formats[$this->_format]) + ->set_status_header($code) + ->set_output(json_encode($data)); + break; + case 'test': + return $data; + break; + default: + return '
' . print_r($data, TRUE) . '
'; + break; + } + } + + /** + * User token invalid + * + * @return string + */ + public function unauthorize_error_message() + { + return $this->output->set_content_type($this->_supported_formats[$this->_format]) + ->set_status_header(401) + ->set_output(json_encode([ + 'code' => 401, + 'success' => FALSE, + 'message' => 'invalid credentials' + ])); + } + + /** + * User Role invalid + * + * @return string + */ + public function unauthorize_resource_error_message() + { + return $this->output->set_content_type($this->_supported_formats[$this->_format]) + ->set_status_header(406) + ->set_output(json_encode([ + 'code' => 406, + 'success' => FALSE, + 'message' => 'cannot access resource' + ])); + } + + /** + * Success API Call + * + * @return string + */ + public function success($success) + { + $success['code'] = 200; + $success['success'] = TRUE; + return $this->output->set_content_type($this->_supported_formats[$this->_format]) + ->set_status_header(200) + ->set_output(json_encode($success)); + } + + /** + * Invalid form input + * + * @return string + */ + protected function _render_validation_error () + { + $data = []; + $data['code'] = 403; + $data['success'] = FALSE; + $data['error'] = $this->form_validation->error_array(); + return $this->output->set_content_type($this->_supported_formats[$this->_format]) + ->set_status_header(403) + ->set_output(json_encode($data)); + } + + /** + * Render Custom Error + * + * @return string + */ + protected function _render_custom_error ($errors) + { + $data = []; + $data['code'] = 403; + $data['success'] = FALSE; + $data['error'] = $errors; + return $this->output->set_content_type($this->_supported_formats[$this->_format]) + ->set_status_header(403) + ->set_output(json_encode($data)); + } + + /** + * Debug Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dl($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER :
' . print_r($data, TRUE) . '
'); + } + } + + /** + * Debug json Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dj($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER : ' . json_encode($data)); + } + } + + /** + * Get Session + * + * @return mixed + */ + public function get_session() + { + if (!$this->_test_mode) + { + return $_SESSION; + } + + $session = $this->config->item('session_test'); + + if (!$session) + { + $session = []; + } + + return $session; + } + + /** + * Set Session Field + * + * @param string $field + * @param mixed $value + * @return void + */ + public function set_session($field, $value) + { + if (!$this->_test_mode) + { + $_SESSION[$field] = $value; + } + else + { + $session = $this->config->item('session_test'); + if (!$session) + { + $session = []; + } + $session[$field] = $value; + $this->config->set_item('session_test', $session); + } + } + + /** + * Destroy Session + * + * @return void + */ + public function destroy_session() + { + if (!$this->_test_mode) + { + unset($_SESSION); + session_unset(); + } + else + { + $this->config->set_item('session_test', []); + } + } + + /** + * Function to send Emails given slug, payload and email + * + * @param string $slug + * @param mixed $payload + * @param string $email + * @return void + */ + protected function _send_email_notification($slug, $payload, $email) + { + $this->load->model('email_model'); + $this->load->library('mail_service'); + $this->mail_service->set_adapter('smtp'); + $email_template = $this->email_model->get_template($slug, $payload); + + if ($email_template) + { + $from = $this->config->item('from_email'); + return $this->mail_service->send($from, $email, $email_template->subject, $email_template->html); + } + + return FALSE; + } + + /** + * Function to send Sms given slug, payload and phone # + * + * @param string $slug + * @param mixed $payload + * @param string $to + * @return void + */ + protected function _send_sms_notification($slug, $payload, $to) + { + $this->load->model('sms_model'); + $this->load->library('sms_service'); + $this->sms_service->set_adapter('sms'); + $sms_template = $this->sms_model->get_template($slug, $payload); + + if ($sms_template) + { + return $this->sms_service->send($to, $sms_template->content); + } + + return FALSE; + } + + /** + * Function to send Push notification + * + * @param string $slug + * @param mixed $payload + * @param string $to + * @return void + */ + protected function _send_push_notification($device_type, $device_id, $title, $message, $image) + { + $this->load->library('push_notification_service'); + $this->push_notification_service->init(); + return $this->push_notification_service->send($device_type, $device_id, $title, $message, $image); + } + + protected function _run_middlewares () + { + $middlewares = [ + 'token' => new Token_middleware($this, $this->config), + 'token_acl' => new Token_acl_middleware($this, $this->config), + 'maintenance' => new Maintenance_middleware($this, $this->config) + ]; + + foreach ($this->_middleware() as $middleware_key) + { + if (isset($middlewares[$middleware_key])) + { + $result = $middlewares[$middleware_key]->run(); + + if (!$result) + { + return FALSE; + } + } + } + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_role_id () + { + return $this->_role_id; + } + + public function set_role_id ($role_id) + { + $this->_role_id = $role_id; + } + + public function get_valid_role () + { + return $this->_valid_roles; + } + + public function get_setting() + { + return $this->_setting; + } +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_attribute_type_controller.php b/application/controllers/Admin/Admin_attribute_type_controller.php new file mode 100755 index 0000000..8434011 --- /dev/null +++ b/application/controllers/Admin/Admin_attribute_type_controller.php @@ -0,0 +1,267 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Attribute_type_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Attribute_type_admin_list_paginate_view_model( + $this->attribute_type_model, + $this->pagination, + '/admin/attribute_type/0'); + $this->_data['view_model']->set_heading('Attribute Type'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_type(($this->input->get('type', TRUE) != NULL) ? $this->input->get('type', TRUE) : NULL); + $this->_data['view_model']->set_field(($this->input->get('field', TRUE) != NULL) ? $this->input->get('field', TRUE) : NULL); + $this->_data['view_model']->set_options(($this->input->get('options', TRUE) != NULL) ? $this->input->get('options', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'type' => $this->_data['view_model']->get_type(), + 'field' => $this->_data['view_model']->get_field(), + 'options' => $this->_data['view_model']->get_options(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->attribute_type_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/attribute_type/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->attribute_type_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Attribute_type', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Attribute_type_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->attribute_type_model->set_form_validation( + $this->form_validation, $this->attribute_type_model->get_all_validation_rule()); + $this->_data['view_model'] = new Attribute_type_admin_add_view_model($this->attribute_type_model); + $this->_data['view_model']->set_heading('Attribute Type'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Attribute_typeAdd', $this->_data); + } + + $type = $this->input->post('type', TRUE); + $field = $this->input->post('field', TRUE); + $options = $this->input->post('options', TRUE); + + $result = $this->attribute_type_model->create([ + 'type' => $type, + 'field' => $field, + 'options' => $options, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/attribute_type/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Attribute_typeAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->attribute_type_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/attribute_type/0'); + } + + include_once __DIR__ . '/../../view_models/Attribute_type_admin_edit_view_model.php'; + $this->form_validation = $this->attribute_type_model->set_form_validation( + $this->form_validation, $this->attribute_type_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Attribute_type_admin_edit_view_model($this->attribute_type_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Attribute Type'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Attribute_typeEdit', $this->_data); + } + + $type = $this->input->post('type', TRUE); + $field = $this->input->post('field', TRUE); + $options = $this->input->post('options', TRUE); + + $result = $this->attribute_type_model->edit([ + 'type' => $type, + 'field' => $field, + 'options' => $options, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/attribute_type/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Attribute_typeEdit', $this->_data); + } + + public function view($id) + { + $model = $this->attribute_type_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/attribute_type/0'); + } + + + include_once __DIR__ . '/../../view_models/Attribute_type_admin_view_view_model.php'; + $this->_data['view_model'] = new Attribute_type_admin_view_view_model($this->attribute_type_model); + $this->_data['view_model']->set_heading('Attribute Type'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/Attribute_typeView', $this->_data); + } + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->attribute_type_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->attribute_type_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + public function bulk_delete() + { + + $bulk_items = $this->input->post('bulk_items'); + foreach ($bulk_items as $key => $id) { + $this->attribute_type_model->real_delete($id); + } + echo 'success'; + exit(); + } + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_cart_controller.php b/application/controllers/Admin/Admin_cart_controller.php new file mode 100755 index 0000000..0054df6 --- /dev/null +++ b/application/controllers/Admin/Admin_cart_controller.php @@ -0,0 +1,228 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Cart_admin_list_paginate_view_model.php'; + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + $session = $this->get_session(); + $where = []; + $this->_data['view_model'] = new Cart_admin_list_paginate_view_model( + $this->cart_model, + $this->pagination, + '/admin/cart/0'); + $this->_data['view_model']->set_heading('Cart'); + $this->_data['view_model']->set_total_rows($this->cart_model->count($where)); + + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/cart/0'); + $this->_data['view_model']->set_list($this->cart_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Cart', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Cart_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->cart_model->set_form_validation( + $this->form_validation, $this->cart_model->get_all_validation_rule()); + $this->_data['view_model'] = new Cart_admin_add_view_model($this->cart_model); + $this->_data['view_model']->set_heading('Cart'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/CartAdd', $this->_data); + } + + $product_id = $this->input->post('product_id', TRUE); + $user_id = $this->input->post('user_id', TRUE); + $session_id = $this->input->post('session_id', TRUE); + $subtotal = $this->input->post('subtotal', TRUE); + $quantity = $this->input->post('quantity', TRUE); + $total = $this->input->post('total', TRUE); + + $result = $this->cart_model->create([ + 'product_id' => $product_id, + 'user_id' => $user_id, + 'session_id' => $session_id, + 'subtotal' => $subtotal, + 'quantity' => $quantity, + 'total' => $total, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/cart/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/CartAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->cart_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/cart/0'); + } + + include_once __DIR__ . '/../../view_models/Cart_admin_edit_view_model.php'; + $this->form_validation = $this->cart_model->set_form_validation( + $this->form_validation, $this->cart_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Cart_admin_edit_view_model($this->cart_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Cart'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/CartEdit', $this->_data); + } + + $product_id = $this->input->post('product_id', TRUE); + $user_id = $this->input->post('user_id', TRUE); + $session_id = $this->input->post('session_id', TRUE); + $subtotal = $this->input->post('subtotal', TRUE); + $quantity = $this->input->post('quantity', TRUE); + $total = $this->input->post('total', TRUE); + + $result = $this->cart_model->edit([ + 'product_id' => $product_id, + 'user_id' => $user_id, + 'session_id' => $session_id, + 'subtotal' => $subtotal, + 'quantity' => $quantity, + 'total' => $total, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/cart/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/CartEdit', $this->_data); + } + + public function view($id) + { + $model = $this->cart_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/cart/0'); + } + + + include_once __DIR__ . '/../../view_models/Cart_admin_view_view_model.php'; + $this->_data['view_model'] = new Cart_admin_view_view_model($this->cart_model); + $this->_data['view_model']->set_heading('Cart'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/CartView', $this->_data); + } + + public function delete($id) + { + $model = $this->cart_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/cart/0'); + } + + $result = $this->cart_model->delete($id); + + if ($result) + { + + return $this->redirect('/admin/cart/0', 'refresh'); + } + + $this->error('Error'); + return redirect('/admin/cart/0'); + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_category_controller.php b/application/controllers/Admin/Admin_category_controller.php new file mode 100755 index 0000000..f2d7335 --- /dev/null +++ b/application/controllers/Admin/Admin_category_controller.php @@ -0,0 +1,234 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Category_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Category_admin_list_paginate_view_model( + $this->category_model, + $this->pagination, + '/admin/category/0'); + $this->_data['view_model']->set_heading('Category'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'name' => $this->_data['view_model']->get_name(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->category_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/category/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->category_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Category', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Category_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->category_model->set_form_validation( + $this->form_validation, $this->category_model->get_all_validation_rule()); + $this->_data['view_model'] = new Category_admin_add_view_model($this->category_model); + $this->_data['view_model']->set_heading('Category'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/CategoryAdd', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->category_model->create([ + 'name' => $name, + 'status' => $status, + + ]); + + if ($result) + { + $this->success('Category added.'); + + return $this->redirect('/admin/category/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/CategoryAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->category_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/category/0'); + } + + include_once __DIR__ . '/../../view_models/Category_admin_edit_view_model.php'; + $this->form_validation = $this->category_model->set_form_validation( + $this->form_validation, $this->category_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Category_admin_edit_view_model($this->category_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Category'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/CategoryEdit', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->category_model->edit([ + 'name' => $name, + 'status' => $status, + + ], $id); + + if ($result) + { + $this->success('Category updated.'); + + return $this->redirect('/admin/category/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/CategoryEdit', $this->_data); + } + + + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->category_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->category_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_class_controller.php b/application/controllers/Admin/Admin_class_controller.php new file mode 100755 index 0000000..47250b4 --- /dev/null +++ b/application/controllers/Admin/Admin_class_controller.php @@ -0,0 +1,234 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Class_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Class_admin_list_paginate_view_model( + $this->classes_model, + $this->pagination, + '/admin/class/0'); + $this->_data['view_model']->set_heading('Class'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'name' => $this->_data['view_model']->get_name(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->classes_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/class/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->classes_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Class', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Class_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->classes_model->set_form_validation( + $this->form_validation, $this->classes_model->get_all_validation_rule()); + $this->_data['view_model'] = new Class_admin_add_view_model($this->classes_model); + $this->_data['view_model']->set_heading('Class'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/ClassAdd', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->classes_model->create([ + 'name' => $name, + 'status' => $status, + + ]); + + if ($result) + { + $this->success('Class added.'); + + return $this->redirect('/admin/class/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/ClassAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->classes_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/class/0'); + } + + include_once __DIR__ . '/../../view_models/Class_admin_edit_view_model.php'; + $this->form_validation = $this->classes_model->set_form_validation( + $this->form_validation, $this->classes_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Class_admin_edit_view_model($this->classes_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Class'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/ClassEdit', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->classes_model->edit([ + 'name' => $name, + 'status' => $status, + + ], $id); + + if ($result) + { + $this->success('Class updated.'); + + return $this->redirect('/admin/class/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/ClassEdit', $this->_data); + } + + + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->classes_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->classes_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_color_controller.php b/application/controllers/Admin/Admin_color_controller.php new file mode 100755 index 0000000..b134b70 --- /dev/null +++ b/application/controllers/Admin/Admin_color_controller.php @@ -0,0 +1,212 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Color_admin_list_paginate_view_model.php'; + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + $session = $this->get_session(); + $where = []; + $this->_data['view_model'] = new Color_admin_list_paginate_view_model( + $this->color_model, + $this->pagination, + '/admin/color/0'); + $this->_data['view_model']->set_heading('Color'); + $this->_data['view_model']->set_total_rows($this->color_model->count($where)); + + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/color/0'); + $this->_data['view_model']->set_list($this->color_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Color', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Color_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->color_model->set_form_validation( + $this->form_validation, $this->color_model->get_all_validation_rule()); + $this->_data['view_model'] = new Color_admin_add_view_model($this->color_model); + $this->_data['view_model']->set_heading('Color'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/ColorAdd', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->color_model->create([ + 'name' => $name, + 'status' => $status, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/color/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/ColorAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->color_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/color/0'); + } + + include_once __DIR__ . '/../../view_models/Color_admin_edit_view_model.php'; + $this->form_validation = $this->color_model->set_form_validation( + $this->form_validation, $this->color_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Color_admin_edit_view_model($this->color_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Color'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/ColorEdit', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->color_model->edit([ + 'name' => $name, + 'status' => $status, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/color/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/ColorEdit', $this->_data); + } + + public function view($id) + { + $model = $this->color_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/color/0'); + } + + + include_once __DIR__ . '/../../view_models/Color_admin_view_view_model.php'; + $this->_data['view_model'] = new Color_admin_view_view_model($this->color_model); + $this->_data['view_model']->set_heading('Color'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/ColorView', $this->_data); + } + + public function delete($id) + { + $model = $this->color_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/color/0'); + } + + $result = $this->color_model->delete($id); + + if ($result) + { + + return $this->redirect('/admin/color/0', 'refresh'); + } + + $this->error('Error'); + return redirect('/admin/color/0'); + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_contact_us_controller.php b/application/controllers/Admin/Admin_contact_us_controller.php new file mode 100755 index 0000000..05ff166 --- /dev/null +++ b/application/controllers/Admin/Admin_contact_us_controller.php @@ -0,0 +1,132 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Contact_us_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Contact_us_admin_list_paginate_view_model( + $this->contact_us_model, + $this->pagination, + '/admin/contact_us/0'); + $this->_data['view_model']->set_heading('Contact'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL); + $this->_data['view_model']->set_email(($this->input->get('email', TRUE) != NULL) ? $this->input->get('email', TRUE) : NULL); + $this->_data['view_model']->set_message(($this->input->get('message', TRUE) != NULL) ? $this->input->get('message', TRUE) : NULL); + $this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'name' => $this->_data['view_model']->get_name(), + 'email' => $this->_data['view_model']->get_email(), + 'message' => $this->_data['view_model']->get_message(), + 'created_at' => $this->_data['view_model']->get_created_at(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->contact_us_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/contact_us/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->contact_us_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Contact_us', $this->_data); + } + + + + + + public function view($id) + { + $model = $this->contact_us_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/contact_us/0'); + } + + + include_once __DIR__ . '/../../view_models/Contact_us_admin_view_view_model.php'; + $this->_data['view_model'] = new Contact_us_admin_view_view_model($this->contact_us_model); + $this->_data['view_model']->set_heading('Contact'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/Contact_usView', $this->_data); + } + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_content_controller.php b/application/controllers/Admin/Admin_content_controller.php new file mode 100755 index 0000000..66ae8ee --- /dev/null +++ b/application/controllers/Admin/Admin_content_controller.php @@ -0,0 +1,245 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Content_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Content_admin_list_paginate_view_model( + $this->content_model, + $this->pagination, + '/admin/content/0'); + $this->_data['view_model']->set_heading('Content'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_content_name(($this->input->get('content_name', TRUE) != NULL) ? $this->input->get('content_name', TRUE) : NULL); + $this->_data['view_model']->set_content_type(($this->input->get('content_type', TRUE) != NULL) ? $this->input->get('content_type', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'content_name' => $this->_data['view_model']->get_content_name(), + 'content_type' => $this->_data['view_model']->get_content_type(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->content_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/content/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->content_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Content', $this->_data); + } + + public function add() + { + return $this->redirect('admin/content'); + include_once __DIR__ . '/../../view_models/Content_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->content_model->set_form_validation( + $this->form_validation, $this->content_model->get_all_validation_rule()); + $this->_data['view_model'] = new Content_admin_add_view_model($this->content_model); + $this->_data['view_model']->set_heading('Content'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/ContentAdd', $this->_data); + } + + $content_name = $this->input->post('content_name', TRUE); + $content_type = $this->input->post('content_type', TRUE); + $content = $this->input->post('content', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->content_model->create([ + 'content_name' => $content_name, + 'content_type' => $content_type, + 'content' => $content, + 'status' => $status, + + ]); + + if ($result) + { + $this->success('Content added.'); + + return $this->redirect('/admin/content/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/ContentAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->content_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/content/0'); + } + + include_once __DIR__ . '/../../view_models/Content_admin_edit_view_model.php'; + // $this->form_validation = $this->content_model->set_form_validation( + // $this->form_validation, $this->content_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Content_admin_edit_view_model($this->content_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Content'); + + + + + if (!$this->input->post('content')) + { + return $this->render('Admin/ContentEdit', $this->_data); + } + + // $content_name = $this->input->post('content_name', TRUE); + // $content_type = $this->input->post('content_type', TRUE); + $content = $this->input->post('content', TRUE); + // $status = $this->input->post('status', TRUE); + + $result = $this->content_model->edit([ + // 'content_name' => $content_name, + // 'content_type' => $content_type, + 'content' => $content, + // 'status' => $status, + + ], $id); + + if ($result) + { + $this->success('Content updated.'); + + return $this->redirect('/admin/content/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/ContentEdit', $this->_data); + } + + + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->content_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->content_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_controller.php b/application/controllers/Admin/Admin_controller.php new file mode 100755 index 0000000..cafcebe --- /dev/null +++ b/application/controllers/Admin/Admin_controller.php @@ -0,0 +1,150 @@ +_data['page_name'] = $this->_page_name; + $this->_data['setting'] = $this->_setting; + $this->_data['layout_clean_mode'] = FALSE; + $this->_run_middlewares(); + $layout_mode = $this->input->get('layout_clean_mode', TRUE); + if (isset($layout_mode) && $layout_mode === '1') + { + $this->_data['layout_clean_mode'] = TRUE; + } + } + + protected function _middleware() + { + return [ + 'auth', 'acl' + ]; + } + + public function render($template, $data) + { + return (!$this->_test_mode) ? $this->_render($template, $data) : $this->_render_test($template, $data); + } + + protected function _render_test($template, $data) + { + return [ + 'header' => $this->load->view('Layout/AdminHeader', $data, TRUE), + 'body' => $this->load->view($template, $data, TRUE), + 'footer' => $this->load->view('Layout/AdminFooter', $data, TRUE), + 'data' => $data, + ]; + } + /** + * Function to return the images for media gallery + */ + public function get_all_images() + { + $this->load->model('image_model'); + $images = $this->image_model->get_all(); + return $images; + } + + protected function _render($template, $data) + { + $data['images'] = $this->get_all_images(); + $data['page_section'] = $template; + $this->load->view('Layout/AdminHeader', $data); + $this->load->view($template, $data); + $this->load->view('Layout/AdminFooter',$data); + } + + /** + * User token invalid + * + * @return string + */ + public function unauthorize_error_message() + { + return $this->output->set_content_type('application/json') + ->set_status_header(401) + ->set_output(json_encode([ + 'code' => 401, + 'success' => FALSE, + 'message' => 'invalid credentials' + ])); + } + + /** + * User Role invalid + * + * @return string + */ + public function unauthorize_resource_error_message() + { + return $this->output->set_content_type('application/json') + ->set_status_header(406) + ->set_output(json_encode([ + 'code' => 406, + 'success' => FALSE, + 'message' => 'cannot access resource' + ])); + } + + /** + * Success API Call + * + * @return string + */ + public function success2($success) + { + $success['code'] = 200; + $success['success'] = TRUE; + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($success)); + } + + /** + * Invalid form input + * + * @return string + */ + protected function _render_validation_error () + { + $data = []; + $data['code'] = 403; + $data['success'] = FALSE; + $data['error'] = $this->form_validation->error_array(); + return $this->output->set_content_type('application/json') + ->set_status_header(403) + ->set_output(json_encode($data)); + } + + /** + * Render Custom Error + * + * @return string + */ + protected function _render_custom_error ($errors) + { + $data = []; + $data['code'] = 403; + $data['success'] = FALSE; + $data['error'] = $errors; + return $this->output->set_content_type('application/json') + ->set_status_header(403) + ->set_output(json_encode($data)); + } +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_credential_api_controller.php b/application/controllers/Admin/Admin_credential_api_controller.php new file mode 100755 index 0000000..e439ee9 --- /dev/null +++ b/application/controllers/Admin/Admin_credential_api_controller.php @@ -0,0 +1,170 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/User_admin_list_paginate_view_model.php'; + + $this->_data['view_model'] = new User_admin_list_paginate_view_model( + $this->credential_model, + $this->pagination, + '/admin/users/0'); + $this->_data['view_model']->set_heading('{{{page_name}}}'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_email(($this->input->get('email', TRUE) != NULL) ? $this->input->get('email', TRUE) : NULL); + $this->_data['view_model']->set_first_name(($this->input->get('first_name', TRUE) != NULL) ? $this->input->get('first_name', TRUE) : NULL); + $this->_data['view_model']->set_last_name(($this->input->get('last_name', TRUE) != NULL) ? $this->input->get('last_name', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'email' => $this->_data['view_model']->get_email(), + 'first_name' => $this->_data['view_model']->get_first_name(), + 'last_name' => $this->_data['view_model']->get_last_name(), + + ]; + + $this->_data['view_model']->set_total_rows($this->credential_model->count_paginated($where)); + + $this->_data['view_model']->set_per_page(10); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->credential_model->get_user_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where)); + return $this->success($this->_data['view_model']->to_json(), 200); + } + + public function add() + { + $this->form_validation = $this->credential_model->set_form_validation( + $this->form_validation, $this->credential_model->get_all_validation_rule()); + + if ($this->form_validation->run() === FALSE) + { + return $this->_render_validation_error(); + } + + $email = $this->input->post('email', TRUE); + $first_name = $this->input->post('first_name', TRUE); + $last_name = $this->input->post('last_name', TRUE); + $phone = $this->input->post('phone', TRUE); + $image = $this->input->post('image', TRUE); + $image_id = $this->input->post('image_id', TRUE); + + $result = $this->credential_model->create([ + 'email' => $email, + 'first_name' => $first_name, + 'last_name' => $last_name, + 'phone' => $phone, + 'image' => $image, + 'image_id' => $image_id, + "password" => str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)), + ]); + + if ($result) + { + + + return $this->success([], 200); + } + + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + public function edit($id) + { + $model = $this->credential_model->get($id); + + if (!$model) + { + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + $this->form_validation = $this->credential_model->set_form_validation( + $this->form_validation, $this->credential_model->get_all_edit_validation_rule()); + + if ($this->form_validation->run() === FALSE) + { + return $this->_render_validation_error(); + } + + $email = $this->input->post('email', TRUE); + $first_name = $this->input->post('first_name', TRUE); + $last_name = $this->input->post('last_name', TRUE); + $phone = $this->input->post('phone', TRUE); + $role_id = $this->input->post('role_id', TRUE); + $status = $this->input->post('status', TRUE); + $image = $this->input->post('image', TRUE); + $image_id = $this->input->post('image_id', TRUE); + + $result = $this->credential_model->edit([ + 'email' => $email, + 'first_name' => $first_name, + 'last_name' => $last_name, + 'phone' => $phone, + 'role_id' => $role_id, + 'status' => $status, + 'image' => $image, + 'image_id' => $image_id, + "password" => str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)), + ], $id); + + if ($result) + { + + + return $this->success([], 200); + } + + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + public function view($id) + { + $model = $this->credential_model->get($id); + + if (!$model) + { + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + + include_once __DIR__ . '/../../view_models/User_admin_view_view_model.php'; + $this->_data['view_model'] = new User_admin_view_view_model($this->credential_model); + $this->_data['view_model']->set_model($model); + return $this->success(['data' => $this->_data['view_model']->to_json()], 200); + } + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_credential_controller.php b/application/controllers/Admin/Admin_credential_controller.php new file mode 100755 index 0000000..e1a5eab --- /dev/null +++ b/application/controllers/Admin/Admin_credential_controller.php @@ -0,0 +1,280 @@ +load->model('admin_operation_model'); + $this->load->model('credential_model'); + } + + public function index($page) + { + $this->load->library('pagination'); + include_once __DIR__ . '/../../view_models/User_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + + if ($order_by == "id") + { + $order_by = 'b_id'; + } + $this->_data['view_model'] = new User_admin_list_paginate_view_model( + $this->credential_model, + $this->pagination, + '/admin/users/0'); + $this->_data['view_model']->set_heading('Users'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_email(($this->input->get('email', TRUE) != NULL) ? $this->input->get('email', TRUE) : NULL); + $this->_data['view_model']->set_first_name(($this->input->get('first_name', TRUE) != NULL) ? $this->input->get('first_name', TRUE) : NULL); + $this->_data['view_model']->set_last_name(($this->input->get('last_name', TRUE) != NULL) ? $this->input->get('last_name', TRUE) : NULL); + + $where = [ + 'user_id' => $this->_data['view_model']->get_id(), + 'email' => $this->_data['view_model']->get_email(), + 'first_name' => $this->_data['view_model']->get_first_name(), + 'last_name' => $this->_data['view_model']->get_last_name() + + ]; + + $this->_data['view_model']->set_total_rows($this->credential_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page(25); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/users/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->credential_model->get_user_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/User', $this->_data); + } + + public function add() + { + $this->load->model('user_model'); + include_once __DIR__ . '/../../view_models/User_admin_add_view_model.php'; + $session = $this->get_session(); + $custom_validation = [ + ['email', 'Email', 'trim|required|valid_email|is_unique[credential.email]'], + ['password', 'Password', 'required'] + ]; + + $custom_validation = array_merge($custom_validation, $this->user_model->get_all_validation_rule()); + + $this->form_validation = $this->user_model->set_form_validation($this->form_validation, $custom_validation); + $this->_data['view_model'] = new User_admin_add_view_model($this->credential_model); + $this->_data['view_model']->set_heading('Users'); + $this->_data['view_data']['roles'] = $this->credential_model->role_id_mapping(); + $this->load->model('image_model'); + $gallery_images = $this->image_model->get_all(); + foreach ($gallery_images as $key => $image) + { + if ($image->type == 4) + { + $image->show_url = $image->url; + } + else + { + $image->show_url = $image->url; + } + $image->type = $this->image_model->type_mapping()[$image->type]; + } + $this->_data['gallery_images'] = $gallery_images; + + $service = new User_service($this->credential_model, $this->user_model); + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/UserAdd', $this->_data); + } + + $email = $this->input->post('email', TRUE); + $first_name = $this->input->post('first_name', TRUE); + $last_name = $this->input->post('last_name', TRUE); + $phone = $this->input->post('phone', TRUE); + $image = $this->input->post('image', TRUE); + $image_id = $this->input->post('image_id', TRUE); + $password = $this->input->post('password'); + $role_id = $this->input->post('role_id'); + + $created_user = $service->create($email, $password, $first_name, $last_name, $role_id, ''); + + if ($created_user) + { + $params = [ + 'image' => $image, + 'phone' => $phone, + 'image_id' => $image_id + ]; + $this->user_model->edit($params, $created_user->id); + + return $this->redirect('/admin/users/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/UserAdd', $this->_data); + } + + public function edit($id) + { + $this->load->model('user_model'); + $model = $this->credential_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/users/0'); + } + + $user = $this->user_model->get($model->user_id); + include_once __DIR__ . '/../../view_models/User_credentials_admin_edit_view_model.php'; + $custom_validation = [ + ['role_id', 'Role', 'required'] + ]; + + $custom_validation = array_merge($custom_validation, $this->user_model->get_all_validation_rule()); + $this->form_validation = $this->user_model->set_form_validation($this->form_validation, $custom_validation); + $this->_data['view_model'] = new User_credentials_admin_edit_view_model($this->credential_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Users'); + $this->_data['view_model']->set_first_name($user->first_name); + $this->_data['view_model']->set_last_name($user->last_name); + $this->_data['view_model']->set_phone($user->phone); + $this->_data['view_model']->set_image($user->image); + $this->_data['view_model']->set_image_id($user->image_id); + $this->_data['view_data']['roles'] = $this->credential_model->role_id_mapping(); + $this->_data['view_data']['status'] = $this->credential_model->status_mapping(); + $this->load->model('image_model'); + $gallery_images = $this->image_model->get_all(); + foreach ($gallery_images as $key => $image) + { + if ($image->type == 4) + { + $image->show_url = $image->url; + } + else + { + $image->show_url = $image->url; + } + $image->type = $this->image_model->type_mapping()[$image->type]; + } + $this->_data['gallery_images'] = $gallery_images; + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/UserEdit', $this->_data); + } + + $email = $this->input->post('email', TRUE); + $first_name = $this->input->post('first_name', TRUE); + $last_name = $this->input->post('last_name', TRUE); + $phone = $this->input->post('phone', TRUE); + $role_id = $this->input->post('role_id', TRUE); + $status = $this->input->post('status', TRUE); + $image = $this->input->post('image', TRUE); + $image_id = $this->input->post('image_id', TRUE); + $password = $this->input->post('password', TRUE); + + $credential_params = [ + 'email' => $email, + 'role_id' => $role_id, + 'status' => $status + ]; + + if (strlen($password) > 2) + { + $credential_params['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)); + } + + $params = [ + 'first_name' => $first_name, + 'last_name' => $last_name, + 'phone' => $phone, + 'image' => $image, + 'image_id' => $image_id + ]; + $credential_obj = $this->credential_model->get_by_field('user_id', $model->user_id); + $credential_result = $this->credential_model->edit($credential_params, $credential_obj->id); + $result = $this->user_model->edit($params, $model->id); + if ($result && $credential_result) + { + $this->success('Saved'); + return $this->redirect('/admin/users/0', 'refresh'); + } + $this->_data['error'] = 'Error'; + return $this->render('Admin/UserEdit', $this->_data); + } + + public function view($id) + { + $model = $this->credential_model->get($id); + $this->load->model('user_model'); + $user = $this->user_model->get_by_field('id', $model->user_id); + $model->first_name = $user->first_name ? $user->first_name : 'N/A'; + $model->last_name = $user->last_name ? $user->last_name : 'N/A'; + $model->image = $user->image ? $user->image : ''; + $model->image_id = $user->image_id ? $user->image_id : '0'; + $model->phone = $user->phone ? $user->phone : 'N/A'; + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/users/0'); + } + + include_once __DIR__ . '/../../view_models/User_admin_view_view_model.php'; + $this->_data['view_model'] = new User_admin_view_view_model($this->credential_model); + $this->_data['view_model']->set_heading('Users'); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_first_name($user->first_name); + $this->_data['view_model']->set_last_name($user->last_name); + $this->_data['view_model']->set_phone($user->phone); + $this->_data['view_model']->set_role_id($model->role_id); + $this->_data['view_model']->set_image($user->image); + $this->_data['view_model']->set_image_id($user->image_id); + + $this->_data['view_model']->set_id($model->user_id); + + return $this->render('Admin/UserView', $this->_data); + } + +} diff --git a/application/controllers/Admin/Admin_dashboard_controller.php b/application/controllers/Admin/Admin_dashboard_controller.php new file mode 100755 index 0000000..ed09c5d --- /dev/null +++ b/application/controllers/Admin/Admin_dashboard_controller.php @@ -0,0 +1,30 @@ +load->model('Admin_operation_model'); + } + + public function index () + { + $this->_data['member_accounts'] = $this->Admin_operation_model->getMemberAccountData(); + $this->_data['member_uploads'] = $this->Admin_operation_model->getMemberUploadData(); + $this->_data['top_school_account'] = $this->Admin_operation_model->getAccountsBySchool(); + $this->_data['top_school_upload'] = $this->Admin_operation_model->getUploadsBySchool(); + return $this->render('Admin/Dashboard', $this->_data); + } +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_dispute_controller.php b/application/controllers/Admin/Admin_dispute_controller.php new file mode 100755 index 0000000..1cf9679 --- /dev/null +++ b/application/controllers/Admin/Admin_dispute_controller.php @@ -0,0 +1,216 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Dispute_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Dispute_admin_list_paginate_view_model( + $this->dispute_model, + $this->pagination, + '/admin/dispute/0'); + $this->_data['view_model']->set_heading('Dispute'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL); + $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL); + $this->_data['view_model']->set_reason(($this->input->get('reason', TRUE) != NULL) ? $this->input->get('reason', TRUE) : NULL); + $this->_data['view_model']->set_stripe_charge_id(($this->input->get('stripe_charge_id', TRUE) != NULL) ? $this->input->get('stripe_charge_id', TRUE) : NULL); + $this->_data['view_model']->set_stripe_dispute_id(($this->input->get('stripe_dispute_id', TRUE) != NULL) ? $this->input->get('stripe_dispute_id', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'order_id' => $this->_data['view_model']->get_order_id(), + 'user_id' => $this->_data['view_model']->get_user_id(), + 'reason' => $this->_data['view_model']->get_reason(), + 'stripe_charge_id' => $this->_data['view_model']->get_stripe_charge_id(), + 'stripe_dispute_id' => $this->_data['view_model']->get_stripe_dispute_id(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->dispute_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/dispute/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->dispute_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Dispute', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Dispute_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->dispute_model->set_form_validation( + $this->form_validation, $this->dispute_model->get_all_validation_rule()); + $this->_data['view_model'] = new Dispute_admin_add_view_model($this->dispute_model); + $this->_data['view_model']->set_heading('Dispute'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/DisputeAdd', $this->_data); + } + + $order_id = $this->input->post('order_id', TRUE); + $user_id = $this->input->post('user_id', TRUE); + $reason = $this->input->post('reason', TRUE); + $explanation = $this->input->post('explanation', TRUE); + $stripe_charge_id = $this->input->post('stripe_charge_id', TRUE); + $stripe_dispute_id = $this->input->post('stripe_dispute_id', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->dispute_model->create([ + 'order_id' => $order_id, + 'user_id' => $user_id, + 'reason' => $reason, + 'explanation' => $explanation, + 'stripe_charge_id' => $stripe_charge_id, + 'stripe_dispute_id' => $stripe_dispute_id, + 'status' => $status, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/dispute/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/DisputeAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->dispute_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/dispute/0'); + } + + include_once __DIR__ . '/../../view_models/Dispute_admin_edit_view_model.php'; + $this->form_validation = $this->dispute_model->set_form_validation( + $this->form_validation, $this->dispute_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Dispute_admin_edit_view_model($this->dispute_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Dispute'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/DisputeEdit', $this->_data); + } + + $order_id = $this->input->post('order_id', TRUE); + $user_id = $this->input->post('user_id', TRUE); + $reason = $this->input->post('reason', TRUE); + $explanation = $this->input->post('explanation', TRUE); + $stripe_charge_id = $this->input->post('stripe_charge_id', TRUE); + $stripe_dispute_id = $this->input->post('stripe_dispute_id', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->dispute_model->edit([ + 'order_id' => $order_id, + 'user_id' => $user_id, + 'reason' => $reason, + 'explanation' => $explanation, + 'stripe_charge_id' => $stripe_charge_id, + 'stripe_dispute_id' => $stripe_dispute_id, + 'status' => $status, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/dispute/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/DisputeEdit', $this->_data); + } + + + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_email_controller.php b/application/controllers/Admin/Admin_email_controller.php new file mode 100755 index 0000000..7cb11f2 --- /dev/null +++ b/application/controllers/Admin/Admin_email_controller.php @@ -0,0 +1,222 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Email_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Email_admin_list_paginate_view_model( + $this->email_model, + $this->pagination, + '/admin/emails/0'); + $this->_data['view_model']->set_heading('Emails'); + $this->_data['view_model']->set_slug(($this->input->get('slug', TRUE) != NULL) ? $this->input->get('slug', TRUE) : NULL); + $this->_data['view_model']->set_subject(($this->input->get('subject', TRUE) != NULL) ? $this->input->get('subject', TRUE) : NULL); + $this->_data['view_model']->set_tag(($this->input->get('tag', TRUE) != NULL) ? $this->input->get('tag', TRUE) : NULL); + + $where = [ + 'slug' => $this->_data['view_model']->get_slug(), + 'subject' => $this->_data['view_model']->get_subject(), + 'tag' => $this->_data['view_model']->get_tag(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->email_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/emails/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->email_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Email', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Email_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->email_model->set_form_validation( + $this->form_validation, $this->email_model->get_all_validation_rule()); + $this->_data['view_model'] = new Email_admin_add_view_model($this->email_model); + $this->_data['view_model']->set_heading('Emails'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/EmailAdd', $this->_data); + } + + $slug = $this->input->post('slug', TRUE); + $subject = $this->input->post('subject', TRUE); + $email_header = $this->input->post('email_header', TRUE); + $email_footer = $this->input->post('email_footer', TRUE); + $subject = $this->input->post('subject', TRUE); + $tag = $this->input->post('tag', TRUE); + $html = $this->input->post('html', TRUE); + + $result = $this->email_model->create([ + 'slug' => $slug, + 'subject' => $subject, + 'email_header' => $email_header, + 'email_footer' => $email_footer, + 'subject' => $subject, + 'tag' => $tag, + 'html' => $html, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/emails/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/EmailAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->email_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/emails/0'); + } + + include_once __DIR__ . '/../../view_models/Email_admin_edit_view_model.php'; + $this->form_validation = $this->email_model->set_form_validation( + $this->form_validation, $this->email_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Email_admin_edit_view_model($this->email_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Emails'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/EmailEdit', $this->_data); + } + + $subject = $this->input->post('subject', TRUE); + $email_header = $this->input->post('email_header', TRUE); + $html = $this->input->post('html', TRUE); + $email_footer = $this->input->post('email_footer', TRUE); + $tag = $this->input->post('tag', TRUE); + + $result = $this->email_model->edit([ + 'subject' => $subject, + 'email_header' => $email_header, + 'html' => $html, + 'email_footer' => $email_footer, + 'tag' => $tag, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/emails/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/EmailEdit', $this->_data); + } + + public function view($id) + { + $model = $this->email_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/emails/0'); + } + + + include_once __DIR__ . '/../../view_models/Email_admin_view_view_model.php'; + $this->_data['view_model'] = new Email_admin_view_view_model($this->email_model); + $this->_data['view_model']->set_heading('Emails'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/EmailView', $this->_data); + } + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_image_controller.php b/application/controllers/Admin/Admin_image_controller.php new file mode 100755 index 0000000..6914f7c --- /dev/null +++ b/application/controllers/Admin/Admin_image_controller.php @@ -0,0 +1,197 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Image_admin_list_paginate_view_model.php'; + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + $session = $this->get_session(); + $where = []; + $this->_data['view_model'] = new Image_admin_list_paginate_view_model( + $this->image_model, + $this->pagination, + '/admin/image/0'); + $this->_data['view_model']->set_heading('Images'); + $this->_data['view_model']->set_total_rows($this->image_model->count($where)); + + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/image/0'); + $this->_data['view_model']->set_list($this->image_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Image', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Image_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->image_model->set_form_validation( + $this->form_validation, $this->image_model->get_all_validation_rule()); + $this->_data['view_model'] = new Image_admin_add_view_model($this->image_model); + $this->_data['view_model']->set_heading('Images'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/ImageAdd', $this->_data); + } + + $url = $this->input->post('url', TRUE); + $type = $this->input->post('type', TRUE); + $type_2 = $this->input->post('type_2', TRUE); + + $result = $this->image_model->create([ + 'url' => $url, + 'type' => $type, + 'type_2' => $type_2, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/image/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/ImageAdd', $this->_data); + } + + + + public function view($id) + { + $model = $this->image_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/image/0'); + } + + + include_once __DIR__ . '/../../view_models/Image_admin_view_view_model.php'; + $this->_data['view_model'] = new Image_admin_view_view_model($this->image_model); + $this->_data['view_model']->set_heading('Images'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/ImageView', $this->_data); + } + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->image_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->image_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_inventory_attribute_controller.php b/application/controllers/Admin/Admin_inventory_attribute_controller.php new file mode 100755 index 0000000..19ed5ab --- /dev/null +++ b/application/controllers/Admin/Admin_inventory_attribute_controller.php @@ -0,0 +1,267 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Inventory_attribute_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Inventory_attribute_admin_list_paginate_view_model( + $this->inventory_attribute_model, + $this->pagination, + '/admin/inventory_attribute/0'); + $this->_data['view_model']->set_heading('Inventory Attribute'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_inventory_id(($this->input->get('inventory_id', TRUE) != NULL) ? $this->input->get('inventory_id', TRUE) : NULL); + $this->_data['view_model']->set_attribute_id(($this->input->get('attribute_id', TRUE) != NULL) ? $this->input->get('attribute_id', TRUE) : NULL); + $this->_data['view_model']->set_value(($this->input->get('value', TRUE) != NULL) ? $this->input->get('value', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'inventory_id' => $this->_data['view_model']->get_inventory_id(), + 'attribute_id' => $this->_data['view_model']->get_attribute_id(), + 'value' => $this->_data['view_model']->get_value(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->inventory_attribute_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/inventory_attribute/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->inventory_attribute_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Inventory_attribute', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Inventory_attribute_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->inventory_attribute_model->set_form_validation( + $this->form_validation, $this->inventory_attribute_model->get_all_validation_rule()); + $this->_data['view_model'] = new Inventory_attribute_admin_add_view_model($this->inventory_attribute_model); + $this->_data['view_model']->set_heading('Inventory Attribute'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Inventory_attributeAdd', $this->_data); + } + + $inventory_id = $this->input->post('inventory_id', TRUE); + $attribute_id = $this->input->post('attribute_id', TRUE); + $value = $this->input->post('value', TRUE); + + $result = $this->inventory_attribute_model->create([ + 'inventory_id' => $inventory_id, + 'attribute_id' => $attribute_id, + 'value' => $value, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/inventory_attribute/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Inventory_attributeAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->inventory_attribute_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/inventory_attribute/0'); + } + + include_once __DIR__ . '/../../view_models/Inventory_attribute_admin_edit_view_model.php'; + $this->form_validation = $this->inventory_attribute_model->set_form_validation( + $this->form_validation, $this->inventory_attribute_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Inventory_attribute_admin_edit_view_model($this->inventory_attribute_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Inventory Attribute'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Inventory_attributeEdit', $this->_data); + } + + $inventory_id = $this->input->post('inventory_id', TRUE); + $attribute_id = $this->input->post('attribute_id', TRUE); + $value = $this->input->post('value', TRUE); + + $result = $this->inventory_attribute_model->edit([ + 'inventory_id' => $inventory_id, + 'attribute_id' => $attribute_id, + 'value' => $value, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/inventory_attribute/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Inventory_attributeEdit', $this->_data); + } + + public function view($id) + { + $model = $this->inventory_attribute_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/inventory_attribute/0'); + } + + + include_once __DIR__ . '/../../view_models/Inventory_attribute_admin_view_view_model.php'; + $this->_data['view_model'] = new Inventory_attribute_admin_view_view_model($this->inventory_attribute_model); + $this->_data['view_model']->set_heading('Inventory Attribute'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/Inventory_attributeView', $this->_data); + } + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->inventory_attribute_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->inventory_attribute_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + public function bulk_delete() + { + + $bulk_items = $this->input->post('bulk_items'); + foreach ($bulk_items as $key => $id) { + $this->inventory_attribute_model->real_delete($id); + } + echo 'success'; + exit(); + } + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_inventory_controller.php b/application/controllers/Admin/Admin_inventory_controller.php new file mode 100755 index 0000000..05921aa --- /dev/null +++ b/application/controllers/Admin/Admin_inventory_controller.php @@ -0,0 +1,474 @@ +load->model('school_model'); + $this->load->model('professor_model'); + $this->load->model('textbook_model'); + $this->load->model('classes_model'); + $this->load->model('user_model'); + $this->load->model('credential_model'); + + } + + + + public function index($page) + { + + $this->load->library('pagination'); + include_once __DIR__ . '/../../view_models/Inventory_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + $previews = $this->input->get('previews', TRUE) ?? ""; + + $this->_data['view_model'] = new Inventory_admin_list_paginate_view_model( + $this->inventory_model, + $this->pagination, + '/admin/inventory/0'); + $this->_data['view_model']->set_heading('Inventory'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_title(($this->input->get('title', TRUE) != NULL) ? $this->input->get('title', TRUE) : NULL); + $this->_data['view_model']->set_school_id(($this->input->get('school_id', TRUE) != NULL) ? $this->input->get('school_id', TRUE) : NULL); + $this->_data['view_model']->set_professor_id(($this->input->get('professor_id', TRUE) != NULL) ? $this->input->get('professor_id', TRUE) : NULL); + $this->_data['view_model']->set_class_id(($this->input->get('class_id', TRUE) != NULL) ? $this->input->get('class_id', TRUE) : NULL); + $this->_data['view_model']->set_textbook_id(($this->input->get('textbook_id', TRUE) != NULL) ? $this->input->get('textbook_id', TRUE) : NULL); + $this->_data['view_model']->set_word_count(($this->input->get('word_count', TRUE) != NULL) ? $this->input->get('word_count', TRUE) : NULL); + $this->_data['view_model']->set_year(($this->input->get('year', TRUE) != NULL) ? $this->input->get('year', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + $this->_data['email'] = ( $this->input->get('email', TRUE) != NULL ) ? $this->input->get('email', TRUE) : NULL; + + $where = [ + 'inventory.id' => $this->_data['view_model']->get_id(), + 'inventory.title' => $this->_data['view_model']->get_title(), + 'inventory.school_id' => $this->_data['view_model']->get_school_id(), + 'inventory.professor_id' => $this->_data['view_model']->get_professor_id(), + 'inventory.class_id' => $this->_data['view_model']->get_class_id(), + 'inventory.isbn' => ($_GET['isbn'] ?? ''), + 'inventory.word_count' => $this->_data['view_model']->get_word_count(), + 'inventory.year' => $this->_data['view_model']->get_year(), + 'inventory.status' => $this->_data['view_model']->get_status(), + 'credential.email' => $this->_data['email'], + ]; + + if ($previews == 2) + { + $this->db->group_start(); + $this->db->where(' feature_image = "" AND feature_image2 = "" AND feature_image3 = "" '); + $this->db->group_end(); + }elseif ($previews == 1) + { + $this->db->group_start(); + $this->db->where(' feature_image != "" OR feature_image2 != "" OR feature_image3 != "" '); + $this->db->group_end(); + } + + $this->_data['view_model']->set_total_rows($this->inventory_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/inventory/0'); + $this->_data['view_model']->set_page($page); + + if ($previews == 2) + { + $this->db->group_start(); + $this->db->where(' feature_image = "" AND feature_image2 = "" AND feature_image3 = "" '); + $this->db->group_end(); + }elseif ($previews == 1) + { + $this->db->group_start(); + $this->db->where(' feature_image != "" OR feature_image2 != "" OR feature_image3 != "" '); + $this->db->group_end(); + } + + $this->_data['view_model']->set_list($this->inventory_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($this->input->get('school_id', TRUE)) + { + $schools = $this->school_model->get_all(['status' => 1, 'id' => $this->input->get('school_id') ]); + } + + + if ($this->input->get('professor_id', TRUE)) + { + $professors = $this->professor_model->get_all(['status' => 1, 'id' => $this->input->get('professor_id') ]); + } + + + if ($this->input->get('class_id', TRUE)) + { + $classes = $this->classes_model->get_all(['status' => 1, 'id' => $this->input->get('class_id') ]); + } + + + if ($this->input->get('isbn', TRUE)) + { + $is_bn = $this->input->get('isbn', TRUE); + $textbooks = $this->db->select('isbn')->from('inventory')->where('isbn', $is_bn)->get()->result_array(); + } + + + + + if( $this->_data['view_model']->get_list()) + { + + foreach ( $this->_data['view_model']->get_list() as $key => &$value) + { + $school_data = $this->school_model->get($value->school_id); + $professor_data = $this->professor_model->get($value->professor_id); + $classes_data = $this->classes_model->get($value->class_id); + $user_data = $this->user_model->get($value->user_id); + $user_data2 = $this->credential_model->get_by_fields(['user_id' => $user_data->id]); + + $value->school_id = isset($school_data->name) ? $school_data->name : ''; + $value->professor_id = isset($professor_data->name) ? $professor_data->name : ''; + $value->class_id = isset($classes_data->name) ? $classes_data->name : ''; + $value->user_id = isset($user_data->first_name) ? $user_data->first_name . " " . $user_data->last_name : ''; + $value->email = isset($user_data2->email) ? $user_data2->email : ''; + } + } + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + $this->_data['previews'] = $previews; + if (!empty($schools)) + { + $this->_data['schools'] = $schools; + } + + if (!empty($professors)) + { + $this->_data['professors'] = $professors; + } + + if (isset($textbooks) && !empty($textbooks)) + { + $this->_data['textbooks'] = $textbooks; + } + + if (!empty($classes)) + { + $this->_data['classes'] = $classes; + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Inventory', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Inventory_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->inventory_model->set_form_validation( + $this->form_validation, $this->inventory_model->get_all_validation_rule()); + $this->_data['view_model'] = new Inventory_admin_add_view_model($this->inventory_model); + $this->_data['view_model']->set_heading('Inventory'); + + $this->load->model('image_model'); + $gallery_images = $this->image_model->get_all(); + foreach ($gallery_images as $key => $image) { + if($image->type == 4){ + $image->show_url = $image->url; + }else + { + $image->show_url = $image->url; + }$image->type = $this->image_model->type_mapping()[$image->type]; + } + $this->_data['gallery_images'] = $gallery_images; + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/InventoryAdd', $this->_data); + } + + $title = $this->input->post('title', TRUE); + $school_id = $this->input->post('school_id', TRUE); + $professor_id = $this->input->post('professor_id', TRUE); + $class_id = $this->input->post('class_id', TRUE); + $textbook_id = $this->input->post('textbook_id', TRUE); + $word_count = $this->input->post('word_count', TRUE); + $year = $this->input->post('year', TRUE); + $isbn = $this->input->post('isbn', TRUE); + $paypal_email = $this->input->post('paypal_email', TRUE); + $file = $this->input->post('file', TRUE); + $file_id = $this->input->post('file_id', TRUE); + $feature_image = $this->input->post('feature_image', TRUE); + $feature_image_id = $this->input->post('feature_image_id', TRUE); + $note_type = $this->input->post('note_type', TRUE); + $description = $this->input->post('description', TRUE); + $inventory_note = $this->input->post('inventory_note', TRUE); + $pin_to_top = $this->input->post('pin_to_top', TRUE); + $approve = $this->input->post('approve', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->inventory_model->create([ + 'title' => $title, + 'school_id' => $school_id, + 'professor_id' => $professor_id, + 'class_id' => $class_id, + 'textbook_id' => $textbook_id, + 'word_count' => $word_count, + 'year' => $year, + 'isbn' => $isbn, + 'paypal_email' => $paypal_email, + 'file' => $file, + 'file_id' => $file_id, + 'feature_image' => $feature_image, + 'feature_image_id' => $feature_image_id, + 'note_type' => $note_type, + 'description' => $description, + 'inventory_note' => $inventory_note, + 'pin_to_top' => $pin_to_top, + 'approve' => $approve, + 'status' => $status, + + ]); + + if ($result) + { + + $this->success('Data has been added successfully.'); + return $this->redirect('/admin/inventory/0?order_by=id&direction=DESC', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/InventoryAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->inventory_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/inventory/0'); + } + + include_once __DIR__ . '/../../view_models/Inventory_admin_edit_view_model.php'; + $this->form_validation = $this->inventory_model->set_form_validation( + $this->form_validation, $this->inventory_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Inventory_admin_edit_view_model($this->inventory_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Inventory'); + + $this->load->model('image_model'); + $gallery_images = $this->image_model->get_all(); + foreach ($gallery_images as $key => $image) { + if($image->type == 4){ + $image->show_url = $image->url; + }else + { + $image->show_url = $image->url; + }$image->type = $this->image_model->type_mapping()[$image->type]; + } + $this->_data['gallery_images'] = $gallery_images; + + + $this->_data['schools'] = $this->school_model->get_all(['status' => 1 , 'id' => $model->school_id]); + $this->_data['professors'] = $this->professor_model->get_all(['status' => 1, 'id' => $model->professor_id]); + $this->_data['classes'] = $this->classes_model->get_all(['status' => 1, 'id' => $model->class_id]); + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/InventoryEdit', $this->_data); + } + + + $school_id = $this->input->post('school_id', TRUE); + $professor_id = $this->input->post('professor_id', TRUE); + $class_id = $this->input->post('class_id', TRUE); + $word_count = $this->input->post('word_count', TRUE); + $year = $this->input->post('year', TRUE); + $isbn = $this->input->post('isbn', TRUE); + $note_type = $this->input->post('note_type', TRUE); + $feature_image3 = $this->input->post('feature_image3', TRUE); + $feature_image2 = $this->input->post('feature_image2', TRUE); + $feature_image = $this->input->post('feature_image', TRUE); + + + $result = $this->inventory_model->edit([ + 'school_id' => $school_id, + 'professor_id' => $professor_id, + 'class_id' => $class_id, + 'word_count' => $word_count, + 'year' => $year, + 'isbn' => $isbn, + 'note_type' => $note_type, + 'feature_image' => $feature_image, + 'feature_image3' => $feature_image3, + 'feature_image2' => $feature_image2, + ], $id); + + if ($result) + { + $this->success('Data has been updated successfully.'); + return $this->redirect('/admin/inventory/0?order_by=id&direction=DESC', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/InventoryEdit', $this->_data); + } + + // public function view($id) + // { + // $model = $this->inventory_model->get($id); + + // if (!$model) + // { + // $this->error('Error'); + // return redirect('/admin/inventory/0'); + // } + + + // include_once __DIR__ . '/../../view_models/Inventory_admin_view_view_model.php'; + // $this->_data['view_model'] = new Inventory_admin_view_view_model($this->inventory_model); + // $this->_data['view_model']->set_heading('Inventory'); + // $this->_data['view_model']->set_model($model); + + + // return $this->render('Admin/InventoryView', $this->_data); + // } + public function view($id) + { + $model = $this->inventory_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/inventory/0'); + } + + include_once __DIR__ . '/../../view_models/Inventory_admin_view_view_model.php'; + $this->_data['view_model'] = new Inventory_admin_view_view_model($this->inventory_model); + $this->_data['view_model']->set_heading('Inventory'); + $this->_data['view_model']->set_model($model); + + //get all school data + $this->_data['school_data'] = array_column($this->school_model->get_all(['status' => 1]),'name','id'); + //get all professor data + $this->_data['professor_data'] = array_column($this->professor_model->get_all(['status' => 1]),'name','id'); + //get all classes data + $this->_data['classes_data'] = array_column($this->classes_model->get_all(['status' => 1]),'name','id'); + //get all textbook data + $this->_data['textbook_data'] = array_column($this->textbook_model->get_all(['status' => 1]),'isbn','id'); + + $this->_data['view_model']->set_school_id( $this->_data['school_data'][$this->_data['view_model']->get_school_id()]); + $this->_data['view_model']->set_professor_id( $this->_data['professor_data'][$this->_data['view_model']->get_professor_id()]); + $this->_data['view_model']->set_class_id( $this->_data['classes_data'][$this->_data['view_model']->get_class_id()]); + // $this->_data['view_model']->set_textbook_id( $this->_data['textbook_data'][$this->_data['view_model']->get_textbook_id()]); + // print_r($this->_data); + // exit; + + return $this->render('Admin/InventoryView', $this->_data); + } + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->inventory_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->inventory_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_inventory_gallery_image_list_controller.php b/application/controllers/Admin/Admin_inventory_gallery_image_list_controller.php new file mode 100755 index 0000000..7376b20 --- /dev/null +++ b/application/controllers/Admin/Admin_inventory_gallery_image_list_controller.php @@ -0,0 +1,252 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Inventory_gallery_image_list_admin_list_paginate_view_model.php'; + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + $session = $this->get_session(); + $where = []; + $this->_data['view_model'] = new Inventory_gallery_image_list_admin_list_paginate_view_model( + $this->inventory_gallery_image_list_model, + $this->pagination, + '/admin/inventory_gallery_image_list/0'); + $this->_data['view_model']->set_heading('Inventory_gallery_image_list'); + $this->_data['view_model']->set_total_rows($this->inventory_gallery_image_list_model->count($where)); + + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/inventory_gallery_image_list/0'); + $this->_data['view_model']->set_list($this->inventory_gallery_image_list_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Inventory_gallery_image_list', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Inventory_gallery_image_list_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->inventory_gallery_image_list_model->set_form_validation( + $this->form_validation, $this->inventory_gallery_image_list_model->get_all_validation_rule()); + $this->_data['view_model'] = new Inventory_gallery_image_list_admin_add_view_model($this->inventory_gallery_image_list_model); + $this->_data['view_model']->set_heading('Inventory_gallery_image_list'); + + $this->load->model('image_model'); + $gallery_images = $this->image_model->get_all(); + foreach ($gallery_images as $key => $image) { + if($image->type == 4){ + $image->show_url = base_url().$image->url; + }else + { + $image->show_url = $image->url; + }$image->type = $this->image_model->type_mapping()[$image->type]; + } + $this->_data['gallery_images'] = $gallery_images; + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Inventory_gallery_image_listAdd', $this->_data); + } + + $inventory_id = $this->input->post('inventory_id', TRUE); + $gallery_image = $this->input->post('gallery_image', TRUE); + $gallery_image_id = $this->input->post('gallery_image_id', TRUE); + $gallery_image_id = $this->input->post('gallery_image_id', TRUE); + $gallery_image_id_id = $this->input->post('gallery_image_id_id', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->inventory_gallery_image_list_model->create([ + 'inventory_id' => $inventory_id, + 'gallery_image' => $gallery_image, + 'gallery_image_id' => $gallery_image_id, + 'gallery_image_id' => $gallery_image_id, + 'gallery_image_id_id' => $gallery_image_id_id, + 'status' => $status, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/inventory_gallery_image_list/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Inventory_gallery_image_listAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->inventory_gallery_image_list_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/inventory_gallery_image_list/0'); + } + + include_once __DIR__ . '/../../view_models/Inventory_gallery_image_list_admin_edit_view_model.php'; + $this->form_validation = $this->inventory_gallery_image_list_model->set_form_validation( + $this->form_validation, $this->inventory_gallery_image_list_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Inventory_gallery_image_list_admin_edit_view_model($this->inventory_gallery_image_list_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Inventory_gallery_image_list'); + + $this->load->model('image_model'); + $gallery_images = $this->image_model->get_all(); + foreach ($gallery_images as $key => $image) { + if($image->type == 4){ + $image->show_url = base_url().$image->url; + }else + { + $image->show_url = $image->url; + }$image->type = $this->image_model->type_mapping()[$image->type]; + } + $this->_data['gallery_images'] = $gallery_images; + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Inventory_gallery_image_listEdit', $this->_data); + } + + $inventory_id = $this->input->post('inventory_id', TRUE); + $gallery_image = $this->input->post('gallery_image', TRUE); + $gallery_image_id = $this->input->post('gallery_image_id', TRUE); + $gallery_image_id = $this->input->post('gallery_image_id', TRUE); + $gallery_image_id_id = $this->input->post('gallery_image_id_id', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->inventory_gallery_image_list_model->edit([ + 'inventory_id' => $inventory_id, + 'gallery_image' => $gallery_image, + 'gallery_image_id' => $gallery_image_id, + 'gallery_image_id' => $gallery_image_id, + 'gallery_image_id_id' => $gallery_image_id_id, + 'status' => $status, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/inventory_gallery_image_list/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Inventory_gallery_image_listEdit', $this->_data); + } + + public function view($id) + { + $model = $this->inventory_gallery_image_list_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/inventory_gallery_image_list/0'); + } + + + include_once __DIR__ . '/../../view_models/Inventory_gallery_image_list_admin_view_view_model.php'; + $this->_data['view_model'] = new Inventory_gallery_image_list_admin_view_view_model($this->inventory_gallery_image_list_model); + $this->_data['view_model']->set_heading('Inventory_gallery_image_list'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/Inventory_gallery_image_listView', $this->_data); + } + + public function delete($id) + { + $model = $this->inventory_gallery_image_list_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/inventory_gallery_image_list/0'); + } + + $result = $this->inventory_gallery_image_list_model->delete($id); + + if ($result) + { + + return $this->redirect('/admin/inventory_gallery_image_list/0', 'refresh'); + } + + $this->error('Error'); + return redirect('/admin/inventory_gallery_image_list/0'); + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_login_controller.php b/application/controllers/Admin/Admin_login_controller.php new file mode 100755 index 0000000..fc646a9 --- /dev/null +++ b/application/controllers/Admin/Admin_login_controller.php @@ -0,0 +1,140 @@ +load->model('credential_model'); + $this->load->model('user_model'); + $this->load->helper('cookie'); + + $service = new User_service($this->credential_model); + if($this->input->cookie('admin_remember_me_token', TRUE) !== null && $this->input->cookie('admin_remember_me_token', TRUE) !== '') + { + $this->_remember_me_login(); + exit(); + } + + $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); + $this->form_validation->set_rules('password', 'Password', 'required'); + $this->_data['portal'] = 'admin'; + + if ($this->form_validation->run() === FALSE) + { + echo $this->load->view('Admin/Login', $this->_data, TRUE); + exit; + } + + $email = $this->input->post('email'); + $password = $this->input->post('password'); + $redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect); + $role = $this->_valid_roles[0]; + $authenticated_user = $service->login_by_role($email, $password, $role); + + if ($authenticated_user) + { + delete_cookie('redirect'); + $user_id = $authenticated_user->user_id; + + if(!empty($this->input->post("remember_me"))) { + $this->load->helper('string'); + $remember_cookie = [ + 'user_id' => $user_id, + 'name' => 'admin_remember_me_token', + 'value' => random_string('alnum', 16), + 'expire' => time()+$this->config->item('cookie_expire'), + 'domain' => base_url() + ]; + $this->load->model('cookies_model'); + $check_cookie = $this->cookies_model->get_by_field('user_id', $user_id); + if($check_cookie) + { + $cookie = $this->cookies_model->edit($remember_cookie, $check_cookie->id); + } + else + { + $cookie = $this->cookies_model->create($remember_cookie); + } + if($cookie) + { + setcookie($remember_cookie['name'], $remember_cookie['value'], $remember_cookie['expire'], $remember_cookie['domain']); + } + } + $this->set_session('credential_id', (int) $authenticated_user->id); + $this->set_session('user_id', (int) $user_id); + $this->set_session('email', (string) $authenticated_user->email); + $this->set_session('role', (string) $authenticated_user->role_id); + return $this->redirect($redirect); + } + + $this->error('Wrong email or password.'); + return $this->redirect('admin/login'); + } + + + public function _remember_me_login() + { + $this->load->helper('string'); + $this->load->model('user_model'); + $this->load->model('credential_model'); + $this->load->model('cookies_model'); + $token_value = $this->input->cookie('admin_remember_me_token', TRUE); + $cookie = $this->cookies_model->get_by_fields(['value' => $token_value]); + $service = new User_service($this->credential_model, $this->user_model); + $redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect); + if($cookie) + { + $user_id = $cookie->user_id; + $credential = $this->credential_model->get_by_field('user_id', $user_id); + $role = $this->_valid_roles[0]; + if($credential->role_id != $role) + { + setcookie('admin_remember_me_token', '', 1, base_url()); + return $this->redirect('admin/login'); + } + $random_string = random_string('alnum', 30); + $this->cookies_model->edit(['value' => $random_string, 'expire' => time()+$this->config->item('cookie_expire')], $cookie->id); + setcookie('admin_remember_me_token', $random_string, time()+$this->config->item('cookie_expire'), base_url()); + $this->set_session('credential_id', (int) $credential->id); + $this->set_session('user_id', (int) $user_id); + $this->set_session('email', (string) $credential->email); + $this->set_session('role', (string) $credential->role_id); + return $this->redirect($redirect); + } + else + { + setcookie('admin_remember_me_token', '', 1, base_url()); + return $this->redirect('admin/login'); + } + + $this->error('Wrong email or password.'); + return $this->redirect('admin/login'); + } + + public function logout () + { + $this->load->helper('cookie'); + setcookie('admin_remember_me_token', '', 1, base_url()); + $this->destroy_session(); + return $this->redirect('admin/login'); + } +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_marketing_controller.php b/application/controllers/Admin/Admin_marketing_controller.php new file mode 100755 index 0000000..9a0028d --- /dev/null +++ b/application/controllers/Admin/Admin_marketing_controller.php @@ -0,0 +1,256 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Marketing_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Marketing_admin_list_paginate_view_model( + $this->marketing_model, + $this->pagination, + '/admin/marketing/0'); + $this->_data['view_model']->set_heading('Marketing'); + $this->_data['view_model']->set_publish_date(($this->input->get('publish_date', TRUE) != NULL) ? $this->input->get('publish_date', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL); + $this->_data['view_model']->set_title(($this->input->get('title', TRUE) != NULL) ? $this->input->get('title', TRUE) : NULL); + + $where = [ + 'publish_date' => $this->_data['view_model']->get_publish_date(), + 'status' => $this->_data['view_model']->get_status(), + 'user_id' => $this->_data['view_model']->get_user_id(), + 'title' => $this->_data['view_model']->get_title(), + ]; + + $this->_data['view_model']->set_total_rows($this->marketing_model->count($where)); + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/marketing/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->marketing_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Marketing', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Marketing_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->marketing_model->set_form_validation( + $this->form_validation, $this->marketing_model->get_all_validation_rule()); + $this->_data['view_model'] = new Marketing_admin_add_view_model($this->marketing_model); + $this->_data['view_model']->set_heading('Marketing'); + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/MarketingAdd', $this->_data); + } + + $title = $this->input->post('title', TRUE); + $seo_title = $this->input->post('seo_title', TRUE); + $seo_description = $this->input->post('seo_description', TRUE); + $content = $this->input->post('content', TRUE); + $slug = $this->input->post('slug', TRUE); + $password_protect = $this->input->post('password_protect', TRUE); + $header_template_path = $this->input->post('header_template_path', TRUE); + $content_template_path = $this->input->post('content_template_path', TRUE); + $footer_template_path = $this->input->post('footer_template_path', TRUE); + $status = $this->input->post('status', TRUE); + $publish_date = date('y-m-d'); + $slug_path = $this->_data['view_model']->marketing_slug_url(); + $result = $this->marketing_model->create([ + 'title' => $title, + 'seo_title' => $seo_title, + 'seo_description' => $seo_description, + 'content' => $content, + 'slug' => $slug_path.$slug, + 'password_protect' => $password_protect, + 'header_template_path' => $header_template_path, + 'content_template_path' => $content_template_path, + 'footer_template_path' => $footer_template_path, + 'status' => $status, + 'publish_date' => $publish_date, + 'user_id' => $session['user_id'] + + ]); + + if ($result) + { + $this->success('Page added successfully'); + + return $this->redirect('/admin/marketing/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/MarketingAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->marketing_model->get($id); + $session = $this->get_session(); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/marketing/0'); + } + + include_once __DIR__ . '/../../view_models/Marketing_admin_edit_view_model.php'; + $this->form_validation = $this->marketing_model->set_form_validation( + $this->form_validation, $this->marketing_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Marketing_admin_edit_view_model($this->marketing_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Marketing'); + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/MarketingEdit', $this->_data); + } + + $title = $this->input->post('title', TRUE); + $seo_title = $this->input->post('seo_title', TRUE); + $seo_description = $this->input->post('seo_description', TRUE); + $content = $this->input->post('content', TRUE); + $slug = $this->input->post('slug', TRUE); + $password_protect = $this->input->post('password_protect', TRUE); + $header_template_path = $this->input->post('header_template_path', TRUE); + $content_template_path = $this->input->post('content_template_path', TRUE); + $footer_template_path = $this->input->post('footer_template_path', TRUE); + $status = $this->input->post('status', TRUE); + + $publish_date = date('y-m-d'); + $slug_path = $this->_data['view_model']->marketing_slug_url(); + + $result = $this->marketing_model->edit([ + 'title' => $title, + 'seo_title' => $seo_title, + 'seo_description' => $seo_description, + 'content' => $content, + 'slug' => $slug_path.$slug, + 'password_protect' => $password_protect, + 'header_template_path' => $header_template_path, + 'content_template_path' => $content_template_path, + 'footer_template_path' => $footer_template_path, + 'status' => $status, + 'publish_date' => $publish_date, + 'user_id' => $session['user_id'] + + ], $id); + + if ($result) + { + $this->success('Page Edited successfully'); + + return $this->redirect('/admin/marketing/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/MarketingEdit', $this->_data); + } + + public function view($id) + { + $model = $this->marketing_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/marketing/0'); + } + + return $this->redirect($model->slug); + } + + public function delete($id) + { + $model = $this->marketing_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/marketing/0'); + } + + + $result = $this->marketing_model->real_delete($id); + + if ($result) + { + $this->success('Page Deleted successfully'); + return $this->redirect('/admin/marketing/0', 'refresh'); + } + + $this->error('Error'); + return redirect('/admin/marketing/0'); + } + + public function bulk_delete() + { + + $bulk_items = $this->input->post('bulk_items'); + foreach ($bulk_items as $key => $id) { + $this->marketing_model->real_delete($id); + } + echo 'success'; + exit(); + } + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_me_controller.php b/application/controllers/Admin/Admin_me_controller.php new file mode 100755 index 0000000..e8f60e1 --- /dev/null +++ b/application/controllers/Admin/Admin_me_controller.php @@ -0,0 +1,60 @@ +get_session(); + $model = $this->credential_model->get($session['credential_id']); + $this->_data['email'] = $model->email; + $this->_data['password'] = ''; + + $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); + $this->form_validation->set_rules('password', 'Password', ''); + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Mes', $this->_data); + } + + $email = $this->input->post('email'); + $password = $this->input->post('password'); + + $payload = [ + 'email' => $email, + ]; + + if (strlen($password) > 1) + { + $payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)); + } + + $result = $this->credential_model->edit($payload, $session['credential_id']); + + if ($result) + { + $this->success('Saved'); + return $this->redirect('/admin/me', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Mes', $this->_data); + } +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_order_controller.php b/application/controllers/Admin/Admin_order_controller.php new file mode 100755 index 0000000..8f162be --- /dev/null +++ b/application/controllers/Admin/Admin_order_controller.php @@ -0,0 +1,209 @@ +load->model('school_model'); + $this->load->model('professor_model'); + $this->load->model('textbook_model'); + $this->load->model('classes_model'); + $this->load->model('user_model'); + $this->load->model('payout_model'); + + } + + + + public function index($page) + { + $this->load->library('pagination'); + include_once __DIR__ . '/../../view_models/Order_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Order_admin_list_paginate_view_model( + $this->order_model, + $this->pagination, + '/admin/order/0'); + $this->_data['view_model']->set_heading('Order'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_purchase_user_id(($this->input->get('purchase_user_id', TRUE) != NULL) ? $this->input->get('purchase_user_id', TRUE) : NULL); + $this->_data['view_model']->set_sale_user_id(($this->input->get('sale_user_id', TRUE) != NULL) ? $this->input->get('sale_user_id', TRUE) : NULL); + $this->_data['view_model']->set_inventory_id(($this->input->get('inventory_id', TRUE) != NULL) ? $this->input->get('inventory_id', TRUE) : NULL); + $this->_data['view_model']->set_order_date(($this->input->get('order_date', TRUE) != NULL) ? $this->input->get('order_date', TRUE) : NULL); + $this->_data['view_model']->set_order_time(($this->input->get('order_time', TRUE) != NULL) ? $this->input->get('order_time', TRUE) : NULL); + $this->_data['view_model']->set_subtotal(($this->input->get('subtotal', TRUE) != NULL) ? $this->input->get('subtotal', TRUE) : NULL); + $this->_data['view_model']->set_tax(($this->input->get('tax', TRUE) != NULL) ? $this->input->get('tax', TRUE) : NULL); + $this->_data['view_model']->set_discount(($this->input->get('discount', TRUE) != NULL) ? $this->input->get('discount', TRUE) : NULL); + $this->_data['view_model']->set_total(($this->input->get('total', TRUE) != NULL) ? $this->input->get('total', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'purchase_user_id' => $this->_data['view_model']->get_purchase_user_id(), + 'sale_user_id' => $this->_data['view_model']->get_sale_user_id(), + 'inventory_id' => $this->_data['view_model']->get_inventory_id(), + 'order_date' => $this->_data['view_model']->get_order_date(), + 'order_time' => $this->_data['view_model']->get_order_time(), + 'subtotal' => $this->_data['view_model']->get_subtotal(), + 'tax' => $this->_data['view_model']->get_tax(), + 'discount' => $this->_data['view_model']->get_discount(), + 'total' => $this->_data['view_model']->get_total(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->order_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/order/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->order_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + // load data + $schools = $this->school_model->get_all(['status' => 1]); + $professors = $this->professor_model->get_all(['status' => 1]); + $textbooks = $this->db->select('isbn')->from('inventory')->get()->result_array(); + $classes = $this->classes_model->get_all(['status' => 1]); + + $inventory_data = $this->db->select('i.*,p.name as professor,s.name as school')->from('inventory i') + ->join('school s','s.id=i.school_id') + ->join('professor p','p.id=i.professor_id') + ->get()->result_array(); + + $user_id_array = $this->user_model->get_all(); + $this->_data['users'] = $user_id_array; + if($user_id_array){ + $user_id_array = array_column($user_id_array,'first_name','id'); + } + + + if( $this->_data['view_model']->get_list()){ + + foreach ( $this->_data['view_model']->get_list() as $key => &$value) { + $value->school_id = ''; + $value->professor_id = ''; + $value->isbn = ''; + $value->purchase_user_id = $user_id_array[$value->purchase_user_id] ?? ''; + foreach ($inventory_data as $ke=> $v) { + # code... + if($v['id']==$value->inventory_id){ + $value->school_id = $v['school']; + $value->professor_id = $v['professor']; + $value->isbn = $v['isbn']; + } + } + + + + } + + } + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Order', $this->_data); + } + + + + + + public function view($id) + { + $model = $this->order_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/order/0'); + } + + + include_once __DIR__ . '/../../view_models/Order_admin_view_view_model.php'; + $this->_data['view_model'] = new Order_admin_view_view_model($this->order_model); + $this->_data['view_model']->set_heading('Order'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/OrderView', $this->_data); + } + public function refund($id){ + + $this->order_model->update('order', [ 'status' => 2 ],['id' => $id ]); + $this->payout_model->update('payout',[ 'status'=>3 ],['order_id' => $id ] ); + $order_data = $this->db->select('*')->from('order')->where('id',$id)->get()->row_array(); + + //create setup intent + $stripe = new \Stripe\StripeClient( + $this->config->item('stripe_secret_key') + ); + + $refund = $stripe->refunds->create([ + 'charge' => $order_data['stripe_charge_id'], + ]); + + if ($refund) + { + $this->success('Order Refunded successfully.'); + } + + return redirect('admin/order/0','refresh'); + } + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_payout_controller.php b/application/controllers/Admin/Admin_payout_controller.php new file mode 100755 index 0000000..1ea8a43 --- /dev/null +++ b/application/controllers/Admin/Admin_payout_controller.php @@ -0,0 +1,149 @@ +load->model('user_model'); + + + } + + + + public function index($page) + { + $this->load->library('pagination'); + include_once __DIR__ . '/../../view_models/Payout_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Payout_admin_list_paginate_view_model( + $this->payout_model, + $this->pagination, + '/admin/payout/0'); + $this->_data['view_model']->set_heading('Payout'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL); + $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL); + $this->_data['view_model']->set_amount(($this->input->get('amount', TRUE) != NULL) ? $this->input->get('amount', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'order_id' => $this->_data['view_model']->get_order_id(), + 'user_id' => $this->_data['view_model']->get_user_id(), + 'amount' => $this->_data['view_model']->get_amount(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->payout_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/payout/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->payout_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + $user_data = $this->user_model->get_all(); + $this->_data['users'] = $user_data; + $user_id_array = []; + $user_email_array = []; + if($user_data){ + $user_id_array = array_column($user_data,'first_name','id'); + $user_email_array = array_column($user_data,'paypal_email','id'); + } + // print_r($user_id_array);exit; + if($this->_data['view_model']->get_list() ){ + + foreach ( $this->_data['view_model']->get_list() as $key => &$value) { + $value->paypal_email = $user_email_array[$value->user_id] ?? ''; + $value->user_id = $user_id_array[$value->user_id] ?? ''; + } + } + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Payout', $this->_data); + } + public function paid($id){ + $this->payout_model->update('payout',['status'=>1],['id'=>$id]); + + $this->success('User paid successfully'); + return redirect('admin/payout/0','refresh'); + } + public function mark_all_paid(){ + + if($_GET['id']){ + + foreach ($_GET['id'] as $key => $value) { + $this->payout_model->update('payout',['status'=>1],['id'=>$value]); + + } + } + + + $this->success('Bulk paid successfully'); + return redirect('admin/payout/0','refresh'); + } + + + + + + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_professor_controller.php b/application/controllers/Admin/Admin_professor_controller.php new file mode 100755 index 0000000..a0e30f5 --- /dev/null +++ b/application/controllers/Admin/Admin_professor_controller.php @@ -0,0 +1,234 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Professor_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Professor_admin_list_paginate_view_model( + $this->professor_model, + $this->pagination, + '/admin/professor/0'); + $this->_data['view_model']->set_heading('Professor'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'name' => $this->_data['view_model']->get_name(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->professor_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/professor/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->professor_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Professor', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Professor_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->professor_model->set_form_validation( + $this->form_validation, $this->professor_model->get_all_validation_rule()); + $this->_data['view_model'] = new Professor_admin_add_view_model($this->professor_model); + $this->_data['view_model']->set_heading('Professor'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/ProfessorAdd', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->professor_model->create([ + 'name' => $name, + 'status' => $status, + + ]); + + if ($result) + { + $this->success('Professor added.'); + + return $this->redirect('/admin/professor/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/ProfessorAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->professor_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/professor/0'); + } + + include_once __DIR__ . '/../../view_models/Professor_admin_edit_view_model.php'; + $this->form_validation = $this->professor_model->set_form_validation( + $this->form_validation, $this->professor_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Professor_admin_edit_view_model($this->professor_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Professor'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/ProfessorEdit', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->professor_model->edit([ + 'name' => $name, + 'status' => $status, + + ], $id); + + if ($result) + { + $this->success('Professor updated.'); + + return $this->redirect('/admin/professor/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/ProfessorEdit', $this->_data); + } + + + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->professor_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->professor_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_profile_controller.php b/application/controllers/Admin/Admin_profile_controller.php new file mode 100755 index 0000000..823b505 --- /dev/null +++ b/application/controllers/Admin/Admin_profile_controller.php @@ -0,0 +1,90 @@ +load->model('credential_model'); + $session = $this->get_session(); + $model = $this->user_model->get($session['user_id']); + $id = $session['user_id']; + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/dashboard'); + } + + $credential = $this->credential_model->get($session['credential_id']); + $email_validation_rules = 'required|valid_email'; + + include_once __DIR__ . '/../../view_models/Admin_profile_view_model.php'; + + if ($this->input->post('email') != $credential->email) + { + $email_validation_rules .= '|is_unique[credential.email]'; + } + + $this->form_validation->set_rules('email', 'Email', $email_validation_rules); + $this->form_validation->set_rules('first_name', 'First Name', 'required'); + $this->form_validation->set_rules('last_name', 'Last Name', 'required'); + + $this->_data['view_model'] = new Admin_profile_view_model($this->user_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_email($credential->email); + $this->_data['view_model']->set_heading('Admin'); + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Profile', $this->_data); + } + + $first_name = $this->input->post('first_name'); + $last_name = $this->input->post('last_name'); + $email = $this->input->post('email'); + $password = $this->input->post('password'); + + $payload = [ + 'first_name' => $first_name, + 'last_name' => $last_name + ]; + + $result = $this->user_model->edit_raw($payload, $id); + + if ($result) + { + $credential_payload = [ + 'email' => $email + ]; + + if (strlen($password) > 0) + { + $credential_payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)); + } + + $result = $this->credential_model->edit_raw($credential_payload, $session['credential_id']); + $this->success('Saved'); + return $this->redirect('/admin/profile', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Profile', $this->_data); + } +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_profile_credential_controller.php b/application/controllers/Admin/Admin_profile_credential_controller.php new file mode 100755 index 0000000..f3299c6 --- /dev/null +++ b/application/controllers/Admin/Admin_profile_credential_controller.php @@ -0,0 +1,79 @@ +load->model('user_model'); + $session = $this->get_session(); + $user_obj = $this->user_model->get($session['user_id']); + $session = $this->get_session(); + $this->load->model($this->_model_file); + $model = $this->credential_model->get($user_obj->credential_id ?? 0); + $id = $user_obj->credential_id ?? 0; + + if (!$model) + { + die(); + } + + include_once __DIR__ . '/../../view_models/Admin_profile_credential_view_model.php'; + $email_validation_rules = 'required|valid_email'; + + if ($this->input->post('email') != $session['email']) + { + $email_validation_rules .= '|is_unique[credential.email]'; + } + + $this->form_validation->set_rules('email', 'Email', $email_validation_rules); + + $this->_data['view_model'] = new Admin_profile_credential_view_model($model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Admin'); + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Credential', $this->_data); + } + + $email = $this->input->post('email'); + $password = $this->input->post('password'); + + $payload = [ + 'email' => $email, + ]; + + if (strlen($password) > 0) + { + $payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)); + } + + $result = $this->credential_model->edit_raw($payload, $id); + + if ($result) + { + $this->success('Saved'); + return $this->redirect('/admin/credential?layout_clean_mode=1', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Credential', $this->_data); + } +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_refund_controller.php b/application/controllers/Admin/Admin_refund_controller.php new file mode 100755 index 0000000..6c29f73 --- /dev/null +++ b/application/controllers/Admin/Admin_refund_controller.php @@ -0,0 +1,226 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Refund_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Refund_admin_list_paginate_view_model( + $this->refund_model, + $this->pagination, + '/admin/refund/0'); + $this->_data['view_model']->set_heading('Refund'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL); + $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL); + $this->_data['view_model']->set_amount(($this->input->get('amount', TRUE) != NULL) ? $this->input->get('amount', TRUE) : NULL); + $this->_data['view_model']->set_reason(($this->input->get('reason', TRUE) != NULL) ? $this->input->get('reason', TRUE) : NULL); + $this->_data['view_model']->set_stripe_charge_id(($this->input->get('stripe_charge_id', TRUE) != NULL) ? $this->input->get('stripe_charge_id', TRUE) : NULL); + $this->_data['view_model']->set_stripe_invoice_id(($this->input->get('stripe_invoice_id', TRUE) != NULL) ? $this->input->get('stripe_invoice_id', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'order_id' => $this->_data['view_model']->get_order_id(), + 'user_id' => $this->_data['view_model']->get_user_id(), + 'amount' => $this->_data['view_model']->get_amount(), + 'reason' => $this->_data['view_model']->get_reason(), + 'stripe_charge_id' => $this->_data['view_model']->get_stripe_charge_id(), + 'stripe_invoice_id' => $this->_data['view_model']->get_stripe_invoice_id(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->refund_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/refund/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->refund_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Refund', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Refund_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->refund_model->set_form_validation( + $this->form_validation, $this->refund_model->get_all_validation_rule()); + $this->_data['view_model'] = new Refund_admin_add_view_model($this->refund_model); + $this->_data['view_model']->set_heading('Refund'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/RefundAdd', $this->_data); + } + + $order_id = $this->input->post('order_id', TRUE); + $user_id = $this->input->post('user_id', TRUE); + $amount = $this->input->post('amount', TRUE); + $reason = $this->input->post('reason', TRUE); + $explanation = $this->input->post('explanation', TRUE); + $receipt_url = $this->input->post('receipt_url', TRUE); + $stripe_charge_id = $this->input->post('stripe_charge_id', TRUE); + $stripe_invoice_id = $this->input->post('stripe_invoice_id', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->refund_model->create([ + 'order_id' => $order_id, + 'user_id' => $user_id, + 'amount' => $amount, + 'reason' => $reason, + 'explanation' => $explanation, + 'receipt_url' => $receipt_url, + 'stripe_charge_id' => $stripe_charge_id, + 'stripe_invoice_id' => $stripe_invoice_id, + 'status' => $status, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/refund/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/RefundAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->refund_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/refund/0'); + } + + include_once __DIR__ . '/../../view_models/Refund_admin_edit_view_model.php'; + $this->form_validation = $this->refund_model->set_form_validation( + $this->form_validation, $this->refund_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Refund_admin_edit_view_model($this->refund_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Refund'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/RefundEdit', $this->_data); + } + + $order_id = $this->input->post('order_id', TRUE); + $user_id = $this->input->post('user_id', TRUE); + $amount = $this->input->post('amount', TRUE); + $reason = $this->input->post('reason', TRUE); + $explanation = $this->input->post('explanation', TRUE); + $receipt_url = $this->input->post('receipt_url', TRUE); + $stripe_charge_id = $this->input->post('stripe_charge_id', TRUE); + $stripe_invoice_id = $this->input->post('stripe_invoice_id', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->refund_model->edit([ + 'order_id' => $order_id, + 'user_id' => $user_id, + 'amount' => $amount, + 'reason' => $reason, + 'explanation' => $explanation, + 'receipt_url' => $receipt_url, + 'stripe_charge_id' => $stripe_charge_id, + 'stripe_invoice_id' => $stripe_invoice_id, + 'status' => $status, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/refund/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/RefundEdit', $this->_data); + } + + + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_review_controller.php b/application/controllers/Admin/Admin_review_controller.php new file mode 100755 index 0000000..cbdd5f9 --- /dev/null +++ b/application/controllers/Admin/Admin_review_controller.php @@ -0,0 +1,134 @@ +load->model('user_model'); + + + } + + + + public function index($page) + { + $this->load->library('pagination'); + include_once __DIR__ . '/../../view_models/Review_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Review_admin_list_paginate_view_model( + $this->review_model, + $this->pagination, + '/admin/review/0'); + $this->_data['view_model']->set_heading('Review'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL); + $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL); + $this->_data['view_model']->set_comment(($this->input->get('comment', TRUE) != NULL) ? $this->input->get('comment', TRUE) : NULL); + $this->_data['view_model']->set_rating(($this->input->get('rating', TRUE) != NULL) ? $this->input->get('rating', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'order_id' => $this->_data['view_model']->get_order_id(), + 'user_id' => $this->_data['view_model']->get_user_id(), + 'comment' => $this->_data['view_model']->get_comment(), + 'rating' => $this->_data['view_model']->get_rating(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->review_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/review/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->review_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + $user_id_array = $this->user_model->get_all(); + $this->_data['users'] = $user_id_array; + if($user_id_array){ + $user_id_array = array_column($user_id_array,'first_name','id'); + } + // print_r($user_id_array);exit; + if($this->_data['view_model']->get_list() ){ + + foreach ( $this->_data['view_model']->get_list() as $key => &$value) { + $value->user_id = $user_id_array[$value->user_id] ?? ''; + } + } + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Review', $this->_data); + } + + public function reject($id){ + $this->review_model->update('review',['status'=>0],['id'=>$id]); + + $this->success('Review Rejected successfully'); + return redirect('admin/review/0','refresh'); + } + + + + + + + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_school_controller.php b/application/controllers/Admin/Admin_school_controller.php new file mode 100755 index 0000000..0b640d6 --- /dev/null +++ b/application/controllers/Admin/Admin_school_controller.php @@ -0,0 +1,234 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/School_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new School_admin_list_paginate_view_model( + $this->school_model, + $this->pagination, + '/admin/school/0'); + $this->_data['view_model']->set_heading('School'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'name' => $this->_data['view_model']->get_name(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->school_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/school/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->school_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/School', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/School_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->school_model->set_form_validation( + $this->form_validation, $this->school_model->get_all_validation_rule()); + $this->_data['view_model'] = new School_admin_add_view_model($this->school_model); + $this->_data['view_model']->set_heading('School'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/SchoolAdd', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->school_model->create([ + 'name' => $name, + 'status' => $status, + + ]); + + if ($result) + { + $this->success('School added.'); + + return $this->redirect('/admin/school/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/SchoolAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->school_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/school/0'); + } + + include_once __DIR__ . '/../../view_models/School_admin_edit_view_model.php'; + $this->form_validation = $this->school_model->set_form_validation( + $this->form_validation, $this->school_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new School_admin_edit_view_model($this->school_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('School'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/SchoolEdit', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->school_model->edit([ + 'name' => $name, + 'status' => $status, + + ], $id); + + if ($result) + { + $this->success('School updated.'); + + return $this->redirect('/admin/school/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/SchoolEdit', $this->_data); + } + + + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->school_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->school_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_setting_controller.php b/application/controllers/Admin/Admin_setting_controller.php new file mode 100755 index 0000000..537885d --- /dev/null +++ b/application/controllers/Admin/Admin_setting_controller.php @@ -0,0 +1,151 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Setting_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Setting_admin_list_paginate_view_model( + $this->setting_model, + $this->pagination, + '/admin/setting/0'); + $this->_data['view_model']->set_heading('Setting'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_key(($this->input->get('key', TRUE) != NULL) ? $this->input->get('key', TRUE) : NULL); + $this->_data['view_model']->set_value(($this->input->get('value', TRUE) != NULL) ? $this->input->get('value', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'key' => $this->_data['view_model']->get_key(), + 'value' => $this->_data['view_model']->get_value(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->setting_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/setting/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->setting_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Setting', $this->_data); + } + + + + public function edit($id) + { + $model = $this->setting_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/setting/0'); + } + + include_once __DIR__ . '/../../view_models/Setting_admin_edit_view_model.php'; + $this->form_validation = $this->setting_model->set_form_validation( + $this->form_validation, $this->setting_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Setting_admin_edit_view_model($this->setting_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Setting'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/SettingEdit', $this->_data); + } + + $value = $this->input->post('value', TRUE); + + $result = $this->setting_model->edit([ + 'value' => $value, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/setting/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/SettingEdit', $this->_data); + } + + + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_sms_api_controller.php b/application/controllers/Admin/Admin_sms_api_controller.php new file mode 100755 index 0000000..efa6bfa --- /dev/null +++ b/application/controllers/Admin/Admin_sms_api_controller.php @@ -0,0 +1,130 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Sms_admin_list_view_model.php'; + $this->_data['view_model'] = new Sms_admin_list_view_model($this->sms_model); + $this->_data['view_model']->set_list($this->sms_model->get_all()); + $this->_data['view_model']->set_heading('Sms'); + return $this->success($this->_data['view_model']->to_json(), 200); + } + + public function add() + { + $this->form_validation = $this->sms_model->set_form_validation( + $this->form_validation, $this->sms_model->get_all_validation_rule()); + + if ($this->form_validation->run() === FALSE) + { + return $this->_render_validation_error(); + } + + $slug = $this->input->post('slug', TRUE); + $content = $this->input->post('content', TRUE); + $tag = $this->input->post('tag', TRUE); + + $result = $this->sms_model->create([ + 'slug' => $slug, + 'content' => $content, + 'tag' => $tag, + + ]); + + if ($result) + { + + + return $this->success([], 200); + } + + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + public function edit($id) + { + $model = $this->sms_model->get($id); + + if (!$model) + { + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + $this->form_validation = $this->sms_model->set_form_validation( + $this->form_validation, $this->sms_model->get_all_edit_validation_rule()); + + if ($this->form_validation->run() === FALSE) + { + return $this->_render_validation_error(); + } + + $content = $this->input->post('content', TRUE); + $tag = $this->input->post('tag', TRUE); + $slug = $this->input->post('slug', TRUE); + + $result = $this->sms_model->edit([ + 'content' => $content, + 'tag' => $tag, + 'slug' => $slug, + + ], $id); + + if ($result) + { + + + return $this->success([], 200); + } + + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + public function view($id) + { + $model = $this->sms_model->get($id); + + if (!$model) + { + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + + include_once __DIR__ . '/../../view_models/Sms_admin_view_view_model.php'; + $this->_data['view_model'] = new Sms_admin_view_view_model($this->sms_model); + $this->_data['view_model']->set_model($model); + return $this->success(['data' => $this->_data['view_model']->to_json()], 200); + } + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_sms_controller.php b/application/controllers/Admin/Admin_sms_controller.php new file mode 100755 index 0000000..3242360 --- /dev/null +++ b/application/controllers/Admin/Admin_sms_controller.php @@ -0,0 +1,159 @@ +load->library('pagination'); + $session = $this->get_session(); + include_once __DIR__ . '/../../view_models/Sms_admin_list_view_model.php'; + $this->_data['view_model'] = new Sms_admin_list_view_model($this->sms_model); + $this->_data['view_model']->set_list($this->sms_model->get_all()); + $this->_data['view_model']->set_heading('SMS'); + + + return $this->render('Admin/Sms', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Sms_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->sms_model->set_form_validation( + $this->form_validation, $this->sms_model->get_all_validation_rule()); + $this->_data['view_model'] = new Sms_admin_add_view_model($this->sms_model); + $this->_data['view_model']->set_heading('SMS'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/SmsAdd', $this->_data); + } + + $slug = $this->input->post('slug', TRUE); + $content = $this->input->post('content', TRUE); + $tag = $this->input->post('tag', TRUE); + + $result = $this->sms_model->create([ + 'slug' => $slug, + 'content' => $content, + 'tag' => $tag, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/sms', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/SmsAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->sms_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/sms'); + } + + include_once __DIR__ . '/../../view_models/Sms_admin_edit_view_model.php'; + $this->form_validation = $this->sms_model->set_form_validation( + $this->form_validation, $this->sms_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Sms_admin_edit_view_model($this->sms_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('SMS'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/SmsEdit', $this->_data); + } + + $content = $this->input->post('content', TRUE); + $tag = $this->input->post('tag', TRUE); + $slug = $this->input->post('slug', TRUE); + + $result = $this->sms_model->edit([ + 'content' => $content, + 'tag' => $tag, + 'slug' => $slug, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/sms', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/SmsEdit', $this->_data); + } + + public function view($id) + { + $model = $this->sms_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/sms'); + } + + + include_once __DIR__ . '/../../view_models/Sms_admin_view_view_model.php'; + $this->_data['view_model'] = new Sms_admin_view_view_model($this->sms_model); + $this->_data['view_model']->set_heading('SMS'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/SmsView', $this->_data); + } + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_spreadsheet_api_controller.php b/application/controllers/Admin/Admin_spreadsheet_api_controller.php new file mode 100755 index 0000000..961d6e0 --- /dev/null +++ b/application/controllers/Admin/Admin_spreadsheet_api_controller.php @@ -0,0 +1,140 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Spreadsheet_admin_list_paginate_view_model.php'; + + $this->_data['view_model'] = new Spreadsheet_admin_list_paginate_view_model( + $this->spreadsheet_model, + $this->pagination, + '/admin/spreadsheet/0'); + $this->_data['view_model']->set_heading('{{{page_name}}}'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL); + $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + $this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'name' => $this->_data['view_model']->get_name(), + 'user_id' => $this->_data['view_model']->get_user_id(), + 'status' => $this->_data['view_model']->get_status(), + 'created_at' => $this->_data['view_model']->get_created_at(), + + ]; + + $this->_data['view_model']->set_total_rows($this->spreadsheet_model->count($where)); + + $this->_data['view_model']->set_per_page(10); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->spreadsheet_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where)); + return $this->success($this->_data['view_model']->to_json(), 200); + } + + public function add() + { + $this->form_validation = $this->spreadsheet_model->set_form_validation( + $this->form_validation, $this->spreadsheet_model->get_all_validation_rule()); + + if ($this->form_validation->run() === FALSE) + { + return $this->_render_validation_error(); + } + + $name = $this->input->post('name', TRUE); + $value = $this->input->post('value', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->spreadsheet_model->create([ + 'name' => $name, + 'value' => $value, + 'status' => $status, + + ]); + + if ($result) + { + $this->success('Spreadsheet added.'); + + return $this->success([], 200); + } + + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + public function edit($id) + { + $model = $this->spreadsheet_model->get($id); + + if (!$model) + { + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + $this->form_validation = $this->spreadsheet_model->set_form_validation( + $this->form_validation, $this->spreadsheet_model->get_all_edit_validation_rule()); + + if ($this->form_validation->run() === FALSE) + { + return $this->_render_validation_error(); + } + + $name = $this->input->post('name', TRUE); + $value = $this->input->post('value', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->spreadsheet_model->edit([ + 'name' => $name, + 'value' => $value, + 'status' => $status, + + ], $id); + + if ($result) + { + $this->success('Spreadsheet updated.'); + + return $this->success([], 200); + } + + return $this->_render_custom_error([ + 'error' => 'Error' + ]); + } + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_spreadsheet_controller.php b/application/controllers/Admin/Admin_spreadsheet_controller.php new file mode 100755 index 0000000..beec310 --- /dev/null +++ b/application/controllers/Admin/Admin_spreadsheet_controller.php @@ -0,0 +1,433 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Spreadsheet_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Spreadsheet_admin_list_paginate_view_model( + $this->spreadsheet_model, + $this->pagination, + '/admin/spreadsheet/0'); + $this->_data['view_model']->set_heading('Spreadsheet'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL); + $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + $this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'name' => $this->_data['view_model']->get_name(), + 'user_id' => $this->_data['view_model']->get_user_id(), + 'status' => $this->_data['view_model']->get_status(), + 'created_at' => $this->_data['view_model']->get_created_at(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->spreadsheet_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/spreadsheet/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->spreadsheet_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Spreadsheet', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Spreadsheet_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->spreadsheet_model->set_form_validation( + $this->form_validation, $this->spreadsheet_model->get_all_validation_rule()); + $this->_data['view_model'] = new Spreadsheet_admin_add_view_model($this->spreadsheet_model); + $this->_data['view_model']->set_heading('Spreadsheet'); + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/SpreadsheetAdd', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $value = $this->input->post('value', TRUE); + $status = $this->input->post('status', TRUE); + + $final_value = ""; + $luckysheet_order = ""; + + $file_name = $_FILES['value']['name']; + + if($file_name != "") + { + + $original_name = ""; + $original_name = explode('.' , $file_name); + if(is_array($original_name) && count($original_name) > 1) + { + $original_name = $original_name[0]; + } + + + + $value_file = fopen($_FILES['value']['tmp_name'], "r"); + if($_FILES['value']['type'] == 'text/csv') + { + $default_delimeter = ";"; + $headers = fgetcsv($value_file, 10000, $default_delimeter); + /** + * Condition for checking and setting up the delimeter for the csv + */ + if(is_array($headers) && count($headers) <= 1) + { + $headers = fgetcsv($value_file, 10000, ','); + if(is_array($headers) && count($headers)>1) + { + $default_delimeter = ","; + } + } + + if(!empty($headers) && is_array($headers)) + { + + $temp_array[] = array(); + for( $x = 0 ; $x < count($headers); $x++) + { + $header_array = array( + 'r' => 0, + 'c' => $x, + 'v' => array( + 'ct' => array( + 'fa' => 'General', + 't' => 'g' + ), + 'm' => $headers[$x], + 'v' => $headers[$x] + ) + ); + $temp_array[$x] = $header_array; + } + $ro = 1 ; //count of rows + while (($data = fgetcsv($value_file, 1000,$default_delimeter)) !== FALSE) + { + + if(!empty($data) && is_array($data)) + { + foreach($data as $data_key => $values) + { + + $body_data = array( + 'r' => $ro, + 'c' => $data_key, + 'v' => array( + 'ct' => array( + 'fa' => 'General', + 't' => 'g' + ), + 'm' => $values, + 'v' => $values + ) + ); + $temp_array[] = $body_data; + } + + + } + $ro++; + } + + + $luckysheet_format = + array( + array( + 'name' => $original_name, //Worksheet name + 'color' => '', //Worksheet color + 'index' => '0', //Worksheet index + 'status' => 1, //Worksheet active status + 'order' => 0, //The order of the worksheet + 'hide' => 0,//Whether worksheet hide + 'row' => 100, //the number of rows in a sheet + 'column' => 36, //the number of columns in a sheet + 'defaultRowHeight' => 19, //Customized default row height + 'defaultColWidth' => 73, //Customized default column width + 'celldata' => $temp_array,//Initial the cell data + 'config' => array( + 'merge' => new ArrayObject(), //merged cells + 'rowlen' => new ArrayObject(), //Table row height + 'columnlen' => new ArrayObject(), //Table column width + 'rowhidden' => new ArrayObject(), //hidden rows + 'colhidden' => new ArrayObject(), //hidden columns + 'borderInfo'=> new ArrayObject(), //borders + 'authority' => new ArrayObject(), //Worksheet protection + ), + 'scrollLeft' => 0, //Left and right scroll bar position + 'scrollTop' => 315, //Up and down scroll bar position + 'luckysheet_select_save' => [], //selected area + 'calcChain' => [],//Formula chain + 'isPivotTable' => false,//Whether is pivot table + 'pivotTable' => new ArrayObject(),//Pivot table settings + 'filter_select' => new ArrayObject(),//Filter range + 'filter' => null,//Filter configuration + 'luckysheet_alternateformat_save' => array(), //Alternate colors + 'luckysheet_alternateformat_save_modelCustom' => [], //Customize alternate colors + 'luckysheet_conditionformat_save' => new ArrayObject(),//condition format + 'frozen' => new ArrayObject(), //freeze row and column configuration + 'chart' => [], //Chart configuration + 'zoomRatio' => 1, // zoom ratio + 'image' => [], //image + 'showGridLines' => 1, //Whether to show grid lines + ) + ); + + $luckysheet_order = json_encode($luckysheet_format); + + } + fclose($value_file); + } + } + else + { + + $luckysheet_format = + array( + array( + 'name' => $name, //Worksheet name + 'color' => '', //Worksheet color + 'index' => '0', //Worksheet index + 'status' => 1, //Worksheet active status + 'order' => 0, //The order of the worksheet + 'hide' => 0,//Whether worksheet hide + 'row' => 100, //the number of rows in a sheet + 'column' => 36, //the number of columns in a sheet + 'defaultRowHeight' => 19, //Customized default row height + 'defaultColWidth' => 73, //Customized default column width + 'celldata' => [],//Initial the cell data + 'config' => array( + 'merge' => new ArrayObject(), //merged cells + 'rowlen' => new ArrayObject(), //Table row height + 'columnlen' => new ArrayObject(), //Table column width + 'rowhidden' => new ArrayObject(), //hidden rows + 'colhidden' => new ArrayObject(), //hidden columns + 'borderInfo'=> new ArrayObject(), //borders + 'authority' => new ArrayObject(), //Worksheet protection + ), + 'scrollLeft' => 0, //Left and right scroll bar position + 'scrollTop' => 315, //Up and down scroll bar position + 'luckysheet_select_save' => [], //selected area + 'calcChain' => [],//Formula chain + 'isPivotTable' => false,//Whether is pivot table + 'pivotTable' => new ArrayObject(),//Pivot table settings + 'filter_select' => new ArrayObject(),//Filter range + 'filter' => null,//Filter configuration + 'luckysheet_alternateformat_save' => array(), //Alternate colors + 'luckysheet_alternateformat_save_modelCustom' => [], //Customize alternate colors + 'luckysheet_conditionformat_save' => new ArrayObject(),//condition format + 'frozen' => new ArrayObject(), //freeze row and column configuration + 'chart' => [], //Chart configuration + 'zoomRatio' => 1, // zoom ratio + 'image' => [], //image + 'showGridLines' => 1, //Whether to show grid lines + ) + ); + + $luckysheet_order = json_encode($luckysheet_format); + + } + + $result = $this->spreadsheet_model->create([ + 'name' => $name, + 'value' => $luckysheet_order, + 'status' => $status, + 'user_id' => $session['user_id'] + + ]); + + if ($result) + { + $this->success('Spreadsheet added.'); + + return $this->redirect('/admin/spreadsheet/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/SpreadsheetAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->spreadsheet_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/spreadsheet/0'); + } + + include_once __DIR__ . '/../../view_models/Spreadsheet_admin_edit_view_model.php'; + $this->form_validation = $this->spreadsheet_model->set_form_validation( + $this->form_validation, $this->spreadsheet_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Spreadsheet_admin_edit_view_model($this->spreadsheet_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Spreadsheet'); + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/SpreadsheetEdit', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->spreadsheet_model->edit([ + 'name' => $name, + 'status' => $status, + + ], $id); + + if ($result) + { + $this->success('Spreadsheet updated.'); + + return $this->redirect('/admin/spreadsheet/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/SpreadsheetEdit', $this->_data); + } + + public function bulk_delete() + { + + $bulk_items = $this->input->post('bulk_items'); + foreach ($bulk_items as $key => $id) { + $this->spreadsheet_model->real_delete($id); + } + echo 'success'; + exit(); + } + /** + * Function to return spreadsheet data only + */ + public function spreadsheet_data($id) + { + $model = $this->spreadsheet_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/spreadsheet/0'); + } + + include_once __DIR__ . '/../../view_models/Spreadsheet_admin_edit_view_model.php'; + $this->form_validation = $this->spreadsheet_model->set_form_validation( + $this->form_validation, $this->spreadsheet_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Spreadsheet_admin_edit_view_model($this->spreadsheet_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Spreadsheet'); + + return $this->render('Admin/Spreadsheet_view_only', $this->_data); + + + } + + /** + * function to update the sheet + */ + + public function update_sheet($id) + { + $model = $this->spreadsheet_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + echo json_encode(['error'=> 'error']); + exit(); + } + $data = file_get_contents("php://input",TRUE); + if($data) + { + $result = $this->spreadsheet_model->edit([ + 'value' => $data, + + ], $id); + + if ($result) + { + $this->success('Spreadsheet Updated Successfully.'); + echo json_encode(['success'=> 'updated']); + exit(); + } + + + } + $this->error('Error'); + echo json_encode(['error'=> 'error']); + exit(); + } + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_suggestion_controller.php b/application/controllers/Admin/Admin_suggestion_controller.php new file mode 100755 index 0000000..c9ee1b1 --- /dev/null +++ b/application/controllers/Admin/Admin_suggestion_controller.php @@ -0,0 +1,156 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Suggestion_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Suggestion_admin_list_paginate_view_model( + $this->suggestion_model, + $this->pagination, + '/admin/suggestion/0'); + $this->_data['view_model']->set_heading('Suggestion'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL); + $this->_data['view_model']->set_email(($this->input->get('email', TRUE) != NULL) ? $this->input->get('email', TRUE) : NULL); + $this->_data['view_model']->set_suggestion_type(($this->input->get('suggestion_type', TRUE) != NULL) ? $this->input->get('suggestion_type', TRUE) : NULL); + $this->_data['view_model']->set_additional_notes(($this->input->get('additional_notes', TRUE) != NULL) ? $this->input->get('additional_notes', TRUE) : NULL); + $this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'name' => $this->_data['view_model']->get_name(), + 'email' => $this->_data['view_model']->get_email(), + 'suggestion_type' => $this->_data['view_model']->get_suggestion_type(), + 'additional_notes' => $this->_data['view_model']->get_additional_notes(), + 'created_at' => $this->_data['view_model']->get_created_at(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->suggestion_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/suggestion/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->suggestion_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Suggestion', $this->_data); + } + + + + + + public function view($id) + { + $model = $this->suggestion_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/suggestion/0'); + } + + + include_once __DIR__ . '/../../view_models/Suggestion_admin_view_view_model.php'; + $this->_data['view_model'] = new Suggestion_admin_view_view_model($this->suggestion_model); + $this->_data['view_model']->set_heading('Suggestion'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/SuggestionView', $this->_data); + } + + public function delete($id) + { + $model = $this->suggestion_model->get($id); + + if (!$model) + { + // $this->error('Error'); + // return redirect('/admin/suggestion/0'); + } + + $result = $this->suggestion_model->real_delete($id); + + if ($result) + { + + return $this->redirect('/admin/suggestion/0', 'refresh'); + } + + $this->error('Error'); + return redirect('/admin/suggestion/0'); + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_tax_controller.php b/application/controllers/Admin/Admin_tax_controller.php new file mode 100755 index 0000000..80d1dc2 --- /dev/null +++ b/application/controllers/Admin/Admin_tax_controller.php @@ -0,0 +1,234 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Tax_admin_list_paginate_view_model.php'; + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + $session = $this->get_session(); + $where = []; + $this->_data['view_model'] = new Tax_admin_list_paginate_view_model( + $this->tax_model, + $this->pagination, + '/admin/tax/0'); + $this->_data['view_model']->set_heading('Tax'); + $this->_data['view_model']->set_total_rows($this->tax_model->count($where)); + + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/tax/0'); + $this->_data['view_model']->set_list($this->tax_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Tax', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Tax_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->tax_model->set_form_validation( + $this->form_validation, $this->tax_model->get_all_validation_rule()); + $this->_data['view_model'] = new Tax_admin_add_view_model($this->tax_model); + $this->_data['view_model']->set_heading('Tax'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/TaxAdd', $this->_data); + } + + $tax = $this->input->post('tax', TRUE); + + $result = $this->tax_model->create([ + 'tax' => $tax, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/tax/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/TaxAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->tax_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/tax/0'); + } + + include_once __DIR__ . '/../../view_models/Tax_admin_edit_view_model.php'; + $this->form_validation = $this->tax_model->set_form_validation( + $this->form_validation, $this->tax_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Tax_admin_edit_view_model($this->tax_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Tax'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/TaxEdit', $this->_data); + } + + $tax = $this->input->post('tax', TRUE); + + $result = $this->tax_model->edit([ + 'tax' => $tax, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/tax/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/TaxEdit', $this->_data); + } + + public function view($id) + { + $model = $this->tax_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/tax/0'); + } + + + include_once __DIR__ . '/../../view_models/Tax_admin_view_view_model.php'; + $this->_data['view_model'] = new Tax_admin_view_view_model($this->tax_model); + $this->_data['view_model']->set_heading('Tax'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/TaxView', $this->_data); + } + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->tax_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->tax_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_test_image_controller.php b/application/controllers/Admin/Admin_test_image_controller.php new file mode 100755 index 0000000..17b090d --- /dev/null +++ b/application/controllers/Admin/Admin_test_image_controller.php @@ -0,0 +1,219 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Test_image_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Test_image_admin_list_paginate_view_model( + $this->test_image_model, + $this->pagination, + '/admin/test_image/0'); + $this->_data['view_model']->set_heading('Test image'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'created_at' => $this->_data['view_model']->get_created_at(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->test_image_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/test_image/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->test_image_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Test_image', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Test_image_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->test_image_model->set_form_validation( + $this->form_validation, $this->test_image_model->get_all_validation_rule()); + $this->_data['view_model'] = new Test_image_admin_add_view_model($this->test_image_model); + $this->_data['view_model']->set_heading('Test image'); + + $this->load->model('image_model'); + $gallery_images = $this->image_model->get_all(); + foreach ($gallery_images as $key => $image) { + if($image->type == 4){ + $image->show_url = base_url().$image->url; + }else + { + $image->show_url = $image->url; + }$image->type = $this->image_model->type_mapping()[$image->type]; + } + $this->_data['gallery_images'] = $gallery_images; + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Test_imageAdd', $this->_data); + } + + $image = $this->input->post('image', TRUE); + $image_id = $this->input->post('image_id', TRUE); + + $result = $this->test_image_model->create([ + 'image' => $image, + 'image_id' => $image_id, + + ]); + + if ($result) + { + $this->success('image added.'); + + return $this->redirect('/admin/test_image/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Test_imageAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->test_image_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/test_image/0'); + } + + include_once __DIR__ . '/../../view_models/Test_image_admin_edit_view_model.php'; + $this->form_validation = $this->test_image_model->set_form_validation( + $this->form_validation, $this->test_image_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Test_image_admin_edit_view_model($this->test_image_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Test image'); + + $this->load->model('image_model'); + $gallery_images = $this->image_model->get_all(); + foreach ($gallery_images as $key => $image) { + if($image->type == 4){ + $image->show_url = base_url().$image->url; + }else + { + $image->show_url = $image->url; + }$image->type = $this->image_model->type_mapping()[$image->type]; + } + $this->_data['gallery_images'] = $gallery_images; + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/Test_imageEdit', $this->_data); + } + + $image = $this->input->post('image', TRUE); + $image_id = $this->input->post('image_id', TRUE); + + $result = $this->test_image_model->edit([ + 'image' => $image, + 'image_id' => $image_id, + + ], $id); + + if ($result) + { + $this->success('image updated.'); + + return $this->redirect('/admin/test_image/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/Test_imageEdit', $this->_data); + } + + + + + + public function bulk_delete() + { + + $bulk_items = $this->input->post('bulk_items'); + foreach ($bulk_items as $key => $id) { + $this->test_image_model->real_delete($id); + } + echo 'success'; + exit(); + } + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_textbook_controller.php b/application/controllers/Admin/Admin_textbook_controller.php new file mode 100755 index 0000000..13fdbea --- /dev/null +++ b/application/controllers/Admin/Admin_textbook_controller.php @@ -0,0 +1,238 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Textbook_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Textbook_admin_list_paginate_view_model( + $this->textbook_model, + $this->pagination, + '/admin/textbook/0'); + $this->_data['view_model']->set_heading('Textbook'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_name(($this->input->get('name', TRUE) != NULL) ? $this->input->get('name', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'name' => $this->_data['view_model']->get_name(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->textbook_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/textbook/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->textbook_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Textbook', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Textbook_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->textbook_model->set_form_validation( + $this->form_validation, $this->textbook_model->get_all_validation_rule()); + $this->_data['view_model'] = new Textbook_admin_add_view_model($this->textbook_model); + $this->_data['view_model']->set_heading('Textbook'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/TextbookAdd', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $isbn = $this->input->post('isbn', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->textbook_model->create([ + 'name' => $name, + 'isbn' => $isbn, + 'status' => $status, + + ]); + + if ($result) + { + $this->success('Textbook added.'); + + return $this->redirect('/admin/textbook/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/TextbookAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->textbook_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/textbook/0'); + } + + include_once __DIR__ . '/../../view_models/Textbook_admin_edit_view_model.php'; + $this->form_validation = $this->textbook_model->set_form_validation( + $this->form_validation, $this->textbook_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Textbook_admin_edit_view_model($this->textbook_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Textbook'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/TextbookEdit', $this->_data); + } + + $name = $this->input->post('name', TRUE); + $isbn = $this->input->post('isbn', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->textbook_model->edit([ + 'name' => $name, + 'isbn' => $isbn, + 'status' => $status, + + ], $id); + + if ($result) + { + $this->success('Textbook updated.'); + + return $this->redirect('/admin/textbook/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/TextbookEdit', $this->_data); + } + + + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->textbook_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->textbook_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_ticket_controller.php b/application/controllers/Admin/Admin_ticket_controller.php new file mode 100755 index 0000000..8eaff2e --- /dev/null +++ b/application/controllers/Admin/Admin_ticket_controller.php @@ -0,0 +1,128 @@ +load->model('user_model'); + + + } + + + + public function index($page) + { + $this->load->library('pagination'); + include_once __DIR__ . '/../../view_models/Ticket_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Ticket_admin_list_paginate_view_model( + $this->ticket_model, + $this->pagination, + '/admin/ticket/0'); + $this->_data['view_model']->set_heading('Ticket'); + $this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL); + $this->_data['view_model']->set_message(($this->input->get('message', TRUE) != NULL) ? $this->input->get('message', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'order_id' => $this->_data['view_model']->get_order_id(), + 'message' => $this->_data['view_model']->get_message(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->ticket_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/ticket/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->ticket_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + $user_id_array = $this->user_model->get_all(); + if($user_id_array){ + $user_id_array = array_column($user_id_array,'first_name','id'); + } + // print_r($user_id_array);exit; + if($this->_data['view_model']->get_list() ){ + + foreach ( $this->_data['view_model']->get_list() as $key => &$value) { + $value->user_id = $user_id_array[$value->user_id] ?? ''; + } + } + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Ticket', $this->_data); + } + + public function resolve($id){ + $this->ticket_model->update('ticket',['status'=>1],['id'=>$id]); + + $this->success('Resolved successfully'); + return redirect('admin/ticket/0','refresh'); + } + + + + + + + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_transaction_controller.php b/application/controllers/Admin/Admin_transaction_controller.php new file mode 100755 index 0000000..9891d1e --- /dev/null +++ b/application/controllers/Admin/Admin_transaction_controller.php @@ -0,0 +1,309 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Transaction_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Transaction_admin_list_paginate_view_model( + $this->transaction_model, + $this->pagination, + '/admin/transaction/0'); + $this->_data['view_model']->set_heading('Transaction'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_payment_method(($this->input->get('payment_method', TRUE) != NULL) ? $this->input->get('payment_method', TRUE) : NULL); + $this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL); + $this->_data['view_model']->set_transaction_date(($this->input->get('transaction_date', TRUE) != NULL) ? $this->input->get('transaction_date', TRUE) : NULL); + $this->_data['view_model']->set_transaction_time(($this->input->get('transaction_time', TRUE) != NULL) ? $this->input->get('transaction_time', TRUE) : NULL); + $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL); + $this->_data['view_model']->set_tax(($this->input->get('tax', TRUE) != NULL) ? $this->input->get('tax', TRUE) : NULL); + $this->_data['view_model']->set_discount(($this->input->get('discount', TRUE) != NULL) ? $this->input->get('discount', TRUE) : NULL); + $this->_data['view_model']->set_subtotal(($this->input->get('subtotal', TRUE) != NULL) ? $this->input->get('subtotal', TRUE) : NULL); + $this->_data['view_model']->set_total(($this->input->get('total', TRUE) != NULL) ? $this->input->get('total', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'payment_method' => $this->_data['view_model']->get_payment_method(), + 'order_id' => $this->_data['view_model']->get_order_id(), + 'transaction_date' => $this->_data['view_model']->get_transaction_date(), + 'transaction_time' => $this->_data['view_model']->get_transaction_time(), + 'user_id' => $this->_data['view_model']->get_user_id(), + 'tax' => $this->_data['view_model']->get_tax(), + 'discount' => $this->_data['view_model']->get_discount(), + 'subtotal' => $this->_data['view_model']->get_subtotal(), + 'total' => $this->_data['view_model']->get_total(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->transaction_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/transaction/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->transaction_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/Transaction', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Transaction_admin_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->transaction_model->set_form_validation( + $this->form_validation, $this->transaction_model->get_all_validation_rule()); + $this->_data['view_model'] = new Transaction_admin_add_view_model($this->transaction_model); + $this->_data['view_model']->set_heading('Transaction'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/TransactionAdd', $this->_data); + } + + $payment_method = $this->input->post('payment_method', TRUE); + $order_id = $this->input->post('order_id', TRUE); + $transaction_date = $this->input->post('transaction_date', TRUE); + $transaction_time = $this->input->post('transaction_time', TRUE); + $user_id = $this->input->post('user_id', TRUE); + $tax = $this->input->post('tax', TRUE); + $discount = $this->input->post('discount', TRUE); + $subtotal = $this->input->post('subtotal', TRUE); + $total = $this->input->post('total', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->transaction_model->create([ + 'payment_method' => $payment_method, + 'order_id' => $order_id, + 'transaction_date' => $transaction_date, + 'transaction_time' => $transaction_time, + 'user_id' => $user_id, + 'tax' => $tax, + 'discount' => $discount, + 'subtotal' => $subtotal, + 'total' => $total, + 'status' => $status, + + ]); + + if ($result) + { + + + return $this->redirect('/admin/transaction/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/TransactionAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->transaction_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/admin/transaction/0'); + } + + include_once __DIR__ . '/../../view_models/Transaction_admin_edit_view_model.php'; + $this->form_validation = $this->transaction_model->set_form_validation( + $this->form_validation, $this->transaction_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Transaction_admin_edit_view_model($this->transaction_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Transaction'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Admin/TransactionEdit', $this->_data); + } + + $payment_method = $this->input->post('payment_method', TRUE); + $order_id = $this->input->post('order_id', TRUE); + $transaction_date = $this->input->post('transaction_date', TRUE); + $transaction_time = $this->input->post('transaction_time', TRUE); + $user_id = $this->input->post('user_id', TRUE); + $tax = $this->input->post('tax', TRUE); + $discount = $this->input->post('discount', TRUE); + $subtotal = $this->input->post('subtotal', TRUE); + $total = $this->input->post('total', TRUE); + $status = $this->input->post('status', TRUE); + + $result = $this->transaction_model->edit([ + 'payment_method' => $payment_method, + 'order_id' => $order_id, + 'transaction_date' => $transaction_date, + 'transaction_time' => $transaction_time, + 'user_id' => $user_id, + 'tax' => $tax, + 'discount' => $discount, + 'subtotal' => $subtotal, + 'total' => $total, + 'status' => $status, + + ], $id); + + if ($result) + { + + + return $this->redirect('/admin/transaction/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Admin/TransactionEdit', $this->_data); + } + + public function view($id) + { + $model = $this->transaction_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/admin/transaction/0'); + } + + + include_once __DIR__ . '/../../view_models/Transaction_admin_view_view_model.php'; + $this->_data['view_model'] = new Transaction_admin_view_view_model($this->transaction_model); + $this->_data['view_model']->set_heading('Transaction'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Admin/TransactionView', $this->_data); + } + + public function delete() + { + $id = $this->input->post('id', TRUE); + + if (!empty($id)) + { + $model = $this->transaction_model->get($id); + + if (!$model) + { + $output['error'] = TRUE; + $output['status'] = 404; + $output['msg'] = 'Error! Data not found.'; + echo json_encode($output); + exit(); + } + else + { + $result = $this->transaction_model->real_delete($id); + + if ($result) + { + $output['success'] = TRUE; + $output['status'] = 200; + $output['msg'] = 'Deleted successfully.'; + echo json_encode($output); + exit(); + } + else + { + $output['error'] = TRUE; + $output['status'] = 500; + $output['msg'] = 'Error! Please try again later.'; + echo json_encode($output); + exit(); + } + } + } + else + { + $output['error'] = TRUE; + $output['status'] = 0; + $output['msg'] = 'Error! ID not found.'; + echo json_encode($output); + exit(); + } + } + + public function bulk_delete() + { + + $bulk_items = $this->input->post('bulk_items'); + foreach ($bulk_items as $key => $id) { + $this->transaction_model->real_delete($id); + } + echo 'success'; + exit(); + } + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Admin_user_card_controller.php b/application/controllers/Admin/Admin_user_card_controller.php new file mode 100755 index 0000000..2e990fc --- /dev/null +++ b/application/controllers/Admin/Admin_user_card_controller.php @@ -0,0 +1,110 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/User_card_admin_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new User_card_admin_list_paginate_view_model( + $this->user_card_model, + $this->pagination, + '/admin/user_card/0'); + $this->_data['view_model']->set_heading('User Card'); + $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL); + $this->_data['view_model']->set_last4(($this->input->get('last4', TRUE) != NULL) ? $this->input->get('last4', TRUE) : NULL); + $this->_data['view_model']->set_is_default(($this->input->get('is_default', TRUE) != NULL) ? $this->input->get('is_default', TRUE) : NULL); + + $where = [ + 'user_id' => $this->_data['view_model']->get_user_id(), + 'last4' => $this->_data['view_model']->get_last4(), + 'is_default' => $this->_data['view_model']->get_is_default(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->user_card_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/admin/user_card/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->user_card_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Admin/User_card', $this->_data); + } + + + + + + + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Admin/Marketing_controller.php b/application/controllers/Admin/Marketing_controller.php new file mode 100755 index 0000000..d6ca3da --- /dev/null +++ b/application/controllers/Admin/Marketing_controller.php @@ -0,0 +1,264 @@ + '', + 'success' => '' + ]; + + public function __construct() + { + parent::__construct(); + $this->load->database(); + $this->load->model('marketing_model'); + + } + + /** + * Debug Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dl($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER :
' . print_r($data, TRUE) . '
'); + } + } + + /** + * Debug json Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dj($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER : ' . json_encode($data)); + } + } + + public function get_session() + { + if (!$this->_test_mode) + { + return $_SESSION; + } + + $session = $this->config->item('session_test'); + + if (!$session) + { + $session = []; + } + + return $session; + } + + public function set_session($field, $value) + { + if (!$this->_test_mode) + { + $_SESSION[$field] = $value; + } + else + { + $session = $this->config->item('session_test'); + if (!$session) + { + $session = []; + } + $session[$field] = $value; + $this->config->set_item('session_test', $session); + } + } + + public function destroy_session() + { + if (!$this->_test_mode) + { + unset($_SESSION); + } + else + { + $this->config->set_item('session_test', []); + } + } + + public function get_setting() + { + return $this->_setting; + } + + /** + * Function to generate a slug + */ + public function generate_marketing_slug($str) + { + + $delimiter = '-'; + $slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter)); + $full_path = base_url() . 'a/'; + + $row = $this->marketing_model->get_by_field('slug', $full_path . $slug); + + if (empty($row)) + { + $output['slug'] = $slug; + echo json_encode($output); + exit; + } + else + { + $i = 1; + $check_me_again = TRUE; + while ($check_me_again) + { + $slug = $slug . '-' . $i; + $row = $this->marketing_model->get_by_field('slug', $full_path . $slug); + + if (empty($row)) + { + $check_me_again = FALSE; + } + $i++; + } + + $output['slug'] = $slug; + echo json_encode($output); + exit; + } + } + + /** + * Function to return the generated page + */ + public function generate_custom_marketing_page($slug) + { + $slug_url = base_url() . 'a/'; + $slug = $slug_url.$slug; + $marketing_data = $this->marketing_model->get_by_field('slug',$slug); + $this->_data['header'] = ''; + $this->_data['footer'] = ''; + $this->_data['content_template'] = ''; + $this->_data['content'] = ''; + $this->_data['success'] = ''; + $this->_data['error'] = ''; + $this->_data['layout_clean_mode'] = TRUE; + $this->_data['reuse_query_string'] = TRUE; + $this->_data['base_url'] = base_url(); + $this->_data['total_rows'] = 25; + $this->_data['per_page'] = 25; + $this->_data['num_links'] = ''; + $this->_data['full_tag_open'] = ''; + $this->_data['attributes'] = ['class' => 'page-link']; + $this->_data['first_link'] = FALSE ; + $this->_data['last_link'] = FALSE; + $this->_data['first_tag_open'] = '
  • '; + $this->_data['first_tag_close'] = '
  • '; + $this->_data['prev_link'] = '«'; + $this->_data['setting'] = $this->get_setting(); + $this->_data['list'] = []; + + if($marketing_data) + { + if($marketing_data->header_template_path != '') + { + $this->_data['header'] = $marketing_data->header_template_path ? $marketing_data->header_template_path : ''; + } + + if($marketing_data->footer_template_path != '') + { + $this->_data['footer'] = $marketing_data->footer_template_path ? $marketing_data->footer_template_path : ''; + } + + $this->_data['content'] = $marketing_data->content ? $marketing_data->content : ''; + $this->_data['content_template'] = $marketing_data->content_template_path ? $marketing_data->content_template_path : ''; + + if($marketing_data->status == 0) + { + if ($marketing_data->password_protect == '') + { + return $this->generate_marketing_template($this->_data); + } + else + { + $valid_passwords = [ + 'guest' => $marketing_data->password_protect + ]; + $valid_users = array_keys($valid_passwords); + + $user = $_SERVER['PHP_AUTH_USER']; + $pass = $_SERVER['PHP_AUTH_PW']; + + $validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]); + + if (!$validated) + { + header('WWW-Authenticate: Basic realm="My Realm"'); + header('HTTP/1.0 401 Unauthorized'); + die ('Not authorized'); + } + + return $this->generate_marketing_template($this->_data); + + } + } + else + { + $this->output->set_status_header('404'); + $data['heading'] = '404 Page Not Found'; + $data['message'] = 'The page you requested was not found'; + $this->load->view('errors/html/error_404',$data); + exit(); + } + + } + $this->output->set_status_header('404'); + $data['heading'] = '404 Page Not Found'; + $data['message'] = 'The page you requested was not found'; + $this->load->view('errors/html/error_404', $data); + exit(); + } + + /** + * Function to generate marketing template + */ + + public function generate_marketing_template($marketing_data) + { + if($marketing_data['header'] != '') + { + $this->load->view($marketing_data['header'], $marketing_data); + } + + if($marketing_data['content_template'] == '') + { + echo $marketing_data['content_template']; + } + else + { + $this->load->view('Guest/Template_page', $marketing_data); + } + + if($marketing_data['footer'] != '') + { + $this->load->view($marketing_data['footer'], $marketing_data); + } + } +} \ No newline at end of file diff --git a/application/controllers/Admin/Stripe_webhooks_api_controller.php b/application/controllers/Admin/Stripe_webhooks_api_controller.php new file mode 100755 index 0000000..021d7c5 --- /dev/null +++ b/application/controllers/Admin/Stripe_webhooks_api_controller.php @@ -0,0 +1,580 @@ + ($this->config->item('stripe_api_version') ?? ''), + 'stripe_publish_key' => ($this->config->item('stripe_publish_key') ?? ''), + 'stripe_secret_key' => ($this->config->item('stripe_secret_key') ?? '') + ]; + $this->load->library('payment_service', $stripe_config); + $this->load->database(); + } + + /** + * handle stripe events + * @see https://stripe.com/docs/api/events/types + */ + public function index() + { + $payload = @file_get_contents('php://input'); + $event = null; + + try + { + $event = $this->payment_service->get_stripe_event($payload); + } + catch (Exception $e) + { + http_response_code(400); + exit(); + } + + $args = $event->data->object; + + switch ($event->type) + { + case 'payment_intent.succeeded': + // $this->handle_payment_intent_succeeded($args); + break; + + case 'payment_method.attached': + // $this->handle_payment_method($args); + break; + + case 'invoice.created': + // $this->handle_invoice_created($args); + break; + + case 'invoice.finalized': + // $this->handle_invoice_finalized($args); + break; + + case 'invoice.payment_failed': + // $this->handle_invoice_payment_failed($args); + break; + + case 'invoice.payment_succeeded': + // $this->handle_invoice_payment_succeeded($args); + break; + + case 'invoice.upcoming': + // $this->handle_invoice_upcoming($args); + break; + + case 'charge.dispute.created': + $this->handle_dispute_created($args); + error_log(print_r($args), true); + break; + + case 'charge.dispute.funds_reinstated': + $this->handle_dispute_funds_reinstated($args); + break; + + case 'charge.dispute.funds_withdrawn': + $this->handle_dispute_funds_withdrawn($args); + break; + + case 'charge.dispute.updated': + $this->handle_dispute_updated($args); + error_log(print_r($args, true)); + break; + + case 'charge.succeeded': + error_log(print_r($args, true)); + // $this->handle_charge_succeeded($args); + break; + + case 'charge.refunded': + $this->handle_charge_refunded($args); + break; + + case 'charge.refund.updated': + $this->handle_refund_updated($args); + break; + + case 'checkout.session.completed': + // $this->handle_checkout_session_completed($args); + break; + + case 'customer.source.expiring': + http_response_code(200); + break; + + case 'customer.subscription.updated': + http_response_code(200); + break; + + case 'customer.subscription.deleted': + // $this->handle_subscription_deleted($args); + break; + + case 'subscription_schedule.aborted': + // $this->handle_subscription_schedule_aborted($args); + break; + + case 'subscription_schedule.canceled': + // $this->handle_subscription_schedule_canceled($args); + break; + + case 'subscription_schedule.completed': + // $this->handle_subscription_schedule_completed($args); + break; + + case 'subscription_schedule.expiring': + // $this->handle_subscription_schedule_expiring($args); + break; + + default: + http_response_code(200); + exit(); + } + } + + /** + * Dispute: + * https://stripe.com/docs/api/disputes/object + */ + public function handle_dispute_created($args) + { + $this->load->model('dispute_model'); + $this->load->model('order_model'); + $this->load->model('order_notes_model'); + + if (isset($args['id'])) + { + // get order_id and user_id + $order_data = $this->order_model->get_by_field('stripe_charge_id', $args['charge']); + + // if (!empty($order_data)) + // { + $payload = [ + 'order_id' => $order_data->id ?? 0, + 'user_id' => $order_data->user_id ?? 0, + 'amount' => $args['amount'] ?? "", + 'reason' => $args['reason'] ?? "", + 'explanation' => $args['explanation'] ?? "", + 'stripe_charge_id' => $args['charge'] ?? "", + 'stripe_dispute_id' => $args['id'] ?? "", + 'status' => $args['status'] ?? "" + ]; + + $result = $this->dispute_model->create($payload); + + if ($result) + { + $order_notes_payload = [ + 'order_id' => $order_data->id ?? 0, + 'description' => 'Dispute created.' + ]; + + $this->order_notes_model->create($order_notes_payload); + + echo json_encode(["success" => true, "message" => "dispute created succeeded captured"]); + http_response_code(200); + exit(); + } + else + { + echo json_encode(["success" => false, "message" => "dispute created failed"]); + http_response_code(400); + exit(); + } + } + // else + // { + // echo json_encode(["success" => false, "message" => "order data not found"]); + // http_response_code(400); + // exit(); + // } + // } + echo json_encode(["success" => false, "message" => "invalid dispute received"]); + http_response_code(400); + exit(); + } + + /** + * Occurs when funds are reinstated to your account after a dispute is closed. + * This includes partially refunded payments. + */ + public function handle_dispute_funds_reinstated($args) + { + $this->load->model('dispute_model'); + $this->load->model('order_model'); + $this->load->model('order_notes_model'); + + if (isset($args['id'])) + { + // get order_id and user_id + $order_data = $this->order_model->get_by_field('stripe_charge_id', $args['charge']); + + if (!empty($order_data)) + { + $dispute_data = $this->dispute_model->get_by_field('stripe_dispute_id', $args['id']); + + $payload = [ + 'amount' => $args['amount'] ?? "", + 'reason' => $args['reason'] ?? "", + 'explanation' => $args['explanation'] ?? "", + 'status' => $args['status'] + ]; + + $result = $this->dispute_model->edit($payload, $dispute_data->id); + + if ($result) + { + $order_notes_payload = [ + 'order_id' => $order_data->id, + 'description' => 'Dispute reinstated. Partial dispute. Amount ' . $args['amount'] / 100 + ]; + + $this->order_notes_model->create($order_notes_payload); + + if (!empty($order_data)) + { + $order_payload = ['status' => 6]; + $this->order_model->edit($order_payload, $order_data->id); + } + + echo json_encode(["success" => true, "message" => "dispute reinstate succeeded"]); + http_response_code(200); + exit(); + } + else + { + echo json_encode(["success" => false, "message" => "dispute reinstate failed"]); + http_response_code(400); + exit(); + } + } + else + { + echo json_encode(["success" => false, "message" => "order data not found"]); + http_response_code(400); + exit(); + } + } + echo json_encode(["success" => false, "message" => "invalid dispute received"]); + http_response_code(400); + exit(); + } + + /** + * Occurs when funds are removed from your account due to a dispute. + */ + public function handle_dispute_funds_withdrawn($args) + { + $this->load->model('dispute_model'); + $this->load->model('order_model'); + $this->load->model('order_notes_model'); + + if (isset($args['id'])) + { + // get order_id and user_id + $order_data = $this->order_model->get_by_field('stripe_charge_id', $args['charge']); + + if (!empty($order_data)) + { + $dispute_data = $this->dispute_model->get_by_field('stripe_dispute_id', $args['id']); + + $payload = [ + 'amount' => $args['amount'] ?? "", + 'reason' => $args['reason'] ?? "", + 'explanation' => $args['explanation'] ?? "", + 'status' => $args['status'] + ]; + + $result = $this->dispute_model->edit($payload, $dispute_data->id); + + if ($result) + { + $order_notes_payload = [ + 'order_id' => $order_data->id, + 'description' => 'Dispute funds_withdrawn' + ]; + + $this->order_notes_model->create($order_notes_payload); + + if (!empty($order_data)) + { + $order_payload = ['status' => 6]; + $this->order_model->edit($order_payload, $order_data->id); + } + + echo json_encode(["success" => true, "message" => "dispute funds_withdrawn succeeded"]); + http_response_code(200); + exit(); + } + else + { + echo json_encode(["success" => false, "message" => "dispute funds_withdrawn failed"]); + http_response_code(400); + exit(); + } + } + else + { + echo json_encode(["success" => false, "message" => "order data not found"]); + http_response_code(400); + exit(); + } + } + echo json_encode(["success" => false, "message" => "invalid dispute received"]); + http_response_code(400); + exit(); + } + + /** + * Occurs when the dispute is updated (usually with evidence). + */ + public function handle_dispute_updated($args) + { + $this->load->model('dispute_model'); + $this->load->model('order_model'); + $this->load->model('order_notes_model'); + + if (isset($args['id'])) + { + // get order_id and user_id + $order_data = $this->order_model->get_by_field('stripe_charge_id', $args['charge']); + + if (!empty($order_data)) + { + $dispute_data = $this->dispute_model->get_by_field('stripe_dispute_id', $args['id']); + + $payload = [ + 'amount' => $args['amount'] ?? "", + 'reason' => $args['reason'] ?? "", + 'explanation' => $args['explanation'] ?? "", + 'status' => $args['status'] + ]; + + $result = $this->dispute_model->edit($payload, $dispute_data->id); + + if ($result) + { + $order_notes_payload = [ + 'order_id' => $order_data->id, + 'description' => 'Dispute dispute updated. Evidence: ' . $args['evidence'] ?? "" + ]; + + $this->order_notes_model->create($order_notes_payload); + + echo json_encode(["success" => true, "message" => "dispute update succeeded"]); + http_response_code(200); + exit(); + } + else + { + echo json_encode(["success" => false, "message" => "dispute update failed"]); + http_response_code(400); + exit(); + } + } + else + { + echo json_encode(["success" => false, "message" => "order data not found"]); + http_response_code(400); + exit(); + } + } + echo json_encode(["success" => false, "message" => "invalid dispute received"]); + http_response_code(400); + exit(); + } + + /** + * Refund: + * + */ + public function handle_charge_refunded($args) + { + $this->load->model('order_model'); + $this->load->model('order_notes_model'); + $this->load->model('refund_model'); + + if (isset($args['id'])) + { + // get order_id and user_id + $order_data = $this->order_model->get_by_field('stripe_charge_id', $args['id']); + + $refund_params = [ + 'order_id' => $order_data->id ?? 0, + 'user_id' => $order_data->user_id ?? 0, + 'amount' => $args['amount_refunded'] ?? 0, + 'reason' => $args['refunds']['data'][0]['reason'] ?? "null", + 'explanation' => $args['refunds']['data'][0]['explanation'] ?? "", + 'stripe_charge_id' => $args['id'], + 'stripe_invoice_id' => $args['invoice'] ?? "", + 'receipt_url' => $args['receipt_url'] ?? "", + 'status' => $args['refunds']['data'][0]['status'] ?? "" + ]; + + $result = $this->refund_model->create($refund_params); + + if ($result) + { + $order_notes_payload = [ + 'order_id' => $order_data->id ?? 0, + 'description' => 'Refund completed.' + ]; + + $this->order_notes_model->create($order_notes_payload); + + if (!empty($order_data)) + { + $order_payload = ['status' => 5]; + $this->order_model->edit($order_payload, $order_data->id); + } + + echo json_encode(["success" => true, "message" => "refund captured"]); + http_response_code(200); + exit(); + } + else + { + echo json_encode(["success" => true, "message" => "charge refund add failed on db"]); + http_response_code(400); + exit(); + } + + } + echo json_encode(["success" => true, "message" => "charge refunded captured"]); + http_response_code(400); + exit(); + } + + public function handle_refund_updated($args) + { + $this->load->model('order_model'); + $this->load->model('order_notes_model'); + $this->load->model('refund_model'); + + if (isset($args['id'])) + { + // get order_id and user_id + $order_data = $this->order_model->get_by_field('stripe_charge_id', $args['id']); + $refund_data = $this->order_model->get_by_field('stripe_charge_id', $args['id']); + + if ($refund_data) + { + $refund_params = [ + 'amount' => $args['amount_refunded'] ?? 0, + 'reason' => $args['refunds']['data'][0]['reason'] ?? "null", + 'explanation' => $args['refunds']['data'][0]['explanation'] ?? "", + 'stripe_charge_id' => $args['id'], + 'stripe_invoice_id' => $args['invoice'] ?? "", + 'receipt_url' => $args['receipt_url'] ?? "", + 'status' => $args['refunds']['data'][0]['status'] ?? "" + ]; + + $result = $this->refund_model->edit($refund_params, $refund_data->id); + + if ($result) + { + $order_notes_payload = [ + 'order_id' => $order_data->id ?? 0, + 'description' => 'Refund updated.' + ]; + + $this->order_notes_model->create($order_notes_payload); + + if (!empty($order_data)) + { + $order_payload = ['status' => 5]; + $this->order_model->edit($order_payload, $order_data->id); + } + + echo json_encode(["success" => true, "message" => "refund updated"]); + http_response_code(200); + exit(); + } + else + { + echo json_encode(["success" => false, "message" => "refund update failed"]); + http_response_code(400); + exit(); + } + } + else + { + echo json_encode(["success" => false, "message" => "refund update failed. data not found on db."]); + http_response_code(400); + exit(); + } + } + echo json_encode(["success" => false, "message" => "refund update capture failed"]); + http_response_code(400); + exit(); + } + + /** + * handle stripe ach events + * @see https://stripe.com/docs/api/events/types + */ + public function stripe_events() + { + $endpoint_secret = $this->config->item('stripe_endpoint_secret'); + + $stripe_secret_key = $this->config->item('stripe_secret_key'); + Stripe::setApiKey($stripe_secret_key); + + $payload = @file_get_contents('php://input'); + $sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE']; + $event = null; + + try { + $event = Webhook::constructEvent( + $payload, $sig_header, $endpoint_secret + ); + } + catch (\UnexpectedValueException $e) + { + // Invalid payload + http_response_code(400); + exit(); + } + catch (\Stripe\Exception\SignatureVerificationException $e) + { + // Invalid signature + http_response_code(400); + exit(); + } + + // Handle the event + switch ($event->type) + { + case 'invoice.paid': + $payment_intent = $event->data->object; + // write your stripe webhook code here + // contains a StripePaymentIntent + // $this->handle_invoice_paid_method($payment_intent); + break; + default: + echo 'Received unknown event type ' . $event->type; + } + + http_response_code(200); + } + +} diff --git a/application/controllers/Cli/Backup_code_cronjob_controller.php b/application/controllers/Cli/Backup_code_cronjob_controller.php new file mode 100755 index 0000000..71aac46 --- /dev/null +++ b/application/controllers/Cli/Backup_code_cronjob_controller.php @@ -0,0 +1,33 @@ +project_backup($date); + // $this->send_backup($date); + } + + private function project_backup($date) + { + $this->load->library('zip'); + $this->zip->read_dir(FCPATH, FALSE); + $this->zip->archive("project_backup_{$date}.zip"); + } +} \ No newline at end of file diff --git a/application/controllers/Cli/Backup_db_cronjob_controller.php b/application/controllers/Cli/Backup_db_cronjob_controller.php new file mode 100755 index 0000000..44f7c8c --- /dev/null +++ b/application/controllers/Cli/Backup_db_cronjob_controller.php @@ -0,0 +1,34 @@ +database_backup($date); + // $this->send_backup($date); + } + + private function database_backup($date) + { + $this->load->helper('file'); + $this->load->dbutil(); + @$backup = $this->dbutil->backup(); + write_file("database_backup_{$date}.zip", $backup); + } +} \ No newline at end of file diff --git a/application/controllers/Cli/Cronjob_controller.php b/application/controllers/Cli/Cronjob_controller.php new file mode 100755 index 0000000..e2a884f --- /dev/null +++ b/application/controllers/Cli/Cronjob_controller.php @@ -0,0 +1,103 @@ +' . print_r($data, TRUE) . ''); + } + } + + /** + * Debug json Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dj($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER : ' . json_encode($data)); + } + } + + /** + * Function to send Emails given slug, payload and email + * + * @param string $slug + * @param mixed $payload + * @param string $email + * @return void + */ + protected function _send_email_notification($slug, $payload, $email) + { + $this->load->model('email_model'); + $this->load->library('mail_service'); + $this->mail_service->set_adapter('smtp'); + $email_template = $this->email_model->get_template($slug, $payload); + + if ($email_template) + { + $from = $this->config->item('from_email'); + return $this->mail_service->send($from, $email, $email_template->subject, $email_template->html); + } + + return FALSE; + } + + /** + * Function to send Sms given slug, payload and phone # + * + * @param string $slug + * @param mixed $payload + * @param string $to + * @return void + */ + protected function _send_sms_notification($slug, $payload, $to) + { + $this->load->model('sms_model'); + $this->load->library('sms_service'); + $this->sms_service->set_adapter('sms'); + $sms_template = $this->sms_model->get_template($slug, $payload); + + if ($sms_template) + { + return $this->sms_service->send($to, $sms_template->content); + } + + return FALSE; + } + + /** + * Function to send Push notification + * + * @param string $slug + * @param mixed $payload + * @param string $to + * @return void + */ + protected function _send_push_notification($device_type, $device_id, $title, $message, $image) + { + $this->load->library('push_notification_service'); + $this->push_notification_service->init(); + return $this->push_notification_service->send($device_type, $device_id, $title, $message, $image); + } +} \ No newline at end of file diff --git a/application/controllers/Cli/Migration_cron_controller.php b/application/controllers/Cli/Migration_cron_controller.php new file mode 100755 index 0000000..45752f3 --- /dev/null +++ b/application/controllers/Cli/Migration_cron_controller.php @@ -0,0 +1,34 @@ +load->library('migration'); + + if ($this->migration->current() === FALSE) + { + print_r($this->migration->error_string()); + } else { + echo 'Complete'; + exit; + } + } + +} \ No newline at end of file diff --git a/application/controllers/Cli/Token_cronjob_controller.php b/application/controllers/Cli/Token_cronjob_controller.php new file mode 100755 index 0000000..83a116d --- /dev/null +++ b/application/controllers/Cli/Token_cronjob_controller.php @@ -0,0 +1,27 @@ +load->database(); + $this->load->model('token_model'); + $reset_token_status = $this->token_model->raw_query("UPDATE `token` SET status=0 WHERE `expire_at` < NOW();"); + $remove_expired_tokens = $this->token_model->raw_query("DELETE FROM `token` WHERE status=0"); + } +} \ No newline at end of file diff --git a/application/controllers/Cli/index.html b/application/controllers/Cli/index.html new file mode 100755 index 0000000..b702fbc --- /dev/null +++ b/application/controllers/Cli/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/controllers/Custom404.php b/application/controllers/Custom404.php new file mode 100755 index 0000000..3bfa579 --- /dev/null +++ b/application/controllers/Custom404.php @@ -0,0 +1,41 @@ +load->helper('url'); + $this->load->database(); + + $this->load->library('redirect_custom_service'); + $this->load->model('url_redirect_model'); + $this->redirect_custom_service->set_url_redirect_model( $this->url_redirect_model ); + if($this->redirect_custom_service->set_url_redirect_model($this->url_redirect_model)) + { + + $this->redirect_custom_service->check_redirect(); + + } + } + + + public function index() + { + $this->output->set_status_header('404'); + $data["heading"] = "404 Page Not Found"; + $data["message"] = "The page you requested was not found "; + + $this->load->view('errors/html/error_404',$data); + } +} +?> \ No newline at end of file diff --git a/application/controllers/Guest/Api_controller.php b/application/controllers/Guest/Api_controller.php new file mode 100755 index 0000000..7b0fb23 --- /dev/null +++ b/application/controllers/Guest/Api_controller.php @@ -0,0 +1,139 @@ +load->database(); + + + $this->load->model('school_model'); + $this->load->model('professor_model'); + $this->load->model('textbook_model'); + $this->load->model('classes_model'); + } + + + + // select2 customer search + public function get_schools() + { + + $custom_query = ''; + if( $this->input->POST('term') ) + { + $custom_query = ' `name` LIKE "%'. $this->input->POST('term',true) .'%" '; + $data_list = $this->school_model->get_all_custom_where($custom_query, ['status' => 1]); + + $response_list = array(); + foreach($data_list as $d_key => $_data) + { + array_push($response_list, array('text' => $_data->name, 'id' => $_data->id)); + } + + $output['results'] = $response_list; + echo json_encode($output); + exit(); + } + + } + + + // select2 customer search + public function get_professors() + { + + $custom_query = ''; + if( $this->input->get('term') ) + { + $custom_query = ' `name` LIKE "%'. $this->input->get('term',true) .'%" '; + $data_list = $this->professor_model->get_all_custom_where($custom_query, ['status' => 1]); + + $response_list = array(); + foreach($data_list as $d_key => $_data) + { + array_push($response_list, array('text' => $_data->name, 'id' => $_data->id)); + } + + $output['results'] = $response_list; + echo json_encode($output); + exit(); + } + + } + + + + // select2 customer search + public function get_courses() + { + + $custom_query = ''; + if( $this->input->get('term') ) + { + $custom_query = ' `name` LIKE "%'. $this->input->get('term',true) .'%" '; + $data_list = $this->classes_model->get_all_custom_where($custom_query, ['status' => 1]); + + $response_list = array(); + foreach($data_list as $d_key => $_data) + { + array_push($response_list, array('text' => $_data->name, 'id' => $_data->id)); + } + + $output['results'] = $response_list; + echo json_encode($output); + exit(); + } + + } + + + + // select2 customer search + public function get_textbooks() + { + if( $this->input->get('term') ) + { + $custom_query = ' `isbn` LIKE "%'. $this->input->get('term',true) .'%" '; + $data_list = $this->db->select('distinct(isbn)')->from('inventory')->where($custom_query)->get()->result_array(); + + + $response_list = array(); + foreach($data_list as $d_key => $_data) + { + array_push($response_list, array('text' => $_data['isbn'], 'id' => $_data['isbn'])); + } + + $output['results'] = $response_list; + echo json_encode($output); + exit(); + } + } + + + // select2 customer search + public function update_old_orders_if_refunded() + { + $this->load->model('order_model'); + $this->load->model('payout_model'); + + + $all_order = $this->order_model->get_all(['status' => 2]); + foreach($all_order as $_key => $_value) + { + $this->payout_model->update('payout',[ 'status'=> 3 ],['order_id' => $_value->id ] ); + } + } + +} +?> \ No newline at end of file diff --git a/application/controllers/Guest/Guest_controller.php b/application/controllers/Guest/Guest_controller.php new file mode 100755 index 0000000..091f72c --- /dev/null +++ b/application/controllers/Guest/Guest_controller.php @@ -0,0 +1,221 @@ + '', + 'success' => '' + ]; + + //testMode flag + protected $_test_mode = FALSE; + + public function __construct() + { + parent::__construct(); + + $this->config->load('setting'); + $this->_setting = $this->config->item('setting'); + + $this->_run_middlewares(); + + } + + protected function _middleware() + { + return [ + 'affilate', + 'maintenance' + ]; + } + + /** + * Debug Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dl($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER :
    ' . print_r($data, TRUE) . '
    '); + } + } + + /** + * Debug json Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dj($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER : ' . json_encode($data)); + } + } + + public function get_session() + { + if (!$this->_test_mode) + { + return $_SESSION; + } + + $session = $this->config->item('session_test'); + + if (!$session) + { + $session = []; + } + + return $session; + } + + public function set_session($field, $value) + { + if (!$this->_test_mode) + { + $_SESSION[$field] = $value; + } + else + { + $session = $this->config->item('session_test'); + if (!$session) + { + $session = []; + } + $session[$field] = $value; + $this->config->set_item('session_test', $session); + } + } + + public function destroy_session() + { + if (!$this->_test_mode) + { + unset($_SESSION); + } + else + { + $this->config->set_item('session_test', []); + } + } + + /** + * Function to send Emails given slug, payload and email + * + * @param string $slug + * @param mixed $payload + * @param string $email + * @return void + */ + protected function _send_email_notification($slug, $payload, $email) + { + $this->load->model('email_model'); + $this->load->library('mail_service'); + $this->mail_service->set_adapter('smtp'); + $email_template = $this->email_model->get_template($slug, $payload); + + if ($email_template) + { + $from = $this->config->item('from_email'); + return $this->mail_service->send($from, $email, $email_template->subject, $email_template->html); + } + + return FALSE; + } + + /** + * Function to send Sms given slug, payload and phone # + * + * @param string $slug + * @param mixed $payload + * @param string $to + * @return void + */ + protected function _send_sms_notification($slug, $payload, $to) + { + $this->load->model('sms_model'); + $this->load->library('sms_service'); + $this->sms_service->set_adapter('sms'); + $sms_template = $this->sms_model->get_template($slug, $payload); + + if ($sms_template) + { + return $this->sms_service->send($to, $sms_template->content); + } + + return FALSE; + } + + /** + * Function to send Push notification + * + * @param string $slug + * @param mixed $payload + * @param string $to + * @return void + */ + protected function _send_push_notification($device_type, $device_id, $title, $message, $image) + { + $this->load->library('push_notification_service'); + $this->push_notification_service->init(); + return $this->push_notification_service->send($device_type, $device_id, $title, $message, $image); + } + + protected function _run_middlewares () + { + + $middlewares = [ + 'affilate' => new Affilate_middleware($this, $this->config), + 'auth' => new Auth_middleware($this, $this->config), + 'acl' => new Acl_middleware($this, $this->config), + 'maintenance' => new Maintenance_middleware($this, $this->config) + ]; + + foreach ($this->_middleware() as $middleware_key) + { + if (isset($middlewares[$middleware_key])) + { + $result = $middlewares[$middleware_key]->run(); + + if (!$result) + { + return FALSE; + } + } + } + } + + public function get_setting() + { + return $this->_setting; + } + + /** + * Redirect to URL + * + * @param string $template + * @param array $data + */ + public function redirect($url, $option = []) + { + return ($option) ? redirect($url, $option) : redirect($url); + } +} \ No newline at end of file diff --git a/application/controllers/Guest/Home_controller.php b/application/controllers/Guest/Home_controller.php new file mode 100755 index 0000000..a064565 --- /dev/null +++ b/application/controllers/Guest/Home_controller.php @@ -0,0 +1,591 @@ + '', + 'success' => '' + ]; + + + protected $_flash_error = [ + 'error' => '', + 'success' => '' + ]; + + public function __construct() + { + parent::__construct(); + $this->load->database(); + + // load services + $this->load->library('helpers_service'); + $this->load->library('stripe_helper_service'); + // $this->load->library('stevesie_api_helper_service'); + // $this->load->library('sale_detail_api_service'); + + + $this->load->model('school_model'); + $this->load->model('content_model'); + $this->load->model('professor_model'); + $this->load->model('textbook_model'); + $this->load->model('classes_model'); + + $this->load->model('inventory_model'); + + // $this->load->library('helpers_service'); + + $this->_data['layout_clean_mode'] = FALSE; + + /** + * social links + */ + $facebook_link = '#'; + $twitter_link = '#'; + $instagram_link = '#'; + + $this->_data['facebook_link'] = $facebook_link; + $this->_data['twitter_link'] = $twitter_link; + $this->_data['instagram_link'] = $instagram_link; + } + + public function index($offset = 0) + { + + $content = $this->content_model->get_all(['status'=>1]); + $this->_data['content'] = []; + if($content ){ + $data = []; + foreach ($content as $key => $value) { + $data[$value->content_name]= $value; + } + $this->_data['content'] = $data; + } + $meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','home_page_meta_title') + ->or_where('content_name','home_page_meta_description')->get()->result_array(); + if($meta_data){ + $meta_data = array_column($meta_data,'content','content_name'); + $this->_data['meta']['title']= $meta_data['home_page_meta_title']; + $this->_data['meta']['desc']= $meta_data['home_page_meta_description']; + } + $this->_data['active'] = 'home'; + $this->_render('Guest/Home', $this->_data); + } + + public function get_all_categories() + { + $data = $this->school_model->get_all(['status' => 1]); + + if ($data) + { + echo json_encode($data); + exit(); + } + echo json_encode(FALSE); + exit(); + } + + public function load_items_by_school_select() + { + $school_id = $this->input->get('school_id'); + + if ($school_id == 0) + { + $output = [ + 'error' => TRUE, + 'status' => 0, + 'msg' => 'all' + ]; + echo json_encode($output); + exit(); + } + + $items = $this->inventory_model->get_all(['school_id' => $school_id]); + + $school_data = $this->school_model->get($school_id); + + if (!empty($items)) + { + $output = [ + 'success' => TRUE, + 'status' => 200, + 'data' => $items, + 'school_name' => $school_data->name + ]; + echo json_encode($output); + exit(); + } + else + { + $output = [ + 'error' => TRUE, + 'status' => 0, + 'msg' => 'No items found for: ' . $school_data->name . ' school.' + ]; + echo json_encode($output); + exit(); + } + + } + + public function item_details($id) + { + $item_details = $this->inventory_model->get_item_details_fe($id); + + if (!empty($item_details)) + { + $this->_data['item_details'] = $item_details; + } + + $school_id = $item_details->school_id; + + $related_items = $this->inventory_model->get_all(['school_id' => $school_id]); + + if (!empty($related_items)) + { + $this->_data['related_items'] = $related_items; + } + + // echo '
    ';print_r($related_items);die();
    +
    +    $this->_data['active'] = 'item_details';
    +    $this->_render('Guest/Item_details', $this->_data);
    +  }
    +
    +  public function about()
    +  {
    +    $this->_data['active'] = 'about';
    +    $this->_render('Guest/About', $this->_data);
    +  }
    +  
    +  public function contact()
    +  { 
    +    if($this->input->post('submit_btn')){
    +     
    +        if($this->input->post('email') && $this->input->post('message') ){
    +    
    +          $email = htmlentities($this->input->post('email'));
    +          // $name = htmlentities($this->input->post('name'));
    +          $message = htmlentities($this->input->post('message'));
    +    
    +    
    +          $regex = '/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/'; 
    +          if (!preg_match($regex, $email)) {
    +            $this->_data['status_'] = 'error'; 
    +            $this->_data['status_msg'] = 'Invalid Email'; 
    +          }else{
    +            
    +            $data = array(
    +              'name'=>'',
    +              'email'=>$email,
    +              'message'=>$message,
    +              'created_at'=>date('Y-m-d')
    +            );
    +           
    +            $this->db->insert('contact_us',$data);
    +
    +            $this->load->model('email_model');
    +            $this->load->library('mail_service');
    +            $this->mail_service->set_adapter('smtp');
    +            $from_email = $this->config->item('from_email');
    +
    +            $this->mail_service->send($from_email, $from_email, "Contact Us", $message, $email);
    +      
    +            $this->_data['status_'] = 'success'; 
    +            $this->_data['status_msg'] = 'Form submitted successfully.'; 
    +          }
    +    
    +        }else{
    +          $this->_data['status_'] = 'error'; 
    +          $this->_data['status_msg'] = 'Fill All required Fields'; 
    +    
    +        }
    +    }
    +
    +    $this->_data['meta'] = [
    +      'title'=>'',
    +      'desc'=>'',
    +    ];
    +
    +    $meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','contact_page_meta_title')
    +    ->or_where('content_name','contact_page_meta_description')->get()->result_array();
    +    if($meta_data){
    +      $meta_data = array_column($meta_data,'content','content_name');
    +      $this->_data['meta']['title']= $meta_data['contact_page_meta_title'];
    +      $this->_data['meta']['desc']= $meta_data['contact_page_meta_description'];
    +    }
    +
    +    $this->_data['active'] = 'contact';
    +    $this->_render('Guest/Contact', $this->_data);
    +  }
    +  public function privacy_policy()
    +  {
    +    $this->_data['active'] = 'privacy_policy';
    +    $this->_data['data'] = $this->db->select('*')->from('content')->where('content_name','privacy_policy')->get()->row_array();
    +    $this->_render('Guest/Privacy_policy', $this->_data);
    +  }
    +    public function buy($offset = 0)
    +    {
    +        // if($this->session->userdata('user_id'))
    +        // { 
    +        //     //create setup intent used in js
    +        //     $stripe = new \Stripe\StripeClient(
    +        //         $this->config->item('stripe_secret_key')
    +        //     );
    +        //     $this->_data['clientSecret'] = $stripe->setupIntents->create([
    +        //         'payment_method_types' => ['card'],
    +        //     ])->client_secret;
    +        // }
    +        
    +        $this->_data['stripe_client']  = $this->config->item('stripe_publish_key');
    +        //get all school data
    +
    +        if ($this->input->get('school_id', TRUE)) 
    +        {
    +            $this->_data['school_data']  = $this->school_model->get_all(['status' => 1, 'id' => $this->input->get('school_id') ]);
    +        }
    +
    +
    +        if ($this->input->get('professor_id', TRUE)) 
    +        {
    +            $this->_data['professor_data']  = $this->professor_model->get_all(['status' => 1, 'id' => $this->input->get('professor_id') ]);
    +        }
    +
    +
    +        if ($this->input->get('class_id', TRUE)) 
    +        {
    +            $this->_data['classes_data']  = $this->classes_model->get_all(['status' => 1, 'id' => $this->input->get('class_id') ]);
    +        }
    +
    +
    +        if ($this->input->get('isbn', TRUE)) 
    +        {
    +            $this->_data['textbook_data']  = $this->db->select('distinct(isbn)')->from('inventory')->where('isbn', $this->input->get('isbn', TRUE))->get()->result_array();
    +        }
    +  
    +         
    +         
    +        
    +        
    +        $search_term    = $this->input->get('search_term', TRUE); 
    +        $school_id      = $this->input->get('school_id', TRUE);
    +        $professor_id   = $this->input->get('professor_id', TRUE);
    +        $textbook_id    = $this->input->get('textbook_id', TRUE);
    +        $isbn           = $this->input->get('isbn', TRUE);
    +        $class_id       = $this->input->get('class_id', TRUE);    
    +        $order_by       = $this->input->get('order_by', TRUE);
    +        $direction      = $this->input->get('direction', TRUE);
    +
    +
    +        // if($school_id || $professor_id || $textbook_id || $class_id || $search_term)
    +        // {
    +        // for pagination
    +        $this->load->library('pagination');
    +
    +        $rows_data = $this->inventory_model->get_all_active_items_list_fe($search_term, $school_id, $professor_id, $textbook_id, $class_id,$isbn,$order_by,$direction);
    +
    +        $total_rows = 0;
    +        if (!empty($rows_data))
    +        {
    +          $total_rows = count($rows_data);
    +        }
    +        $limit = 10;
    +
    +        // $offset = $offset * $limit ;
    +
    +        if ($offset != 0 OR $offset != "") 
    +        {
    +            $offset = ($offset - 1) * $limit;
    +        }
    +
    +
    +        $this->pagination->initialize([
    +          'reuse_query_string' => TRUE,
    +          'base_url'           => base_url().'/buy',
    +          'total_rows'         => $total_rows,
    +          'per_page'           => $limit,
    +          'num_links'          => 2,
    +          'full_tag_open'      => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'use_page_numbers' => TRUE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + + $items = $this->inventory_model->get_all_active_items_list_fe($search_term, $school_id, $professor_id, $textbook_id, $class_id,$isbn,$order_by,$direction, $offset, $limit); + + if (!empty($items)) + { + $this->_data['links'] = $this->pagination->create_links(); + $this->_data['items'] = $items; + } + + // } + //notes amount + $notes_amount = $this->db->select('value')->from('setting')->where('key','fixed_paper_amount')->get()->row_array(); + if( $notes_amount){ + $this->_data['notes_amount'] = $notes_amount['value']; + }else{ + $this->_data['notes_amount'] = 50; + } + + $this->_data['user_downloaded_files'] = []; + if($this->session->userdata('user_id')) + { + $this->_data['user_downloaded_files'] = $this->db->select('inventory_id')->from('order')->where('purchase_user_id',$this->session->userdata('user_id'))->get()->result_array(); + if($this->_data['user_downloaded_files'] ) + { + $this->_data['user_downloaded_files'] = array_column($this->_data['user_downloaded_files'],'inventory_id'); + } + } + + $this->_data['meta'] = [ + 'title' => '', + 'desc' => '', + ]; + + $meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','buy_page_meta_title')->or_where('content_name','buy_page_meta_description')->get()->result_array(); + if($meta_data) + { + $meta_data = array_column($meta_data,'content','content_name'); + $this->_data['meta']['title'] = $meta_data['buy_page_meta_title']; + $this->_data['meta']['desc'] = $meta_data['buy_page_meta_description']; + } + + $this->_data['active'] = 'buy'; + $this->_render('Guest/Buy', $this->_data); + } + + + + + + + + public function sell() + { + $content = $this->content_model->get_all(['status'=>1]); + $this->_data['content'] = []; + if($content ) + { + $data = []; + foreach ($content as $key => $value) { + $data[$value->content_name]= $value; + } + $this->_data['content'] = $data; + } + + // //get all school data + // $this->_data['school_data'] = $this->school_model->get_all(['status' => 1]); + // $this->_data['professor_data'] = $this->professor_model->get_all(['status' => 1]); + // $this->_data['classes_data'] = $this->classes_model->get_all(['status' => 1]); + // $this->_data['textbook_data'] = $this->textbook_model->get_all(['status' => 1]); + + + + $data = $this->db->select('paypal_email')->from('user')->where('id',$this->session->userdata('user_id'))->get()->row_array(); + + if (isset($data['paypal_email'])) + { + $this->_data['paypal_email'] = $data['paypal_email']; + } + + + + $this->_data['meta'] = [ + 'title'=>'', + 'desc'=>'', + ]; + + $meta_data = $this->db->select('content,content_name')->from('content')->where('content_name','sell_page_meta_title')->or_where('content_name','sell_page_meta_description')->get()->result_array(); + + if($meta_data) + { + $meta_data = array_column($meta_data,'content','content_name'); + $this->_data['meta']['title']= $meta_data['sell_page_meta_title']; + $this->_data['meta']['desc']= $meta_data['sell_page_meta_description']; + } + + $this->_data['active'] = 'sell'; + + $this->_render('Guest/Sell', $this->_data); + } + + + public function checkout() + { + + if(!$this->session->userdata('user_id')){ + + echo json_encode(['status'=>'error','message'=>'You Have to Login First']); + exit; + } + + $user_id = $this->session->userdata('user_id'); + // stripe_helper_service + $card_number = $this->input->post('card_number', TRUE); + $exp_month = $this->input->post('exp_month', TRUE); + $exp_year = $this->input->post('exp_year', TRUE); + $cvc = $this->input->post('cvc', TRUE); + $inv_id = $this->input->post('inv_id', TRUE); + + $new_card_last4 = substr($card_number, 12); + + // add card + $this->stripe_helper_service->set_config($this->config); + $response = $this->stripe_helper_service->create_stripe_token($card_number, $exp_month, $exp_year, $cvc); + + if (isset($response['success'])) + { + $stripe_token_id = $response['token']->id; + + $this->stripe_helper_service->set_config($this->config); + $this->stripe_helper_service->set_user_model($this->user_model); + // pass token_id to assign card to user + $res_card_data = $this->stripe_helper_service->add_new_card($stripe_token_id, $user_id); + + if (isset($res_card_data['success'])) + { + $stripe_card_id = $res_card_data['card_data']->id; + $stripe_brand = $res_card_data['card_data']->brand; + $stripe_exp_month = $res_card_data['card_data']->exp_month; + $stripe_exp_year = $res_card_data['card_data']->exp_year; + $stripe_last4 = $res_card_data['card_data']->last4; + + // store the card id with the associated user + $check_new_card = $this->user_card_model->create([ + 'is_default' => 0, + 'user_id' => $user_id, + 'stripe_card_id' => $stripe_card_id, + 'brand' => $stripe_brand, + 'exp_month' => $stripe_exp_month, + 'exp_year' => $stripe_exp_year, + 'last4' => $stripe_last4, + 'cvc' => $cvc, + 'status' => 1 + ]); + } + else + { + // when user do not have the user->stripe_id + echo json_encode(['status'=>'error','message'=>'Error']); + exit; + } + } + else + { + // when new card validation failed + echo json_encode(['status'=>'error','message'=>'Error You card is invalid']); + exit; + } + } + + + public function autocomplete() + { + $html = ''; + if($this->input->post('keyword')) + { + + $result = $this->db->query(" + SELECT name FROM school WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%' + UNION ALL + SELECT name FROM classes WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%' + UNION ALL + SELECT name FROM professor WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%' + UNION ALL + SELECT name FROM textbook WHERE name LIKE '%".htmlentities($this->input->post('keyword'))."%' + UNION ALL + SELECT title as name FROM inventory WHERE title LIKE '%".htmlentities($this->input->post('keyword'))."%' + ")->result_array(); + + + + + if(!empty($result)) { + $html .='
      '; + foreach($result as $key =>$value) { + $html .= '
    • '.$value["name"].'
    • '; + } + $html .= '
    '; + } + } + echo json_encode(['html'=>$html]); + exit(); + } + public function preview($id) + { + + $this->_data['active'] = 'Preview'; + $this->_data['data'] = $this->inventory_model->get_by_fields(['status'=>1,'id'=>$id]); + $this->_render('Guest/Preview', $this->_data); + } + public function terms_and_conditions() + { + // $terms = $this->terms_and_conditions_model->get(1); + + // if (!empty($terms)) + // { + // $this->_data['terms'] = $terms; + // } + $this->_data['data'] = $this->db->select('*')->from('content')->where('content_name','terms_conditon')->get()->row_array(); + $this->_data['active'] = 'terms_and_conditions'; + $this->_render('Guest/Terms_and_conditions', $this->_data); + } + + protected function _render($template, $_data) + { + $this->_data['page_section'] = $template; + + $this->load->view('Guest/Header', $this->_data); + $this->load->view($template, $this->_data); + $this->load->view('Guest/Footer', $this->_data); + } + + public function dd() + { + $output = ''; + + echo "
    ";
    +    print_r($output);
    +    die();
    +  }
    +
    +  public function get_review(){
    +    if( isset($_POST['id']) )
    +    {
    +
    +      $data = $this->db->select('r.*,u.image,u.first_name')->from('review r')->join('user u','r.user_id=u.id')->where('inventory_id',$_POST['id'])->where('r.status',1)->order_by('r.created_at')->get()->result_array();
    +      echo json_encode(['status'=>true,'data'=>$data]);
    +      exit;
    +    }
    +    echo json_encode(['status'=>false]);
    +    exit;
    +  }
    +
    +}
    diff --git a/application/controllers/Guest/Image_controller.php b/application/controllers/Guest/Image_controller.php
    new file mode 100755
    index 0000000..fa9df2d
    --- /dev/null
    +++ b/application/controllers/Guest/Image_controller.php
    @@ -0,0 +1,473 @@
    + '',
    +        'success' => ''
    +    ];
    +
    +    //testMode flag
    +    protected $_test_mode = FALSE;
    +
    +    public function __construct()
    +    {
    +        parent::__construct();
    +        $this->load->database();
    +    }
    +
    +    public function index ()
    +    {
    +        $image_upload_type = $this->config->item('image_upload');
    +
    +        if ($image_upload_type == 's3')
    +        {
    +            return $this->s3_upload();
    +        }
    +
    +        $this->load->model('image_model');
    +        $data_uri = $this->input->post('image');
    +        $base_url = $this->config->item('base_url');
    +        $image_path = __DIR__ . '/../../../uploads/';
    +        $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data_uri));
    +        $filename = md5(uniqid() . time()) . '.png';
    +        file_put_contents($image_path . $filename, $data);
    +        list($width, $height) = @getimagesize( $image_path .$filename );
    +        $session = $this->get_session();
    +        $user_id = isset($session['user_id']) ? $session['user_id'] : 0;
    +
    +        $image_id = $this->image_model->create([
    +            'url' => '/uploads/' . $filename,
    +			'type' => 0,
    +			'user_id' => $user_id,
    +            'width' => $width,
    +            'caption' => '',
    +			'height' => $height
    +        ]);
    +
    +        return $this->output->set_content_type('application/json')
    +        ->set_status_header(200)
    +        ->set_output(json_encode([
    +            'id' => $image_id,
    +            'image' => $base_url . '/uploads/' . $filename,
    +            'width' => $width,
    +            'height' => $height
    +        ]));
    +    }
    +
    +    public function s3_upload ()
    +    {
    +        $s3 = new S3Client([
    +            'version' => $this->config->item('aws_version'),
    +            'region'  => $this->config->item('aws_region'),
    +            'endpoint'  => $this->config->item('aws_endpoint'),
    +            'use_path_style_endpoint' => true,
    +            'credentials' => [
    +                'key'    => $this->config->item('aws_key'),
    +                'secret' => $this->config->item('aws_secret'),
    +            ]
    +        ]);
    +
    +        $this->load->model('image_model');
    +        $data_uri = $this->input->post('image');
    +        $image_path = __DIR__ . '/../../../uploads/';
    +        $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data_uri));
    +        $filename = md5(uniqid() . time()) . '.png';
    +        file_put_contents($image_path . $filename, $data);
    +        list($width, $height) = getimagesize( $image_path . $filename );
    +        $session = $this->get_session();
    +        $user_id = isset($session['user_id']) ? $session['user_id'] : 0;
    +
    +        try
    +        {
    +            $result = $s3->putObject([
    +                'Bucket' => $this->config->item('aws_bucket'),
    +                'Key'    => $filename,
    +                'Body'   => fopen($image_path . $filename, 'r'),
    +                'ACL'    => 'public-read',
    +            ]);
    +
    +            $image_id = $this->image_model->create([
    +                'url' => $result->get('ObjectURL'),
    +                'type' => 0,
    +                'user_id' => $user_id,
    +                'width' => $width,
    +                'caption' => '',
    +                'height' => $height
    +            ]);
    +
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(200)
    +            ->set_output(json_encode([
    +                'id' => $image_id,
    +                'image' => $result->get('ObjectURL'),
    +                'width' => $width,
    +                'height' => $height
    +            ]));
    +        }
    +        catch (Aws\S3\Exception\S3Exception $e)
    +        {
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(403)
    +            ->set_output(json_encode([
    +                'message' => 'Upload to S3 Failed'
    +            ]));
    +        }
    +    }
    +
    +    public function file_upload ()
    +    {
    +        $file_upload_type = $this->config->item('file_upload');
    +        $this->load->library('mime_service');
    +        if ($file_upload_type == 's3')
    +        {
    +            return $this->s3_file_upload();
    +        }
    +
    +        $this->load->model('image_model');
    +
    +        if  (!(isset($_FILES) && count($_FILES) > 0 && isset($_FILES['file'])))
    +        {
    +            return $this->output->set_content_type('application/json')
    +                ->set_status_header(403)
    +                ->set_output(json_encode([
    +                    'message' => 'Upload file missing'
    +                ]));
    +        }
    +
    +        $file = $_FILES['file'];
    +        $size = $file['size'];
    +        $path = $file['tmp_name'];
    +        $type = $file['type'];
    +        $extension = $this->mime_service->get_extension($type);
    +
    +        if ($size > $this->config->item('upload_byte_size_limit'))
    +        {
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(403)
    +            ->set_output(json_encode([
    +                'message' => 'Upload file size too big'
    +            ]));
    +        }
    +
    +        $filename = md5(uniqid() . time()) . $extension;
    +        $width = 0;
    +        $height = 0;
    +        $session = $this->get_session();
    +        $user_id = isset($session['user_id']) ? $session['user_id'] : 0;
    +        $image_path = __DIR__ . '/../../../uploads/';
    +
    +        if (!move_uploaded_file($path, $image_path . $filename))
    +        {
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(403)
    +            ->set_output(json_encode([
    +                'message' => 'Upload file failed'
    +            ]));
    +        }
    +
    +        $image_id = $this->image_model->create([
    +            'url' => '/uploads/' . $filename,
    +            'type' => 4,
    +            'user_id' => $user_id,
    +            'width' => $width,
    +            'caption' => '',
    +            'height' => $height
    +        ]);
    +
    +        return $this->output->set_content_type('application/json')
    +        ->set_status_header(200)
    +        ->set_output(json_encode([
    +            'id' => $image_id,
    +            'file' => '/uploads/' . $filename,
    +            'width' => $width,
    +            'height' => $height
    +        ]));
    +    }
    +
    +    public function s3_file_upload ()
    +    {
    +        $this->load->model('image_model');
    +        $this->load->library('mime_service');
    +
    +        $s3 = new S3Client([
    +            'version' => $this->config->item('aws_version'),
    +            'region'  => $this->config->item('aws_region'),
    +            'endpoint'  => $this->config->item('aws_endpoint'),
    +            'use_path_style_endpoint' => true,
    +            'credentials' => [
    +                'key'    => $this->config->item('aws_key'),
    +                'secret' => $this->config->item('aws_secret'),
    +            ]
    +        ]);
    +
    +        if (!(isset($_FILES) && count($_FILES) > 0 && isset($_FILES['file'])))
    +        {
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(403)
    +            ->set_output(json_encode([
    +                'message' => 'Upload file failed'
    +            ]));
    +        }
    +
    +        $file = $_FILES['file'];
    +        $size = $file['size'];
    +        $path = $file['tmp_name'];
    +        $type = $file['type'];
    +        $extension = $this->mime_service->get_extension($type);
    +
    +        if ($size > $this->config->item('upload_byte_size_limit'))
    +        {
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(403)
    +            ->set_output(json_encode([
    +                'message' => 'Upload file size too big'
    +            ]));
    +        }
    +
    +        $filename = md5(uniqid() . time()) . $extension;
    +        $width = 0;
    +        $height = 0;
    +        $session = $this->get_session();
    +        $user_id = isset($session['user_id']) ? $session['user_id'] : 0;
    +
    +        try
    +        {
    +            $result = $s3->putObject([
    +                'Bucket' => $this->config->item('aws_bucket'),
    +                'Key'    => $filename,
    +                'Body'   => fopen($path, 'r'),
    +                'ACL'    => 'public-read',
    +            ]);
    +
    +            $image_id = $this->image_model->create([
    +                'url' => $result->get('ObjectURL'),
    +                'type' => 5,
    +                'user_id' => $user_id,
    +                'width' => $width,
    +                'caption' => '',
    +                'height' => $height
    +            ]);
    +
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(200)
    +            ->set_output(json_encode([
    +                'id' => $image_id,
    +                'file' => $result->get('ObjectURL'),
    +                'width' => $width,
    +                'height' => $height
    +            ]));
    +        }
    +        catch (Aws\S3\Exception\S3Exception $e)
    +        {
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(403)
    +            ->set_output(json_encode([
    +                'message' => 'Upload to S3 Failed'
    +            ]));
    +        }
    +    }
    +
    +    public function paginate($page)
    +	{
    +        $this->load->library('pagination');
    +        $this->load->model('image_model');
    +        include_once __DIR__ . '/../../view_models/Image_asset_paginate_view_model.php';
    +        $where = [];
    +        $this->_data['view_model'] = new Image_asset_paginate_view_model(
    +            $this->image_model,
    +            $this->pagination,
    +            '/v1/api/assets/0');
    +
    +        $this->_data['view_model']->set_heading('Images');
    +
    +        $this->_data['view_model']->set_total_rows($this->image_model->count($where));
    +
    +        $this->_data['view_model']->set_per_page(10);
    +        $this->_data['view_model']->set_page($page);
    +		$this->_data['view_model']->set_list($this->image_model->get_paginated(
    +            $this->_data['view_model']->get_page(),
    +            $this->_data['view_model']->get_per_page(),
    +            $where));
    +
    +        return $this->success($this->_data['view_model']->to_json(), 200);
    +	}
    +
    +    public function file_import ($model)
    +    {
    +        $model_name = $model . '_model';
    +        $this->load->library('mime_service');
    +        $this->load->library('csv_import_service');
    +        $this->load->model($model_name);
    +
    +        $this->csv_import_service->set_model($this->$model_name, $model);
    +
    +       /* if  ($this->csv_import_service->csv_file_exist($_FILES))
    +        {
    +            return $this->output->set_content_type('application/json')
    +                ->set_status_header(403)
    +                ->set_output(json_encode([
    +                    'message' => 'Upload CSV File missing'
    +                ]));
    +        }*/
    +
    +        $file = $_FILES['file'];
    +        $size = $file['size'];
    +        $path = $file['tmp_name'];
    +        $type = $file['type'];
    +        $extension = $this->mime_service->get_extension($type);
    +        //$extension = ucfirst(str_replace('.', '', $this->mime_service->get_extension($type)));
    +        $save_as = FCPATH . 'uploads/' . $file["name"];
    +
    +        if ($size > $this->config->item('upload_byte_size_limit'))
    +        {
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(403)
    +            ->set_output(json_encode([
    +                'message' => 'Upload file size too big'
    +            ]));
    +        }
    +
    +
    +        $save_as = FCPATH . 'uploads/temp' . $extension;
    +
    +        if ($size > $this->config->item('upload_byte_size_limit'))
    +        {
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(403)
    +            ->set_output(json_encode([
    +                'message' => 'Upload file size too big'
    +            ]));
    +        }
    +
    +        if (move_uploaded_file($path, $save_as))
    +        {
    +            $data =  $this->csv_import_service->_import_data( $save_as );
    +
    +            if($data)
    +            {
    +                unlink($save_as);
    +                return $this->output->set_content_type('application/json')
    +                ->set_status_header(200)
    +                ->set_output(json_encode([
    +                    'status' => TRUE
    +                ]));
    +            }
    +        }
    +
    +        return $this->output->set_content_type('application/json')
    +        ->set_status_header(403)
    +        ->set_output(json_encode([
    +            'message' => 'Generating SQL worked but insert error to the database'
    +        ]));
    +    }
    +
    +    public function preview_csv()
    +    {
    +        $this->load->library('mime_service');
    +        $this->load->library('csv_import_service');
    +
    +        $file = $_FILES['file'];
    +        $size = $file['size'];
    +        $path = $file['tmp_name'];
    +        $type = $file['type'];
    +        $save_as = FCPATH . 'uploads/' . $file["name"];
    +
    +        if ($size > $this->config->item('upload_byte_size_limit'))
    +        {
    +            return $this->output->set_content_type('application/json')
    +            ->set_status_header(403)
    +            ->set_output(json_encode([
    +                'message' => 'Upload file size too big'
    +            ]));
    +        }
    +
    +        if (move_uploaded_file($path, $save_as))
    +        {
    +            $data =  $this->csv_import_service->_get_file_data( $save_as );
    +            return $this->output->set_content_type('application/json')
    +                ->set_status_header(200)
    +                ->set_output(json_encode([
    +                    'message' => 'xyzFile loaded',
    +                    'data' => $data,
    +                    'preview' => TRUE
    +            ]));
    +        }
    +
    +
    +
    +    }
    +
    +    /**
    +     * Debug Controller to error_log and turn off in production
    +     *
    +     * @param mixed $data
    +     * @return void
    +     */
    +    public function dl($key, $data)
    +    {
    +        if (ENVIRONMENT == 'development')
    +        {
    +            error_log($key . ' CONTROLLER : 
    ' . print_r($data, TRUE) . '
    '); + } + } + + /** + * Debug json Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dj($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER : ' . json_encode($data)); + } + } + + public function get_session() + { + if (!$this->_test_mode) + { + return $_SESSION; + } + + $session = $this->config->item('session_test'); + + if (!$session) + { + $session = []; + } + + return $session; + } + + /** + * Success API Call + * + * @return string + */ + public function success($success) + { + $success['code'] = 200; + $success['success'] = TRUE; + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($success)); + } + + +} \ No newline at end of file diff --git a/application/controllers/Guest/Marketing_controller.php b/application/controllers/Guest/Marketing_controller.php new file mode 100755 index 0000000..d6ca3da --- /dev/null +++ b/application/controllers/Guest/Marketing_controller.php @@ -0,0 +1,264 @@ + '', + 'success' => '' + ]; + + public function __construct() + { + parent::__construct(); + $this->load->database(); + $this->load->model('marketing_model'); + + } + + /** + * Debug Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dl($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER :
    ' . print_r($data, TRUE) . '
    '); + } + } + + /** + * Debug json Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dj($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER : ' . json_encode($data)); + } + } + + public function get_session() + { + if (!$this->_test_mode) + { + return $_SESSION; + } + + $session = $this->config->item('session_test'); + + if (!$session) + { + $session = []; + } + + return $session; + } + + public function set_session($field, $value) + { + if (!$this->_test_mode) + { + $_SESSION[$field] = $value; + } + else + { + $session = $this->config->item('session_test'); + if (!$session) + { + $session = []; + } + $session[$field] = $value; + $this->config->set_item('session_test', $session); + } + } + + public function destroy_session() + { + if (!$this->_test_mode) + { + unset($_SESSION); + } + else + { + $this->config->set_item('session_test', []); + } + } + + public function get_setting() + { + return $this->_setting; + } + + /** + * Function to generate a slug + */ + public function generate_marketing_slug($str) + { + + $delimiter = '-'; + $slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter)); + $full_path = base_url() . 'a/'; + + $row = $this->marketing_model->get_by_field('slug', $full_path . $slug); + + if (empty($row)) + { + $output['slug'] = $slug; + echo json_encode($output); + exit; + } + else + { + $i = 1; + $check_me_again = TRUE; + while ($check_me_again) + { + $slug = $slug . '-' . $i; + $row = $this->marketing_model->get_by_field('slug', $full_path . $slug); + + if (empty($row)) + { + $check_me_again = FALSE; + } + $i++; + } + + $output['slug'] = $slug; + echo json_encode($output); + exit; + } + } + + /** + * Function to return the generated page + */ + public function generate_custom_marketing_page($slug) + { + $slug_url = base_url() . 'a/'; + $slug = $slug_url.$slug; + $marketing_data = $this->marketing_model->get_by_field('slug',$slug); + $this->_data['header'] = ''; + $this->_data['footer'] = ''; + $this->_data['content_template'] = ''; + $this->_data['content'] = ''; + $this->_data['success'] = ''; + $this->_data['error'] = ''; + $this->_data['layout_clean_mode'] = TRUE; + $this->_data['reuse_query_string'] = TRUE; + $this->_data['base_url'] = base_url(); + $this->_data['total_rows'] = 25; + $this->_data['per_page'] = 25; + $this->_data['num_links'] = ''; + $this->_data['full_tag_open'] = '
      '; + $this->_data['full_tag_close'] = '
    '; + $this->_data['attributes'] = ['class' => 'page-link']; + $this->_data['first_link'] = FALSE ; + $this->_data['last_link'] = FALSE; + $this->_data['first_tag_open'] = '
  • '; + $this->_data['first_tag_close'] = '
  • '; + $this->_data['prev_link'] = '«'; + $this->_data['setting'] = $this->get_setting(); + $this->_data['list'] = []; + + if($marketing_data) + { + if($marketing_data->header_template_path != '') + { + $this->_data['header'] = $marketing_data->header_template_path ? $marketing_data->header_template_path : ''; + } + + if($marketing_data->footer_template_path != '') + { + $this->_data['footer'] = $marketing_data->footer_template_path ? $marketing_data->footer_template_path : ''; + } + + $this->_data['content'] = $marketing_data->content ? $marketing_data->content : ''; + $this->_data['content_template'] = $marketing_data->content_template_path ? $marketing_data->content_template_path : ''; + + if($marketing_data->status == 0) + { + if ($marketing_data->password_protect == '') + { + return $this->generate_marketing_template($this->_data); + } + else + { + $valid_passwords = [ + 'guest' => $marketing_data->password_protect + ]; + $valid_users = array_keys($valid_passwords); + + $user = $_SERVER['PHP_AUTH_USER']; + $pass = $_SERVER['PHP_AUTH_PW']; + + $validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]); + + if (!$validated) + { + header('WWW-Authenticate: Basic realm="My Realm"'); + header('HTTP/1.0 401 Unauthorized'); + die ('Not authorized'); + } + + return $this->generate_marketing_template($this->_data); + + } + } + else + { + $this->output->set_status_header('404'); + $data['heading'] = '404 Page Not Found'; + $data['message'] = 'The page you requested was not found'; + $this->load->view('errors/html/error_404',$data); + exit(); + } + + } + $this->output->set_status_header('404'); + $data['heading'] = '404 Page Not Found'; + $data['message'] = 'The page you requested was not found'; + $this->load->view('errors/html/error_404', $data); + exit(); + } + + /** + * Function to generate marketing template + */ + + public function generate_marketing_template($marketing_data) + { + if($marketing_data['header'] != '') + { + $this->load->view($marketing_data['header'], $marketing_data); + } + + if($marketing_data['content_template'] == '') + { + echo $marketing_data['content_template']; + } + else + { + $this->load->view('Guest/Template_page', $marketing_data); + } + + if($marketing_data['footer'] != '') + { + $this->load->view($marketing_data['footer'], $marketing_data); + } + } +} \ No newline at end of file diff --git a/application/controllers/Guest/Spreadsheet_controller.php b/application/controllers/Guest/Spreadsheet_controller.php new file mode 100755 index 0000000..980baed --- /dev/null +++ b/application/controllers/Guest/Spreadsheet_controller.php @@ -0,0 +1,107 @@ + '', + 'success' => '' + ]; + + public function __construct() + { + parent::__construct(); + $this->load->database(); + $this->load->model('spreadsheet_model'); + + } + + /** + * Debug Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dl($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER :
    ' . print_r($data, TRUE) . '
    '); + } + } + + /** + * Debug json Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dj($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER : ' . json_encode($data)); + } + } + + public function get_session() + { + if (!$this->_test_mode) + { + return $_SESSION; + } + + $session = $this->config->item('session_test'); + + if (!$session) + { + $session = []; + } + + return $session; + } + + public function set_session($field, $value) + { + if (!$this->_test_mode) + { + $_SESSION[$field] = $value; + } + else + { + $session = $this->config->item('session_test'); + if (!$session) + { + $session = []; + } + $session[$field] = $value; + $this->config->set_item('session_test', $session); + } + } + + public function destroy_session() + { + if (!$this->_test_mode) + { + unset($_SESSION); + } + else + { + $this->config->set_item('session_test', []); + } + } + + public function get_setting() + { + return $this->_setting; + } + +} \ No newline at end of file diff --git a/application/controllers/Guest/index.html b/application/controllers/Guest/index.html new file mode 100755 index 0000000..b702fbc --- /dev/null +++ b/application/controllers/Guest/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/controllers/Health_check_controller.php b/application/controllers/Health_check_controller.php new file mode 100755 index 0000000..28386a7 --- /dev/null +++ b/application/controllers/Health_check_controller.php @@ -0,0 +1,45 @@ +load->database(); + $error = get_instance()->db->error(); + + if (!empty($error) && $error['code'] > 0) + { + throw new Exception('Database Connection Failed'); + } + + return $this->output + ->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode(array( + 'status' => 200, + 'date' => date('Y-m-j H:i:s', time()) + ))); + } + catch (\Exception $e) + { + return $this->output + ->set_content_type('application/json') + ->set_status_header(500) + ->set_output(json_encode(array( + 'status' => 500, + 'date' => date('Y-m-j H:i:s', time()) + ))); + } + } +} \ No newline at end of file diff --git a/application/controllers/Member/Member_cart_controller.php b/application/controllers/Member/Member_cart_controller.php new file mode 100755 index 0000000..a24e5a5 --- /dev/null +++ b/application/controllers/Member/Member_cart_controller.php @@ -0,0 +1,228 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Cart_member_list_paginate_view_model.php'; + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + $session = $this->get_session(); + $where = []; + $this->_data['view_model'] = new Cart_member_list_paginate_view_model( + $this->cart_model, + $this->pagination, + '/member/cart/0'); + $this->_data['view_model']->set_heading('Cart'); + $this->_data['view_model']->set_total_rows($this->cart_model->count($where)); + + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/member/cart/0'); + $this->_data['view_model']->set_list($this->cart_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Member/Cart', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Cart_member_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->cart_model->set_form_validation( + $this->form_validation, $this->cart_model->get_all_validation_rule()); + $this->_data['view_model'] = new Cart_member_add_view_model($this->cart_model); + $this->_data['view_model']->set_heading('Cart'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Member/CartAdd', $this->_data); + } + + $product_id = $this->input->post('product_id', TRUE); + $user_id = $this->input->post('user_id', TRUE); + $session_id = $this->input->post('session_id', TRUE); + $subtotal = $this->input->post('subtotal', TRUE); + $quantity = $this->input->post('quantity', TRUE); + $total = $this->input->post('total', TRUE); + + $result = $this->cart_model->create([ + 'product_id' => $product_id, + 'user_id' => $user_id, + 'session_id' => $session_id, + 'subtotal' => $subtotal, + 'quantity' => $quantity, + 'total' => $total, + + ]); + + if ($result) + { + + + return $this->redirect('/member/cart/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Member/CartAdd', $this->_data); + } + + public function edit($id) + { + $model = $this->cart_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/member/cart/0'); + } + + include_once __DIR__ . '/../../view_models/Cart_member_edit_view_model.php'; + $this->form_validation = $this->cart_model->set_form_validation( + $this->form_validation, $this->cart_model->get_all_edit_validation_rule()); + $this->_data['view_model'] = new Cart_member_edit_view_model($this->cart_model); + $this->_data['view_model']->set_model($model); + $this->_data['view_model']->set_heading('Cart'); + + + + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Member/CartEdit', $this->_data); + } + + $product_id = $this->input->post('product_id', TRUE); + $user_id = $this->input->post('user_id', TRUE); + $session_id = $this->input->post('session_id', TRUE); + $subtotal = $this->input->post('subtotal', TRUE); + $quantity = $this->input->post('quantity', TRUE); + $total = $this->input->post('total', TRUE); + + $result = $this->cart_model->edit([ + 'product_id' => $product_id, + 'user_id' => $user_id, + 'session_id' => $session_id, + 'subtotal' => $subtotal, + 'quantity' => $quantity, + 'total' => $total, + + ], $id); + + if ($result) + { + + + return $this->redirect('/member/cart/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Member/CartEdit', $this->_data); + } + + public function view($id) + { + $model = $this->cart_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/member/cart/0'); + } + + + include_once __DIR__ . '/../../view_models/Cart_member_view_view_model.php'; + $this->_data['view_model'] = new Cart_member_view_view_model($this->cart_model); + $this->_data['view_model']->set_heading('Cart'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Member/CartView', $this->_data); + } + + public function delete($id) + { + $model = $this->cart_model->get($id); + $session = $this->get_session(); + if (!$model) + { + $this->error('Error'); + return redirect('/member/cart/0'); + } + + $result = $this->cart_model->delete($id); + + if ($result) + { + + return $this->redirect('/member/cart/0', 'refresh'); + } + + $this->error('Error'); + return redirect('/member/cart/0'); + } + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Member/Member_controller.php b/application/controllers/Member/Member_controller.php new file mode 100755 index 0000000..7635868 --- /dev/null +++ b/application/controllers/Member/Member_controller.php @@ -0,0 +1,150 @@ +_data['page_name'] = $this->_page_name; + $this->_data['setting'] = $this->_setting; + $this->_data['layout_clean_mode'] = FALSE; + $this->_run_middlewares(); + $layout_mode = $this->input->get('layout_clean_mode', TRUE); + if (isset($layout_mode) && $layout_mode === '1') + { + $this->_data['layout_clean_mode'] = TRUE; + } + } + + protected function _middleware() + { + return [ + 'affilate', 'auth', 'acl', 'maintenance' + ]; + } + + public function render($template, $data) + { + return (!$this->_test_mode) ? $this->_render($template, $data) : $this->_render_test($template, $data); + } + + protected function _render_test($template, $data) + { + return [ + 'header' => $this->load->view('Layout/MemberHeader', $data, TRUE), + 'body' => $this->load->view($template, $data, TRUE), + 'footer' => $this->load->view('Layout/MemberFooter', $data, TRUE), + 'data' => $data, + ]; + } + /** + * Function to return the images for media gallery + */ + public function get_all_images() + { + $this->load->model('image_model'); + $images = $this->image_model->get_all(); + return $images; + } + + protected function _render($template, $data) + { + $data['images'] = $this->get_all_images(); + $data['page_section'] = $template; + $this->load->view('Layout/MemberHeader', $data); + $this->load->view($template, $data); + $this->load->view('Layout/MemberFooter',$data); + } + + /** + * User token invalid + * + * @return string + */ + public function unauthorize_error_message() + { + return $this->output->set_content_type('application/json') + ->set_status_header(401) + ->set_output(json_encode([ + 'code' => 401, + 'success' => FALSE, + 'message' => 'invalid credentials' + ])); + } + + /** + * User Role invalid + * + * @return string + */ + public function unauthorize_resource_error_message() + { + return $this->output->set_content_type('application/json') + ->set_status_header(406) + ->set_output(json_encode([ + 'code' => 406, + 'success' => FALSE, + 'message' => 'cannot access resource' + ])); + } + + /** + * Success API Call + * + * @return string + */ + public function success2($success) + { + $success['code'] = 200; + $success['success'] = TRUE; + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($success)); + } + + /** + * Invalid form input + * + * @return string + */ + protected function _render_validation_error () + { + $data = []; + $data['code'] = 403; + $data['success'] = FALSE; + $data['error'] = $this->form_validation->error_array(); + return $this->output->set_content_type('application/json') + ->set_status_header(403) + ->set_output(json_encode($data)); + } + + /** + * Render Custom Error + * + * @return string + */ + protected function _render_custom_error ($errors) + { + $data = []; + $data['code'] = 403; + $data['success'] = FALSE; + $data['error'] = $errors; + return $this->output->set_content_type('application/json') + ->set_status_header(403) + ->set_output(json_encode($data)); + } +} \ No newline at end of file diff --git a/application/controllers/Member/Member_dashboard_controller.php b/application/controllers/Member/Member_dashboard_controller.php new file mode 100755 index 0000000..8435f38 --- /dev/null +++ b/application/controllers/Member/Member_dashboard_controller.php @@ -0,0 +1,25 @@ +render('Member/Dashboard', $this->_data); + } +} \ No newline at end of file diff --git a/application/controllers/Member/Member_dispute_controller.php b/application/controllers/Member/Member_dispute_controller.php new file mode 100755 index 0000000..78014c6 --- /dev/null +++ b/application/controllers/Member/Member_dispute_controller.php @@ -0,0 +1,136 @@ +load->library('pagination'); + include_once __DIR__ . '/../../view_models/Dispute_member_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Dispute_member_list_paginate_view_model( + $this->dispute_model, + $this->pagination, + '/member/dispute/0'); + $this->_data['view_model']->set_heading('Dispute'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL); + $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL); + $this->_data['view_model']->set_reason(($this->input->get('reason', TRUE) != NULL) ? $this->input->get('reason', TRUE) : NULL); + $this->_data['view_model']->set_stripe_charge_id(($this->input->get('stripe_charge_id', TRUE) != NULL) ? $this->input->get('stripe_charge_id', TRUE) : NULL); + $this->_data['view_model']->set_stripe_dispute_id(($this->input->get('stripe_dispute_id', TRUE) != NULL) ? $this->input->get('stripe_dispute_id', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'id' => $this->_data['view_model']->get_id(), + 'order_id' => $this->_data['view_model']->get_order_id(), + 'user_id' => $this->_data['view_model']->get_user_id(), + 'reason' => $this->_data['view_model']->get_reason(), + 'stripe_charge_id' => $this->_data['view_model']->get_stripe_charge_id(), + 'stripe_dispute_id' => $this->_data['view_model']->get_stripe_dispute_id(), + 'status' => $this->_data['view_model']->get_status(), + + + ]; + + $this->_data['view_model']->set_total_rows($this->dispute_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/member/dispute/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->dispute_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Member/Dispute', $this->_data); + } + + + + + + public function view($id) + { + $model = $this->dispute_model->get($id); + + if (!$model) + { + $this->error('Error'); + return redirect('/member/dispute/0'); + } + + + include_once __DIR__ . '/../../view_models/Dispute_member_view_view_model.php'; + $this->_data['view_model'] = new Dispute_member_view_view_model($this->dispute_model); + $this->_data['view_model']->set_heading('Dispute'); + $this->_data['view_model']->set_model($model); + + + return $this->render('Member/DisputeView', $this->_data); + } + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/application/controllers/Member/Member_forgot_controller.php b/application/controllers/Member/Member_forgot_controller.php new file mode 100755 index 0000000..5cc64d1 --- /dev/null +++ b/application/controllers/Member/Member_forgot_controller.php @@ -0,0 +1,53 @@ +load->model('user_model'); + $this->load->model('credential_model'); + $this->load->model('email_model'); + $this->load->model('token_model'); + $this->load->library('mail_service'); + + $service = new User_service($this->credential_model); + + $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); + + if ($this->form_validation->run() === FALSE) + { + echo $this->load->view('Member/Forgot', $this->_data, TRUE); + exit; + } + + $email = $this->input->post('email'); + $from_email = $this->config->item('from_email'); + $base_url = $this->config->item('base_url'); + + $this->mail_service->set_adapter('smtp'); + $service->set_email_model($this->email_model); + $service->set_token_model($this->token_model); + $service->set_email_service($this->mail_service); + + $reset = $service->forgot_password($email, $from_email, $base_url . '/member/reset', 1); + + if ($reset) + { + $this->success('Your Reset email was sent. Check your email.'); + return $this->redirect('/member/login'); + } + + $this->_data['error'] = 'Email does not exist in our system.'; + echo $this->load->view('Member/Forgot', $this->_data, TRUE); + exit; + } +} \ No newline at end of file diff --git a/application/controllers/Member/Member_inventory_controller.php b/application/controllers/Member/Member_inventory_controller.php new file mode 100755 index 0000000..754b4f3 --- /dev/null +++ b/application/controllers/Member/Member_inventory_controller.php @@ -0,0 +1,1657 @@ +load->model('school_model'); + $this->load->model('professor_model'); + $this->load->model('textbook_model'); + $this->load->model('classes_model'); + $this->load->model('user_model'); + $this->load->model('inventory_model'); + $this->load->model('credential_model'); + + + + } + + function parseWord($userDoc) + { + $fileHandle = fopen($userDoc, "r"); + $word_text = @fread($fileHandle, filesize($userDoc)); + $line = ""; + $tam = filesize($userDoc); + $nulos = 0; + $caracteres = 0; + for($i=1536; $i<$tam; $i++) + { + $line .= $word_text[$i]; + + if( $word_text[$i] == 0) + { + $nulos++; + } + else + { + $nulos=0; + $caracteres++; + } + + if( $nulos>1996) + { + break; + } + } + + //echo $caracteres; + + $lines = explode(chr(0x0D),$line); + //$outtext = "
    ";
    +  
    +      $outtext = "";
    +      foreach($lines as $thisline)
    +      {
    +          $tam = strlen($thisline);
    +          if( !$tam )
    +          {
    +              continue;
    +          }
    +  
    +          $new_line = ""; 
    +          for($i=0; $i<$tam; $i++)
    +          {
    +              $onechar = $thisline[$i];
    +              if( $onechar > chr(240) )
    +              {
    +                  continue;
    +              }
    +  
    +              if( $onechar >= chr(0x20) )
    +              {
    +                  $caracteres++;
    +                  $new_line .= $onechar;
    +              }
    +  
    +              if( $onechar == chr(0x14) )
    +              {
    +                  $new_line .= "";
    +              }
    +  
    +              if( $onechar == chr(0x07) )
    +              {
    +                  $new_line .= "\t";
    +                  if( isset($thisline[$i+1]) )
    +                  {
    +                      if( $thisline[$i+1] == chr(0x07) )
    +                      {
    +                          $new_line .= "\n";
    +                      }
    +                  }
    +              }
    +          }
    +          //troca por hiperlink
    +          $new_line = str_replace("HYPERLINK" ,"",$new_line); 
    +          $new_line .= "\n";
    +  
    +          //link de imagens
    +          $new_line = str_replace("INCLUDEPICTURE" ,"

    ",$new_line); + $new_line = str_replace("MERGEFORMATINET" ,"",$new_line); + + + $outtext .= nl2br($new_line); + } + + return $outtext; + } + + + public function index($page) + { + $this->load->library('pagination'); + include_once __DIR__ . '/../../view_models/Inventory_member_list_paginate_view_model.php'; + $session = $this->get_session(); + $format = $this->input->get('format', TRUE) ?? 'view'; + $order_by = $this->input->get('order_by', TRUE) ?? ''; + $direction = $this->input->get('direction', TRUE) ?? 'ASC'; + $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25; + + $this->_data['view_model'] = new Inventory_member_list_paginate_view_model( + $this->inventory_model, + $this->pagination, + '/member/inventory/0'); + $this->_data['view_model']->set_heading('Inventory'); + $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL); + $this->_data['view_model']->set_title(($this->input->get('title', TRUE) != NULL) ? $this->input->get('title', TRUE) : NULL); + $this->_data['view_model']->set_school_id(($this->input->get('school_id', TRUE) != NULL) ? $this->input->get('school_id', TRUE) : NULL); + $this->_data['view_model']->set_professor_id(($this->input->get('professor_id', TRUE) != NULL) ? $this->input->get('professor_id', TRUE) : NULL); + $this->_data['view_model']->set_class_id(($this->input->get('class_id', TRUE) != NULL) ? $this->input->get('class_id', TRUE) : NULL); + $this->_data['view_model']->set_textbook_id(($this->input->get('textbook_id', TRUE) != NULL) ? $this->input->get('textbook_id', TRUE) : NULL); + $this->_data['view_model']->set_word_count(($this->input->get('word_count', TRUE) != NULL) ? $this->input->get('word_count', TRUE) : NULL); + $this->_data['view_model']->set_year(($this->input->get('year', TRUE) != NULL) ? $this->input->get('year', TRUE) : NULL); + $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL); + + $where = [ + 'inventory.id' => $this->_data['view_model']->get_id(), + 'inventory.title' => $this->_data['view_model']->get_title(), + 'inventory.school_id' => $this->_data['view_model']->get_school_id(), + 'inventory.professor_id' => $this->_data['view_model']->get_professor_id(), + 'inventory.class_id' => $this->_data['view_model']->get_class_id(), + 'inventory.textbook_id' => $this->_data['view_model']->get_textbook_id(), + 'inventory.word_count' => $this->_data['view_model']->get_word_count(), + 'inventory.year' => $this->_data['view_model']->get_year(), + 'inventory.status' => $this->_data['view_model']->get_status(), + 'inventory.user_id' => $this->session->userdata('user_id'), + ]; + + $this->_data['view_model']->set_total_rows($this->inventory_model->count($where)); + + $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']); + $this->_data['view_model']->set_per_page($per_page_sort); + $this->_data['view_model']->set_order_by($order_by); + $this->_data['view_model']->set_sort($direction); + $this->_data['view_model']->set_sort_base_url('/member/inventory/0'); + $this->_data['view_model']->set_page($page); + $this->_data['view_model']->set_list($this->inventory_model->get_paginated( + $this->_data['view_model']->get_page(), + $this->_data['view_model']->get_per_page(), + $where, + $order_by, + $direction)); + + + // load data + $schools = $this->school_model->get_all(['status' => 1]); + $professors = $this->professor_model->get_all(['status' => 1]); + $textbooks = $this->textbook_model->get_all(['status' => 1]); + $classes = $this->classes_model->get_all(['status' => 1]); + $purchase_array = $this->inventory_model->get_current_user_order_count($this->session->userdata('user_id')); + if($purchase_array){ + $purchase_array = array_column($purchase_array,'order_count','inventory_id'); + } + $refunded_array = $this->inventory_model->get_current_user_refunded_count($this->session->userdata('user_id')); + if($refunded_array){ + $refunded_array = array_column($refunded_array,'order_count','inventory_id'); + } + // print_r($this->_data['view_model']->get_list());exit; + + if( $this->_data['view_model']->get_list()){ + + //get all school data + $school_data = array_column($schools ,'name','id'); + //get all professor data + $professor_data = array_column($professors,'name','id'); + //get all classes data + $classes_data = array_column( $classes ,'name','id'); + //get all textbook data + $textbook_data = array_column($textbooks ,'isbn','id'); + + foreach ( $this->_data['view_model']->get_list() as $key => &$value) { + $value->school_id = $school_data[$value->school_id]; + $value->professor_id = $professor_data[$value->professor_id]; + $value->class_id = $classes_data[$value->class_id]; + $value->textbook_id = $textbook_data[$value->textbook_id] ?? ''; + if(isset($purchase_array[$value->id])) + $value->purchased_count = $purchase_array[$value->id] ?? 0; + else + $value->purchased_count = 0; + + if(isset($refunded_array[$value->id])) + $value->refunded_count = $refunded_array[$value->id] ?? 0; + else + $value->refunded_count = 0; + + } + + } + + if ($format == 'csv') + { + header('Content-Type: text/csv'); + header('Content-Disposition: attachment; filename="export.csv"'); + + echo $this->_data['view_model']->to_csv(); + exit(); + } + + + if (!empty($schools)) + { + $this->_data['schools'] = $schools; + } + + if (!empty($professors)) + { + $this->_data['professors'] = $professors; + } + + if (!empty($textbooks)) + { + $this->_data['textbooks'] = $textbooks; + } + + if (!empty($classes)) + { + $this->_data['classes'] = $classes; + } + + if ($format != 'view') + { + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode($this->_data['view_model']->to_json())); + } + + return $this->render('Member/Inventory', $this->_data); + } + + public function add() + { + include_once __DIR__ . '/../../view_models/Inventory_member_add_view_model.php'; + $session = $this->get_session(); + $this->form_validation = $this->inventory_model->set_form_validation( + $this->form_validation, $this->inventory_model->get_all_validation_rule()); + $this->_data['view_model'] = new Inventory_member_add_view_model($this->inventory_model); + $this->_data['view_model']->set_heading('Inventory'); + + $this->load->model('image_model'); + $gallery_images = $this->image_model->get_all(); + foreach ($gallery_images as $key => $image) + { + if ($image->type == 4) + { + $image->show_url = base_url() . $image->url; + } + else + { + $image->show_url = $image->url; + }$image->type = $this->image_model->type_mapping()[$image->type]; + } + $this->_data['gallery_images'] = $gallery_images; + + // load data + $schools = $this->school_model->get_all(['status' => 1]); + $professors = $this->professor_model->get_all(['status' => 1]); + $textbooks = $this->textbook_model->get_all(['status' => 1]); + $classes = $this->classes_model->get_all(['status' => 1]); + + if (!empty($schools)) + { + $this->_data['schools'] = $schools; + } + + if (!empty($professors)) + { + $this->_data['professors'] = $professors; + } + + if (!empty($textbooks)) + { + $this->_data['textbooks'] = $textbooks; + } + + if (!empty($classes)) + { + $this->_data['classes'] = $classes; + } + + if ($this->form_validation->run() === FALSE) + { + return $this->render('Member/InventoryAdd', $this->_data); + } + + $title = $this->input->post('title', TRUE); + $school_id = $this->input->post('school_id', TRUE); + $professor_id = $this->input->post('professor_id', TRUE); + $class_id = $this->input->post('class_id', TRUE); + $textbook_id = $this->input->post('textbook_id', TRUE); + $word_count = $this->input->post('word_count', TRUE); + $year = $this->input->post('year', TRUE); + $isbn = $this->input->post('isbn', TRUE); + // $paypal_email = $this->input->post('paypal_email', TRUE); + $file = $this->input->post('file', TRUE); + $file_id = $this->input->post('file_id', TRUE); + $feature_image = $this->input->post('feature_image', TRUE); + $feature_image_id = $this->input->post('feature_image_id', TRUE); + $note_type = $this->input->post('note_type', TRUE); + // $description = $this->input->post('description', TRUE); + // $inventory_note = $this->input->post('inventory_note', TRUE); + + // $pin_to_top = $this->input->post('pin_to_top', TRUE); + // $approve = $this->input->post('approve', TRUE); + // $status = $this->input->post('status', TRUE); + $session_user_id = $this->session->userdata('user_id'); + + $result = $this->inventory_model->create([ + 'title' => $title, + 'school_id' => $school_id, + 'user_id' => $session_user_id, + 'professor_id' => $professor_id, + 'class_id' => $class_id, + 'textbook_id' => $textbook_id, + 'word_count' => $word_count, + 'year' => $year, + 'isbn' => $isbn, + // 'paypal_email' => $paypal_email, + 'file' => $file, + 'file_id' => $file_id, + 'feature_image' => $feature_image, + 'feature_image_id' => $feature_image_id, + 'note_type' => $note_type, + // 'description' => $description, + // 'inventory_note' => $inventory_note, + 'pin_to_top' => 0, + 'approve' => 1, + 'status' => 1 + ]); + + if ($result) + { + $this->success('Added successfully'); + return $this->redirect('/member/inventory/0', 'refresh'); + } + + $this->_data['error'] = 'Error'; + return $this->render('Member/InventoryAdd', $this->_data); + } + + + + + + + protected function s3_file_upload () + { + $this->load->model('image_model'); + $this->load->library('mime_service'); + + $s3 = new S3Client([ + 'version' => $this->config->item('aws_version'), + 'region' => $this->config->item('aws_region'), + 'endpoint' => $this->config->item('aws_endpoint'), + 'use_path_style_endpoint' => true, + 'credentials' => [ + 'key' => $this->config->item('aws_key'), + 'secret' => $this->config->item('aws_secret'), + ] + ]); + + // $s3->setEndpoint('s3.us-west-001.backblazeb2.com'); + + if (!(isset($_FILES) && count($_FILES) > 0 && isset($_FILES['file_upload']))) + { + $output['error'] = 'Upload file failed'; + return $output; + } + + $file = $_FILES['file_upload']; + $size = $file['size']; + $path = $file['tmp_name']; + $type = $file['type']; + $extension = $this->mime_service->get_extension($type); + + if ($size > $this->config->item('upload_byte_size_limit')) + { + $output['error'] = 'Upload file size too big'; + return $output; + } + + $filename = md5(uniqid() . time()) . $extension; + $width = 0; + $height = 0; + $session = $this->get_session(); + $user_id = isset($session['user_id']) ? $session['user_id'] : 0; + + try + { + $result = $s3->putObject([ + 'Bucket' => $this->config->item('aws_bucket'), + 'Key' => $filename, + 'Body' => fopen($path, 'r'), + 'ACL' => 'public-read', + ]); + + $image_id = $this->image_model->create([ + 'url' => $result->get('ObjectURL'), + 'type' => 5, + 'user_id' => $user_id, + 'width' => $width, + 'caption' => '', + 'height' => $height + ]); + + $output['file'] = $result->get('ObjectURL'); + return $output; + } + catch (Aws\S3\Exception\S3Exception $e) + { + echo "
    ";
    +            print_r($e->getMessage());
    +            die;
    +            $output['error'] = $e->getMessage();
    +            return $output;
    +        }
    +    }
    +
    +
    +    public function add_inventory()
    +    {
    + 
    +        include_once __DIR__ . '/../../view_models/Inventory_member_add_view_model.php';
    +        $session               = $this->get_session();
    +        $this->form_validation = $this->inventory_model->set_form_validation(
    +        $this->form_validation, $this->inventory_model->get_all_validation_rule());
    +        $this->_data['view_model'] = new Inventory_member_add_view_model($this->inventory_model);
    +        $this->_data['view_model']->set_heading('Inventory');
    +
    +        $this->load->model('image_model');
    +        $gallery_images = $this->image_model->get_all();
    +        foreach ($gallery_images as $key => $image)
    +        {
    +            if ($image->type == 4)
    +            {
    +                $image->show_url = base_url() . $image->url;
    +            }
    +            else
    +            {
    +                $image->show_url = $image->url;
    +            }
    +            $image->type = $this->image_model->type_mapping()[$image->type];
    +        }
    +        $this->_data['gallery_images'] = $gallery_images;
    +
    +        // load data
    +        $schools    = $this->school_model->get_all(['status' => 1]);
    +        $professors = $this->professor_model->get_all(['status' => 1]);
    +        $textbooks  = $this->textbook_model->get_all(['status' => 1]);
    +        $classes    = $this->classes_model->get_all(['status' => 1]);
    +
    +        if (!empty($schools))
    +        {
    +          $this->_data['schools'] = $schools;
    +        }
    +
    +        if (!empty($professors))
    +        {
    +          $this->_data['professors'] = $professors;
    +        }
    +
    +        if (!empty($textbooks))
    +        {
    +          $this->_data['textbooks'] = $textbooks;
    +        }
    +
    +        if (!empty($classes))
    +        {
    +          $this->_data['classes'] = $classes;
    +        }
    +
    +        if ($this->form_validation->run() === FALSE  || (!($this->input->post('remember1')) || !($this->input->post('remember2')) ))
    +        {
    +         
    +            $this->error(validation_errors()); 
    +            return $this->redirect('/sell', 'refresh');
    +        }
    +
    +        $file = '';
    +        $preview_files = [];
    +
    +        $file_upload_type = $this->config->item('file_upload'); 
    +        if ($file_upload_type == 's3')
    +        {
    +            $output =  $this->s3_file_upload();
    +            if (isset($output['file'])) 
    +            {
    +                $file = $output['file'];
    +            }else if( isset($output['error']) )
    +            {
    +                $this->error($output['error']);
    +                return $this->redirect('/sell', 'refresh');
    +            }
    +        }else{
    +            $config['upload_path']          = './uploads/';
    +            $config['allowed_types']        = 'doc|docx';
    +            // $config['max_size']             = 100;
    +           
    +
    +            $this->load->library('upload', $config);
    +
    +            if ( ! $this->upload->do_upload('file_upload'))
    +            {
    +                $this->error($this->upload->display_errors());
    +                return $this->redirect('/sell', 'refresh');
    +            }
    +            else
    +            {
    +                $data =$this->upload->data();
    +                $file =  'uploads/'.$data['file_name']; 
    +                // $this->load->view('upload_success', $data);
    +            }
    +
    +            //   echo '
    ';
    +            $upload_file_prop = pathinfo($file);
    +
    +            // $phpWord = new \PhpOffice\PhpWord\PhpWord();
    +
    +            $type = '';
    +            if( $upload_file_prop['extension'] == 'doc')
    +            {
    +                $type = 'MsDoc';
    +            }
    +            else if( $upload_file_prop['extension'] == 'docx')
    +            {
    +                $type = 'Word2007';
    +            }
    +
    +            if($type=='')
    +            {
    +                $this->error('File Name is not correct');
    +                return $this->redirect('/sell', 'refresh');
    +            }
    +        }
    +
    +
    +        
    +
    +
    +        $uri = __DIR__ . "/../../../" . $file;
    +
    +       
    +        $error          = false; 
    +        $api_fileName   = '';
    +        $api_folderName = '';
    +
    +        
    +        $school_id        = $this->input->post('school_id', TRUE);
    +        $professor_id     = $this->input->post('professor_id', TRUE);
    +        $class_id         = $this->input->post('class_id', TRUE); 
    +        $textbook         = $this->input->post('textbook', TRUE) ?? '0';
    +        $word_count       = $this->input->post('word_count', TRUE);
    +        $year             = $this->input->post('year', TRUE);
    +      
    +        $note_type        = $this->input->post('note_type', TRUE);
    +
    +        $session_user_id = $this->session->userdata('user_id');
    +
    +        $result = $this->inventory_model->create([
    +            'title'             => ' ',
    +            'school_id'         => $school_id,
    +            'user_id'           => $session_user_id,
    +            'professor_id'      => $professor_id,
    +            'class_id'          => $class_id, 
    +            'isbn'              => $textbook ?? '',
    +            'word_count'        => $word_count,
    +            'year'              => $year, 
    +            'file'              => $file, 
    +            'feature_image'     =>  "",
    +            'feature_image2'    =>  "",
    +            'feature_image3'    =>  "", 
    +            'note_type'         => $note_type, 
    +            'pin_to_top'        => 0,
    +            'approve'           => 1,
    +            'status'            => 1
    +        ]);
    +
    +        $paypal_email = $this->input->post('paypal_email', TRUE);
    +        if($paypal_email )
    +        {
    +            $this->db->set('paypal_email',$paypal_email)->where('id',$session_user_id)->update('user');
    +        }
    +        if ($result)
    +        {
    +            $this->load->model('email_model');
    +            $this->load->library('mail_service');
    +            $this->mail_service->set_adapter('smtp');
    +            $from_email = $this->config->item('from_email');
    +            $message = "A new outline has been added with ID " . $result . ".";
    +            $this->mail_service->send($from_email, $from_email, "New Outline Added", $message );
    +            
    +
    +
    +            $user_data = $this->user_model->get($this->session->userdata('user_id'));
    +            $logo      = base_url('assets/frontend/img/logo.png');
    +
    +            //send email to uploader  
    +            $template = $this->email_model->get_template('outline_uploaded', [ 
    +                'name'     => $user_data->first_name . " " . $user_data->last_name,         
    +                'logo'     => $logo,         
    +            ]); 
    +            $this->mail_service->send( $from_email, $this->session->userdata('email'), $template->subject, $template->html);
    +
    +
    +            $this->success('Added successfully');
    +            return $this->redirect('/sell', 'refresh');
    +        }
    +
    +        $this->error('Error');
    +        return $this->redirect('/sell', 'refresh');
    +    }
    +
    +  public function edit($id)
    +  {
    +    $model   = $this->inventory_model->get($id);
    +    $session = $this->get_session();
    +    if (!$model)
    +    {
    +      $this->error('Error');
    +      return redirect('/member/inventory/0');
    +    }
    +
    +    include_once __DIR__ . '/../../view_models/Inventory_member_edit_view_model.php';
    +    $this->form_validation = $this->inventory_model->set_form_validation(
    +      $this->form_validation, $this->inventory_model->get_all_edit_validation_rule());
    +    $this->_data['view_model'] = new Inventory_member_edit_view_model($this->inventory_model);
    +    $this->_data['view_model']->set_model($model);
    +    $this->_data['view_model']->set_heading('Inventory');
    +
    +    $this->load->model('image_model');
    +    $gallery_images = $this->image_model->get_all();
    +    foreach ($gallery_images as $key => $image)
    +    {
    +      if ($image->type == 4)
    +      {
    +        $image->show_url = base_url() . $image->url;
    +      }
    +      else
    +      {
    +        $image->show_url = $image->url;
    +      }$image->type = $this->image_model->type_mapping()[$image->type];
    +    }
    +    $this->_data['gallery_images'] = $gallery_images;
    +
    +    // load data
    +    $schools    = $this->school_model->get_all(['status' => 1]);
    +    $professors = $this->professor_model->get_all(['status' => 1]);
    +    $textbooks  = $this->textbook_model->get_all(['status' => 1]);
    +    $classes    = $this->classes_model->get_all(['status' => 1]);
    +
    +    if (!empty($schools))
    +    {
    +      $this->_data['schools'] = $schools;
    +    }
    +
    +    if (!empty($professors))
    +    {
    +      $this->_data['professors'] = $professors;
    +    }
    +
    +    if (!empty($textbooks))
    +    {
    +      $this->_data['textbooks'] = $textbooks;
    +    }
    +
    +    if (!empty($classes))
    +    {
    +      $this->_data['classes'] = $classes;
    +    }
    +
    +    if ($this->form_validation->run() === FALSE)
    +    {
    +      return $this->render('Member/InventoryEdit', $this->_data);
    +    }
    +
    +    // $title            = $this->input->post('title', TRUE);
    +    $school_id        = $this->input->post('school_id', TRUE);
    +    $professor_id     = $this->input->post('professor_id', TRUE);
    +    $class_id         = $this->input->post('class_id', TRUE);
    +    $textbook_id      = $this->input->post('textbook_id', TRUE) ?? '0';
    +    $word_count       = $this->input->post('word_count', TRUE);
    +    $year             = $this->input->post('year', TRUE);
    +    $isbn             = $this->input->post('isbn', TRUE);
    +    // $paypal_email     = $this->input->post('paypal_email', TRUE);
    +    $file             = $this->input->post('file', TRUE);
    +    $file_id          = $this->input->post('file_id', TRUE);
    +    $feature_image    = $this->input->post('feature_image', TRUE);
    +    $feature_image_id = $this->input->post('feature_image_id', TRUE);
    +    $note_type        = $this->input->post('note_type', TRUE);
    +    $description      = $this->input->post('description', TRUE);
    +    $inventory_note   = $this->input->post('inventory_note', TRUE);
    +
    +    // $pin_to_top       = $this->input->post('pin_to_top', TRUE);
    +    // $approve          = $this->input->post('approve', TRUE);
    +    // $status           = $this->input->post('status', TRUE);
    +
    +    $result = $this->inventory_model->edit([
    +      // 'title'            => $title,
    +      'school_id'        => $school_id,
    +      'professor_id'     => $professor_id,
    +      'class_id'         => $class_id,
    +      'textbook_id'      => $textbook_id,
    +      'word_count'       => $word_count,
    +      'year'             => $year,
    +      // 'isbn'             => $isbn,
    +      // 'paypal_email'     => $paypal_email,
    +      // 'file'             => $file,
    +      // 'file_id'          => $file_id,
    +      // 'feature_image'    => $feature_image,
    +      // 'feature_image_id' => $feature_image_id,
    +      'note_type'        => $note_type,
    +      // 'description'      => $description ?? '',
    +      // 'inventory_note'   => $inventory_note ?? '',
    +      'pin_to_top'       => 0,
    +      'approve'          => 1,
    +      'status'           => 1
    +    ], $id);
    +
    +    if ($result)
    +    {
    +      $this->success('Updated successfully');
    +      return $this->redirect('/member/inventory/0', 'refresh');
    +    }
    +
    +    $this->_data['error'] = 'Error';
    +    return $this->render('Member/InventoryEdit', $this->_data);
    +  }
    +
    +  public function view($id)
    +  {
    +    $model = $this->inventory_model->get($id);
    +
    +    if (!$model)
    +    {
    +      $this->error('Error');
    +      return redirect('/member/inventory/0');
    +    }
    +
    +    include_once __DIR__ . '/../../view_models/Inventory_member_view_view_model.php';
    +    $this->_data['view_model'] = new Inventory_member_view_view_model($this->inventory_model);
    +    $this->_data['view_model']->set_heading('Inventory');
    +    $this->_data['view_model']->set_model($model);
    +
    +       //get all school data
    +       $this->_data['school_data']  = array_column($this->school_model->get_all(['status' => 1]),'name','id');
    +       //get all professor data
    +       $this->_data['professor_data']  = array_column($this->professor_model->get_all(['status' => 1]),'name','id');
    +       //get all classes data
    +       $this->_data['classes_data']  = array_column($this->classes_model->get_all(['status' => 1]),'name','id');
    +       //get all textbook data
    +       $this->_data['textbook_data']  = array_column($this->textbook_model->get_all(['status' => 1]),'isbn','id');
    +
    +    $this->_data['view_model']->set_school_id( $this->_data['school_data'][$this->_data['view_model']->get_school_id()]);
    +    $this->_data['view_model']->set_professor_id( $this->_data['professor_data'][$this->_data['view_model']->get_professor_id()]);
    +    $this->_data['view_model']->set_class_id( $this->_data['classes_data'][$this->_data['view_model']->get_class_id()]);
    +    // $this->_data['view_model']->set_textbook_id( $this->_data['textbook_data'][$this->_data['view_model']->get_textbook_id()]);
    +    
    +
    +    return $this->render('Member/InventoryView', $this->_data);
    +  }
    +
    +  public function dispute_order(){
    +
    +    $this->_data['orders'] = $this->db->query('select * from `order` o where o.id not in (select order_id from ticket where user_id='.$this->session->userdata("user_id").')')->result_array();
    +    
    +     return $this->render('Member/Dispute', $this->_data);
    +  }
    +  public function post_dispute(){
    +       
    +    if(empty($this->input->get('comment')) || empty($this->input->get('order_id')) ){
    +      $this->_data['status_'] = 'error'; 
    +      $this->_data['status_msg'] = 'Fill Required Fields'; 
    +    }else{    
    +
    +      $already_disputed = $this->db->select('*')->from('ticket')->where('order_id',intval($this->input->get('order_id')))->get()->row_array();
    +      if(empty( $already_disputed )){
    +        
    +        $this->db->insert('ticket',[
    +          'message'=>$this->input->get('comment'),
    +          'user_id'=>$this->session->userdata('user_id'),         
    +          'order_id'=>intval($this->input->get('order_id')),
    +          'status'=>0,
    +          'receive_status'=>0,
    +          'created_at'=>date('Y-m-d h:i:s')
    +        ]);
    +          
    +        $this->load->model('email_model');
    +        $this->load->library('mail_service');
    +        $this->mail_service->set_adapter('smtp');
    +
    +        $user_data = $this->db->select('u.*,c.email')->from('user u')->join('credential c','c.user_id=u.id')->where('u.id',$this->session->userdata('user_id'))->get()->row_array();
    +
    +
    +
    +        $from_email = $this->config->item('from_email');
    +        $domain = explode("@", $from_email)[1];
    +
    +        $template = $this->email_model->get_template('dispute_added', [ 
    +          'email' => $user_data['email'],         
    +          'order_id' =>$this->input->get('order_id'),         
    +        ]);
    +        
    +        $this->mail_service->send( $from_email,$from_email, $template->subject, $template->html);
    +
    +        $this->_data['status_'] = 'success'; 
    +        $this->_data['status_msg'] = 'Dispute Submitted Successfully.';       
    +      }
    +        $this->_data['orders'] = $this->db->query('select * from `order` o where o.id not in (select order_id from ticket where user_id='.$this->session->userdata("user_id").')')->result_array();
    +    
    +
    +      
    +    }
    +    
    +    return $this->render('Member/Dispute', $this->_data);
    +  }
    +  public function review($invetory_id,$order_id){
    +
    +    return $this->render('Member/Review', $this->_data);
    +  }
    +  public function post_review($invetory_id,$order_id){
    +       
    +    if(empty($this->input->get('comment')) || empty($this->input->get('review')) || empty($this->input->get('inventory_id')) ){
    +      $this->_data['status_'] = 'error'; 
    +      $this->_data['status_msg'] = 'Fill Required Fields'; 
    +    }else{    
    +
    +      if($this->db->select('*')->from('review')->where('user_id',$this->session->userdata('user_id'))->where( 'inventory_id',intval($this->input->get('inventory_id')))->get()->result_array()){
    +        $this->_data['status_'] = 'error'; 
    +        $this->_data['status_msg'] = 'Can not give Review again for same Paper'; 
    +      }else{
    +
    +        $this->db->insert('review',[
    +          'comment'=>$this->input->get('comment'),
    +          'user_id'=>$this->session->userdata('user_id'),
    +          'rating'=>intval($this->input->get('review')),
    +          'inventory_id'=>intval($this->input->get('inventory_id')),
    +          'order_id'=>intval($order_id),
    +          'status'=>1,
    +          'created_at'=>date('Y-m-d h:i:s')
    +        ]);
    +  
    +        $this->_data['status_'] = 'success'; 
    +        $this->_data['status_msg'] = 'Review Submitted Successfully.';       
    +      }
    +
    +      
    +    }
    +    
    +    return $this->render('Member/Review', $this->_data);
    +  }
    +
    +  public function setting(){
    +
    +    $this->_data['paypal_email'] = $this->db->select('paypal_email')->from('user')->where('id',$this->session->userdata('user_id'))->get()->row_array();
    +    return $this->render('Member/Setting', $this->_data);
    +  }
    +  public function post_setting(){
    +    $regex = '/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/'; 
    +        
    +    if(empty($this->input->get('email')) ){
    +      $this->_data['status_'] = 'error'; 
    +      $this->_data['status_msg'] = 'Enter Email'; 
    +    }else{
    +
    +      if(!preg_match($regex, $this->input->get('email'))){
    +            $this->_data['status_'] = 'error'; 
    +          $this->_data['status_msg'] = 'Invalid Email'; 
    +      }else{
    +
    +        $this->db->set('paypal_email',$this->input->get('email'))
    +        ->where('id',$this->session->userdata('user_id'))->update('user');
    +
    +        $this->_data['status_'] = 'success'; 
    +        $this->_data['status_msg'] = 'Email updated submitted successfully.'; 
    +      }
    +      
    +    }
    +    $this->_data['paypal_email'] = $this->db->select('paypal_email')->from('user')->where('id',$this->session->userdata('user_id'))->get()->row_array();
    +    return $this->render('Member/Setting', $this->_data);
    +  }
    +
    +  public function delete()
    +  {
    +    $id = $this->input->post('id');
    +    $model = $this->inventory_model->get($id);
    +
    +
    +    if (!empty($id))
    +    {
    +      $result = $this->inventory_model->real_delete($id);
    +
    +      if ($result)
    +      {
    +        $output['success'] = TRUE;
    +        $output['status']  = 200;
    +        $output['msg']     = 'Notes deleted successfully.';
    +        echo json_encode($output);
    +        exit();
    +      }
    +      else
    +      {
    +        $output['error']  = TRUE;
    +        $output['status'] = 0;
    +        $output['msg']    = 'Error! Please try again later.';
    +        echo json_encode($output);
    +        exit();
    +      }
    +    }
    +    else
    +    {
    +      $output['error']  = TRUE;
    +      $output['status'] = 0;
    +      $output['msg']    = 'Error! Data not found.';
    +      echo json_encode($output);
    +      exit();
    +    }
    +  }
    +
    +    public function add_suggestion()
    +    {
    +        $this->load->model('suggestion_model');
    +
    +        $this->form_validation = $this->suggestion_model->set_form_validation(
    +        $this->form_validation, $this->suggestion_model->get_all_validation_rule()); 
    +        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
    +
    +        $name             = $this->input->post('name', TRUE);
    +        $email            = $this->input->post('email', TRUE);
    +        $suggestion_type  = $this->input->post('suggestion_type', TRUE);
    +        $suggestion_name  = $this->input->post('suggestion_name', TRUE);
    +        $additional_notes = $this->input->post('additional_notes', TRUE);
    +
    +        $payload_1 = [
    +            'name'             => $name,
    +            'email'            => $email,
    +            'suggestion_type'  => $suggestion_type,
    +            'suggestion_name'  => $suggestion_name,
    +            'additional_notes' => $additional_notes
    +        ];
    +
    +        $this->db->trans_begin();
    +        $result_1 = $this->suggestion_model->create($payload_1);
    +
    +        if ($result_1)
    +        {
    +            $this->db->trans_commit();
    +                $res = [
    +                'success' => TRUE,
    +                'status'  => 200,
    +                'msg'     => 'Success! Suggestion Added.'
    +            ];
    +
    +            $type_name = "";
    +            if ($suggestion_type == 1) 
    +            {
    +                $type_name = "School";
    +            }else if ($suggestion_type == 2) 
    +            {
    +                $type_name = "Professor";
    +            }else if ($suggestion_type == 3) 
    +            {
    +                $type_name = "Textbook";
    +            }else if ($suggestion_type == 4) 
    +            {
    +                $type_name = "Course";
    +            }
    +
    +            $this->load->model('email_model');
    +            $this->load->library('mail_service');
    +            $this->mail_service->set_adapter('smtp');
    +            $from_email = $this->config->item('from_email');
    +
    +            $message = "A new suggestion has been recieved.
    "; + $message .= "Name :- " . $name . "
    "; + $message .= "Email :- " . $email . "
    "; + $message .= "Suggestion Type :- " . $type_name . "
    "; + $message .= "Suggestion Name :- " . $suggestion_name . "
    "; + $message .= "Additional Note :- " . $additional_notes . "
    "; + $this->mail_service->send($from_email, $from_email, "New Suggestion", $message); + + + echo json_encode($res); + exit; + } + else + { + $this->db->trans_rollback(); + $res = [ + 'error' => TRUE, + 'status' => 0, + 'msg' => 'Error! Suggestion add failed.' + ]; + echo json_encode($res); + exit; + } + } + + // public function purchasec(){ + // // for demo + // if($this->session->userdata('user_id') && is_numeric($this->input->post('id')) ){ + + // $this->load->model('email_model'); + // $this->load->library('mail_service'); + // $this->mail_service->set_adapter('smtp'); + + + // $user_data = $this->db->select('u.*,c.email')->from('user u')->join('credential c','c.user_id=u.id')->where('u.id',$this->session->userdata('user_id'))->get()->row_array(); + // $output = []; + + + // $invetory_data = $this->db->select('i.*,p.name as professor,c.name as class')->from('inventory i ') + // ->join('professor p','p.id=i.professor_id') + // ->join('classes c','c.id=i.class_id') + // ->where('i.id',$this->input->post('id'))->get()->row_array(); + + // $insert = [ + // 'purchase_user_id'=>$user_data['id'], + // 'sale_user_id'=>$invetory_data['user_id'], + // 'inventory_id'=>$invetory_data['id'], + // 'order_date'=>date('Y-m-d'), + // 'order_time'=>date('h:i:s'), + // 'subtotal'=>50, + // 'tax'=>0, + // 'discount'=>0, + // 'total'=>50, + // 'stripe_charge_id'=>'Test11', + // 'stripe_intent'=>json_encode(['test'=>1]), + // 'status'=>1, + // 'created_at'=>date('Y-m-d'), + // 'updated_at'=>date('Y-m-d'), + // ]; + + // $this->db->insert('order',$insert); + + + // //send email + + // $from_email = $this->config->item('from_email'); + // $domain = explode("@", $from_email)[1]; + + // $template = $this->email_model->get_template('give_review', [ + // 'email' => $user_data['email'] + // ]); + + // $this->mail_service->send('admin@' . $domain , $from_email , $template->subject, $template->html); + + + // $output['status'] = true; + // $output['file_source'] = base_url().$invetory_data['file']; + // $output['file_name'] = $invetory_data['professor'].'.'.$invetory_data['class'].'.'.$invetory_data['year']; + // $output['extension'] = explode('.',$invetory_data['file'])[1]; + // echo json_encode($output); + // exit(); + + + // }else{ + // $output['status'] = false; + // echo json_encode($output); + // exit(); + // } + // } + + + + + public function purchase() + { + + if( $this->session->userdata('user_id') && $this->input->post('id') ) + { + $this->form_validation->set_rules('card_name', 'Card Name', 'required'); + $this->form_validation->set_rules('card_number', 'Card Number', 'required'); + $this->form_validation->set_rules('exp_month', 'Card Expiry Month', 'required'); + $this->form_validation->set_rules('exp_year', 'Card Expiry Year', 'required'); + $this->form_validation->set_rules('card_cvc', 'Card CVC', 'required'); + + + + if ($this->form_validation->run() === FALSE) + { + $error_msg = validation_errors(); + $output['error_msg'] = $error_msg; + echo json_encode($output); + exit(); + } + + try + { + $card_number = $this->input->post('card_number', TRUE); + $card_cvc = $this->input->post('card_cvc', TRUE); + $card_name = $this->input->post('card_name', TRUE); + $exp_year = $this->input->post('exp_year', TRUE); + $exp_month = $this->input->post('exp_month', TRUE); + + + $this->load->model('email_model'); + $this->load->library('mail_service'); + $this->mail_service->set_adapter('smtp'); + + //create setup intent used in js + Stripe::setApiKey($this->config->item('stripe_secret_key')); + + $user_data = $this->db->select('u.*,c.email')->from('user u')->join('credential c','c.user_id=u.id')->where('u.id',$this->session->userdata('user_id'))->get()->row_array(); + + + + + if( empty($user_data['stripe_id']) ) + { + + $obj = Customer::create([ + 'customer' => [ + 'email' => $user_data['email'], + ], + ]); + + // $obj = $stripe->customers->create([ + // 'email' => $user_data['email'], + // 'payment_method' => $this->input->post('key'), + // ]); + + $this->db->set('stripe_id',$obj->id); + $this->db->where('id', $user_data['id']); + $this->db->update('user'); + $user_data['stripe_id'] = $obj->id; + } + + + $token = Token::create([ + 'card' => [ + 'number' => $card_number, + 'exp_month' => $exp_month, + 'exp_year' => $exp_year, + 'cvc' => $card_cvc, + ], + ]); + + + $stripe_token_id = $token->id; + $stripe_customer_id = $user_data['stripe_id']; + // assign card to the user (not default) + $card_data = Customer::createSource( + $stripe_customer_id, + [ + 'source' => $stripe_token_id, + ] + ); + + + + + + // // add payment method + // $card_response = $stripe->paymentMethods->attach( + // $this->input->post('key'), + // ['customer' => $user_data['stripe_id']] + // ); + + + // $payment_method_id = ''; + + // if($card_response) + // { + // $payment_method_id = $card_response->id; + // } + + // if($payment_method_id=='') + // { + + // $data = $stripe->paymentMethods->all([ + // 'customer' => $user_data['stripe_id'], + // 'type' => 'card', + // ]); + + // foreach ($data->data as $key => $value) + // { + // $payment_method_id = $value->id; + // } + // } + + //notes amount + $notes_amount = $this->db->select('value')->from('setting')->where('key','fixed_paper_amount')->get()->row_array(); + if( $notes_amount) + { + $notes_amount = $notes_amount['value']; + }else{ + $notes_amount = 50; + } + + //sales percent + $sale_percent = $this->db->select('value')->from('setting')->where('key','payout_percentage_seller')->get()->row_array(); + if( $sale_percent) + { + $sale_percent = $sale_percent['value']; + }else{ + $sale_percent = 20; + } + + + // $payment_intent = $stripe->paymentIntents->create([ + // 'amount' => $notes_amount*100, + // 'currency' => 'usd', + // 'confirm' => true, + // 'payment_method' => $payment_method_id, + // 'payment_method_types' => ['card'], + // 'customer' => $user_data['stripe_id'], + // 'capture_method' => 'manual', + // 'description' => 'Buying Papers From Outline Gurus', + // ]); + + // $result = $stripe->paymentIntents->capture($payment_intent->id ); + + $amount = str_replace(",", "", $notes_amount); + + $price_total = 0; + $price_total = $amount * 100; + $stripe_customer_id = $user_data['stripe_id']; + $stripe_card_id = $card_data->id; + + $result = Charge::create(array( + "amount" => $price_total, + "currency" => "usd", + "customer" => $stripe_customer_id, + "receipt_email" => $this->session->userdata('email'), + "source" => $stripe_card_id, + "description" => 'Buying Papers From OutlineGurus', + )); + + + + $invetory_data = $this->db->select('i.*,p.name as professor,c.name as class')->from('inventory i ') + ->join('professor p','p.id=i.professor_id') + ->join('classes c','c.id=i.class_id') + ->where('i.id',$this->input->post('id'))->get()->row_array(); + + $insert = [ + 'purchase_user_id' => $user_data['id'], + 'sale_user_id' => $invetory_data['user_id'], + 'inventory_id' => $invetory_data['id'], + 'order_date' => date('Y-m-d'), + 'order_time' => date('h:i:s'), + 'subtotal' => $notes_amount, + 'tax' => 0, + 'discount' => 0, + 'total' => $notes_amount, + 'stripe_charge_id' => $result->id, + 'stripe_intent' => json_encode($result), + 'status' => 1, + 'created_at' => date('Y-m-d'), + 'updated_at' => date('Y-m-d'), + ]; + + $this->db->insert('order',$insert); + $order_id = $this->db->insert_id(); + + + //payout table + $insert = [ + 'user_id' => $invetory_data['user_id'], + 'order_id' => $order_id, + 'inventory_id' => $invetory_data['id'], + 'created_at' => date('Y-m-d'), + 'amount' => ($sale_percent*$notes_amount)/100, + 'payout_date' => null, + 'status' => 0,//unpaid + ]; + + $this->db->insert('payout',$insert); + + + $logo = base_url('assets/frontend/img/logo.png'); + + //send email + + $from_email = $this->config->item('from_email'); + $domain = explode("@", $from_email)[1]; + + $template = $this->email_model->get_template('give_review', [ + 'email' => $user_data['first_name'] . " " . $user_data['last_name'], + 'link' => '
    Click here to leave review ', + ]); + + + + + $html = $template->html; + $html .= "
    Thanks,"; + $html .= "

    The OutlineGurus Team"; + $html .= "
    "; + + $email_to_user = $this->mail_service->send( $from_email,$user_data['email'], $template->subject, $html); + + + + + + + $invetory_data2 = $this->inventory_model->get($this->input->post('id')); + $sale_user_data = $this->user_model->get($invetory_data2->user_id); + $email_data = $this->credential_model->get_by_fields(['user_id' => $invetory_data2->user_id]); + + + //send email to uploader + $template = $this->email_model->get_template('outline_downloaded', [ + 'name' => $sale_user_data->first_name . " " . $sale_user_data->last_name, + 'logo' => $logo, + ]); + $send = $this->mail_service->send( $from_email, $email_data->email, $template->subject, $template->html); + + + $output['status'] = true; + $output['file_name'] = $invetory_data['professor'].'.'.$invetory_data['class'].'.'.$invetory_data['year']; + $output['file_source'] = $invetory_data['file']; + $output['extension'] = explode('.',$invetory_data['file'])[1]; + echo json_encode($output); + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + echo json_encode($output); + exit(); + + } + catch (\Stripe\Exception\RateLimitException $e) + { + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + echo json_encode($output); + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + echo json_encode($output); + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + echo json_encode($output); + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->message(); + echo json_encode($output); + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + echo json_encode($output); + exit(); + } + catch (Exception $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + echo json_encode($output); + exit(); + } + + } + else + { + $output['status'] = false; + echo json_encode($output); + exit(); + } + } + + + protected function pay_using_stripe($amount, $stripe_customer_id, $stripe_card_id) + { + + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + Stripe::setApiKey( $stripe_secret_key ); + + $get_user_data = $this->_customer_model->get($user_id); + $get_user_card_data = $this->_customer_cards_model->get($user_card_id); + $stripe_customer_id = $get_user_data->stripe_id; + $stripe_card_id = $get_user_card_data->card_token; + + if($stripe_customer_id && $amount) + { + $amount = str_replace(",", "", $amount); + + $price_total = 0; + $price_total = $amount * 100; + $stripe_customer_id = $stripe_customer_id; + + + try + { + $charge = Charge::create(array( + "amount" => $price_total, + "currency" => "usd", + "customer" => $stripe_customer_id, + "source" => $stripe_card_id, + "description" => $description + )); + + + $output['success'] = true; + $output['response'] = $charge; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + + } + catch (\Stripe\Exception\RateLimitException $e) + { + + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = true; + $output['error_msg'] = "Error! Token and Amount is required."; + return $output; + exit(); + } + + } + + + + + + + + + + + public function test_docx() + { + $file = "uploads/test_doc_4.docx"; + $uri = __DIR__ . "/../../../" . $file; + + //phpinfo(); + //die(); + + $preview_files = []; + try + { + $FilePathPdf = "uploads/" . uniqid() . "pdf-file.pdf"; + $rendererLibraryPath = __DIR__ . "/../../../vendor/dompdf/dompdf"; + $rendererName = \PhpOffice\PhpWord\Settings::PDF_RENDERER_DOMPDF; + \PhpOffice\PhpWord\Settings::setPdfRenderer($rendererName, $rendererLibraryPath); + \PhpOffice\PhpWord\Settings::setPdfRendererPath($rendererLibraryPath); + + + $phpWord = \PhpOffice\PhpWord\IOFactory::load($uri); + $pdfWriter = \PhpOffice\PhpWord\IOFactory::createWriter( $phpWord, 'PDF' ); + $pdfWriter->save($FilePathPdf); + + $document = __DIR__ . "/../../../" . $FilePathPdf; + $im = new imagick($document); + + $u_id = uniqid(); + if ($im) + { + $im->setIteratorIndex(0); + $im->setResolution(600, 600); + $im->setImageFormat('png'); + $im->setImageCompression(imagick::COMPRESSION_ZIP); + $im->setImageCompressionQuality(100); + $im->setCompressionQuality(100); + + + $uid = __DIR__ . "/../../../uploads/"; + + $im->writeImage($uid . $u_id . "-ttt.png"); + $preview_files[0] = 'uploads/' . $u_id . '-ttt.png'; + + $im->clear(); + $im->destroy(); + } + + + $im2 = new imagick($document); + + if ($im2) + { + $im2->setIteratorIndex(1); + $im2->setResolution(600, 600); + $im2->setImageFormat('png'); + $im2->setImageCompression(imagick::COMPRESSION_ZIP); + $im2->setImageCompressionQuality(100); + $im2->setCompressionQuality(100); + + $uid = __DIR__ . "/../../../uploads/"; + + $im2->writeImage($uid . $u_id . "-ttt2.png"); + $preview_files[1] = 'uploads/' . $u_id . '-ttt2.png'; + + $im2->clear(); + $im2->destroy(); + } + + + $im3 = new imagick($document); + + if ($im3) + { + $im3->setResolution(600, 600); + $im3->setImageFormat('png'); + $im3->setImageCompression(imagick::COMPRESSION_ZIP); + $im3->setImageCompressionQuality(100); + $im3->setCompressionQuality(100); + + + $uid = __DIR__ . "/../../../uploads/"; + + $im3->writeImage($uid . $u_id . "-ttt3.png"); + $preview_files[2] = 'uploads/' . $u_id . '-ttt3.png'; + + $im3->clear(); + $im3->destroy(); + } + } + catch (\BadMethodCallException $e) + { + echo date('H:i:s'), ' error ...' . $e->getMessage(); + } + + + + echo "
    ";
    +        print_r($preview_files);
    +        print_r($im);
    +        die(); 
    +    }
    +  
    +}
    diff --git a/application/controllers/Member/Member_login_controller.php b/application/controllers/Member/Member_login_controller.php
    new file mode 100755
    index 0000000..771af18
    --- /dev/null
    +++ b/application/controllers/Member/Member_login_controller.php
    @@ -0,0 +1,145 @@
    +load->model('credential_model');
    +        $this->load->model('user_model');
    +        $this->load->helper('cookie');
    +
    +        $service = new User_service($this->credential_model, $this->user_model);
    +        if($this->input->cookie('member_remember_me_token', TRUE) !== null && $this->input->cookie('member_remember_me_token', TRUE) !== '')
    +        {
    +            $this->_remember_me_login();
    +            exit();
    +        }
    +        
    +        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
    +        $this->form_validation->set_rules('password', 'Password', 'required');
    +        $this->_data['portal'] = 'member';
    +        if ($this->form_validation->run() === FALSE)
    +        {
    +            echo $this->load->view('Member/Login', $this->_data, TRUE);
    +            exit;
    +        }
    +
    +        $email = $this->input->post('email');
    +        $password = $this->input->post('password');
    +        $redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
    +
    +        $role = $this->_valid_roles[0];
    +        $authenticated_user = $service->login_by_role($email, $password, $role);
    +
    +        if ($authenticated_user)
    +        {
    +            delete_cookie('redirect');
    +            $user_id = $authenticated_user->user_id;
    +
    +            if(!empty($this->input->post("remember_me"))) {
    +                $this->load->helper('string');
    +                $remember_cookie = [
    +                    'user_id' => $user_id,
    +                    'name' => 'member_remember_me_token',
    +                    'value' => random_string('alnum', 16),
    +                    'expire' => time()+$this->config->item('cookie_expire'),
    +                    'domain' => base_url()
    +                ];
    +                $this->load->model('cookies_model');
    +                $check_cookie = $this->cookies_model->get_by_field('user_id', $user_id);
    +                if($check_cookie)
    +                {
    +                    $cookie = $this->cookies_model->edit($remember_cookie, $check_cookie->id);
    +                }
    +                else
    +                {
    +                    $cookie = $this->cookies_model->create($remember_cookie);
    +                }
    +                if($cookie)
    +                {
    +                    setcookie($remember_cookie['name'], $remember_cookie['value'], $remember_cookie['expire'], $remember_cookie['domain']);
    +                }
    +            }
    +            $this->set_session('credential_id', (int) $authenticated_user->id);
    +            $this->set_session('user_id', (int) $user_id);
    +            $this->set_session('email', (string) $authenticated_user->email);
    +            $this->set_session('role', (string) $authenticated_user->role_id);
    +
    +            if( isset($_POST['return_url']) && $_POST['return_url'] =='buy')
    +            {
    +                return $this->redirect('buy'); 
    +            }
    +            return $this->redirect($redirect);
    +        }
    +
    +        $this->error('Wrong email or password.');
    +        return $this->redirect('member/login');
    +    }
    +
    +
    +    public function _remember_me_login()
    +    {
    +        $this->load->helper('string');
    +        $this->load->model('user_model');
    +        $this->load->model('credential_model');
    +        $this->load->model('cookies_model');
    +        $token_value = $this->input->cookie('member_remember_me_token', TRUE);
    +        $cookie = $this->cookies_model->get_by_fields(['value' => $token_value]);
    +        $service = new User_service($this->credential_model, $this->user_model);
    +        $redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
    +        if($cookie)
    +        {
    +            $user_id = $cookie->user_id;
    +            $credential = $this->credential_model->get_by_field('user_id', $user_id);
    +            $role = $this->_valid_roles[0];
    +            if($credential->role_id != $role)
    +            {
    +                setcookie('member_remember_me_token', '', 1, base_url());
    +                return $this->redirect('admin/login');
    +            }
    +            $random_string = random_string('alnum', 30);
    +            $this->cookies_model->edit(['value' => $random_string, 'expire' => time()+$this->config->item('cookie_expire')], $cookie->id);
    +            setcookie('member_remember_me_token', $random_string, time()+$this->config->item('cookie_expire'), base_url());
    +            $this->set_session('credential_id', (int) $credential->id);
    +            $this->set_session('user_id', (int) $user_id);
    +            $this->set_session('email', (string) $credential->email);
    +            $this->set_session('role', (string) $credential->role_id);
    +            return $this->redirect($redirect);
    +        }
    +        else
    +        {
    +            setcookie('member_remember_me_token', '', 1, base_url());
    +            return $this->redirect('admin/login');
    +        }
    +
    +        $this->error('Wrong email or password.');
    +        return $this->redirect('member/login');
    +    }
    +
    +    public function logout ()
    +    {
    +        $this->load->helper('cookie');
    +        setcookie('member_remember_me_token', '', 1, base_url());
    +        $this->destroy_session();
    +		return $this->redirect('member/login');
    +    }
    +}
    \ No newline at end of file
    diff --git a/application/controllers/Member/Member_me_controller.php b/application/controllers/Member/Member_me_controller.php
    new file mode 100755
    index 0000000..ca97c97
    --- /dev/null
    +++ b/application/controllers/Member/Member_me_controller.php
    @@ -0,0 +1,60 @@
    +get_session();
    +        $model = $this->credential_model->get($session['credential_id']);
    +        $this->_data['email'] = $model->email;
    +        $this->_data['password'] = '';
    +
    +        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
    +        $this->form_validation->set_rules('password', 'Password', '');
    +
    +		if ($this->form_validation->run() === FALSE)
    +		{
    +			return $this->render('Member/Mes', $this->_data);
    +        }
    +
    +        $email = $this->input->post('email');
    +		$password = $this->input->post('password');
    +
    +        $payload = [
    +            'email' => $email,
    +        ];
    +
    +        if (strlen($password) > 1)
    +        {
    +            $payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
    +        }
    +
    +        $result = $this->credential_model->edit($payload, $session['credential_id']);
    +
    +        if ($result)
    +        {
    +            $this->success('Saved');
    +            return $this->redirect('/member/me', 'refresh');
    +        }
    +
    +        $this->_data['error'] = 'Error';
    +        return $this->render('Member/Mes', $this->_data);
    +	}
    +}
    \ No newline at end of file
    diff --git a/application/controllers/Member/Member_profile_controller.php b/application/controllers/Member/Member_profile_controller.php
    new file mode 100755
    index 0000000..48fb7d9
    --- /dev/null
    +++ b/application/controllers/Member/Member_profile_controller.php
    @@ -0,0 +1,121 @@
    +load->model('credential_model'); 
    +    $this->load->model('member_profile_model');
    +    $this->load->model('school_model');
    +        $session = $this->get_session();
    +        $model = $this->user_model->get($session['user_id']);
    +        $id = $session['user_id'];
    +
    +             // load data
    +    $schools    = $this->school_model->get_all();
    +
    +    
    +    if (!empty($schools))
    +    {
    +      $this->_data['schools'] = $schools;
    +    }
    +
    +		if (!$model)
    +		{
    +			$this->error('Error');
    +			return redirect('/member/dashboard');
    +        }
    +
    +        $credential = $this->credential_model->get($session['credential_id']);
    +        $email_validation_rules = 'required|valid_email';
    +
    +        include_once __DIR__ . '/../../view_models/Member_profile_view_model.php';
    +
    +        if ($this->input->post('email') != $credential->email)
    +		{
    +			$email_validation_rules .= '|is_unique[credential.email]';
    +		}
    +
    +      $member_profile_data = $this->db->select('*')->from('member_profile')->where('user_id',$id)->get()->row_array();
    +      $user_data = $this->db->select('*')->from('user')->where('id',$id)->get()->row_array();
    +
    +    $this->_data['phone']  = $user_data['phone'];
    +    $this->_data['username']  = $member_profile_data['username'];
    +    $this->_data['school_id'] = $member_profile_data['school_id'];
    +
    +		$this->form_validation->set_rules('email', 'Email', $email_validation_rules);
    +		$this->form_validation->set_rules('first_name', 'First Name', 'required');
    +        $this->form_validation->set_rules('last_name', 'Last Name', 'required');
    +
    +        $this->_data['view_model'] = new Member_profile_view_model($this->user_model);
    +        $this->_data['view_model']->set_model($model);
    +        $this->_data['view_model']->set_email($credential->email);
    +        $this->_data['view_model']->set_heading('Member');
    +
    +		if ($this->form_validation->run() === FALSE)
    +		{
    +			return $this->render('Member/Profile', $this->_data);
    +        }
    +
    +    
    +
    +		$first_name = $this->input->post('first_name');
    +		$last_name = $this->input->post('last_name');
    +		$email = $this->input->post('email');
    +        $password = $this->input->post('password');
    +
    +      // $username = $this->input->post('username');
    +      $school_id = $this->input->post('school_id');
    +
    +        $payload = [
    +			'first_name' => $first_name,
    +			'last_name' => $last_name
    +        ];
    +        
    +    $payload_2 = [
    +      // 'username'  => $username,
    +      'school_id' => $school_id
    +    ];
    +
    +        $result = $this->user_model->edit_raw($payload, $id);
    +
    +        if ($result)
    +        {
    +          $this->db->set($payload_2)->where('id',$member_profile_data['id'])->update('member_profile');
    +          $this->db->set(['phone'=>$this->input->post('phone')])->where('id',$id)->update('user');
    +            $credential_payload = [
    +                'email' => $email
    +            ];
    +
    +            if (strlen($password) > 0)
    +            {
    +                $credential_payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
    +            }
    +
    +            $result = $this->credential_model->edit_raw($credential_payload, $session['credential_id']);
    +            $this->success('Saved');
    +            return $this->redirect('/member/profile', 'refresh');
    +        }
    +
    +        $this->_data['error'] = 'Error';
    +        return $this->render('Member/Profile', $this->_data);
    +    }
    +}
    diff --git a/application/controllers/Member/Member_profile_credential_controller.php b/application/controllers/Member/Member_profile_credential_controller.php
    new file mode 100755
    index 0000000..661937f
    --- /dev/null
    +++ b/application/controllers/Member/Member_profile_credential_controller.php
    @@ -0,0 +1,79 @@
    +load->model('user_model');
    +        $session = $this->get_session();
    +        $user_obj = $this->user_model->get($session['user_id']);
    +        $session = $this->get_session();
    +        $this->load->model($this->_model_file);
    +        $model = $this->credential_model->get($user_obj->credential_id ?? 0);
    +        $id = $user_obj->credential_id ?? 0;
    +
    +		if (!$model)
    +		{
    +			die();
    +        }
    +
    +        include_once __DIR__ . '/../../view_models/Member_profile_credential_view_model.php';
    +        $email_validation_rules = 'required|valid_email';
    +        
    +        if ($this->input->post('email') != $session['email'])
    +		{
    +			$email_validation_rules .= '|is_unique[credential.email]';
    +		}
    +
    +		$this->form_validation->set_rules('email', 'Email', $email_validation_rules);
    +
    +        $this->_data['view_model'] = new Member_profile_credential_view_model($model);
    +        $this->_data['view_model']->set_model($model);
    +        $this->_data['view_model']->set_heading('Member');
    +
    +		if ($this->form_validation->run() === FALSE)
    +		{
    +            return $this->render('Member/Credential', $this->_data);
    +        }
    +
    +        $email = $this->input->post('email');
    +        $password = $this->input->post('password');
    +
    +        $payload = [
    +            'email' => $email,
    +        ];
    +
    +        if (strlen($password) > 0)
    +        {
    +            $payload['password'] = str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT));
    +        }
    +
    +        $result = $this->credential_model->edit_raw($payload, $id);
    +
    +        if ($result)
    +        {
    +            $this->success('Saved');
    +            return $this->redirect('/member/credential?layout_clean_mode=1', 'refresh');
    +        }
    +
    +        $this->_data['error'] = 'Error';
    +        return $this->render('Member/Credential', $this->_data);
    +	}
    +}
    \ No newline at end of file
    diff --git a/application/controllers/Member/Member_purchases_controller.php b/application/controllers/Member/Member_purchases_controller.php
    new file mode 100755
    index 0000000..b37324d
    --- /dev/null
    +++ b/application/controllers/Member/Member_purchases_controller.php
    @@ -0,0 +1,277 @@
    +load->model('school_model');
    +        $this->load->model('professor_model');
    +        $this->load->model('classes_model');
    +        $this->load->model('textbook_model');
    +    
    +        $this->load->model('inventory_model');
    +    
    +        $this->load->library('helpers_service');
    +        $this->load->library('names_helper_service');
    +        
    +    }
    +
    +    
    +
    +        public function index($page)
    +    {
    +
    +    // load data
    +    $schools    = $this->school_model->get_all(['status' => 1]);
    +    $professors = $this->professor_model->get_all(['status' => 1]);
    +    
    +    if (!empty($schools))
    +    {
    +      $this->_data['schools'] = $schools;
    +    }
    +
    +    if (!empty($professors))
    +    {
    +      $this->_data['professors'] = $professors;
    +    }
    +
    +   
    +
    +        $this->load->library('pagination');
    +        include_once __DIR__ . '/../../view_models/Purchases_member_list_paginate_view_model.php';
    +        $session = $this->get_session();
    +        $format = $this->input->get('format', TRUE) ?? 'view';
    +        $order_by = $this->input->get('order_by', TRUE) ?? '';
    +        $direction = $this->input->get('direction', TRUE) ?? 'ASC';
    +        $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
    +
    +        $this->_data['view_model'] = new Purchases_member_list_paginate_view_model(
    +            $this->order_model,
    +            $this->pagination,
    +            '/member/purchases/0');
    +        $this->_data['view_model']->set_heading('Purchases');
    +        $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
    +        $this->_data['view_model']->set_purchase_user_id(($this->input->get('purchase_user_id', TRUE) != NULL) ? $this->input->get('purchase_user_id', TRUE) : NULL);
    +        $this->_data['view_model']->set_sale_user_id(($this->input->get('sale_user_id', TRUE) != NULL) ? $this->input->get('sale_user_id', TRUE) : NULL);
    +        $this->_data['view_model']->set_inventory_id(($this->input->get('inventory_id', TRUE) != NULL) ? $this->input->get('inventory_id', TRUE) : NULL);
    +        $this->_data['view_model']->set_order_date(($this->input->get('order_date', TRUE) != NULL) ? $this->input->get('order_date', TRUE) : NULL);
    +        $this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
    +        
    +    $where = ['purchase_user_id' => $this->session->userdata('user_id')];
    +
    +    if (!empty($_GET['school_id']))
    +    {  
    +      $inventory = $this->inventory_model->get_all(['school_id' => $_GET['school_id']]);
    +      
    +      if ($inventory)
    +      {
    +        $where[] = "inventory_id in (" . implode(',',array_column($inventory,'id')) . " ) ";
    +      }
    +      else
    +      {
    +        $where[] = "inventory_id = 0";
    +      }
    +    }
    +
    +    if (!empty($_GET['professor_id']))
    +    {
    +      $inventory = $this->inventory_model->get_all(['professor_id' => $_GET['professor_id']]);     
    +      if ($inventory)
    +      {
    +        $where[] = "inventory_id in (" . implode(',',array_column($inventory,'id')) . " ) ";
    +      }
    +      else
    +      {
    +        $where[] = "inventory_id = 0";
    +      }
    +     
    +    }
    +    if (!empty($_GET['year']))
    +    {
    +      $inventory = $this->inventory_model->get_all(['year' => $_GET['year']]);     
    +      if ($inventory)
    +      {
    +        $where[] = "inventory_id in (" . implode(',',array_column($inventory,'id')) . " ) ";
    +      }
    +      else
    +      {
    +        $where[] = "inventory_id = 0";
    +      }
    +     
    +    }
    +
    +    if ($this->_data['view_model']->get_id())
    +    {
    +      $where[] = "id = " . $this->_data['view_model']->get_id();
    +    }
    +
    +    if ($this->_data['view_model']->get_inventory_id())
    +    {
    +      $where[] = "inventory_id = " . $this->_data['view_model']->get_inventory_id();
    +    }
    +
    +    if ($this->_data['view_model']->get_order_date())
    +    {
    +      $where[] = "order_date = " . $this->_data['view_model']->get_order_date();
    +    }
    +
    +    if ($this->_data['view_model']->get_status() || $this->_data['view_model']->get_status() == '0')
    +    {
    +      $where[] = "status = " . $this->_data['view_model']->get_status();
    +    }
    +
    +      //   $where = [
    +      //       'id' => $this->_data['view_model']->get_id(),
    +            // 'purchase_user_id' => $this->_data['view_model']->get_purchase_user_id(),
    +            // 'sale_user_id' => $this->_data['view_model']->get_sale_user_id(),
    +            // 'inventory_id' => $this->_data['view_model']->get_inventory_id(),
    +            // 'order_date' => $this->_data['view_model']->get_order_date(),
    +            // 'status' => $this->_data['view_model']->get_status(),
    +            
    +            
    +      //   ];
    +
    +        $this->_data['view_model']->set_total_rows($this->order_model->count($where));
    +
    +        $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
    +        $this->_data['view_model']->set_per_page($per_page_sort);
    +        $this->_data['view_model']->set_order_by($order_by);
    +        $this->_data['view_model']->set_sort($direction);
    +        $this->_data['view_model']->set_sort_base_url('/member/purchases/0');
    +        $this->_data['view_model']->set_page($page);
    +            $this->_data['view_model']->set_list($this->order_model->get_paginated(
    +            $this->_data['view_model']->get_page(),
    +            $this->_data['view_model']->get_per_page(),
    +            $where,
    +            $order_by,
    +            $direction));
    +        
    +        if( $this->_data['view_model']->get_list())
    +        {
    +
    +            $invetory_ids = array_column($this->_data['view_model']->get_list(),'inventory_id');
    +            if($invetory_ids)
    +            {
    +                $inventory_data  = $this->db->select('i.*,s.name as school,p.name as professor')->from('inventory i')->join('school s','s.id=i.school_id')->join('professor p','p.id=i.professor_id')->where_in('i.id',$invetory_ids,true)->get()->result_array();
    +                
    +                $review_given = $this->db->select('*')->from('review')->where('user_id',$this->session->userdata('user_id'))->get()->result_array();
    +                if($review_given)
    +                {
    +                    $review_given = array_column($review_given,'inventory_id');
    +                }
    +            
    +                $dispute_given = $this->db->select('*')->from('ticket')->where('user_id',$this->session->userdata('user_id'))->get()->result_array();
    +                if($dispute_given){
    +                    $dispute_given = array_column($dispute_given,'order_id');
    +                }
    +                foreach ($this->_data['view_model']->get_list() as $data) 
    +                {
    +
    +                    $data->review_given = 0;
    +                    if(in_array($data->inventory_id,$review_given))
    +                    {
    +                        $data->review_given = 1;
    +                    }
    +                    $data->dispute_given = 0;
    +                    if(in_array($data->id,$dispute_given))
    +                    {
    +                        $data->dispute_given = 1;
    +                    }
    +
    +
    +                    foreach ($inventory_data as $key => $value) 
    +                    {
    +                        if($data->inventory_id == $value['id'])
    +                        {
    +                            $data->school     = $value['school'];
    +                            $data->year       = $value['year'];
    +                            $data->file_src   = base_url().$value['file'];
    +                            $data->professor  = $value['professor'];
    +                            $data->word_count = $value['word_count'];
    +                        } 
    +                    } 
    +
    +                    if (!isset($data->school)) 
    +                    {
    +                        $data->school     = "";
    +                        $data->year       = "";
    +                        $data->file_src   = "";
    +                        $data->professor  = "";
    +                        $data->word_count = ""; 
    +                    }
    +                } 
    +            } 
    +        }
    +        
    +
    +        if ($format == 'csv')
    +        {
    +            header('Content-Type: text/csv');
    +            header('Content-Disposition: attachment; filename="export.csv"');
    +
    +            echo $this->_data['view_model']->to_csv();
    +            exit();
    +        }
    +
    +        if ($format != 'view')
    +        {
    +            return $this->output->set_content_type('application/json')
    +                ->set_status_header(200)
    +                ->set_output(json_encode($this->_data['view_model']->to_json()));
    +        }
    +
    +        return $this->render('Member/Purchases', $this->_data);
    +    }
    +
    +    
    +
    +    
    +
    +        public function view($id)
    +    {
    +        $model = $this->order_model->get($id);
    +
    +        if (!$model)
    +        {
    +            $this->error('Error');
    +            return redirect('/member/purchases/0');
    +        }
    +
    +
    +        include_once __DIR__ . '/../../view_models/Purchases_member_view_view_model.php';
    +        $this->_data['view_model'] = new Purchases_member_view_view_model($this->order_model);
    +        $this->_data['view_model']->set_heading('Purchases');
    +        $this->_data['view_model']->set_model($model);
    +        
    +        
    +        return $this->render('Member/PurchasesView', $this->_data);
    +    }
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +}
    \ No newline at end of file
    diff --git a/application/controllers/Member/Member_register_controller.php b/application/controllers/Member/Member_register_controller.php
    new file mode 100755
    index 0000000..8c965d2
    --- /dev/null
    +++ b/application/controllers/Member/Member_register_controller.php
    @@ -0,0 +1,106 @@
    +_run_middlewares();
    +  }
    +
    +  protected function _middleware()
    +  {
    +    return [
    +      'affilate',
    +      'maintenance'
    +    ];
    +  }
    +
    +  public function index()
    +  {
    +    $this->load->model('user_model');
    +    $this->load->model('refer_log_model');
    +    $this->load->helper('cookie');
    +    $this->load->model('credential_model');
    +    $this->load->model('member_profile_model');
    +
    +    $service = new User_service($this->credential_model, $this->user_model, $this->member_profile_model);
    +    $service->set_refer_log_model($this->refer_log_model);
    +
    +    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[credential.email]');
    +    $this->form_validation->set_rules('password', 'Password', 'trim|required');
    +    $this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|matches[password]');
    +    $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
    +    $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
    +
    +    // $this->form_validation->set_rules('username', 'Username', 'trim|required|is_unique[member_profile.username]');
    +
    +    if ($this->form_validation->run() === FALSE)
    +    {
    +      echo $this->load->view('Member/Register', $this->_data, TRUE);
    +      exit;
    +    }
    +    
    +
    +    $email      = $this->input->post('email');
    +    $password   = $this->input->post('password');
    +    $first_name = $this->input->post('first_name');
    +    $last_name  = $this->input->post('last_name');
    +    // $username   = $this->input->post('username');
    +    $username   = $first_name;
    +    // if($email == $username){
    +    //   $this->_data['error'] = 'Can not Use Email as Username';
    +    //   echo $this->load->view('Member/Register', $this->_data, TRUE);
    +    //   exit;
    +    // }
    +
    +
    +    $redirect = $service->get_redirect($this->input->cookie('redirect', TRUE), $this->_redirect);
    +    $session  = $this->get_session();
    +    $refer    = (isset($session['refer']) && strlen($session['refer']) > 0) ? $session['refer'] : '';
    +    
    +    $this->db->trans_begin();
    +
    +    $created_user = $service->create($email, $password, $first_name, $last_name, $username, 1, $refer);
    +
    +    if (!$created_user)
    +    {
    +      $this->db->trans_rollback();
    +      $this->_data['error'] = 'User creation failed. Please try again.';
    +      echo $this->load->view('Member/Register', $this->_data, TRUE);
    +      exit;
    +    }
    +
    +    delete_cookie('redirect');
    +    $credential = $this->credential_model->get_by_fields([
    +      'email' => $email,
    +      'type'  => 'n'
    +    ]);
    +
    +    $this->db->trans_commit();
    +
    +    $this->set_session('credential_id', (int) $credential->id);
    +    $this->set_session('user_id', (int) $created_user->id);
    +    $this->set_session('email', (string) $created_user->email);
    +    $this->set_session('role', (string) $created_user->role_id);
    +    if(isset($_POST['return_url'] ) && $_POST['return_url'] =='buy'){
    +      return $this->redirect('buy');
    +     
    +    }
    +    return $this->redirect($redirect);
    +  }
    +}
    diff --git a/application/controllers/Member/Member_reset_controller.php b/application/controllers/Member/Member_reset_controller.php
    new file mode 100755
    index 0000000..4198dd2
    --- /dev/null
    +++ b/application/controllers/Member/Member_reset_controller.php
    @@ -0,0 +1,61 @@
    +load->model('user_model');
    +        $this->load->model('token_model');
    +        $this->load->model('credential_model');
    +
    +        $service = new User_service($this->credential_model);
    +        $service->set_token_model($this->token_model);
    +
    +        $valid_user = $service->valid_reset_token($reset_token);
    +
    +        if (!$valid_user)
    +        {
    +            $this->error('Email does not exist in our system.');
    +            return $this->redirect('/member/login');
    +        }
    +
    +        $this->_data['reset_token'] = $reset_token;
    +
    +        $this->form_validation->set_rules('password', 'Password', 'trim|required');
    +        $this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|matches[password]');
    +
    +        if ($this->form_validation->run() === FALSE)
    +        {
    +            echo $this->load->view('Member/Reset', $this->_data, TRUE);
    +            exit;
    +        }
    +
    +        $password = $this->input->post('password');
    +        $password_reseted = $service->reset_password($valid_user->id, $password);
    +
    +        if ($password_reseted)
    +        {
    +            $service->invalidate_token($reset_token, $valid_user->id);
    +            $credential = $this->credential_model->get_by_field('user_id', $valid_user->id);
    +            $this->credential_model->edit(['verify' => '1'], $credential->id);
    +            $this->set_session('credential_id', (int) $credential->id);
    +            $this->set_session('user_id', (int) $credential->user_id);
    +            $this->set_session('email', (string) $credential->email);
    +            $this->set_session('role', (string) $credential->role_id);
    +            $this->success('Success! You can start using your account now.');
    +            return $this->redirect('/member/dashboard');
    +        }
    +
    +        $this->error('Invalid reset token to reset password.');
    +        return $this->redirect('/member/login');
    +	}
    +}
    \ No newline at end of file
    diff --git a/application/controllers/Member/Member_sales_controller.php b/application/controllers/Member/Member_sales_controller.php
    new file mode 100755
    index 0000000..8bfef97
    --- /dev/null
    +++ b/application/controllers/Member/Member_sales_controller.php
    @@ -0,0 +1,137 @@
    +load->library('pagination');
    +        include_once __DIR__ . '/../../view_models/Sales_member_list_paginate_view_model.php';
    +        $session = $this->get_session();
    +        $format = $this->input->get('format', TRUE) ?? 'view';
    +        $order_by = $this->input->get('order_by', TRUE) ?? '';
    +        $direction = $this->input->get('direction', TRUE) ?? 'ASC';
    +        $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
    +
    +        $this->_data['view_model'] = new Sales_member_list_paginate_view_model(
    +            $this->payout_model,
    +            $this->pagination,
    +            '/member/sales/0');
    +        $this->_data['view_model']->set_heading('Sales');
    +        $this->_data['view_model']->set_id(($this->input->get('id', TRUE) != NULL) ? $this->input->get('id', TRUE) : NULL);
    +		$this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
    +		$this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
    +		$this->_data['view_model']->set_amount(($this->input->get('amount', TRUE) != NULL) ? $this->input->get('amount', TRUE) : NULL);
    +		$this->_data['view_model']->set_created_at(($this->input->get('created_at', TRUE) != NULL) ? $this->input->get('created_at', TRUE) : NULL);
    +		$this->_data['view_model']->set_status(($this->input->get('status', TRUE) != NULL) ? $this->input->get('status', TRUE) : NULL);
    +		
    +        $where = [
    +            'id' => $this->_data['view_model']->get_id(),
    +			'user_id' => $this->session->userdata('user_id'),
    +			'order_id' => $this->_data['view_model']->get_order_id(),
    +			'amount' => $this->_data['view_model']->get_amount(),
    +			'created_at' => $this->_data['view_model']->get_created_at(),
    +			'status' => $this->_data['view_model']->get_status(),
    +			
    +            
    +        ];
    +
    +        $this->_data['view_model']->set_total_rows($this->payout_model->count($where));
    +
    +        $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
    +        $this->_data['view_model']->set_per_page($per_page_sort);
    +        $this->_data['view_model']->set_order_by($order_by);
    +        $this->_data['view_model']->set_sort($direction);
    +        $this->_data['view_model']->set_sort_base_url('/member/sales/0');
    +        $this->_data['view_model']->set_page($page);
    +		$this->_data['view_model']->set_list($this->payout_model->get_paginated(
    +            $this->_data['view_model']->get_page(),
    +            $this->_data['view_model']->get_per_page(),
    +            $where,
    +            $order_by,
    +            $direction));
    +
    +        $invetory_data = $this->db->select('i.*,p.name as professor,c.name as class,s.name as school')->from('inventory i ')
    +            ->join('school s','s.id=i.school_id')
    +            ->join('professor p','p.id=i.professor_id')
    +            ->join('classes c','c.id=i.class_id')
    +            ->get()->result_array();
    +        
    +        foreach ( $this->_data['view_model']->get_list() as $key => &$value) {
    +            $value->school = '';
    +            $value->professor = '';
    +            $value->class = '';
    +            $value->isbn = '';
    +            foreach ($invetory_data as $k => $v) {
    +                if($value->inventory_id==$v['id']){
    +                    $value->school = $v['school'];
    +                    $value->professor =  $v['professor'];
    +                    $value->class =  $v['class'];
    +                    $value->isbn =  $v['isbn'];
    +                }
    +            }
    +
    +        }
    +            
    +        
    +
    +        if ($format == 'csv')
    +        {
    +            header('Content-Type: text/csv');
    +            header('Content-Disposition: attachment; filename="export.csv"');
    +
    +            echo $this->_data['view_model']->to_csv();
    +            exit();
    +        }
    +
    +        if ($format != 'view')
    +        {
    +            return $this->output->set_content_type('application/json')
    +                ->set_status_header(200)
    +                ->set_output(json_encode($this->_data['view_model']->to_json()));
    +        }
    +
    +        return $this->render('Member/Sales', $this->_data);
    +	}
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +}
    \ No newline at end of file
    diff --git a/application/controllers/Member/Member_ticket_controller.php b/application/controllers/Member/Member_ticket_controller.php
    new file mode 100755
    index 0000000..ed78872
    --- /dev/null
    +++ b/application/controllers/Member/Member_ticket_controller.php
    @@ -0,0 +1,111 @@
    +load->library('pagination');
    +        include_once __DIR__ . '/../../view_models/Ticket_member_list_paginate_view_model.php';
    +        $session = $this->get_session();
    +        $format = $this->input->get('format', TRUE) ?? 'view';
    +        $order_by = $this->input->get('order_by', TRUE) ?? '';
    +        $direction = $this->input->get('direction', TRUE) ?? 'ASC';
    +        $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
    +
    +        $this->_data['view_model'] = new Ticket_member_list_paginate_view_model(
    +            $this->ticket_model,
    +            $this->pagination,
    +            '/member/ticket/0');
    +        $this->_data['view_model']->set_heading('Ticket');
    +        $this->_data['view_model']->set_order_id(($this->input->get('order_id', TRUE) != NULL) ? $this->input->get('order_id', TRUE) : NULL);
    +		$this->_data['view_model']->set_message(($this->input->get('message', TRUE) != NULL) ? $this->input->get('message', TRUE) : NULL);
    +		$this->_data['view_model']->set_receive_status(($this->input->get('receive_status', TRUE) != NULL) ? $this->input->get('receive_status', TRUE) : NULL);
    +
    +
    +        $where = [
    +            'order_id' => $this->_data['view_model']->get_order_id(),
    +			'message' => $this->_data['view_model']->get_message(),
    +			'receive_status' => $this->_data['view_model']->get_receive_status(),
    +		    'user_id' => $this->session->userdata('user_id'),
    +        ];
    +
    +
    +        $this->_data['view_model']->set_total_rows($this->ticket_model->count($where));
    +
    +        $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
    +        $this->_data['view_model']->set_per_page($per_page_sort);
    +        $this->_data['view_model']->set_order_by($order_by);
    +        $this->_data['view_model']->set_sort($direction);
    +        $this->_data['view_model']->set_sort_base_url('/member/ticket/0');
    +        $this->_data['view_model']->set_page($page);
    +		$this->_data['view_model']->set_list($this->ticket_model->get_paginated(
    +            $this->_data['view_model']->get_page(),
    +            $this->_data['view_model']->get_per_page(),
    +            $where,
    +            $order_by,
    +            $direction));
    +
    +
    +
    +
    +        if ($format == 'csv')
    +        {
    +            header('Content-Type: text/csv');
    +            header('Content-Disposition: attachment; filename="export.csv"');
    +
    +            echo $this->_data['view_model']->to_csv();
    +            exit();
    +        }
    +
    +        if ($format != 'view')
    +        {
    +            return $this->output->set_content_type('application/json')
    +                ->set_status_header(200)
    +                ->set_output(json_encode($this->_data['view_model']->to_json()));
    +        }
    +
    +        return $this->render('Member/Ticket', $this->_data);
    +	}
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +}
    \ No newline at end of file
    diff --git a/application/controllers/Member/Member_transaction_controller.php b/application/controllers/Member/Member_transaction_controller.php
    new file mode 100755
    index 0000000..75432a9
    --- /dev/null
    +++ b/application/controllers/Member/Member_transaction_controller.php
    @@ -0,0 +1,248 @@
    +load->library('pagination');
    +        include_once __DIR__ . '/../../view_models/Transaction_member_list_paginate_view_model.php';
    +        $format = $this->input->get('format', TRUE) ?? 'view';
    +        $order_by = $this->input->get('order_by', TRUE) ?? '';
    +        $direction = $this->input->get('direction', TRUE) ?? 'ASC';
    +        $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
    +        $session = $this->get_session();
    +        $where = [];
    +        $this->_data['view_model'] = new Transaction_member_list_paginate_view_model(
    +            $this->transaction_model,
    +            $this->pagination,
    +            '/member/transaction/0');
    +        $this->_data['view_model']->set_heading('Transaction');
    +        $this->_data['view_model']->set_total_rows($this->transaction_model->count($where));
    +
    +        $this->_data['view_model']->set_per_page($per_page_sort);
    +        $this->_data['view_model']->set_page($page);
    +        $this->_data['view_model']->set_order_by($order_by);
    +        $this->_data['view_model']->set_sort($direction);
    +        $this->_data['view_model']->set_sort_base_url('/member/transaction/0');
    +		$this->_data['view_model']->set_list($this->transaction_model->get_paginated(
    +            $this->_data['view_model']->get_page(),
    +            $this->_data['view_model']->get_per_page(),
    +            $where,
    +            $order_by,
    +            $direction));
    +        
    +        
    +
    +        if ($format == 'csv')
    +        {
    +            header('Content-Type: text/csv');
    +            header('Content-Disposition: attachment; filename="export.csv"');
    +
    +            echo $this->_data['view_model']->to_csv();
    +            exit();
    +        }
    +
    +        if ($format != 'view')
    +        {
    +            return $this->output->set_content_type('application/json')
    +                ->set_status_header(200)
    +                ->set_output(json_encode($this->_data['view_model']->to_json()));
    +        }
    +
    +        return $this->render('Member/Transaction', $this->_data);
    +	}
    +
    +    	public function add()
    +	{
    +        include_once __DIR__ . '/../../view_models/Transaction_member_add_view_model.php';
    +        $session = $this->get_session();
    +        $this->form_validation = $this->transaction_model->set_form_validation(
    +        $this->form_validation, $this->transaction_model->get_all_validation_rule());
    +        $this->_data['view_model'] = new Transaction_member_add_view_model($this->transaction_model);
    +        $this->_data['view_model']->set_heading('Transaction');
    +        
    +        
    +        
    +        
    +		if ($this->form_validation->run() === FALSE)
    +		{
    +			return $this->render('Member/TransactionAdd', $this->_data);
    +        }
    +
    +        $order_id = $this->input->post('order_id', TRUE);
    +		$user_id = $this->input->post('user_id', TRUE);
    +		$transaction_date = $this->input->post('transaction_date', TRUE);
    +		$transaction_time = $this->input->post('transaction_time', TRUE);
    +		$subtotal = $this->input->post('subtotal', TRUE);
    +		$tax = $this->input->post('tax', TRUE);
    +		$discount = $this->input->post('discount', TRUE);
    +		$total = $this->input->post('total', TRUE);
    +		$stripe_charge_id = $this->input->post('stripe_charge_id', TRUE);
    +		$payment_method = $this->input->post('payment_method', TRUE);
    +		$status = $this->input->post('status', TRUE);
    +		
    +        $result = $this->transaction_model->create([
    +            'order_id' => $order_id,
    +			'user_id' => $user_id,
    +			'transaction_date' => $transaction_date,
    +			'transaction_time' => $transaction_time,
    +			'subtotal' => $subtotal,
    +			'tax' => $tax,
    +			'discount' => $discount,
    +			'total' => $total,
    +			'stripe_charge_id' => $stripe_charge_id,
    +			'payment_method' => $payment_method,
    +			'status' => $status,
    +			
    +        ]);
    +
    +        if ($result)
    +        {
    +            
    +            
    +            return $this->redirect('/member/transaction/0', 'refresh');
    +        }
    +
    +        $this->_data['error'] = 'Error';
    +        return $this->render('Member/TransactionAdd', $this->_data);
    +	}
    +
    +    	public function edit($id)
    +	{
    +        $model = $this->transaction_model->get($id);
    +        $session = $this->get_session();
    +		if (!$model)
    +		{
    +			$this->error('Error');
    +			return redirect('/member/transaction/0');
    +        }
    +
    +        include_once __DIR__ . '/../../view_models/Transaction_member_edit_view_model.php';
    +        $this->form_validation = $this->transaction_model->set_form_validation(
    +        $this->form_validation, $this->transaction_model->get_all_edit_validation_rule());
    +        $this->_data['view_model'] = new Transaction_member_edit_view_model($this->transaction_model);
    +        $this->_data['view_model']->set_model($model);
    +        $this->_data['view_model']->set_heading('Transaction');
    +        
    +        
    +        
    +        
    +		if ($this->form_validation->run() === FALSE)
    +		{
    +			return $this->render('Member/TransactionEdit', $this->_data);
    +        }
    +
    +        $order_id = $this->input->post('order_id', TRUE);
    +		$user_id = $this->input->post('user_id', TRUE);
    +		$transaction_date = $this->input->post('transaction_date', TRUE);
    +		$transaction_time = $this->input->post('transaction_time', TRUE);
    +		$subtotal = $this->input->post('subtotal', TRUE);
    +		$tax = $this->input->post('tax', TRUE);
    +		$discount = $this->input->post('discount', TRUE);
    +		$total = $this->input->post('total', TRUE);
    +		$stripe_charge_id = $this->input->post('stripe_charge_id', TRUE);
    +		$payment_method = $this->input->post('payment_method', TRUE);
    +		$status = $this->input->post('status', TRUE);
    +		
    +        $result = $this->transaction_model->edit([
    +            'order_id' => $order_id,
    +			'user_id' => $user_id,
    +			'transaction_date' => $transaction_date,
    +			'transaction_time' => $transaction_time,
    +			'subtotal' => $subtotal,
    +			'tax' => $tax,
    +			'discount' => $discount,
    +			'total' => $total,
    +			'stripe_charge_id' => $stripe_charge_id,
    +			'payment_method' => $payment_method,
    +			'status' => $status,
    +			
    +        ], $id);
    +
    +        if ($result)
    +        {
    +            
    +            
    +            return $this->redirect('/member/transaction/0', 'refresh');
    +        }
    +
    +        $this->_data['error'] = 'Error';
    +        return $this->render('Member/TransactionEdit', $this->_data);
    +	}
    +
    +    	public function view($id)
    +	{
    +        $model = $this->transaction_model->get($id);
    +
    +		if (!$model)
    +		{
    +			$this->error('Error');
    +			return redirect('/member/transaction/0');
    +		}
    +
    +
    +        include_once __DIR__ . '/../../view_models/Transaction_member_view_view_model.php';
    +		$this->_data['view_model'] = new Transaction_member_view_view_model($this->transaction_model);
    +		$this->_data['view_model']->set_heading('Transaction');
    +        $this->_data['view_model']->set_model($model);
    +        
    +        
    +		return $this->render('Member/TransactionView', $this->_data);
    +	}
    +
    +    	public function delete($id)
    +	{
    +        $model = $this->transaction_model->get($id);
    +        $session = $this->get_session();
    +		if (!$model)
    +		{
    +			$this->error('Error');
    +			return redirect('/member/transaction/0');
    +        }
    +        
    +        $result = $this->transaction_model->delete($id);
    +
    +        if ($result)
    +        {
    +            
    +            return $this->redirect('/member/transaction/0', 'refresh');
    +        }
    +
    +        $this->error('Error');
    +        return redirect('/member/transaction/0');
    +	}
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +
    +    
    +}
    \ No newline at end of file
    diff --git a/application/controllers/Member/Member_user_card_controller.php b/application/controllers/Member/Member_user_card_controller.php
    new file mode 100755
    index 0000000..8578c1e
    --- /dev/null
    +++ b/application/controllers/Member/Member_user_card_controller.php
    @@ -0,0 +1,415 @@
    +load->model('credential_model');
    +    $this->load->model('user_model');
    +
    +    $this->load->library('stripe_helper_service');
    +  }
    +
    +  /**
    +   * @param $page
    +   * @return mixed
    +   */
    +  public function index($page)
    +  {
    +    $this->load->library('pagination');
    +    include_once __DIR__ . '/../../view_models/User_card_member_list_paginate_view_model.php';
    +    $session = $this->get_session();
    +    $user_id = $this->session->userdata('user_id');
    +
    +    $format        = $this->input->get('format', TRUE) ?? 'view';
    +    $order_by      = $this->input->get('order_by', TRUE) ?? '';
    +    $direction     = $this->input->get('direction', TRUE) ?? 'ASC';
    +    $per_page_sort = $this->input->get('per_page_sort', TRUE) ?? 25;
    +
    +    $this->_data['view_model'] = new User_card_member_list_paginate_view_model(
    +      $this->user_card_model,
    +      $this->pagination,
    +      '/member/user_card/0');
    +    $this->_data['view_model']->set_heading('User Card');
    +    $this->_data['view_model']->set_is_default(($this->input->get('is_default', TRUE) != NULL) ? $this->input->get('is_default', TRUE) : NULL);
    +    // $this->_data['view_model']->set_user_id(($this->input->get('user_id', TRUE) != NULL) ? $this->input->get('user_id', TRUE) : NULL);
    +    $this->_data['view_model']->set_last4(($this->input->get('last4', TRUE) != NULL) ? $this->input->get('last4', TRUE) : NULL);
    +
    +    $where = [
    +      'is_default' => $this->_data['view_model']->get_is_default(),
    +      'user_id'    => $user_id,
    +      'last4'      => $this->_data['view_model']->get_last4()
    +    ];
    +
    +    $this->_data['view_model']->set_total_rows($this->user_card_model->count($where));
    +
    +    $this->_data['view_model']->set_format_layout($this->_data['layout_clean_mode']);
    +    $this->_data['view_model']->set_per_page($per_page_sort);
    +    $this->_data['view_model']->set_order_by($order_by);
    +    $this->_data['view_model']->set_sort($direction);
    +    $this->_data['view_model']->set_sort_base_url('/member/user_card/0');
    +    $this->_data['view_model']->set_page($page);
    +    $this->_data['view_model']->set_list($this->user_card_model->get_paginated(
    +      $this->_data['view_model']->get_page(),
    +      $this->_data['view_model']->get_per_page(),
    +      $where,
    +      $order_by,
    +      $direction));
    +
    +    if ($format == 'csv')
    +    {
    +      header('Content-Type: text/csv');
    +      header('Content-Disposition: attachment; filename="export.csv"');
    +
    +      echo $this->_data['view_model']->to_csv();
    +      exit();
    +    }
    +
    +    if ($format != 'view')
    +    {
    +      return $this->output->set_content_type('application/json')
    +        ->set_status_header(200)
    +        ->set_output(json_encode($this->_data['view_model']->to_json()));
    +    }
    +
    +    return $this->render('Member/User_card', $this->_data);
    +  }
    +
    +  /**
    +   * @return mixed
    +   */
    +  public function add()
    +  {
    +    include_once __DIR__ . '/../../view_models/User_card_member_add_view_model.php';
    +    $session = $this->get_session();
    +    $user_id = $this->session->userdata('user_id');
    +
    +    $this->form_validation = $this->user_card_model->set_form_validation(
    +      $this->form_validation, $this->user_card_model->get_all_validation_rule());
    +    $this->_data['view_model'] = new User_card_member_add_view_model($this->user_card_model);
    +    $this->_data['view_model']->set_heading('User Card');
    +
    +    if ($this->form_validation->run() === FALSE)
    +    {
    +      return $this->render('Member/User_cardAdd', $this->_data);
    +    }
    +
    +    $user_all_card_data = $this->user_card_model->get_all(['user_id' => $user_id]);
    +    // $user_card_data     = $this->user_card_model->get_by_field('user_id', $user_id);
    +
    +    $is_default  = $this->input->post('is_default', TRUE);
    +    $card_name   = $this->input->post('card_name', TRUE);
    +    $card_number = $this->input->post('card_number', TRUE);
    +    $exp_month   = $this->input->post('exp_month', TRUE);
    +    $exp_year    = $this->input->post('exp_year', TRUE);
    +    $cvc         = $this->input->post('cvc', TRUE);
    +
    +    $new_card_last4 = substr($card_number, 12);
    +
    +    if (!empty($user_all_card_data))
    +    {
    +      if (!empty($card_number) && !empty($exp_month) && !empty($exp_year) && !empty($cvc))
    +      {
    +        // use for each
    +        foreach ($user_all_card_data as $key1 => $res1)
    +        {
    +          if ($res1->last4 == $new_card_last4)
    +          {
    +            // throw error
    +            $this->error('This card last4->(...' . $new_card_last4 . ') is already added. Try again with a new card.');
    +            return redirect($_SERVER['HTTP_REFERER']);
    +          }
    +        }
    +        // add card
    +        $this->stripe_helper_service->set_config($this->config);
    +        $response = $this->stripe_helper_service->create_stripe_token($card_number, $exp_month, $exp_year, $cvc);
    +
    +        if (isset($response['success']))
    +        {
    +          $stripe_token_id = $response['token']->id;
    +
    +          $this->stripe_helper_service->set_user_model($this->user_model);
    +          // pass token_id to assign card to user
    +          $res_card_data = $this->stripe_helper_service->add_new_card($stripe_token_id, $user_id);
    +
    +          if (isset($res_card_data['success']))
    +          {
    +            $stripe_card_id   = $res_card_data['card_data']->id;
    +            $stripe_brand     = $res_card_data['card_data']->brand;
    +            $stripe_exp_month = $res_card_data['card_data']->exp_month;
    +            $stripe_exp_year  = $res_card_data['card_data']->exp_year;
    +            $stripe_last4     = $res_card_data['card_data']->last4;
    +
    +            // store the card id with the associated user
    +            $check_new_card = $this->user_card_model->create([
    +              'is_default'     => 0,
    +              'user_id'        => $user_id,
    +              'stripe_card_id' => $stripe_card_id,
    +              'last4'          => $stripe_last4,
    +              'brand'          => $stripe_brand,
    +              'exp_month'      => $stripe_exp_month,
    +              'exp_year'       => $stripe_exp_year
    +            ]);
    +
    +            if ($check_new_card)
    +            {
    +              $this->success('Card added successfully.');
    +              return $this->redirect('/member/user_card/0', 'refresh');
    +            }
    +            else
    +            {
    +              $this->error('Card add failed. Try Again.');
    +              return redirect($_SERVER['HTTP_REFERER']);
    +            }
    +          }
    +          else
    +          {
    +            // when user do not have the user->stripe_id
    +            $this->error($res_card_data['error_msg']);
    +            return redirect($_SERVER['HTTP_REFERER']);
    +          }
    +        }
    +        else
    +        {
    +          // when new card validation failed
    +          $this->error($response['error_msg']);
    +          return redirect($_SERVER['HTTP_REFERER']);
    +        }
    +
    +      }
    +      else
    +      {
    +        $this->error('Empty Field');
    +        return redirect($_SERVER['HTTP_REFERER']);
    +      }
    +    }
    +    else
    +    {
    +      // create stripe_customer_id and add the new card
    +      $this->stripe_helper_service->set_config($this->config);
    +      $response = $this->stripe_helper_service->create_stripe_token($card_number, $exp_month, $exp_year, $cvc);
    +
    +      if (isset($response['success']))
    +      {
    +        $stripe_token_id = $response['token']->id;
    +        // var_dump($stripe_token_id);
    +        // die();
    +
    +        // get user email from credential model
    +        $customer_email = $this->credential_model->get_by_field('user_id', $user_id);
    +
    +        $this->stripe_helper_service->set_config($this->config);
    +        $res_customer = $this->stripe_helper_service->create_stripe_customer_with_card($customer_email, $stripe_token_id);
    +
    +        if (isset($res_customer['success']))
    +        {
    +          $stripe_customer_id = $res_customer['card']->customer;
    +          $stripe_card_id     = $res_customer['card']->id;
    +          $stripe_brand       = $res_customer['card']->brand;
    +          $stripe_exp_month   = $res_customer['card']->exp_month;
    +          $stripe_exp_year    = $res_customer['card']->exp_year;
    +          $stripe_last4       = $res_customer['card']->last4;
    +
    +          // update user->stripe_id
    +          $update_stripe_id = $this->user_model->edit([
    +            'stripe_id' => $stripe_customer_id
    +          ], $user_id);
    +
    +          // add card on user_card
    +          if ($update_stripe_id)
    +          {
    +            // store the card id with the associated user
    +            $check_new_card = $this->user_card_model->create([
    +              'is_default'     => 1,
    +              'user_id'        => $user_id,
    +              'stripe_card_id' => $stripe_card_id,
    +              'last4'          => $stripe_last4,
    +              'brand'          => $stripe_brand,
    +              'exp_month'      => $stripe_exp_month,
    +              'exp_year'       => $stripe_exp_year
    +            ]);
    +
    +            if ($check_new_card)
    +            {
    +              $this->success('Card added successfully and set to default.');
    +              return $this->redirect('/member/user_card/0', 'refresh');
    +            }
    +            else
    +            {
    +              $this->error('Card add failed. Try Again.');
    +              return redirect($_SERVER['HTTP_REFERER']);
    +            }
    +          }
    +        }
    +        else
    +        {
    +          $this->error($res_customer['error_msg']);
    +          return redirect($_SERVER['HTTP_REFERER']);
    +        }
    +      }
    +      else
    +      {
    +        // when new card validation failed
    +        $this->error($response['error_msg']);
    +        return redirect($_SERVER['HTTP_REFERER']);
    +      }
    +    }
    +
    +    $this->_data['error'] = 'Error';
    +    return $this->render('Member/User_cardAdd', $this->_data);
    +  }
    +
    +  public function set_default()
    +  {
    +    $user_id = $this->session->userdata('user_id');
    +
    +    $user_card_id = $this->input->post('user_card_id');
    +
    +    if (!empty($user_card_id))
    +    {
    +      $user_card_data = $this->user_card_model->get($user_card_id);
    +
    +      if (!empty($user_card_data))
    +      {
    +        if ($user_card_data->is_default == 1)
    +        {
    +          $output['error']  = TRUE;
    +          $output['status'] = 0;
    +          $output['msg']    = 'This card is already set to default.';
    +          echo json_encode($output);
    +          exit();
    +        }
    +      }
    +
    +      $this->stripe_helper_service->set_config($this->config);
    +      $this->stripe_helper_service->set_user_model($this->user_model);
    +      $response = $this->stripe_helper_service->update_default_card($user_card_data->stripe_card_id, $user_id);
    +
    +      if (isset($response['success']))
    +      {
    +        // make other cards is_default to = 0
    +        $all_card_data = $this->user_card_model->get_all(['user_id' => $user_id]);
    +        if (!empty($all_card_data))
    +        {
    +          foreach ($all_card_data as $key1 => $res1)
    +          {
    +            $this->user_card_model->edit(['is_default' => 0], $res1->id);
    +          }
    +        }
    +
    +        // then only set is_default 1 to the default card
    +        $result = $this->user_card_model->edit([
    +          'is_default' => 1
    +        ], $user_card_id);
    +
    +        if ($result)
    +        {
    +          $output['success'] = TRUE;
    +          $output['status']  = 200;
    +          $output['msg']     = 'Card set to default.';
    +          echo json_encode($output);
    +          exit();
    +        }
    +        else
    +        {
    +          $output['error']  = TRUE;
    +          $output['status'] = 0;
    +          $output['msg']    = 'Error! Please try again later.';
    +          echo json_encode($output);
    +          exit();
    +        }
    +      }
    +      else
    +      {
    +        $output['error']  = TRUE;
    +        $output['status'] = 0;
    +        $output['msg']    = $response['error_msg'];
    +        echo json_encode($output);
    +        exit();
    +      }
    +    }
    +    else
    +    {
    +      $output['error']  = TRUE;
    +      $output['status'] = 0;
    +      $output['msg']    = 'Error! User card not found.';
    +      echo json_encode($output);
    +      exit();
    +    }
    +  }
    +
    +  public function delete()
    +  {
    +    $user_id = $this->session->userdata('user_id');
    +
    +    $user_card_id = $this->input->post('user_card_id');
    +
    +    if (!empty($user_card_id))
    +    {
    +      $user_card_data = $this->user_card_model->get($user_card_id);
    +
    +      $this->stripe_helper_service->set_config($this->config);
    +      $this->stripe_helper_service->set_user_model($this->user_model);
    +      $response = $this->stripe_helper_service->delete_card_from_customer($user_id, $user_card_data->stripe_card_id);
    +
    +      if (isset($response['success']))
    +      {
    +        $result = $this->user_card_model->real_delete($user_card_id);
    +
    +        if ($result)
    +        {
    +          $output['success'] = TRUE;
    +          $output['status']  = 200;
    +          $output['msg']     = 'User card deleted successfully.';
    +          echo json_encode($output);
    +          exit();
    +        }
    +        else
    +        {
    +          $output['error']  = TRUE;
    +          $output['status'] = 0;
    +          $output['msg']    = 'Error! Please try again later.';
    +          echo json_encode($output);
    +          exit();
    +        }
    +      }
    +      else
    +      {
    +        $output['error']  = TRUE;
    +        $output['status'] = 0;
    +        $output['msg']    = $response['error_msg'];
    +        echo json_encode($output);
    +        exit();
    +      }
    +    }
    +    else
    +    {
    +      $output['error']  = TRUE;
    +      $output['status'] = 0;
    +      $output['msg']    = 'Error! User card not found.';
    +      echo json_encode($output);
    +      exit();
    +    }
    +  }
    +
    +}
    diff --git a/application/controllers/Welcome.php b/application/controllers/Welcome.php
    new file mode 100755
    index 0000000..7fb9fd2
    --- /dev/null
    +++ b/application/controllers/Welcome.php
    @@ -0,0 +1,11 @@
    +
    +
    +
    +	403 Forbidden
    +
    +
    +
    +

    Directory access is forbidden.

    + + + diff --git a/application/core/Manaknight_Controller.php b/application/core/Manaknight_Controller.php new file mode 100755 index 0000000..46d8e57 --- /dev/null +++ b/application/core/Manaknight_Controller.php @@ -0,0 +1,442 @@ + 'https://2c9f2b0e8d3e424a81d19c501c479d02@o1003846.ingest.sentry.io/5970395' ]); + + + +class Manaknight_Controller extends CI_Controller +{ + + // If set, this language file will automatically be loaded. + protected $_language_file = NULL; + + // If set, this model file will automatically be loaded. + protected $_model_file = NULL; + + //testMode flag + protected $_test_mode = FALSE; + + protected $_setting = FALSE; + + /** + * View Model + * @var array + */ + public $_data = [ + 'error' => '', + 'success' => '' + ]; + + /** + * Flash Data + * @var array + */ + protected $_flash_error = [ + 'error' => '', + 'success' => '' + ]; + + public function __construct() + { + parent::__construct(); + $this->load->database(); + + + //-------------------------------------------------------------------- + // Language & Model Files + //-------------------------------------------------------------------- + + if (!is_null($this->_language_file)) + { + $this->lang->load($this->_language_file); + } + + if (!is_null($this->_model_file)) + { + $this->load->model($this->_model_file); + } + + //Flashdata setup + if ($this->session->flashdata('error')) + { + $this->_flash_error['error'] = $this->session->flashdata('error'); + $this->session->set_flashdata('error', ''); + $this->_data['error'] = $this->_flash_error['error']; + } + + if ($this->session->flashdata('success')) + { + $this->_flash_error['success'] = $this->session->flashdata('success'); + $this->session->set_flashdata('success', ''); + $this->_data['success'] = $this->_flash_error['success']; + } + + $this->load->model('setting_model'); + $this->_setting = $this->setting_model->get_config_settings(); + + date_default_timezone_set($this->config->item('default_time_zone')); + } + + /** + * Set Controller into test mode + * + * @return void + */ + public function set_test_mode () + { + $this->_test_mode = TRUE; + } + + /** + * Render view + * + * @param string $template + * @param array $data + */ + public function render($template, $data) + { + return (!$this->_test_mode) ? $this->_render($template, $data) : $this->_render_test($template, $data); + } + + /** + * Render Test Model + * + * @param string $template + * @param mixed $data + * @return mixed + */ + protected function _render_test($template, $data) + { + return [ + 'header' => $this->load->view('Layout/Header', $data, TRUE), + 'body' => $this->load->view($template, $data, TRUE), + 'footer' => $this->load->view('Layout/Footer', $data, TRUE), + 'data' => $data, + ]; + } + + /** + * Render Normal View + * + * @param string $template + * @param mixed $data + * @return void + */ + protected function _render($template, $data) + { + $this->load->view('Layout/Header', $data); + $this->load->view($template, $data); + $this->load->view('Layout/Footer'); + } + + /** + * Redirect to URL + * + * @param string $template + * @param array $data + */ + public function redirect($url, $option = []) + { + return ($option) ? redirect($url, $option) : redirect($url); + } + + /** + * Set the Flashdata + * + * @param string $message + */ + public function success($message) + { + $this->session->set_flashdata('success', $message); + } + + /** + * Set the Flashdata + * + * @param string $message + */ + public function error($message) + { + $this->session->set_flashdata('error', $message); + } + + /** + * Debug Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dl($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER :
    ' . print_r($data, TRUE) . '
    '); + } + } + + /** + * Debug json Controller to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dj($key, $data) + { + if (ENVIRONMENT == 'development') + { + error_log($key . ' CONTROLLER : ' . json_encode($data)); + } + } + + public function get_session() + { + if (!$this->_test_mode) + { + return $_SESSION; + } + + $session = $this->config->item('session_test'); + + if (!$session) + { + $session = []; + } + + return $session; + } + + public function set_session($field, $value) + { + if (!$this->_test_mode) + { + $_SESSION[$field] = $value; + } + else + { + $session = $this->config->item('session_test'); + if (!$session) + { + $session = []; + } + $session[$field] = $value; + $this->config->set_item('session_test', $session); + } + } + + public function destroy_session() + { + if (!$this->_test_mode) + { + unset($_SESSION); + session_unset(); + } + else + { + $this->config->set_item('session_test', []); + } + } + + /** + * Function to send Emails given slug, payload and email + * + * @param string $slug + * @param mixed $payload + * @param string $email + * @return void + */ + protected function _send_email_notification($slug, $payload, $email) + { + $this->load->model('email_model'); + $this->load->library('mail_service'); + $this->mail_service->set_adapter('smtp'); + $email_template = $this->email_model->get_template($slug, $payload); + + if ($email_template) + { + $from = $this->config->item('from_email'); + return $this->mail_service->send($from, $email, $email_template->subject, $email_template->html); + } + + return FALSE; + } + + /** + * Function to send Sms given slug, payload and phone # + * + * @param string $slug + * @param mixed $payload + * @param string $to + * @return void + */ + protected function _send_sms_notification($slug, $payload, $to) + { + $this->load->model('sms_model'); + $this->load->library('sms_service'); + $this->sms_service->set_adapter('sms'); + $sms_template = $this->sms_model->get_template($slug, $payload); + + if ($sms_template) + { + return $this->sms_service->send($to, $sms_template->content); + } + + return FALSE; + } + + /** + * Function to send Push notification + * + * @param string $slug + * @param mixed $payload + * @param string $to + * @return void + */ + protected function _send_push_notification($device_type, $device_id, $title, $message, $image) + { + $this->load->library('push_notification_service'); + $this->push_notification_service->init(); + return $this->push_notification_service->send($device_type, $device_id, $title, $message, $image); + } + + protected function _middleware() + { + return []; + } + + protected function _run_middlewares () + { + + $middlewares = [ + 'affilate' => new Affilate_middleware($this, $this->config), + 'auth' => new Auth_middleware($this, $this->config), + 'acl' => new Acl_middleware($this, $this->config), + 'maintenance' => new Maintenance_middleware($this, $this->config), + 'subscription' => new Subscription_middleware($this, $this->config) + ]; + + foreach ($this->_middleware() as $middleware_key) + { + if (isset($middlewares[$middleware_key])) + { + $result = $middlewares[$middleware_key]->run(); + + if (!$result) + { + return FALSE; + } + } + } + } + + public function get_setting() + { + return $this->_setting; + } + + + + public function image_upload_using_s3($file_name) + { + + if( $this->config->item('image_upload') == 's3') + { + $s3 = new S3Client([ + 'version' => $this->config->item('aws_version'), + 'region' => $this->config->item('aws_region'), + 'endpoint' => $this->config->item('aws_endpoint'), + 'use_path_style_endpoint' => true, + 'credentials' => [ + 'key' => $this->config->item('aws_key'), + 'secret' => $this->config->item('aws_secret'), + ] + ]); + + $this->load->model('image_model'); + + $image_path = __DIR__ . '/../../' . $file_name; + + // $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data_uri)); + // $filename = md5(uniqid() . time()) . '.png'; + // file_put_contents($image_path . $filename, $data); + + + list($width, $height) = getimagesize( $image_path ); + $session = $this->get_session(); + $user_id = isset($session['user_id']) ? $session['user_id'] : 0; + + $file_name = str_replace('/uploads/','',$file_name); + + try + { + $result = $s3->putObject([ + 'Bucket' => $this->config->item('aws_bucket'), + 'Key' => $file_name, + 'Body' => fopen($image_path, 'r'), + 'ACL' => 'public-read', + ]); + + $image_id = $this->image_model->create([ + 'url' => $result->get('ObjectURL'), + 'type' => 0, + 'user_id' => $user_id, + 'width' => $width, + 'caption' => '', + 'height' => $height + ]); + + return $this->output->set_content_type('application/json') + ->set_status_header(200) + ->set_output(json_encode([ + 'id' => $image_id, + 'image' => $result->get('ObjectURL'), + 'width' => $width, + 'height' => $height + ])); + } + catch (Aws\S3\Exception\S3Exception $e) + { + return $this->output->set_content_type('application/json') + ->set_status_header(403) + ->set_output(json_encode([ + 'message' => 'Upload To S3 Failed' + ])); + } + } + } + + + + + public function upload_image_with_s3($file_name) + { + $output = $this->image_upload_using_s3($file_name); + $out_image = ''; + if( isset($output->final_output ) ) + { + $result = json_decode( $output->final_output ); + if(isset($result->image)) + { + $out_image = $result->image; + } + return $out_image; + } else{ + return $out_image; + } + } +} \ No newline at end of file diff --git a/application/core/Manaknight_Form_validation.php b/application/core/Manaknight_Form_validation.php new file mode 100755 index 0000000..6e1eb93 --- /dev/null +++ b/application/core/Manaknight_Form_validation.php @@ -0,0 +1,124 @@ +_error_array; + } + + /** + * Exist + * + * Check if the input value exist in system + * + * @param string $str + * @param string $field + * @return bool + */ + public function exist($str, $field) + { + sscanf($field, '%[^.].%[^.]', $table, $field); + return isset($this->CI->db) + ? ($this->CI->db->limit(1)->get_where($table, array($field => $str))->num_rows() === 1) + : FALSE; + } + + /** + * Greater Than + * + * @param string $str + * @param number $min + * @return bool + */ + public function greater_than($str, $min) + { + if (!is_numeric($str)) + { + return FALSE; + } + + return $str > $min; + } + + /** + * Less Than + * + * @param string $str + * @param number $min + * @return bool + */ + public function less_than($str, $max) + { + if (!is_numeric($str)) + { + return FALSE; + } + + return $str < $max; + } + + /** + * Equal To + * + * @param string $str + * @param number $min + * @return bool + */ + public function equal_to($str, $eq) + { + if (!is_numeric($str)) + { + return FALSE; + } + + return $str == $eq; + } + + /** + * Max Count + * + * @param string $str + * @param number $min + * @return bool + */ + public function max_count($str, $max) + { + return count($str) <= $max; + } + + /** + * Min Count + * + * @param string $str + * @param number $min + * @return bool + */ + public function min_count($str, $min) + { + return count($str) >= $min; + } + + /** + * Allowed domain email + * + * @param string $str + * @param number $min + * @return bool + */ + public function domain_email($str, $params) + { + $parts = explode("@", $str); + $domain = $parts[1]; + $allowed_array = explode(',', $params); + return in_array($domain, $allowed_array); + } +} \ No newline at end of file diff --git a/application/core/Manaknight_Input.php b/application/core/Manaknight_Input.php new file mode 100755 index 0000000..6a900db --- /dev/null +++ b/application/core/Manaknight_Input.php @@ -0,0 +1,35 @@ +get_request_header('Content-Type'); + + if ($this->method('post') && stripos($content_type, 'application/json') !== FALSE && + ($postdata = $this->raw_post()) && + in_array($postdata[0], array('{', '['))) + { + $decoded_postdata = json_decode($postdata, true); + if ((json_last_error() == JSON_ERROR_NONE)) + { + $_POST = $decoded_postdata; + } + } + } + + protected function raw_post() + { + return file_get_contents('php://input'); + } +} \ No newline at end of file diff --git a/application/core/Manaknight_Model.php b/application/core/Manaknight_Model.php new file mode 100755 index 0000000..03e64f0 --- /dev/null +++ b/application/core/Manaknight_Model.php @@ -0,0 +1,1055 @@ +_mapping = new Mapping(); + } + + /** + * Get Mapping Delegate + * + * @return mixed + */ + public function get_mapping() + { + return $this->_mapping; + } + + /** + * Raw Mysql query + * + * @param string $sql + * @return mixed + */ + public function raw_query($sql) + { + return $this->db->query($sql); + } + + /** + * Raw no error query for writes + * + * @param string $sql + * @return mixed + */ + public function raw_no_error_query($sql) + { + return $this->db->simple_query($sql); + } + + /** + * Raw Mysql query + * + * @param string $sql + * @return mixed + */ + public function raw_prepare_query($sql, $parameters) + { + return $this->db->query($sql, $parameters); + } + + /** + * Get Model + * + * @param integer $id + * @return mixed + */ + public function get($id) + { + $this->db->from($this->_table); + $this->db->where($this->_primary_key, $id, TRUE); + return $this->db->get()->row(); + } + + /** + * Get Model by field + * + * @param string $field + * @param mixed $value + * @return mixed + */ + public function get_by_field($field, $value) + { + $this->db->from($this->_table); + $this->db->where($this->clean_alpha_field($field), $value, TRUE); + return $this->db->get()->row(); + } + + /** + * Get Model by fields + * + * @param string $field + * @param mixed $value + * @return mixed + */ + public function get_by_fields($where) + { + $this->db->from($this->_table); + + if (!empty($where)) + { + foreach($where as $field => $value) + { + if (is_numeric($field) && strlen($value) > 0) + { + $this->db->where($value); + continue; + } + + if ($value === NULL) + { + continue; + } + + if ($value !== NULL) + { + $this->db->where($this->clean_alpha_field($field), $value, TRUE); + } + + } + } + + return $this->db->get()->row(); + } + + public function update($table,$set,$where) + { + return $this->db->set($set)->where($where)->update($table); + } + /** + * Get all Model + * + * @return array + */ + public function get_all($where = array()) + { + $this->db->from($this->_table); + + foreach($where as $field => $value) + { + if (is_numeric($field) && strlen($value) > 0) + { + $this->db->where($value); + continue; + } + + if ($field === NULL && $value === NULL) + { + continue; + } + + if ($value !== NULL) + { + $this->db->where($this->clean_alpha_field($field), $value, TRUE); + } + } + + return $this->db->get()->result(); + } + + /** + * Get all Model + * + * @return array + */ + public function get_all_by_status($status) + { + $this->db->from($this->_table); + $this->db->where('status', $status, TRUE); + return $this->db->get()->result(); + } + + /** + * Get all Model key value + * + * @return array + */ + public function get_all_by_key_value($field, $status) + { + $this->db->from($this->_table); + $this->db->where('status', $status, TRUE); + + $data = []; + $results = $this->db->get()->result(); + + foreach ($results as $key => $value) + { + $data[$value->id] = $value->{$field}; + } + + return $data; + } + + /** + * Create + * + * @param array $data + * @return mixed + */ + public function create($data) + { + if ($this->_use_timestamps) + { + if (!isset($data[$this->_created_field])) + { + $data[$this->_created_field] = date('Y-m-j'); + } + if (!isset($data[$this->_updated_field])) + { + $data[$this->_updated_field] = date('Y-m-j H:i:s'); + } + } + + $data = $this->_pre_create_processing($data); + + $inserted_row = $this->db->insert($this->_table, $this->_filter_allow_keys($data), TRUE); + + if ($inserted_row) + { + return $this->db->insert_id(); + } + + return FALSE; + } + + /** + * Duplicate + * + * @param array $data + * @return mixed + */ + public function duplicate($where, $id) + { + $row = $this->get($id); + + if (!$row) + { + return FALSE; + } + + $data = json_decode(json_encode($row), true); + + if ($this->_use_timestamps) + { + if (!isset($data[$this->_created_field])) + { + $data[$this->_created_field] = date('Y-m-j'); + } + if (!isset($data[$this->_updated_field])) + { + $data[$this->_updated_field] = date('Y-m-j H:i:s'); + } + } + + unset($data['id']); + + $data = $this->_pre_create_processing($data); + + foreach ($where as $key => $value) + { + $data[$key] = $value; + } + + + $inserted_row = $this->db->insert($this->_table, $this->_filter_allow_keys($data), TRUE); + + if ($inserted_row) + { + return $this->db->insert_id(); + } + + return FALSE; + } + + /** + * Bulk Create + * + * @param [type] $params + * @return void + */ + public function batch_insert($params) + { + if ($this->_use_timestamps) + { + foreach ($params as $key => $value) + { + $params[$key][$this->_created_field] = date('Y-m-j'); + $params[$key][$this->_updated_field] = date('Y-m-j H:i:s'); + } + } + + return $this->db->insert_batch($this->_table, $params); + } + + /** + * Edit {{{upper_case_model}}} + * @param array $data + * @param integer $id + * @return bool + */ + public function edit($data, $id) + { + if ($this->_use_timestamps) + { + if (!isset($data[$this->_updated_field])) + { + $data[$this->_updated_field] = date('Y-m-j H:i:s'); + } + } + + $data = $this->_post_edit_processing($data); + + $this->db->where($this->_primary_key, $id, TRUE); + + return $this->db->update($this->_table, $this->_filter_allow_keys($data)); + } + + /** + * Edit {{{upper_case_model}}} + * @param array $data + * @param integer $id + * @return bool + */ + public function edit_raw($data, $id) + { + if ($this->_use_timestamps) + { + $data[$this->_updated_field] = date('Y-m-j H:i:s'); + } + + $this->db->where($this->_primary_key, $id, TRUE); + + return $this->db->update($this->_table, $this->_filter_allow_keys($data)); + } + + /** + * Soft Delete Model + * @param array $data + * @param integer $id + * @return bool + */ + public function delete($id) + { + $data = []; + + if ($this->_use_timestamps) + { + $data[$this->_updated_field] = date('Y-m-j H:i:s'); + $data['status'] = 0; + } + + $this->db->where($this->_primary_key, $id, TRUE); + + return $this->db->update($this->_table, $this->_filter_allow_keys($data)); + } + + /** + * Real Delete Model + * @param integer $id + * @return bool + */ + public function real_delete($id) + { + return $this->db->delete($this->_table, ['id' => $id]); + } + + /** + * Real Delete Model + * @param integer $id + * @return bool + */ + public function real_delete_by_fields($where=[]) + { + $payload = []; + + if (!empty($where)) + { + foreach($where as $field => $value) + { + if (is_numeric($field) && strlen($value) > 0) + { + $payload[] = $value; + continue; + } + + if ($value === null) + { + continue; + } + + if ($value !== NULL) + { + $payload[$field] = $value; + } + + } + } + return $this->db->delete($this->_table, $payload); + } + + /** + * Real Delete Model + * @param integer $id + * @return bool + */ + public function real_delete_all() + { + return $this->db->truncate($this->_table); + } + + /** + * Debug json Model to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dj($key, $data) + { + if (ENVIRONMENT == 'development') { + error_log($key . ' MODEL : ' . json_encode($data)); + } + } + + /** + * Debug Model to error_log and turn off in production + * + * @param mixed $data + * @return void + */ + public function dl($key, $data) + { + if (ENVIRONMENT == 'development') { + error_log($key . ' MODEL: ' . '
    ' . print_r($data, TRUE) . '
    '); + } + } + + /** + * Get All Validation Rules + * + * @param string $key + * @return array + */ + public function get_all_validation_rule () + { + return $this->_validation_rules; + } + + /** + * Get All Edit Validation Rules + * + * @param string $key + * @return array + */ + public function get_all_edit_validation_rule () + { + return $this->_validation_edit_rules; + } + + /** + * Fill validation rules + * + * @param mixed $form_validation + * @param mixed $validation_rules + * @return void + */ + public function set_form_validation($form_validation, $validation_rules) + { + $rules = $validation_rules; + + $messages = $this->_validation_messages; + + foreach ($rules as $key => $value) + { + $error_object = []; + + if (array_key_exists($key, $messages)) + { + $error_object = $messages[$key]; + } + + $form_validation->set_rules($value[0], $value[1], $value[2], $error_object); + } + + return $form_validation; + } + + /** + * Count number of model + * + * @access public + * @param mixed $parameters + * @return integer $result + */ + public function count($parameters) + { + if (!empty($parameters)) + { + foreach ($parameters as $key => $value) + { + if (is_numeric($key) && strlen($value) > 0) + { + $this->db->where($value); + continue; + } + + if ($key === NULL && $value === NULL) + { + continue; + } + + if (!is_null($value)) + { + if(is_numeric($value)) + { + $this->db->where($key, $value); + continue; + } + + if(is_string($value)) + { + $this->db->like($key, $value); + continue; + } + + $this->db->where($key, $value); + } + } + } + + $this->_custom_counting_conditions($this->db); + $this->db->from($this->_table); + return $this->db->count_all_results(); + } + + /** + * Get paginated model + * + * @access public + * @param integer $page default 0 + * @param integer $limit default 10 + * @return array + */ + public function get_paginated($page = 0, $limit=10, $where=[], $order_by='', $direction='ASC') + { + $this->db->limit($limit, $page); + + if ($order_by === '') + { + $order_by = $this->_primary_key; + } + + $this->db->order_by($this->clean_alpha_num_field($order_by), $this->clean_alpha_field($direction)); + + if (!empty($where)) + { + foreach($where as $field => $value) + { + if (is_numeric($field) && strlen($value) > 0) + { + $this->db->where($value); + continue; + } + + if ($field === NULL && $value === NULL) + { + continue; + } + + if ($value !== NULL) + { + if(is_numeric($value)) + { + $this->db->where($field, $value); + continue; + } + + if(is_string($value)) + { + $this->db->like($field, $value); + continue; + } + + $this->db->where($field, $value); + } + } + } + + $query = $this->db->get($this->_table); + $result = []; + + if ($query->num_rows() > 0) + { + foreach ($query->result() as $row) + { + $result[] = $row; + } + } + + return $result; + } + + public function _join ($table, $field, $where, $custom_duplicate_names=[]) + { + $select_statement = '`a`.id as a_id, `b`.id as b_id,' ; + + $duplicate_names = [ + // 'status', + // 'created_at', + // 'updated_at', + // 'type', + // 'image', + // 'data', + // 'slug', + // 'description', + // 'amount', + // 'subtotal', + // 'total', + // 'lat', + // 'lng', + // 'address', + // 'state', + // 'country', + // 'city', + // 'order' + ]; + + if (count($custom_duplicate_names) > 0) + { + $duplicate_names = $custom_duplicate_names; + } + + foreach ($this->_allowed_fields as $key => $value) + { + if (in_array($value, $duplicate_names)) + { + $select_statement .= "`a`.{$value} as a_{$value}, `b`.{$value} as b_{$value}," ; + } + } + + $this->db->select($select_statement . ' `a`.*, `b`.*'); + $this->db->from($this->_table . ' a'); + $this->db->join($table . ' b', "a.{$field} = b.id"); + + if (!empty($where)) + { + foreach ($where as $key => $value) + { + $this->db->where($key, $value); + } + } + + $result = []; + $query = $this->db->get(); + foreach ($query->result() as $row) + { + $result[] = $row; + } + + return $result; + } + + public function _join_paginate ($table, $field, $where, $page = 0, $limit = 10, $order_by='', $direction='ASC', $custom_duplicate_names=[]) + { + $select_statement = '`a`.id as a_id, `b`.id as b_id,' ; + + $duplicate_names = [ + // 'status', + // 'created_at', + // 'updated_at', + // 'type', + // 'image', + // 'data', + // 'slug', + // 'description', + // 'amount', + // 'subtotal', + // 'total', + // 'lat', + // 'lng', + // 'address', + // 'state', + // 'country', + // 'city', + // 'order' + ]; + + if (count($custom_duplicate_names) > 0) + { + $duplicate_names = $custom_duplicate_names; + } + + foreach ($this->_allowed_fields as $key => $value) + { + if (in_array($value, $duplicate_names)) + { + $select_statement .= "`a`.{$value} as a_{$value}, `b`.{$value} as b_{$value}," ; + } + } + + $this->db->select($select_statement . ' `a`.*, `b`.*'); + $this->db->from($this->_table . ' a'); + $this->db->join($table . ' b', "a.{$field} = b.id"); + + if (!empty($where)) + { + foreach ($where as $key => $value) + { + if ($value === NULL) + { + continue; + } + + if (is_numeric($key) && strlen($value) < 1) + { + $this->db->where($value); + continue; + } + + if (is_numeric($key) && strlen($value) > 1) + { + $this->db->where($value); + continue; + } + + if ($value !== NULL) + { + $this->db->where($key, $value); + } + + } + } + + $result = []; + + $this->db->limit($limit, $page); + + if ($order_by === '') + { + $order_by = 'a_id'; + } + + $this->db->order_by($this->clean_alpha_num_field($order_by), $this->clean_alpha_field($direction)); + + $query = $this->db->get(); + foreach ($query->result() as $row) + { + $result[] = $row; + } + + return $result; + } + + /** + * Filter all keys before inserting to make sure they are allowed + * + * @param mixed $data + * @return mixed + */ + protected function _filter_allow_keys ($data) + { + $clean_data = []; + $allowed_fields = $this->_allowed_fields; + $allowed_fields[] = $this->_primary_key; + + if($this->_use_timestamps) + { + $allowed_fields[] = $this->_created_field; + $allowed_fields[] = $this->_updated_field; + } + + foreach ($data as $key => $val) + { + if (!in_array($key, $allowed_fields)) + { + continue; + } + $clean_data[$key] = $val; + } + return $clean_data; + } + + /** + * If you need to modify payload before create, overload this function + * + * @param mixed $data + * @return mixed + */ + protected function _pre_create_processing($data) + { + return $data; + } + + /** + * If you need to modify payload before edit, overload this function + * + * @param mixed $data + * @return mixed + */ + protected function _post_edit_processing($data) + { + return $data; + } + + /** + * Allow user to add extra counting condition so user don't have to change main function + * + * @param mixed $parameters + * @return $db + */ + protected function _custom_counting_conditions(&$db) + { + return $this->db; + } + + /** + * Escape data + * + * @param mixed $data + * @return mixed + */ + public function escape ($data) + { + return $this->db->escape($data); + } + + /** + * escapeLikeString data + * + * @param mixed $data + * @return mixed + */ + public function escapeLikeString ($data) + { + return $this->db->escapeLikeString($data); + } + + /** + * Get Last ID in table + * + * @return integer + */ + public function get_last_id() + { + $last = $this->db->order_by('id','desc') + ->limit(1) + ->get($this->_table) + ->row(); + + if ($last) + { + return (int)$last->id; + } + + return FALSE; + } + + /** + * Get Database Table Schema + * + * @return mixed + */ + public function get_schema() + { + return $this->db->field_data($this->_table); + } + + /** + * Get Type Mapping + * + * @param string $text + * @param string $database_expected_field + * @return boolean + */ + public function verify_field_type ($text, $database_expected_field) + { + $type_mapping = [ + 'string' => ['varchar', 'text', 'char', 'tinytext','mediumtext','longtext', 'binary', 'blob', 'enum'], + 'integer' => ['int', 'tinyint', 'bigint', 'mediumint', 'bit', 'timestamp', 'year'], + 'float' => ['float','decimal', 'double'], + 'date' => ['date'], + 'datetime' => ['datetime'], + 'time' => ['time'] + ]; + + $field_allow = $type_mapping['string']; + + if (in_array($database_expected_field, $type_mapping['string'])) + { + return TRUE; + } + + if (preg_match("/^[0-9]+$/i", $text)) + { + // $this->dl('integer', $text); + $field_allow = $type_mapping['integer']; + } + elseif (is_numeric($text)) + { + // $this->dl('float', $text); + $field_allow = $type_mapping['float']; + } + elseif ($this->validate_date($text, 'Y-m-d')) + { + // $this->dl('date', $text); + $field_allow = $type_mapping['date']; + } + elseif ($this->validate_date($text, 'Y-m-d H:i:s')) + { + // $this->dl('datetime', $text); + $field_allow = $type_mapping['datetime']; + } + elseif ($this->validate_date($text, 'H:i:s')) + { + // $this->dl('time', $text); + $field_allow = $type_mapping['time']; + } + + // $this->dl('keys', implode(',', $field_allow)); + + if (in_array($database_expected_field,$field_allow)) + { + return TRUE; + } + + return FALSE; + } + + /** + * Validate string matches date + * + * @param string $date + * @param string $format + * @return boolean + */ + protected function validate_date($date, $format = 'Y-m-d') + { + $d = DateTime::createFromFormat($format, $date); + return $d && $d->format($format) === $date; + } + + + protected function clean_alpha_num_field ($text) + { + return preg_replace("/[^0-9a-zA-Z\_%]/", "", $text ); + } + + protected function clean_alpha_field ($text) + { + return preg_replace("/[^a-zA-Z\_%]/", "", $text ); + } + + public function batch_update($params) + { + return $this->db->update_batch($this->_table, $params, 'id'); + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + + public function get_auto_increment_id() + { + $sql = $this->db->query('SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = "'. $this->db->database .'" AND TABLE_NAME = "'. $this->_table .'" '); + + return $sql->row()->AUTO_INCREMENT; + } + + public function log_activity($action, $now_data, $prev_data, $user_id) + { + $prev_data = json_decode(json_encode($prev_data), true); + $change_details = ''; + if(count($prev_data) > 0) + { + $change_details = 'Data changed from '. json_encode($prev_data) . ' to ' .json_encode($now_data); + } + else + { + $change_details = json_encode($now_data); + } + $operation_data = [ + 'user_id' => $user_id, + 'action' => $action, + 'detail' => $change_details, + 'created_at' => date('Y-m-j H:i:s'), + 'updated_at' => date('Y-m-j H:i:s') + ]; + $this->db->insert($this->_table, $operation_data); + } + + + + public function get_all_custom_where($custom_where = null,$where = array()) + { + $this->db->from($this->_table); + + foreach($where as $field => $value) + { + if (is_numeric($field) && strlen($value) > 0) + { + $this->db->where($value); + continue; + } + + if ($field === NULL && $value === NULL) + { + continue; + } + + if ($value !== NULL) + { + $this->db->where($this->clean_alpha_field($field), $value, TRUE); + } + } + + if($custom_where !=null){ + $this->db->where($custom_where); + } + + return $this->db->get()->result(); + } + + + + + + + + +} \ No newline at end of file diff --git a/application/core/Mapping.php b/application/core/Mapping.php new file mode 100755 index 0000000..f4f5360 --- /dev/null +++ b/application/core/Mapping.php @@ -0,0 +1,61 @@ + 'Inactive', + 1 => 'Active', + 2 => 'Suspend', + 3 => 'Pending', + ]; + } + + /** + * Status Mapping. + * + * @return array + */ + public function status_mapping() + { + return [ + 0 => 'Inactive', + 1 => 'Active', + ]; + } +} diff --git a/application/core/index.html b/application/core/index.html new file mode 100755 index 0000000..b702fbc --- /dev/null +++ b/application/core/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/factories/User_factory.php b/application/factories/User_factory.php new file mode 100755 index 0000000..bf019e2 --- /dev/null +++ b/application/factories/User_factory.php @@ -0,0 +1,146 @@ +_user_model = $user_model; + $this->_credential_model = $credential_model; + $this->_member_profile_model = $member_profile_model; + } + + /** + * @param object $user_model + */ + public function set_user_model($user_model) + { + $this->_user_model = $user_model; + } + + /** + * @param object $credential_model + */ + public function set_credential_model($credential_model) + { + $this->_credential_model = $credential_model; + } + + /** + * @param object member_profile_model + */ + public function set_member_profile_model($member_profile_model) + { + $this->_member_profile_model = $member_profile_model; + } + + /** + * Create User + * + * @param mixed $user_model + * @param string $email + * @param string $password + * @param integer $role + * @param string $type + * @return mixed + */ + public function create($user_model, $email, $password, $role, $type = 'n') + { + $credential_params = [ + 'email' => $email, + 'password' => str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)), + 'type' => $type ?? 'n', + 'verify' => 0, + 'role_id' => $role, + 'user_id' => 0, + 'status' => 1 + ]; + + $credential_id = $this->_credential_model->create($credential_params); + $existing_user_id = isset($_SESSION) && isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0; + + if ($type != 'n' && $existing_user_id) + { + $this->_credential_model->edit([ + 'user_id' => $_SESSION['user_id'] + ], $credential_id); + + return $_SESSION['user_id']; + } + + if ($credential_id) + { + $user_id = $this->_user_model->create([ + 'first_name' => '', + 'last_name' => '', + 'phone' => '', + 'image' => 'https://i.imgur.com/AzJ7DRw.png', + 'image_id' => 1, + 'refer' => uniqid(), + 'profile_id' => 0, + 'stripe_id' => '' + ]); + + $this->_credential_model->edit([ + 'user_id' => $user_id + ], $credential_id); + + return $user_id; + } + + return FALSE; + } + + public function create_full_user($user_model, $email, $password, $first_name, $last_name, $username, $role, $type = 'n') + { + $credential_params = [ + 'email' => $email, + 'password' => str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)), + 'type' => $type ?? 'n', + 'verify' => 0, + 'role_id' => $role, + 'user_id' => 0, + 'status' => 1 + ]; + + $credential_id = $this->_credential_model->create($credential_params); + + if ($credential_id) + { + $user_id = $this->_user_model->create([ + 'first_name' => $first_name, + 'last_name' => $last_name, + 'phone' => '', + 'image' => 'https://i.imgur.com/AzJ7DRw.png', + 'image_id' => 1, + 'refer' => uniqid(), + 'profile_id' => 0, + 'stripe_id' => '' + ]); + + $this->_credential_model->edit([ + 'user_id' => $user_id + ], $credential_id); + + $this->_member_profile_model->create([ + 'user_id' => $user_id, + 'username' => $username, + 'school_id' => 0 + ]); + + return $user_id; + } + return FALSE; + } +} diff --git a/application/factories/index.html b/application/factories/index.html new file mode 100755 index 0000000..b702fbc --- /dev/null +++ b/application/factories/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 0000000..b702fbc --- /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 0000000..b702fbc --- /dev/null +++ b/application/hooks/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 0000000..b702fbc --- /dev/null +++ b/application/language/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/language/spanish/README.md b/application/language/spanish/README.md new file mode 100755 index 0000000..d40c498 --- /dev/null +++ b/application/language/spanish/README.md @@ -0,0 +1,23 @@ +# CodeIgniter Spanish Pack +Paquete de idioma español del framework PHP CodeIgniter +Versión actual: 2.2.0 + +## Ficheros actuales: +* calendar_lang.php +* date_lang.php +* db_lang.php +* email_lang.php +* form_validation_lang.php +* ftp_lang.php +* imglib_lang.php +* migration_lang.php +* number_lang.php +* profiler_lang.php +* unit_test_lang.php +* upload_lang.php + +## Instalacion +* Descarga el paquete de idiomas +* Crea un directorio llamado 'spanish' dentro de application/languages de tu proyecto +* Copia los archivos descargados +* Modifica el lenguaje en tu archivo config.php de la siguiente manera $config['language'] = 'spanish'; diff --git a/application/language/spanish/calendar_lang.php b/application/language/spanish/calendar_lang.php new file mode 100755 index 0000000..5e3806e --- /dev/null +++ b/application/language/spanish/calendar_lang.php @@ -0,0 +1,51 @@ +_s3 = new S3Client([ + 'version' => $version, + 'region' => $region, + 'credentials' => [ + 'key' => $key, + 'secret' => $secret + ] + ]); + } + + public function set_image_model ($image_model) + { + $this->_image_model = $image_model; + } + + public function set_bucket ($bucket) + { + $this->_bucket = $bucket; + } + + public function delete_image ($image_id) + { + try + { + $model = $this->_image_model->get($image_id); + $url = $model->url; + + $this->delete_image_url($url); + $this->_image_model->real_delete($image_id); + return TRUE; + } + catch (AwsExceptionInterface $e) + { + // throw Exception\StorageException::deleteError($path, $e); + return FALSE; + } + } + + public function delete_image_url ($url) + { + try + { + $matches = []; + $re = '/\/com.nds.*\//m'; + preg_match_all($re, $url, $matches, PREG_SET_ORDER, 0); + if(count($matches) == 1 && count($matches[0]) == 1) + { + $bucket = str_replace('/','', $matches[0][0]); + $parts = explode('/', $url); + $key = $parts[count($parts) - 1]; + + $this->_s3->deleteObject(['Bucket' => $bucket, 'Key' => $key]); + } + return TRUE; + } + catch (AwsExceptionInterface $e) + { + // throw Exception\StorageException::deleteError($path, $e); + return FALSE; + } + } +} \ No newline at end of file diff --git a/application/libraries/Barcode_service.php b/application/libraries/Barcode_service.php new file mode 100755 index 0000000..215f805 --- /dev/null +++ b/application/libraries/Barcode_service.php @@ -0,0 +1,36 @@ +getBarcode($barcode, $generator::TYPE_CODE_128 ,3 , 50, $black_color); + + if(file_put_contents($file_name, $barcode)) + { + return $barcode_image_name; + } + } +} \ No newline at end of file diff --git a/application/libraries/Cache_service.php b/application/libraries/Cache_service.php new file mode 100755 index 0000000..7bda9ae --- /dev/null +++ b/application/libraries/Cache_service.php @@ -0,0 +1,81 @@ +_type = $type; + $this->_cache_time = $cache_time; + + switch ($type) + { + case 'file': + $this->_adapter = null; + break; + default: + break; + } + } + + /** + * Set cache Key + * + * @param string $key + * @param mixed $value + * @return void + */ + public function set($key, $value) + { + file_put_contents(__DIR__ . '/../config/' . md5($key) . '.json', json_encode($value)); + } + + public function get($key) + { + $file_path = __DIR__ . '/../config/' . md5($key) . '.json'; + + if (file_exists($file_path)) + { + if (time() - $this->_cache_time < filemtime($file_path)) + { + $data = file_get_contents($file_path); + return json_decode($data, TRUE); + } + else + { + unlink($file_path); + } + } + return NULL; + } + + public function remove($key) + { + $file_path = __DIR__ . '/../config/' . md5($key) . '.json'; + + if (file_exists($file_path)) + { + unlink($file_path); + return TRUE; + } + return NULL; + } +} \ No newline at end of file diff --git a/application/libraries/Csv_import_service.php b/application/libraries/Csv_import_service.php new file mode 100755 index 0000000..3f953ce --- /dev/null +++ b/application/libraries/Csv_import_service.php @@ -0,0 +1,265 @@ +_model = $model; + $this->_model_name = $model_name; + } + + /** + * CSV File Exist + * + * @param array $files + * @return boolean + */ + public function csv_file_exist($files) + { + return !(isset($files) && count($files) > 0 && isset($files['file'])); + } + + /** + * Make the import insert query + * Steps: + * 1.Figure out the last id + * 2.Find out schema + * 3.Loop through each line and make sure schema match + * 4.Else return error + * 5.If everything correct, dump sql out + * 6.Insert sql into database + * + * @param [type] $file + * @return void + */ + public function make_query($file) + { + $last_id = $this->_model->get_last_id(); + $schema = $this->_model->get_schema(); + $insert_query_template_start = "INSERT INTO `{$this->_model_name}` ("; + $insert_query_template_middle = ') VALUES '; + $line_num = 1; + $insert_query_list = []; + + foreach ($schema as $field_num => $field) + { + $field_list[] = "`$field->name`"; + } + + + $field_list_str = implode(',', $field_list); + $insert_query = "{$insert_query_template_start}{$field_list_str} {$insert_query_template_middle} "; + + + while (($getData = fgetcsv($file, 1000000, ';')) !== FALSE) + { + $valid = TRUE; + $field_list = []; + + if(count($getData) > 0) + { + $new_id = (int) $getData[0]; + } + else + { + return [ + 'status' => FALSE, + 'message' => 'Missing ID on Line ' . $line_num + ]; + } + if (!$getData) + { + // error_log('LINE FAILED ON: ' . $line_num); + return [ + 'status' => FALSE, + 'message' => 'Fail to get data on line ' . $line_num + ]; + } + + foreach ($schema as $field_num => $field) + { + // error_log("{$field_num} {$field->type} $getData[$field_num]\n"); + $valid = $valid && $this->_model->verify_field_type($getData[$field_num], $field->type); + + if (!$valid) + { + return [ + 'status' => FALSE, + 'message' => 'Fail to get data on line ' . $line_num . '. Field Type did not match ' . $field->name + ]; + } + } + + if ($new_id < $last_id) + { + return [ + 'status' => FALSE, + 'message' => 'Fail to get data on line ' . $line_num . '. Field ID conflict with another row ' . $new_id + ]; + } + + if ($valid) + { + $insert_query_list []= "('" . implode('\',\'', $getData) . "')"; + $field_list = []; + } + + $line_num++; + } + + return [ + 'status' => TRUE, + 'message' => $insert_query . implode(',', $insert_query_list) . ';' + ]; + } + + /** + * Take file, make array + * + * @param [type] $file + * @return void + */ + public function get_csv_data($file) + { + $line_num = 1; + $result = []; + $handle = fopen($file, "r"); + while (($getData = fgetcsv($handle, 1000000, ';')) !== FALSE) + { + $valid = TRUE; + + if(count($getData) > 0) + { + $new_id = (int) $getData[0]; + } + else + { + return [ + 'status' => FALSE, + 'message' => 'Missing ID on Line ' . $line_num + ]; + } + + if (!$getData) + { + // error_log('LINE FAILED ON: ' . $line_num); + return [ + 'status' => FALSE, + 'message' => 'Fail to get data on line ' . $line_num + ]; + } + + + if ($valid) + { + $result[] = $getData; + } + + $line_num++; + } + + return [ + 'status' => TRUE, + 'data' => $result + ]; + } + + public function import ($query) + { + return $this->_model->raw_no_error_query($query); + } + + + public function _import_data($file) + { + try + { + $reader = ReaderEntityFactory::createReaderFromFile( $file ); + $reader->open($file); + $import_fields = $this->_model->get_import_fields(); + + if(empty($import_fields)) + { + return false; + } + $payload = []; + + foreach ($reader->getSheetIterator() as $sheet) + { + foreach($sheet->getRowIterator() as $row) + { + + $cells = $row->getCells(); + $temp = []; + for($i = 0; $i < count($cells); $i ++) + { + $temp[ $import_fields[$i] ] = $cells[$i]->getValue(); + } + + $payload[] = $temp; + + } + } + + if(!empty($payload)) + { + return $this->_model->batch_insert($payload); + } + + return FALSE; + } + catch(Exception $e) + { + return FALSE; + } + } + + + public function _get_file_data($file) + { + + try + { + $reader = ReaderEntityFactory::createReaderFromFile( $file ); + $reader->open($file); + $payload = []; + + foreach ($reader->getSheetIterator() as $sheet) + { + foreach($sheet->getRowIterator() as $row) + { + + $cells = $row->getCells(); + $temp = []; + for($i = 0; $i < count($cells); $i ++) + { + $temp[] = $cells[$i]->getValue(); + } + + $payload[] = $temp; + + } + } + + return $payload; + } + catch(Exception $e) + { + return []; + } + } + +} \ No newline at end of file diff --git a/application/libraries/Helpers_service.php b/application/libraries/Helpers_service.php new file mode 100755 index 0000000..ded7ea6 --- /dev/null +++ b/application/libraries/Helpers_service.php @@ -0,0 +1,41 @@ +_inventory_model = $inventory_model; + } + + + + /** + * getters + */ + public function get_word_count($id) + { + $word_count = "N/A"; + $check_data = $this->_inventory_model->get($id); + if (isset($check_data->word_count)) + { + $word_count = $check_data->word_count; + } + return $word_count; + } + + public function get_year($id) + { + $year = "N/A"; + $check_data = $this->_inventory_model->get($id); + if (isset($check_data->year)) + { + $year = $check_data->year; + } + return $year; + } + +} diff --git a/application/libraries/Mail_service.php b/application/libraries/Mail_service.php new file mode 100755 index 0000000..0b808bc --- /dev/null +++ b/application/libraries/Mail_service.php @@ -0,0 +1,165 @@ +_type = $type; + $this->_ci = &get_instance(); + $this->_platform_name = $this->_ci->config->item('platform_name'); + + switch ($type) + { + case 'mailgun': + $this->_adapter = Mailgun::create($this->_ci->config->item('mailgun_key')); + $this->_domain = $this->_ci->config->item('mail_domain'); + break; + + case 'test': + break; + case 'smtp': + default: + $this->_ci->load->library('email'); + $settings = $this->_ci->config->item('email_smtp'); + + if (empty($settings)) + { + throw new Exception('Email not setup'); + } + $this->_from_name = $settings['smtp_name']; + $this->_adapter = $this->_ci->email->initialize($settings); + break; + } + } + + /** + * Set domain to send from (mailgun exclusive). + * + * @param string $domain + */ + public function setDomain($domain) + { + $this->_domain = $domain; + } + + /** + * Send email. + * + * @param string $from + * @param string $to + * @param string $subject + * @param string $html + */ + public function send($from, $to, $subject, $html, $reply_to = "") + { + switch ($this->_type) { + case 'mailgun': + return $this->_adapter->messages()->send($this->_domain, [ + 'from' => $from, + 'to' => $to, + 'subject' => $subject, + 'html' => $html, + ]); + break; + + case 'test': + return [ + 'from' => $from, + 'to' => $to, + 'subject' => $subject, + 'html' => $html + ]; + break; + + case 'smtp': + + default: + $this->_ci->load->library('encryption'); + $this->_adapter->to($to); + $this->_adapter->from($from, $this->_from_name); + $this->_adapter->subject($subject); + if ($reply_to != "" || $this->_ci->session->userdata('email') ) + { + $f_email = $this->_ci->session->userdata('email'); + if ($f_email && !empty($f_email) ) + { + $f_email = $this->_ci->session->userdata('email'); + $this->_adapter->reply_to($f_email); + }else + { + $this->_adapter->reply_to($reply_to); + } + + } + + $this->_adapter->message($html); + $result = $this->_adapter->send(); + + if (!$result) + { + // echo "
    ";
    +                    // // print_r($this->_adapter);
    +                    // print_r($this->_adapter->print_debugger());
    +                    // die();
    +                    error_log($this->_adapter->print_debugger());
    +                }
    +
    +                return $result;
    +
    +                break;
    +        }
    +    }
    +}
    diff --git a/application/libraries/Mime_service.php b/application/libraries/Mime_service.php
    new file mode 100755
    index 0000000..5833754
    --- /dev/null
    +++ b/application/libraries/Mime_service.php
    @@ -0,0 +1,94 @@
    + '.md',
    +        'audio/aac' => '.aac',
    +        'application/x-abiword' => '.abw',
    +        'application/x-freearc' => '.arc',
    +        'video/x-msvideo' => '.avi',
    +        'application/vnd.amazon.ebook' => '.azw',
    +        'application/octet-stream' => '.bin',
    +        'image/bmp' => '.bmp',
    +        'application/x-bzip' => '.bz',
    +        'application/x-bzip2' => '.bz2',
    +        'application/x-csh' => '.csh',
    +        'text/css' => '.css',
    +        'text/csv' => '.csv',
    +        'application/msword' => '.doc',
    +        'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => '.docx',
    +        'application/vnd.ms-fontobject' => '.eot',
    +        'application/epub+zip' => '.epub',
    +        'image/gif' => '.gif',
    +        'text/html' => '.html',
    +        'image/vnd.microsoft.icon' => '.ico',
    +        'text/calendar' => '.ics',
    +        'application/java-archive' => '.jar',
    +        'image/jpeg' => '.jpg',
    +        'image/jpg' => '.jpg',
    +        'text/javascript' => '.js',
    +        'application/json' => '.json',
    +        'application/ld+json' => '.jsonld',
    +        'audio/midi' => '.mid',
    +        'audio/x-midi' => '.midi',
    +        'text/javascript' => '.javascript',
    +        'audio/mp3' => '.mp3',
    +        'audio/mp4' => '.mp3',
    +        'audio/mpeg' => '.mp3',
    +        'video/mpeg' => '.mpeg',
    +        'application/vnd.apple.installer+xml' => '.mpkg',
    +        'application/vnd.oasis.opendocument.presentation' => '.odp',
    +        'application/vnd.oasis.opendocument.spreadsheet' => '.ods',
    +        'application/vnd.oasis.opendocument.text' => '.odt',
    +        'audio/ogg' => '.oga',
    +        'video/ogg' => '.ogv',
    +        'application/ogg' => '.ogx',
    +        'font/otf' => '.otf',
    +        'image/png' => '.png',
    +        'application/pdf' => '.pdf',
    +        'application/vnd.ms-powerpoint' => '.ppt',
    +        'application/vnd.openxmlformats-officedocument.presentationml.presentation' => '.pptx',
    +        'application/x-rar-compressed' => '.rar',
    +        'application/rtf' => '.rtf',
    +        'application/x-sh' => '.sh',
    +        'image/svg+xml' => '.svg',
    +        'application/x-shockwave-flash' => '.swf',
    +        'application/x-tar' => '.tar',
    +        'image/tiff' => '.tiff',
    +        'video/mp2t' => '.ts',
    +        'font/ttf' => '.ttf',
    +        'text/plain' => '.txt',
    +        'application/vnd.visio' => '.vsd',
    +        'audio/wav' => '.wav',
    +        'audio/webm' => '.weba',
    +        'video/webm' => '.webm',
    +        'image/webp' => '.webp',
    +        'font/woff' => '.woff',
    +        'font/woff2' => '.woff2',
    +        'application/xhtml+xml' => '.xhtml',
    +        'application/vnd.ms-excel' => '.xls',
    +        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => '.xlsx',
    +        'application/xml' => '.xml',
    +        'text/xml' => '.xml',
    +        'application/vnd.mozilla.xul+xml' => '.xul',
    +        'application/zip' => '.zip',
    +        'video/3gpp' => '.3pg',
    +        'audio/3gpp' => '.3gp',
    +        'video/3gpp2' => '.3g2',
    +        'audio/3gpp2' => '.3g2',
    +        'application/x-7z-compressed' => '.7z',
    +        'video/mp4' => '.mp4'
    +    ];
    +
    +    public function get_extension($type) {
    +
    +        if(in_array($type, array_keys($this->_types)))
    +        {
    +            return $this->_types[$type];
    +        }
    +
    +        return str_replace('/', '', $type);
    +    }
    +}
    \ No newline at end of file
    diff --git a/application/libraries/Names_helper_service.php b/application/libraries/Names_helper_service.php
    new file mode 100755
    index 0000000..7b0b57c
    --- /dev/null
    +++ b/application/libraries/Names_helper_service.php
    @@ -0,0 +1,98 @@
    +_user_model = $user_model;
    +  }
    +
    +  public function set_school_model($school_model)
    +  {
    +    $this->_school_model = $school_model;
    +  }
    +
    +  public function set_professor_model($professor_model)
    +  {
    +    $this->_professor_model = $professor_model;
    +  }
    +
    +  public function set_textbook_model($textbook_model)
    +  {
    +    $this->_textbook_model = $textbook_model;
    +  }
    +
    +  public function set_classes_model($classes_model)
    +  {
    +    $this->_classes_model = $classes_model;
    +  }
    +
    +  /**
    +   * getters
    +   */
    +  
    +  public function get_user_full_name($id)
    +  {
    +    $full_name  = "N/A";
    +    $check_data = $this->_user_model->get($id);
    +    if (isset($check_data->first_name))
    +    {
    +      $full_name = $check_data->first_name . ' ' . $check_data->last_name;
    +    }
    +    return $full_name;
    +  }
    +
    +  public function get_school_name($id)
    +  {
    +    $name  = "N/A";
    +    $check_data = $this->_school_model->get($id);
    +    if (isset($check_data->name))
    +    {
    +      $name = $check_data->name;
    +    }
    +    return $name;
    +  }
    +
    +  public function get_professor_name($id)
    +  {
    +    $name  = "N/A";
    +    $check_data = $this->_professor_model->get($id);
    +    if (isset($check_data->name))
    +    {
    +      $name = $check_data->name;
    +    }
    +    return $name;
    +  }
    +
    +  public function get_class_name($id)
    +  {
    +    $name  = "N/A";
    +    $check_data = $this->_classes_model->get($id);
    +    if (isset($check_data->name))
    +    {
    +      $name = $check_data->name;
    +    }
    +    return $name;
    +  }
    +
    +  public function get_textbook_name($id)
    +  {
    +    $name  = "N/A";
    +    $check_data = $this->_textbook_model->get($id);
    +    if (isset($check_data->name))
    +    {
    +      $name = $check_data->name;
    +    }
    +    return $name;
    +  }
    +
    +}
    diff --git a/application/libraries/Payment_service.php b/application/libraries/Payment_service.php
    new file mode 100755
    index 0000000..8d20e2d
    --- /dev/null
    +++ b/application/libraries/Payment_service.php
    @@ -0,0 +1,1248 @@
    +_stripe_client = new StripeClient($params['stripe_secret_key']);
    +    if (!empty($params['stripe_api_version']))
    +    {
    +      Stripe::setApiVersion($params['stripe_api_version']);
    +    }
    +    Stripe::setApiKey($params['stripe_secret_key']);
    +    $this->_api_secret_key  = $params['stripe_secret_key'] ?? "";
    +    $this->_api_publish_key = $params['stripe_publish_key'] ?? "";
    +  }
    +
    +  /**
    +   * Set sum time cents / dollars
    +   *
    +   * @param boolean $set_convert_to_cents
    +   * @return void
    +   */
    +  public function set_convert_to_cents($should_convert)
    +  {
    +    $this->_convert_to_cents = $should_convert;
    +  }
    +
    +  /**
    +   * Get covert to cents setting
    +   * @return boolean
    +   */
    +  public function get_convert_to_cents()
    +  {
    +    return $this->_convert_to_cents;
    +  }
    +
    +  /**
    +   * Create stripe customer by email and stripe token.
    +   *
    +   * @param array $customer_params
    +   * @return \Stripe\Customer|boolean
    +   */
    +  public function create_customer($customer_params)
    +  {
    +    //address
    +    $stripe_type   = 'customer_create';
    +    $args['email'] = $customer_params['email'];
    +
    +    if (isset($customer_params['source']) && $customer_params['source'] !== null)
    +    {
    +      $args['source'] = $customer_params['source'];
    +    }
    +
    +    if (isset($customer_params['customer']) && $customer_params['customer'] !== null)
    +    {
    +      $args['customer'] = $customer_params['customer'];
    +    }
    +
    +    if (isset($customer_params['description']) && $customer_params['description'] !== null)
    +    {
    +      $args['description'] = $customer_params['description'];
    +    }
    +
    +    if (isset($customer_params['metadata']) && $customer_params['metadata'] !== null)
    +    {
    +      $args['metadata'] = $customer_params['metadata'];
    +    }
    +
    +    if (isset($customer_params['name']) && $customer_params['name'] !== null)
    +    {
    +      $args['name'] = $customer_params['name'];
    +    }
    +
    +    if (isset($customer_params['payment_method']) && $customer_params['payment_method'] !== null)
    +    {
    +      $args['payment_method'] = $customer_params['payment_method'];
    +    }
    +
    +    if (isset($customer_params['phone']) && $customer_params['phone'] !== null)
    +    {
    +      $args['phone'] = $customer_params['phone'];
    +    }
    +
    +    if (isset($customer_params['shipping']) && $customer_params['shipping'] !== null)
    +    {
    +      $args['shipping'] = $customer_params['shipping'];
    +    }
    +    $result = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +
    +  }
    +
    +  /**
    +   * Retrieve the Customer from Stripe.
    +   *
    +   * @param string $customer_id
    +   * @return \Stripe\Customer
    +   */
    +
    +  public function update_customer_payment_method($customer_id, $source_id)
    +  {
    +    $result = $this->_stripe_client->customers->update(
    +      $customer_id,
    +      ['default_source' => $source_id]
    +    );
    +    return $result;
    +
    +  }
    +
    +  /**
    +   * Retrieve the Customer from Stripe.
    +   *
    +   * @param string $customer_id
    +   * @return \Stripe\Customer
    +   */
    +  public function retrieve_customer($customer_id)
    +  {
    +    $stripe_type = 'customer_retrieve';
    +    $result      = $this->stripe_master($stripe_type, $customer_id);
    +    return $result;
    +  }
    +
    +  /**
    +   * Create create charge by customer id.
    +   * @param array $$charge_params
    +   * @return \Stripe\Charge|boolean
    +   */
    +
    +  public function create_charge($charge_params)
    +  {
    +    $stripe_type = 'charge_create';
    +    $args        = [
    +      'amount'      => ($this->_convert_to_cents ? ($charge_params['amount'] * 100) : $charge_params['amount']),
    +      'currency'    => $charge_params['currency'],
    +      'description' => $charge_params['description']
    +    ];
    +
    +    if (isset($charge_params['customer']) && $charge_params['customer'] !== null)
    +    {
    +      $args['customer'] = $charge_params['customer'];
    +    }
    +
    +    if (isset($charge_params['payment_intent']) && $charge_params['payment_intent'] !== null)
    +    {
    +      $args['payment_intent'] = $charge_params['payment_intent'];
    +    }
    +
    +    if (isset($charge_params['metadata']) && $charge_params['metadata'] !== null)
    +    {
    +      $args['metadata'] = $charge_params['metadata'];
    +    }
    +
    +    if (isset($charge_params['source']) && $charge_params['source'] !== null)
    +    {
    +      $args['source'] = $charge_params['source'];
    +    }
    +
    +    if (isset($charge_params['statement_descriptor']) && $charge_params['statement_descriptor'] !== null)
    +    {
    +      $args['statement_descriptor'] = $charge_params['statement_descriptor'];
    +    }
    +
    +    if (isset($charge_params['receipt_email']) && $charge_params['receipt_email'] !== null)
    +    {
    +      $args['receipt_email'] = $charge_params['receipt_email'];
    +    }
    +
    +    if (isset($charge_params['statement_descriptor']) && $charge_params['statement_descriptor'] !== null)
    +    {
    +      $args['statement_descriptor'] = $charge_params['statement_descriptor'];
    +    }
    +
    +    if (isset($charge_params['statement_descriptor_suffix']) && $charge_params['statement_descriptor_suffix'] !== null)
    +    {
    +      $args['statement_descriptor_suffix'] = $charge_params['statement_descriptor_suffix'];
    +    }
    +
    +    $result = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  /**
    +   * Retrieve a charge.
    +   * @param string $charge_id
    +   * @return \Stripe\charge
    +   */
    +  public function retrieve_charge($charge_id)
    +  {
    +    $stripe_type = 'charge_retrieve';
    +    $result      = $this->stripe_master($stripe_type, $charge_id);
    +    return $result;
    +  }
    +
    +  /**
    +   * Create payment_method
    +   *
    +   * @param array $payment_method_params
    +   * @return \Stripe\PaymentMethod
    +   */
    +
    +  public function create_payment_method($payment_method_params)
    +  {
    +    $stripe_type = 'payment_method_create';
    +    $args        = [
    +      'type' => $payment_method_params['type']
    +    ];
    +
    +    if (isset($payment_method_params['card']) && !empty($payment_method_params['card']))
    +    {
    +      $args['card'] = $payment_method_params['card'];
    +    }
    +
    +    if (isset($payment_method_params['billing_details']) && !empty($payment_method_params['billing_details']))
    +    {
    +      $args['billing_details'] = $payment_method_params['billing_details'];
    +    }
    +
    +    if (isset($payment_method_params['au_becs_debit']) && !empty($payment_method_params['au_becs_debit']))
    +    {
    +      $args['au_becs_debit'] = $payment_method_params['au_becs_debit'];
    +    }
    +
    +    $result = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  /**
    +   * Create payment_method
    +   *
    +   * @param string $payment_method_id
    +   * @param string $stripe_customer_id
    +   * @return \Stripe\PaymentMethod
    +   */
    +  public function attach_payment_method($payment_method_id, $stripe_customer_id)
    +  {
    +    $stripe_type    = 'payment_method_retrieve';
    +    $payment_method = $this->stripe_master($stripe_type, $payment_method_id);
    +
    +    if (isset($payment_method['id']))
    +    {
    +      return $payment_method->attach([
    +        'customer' => $stripe_customer_id
    +      ]);
    +    }
    +
    +    return null;
    +
    +  }
    +
    +  /**
    +   * Create product .
    +   *
    +   * @param array $product_params
    +   * @return \Stripe\Product
    +   */
    +  public function create_product($product_params)
    +  {
    +    $stripe_type = 'product_create';
    +    $result      = $this->stripe_master($stripe_type, $product_params);
    +    return $result;
    +  }
    +
    +  public function update_product($product_params)
    +  {
    +    $stripe_type = 'product_update';
    +    $result      = $this->stripe_master($stripe_type, $product_params);
    +    return $result;
    +  }
    +  public function create_refund($refund_params)
    +  {
    +    $stripe_type = 'refund_create';
    +    $args        = [];
    +
    +    if (isset($refund_params['charge']) && $refund_params['charge'] !== null)
    +    {
    +      $args['charge'] = $refund_params['charge'];
    +    }
    +
    +    if (isset($refund_params['amount']) && $refund_params['amount'] !== null)
    +    {
    +      $args['amount'] = ($this->_convert_to_cents ? ($refund_params['amount'] * 100) : $refund_params['amount']);
    +    }
    +
    +    if (isset($refund_params['metadata']) && $refund_params['metadata'] !== null)
    +    {
    +      $args['metadata'] = $refund_params['metadata'];
    +    }
    +
    +    if (isset($refund_params['payment_intent']) && $refund_params['payment_intent'] !== null)
    +    {
    +      $args['payment_intent'] = $refund_params['payment_intent'];
    +    }
    +
    +    if (isset($refund_params['reason']) && $refund_params['reason'] !== null)
    +    {
    +      $args['reason'] = $refund_params['reason'];
    +    }
    +
    +    if (isset($refund_params['refund_application_fee']) && $refund_params['refund_application_fee'] !== null)
    +    {
    +      $args['refund_application_fee'] = $refund_params['refund_application_fee'];
    +    }
    +
    +    if (isset($refund_params['reverse_transfer']) && $refund_params['reverse_transfer'] !== null)
    +    {
    +      $args['reverse_transfer'] = $refund_params['reverse_transfer'];
    +    }
    +    $result = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  /**
    +   * Create card by customer ID and token.
    +   *
    +   * @param array $card_params
    +   * @return \Stripe\Card
    +   */
    +  public function create_card($card_params)
    +  {
    +    $stripe_type = 'card_create';
    +
    +    if (!empty($card_params['customer_stripe_id']) && !empty($card_params['source']))
    +    {
    +      return Customer::createSource($card_params['customer_stripe_id'], ['source' => $card_params['source']]);
    +    }
    +    return null;
    +  }
    +
    +  /**
    +   * retrieve card by customer ID and card ID.
    +   *
    +   * @param string $customer_id
    +   * @param string $card_id
    +   * @return \Stripe\Card
    +   */
    +  public function retrieve_card($customer_id, $card_id)
    +  {
    +    // $customer = $this->retrieve_customer($customer_id);
    +    // if (!$customer)
    +    // {
    +    //     return FALSE;
    +    // }
    +
    +    // $card = $customer->sources->retrieve($card_id);
    +    $card = Customer::retrieveSource($customer_id, $card_id);
    +    return $card;
    +  }
    +
    +  /**
    +   * delete card by customer ID and card ID.
    +   *
    +   * @param string $customer_id
    +   * @param string $card_id
    +   * @return \Stripe\Card
    +   */
    +  public function delete_card($customer_id, $card_id)
    +  {
    +    $customer = $this->retrieve_customer($customer_id);
    +    if (!$customer)
    +    {
    +      return false;
    +    }
    +
    +    $delete = $customer->sources->retrieve($card_id)->delete();
    +    return $delete;
    +  }
    +
    +  /**
    +   * Create File
    +   * @param array file_params
    +   * @return \Stripe\File|boolean
    +   */
    +  public function create_file($file_params)
    +  {
    +    if (!empty($file_params['path']) && !empty($file_params['purpose']))
    +    {
    +      $fp = fopen($file_params['path'], 'r');
    +      return File::create([
    +        'purpose' => $file_params['purpose'],
    +        'file'    => $fp
    +      ]);
    +    }
    +    return null;
    +  }
    +
    +  /**
    +   * Decodes json data received by webhook
    +   * @param json  event_params
    +   * @return \Stripe\Event|boolean
    +   */
    +  public function get_stripe_event($event_params)
    +  {
    +    $stripe_type = 'stripe_events';
    +    $result      = $this->stripe_master($stripe_type, $event_params);
    +    return $result;
    +  }
    +
    +  /**
    +   * Create Coupon.
    +   * @param array $coupon_params
    +   * @return \Stripe\Coupon|boolean
    +   */
    +  public function create_coupon($coupon_params)
    +  {
    +    $stripe_type = 'coupon_create';
    +
    +    $args = [
    +      'duration' => $coupon_params['duration']
    +    ];
    +
    +    if (isset($coupon_params['amount_off']) && !empty($coupon_params['amount_off']))
    +    {
    +      $args['amount_off'] = ($this->_convert_to_cents ? ($coupon_params['amount_off'] * 100) : $coupon_params['amount_off']);
    +    }
    +
    +    if (isset($coupon_params['currency']) && !empty($coupon_params['currency']))
    +    {
    +      $args['currency'] = $coupon_params['currency'];
    +    }
    +
    +    if (isset($coupon_params['duration_in_months']) && !empty($coupon_params['duration_in_months']))
    +    {
    +      $args['duration_in_months'] = $coupon_params['duration_in_months'];
    +    }
    +
    +    if (isset($coupon_params['metadata']) && !empty($coupon_params['metadata']))
    +    {
    +      $args['metadata'] = $coupon_params['metadata'];
    +    }
    +
    +    if (isset($coupon_params['name']) && !empty($coupon_params['name']))
    +    {
    +      $args['name'] = $coupon_params['name'];
    +    }
    +
    +    if (isset($coupon_params['percent_off']) && !empty($coupon_params['percent_off']))
    +    {
    +      $args['percent_off'] = $coupon_params['percent_off'];
    +    }
    +
    +    if (isset($coupon_params['max_redemptions']) && !empty($coupon_params['max_redemptions']))
    +    {
    +      $args['max_redemptions'] = $coupon_params['max_redemptions'];
    +    }
    +
    +    if (isset($coupon_params['redeem_by']) && !empty($coupon_params['redeem_by']))
    +    {
    +      $args['redeem_by'] = $coupon_params['redeem_by'];
    +    }
    +
    +    $result = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  public function retrieve_coupon($coupon_id)
    +  {
    +    $stripe_type = 'coupon_retrieve';
    +    $result      = $this->stripe_master($stripe_type, $coupon_id);
    +  }
    +
    +  public function create_plan($plan_params)
    +  {
    +    $stripe_type = "plan_create";
    +    $args        = [
    +      'amount'   => ($this->_convert_to_cents ? ($plan_params['amount'] * 100) : $plan_params['amount']),
    +      'currency' => $plan_params['currency'],
    +      'interval' => $plan_params['interval'],
    +      'product'  => $plan_params['product']
    +    ];
    +
    +    if (isset($plan_params['active']) && $plan_params['active'] !== null)
    +    {
    +      $args['active'] = $plan_params['active'];
    +    }
    +
    +    if (isset($plan_params['metadata']) && $plan_params['metadata'] !== null)
    +    {
    +      $args['metadata'] = $plan_params['metadata'];
    +    }
    +
    +    if (isset($plan_params['nickname']) && $plan_params['nickname'] !== null)
    +    {
    +      $args['nickname'] = $plan_params['nickname'];
    +    }
    +
    +    if (isset($plan_params['id']) && $plan_params['id'] !== null)
    +    {
    +      $args['id'] = $plan_params['id'];
    +    }
    +
    +    if (isset($plan_params['tiers']) && $plan_params['tiers'] !== null)
    +    {
    +      $args['tiers'] = $plan_params['tiers'];
    +    }
    +
    +    if (isset($plan_params['tiers_mode']) && $plan_params['tiers_mode'] !== null)
    +    {
    +      $args['tiers_mode'] = $plan_params['tiers_mode'];
    +    }
    +
    +    if (isset($plan_params['aggregate_usage']) && $plan_params['aggregate_usage'] !== null)
    +    {
    +      $args['aggregate_usage'] = $plan_params['aggregate_usage'];
    +    }
    +
    +    if (isset($plan_params['amount_decimal']) && $plan_params['amount_decimal'] !== null)
    +    {
    +      $args['amount_decimal'] = $plan_params['amount_decimal'];
    +    }
    +
    +    if (isset($plan_params['billing_scheme']) && $plan_params['billing_scheme'] !== null)
    +    {
    +      $args['billing_scheme'] = $plan_params['billing_scheme'];
    +    }
    +
    +    if (isset($plan_params['interval_count']) && $plan_params['interval_count'] !== null)
    +    {
    +      $args['interval_count'] = $plan_params['interval_count'];
    +    }
    +
    +    if (isset($plan_params['transform_usage']) && $plan_params['transform_usage'] !== null)
    +    {
    +      $args['transform_usage'] = $plan_params['transform_usage'];
    +    }
    +
    +    if (isset($plan_params['trial_period_days']) && $plan_params['trial_period_days'] !== null)
    +    {
    +      $args['trial_period_days'] = $plan_params['trial_period_days'];
    +    }
    +
    +    if (isset($plan_params['usage_type']) && $plan_params['usage_type'] !== null)
    +    {
    +      $args['usage_type'] = $plan_params['usage_type'];
    +    }
    +
    +    $result = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  /**
    +   * Retrieve plan by ID.
    +   *
    +   * @param string $plan_id
    +   * @return \Stripe\Plan|boolean
    +   */
    +  public function retrieve_plan($plan_id)
    +  {
    +    $stripe_type = 'plan_retrieve';
    +    $args        = $plan_id;
    +    $result      = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  /**
    +   * update plan by ID.
    +   *
    +   * @param string $plan_id
    +   * @param array $data
    +   * @return \Stripe\Plan|boolean
    +   */
    +
    +  public function update_plan($plan_id, $data)
    +  {
    +    //EOF validate provided parameters.
    +    $stripe_type     = 'plan_update';
    +    $args            = [];
    +    $args['plan_id'] = $plan_id;
    +    $args['data']    = $data;
    +    $result          = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  /**
    +   * List all disputes.
    +   *
    +   * @param array $dispute_params
    +   * @return \Stripe\Dispute|boolean
    +   */
    +  public function list_all_disputes($dispute_params)
    +  {
    +    $stripe_type = 'list_all_disputes';
    +    $args        = [];
    +
    +    if (isset($dispute_params['charge']) && $dispute_params['charge'] !== null)
    +    {
    +      $args['charge'] = $dispute_params['charge'];
    +    }
    +
    +    if (isset($dispute_params['payment_intent']) && $dispute_params['payment_intent'] !== null)
    +    {
    +      $args['payment_intent'] = $dispute_params['payment_intent'];
    +    }
    +
    +    if (isset($dispute_params['created']) && $dispute_params['created'] !== null)
    +    {
    +      $args['created'] = $dispute_params['created'];
    +    }
    +
    +    if (isset($dispute_params['ending_before']) && $dispute_params['ending_before'] !== null)
    +    {
    +      $args['ending_before'] = $dispute_params['ending_before'];
    +    }
    +
    +    if (isset($dispute_params['starting_after']) && $dispute_params['starting_after'] !== null)
    +    {
    +      $args['starting_after'] = $dispute_params['starting_after'];
    +    }
    +
    +    $result = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  /**
    +   * List all disputes.
    +   *
    +   * @param array $dispute_params
    +   * @return \Stripe\Dispute|boolean
    +   */
    +  public function update_disputes($dispute_params)
    +  {
    +
    +  }
    +
    +  /**
    +   * Create a subscription.
    +   *
    +   * @param array subscription_params
    +   * @return \Stripe\Subscription|boolean
    +   */
    +  public function create_subscription($subscription_params)
    +  {
    +    $stripe_type = 'subscription_create';
    +    $args        = [
    +      'customer' => $subscription_params['customer'],
    +      'items'    => [$subscription_params['items']]
    +    ];
    +
    +    if (isset($subscription_params['cancel_at_period_end']) && $subscription_params['cancel_at_period_end'] !== null)
    +    {
    +      $args['cancel_at_period_end'] = $subscription_params['cancel_at_period_end'];
    +    }
    +
    +    if (isset($subscription_params['default_payment_method']) && $subscription_params['default_payment_method'] !== null)
    +    {
    +      $args['default_payment_method'] = $subscription_params['default_payment_method'];
    +    }
    +
    +    if (isset($subscription_params['metadata']) && $subscription_params['metadata'] !== null)
    +    {
    +      $args['metadata'] = $subscription_params['metadata'];
    +    }
    +
    +    if (isset($subscription_params['application_fee_percent']) && $subscription_params['application_fee_percent'] !== null)
    +    {
    +      $args['application_fee_percent'] = $subscription_params['application_fee_percent'];
    +    }
    +
    +    if (isset($subscription_params['backdate_start_date']) && $subscription_params['backdate_start_date'] !== null)
    +    {
    +      $args['backdate_start_date'] = $subscription_params['backdate_start_date'];
    +    }
    +
    +    if (isset($subscription_params['billing_cycle_anchor']) && $subscription_params['billing_cycle_anchor'] !== null)
    +    {
    +      $args['billing_cycle_anchor'] = $subscription_params['billing_cycle_anchor'];
    +    }
    +
    +    if (isset($subscription_params['billing_thresholds']) && $subscription_params['billing_thresholds'] !== null)
    +    {
    +      $args['billing_thresholds'] = $subscription_params['billing_thresholds'];
    +    }
    +
    +    if (isset($subscription_params['cancel_at']) && $subscription_params['cancel_at'] !== null)
    +    {
    +      $args['cancel_at'] = $subscription_params['cancel_at'];
    +    }
    +
    +    if (isset($subscription_params['collection_method']) && $subscription_params['collection_method'] !== null)
    +    {
    +      $args['collection_method'] = $subscription_params['collection_method'];
    +    }
    +
    +    if (isset($subscription_params['coupon']) && $subscription_params['coupon'] !== null)
    +    {
    +      $args['coupon'] = $subscription_params['coupon'];
    +    }
    +
    +    if (isset($subscription_params['days_until_due']) && $subscription_params['days_until_due'] !== null)
    +    {
    +      $args['days_until_due'] = $subscription_params['days_until_due'];
    +    }
    +
    +    if (isset($subscription_params['default_source']) && $subscription_params['default_source'] !== null)
    +    {
    +      $args['default_source'] = $subscription_params['default_source'];
    +    }
    +
    +    if (isset($subscription_params['default_tax_rates']) && $subscription_params['default_tax_rates'] !== null)
    +    {
    +      $args['default_tax_rates'] = $subscription_params['default_tax_rates'];
    +    }
    +
    +    if (isset($subscription_params['off_session']) && $subscription_params['off_session'] !== null)
    +    {
    +      $args['off_session'] = $subscription_params['off_session'];
    +    }
    +
    +    if (isset($subscription_params['payment_behavior']) && $subscription_params['payment_behavior'] !== null)
    +    {
    +      $args['payment_behavior'] = $subscription_params['payment_behavior'];
    +    }
    +
    +    if (isset($subscription_params['pending_invoice_item_interval']) && $subscription_params['pending_invoice_item_interval'] !== null)
    +    {
    +      $args['pending_invoice_item_interval'] = $subscription_params['pending_invoice_item_interval'];
    +    }
    +
    +    if (isset($subscription_params['proration_behavior']) && $subscription_params['proration_behavior'] !== null)
    +    {
    +      $args['proration_behavior'] = $subscription_params['proration_behavior'];
    +    }
    +
    +    if (isset($subscription_params['trial_end']) && $subscription_params['trial_end'] !== null)
    +    {
    +      $args['trial_end'] = $subscription_params['trial_end'];
    +    }
    +
    +    if (isset($subscription_params['trial_from_plan']) && $subscription_params['trial_from_plan'] !== null)
    +    {
    +      $args['trial_from_plan'] = $subscription_params['trial_from_plan'];
    +    }
    +
    +    if (isset($subscription_params['trial_period_days']) && $subscription_params['trial_period_days'] !== null)
    +    {
    +      $args['trial_period_days'] = $subscription_params['trial_period_days'];
    +    }
    +
    +    $result = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  /**
    +   * Retrieve a subscription.
    +   *
    +   * @param string $subscription_id
    +   * @return \Stripe\Subscription|boolean
    +   */
    +  public function retrieve_subscription($subscription_id)
    +  {
    +    $stripe_type = 'subscription_retrieve';
    +    $args        = $subscription_id;
    +    $result      = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  /**
    +   * Cancel a subscription.
    +   *
    +   * @param string $subscription_id
    +   * @param boolean $force_cancel
    +   * @param array $cancellation_params
    +   * @return \Stripe\Subscription|boolean
    +   */
    +  public function cancel_subscription($subscription_id, $force_cancel = false, $cancellation_params = [])
    +  {
    +    $subscription = $this->retrieve_subscription($subscription_id);
    +
    +    if ($force_cancel)
    +    {
    +      // $result = $subscription->delete($cancellation_params);
    +      $cancellation_args = [
    +        'subscription_id' => $subscription_id,
    +        'params'          => $cancellation_params
    +      ];
    +
    +      $result = $this->stripe_master('subscription_cancel', $cancellation_args);
    +    }
    +    else
    +    {
    +      $subscription->cancel_at_period_end = true;
    +      $result                             = $subscription->save();
    +    }
    +    return $result;
    +  }
    +
    +  /**
    +   * Reactivate a subscription.
    +   *
    +   * @param string $subscription_id
    +   * @return \Stripe\Subscription|boolean
    +   */
    +  public function reactivate_subscription($subscription_id)
    +  {
    +    $subscription = $this->retrieve_subscription($subscription_id);
    +    if (!$subscription)
    +    {
    +      return false;
    +    }
    +    $subscription->cancel_at_period_end = false;
    +    $result                             = $subscription->save();
    +    return $result;
    +  }
    +
    +  /**
    +   * Update a subscription.
    +   *
    +   * @param string $subscription_id
    +   * @param array $update_data
    +   * @return \Stripe\Subscription|boolean
    +   */
    +  public function update_subscription($subscription_id, $update_data, $default_source = '')
    +  {
    +    $stripe_type = 'subscription_update';
    +    $args        = [
    +      'subscription_id' => $subscription_id,
    +      'data'            => $update_data
    +    ];
    +
    +    if (!empty($default_source))
    +    {
    +      $args['default_source'] = $default_source;
    +    }
    +    $result = $this->stripe_master($stripe_type, $args);
    +    return $result;
    +  }
    +
    +  /**
    +   * Upgrading or Downgrading Plan in a subscription.
    +   *
    +   * @param string $subscription_id
    +   * @param string $plan_id
    +   * @param boolean $prorate
    +   * @return \Stripe\Subscription|boolean
    +   */
    +  public function update_subscription_plan($subscription_id, $plan_id, $prorate = false, $default_source = '', $coupon_id = 0)
    +  {
    +    $subscription = $this->retrieve_subscription($subscription_id);
    +    if (!$subscription)
    +    {
    +      return false;
    +    }
    +
    +    $proration_date = time();
    +
    +    $stripe_type = 'subscription_update';
    +
    +    //cancel trial time if subscription is running in trial
    +    if ($subscription->status == 'trialing')
    +    {
    +      $trial_end_data = [
    +        'subscription_id' => $subscription_id,
    +        'data'            => [
    +          'trial_end' => 'now'
    +        ]
    +      ];
    +      $trial_end_result = $this->stripe_master($stripe_type, $trial_end_data);
    +      if (!$trial_end_result)
    +      {
    +        return false;
    +      }
    +    }
    +    //EOF cancel trial time if subscription is running in trial
    +
    +    $args['subscription_id'] = $subscription_id;
    +    $items                   = [
    +      [
    +        'id'   => $subscription->items->data[0]->id,
    +        'plan' => $plan_id
    +      ]
    +    ];
    +
    +    $args['data'] = [
    +      'cancel_at_period_end' => false,
    +      'items'                => $items
    +    ];
    +
    +    if ($coupon_id !== 0)
    +    {
    +      $args['data']['coupon'] = $coupon_id;
    +    }
    +
    +    if ($prorate === false)
    +    {
    +      $args['data']['proration_behavior'] = 'none';
    +    }
    +    else
    +    {
    +      $args['data']['proration_behavior'] = 'create_prorations';
    +    }
    +    $result = $this->stripe_master($stripe_type, $args);
    +
    +    //Immediately send invoice if $prorate is not FALSE
    +    if ($prorate != false && $result)
    +    {
    +      $stripe_type = 'invoice_upcoming';
    +      $args        = [
    +        'customer'                    => $subscription->customer,
    +        'subscription'                => $subscription_id,
    +        'subscription_items'          => $items,
    +        'subscription_proration_date' => $proration_date
    +      ];
    +
    +      $invoice_upcoming_result = $this->stripe_master($stripe_type, $args);
    +      if (!$invoice_upcoming_result)
    +      {
    +        return false;
    +      }
    +    }
    +    // update payment method
    +    if (!empty($default_source))
    +    {
    +      $args['default_source'] = $default_source;
    +    }
    +    //EOF immediately send invoice if $prorate is not FALSE
    +    return $result;
    +  }
    +
    +  /**
    +   * Upgrading or Downgrading Plan in a subscription.
    +   *
    +   * @param string $invoice_id
    +   * @return \Stripe\Invoice|boolean
    +   */
    +  public function send_reminder_invoice($invoice_id)
    +  {
    +    $stripe_type = 'invoice_retrieve';
    +    $invoice     = $this->stripe_master($stripe_type, $invoice_id);
    +    return $invoice->sendInvoice();
    +  }
    +
    +  public function create_price($args)
    +  {
    +    $stripe_type = 'price_create';
    +    return $this->stripe_master($stripe_type, $args);
    +  }
    +
    +  public function retrieve_price($args)
    +  {
    +    $stripe_type = 'price_retrieve';
    +    return $this->stripe_master($stripe_type, $args);
    +  }
    +
    +  public function create_session($args)
    +  {
    +    $stripe_type = 'session_create';
    +    return $this->stripe_master($stripe_type, $args);
    +  }
    +  /**
    +   * Make actual call to stripe API
    +   *
    +   * @param string $stripe_type
    +   * @param mixed $args
    +   * @return mixed
    +   */
    +  protected function stripe_master($stripe_type, $args)
    +  {
    +    try
    +    {
    +      switch ($stripe_type)
    +      {
    +        case 'customer_create':
    +          $return = Customer::create($args);
    +          break;
    +        case 'customer_retrieve':
    +          $return = Customer::retrieveSource($args);
    +          break;
    +        case 'customer_all':
    +          $return = Customer::all($args);
    +          break;
    +
    +        case 'product_create':
    +          $return = $this->_stripe_client->products->create($args);
    +          break;
    +        case 'product_update':
    +          $product_id = $args['product_id'];
    +          $params     = $args['params'];
    +          $return     = $this->_stripe_client->products->update($product_id, $params);
    +          break;
    +
    +        case 'charge_create':
    +          $return = $this->_stripe_client->charges->create($args);
    +          break;
    +        case 'charge_retrieve':
    +          $return = Charge::retrieve($args);
    +          break;
    +        case 'charge_all':
    +          $return = Charge::all($args);
    +          break;
    +
    +        case 'refund_create':
    +          $return = Refund::create($args);
    +          break;
    +        case 'refund_retrieve':
    +          $return = Refund::retrieve($args);
    +          break;
    +        case 'refund_all':
    +          $return = Refund::all($args);
    +          break;
    +
    +        case 'price_create':
    +          $return = $this->_stripe_client->prices->create($args);
    +          break;
    +        case 'price_retrieve':
    +          $return = $this->_stripe_client->prices->retrieve($args);
    +          break;
    +        case 'plan_create':
    +          $return = Plan::create($args);
    +          break;
    +        case 'plan_retrieve':
    +          $return = Plan::retrieve($args);
    +          break;
    +        case 'plan_update':
    +          $return = Plan::retrieve($args['plan_id']);
    +          foreach ($args['data'] as $key => $value)
    +          {
    +            $return->$key = $value;
    +          }
    +          $return->save();
    +          break;
    +
    +        case 'subscription_create':
    +          $return = $this->_stripe_client->subscriptions->create($args);
    +          break;
    +        case 'subscription_retrieve':
    +          $return = Subscription::retrieve($args);
    +          break;
    +        case 'subscription_update':
    +          $return = Subscription::update($args['subscription_id'], $args['data']);
    +          break;
    +        case 'subscription_cancel':
    +          $return = $this->_stripe_client->subscriptions->cancel($args['subscription_id'], $args['params']);
    +          break;
    +
    +        case 'coupon_create':
    +          $return = Coupon::create($args);
    +          break;
    +        case 'coupon_retrieve':
    +          $return = Coupon::retrieve($args);
    +          break;
    +        case 'coupon_update':
    +          $return = Coupon::create($args);
    +          break;
    +
    +        case 'invoice_create':
    +          $return = Invoice::create($args);
    +          break;
    +        case 'invoice_retrieve':
    +          $return = Invoice::retrieve($args);
    +          break;
    +        case 'list_all_invoices':
    +          $return = Invoice::all($args);
    +          break;
    +        case 'invoice_upcoming':
    +          $return = Invoice::upcoming($args);
    +          break;
    +
    +        case 'session_create':
    +          $return = $this->_stripe_client->checkout->sessions->create($args);
    +          break;
    +
    +        case 'source_create':
    +          $return = Source::create($args);
    +          break;
    +
    +        case 'dispute_retrieve':
    +          $return = Dispute::retrieve($args);
    +          break;
    +
    +        case 'list_all_disputes':
    +          $return = Dispute::all($args);
    +          break;
    +
    +        case 'stripe_events':
    +          $return = Event::constructFrom(json_decode($args, true));
    +          break;
    +
    +        case 'payment_method_create':
    +          $return = PaymentMethod::create($args);
    +          break;
    +        case 'payment_method_retrieve':
    +          $return = PaymentMethod::retrieve($args);
    +          break;
    +
    +      }
    +      return $return;
    +    }
    +    catch (\Stripe\Exception\CardException $e)
    +    {
    +      $this->_error_msg = $e->getError()->message;
    +      $this->_api_error = true;
    +      log_message('error', 'Since it\'s a decline, \Stripe\Exception\CardException will be caught');
    +      $this->error_handler($e);
    +    }
    +    catch (\Stripe\Exception\RateLimitException $e)
    +    {
    +      $this->_error_msg = $e->getError()->message;
    +      $this->_api_error = true;
    +      log_message('error', 'Too many requests made to the API too quickly');
    +      $this->error_handler($e);
    +    }
    +    catch (\Stripe\Exception\InvalidRequestException $e)
    +    {
    +      $this->_error_msg = $e->getError()->message;
    +      $this->_api_error = true;
    +      log_message('error', 'Invalid parameters were supplied to Stripe\'s API');
    +      $this->error_handler($e);
    +    }
    +    catch (\Stripe\Exception\AuthenticationException $e)
    +    {
    +      $this->_error_msg = $e->getError()->message;
    +      $this->_api_error = true;
    +      log_message('error', 'Authentication with Stripe\'s API failed maybe you changed API keys recently');
    +      $this->error_handler($e);
    +    }
    +    catch (\Stripe\Exception\ApiConnectionException $e)
    +    {
    +      $this->_error_msg = $e->getError()->message;
    +      $this->_api_error = true;
    +      log_message('error', 'Network communication with Stripe failed');
    +      $this->error_handler($e);
    +    }
    +    catch (\Stripe\Exception\ApiErrorException $e)
    +    {
    +      $this->_error_msg = $e->getError()->message;
    +      $this->_api_error = true;
    +      log_message('error', 'Display a very generic error to the user, and maybe send  yourself an email');
    +      $this->error_handler($e);
    +    }
    +    catch (\Stripe\Exception\UnexpectedValueException $e)
    +    {
    +      $this->_error_msg = $e->getError()->message;
    +      $this->_api_error = true;
    +      log_message('error', 'Stripe webhook exception');
    +      $this->error_handler($e);
    +    }
    +    catch (\Exception $e)
    +    {
    +      $this->_error_msg = $e->getMessage();
    +      $this->_api_error = true;
    +      log_message('error', 'Something else happened, completely unrelated to Stripe');
    +      $this->error_handler($e);
    +    }
    +
    +    return false;
    +  }
    +
    +  /**
    +   * error log in 
     tag.
    +   *
    +   * @param string $error_text
    +   * @return formatted error text with 
     tag.
    +   */
    +  public function pre_log($error_text)
    +  {
    +    log_message('error', '
    ' . print_r($error_text, true) . '
    '); + } + + /** + * Handle display an errors. + * + * @param $error + */ + private function error_handler($error) + { + log_message('error', print_r($error, true)); + $this->pre_log('Status is:' . $e->getHttpStatus() . "\n"); + + if (isset($e->getError()->code)) + { + $this->pre_log('Code is:' . $e->getError()->code . "\n"); + } + + if (isset($e->getError()->type)) + { + $this->pre_log('Type is:' . $e->getError()->type . "\n"); + } + + if (isset($e->getError()->param)) + { + $this->pre_log('Param is:' . $e->getError()->param . "\n"); + } + + $this->pre_log('Message is:' . $e->getError()->message . "\n"); + } +} diff --git a/application/libraries/Push_notification_service.php b/application/libraries/Push_notification_service.php new file mode 100755 index 0000000..ca70e6a --- /dev/null +++ b/application/libraries/Push_notification_service.php @@ -0,0 +1,222 @@ +_url = 'https://fcm.googleapis.com/fcm/send'; + $this->_ci = &get_instance(); + $this->_server_key = $this->_ci->config->item('push_server_key'); + $this->_project_id = $this->_ci->config->item('push_project_id'); + } + + /** + * Send push notification + * https://firebase.google.com/docs/cloud-messaging/admin/send-messages. + * + * @param string $device_type + * @param string $device_id + * @param string $title + * @param string $message + * @param string $image + */ + + private function _send_request($fields) + { + $headers = [ + 'Content-Type:application/json', 'project_id:' . $this->_project_id, + 'Authorization:key=' . $this->_server_key, + ]; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->_url); + curl_setopt($ch, CURLOPT_POST, TRUE); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); + curl_exec($ch); + curl_close($ch); + + return $ch; + } + + + + public function send($device_type, $device_id, $title, $message, $image = '', $data = []) + { + $payload = []; + $fields = [ + 'registration_ids' => [ + $device_id + ], + + 'notification' => [ + 'title' => $title, + 'body' => $message + ], + ]; + + if ($device_type == 'ANDROID') + { + $fields = [ + 'registration_ids' => [ + $device_id + ], + + 'data' => [ + 'title' => $title, + 'message' => $message, + 'image' => $image, + "channelId" => "default", + "data" => $data + ], + + 'notification' => [ + 'title' => $title, + 'body' => $message + ] + ]; + + if(!empty($data) && is_array($data)) + { + $fields['data'] = array_merge( $fields['data'], $data); + } + } + + if($device_type == 'IOS') + { + $notification =[ + 'title' =>$title , + 'text' => $message, + 'sound' => 'default', + 'badge' => '0' + ]; + + $fields = [ + 'to' => $device_id, + 'notification' => $notification, + 'priority' => 'high', + 'data' => $data + ]; + + } + + $headers = [ + 'Content-Type:application/json', 'project_id:' . $this->_project_id, + 'Authorization:key=' . $this->_server_key, + ]; + + $payload['headers'] = $headers; + $payload['fields'] = $fields; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->_url); + curl_setopt($ch, CURLOPT_POST, TRUE); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); + curl_exec($ch); + curl_close($ch); + return $ch; + } + + + public function send_multiple($devices, $title, $message, $image = '', $data = []) + { + $ios_ids = []; + $android_ids = []; + + foreach($devices as $device) + { + if($device['type'] == 'ANDROID') + { + $android_ids[] = $device['device_id']; + } + + if($device['type'] == 'IOS') + { + $ios_ids[] = $device['device_id']; + } + } + + if(count($android_ids) > 0) + { + $fields = [ + 'registration_ids' => $android_ids, + 'data' => [ + 'title' => $title, + 'message' => $message, + 'image' => $image, + "channelId" => "default", + "data" => $data + ], + 'notification' => [ + 'title' => $title, + 'body' => $message + ] + ]; + + if(!empty($data) && is_array($data)) + { + $fields['data'] = array_merge($fields['data'], $data); + } + + $this->_send_request($fields); + } + + if(count($ios_ids) > 0) + { + $notification =[ + 'title' =>$title , + 'text' => $message, + 'sound' => 'default', + 'badge' => '0' + ]; + + $fields = [ + 'to' => $ios_ids, + 'notification' => $notification, + 'priority' => 'high', + 'data' => $data + ]; + + $this->_send_request($fields); + } + } +} \ No newline at end of file diff --git a/application/libraries/Redirect_custom_service.php b/application/libraries/Redirect_custom_service.php new file mode 100755 index 0000000..518c9b5 --- /dev/null +++ b/application/libraries/Redirect_custom_service.php @@ -0,0 +1,54 @@ +_url_redirect_model = $url_redirect_model; + } + + public function check_redirect() + { + $current_url = current_url(); + $params = $_SERVER['QUERY_STRING']; + + if(!empty($params)) + { + $full_url = $current_url . '?' . $params; + } + else + { + $full_url = $current_url; + } + + $check_data =$this->_url_redirect_model->get_by_fields([ + 'url' => $full_url + ]); + + if(!empty($check_data)) + { + $rewrite_url = $this->add_http($check_data->rewrite_url); + return redirect($rewrite_url); + } + } + + public function add_http($url) + { + if (!preg_match("~^(?:f|ht)tps?://~i", $url)) + { + $url = 'https://' . $url; + } + + return $url; + } +} \ No newline at end of file diff --git a/application/libraries/Slug_service.php b/application/libraries/Slug_service.php new file mode 100755 index 0000000..ab882fb --- /dev/null +++ b/application/libraries/Slug_service.php @@ -0,0 +1,20 @@ +_type = $type; + $this->_ci = &get_instance(); + $this->_from = $this->_ci->config->item('twilio_phone_number'); + + switch ($type) + { + case 'sms': + $this->_adapter = new Client($this->_ci->config->item('twilio_sid'), $this->_ci->config->item('twilio_token')); + break; + + case 'whatsapp': + // Your Account Sid and Auth Token from twilio.com/user/account + $this->_adapter = new Client($this->_ci->config->item('twilio_sid'), $this->_ci->config->item('twilio_token')); + case 'test': + break; + default: + break; + } + } + + /** + * Send email + * + * @param string $to + * @param string $message + */ + public function send ($to, $message) + { + switch ($this->_type) + { + case 'sms': + try { + $result = $this->_adapter->messages->create( + "{$to}", + [ + 'from' => "{$this->_from}", + 'body' => $message, + ] + ); + error_log('TO: ' . $to); + error_log('Message: ' . $message); + error_log('Result: ' . $result); + if (!$result || !$result->sid) + { + return NULL; + } + // error_log(print_r($result, TRUE)); + return $result->sid; + } catch (Exception $e) { + error_log('TO: ' . $to); + error_log('Message: ' . $message); + error_log('SMS Error: ' . $e->getMessage()); + return FALSE; + } + break; + + case 'test': + return TRUE; + break; + + case 'whatsapp': + try { + $result = $this->_adapter->messages->create( + "whatsapp:{$to}", + [ + 'from' => "whatsapp:{$this->_from}", + 'body' => $message, + ] + ); + error_log('TO: ' . $to); + error_log('Message: ' . $message); + error_log('Result: ' . $result); + return TRUE; + } catch (Exception $e) { + error_log('TO: ' . $to); + error_log('Message: ' . $message); + error_log('SMS Error: ' . $e->getMessage()); + return FALSE; + } + break; + default: + break; + } + + } + + /** + * Send email + * + * @param string $to + * @param string $message + */ + public function send_callback ($to, $message, $callback_url) + { + switch ($this->_type) + { + case 'sms': + try { + $result = $this->_adapter->messages->create( + "{$to}", + [ + 'from' => "{$this->_from}", + 'body' => $message, + 'statusCallback' => $callback_url + ] + ); + error_log('TO: ' . $to); + error_log('Message: ' . $message); + error_log('Result: ' . $result); + if (!$result || !$result->sid) + { + return NULL; + } + // error_log(print_r($result, TRUE)); + return $result->sid; + } catch (Exception $e) { + error_log('TO: ' . $to); + error_log('Message: ' . $message); + error_log('SMS Error: ' . $e->getMessage()); + return FALSE; + } + break; + + case 'test': + return TRUE; + break; + + case 'whatsapp': + try { + $result = $this->_adapter->messages->create( + "whatsapp:{$to}", + [ + 'from' => "whatsapp:{$this->_from}", + 'body' => $message, + ] + ); + error_log('TO: ' . $to); + error_log('Message: ' . $message); + error_log('Result: ' . $result); + return TRUE; + } catch (Exception $e) { + error_log('TO: ' . $to); + error_log('Message: ' . $message); + error_log('SMS Error: ' . $e->getMessage()); + return FALSE; + } + break; + default: + break; + } + + } + + public function retrieve_single_sms_log ($sid) + { + return $this->_adapter->messages($sid)->fetch(); + } + + public function add_country_code ($country_code=1, $phone_number) + { + $str_phone = (string) $phone_number; + + if (substr($str_phone, 0, $country_code) === $country_code) + { + return '+' . $phone_number; + } + else + { + return '+' . $country_code . $phone_number; + } + } + public function add_custom_country_code ($country_code=1, $phone_number) + { + + $str_phone = (string) $phone_number; + + if (substr($str_phone, 0, $country_code) === $country_code) + { + return '+' . $phone_number; + } + else + { + return '+' . $country_code . $phone_number; + } + } +} \ No newline at end of file diff --git a/application/libraries/Stripe_ach_invoice_service.php b/application/libraries/Stripe_ach_invoice_service.php new file mode 100755 index 0000000..064928d --- /dev/null +++ b/application/libraries/Stripe_ach_invoice_service.php @@ -0,0 +1,105 @@ +_config = $config; + } + + public function send_ach_invoice_sale_order($customer_real_name, $customer_email, $customer_phone, $total, $days_until_due) + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + Stripe::setApiKey( $stripe_secret_key ); + try + { + $customer = Customer::create([ + 'name' => $customer_real_name, + 'email' => $customer_email, + 'description' => $customer_phone, + ]); + + $amount = $total * 100; + + try + { + $invoice_item = InvoiceItem::create([ + 'amount' => $amount, + 'currency' => 'usd', + 'customer' => $customer->id, + 'description' => 'Sale Order Invoice' + ]); + + if ($invoice_item) + { + try + { + // pulls in invoice items + $invoice_detail = Invoice::create(array( + 'customer' => $customer->id, + 'collection_method' => 'send_invoice', + 'days_until_due' => $days_until_due, + )); + + try + { + + $output['invoice_id'] = $invoice_detail->id; + return $output; + + // Invoice::sendInvoice(array($invoice_detail->id)); + } + catch (Exception $e) + { + $output['error'] = $e; + return $output; + } + // # status (error: 0, success: 1) + // echo json_encode(['status' => 1]); + // exit(); + } catch (Exception $e) + { + $output['error'] = $e; + return $output; + } + } + else + { + $output['error'] = $e; + return $output; + } + } + catch (Exception $e) + { + $output['error'] = $e; + return $output; + } + } + catch (Exception $e) + { + $output['error'] = $e; + return $output; + } + } +} +?> \ No newline at end of file diff --git a/application/libraries/Stripe_helper_service.php b/application/libraries/Stripe_helper_service.php new file mode 100755 index 0000000..24f25b3 --- /dev/null +++ b/application/libraries/Stripe_helper_service.php @@ -0,0 +1,1910 @@ +_config = $config; + } + + /** + * @param $user_model + */ + public function set_user_model($user_model) + { + $this->_user_model = $user_model; + } + + /** + * @param $user_card_model + */ + public function set_user_card_model($user_card_model) + { + $this->_user_card_model = $user_card_model; + } + + /** + * @param $charge_id + * @param $reason + * @param $explanation + * @return mixed + */ + public function create_dispute($charge_id, $reason = '', $explanation = '') + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + if ($charge_id && $reason && $explanation) + { + try { + $response = $stripe->issuing->disputes->create([ + 'transaction' => $charge_id, + 'evidence' => [ + 'reason' => $reason, + $reason => [ + 'explanation' => $explanation + ] + ] + ]); + + // evidence.reason => not_received, fraudulent, duplicate, other, merchandise_not_as_described, service_not_as_described, canceled + // reason will be dropdown + + // check additional params here: https://stripe.com/docs/api/issuing/disputes/create?lang=php + + $output['success'] = TRUE; + $output['response'] = $response; + $output['stripe_dispute_id'] = $response->id; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $dispute_id + * @return mixed + */ + public function submit_dispute($dispute_id) + { + // note: dispute id is the response->id from create_dispute + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + if ($dispute_id) + { + try { + $response = $stripe->issuing->disputes->submit( + $dispute_id, + [] + ); + + // doc: https://stripe.com/docs/api/issuing/dispute/submit + + $output['success'] = TRUE; + $output['response'] = $response; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getMessage(); + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $dispute_id + * @return mixed + */ + public function retrieve_dispute($dispute_id) + { + // note: dispute id is the response->id from create_dispute + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + if ($dispute_id) + { + try { + $response = $stripe->issuing->disputes->retrieve( + $dispute_id, + [] + ); + + // doc: https://stripe.com/docs/api/issuing/disputes/retrieve + + $output['success'] = TRUE; + $output['response'] = $response; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $dispute_id + * @param $reason + * @param $expected_at + * @param $explanation + * @param $product_description + * @param $product_type + * @return mixed + */ + public function update_dispute($dispute_id, $reason, $expected_at, $explanation, $product_description, $product_type) + { + // note: dispute id is the response->id from create_dispute + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + if ($dispute_id && $reason && $expected_at && $explanation && $product_description && $product_type) + { + try { + $response = $stripe->issuing->disputes->update( + $dispute_id, + [ + 'evidence' => [ + 'reason' => 'not_received', + 'not_received' => [ + 'expected_at' => strtotime($expected_at), + 'explanation' => '', + 'product_description' => $product_description, + 'product_type' => $product_type + ] + ] + ]); + + // evidence.reason => not_received, fraudulent, duplicate, other, merchandise_not_as_described, service_not_as_described, canceled + // reason will be dropdown + + // doc: https://stripe.com/docs/api/issuing/disputes/update + // stripe date_time format: https://en.m.wikipedia.org/wiki/Unix_time + // strtotime() + + $output['success'] = TRUE; + $output['response'] = $response; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $result_limit + * @return mixed + */ + public function list_all_disputes($result_limit) + { + // note: limit, created, ending_before, starting_after (optional) + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + $stripe = new \Stripe\StripeClient( + $stripe_secret_key + ); + + if ($result_limit) + { + try { + $response = $stripe->issuing->disputes->all(['limit' => $result_limit]); + + // limit is optional + // reason will be dropdown + + // doc: https://stripe.com/docs/api/issuing/disputes/list + // stripe date_time format: https://en.m.wikipedia.org/wiki/Unix_time + // strtotime() + + $output['success'] = TRUE; + $output['response'] = $response; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $charge_id + * @param $amount + * @param $reason + * @return mixed + */ + public function create_refund($charge_id, $amount, $reason) + { + // note: amount is the refund amount and it has to be within the limit of paid amount + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + Stripe::setApiKey($stripe_secret_key); + + if ($charge_id) + { + // don't need reason, admin create refund, which return success + try { + $obj = Refund::create([ + 'charge' => $charge_id, + 'amount' => $amount, + 'reason' => $reason + ]); + + // reason: duplicate, fraudulent & requested_by_customer + // doc: https://stripe.com/docs/api/refunds/create?lang=php + // stripe date_time format: https://en.m.wikipedia.org/wiki/Unix_time + // strtotime() + + $output['success'] = TRUE; + $output['obj'] = $obj; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $retrieve_id + * @param $order_id + * @return mixed + */ + public function retrieve_refund($retrieve_id, $order_id) + { + // note: use order_id to track with local order->id + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + Stripe::setApiKey($stripe_secret_key); + + if ($retrieve_id && $order_id) + { + + try { + $obj = Refund::retrieve( + $retrieve_id, + ['metadata' => ['order_id' => $order_id]] + ); + + // doc: https://stripe.com/docs/api/refunds/retrieve?lang=php + // stripe date_time format: https://en.m.wikipedia.org/wiki/Unix_time + // strtotime() + + $output['success'] = TRUE; + $output['obj'] = $obj; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $retrieve_id + * @param $order_id + * @return mixed + */ + public function update_refund($retrieve_id, $order_id) + { + // note: order_id is the local order->id to track + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + Stripe::setApiKey($stripe_secret_key); + + if ($retrieve_id && $order_id) + { + + try { + $obj = Refund::update( + $retrieve_id, + ['metadata' => ['order_id' => $order_id]] + ); + + // doc: https://stripe.com/docs/api/refunds/update?lang=php + // stripe date_time format: https://en.m.wikipedia.org/wiki/Unix_time + // strtotime() + + $output['success'] = TRUE; + $output['obj'] = $obj; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $limit + * @return mixed + */ + public function list_all_refunds($limit) + { + // note: limit, created, ending_before, starting_after (optional) + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + Stripe::setApiKey($stripe_secret_key); + + if ($limit) + { + + try { + $obj = Refund::all( + ['limit' => $limit] + ); + + // doc: https://stripe.com/docs/api/refunds/list?lang=php + // stripe date_time format: https://en.m.wikipedia.org/wiki/Unix_time + // strtotime() + + $output['success'] = TRUE; + $output['obj'] = $obj; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $number + * @param $exp_month + * @param $exp_year + * @param $cvc + * @return mixed + */ + public function create_stripe_token($number, $exp_month, $exp_year, $cvc) + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + if ($number && $exp_month && $exp_year && $cvc) + { + try { + $token = $stripe->tokens->create([ + 'card' => [ + 'number' => $number, + 'exp_month' => $exp_month, + 'exp_year' => $exp_year, + 'cvc' => $cvc + ] + ]); + + $output['success'] = TRUE; + $output['token'] = $token; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $customer_email + * @param $stripe_token_id + * @return mixed + */ + public function create_stripe_customer_with_card($customer_email, $stripe_token_id) + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + if ($customer_email) + { + try + { + $customer_data = $stripe->customers->create([ + 'customer' => [ + 'email' => $customer_email + ] + ]); + + $card_data = $stripe->customers->createSource( + $customer_data->id, + ['source' => $stripe_token_id] + ); + + // $card_data = Customer::createSource( + // $customer_data->id, + // [ + // 'source' => $stripe_token_id + // ] + // ); + + $output['success'] = TRUE; + $output['card'] = $card_data; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $stripe_token_id + * @param $user_id + * @return mixed + */ + public function add_new_card($stripe_token_id, $user_id) + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + $get_user_data = $this->_user_model->get($user_id); + + $stripe_customer_id = $get_user_data->stripe_id; + + if ($stripe_token_id && $stripe_customer_id) + { + try + { + // assign card to the user (not default) + $card_data = $stripe->customers->createSource( + $stripe_customer_id, + ['source' => $stripe_token_id] + ); + + // $card_data = Customer::createSource( + // $stripe_customer_id, + // [ + // 'source' => $stripe_token_id + // ] + // ); + + // set default (not needed) + // $updated_customer_data = Customer::update( + // $stripe_customer_id, + // [ + // 'default_source' => $add_card_data->id, + // ] + // ); + + $output['success'] = TRUE; + $output['card_data'] = $card_data; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $stripe_token_id + * @param $user_id + * @return mixed + */ + public function update_default_card($stripe_card_id, $user_id) + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + // Stripe::setApiKey($stripe_secret_key); + + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + $get_user_data = $this->_user_model->get($user_id); + + $stripe_customer_id = $get_user_data->stripe_id; + + if ($stripe_card_id && $stripe_customer_id) + { + try + { + // assign card to customer + // $add_card_data = $stripe->customers->createSource( + // $stripe_customer_id, + // ['source' => $stripe_token_id] + // ); + + // set default the card to user + $updated_customer_data = $stripe->customers->update( + $stripe_customer_id, + ['default_source' => $stripe_card_id] + ); + + $output['success'] = TRUE; + $output['updated_customer_data'] = $updated_customer_data; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Please fill data correctly."; + return $output; + exit(); + } + } + + /** + * @param $token_id + * @param $amount + * @param $description + * @return mixed + */ + public function create_stripe_simple_charge($token_id, $amount, $description = '') + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + if ($token_id && $amount) + { + try + { + $charge = $stripe->charges->create([ + 'amount' => $amount, + 'currency' => 'usd', + 'source' => $token_id, + 'description' => $description + ]); + + $output['success'] = TRUE; + $output['response'] = $charge; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Token and Amount is required."; + return $output; + exit(); + } + } + + /** + * @param $user_id + * @param $user_card_id + * @param $amount + * @param $description + * @return mixed + */ + public function create_stripe_charge($user_id, $user_card_id, $amount, $description) + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + $get_user_data = $this->_user_model->get($user_id); + $get_user_card_data = $this->_user_card_model->get($user_card_id); + + $stripe_customer_id = $get_user_data->stripe_id; + $stripe_card_id = $get_user_card_data->stripe_card_id; + + if ($stripe_customer_id && $amount) + { + try + { + $charge = $stripe->charges->create([ + "amount" => $amount * 100, + "currency" => "usd", + "customer" => $stripe_customer_id, + "source" => $stripe_card_id, + "description" => $description + ]); + + $output['success'] = TRUE; + $output['response'] = $charge; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Token and Amount is required."; + return $output; + exit(); + } + } + + /** + * @param $user_id + * @return mixed + */ + public function retrieve_stripe_customer_data($user_id) + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + Stripe::setApiKey($stripe_secret_key); + + $customer_data = $this->_user_model->get($user_id); + + $stripe_customer_id = $customer_data->stripe_id; + + if ($stripe_customer_id) + { + try + { + $retrieve = Customer::retrieve( + $stripe_customer_id, + [] + ); + + $output['success'] = TRUE; + $output['retrieve_customer'] = $retrieve; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Token and Amount is required."; + return $output; + exit(); + } + } + + /** + * @param $user_id + * @param $stripe_card_id + * @return mixed + */ + public function retrieve_stripe_card_data($user_id, $stripe_card_id) + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + Stripe::setApiKey($stripe_secret_key); + + $customer_data = $this->_user_model->get($user_id); + + $stripe_customer_id = $customer_data->stripe_id; + + if ($stripe_customer_id) + { + try + { + $retrieve_card = Customer::retrieveSource( + $stripe_customer_id, + $stripe_card_id, + [] + ); + + $output['success'] = TRUE; + $output['retrieve_card'] = $retrieve_card; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Token and Amount is required."; + return $output; + exit(); + } + } + + /** + * @param $user_id + * @param $stripe_card_id + * @return mixed + */ + public function delete_card_from_customer($user_id, $stripe_card_id) + { + $stripe_secret_key = $this->_config->item('stripe_secret_key'); + + $stripe = new \Stripe\StripeClient($stripe_secret_key); + + $customer_data = $this->_user_model->get($user_id); + + $stripe_customer_id = $customer_data->stripe_id; + + if ($stripe_customer_id) + { + try + { + $delete_card = $stripe->customers->deleteSource( + $stripe_customer_id, + $stripe_card_id, + [] + ); + + $output['success'] = TRUE; + return $output; + exit(); + } + catch (\Stripe\Exception\CardException $e) + { + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\RateLimitException $e) + { + // Too many requests made to the API too quickly + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\InvalidRequestException $e) + { + // Invalid parameters were supplied to Stripe's API + // echo 'Message is:' . $e->getError()->message . '\n'; + + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\AuthenticationException $e) + { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiConnectionException $e) + { + // Network communication with Stripe failed + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Stripe\Exception\ApiErrorException $e) + { + // Display a very generic error to the user, and maybe send + // yourself an email + $output['error'] = TRUE; + $output['error_msg'] = $e->getError()->message; + return $output; + exit(); + } + catch (\Exception $e) + { + // Something else happened, completely unrelated to Stripe + $output['error'] = TRUE; + $output['error_msg'] = $e->getMessage(); + return $output; + exit(); + } + } + else + { + $output['error'] = TRUE; + $output['error_msg'] = "Error! Token and Amount is required."; + return $output; + exit(); + } + } + +} diff --git a/application/libraries/Twillo_service.php b/application/libraries/Twillo_service.php new file mode 100755 index 0000000..5a6f196 --- /dev/null +++ b/application/libraries/Twillo_service.php @@ -0,0 +1,84 @@ +_ci = &get_instance(); + $this->_sid = $this->_ci->config->item('twilio_sid'); + $this->_api_token = $this->_ci->config->item('twilio_token'); + $this->_from_number = $this->_ci->config->item('twilio_phone_number'); + $this->_twilio_verification_service = $this->_ci->config->item('twilio_verification_service'); + + try + { + $this->_client = new Client($this->_sid, $this->_api_token); + } + catch(Twilio\Exceptions\ConfigurationException $e) + { + die($e->getMessage()) ; + } + } + + /** + * Send Message + * + * @param string $number + * @param string $message + * @return mixed + */ + public function send_message($number, $message) + { + return $this->_client->messages->create( + $number, // to + ['body' => $message, 'from' => $this->_from_number] + ); + } + + /** + * Verify Number + * + * @see https://www.twilio.com/docs/verify/api/verification + * @param [type] $number + * @return void + */ + public function verify_number($number) + { + return $this->_client->verify->v2->services($this->_twilio_verification_service)->verifications->create($number, 'sms'); + } + + /** + * Fetch Verification + * + * @param string $seID + * @return mixed + */ + public function fetch_verification($seID) + { + return $this->_client->verify->v2->services($this->_twilio_verification_service)->verifications($seID)->fetch(); + } + + /** + * Check Verification Code + * + * @param string $code + * @param string $number + * @return mixed + */ + public function check_verification_code($code, $number) + { + return $this->_client->verify->v2->services($this->_twilio_verification_service)->verificationChecks->create($code, ['to' => $number]); + } + +} diff --git a/application/libraries/View_helper.php b/application/libraries/View_helper.php new file mode 100755 index 0000000..5c82af4 --- /dev/null +++ b/application/libraries/View_helper.php @@ -0,0 +1,22 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

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

    Directory access is forbidden.

    + + + diff --git a/application/middlewares/Acl_middleware.php b/application/middlewares/Acl_middleware.php new file mode 100755 index 0000000..33cb541 --- /dev/null +++ b/application/middlewares/Acl_middleware.php @@ -0,0 +1,43 @@ +_controller = $controller; + $this->_ci = $ci; + } + + public function run() + { + $session = $this->_controller->get_session(); + + $user_id = isset($session['user_id']) ? $session['user_id'] : 0; + $email = isset($session['email']) ? $session['email'] : ''; + $role = isset($session['role']) ? $session['role'] : NULL; + + $condition = ($role != NULL) && in_array((int)$role, $this->_controller->_valid_roles) && + ($user_id > 0) && (strlen($email) > 0); + + if (!$condition) + { + $this->_controller->destroy_session(); + return $this->_controller->redirect('/', 'refresh'); + } + + return TRUE; + } +} \ No newline at end of file diff --git a/application/middlewares/Affilate_middleware.php b/application/middlewares/Affilate_middleware.php new file mode 100755 index 0000000..84de68c --- /dev/null +++ b/application/middlewares/Affilate_middleware.php @@ -0,0 +1,35 @@ +_controller = $controller; + $this->_ci = $ci; + } + + public function run() + { + $refer_code = $this->_controller->input->get('affilate', TRUE); + + if ($refer_code && strlen($refer_code) > 0) + { + $this->_controller->set_session('refer', $refer_code); + } + + return TRUE; + } +} \ No newline at end of file diff --git a/application/middlewares/Auth_middleware.php b/application/middlewares/Auth_middleware.php new file mode 100755 index 0000000..6d2d116 --- /dev/null +++ b/application/middlewares/Auth_middleware.php @@ -0,0 +1,45 @@ +_controller = $controller; + $this->_ci = $ci; + } + public function run() + { + $session = $this->_controller->get_session(); + + $logged_in = empty($session) || ! isset($session['user_id']) || ! isset($session['email']); + + if ($logged_in) + { + $this->_controller->destroy_session(); + $this->_controller->load->helper('cookie'); + $cookie = [ + 'name' => 'redirect', + 'value' => '/' . uri_string(), + 'expire' => '60', + 'secure' => FALSE + ]; + set_cookie($cookie); + return $this->_controller->redirect('/', 'refresh'); + } + + return TRUE; + } +} \ No newline at end of file diff --git a/application/middlewares/Maintenance_middleware.php b/application/middlewares/Maintenance_middleware.php new file mode 100755 index 0000000..76ac7f2 --- /dev/null +++ b/application/middlewares/Maintenance_middleware.php @@ -0,0 +1,38 @@ +_controller = $controller; + $this->_ci = $ci; + } + + public function run() + { + $setting = $this->_controller->get_setting(); + $condition = (isset($setting) && isset($setting['maintenance']) && $setting['maintenance'] == 1); + + if ($condition) + { + header( '503 Service Unavailable', TRUE, 503 ); + stop_execution(); + return FALSE; + } + + return TRUE; + } +} \ No newline at end of file diff --git a/application/middlewares/Subscription_middleware.php b/application/middlewares/Subscription_middleware.php new file mode 100755 index 0000000..7688187 --- /dev/null +++ b/application/middlewares/Subscription_middleware.php @@ -0,0 +1,78 @@ +_controller = $controller; + $this->_ci = $ci; + $this->_controller->load->database(); + } + + public function run() + { + $session = $this->_controller->get_session(); + $this->_controller->load->model('stripe_subscriptions_model'); + $this->_controller->load->model('stripe_feature_model'); + $this->_controller->load->model('controllers_features_model'); + + if (!empty($session)) { + $user_id = $session['user_id']; + $role_id = $session['role']; + $user_sub = $this->_controller->stripe_subscriptions_model->get_last_active_subscription([ + 'user_id' => $user_id, + 'role_id' => $role_id, + ]); + + $portal = $this->_controller->uri->segment(1); + + //if user is not subscriped to anything get all features for plan -1 which is free plan (always should be like this) + //if user is not subscriped to anything get all features for plan 0 which is access all (always should be like this) + if (!$user_sub) { + $features = $this->_controller->stripe_feature_model->get_all(['plan_id' => -1]); + } else { + $features = $this->_controller->stripe_feature_model->get_all(['plan_id' => $user_sub->plan_id]); + if (!$features) { + $features = $this->_controller->stripe_feature_model->get_all(['plan_id' => -1]); + } + } + + //check if a plan has "all" feature + $found = false; + + foreach ($features as $feature) { + // if ($feature->slug == 'all' || $feature->controller_name == 'all') { + // $found = true; + // break; + // } + $feature = $this->_controller->controllers_features_model->get($feature->controller_feature_id); + if (strcmp($this->_controller->uri->rsegments[1], $feature->controller_name) == 0) { + $found = true; + } + } + + if ($found == false) { + $this->_controller->error('Your current subscription doesn\'t have access to that page. Upgrade your subscription.'); + $this->_controller->redirect("/{$portal}/stripe_subscriptions/0", 'refresh'); + } + + return false; + + } + $this->_controller->error('Subscription required to access page'); + return $this->_controller->redirect("/{$portal}/stripe_subscriptions/0", 'refresh'); + } + +} \ No newline at end of file diff --git a/application/middlewares/Token_acl_middleware.php b/application/middlewares/Token_acl_middleware.php new file mode 100755 index 0000000..ad3b48b --- /dev/null +++ b/application/middlewares/Token_acl_middleware.php @@ -0,0 +1,59 @@ +_controller = $controller; + $this->_ci = $ci; + } + + /** + * Steps: + * 1.Get authorization header + * 2.Validate it + * 3.Check if it matches role + * 4.Return error if not match + * + * @return void + */ + public function run() + { + $condition = in_array($this->_controller->get_role_id(), $this->_controller->get_valid_role()); + + if (!$condition) + { + $this->unauthorize_resource_error_message(); + return FALSE; + } + + return TRUE; + } + + private function unauthorize_resource_error_message() + { + http_response_code(406); + echo json_encode([ + 'code' => 406, + 'success' => FALSE, + 'message' => 'cannot access resource' + ]); + stop_execution(); + } +} \ No newline at end of file diff --git a/application/middlewares/Token_middleware.php b/application/middlewares/Token_middleware.php new file mode 100755 index 0000000..8080e2c --- /dev/null +++ b/application/middlewares/Token_middleware.php @@ -0,0 +1,114 @@ +_controller = $controller; + $this->_ci = $ci; + } + + /** + * Steps: + * 1.Get authorization header + * 2.Validate it + * 3.Check if it matches role + * 4.Return error if not match + * + * @return void + */ + public function run() + { + $token_service = new Token_service(); + $key = $this->_ci->item('jwt_key'); + + $jwt_token = $this->_get_bearer_token(); + + if (strlen($jwt_token) < 1) + { + $this->unauthorize_error_message(); + } + + $result = $token_service->validate_token ($key, $this->_get_bearer_token()); + + if ($result) + { + $this->_controller->set_user_id($result->user_id); + $this->_controller->set_role_id($result->role_id); + return TRUE; + } + + $this->unauthorize_error_message(); + return FALSE; + } + + private function _get_bearer_token() + { + $bearer_token = ''; + + $bearer_token_header = $this->_controller->input->get_request_header('Authorization'); + $bearer_token_get = $this->_controller->input->get('Authorization'); + + if (strlen($bearer_token_header) < 1) + { + if (strlen($bearer_token_get) < 1) + { + $lower_case_bearer_token_header = $this->_controller->input->get_request_header('authorization'); + $lower_case_bearer_token_get = $this->_controller->input->get('authorization'); + if (strlen($lower_case_bearer_token_header) < 1) + { + if (strlen($lower_case_bearer_token_get) > 1) + { + $bearer_token = $lower_case_bearer_token_get; + } + } + else + { + $bearer_token = $lower_case_bearer_token_header; + } + } + else + { + $bearer_token = $bearer_token_get; + } + } + else + { + $bearer_token = $bearer_token_header; + } + + if (strpos($bearer_token, 'Bearer ') !== 0) + { + return ''; + } + else + { + return str_replace('Bearer ', '', $bearer_token); + } + } + + private function unauthorize_error_message() + { + http_response_code(401); + echo json_encode([ + 'code' => 401, + 'success' => FALSE, + 'message' => 'invalid credentials' + ]); + stop_execution(); + } +} \ No newline at end of file diff --git a/application/middlewares/index.html b/application/middlewares/index.html new file mode 100755 index 0000000..b702fbc --- /dev/null +++ b/application/middlewares/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/models/Admin_operation_model.php b/application/models/Admin_operation_model.php new file mode 100755 index 0000000..d9d7c25 --- /dev/null +++ b/application/models/Admin_operation_model.php @@ -0,0 +1,235 @@ +get_ip(); + $data['last_ip'] = $this->get_user_agent(); + + return $data; + } + + /** + * If you need to modify payload before edit, overload this function + * + * @param mixed $data + * @return mixed + */ + protected function _post_edit_processing($data) + { + + return $data; + } + + /** + * Allow user to add extra counting condition so user don't have to change main function + * + * @param mixed $parameters + * @return $db + */ + protected function _custom_counting_conditions(&$db) + { + + return $db; + } + + + function get_ip() + { + if(!empty($_SERVER['HTTP_CLIENT_IP'])) + { + $ip = $_SERVER['HTTP_CLIENT_IP']; + } + elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) + { + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + else + { + $ip = $_SERVER['REMOTE_ADDR']; + } + return $ip; + } + + function get_user_agent() + { + return $_SERVER['HTTP_USER_AGENT']; + } + + public function get_user ($where) + { + return $this->_join ('user', 'user_id', $where, []); + } + + public function get_user_paginated ($page, $limit, $where, $order_by, $direction) + { + return $this->_join_paginate ('user', 'user_id', $where, $page, $limit, $order_by, $direction, []); + } + + public function count_paginated ($where) + { + return count($this->_join ('user', 'user_id', $where, [])); + } + + public function getMemberAccountData(){ + + $data = [ + 'month'=>0, + 'week'=>0, + 'year'=>0, + 'total'=>0 + ]; + + $result = $this->db->select('count(*) as count')->from('phinxlog')->where('breakpoint',0)->get()->row_array(); + if($result){ + $data['total'] = $result['count']; + } + + $result = $this->db->select('count(id) as count')->from('credential')->where('role_id',2)->where('MONTH(created_at) =',date('n')) + ->where('YEAR(created_at)',date('Y'))->get()->row_array(); + if($result){ + $data['month'] = $result['count']; + } + + $result = $this->db->select('count(id) as count')->from('credential')->where('role_id',1) + ->where('YEAR(created_at) =',date('Y'))->get()->row_array(); + if($result){ + $data['year'] = $result['count']; + } + + $result = $this->db->select('count(id) as count')->from('credential')->where('role_id',1) + ->where('YEARWEEK(created_at, 1) = YEARWEEK(CURDATE(), 1)')->get()->row_array(); + if($result){ + $data['week'] = $result['count']; + } + + + return $data; + } + public function getMemberUploadData(){ + + $data = [ + 'month'=>0, + 'week'=>0, + 'year'=>0, + 'total'=>0 + ]; + + $result = $this->db->select('count(id) as count')->from('inventory')->where('status',1)->get()->row_array(); + if($result){ + $data['total'] = $result['count']; + } + + $result = $this->db->select('count(id) as count')->from('inventory')->where('status',1)->where('MONTH(created_at) =',date('n')) + ->where('YEAR(created_at)',date('Y'))->get()->row_array(); + if($result){ + $data['month'] = $result['count']; + } + + $result = $this->db->select('count(id) as count')->from('inventory')->where('status',1) + ->where('YEAR(created_at) =',date('Y'))->get()->row_array(); + if($result){ + $data['year'] = $result['count']; + } + + $result = $this->db->select('count(id) as count')->from('inventory')->where('status',1) + ->where('YEARWEEK(created_at, 1) = YEARWEEK(CURDATE(), 1)')->get()->row_array(); + if($result){ + $data['week'] = $result['count']; + } + + + return $data; + } + public function getAccountsBySchool(){ + + + $result = $this->db->select('count(c.id) as count,s.name as school')->from('credential c') + ->join('member_profile m','m.user_id=c.user_id') + ->join('school s','s.id=m.school_id','left') + ->where('c.role_id',1) + ->group_by('m.school_id') + ->order_by('count') + ->limit(5) + ->get()->result_array(); + + + return $result; + } + public function getUploadsBySchool(){ + + $result = $this->db->select('count(i.id) as count,s.name as school')->from('inventory i') + ->join('school s','s.id=i.school_id') + ->where('i.status',1) + ->group_by('i.school_id') + ->order_by('count') + ->limit(5) + ->get()->result_array(); + + + return $result; + } + + + +} \ No newline at end of file diff --git a/application/models/Cart_model.php b/application/models/Cart_model.php new file mode 100755 index 0000000..4b982c2 --- /dev/null +++ b/application/models/Cart_model.php @@ -0,0 +1,98 @@ + 'Active', + 0 => 'Inactive', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Classes_model.php b/application/models/Classes_model.php new file mode 100755 index 0000000..1ba118d --- /dev/null +++ b/application/models/Classes_model.php @@ -0,0 +1,97 @@ + 'Active', + 0 => 'Inactive', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Contact_us_model.php b/application/models/Contact_us_model.php new file mode 100755 index 0000000..e898308 --- /dev/null +++ b/application/models/Contact_us_model.php @@ -0,0 +1,92 @@ + 'Text', + 2 => 'Image', + 3 => 'Link', + ]; + } + + public function status_mapping () + { + return [ + 1 => 'Active', + 0 => 'Inactive', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Cookies_model.php b/application/models/Cookies_model.php new file mode 100755 index 0000000..f9309d3 --- /dev/null +++ b/application/models/Cookies_model.php @@ -0,0 +1,106 @@ + 'Inactive', + 1 => 'Active', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Credential_model.php b/application/models/Credential_model.php new file mode 100755 index 0000000..330a09b --- /dev/null +++ b/application/models/Credential_model.php @@ -0,0 +1,154 @@ + 'Not verified', + 1 => 'Verified', + ]; + } + + public function status_mapping () + { + return [ + 0 => 'Inactive', + 1 => 'Active', + 2 => 'Suspend', + ]; + } + + public function role_id_mapping () + { + return [ + 1 => 'Member', + 2 => 'Admin', + ]; + } + + public function type_mapping () + { + return [ + 'n' => 'Normal', + 'f' => 'Facebook', + 'g' => 'Google', + ]; + } + + + public function get_user ($where) + { + return $this->_join ('user', 'user_id', $where, []); + } + + public function get_user_paginated ($page, $limit, $where, $order_by, $direction) + { + return $this->_join_paginate ('user', 'user_id', $where, $page, $limit, $order_by, $direction, []); + } + + public function count_paginated ($where) + { + return count($this->_join ('user', 'user_id', $where, [])); + } + + + +} \ No newline at end of file diff --git a/application/models/Dispute_model.php b/application/models/Dispute_model.php new file mode 100755 index 0000000..32e101b --- /dev/null +++ b/application/models/Dispute_model.php @@ -0,0 +1,107 @@ +db->from('email'); + $this->db->where('slug',$slug,TRUE); + $template=$this->db->get()->row(); + if(!$template) + { + return FALSE; + } + $tags_raw=$template->tag; + $tags=explode(',',$tags_raw); + $template->subject=$this->inject_substitute($template->subject,$tags,$data); + $html = $template->email_header . $template->html . $template->email_footer; + $template->html = $this->inject_substitute($html, $tags, $data); + + return $template; + } + + public function inject_substitute($raw, $tags, $data) + { + foreach ($data as $key => $value) + { + if (in_array($key, $tags) || $key == 'logo') + { + if ($key == 'logo') + { + $logo = base_url('assets/frontend/img/logo.png'); + $new_val = ""; + + $value = $new_val; + } + $raw = str_replace('{{{' . $key . '}}}', $value, $raw); + } + } + return $raw; + } + + + +} \ No newline at end of file diff --git a/application/models/Image_model.php b/application/models/Image_model.php new file mode 100755 index 0000000..85297d4 --- /dev/null +++ b/application/models/Image_model.php @@ -0,0 +1,156 @@ + 'Server Hosted', + 1 => 'External Link', + 2 => 'S3', + 3 => 'Cloudinary', + 4 => 'File', + 5 => 'External File', + 6 => 'Video', + ]; + } + + + public function get_user ($where) + { + return $this->_join ('user', 'user_id', $where, []); + } + + public function get_user_paginated ($page, $limit, $where, $order_by, $direction) + { + return $this->_join_paginate ('user', 'user_id', $where, $page, $limit, $order_by, $direction, []); + } + + public function count_paginated ($where) + { + return count($this->_join ('user', 'user_id', $where, [])); + } + + + +} \ No newline at end of file diff --git a/application/models/Inventory_gallery_image_list_model.php b/application/models/Inventory_gallery_image_list_model.php new file mode 100755 index 0000000..8a601ac --- /dev/null +++ b/application/models/Inventory_gallery_image_list_model.php @@ -0,0 +1,103 @@ + 'Active', + 0 => 'Inactive', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Inventory_model.php b/application/models/Inventory_model.php new file mode 100755 index 0000000..4887298 --- /dev/null +++ b/application/models/Inventory_model.php @@ -0,0 +1,437 @@ + 'Outline', + 2 => 'Lecture Notes' + ]; + } + + public function pin_to_top_mapping() + { + return [ + 0 => 'No', + 1 => 'Yes' + ]; + } + + public function approve_mapping() + { + return [ + 1 => 'Yes', + 0 => 'No' + ]; + } + + public function status_mapping() + { + return [ + 1 => 'Active', + 0 => 'Inactive', + 2 => 'Removed' + ]; + } + + // frontend functions + public function get_all_active_items_list_fe($search_term = '', $school_id = '', $professor_id = '', $textbook_id = '', $class_id = '',$isbn='',$order_by='',$direction='', $offset = '', $limit = '') + { + $this->db->from('inventory'); + $this->db->join('school', 'inventory.school_id = school.id', 'LEFT'); + $this->db->join('professor', 'inventory.professor_id = professor.id', 'LEFT'); + $this->db->join('textbook', 'inventory.textbook_id = textbook.id', 'LEFT'); + $this->db->join('classes', 'inventory.class_id = classes.id', 'LEFT'); + $this->db->join('user', 'inventory.user_id = user.id', 'LEFT'); + $this->db->join('review', 'inventory.id = review.inventory_id', 'LEFT'); + + $this->db->select('inventory.*,sum(review.rating) as rating,count(review.id) as rating_count,user.first_name ,school.name AS school_name,classes.name AS class_name,textbook.name AS textbook_name,textbook.isbn AS textbook_isbn,professor.name AS professor_name'); + $this->db->where('inventory.status', 1); + $this->db->where('school.status', 1); + $this->db->group_by('inventory.id'); + + + if($order_by && $direction) + { + if(in_array($order_by,['school_id','isbn','class_id','professor_id','textbook_id','year','word_count','note_type'])) + { + $this->db->order_by($order_by, $direction); + }else if($order_by=='seller'){ + $this->db->order_by('user.first_name', $direction); + }else if($order_by=='review'){ + $this->db->order_by('rating', $direction); + } + + } + else + { + $this->db->order_by('inventory.created_at', 'DESC'); + } + + if ($search_term) + { + $query = $this->db->where(' (inventory.title like "%'.$search_term.'%" or + classes.name like "%'.$search_term.'%" or + school.name like "%'.$search_term.'%" or + textbook.name like "%'.$search_term.'%" or + professor.name like "%'.$search_term.'%" )'); + + } + + if ($school_id) + { + $query = $this->db->where('inventory.school_id', $school_id); + } + + if ($professor_id) + { + $query = $this->db->where('inventory.professor_id', $professor_id); + } + + if ($textbook_id) + { + $query = $this->db->where('inventory.textbook_id', $textbook_id); + } + if ($isbn) + { + $query = $this->db->where('inventory.isbn', $isbn); + } + + if ($class_id) + { + $query = $this->db->where('inventory.class_id', $class_id); + } + + if ($limit) + { + $this->db->limit($limit, $offset); + } + + $query = $this->db->get(); + + if ($query->num_rows() > 0) + { + return $query->result(); + } + return FALSE; + } + + + + public function get_current_user_order_count($user_id){ + return $this->db->select('count(id) as order_count,inventory_id')->from('order')->where('status',1)->where('sale_user_id',$user_id)->group_by('inventory_id')->get()->result_array(); + + } + public function get_current_user_refunded_count($user_id){ + return $this->db->select('count(id) as order_count,inventory_id')->from('order')->where('status',2)->where('sale_user_id',$user_id)->group_by('inventory_id')->get()->result_array(); + + } + public function get_all_active_items_by_school_list_fe($school_id, $offset = '', $limit = '') + { + $this->db->from('inventory'); + $this->db->join('school', 'inventory.school_id = school.id', 'BOTH'); + + $this->db->select('inventory.*, school.id AS school_id, school.name AS school_name'); + + $this->db->where('inventory.school_id', $school_id); + + $this->db->where('inventory.status', 1); + $this->db->where('school.status', 1); + + $this->db->order_by('school.created_at', 'DESC'); + $this->db->order_by('inventory.created_at', 'DESC'); + + if ($limit != '') + { + $this->db->limit($limit, $offset); + } + + $query = $this->db->get(); + + if ($query->num_rows() > 0) + { + return $query->result(); + } + return FALSE; + } + + public function get_item_details_fe($id) + { + $this->db->select('inventory.*, school.id AS school_id, school.name AS school_name'); + $this->db->from('inventory'); + + $this->db->join('school', 'inventory.school_id = school.id'); + + $this->db->where('inventory.id', $id); + $this->db->where('inventory.status', 1); + $this->db->where('school.status', 1); + + $data = $this->db->get()->row(); + // die($this->db->last_query()); + + if ($data) + { + return $data; + } + return FALSE; + } + + + + /** + * Count number of model + * + * @access public + * @param mixed $parameters + * @return integer $result + */ + public function count($parameters) + { + $this->db->select('user.first_name, user.last_name, credential.email, inventory.* '); + if (!empty($parameters)) + { + foreach ($parameters as $key => $value) + { + if (is_numeric($key) && strlen($value) > 0) + { + $this->db->where($value); + continue; + } + + if ($key === NULL && $value === NULL) + { + continue; + } + + if (!is_null($value)) + { + if(is_numeric($value)) + { + $this->db->where($key, $value); + continue; + } + + if(is_string($value)) + { + $this->db->like($key, $value); + continue; + } + + $this->db->where($key, $value); + } + } + } + + $this->db->join('user', 'inventory.user_id = user.id', 'LEFT'); + $this->db->join('credential', 'user.id = credential.user_id', 'LEFT'); + + + $this->_custom_counting_conditions($this->db); + $this->db->from($this->_table); + return $this->db->count_all_results(); + } + + /** + * Get paginated model + * + * @access public + * @param integer $page default 0 + * @param integer $limit default 10 + * @return array + */ + public function get_paginated($page = 0, $limit=10, $where=[], $order_by='', $direction='ASC') + { + $this->db->limit($limit, $page); + + if ($order_by === '') + { + $order_by = $this->_primary_key; + } + $this->db->select('user.first_name, user.last_name, credential.email, inventory.* '); + $this->db->order_by($this->clean_alpha_num_field($order_by), $this->clean_alpha_field($direction)); + + if (!empty($where)) + { + foreach($where as $field => $value) + { + if (is_numeric($field) && strlen($value) > 0) + { + $this->db->where($value); + continue; + } + + if ($field === NULL && $value === NULL) + { + continue; + } + + if ($value !== NULL) + { + if(is_numeric($value)) + { + $this->db->where($field, $value); + continue; + } + + if(is_string($value)) + { + $this->db->like($field, $value); + continue; + } + + $this->db->where($field, $value); + } + } + } + + $this->db->join('user', 'inventory.user_id = user.id', 'LEFT'); + $this->db->join('credential', 'user.id = credential.user_id', 'LEFT'); + + $query = $this->db->get($this->_table); + $result = []; + + if ($query->num_rows() > 0) + { + foreach ($query->result() as $row) + { + $result[] = $row; + } + } + + return $result; + } + + +} diff --git a/application/models/Marketing_model.php b/application/models/Marketing_model.php new file mode 100755 index 0000000..ab56620 --- /dev/null +++ b/application/models/Marketing_model.php @@ -0,0 +1,143 @@ + 'Public', + 1 => 'Private', + 2 => 'Inactive', + ]; + } + + + public function get_user ($where) + { + return $this->_join ('user', 'user_id', $where, []); + } + + public function get_user_paginated ($page, $limit, $where, $order_by, $direction) + { + return $this->_join_paginate ('user', 'user_id', $where, $page, $limit, $order_by, $direction, []); + } + + public function count_paginated ($where) + { + return count($this->_join ('user', 'user_id', $where, [])); + } + + + +} \ No newline at end of file diff --git a/application/models/Member_operation_model.php b/application/models/Member_operation_model.php new file mode 100755 index 0000000..ba3022d --- /dev/null +++ b/application/models/Member_operation_model.php @@ -0,0 +1,136 @@ +get_ip(); + $data['last_ip'] = $this->get_user_agent(); + + return $data; + } + + /** + * If you need to modify payload before edit, overload this function + * + * @param mixed $data + * @return mixed + */ + protected function _post_edit_processing($data) + { + + return $data; + } + + /** + * Allow user to add extra counting condition so user don't have to change main function + * + * @param mixed $parameters + * @return $db + */ + protected function _custom_counting_conditions(&$db) + { + + return $db; + } + + + function get_ip() + { + if(!empty($_SERVER['HTTP_CLIENT_IP'])) + { + $ip = $_SERVER['HTTP_CLIENT_IP']; + } + elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) + { + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + else + { + $ip = $_SERVER['REMOTE_ADDR']; + } + return $ip; + } + + function get_user_agent() + { + return $_SERVER['HTTP_USER_AGENT']; + } + + public function get_user ($where) + { + return $this->_join ('user', 'user_id', $where, []); + } + + public function get_user_paginated ($page, $limit, $where, $order_by, $direction) + { + return $this->_join_paginate ('user', 'user_id', $where, $page, $limit, $order_by, $direction, []); + } + + public function count_paginated ($where) + { + return count($this->_join ('user', 'user_id', $where, [])); + } + + + +} \ No newline at end of file diff --git a/application/models/Member_profile_model.php b/application/models/Member_profile_model.php new file mode 100755 index 0000000..fca09c1 --- /dev/null +++ b/application/models/Member_profile_model.php @@ -0,0 +1,107 @@ +_join ('user', 'user_id', $where, []); + } + + public function get_user_paginated ($page, $limit, $where, $order_by, $direction) + { + return $this->_join_paginate ('user', 'user_id', $where, $page, $limit, $order_by, $direction, []); + } + + public function count_paginated ($where) + { + return count($this->_join ('user', 'user_id', $where, [])); + } + + + +} \ No newline at end of file diff --git a/application/models/Notification_model.php b/application/models/Notification_model.php new file mode 100755 index 0000000..ac4a426 --- /dev/null +++ b/application/models/Notification_model.php @@ -0,0 +1,95 @@ + 'Paid', + 2 => 'Refunded', + 3 => 'Disputed', + 4 => 'Canceled', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Order_notes_model.php b/application/models/Order_notes_model.php new file mode 100755 index 0000000..273d158 --- /dev/null +++ b/application/models/Order_notes_model.php @@ -0,0 +1,89 @@ + 'Refunded', + 1 => 'Paid', + 0 => 'Unpaid', + 2 => 'Pending', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Professor_model.php b/application/models/Professor_model.php new file mode 100755 index 0000000..57f32c7 --- /dev/null +++ b/application/models/Professor_model.php @@ -0,0 +1,97 @@ + 'Active', + 0 => 'Inactive', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Refer_log_model.php b/application/models/Refer_log_model.php new file mode 100755 index 0000000..966c93a --- /dev/null +++ b/application/models/Refer_log_model.php @@ -0,0 +1,133 @@ + 'Pending', + 1 => 'Confirmed', + 2 => 'Paid' + ]; + } + + public function type_mapping() + { + return [ + 0 => 'user' + ]; + } + + public function get_user($where) + { + return $this->_join('user', 'user_id', $where, []); + } + + public function get_user_paginated($page, $limit, $where, $order_by, $direction) + { + return $this->_join_paginate('user', 'user_id', $where, $page, $limit, $order_by, $direction, []); + } + + public function count_paginated($where) + { + return count($this->_join('user', 'user_id', $where, [])); + } + + public function get_referrer($where) + { + return $this->_join('referrer', 'referrer_user_id', $where, []); + } + + public function get_referrer_paginated($page, $limit, $where, $order_by, $direction) + { + return $this->_join_paginate('referrer', 'referrer_user_id', $where, $page, $limit, $order_by, $direction, []); + } + +} diff --git a/application/models/Refund_model.php b/application/models/Refund_model.php new file mode 100755 index 0000000..aa578c7 --- /dev/null +++ b/application/models/Refund_model.php @@ -0,0 +1,110 @@ + '1/10', + 2 => '2/10', + 3 => '3/10', + 4 => '4/10', + 5 => '5/10', + 6 => '6/10', + 7 => '7/10', + 8 => '8/10', + 9 => '9/10', + 10 => '10/10', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Role_model.php b/application/models/Role_model.php new file mode 100755 index 0000000..3693ed0 --- /dev/null +++ b/application/models/Role_model.php @@ -0,0 +1,86 @@ + 'Active', + 0 => 'Inactive', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Setting_model.php b/application/models/Setting_model.php new file mode 100755 index 0000000..00646a4 --- /dev/null +++ b/application/models/Setting_model.php @@ -0,0 +1,126 @@ + 'text', + 1 => 'select', + 2 => 'number', + 3 => 'image', + 4 => 'read_only', + ]; + } + + public function maintenance_mapping () + { + return [ + 0 => 'No', + 1 => 'Yes', + ]; + } + + public function get_config_settings() + { + $this->db->from('setting'); + $results = $this->db->get()->result(); + $data = []; + foreach ($results as $key => $value) + { + $data[$value->key] = $value->value; + } + return $data; + } + + + +} \ No newline at end of file diff --git a/application/models/Sms_model.php b/application/models/Sms_model.php new file mode 100755 index 0000000..e66ea12 --- /dev/null +++ b/application/models/Sms_model.php @@ -0,0 +1,122 @@ +db->from('sms'); + $this->db->where('slug',$slug,TRUE); + $template=$this->db->get()->row(); + if(!$template) + { + return FALSE; + } + $tags_raw=$template->tags; + $tags=explode(',',$tags_raw); + $template->content=$this->inject_substitute($template->content,$tags,$data); + return $template; + } + + public function inject_substitute($raw, $tags, $data) + { + foreach ($data as $key => $value) + { + if (in_array($key, $tags)) + { + $raw = str_replace('{{{' . $key . '}}}', $value, $raw); + } + } + return $raw; + } + + + +} \ No newline at end of file diff --git a/application/models/Spreadsheet_model.php b/application/models/Spreadsheet_model.php new file mode 100755 index 0000000..3c2cc65 --- /dev/null +++ b/application/models/Spreadsheet_model.php @@ -0,0 +1,104 @@ + 'Inactive', + 1 => 'Active', + 2 => 'Private', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Suggestion_model.php b/application/models/Suggestion_model.php new file mode 100755 index 0000000..3a88fd6 --- /dev/null +++ b/application/models/Suggestion_model.php @@ -0,0 +1,119 @@ + 'School', + 2 => 'Professor', + 3 => 'Textbook', + 4 => 'Class', + ]; + } + + public function status_mapping () + { + return [ + 1 => 'Approve', + 0 => 'Decline', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Tax_model.php b/application/models/Tax_model.php new file mode 100755 index 0000000..2c51de2 --- /dev/null +++ b/application/models/Tax_model.php @@ -0,0 +1,86 @@ + 'Active', + 0 => 'Inactive', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Ticket_model.php b/application/models/Ticket_model.php new file mode 100755 index 0000000..dd1d980 --- /dev/null +++ b/application/models/Ticket_model.php @@ -0,0 +1,114 @@ + 'Yes', + 0 => 'No', + ]; + } + + public function status_mapping () + { + return [ + 1 => 'Resolved', + 0 => 'Unsolved', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Token_model.php b/application/models/Token_model.php new file mode 100755 index 0000000..c63797f --- /dev/null +++ b/application/models/Token_model.php @@ -0,0 +1,185 @@ + 'Inactive', + 1 => 'Active', + ]; + } + + public function type_mapping () + { + return [ + 0 => 'Forgot_token', + 1 => 'Access token', + 2 => 'Refresh_token', + 3 => 'Other', + 4 => 'Api Key', + 5 => 'Api Secret', + 6 => 'Verify', + ]; + } + + const NOT_FOUND = 0; + + const EXPIRED = 1; + + const FOUND = 2; + + public function create_verify_token ($user_id, $phone) + { + $code = rand(100000,999999); + $expire_at = date('Y-m-j H:i:s', time() + 60 * 5); + $token = $this->create([ + 'token' => $code, + 'data' => json_encode([ + 'code' => $code, + 'phone' => $phone + ]), + 'type' => 6, + 'user_id' => $user_id, + 'ttl' => 5 * 60, + 'issue_at' => date('Y-m-j H:i:s'), + 'expire_at' => $expire_at, + 'status' => 1 + ]); + return $code; + } + + public function check_verify_token ($code) + { + $exist = $this->get_by_field('token', $code); + if (!$exist) + { + return NOT_FOUND; + } + $expire_at = strtotime($exist->expire_at); + + if ($expire_at < time()) + { + return EXPIRED; + } + return json_decode($exist->data, TRUE); + } + + public function get_user ($where) + { + return $this->_join ('user', 'user_id', $where, []); + } + + public function get_user_paginated ($page, $limit, $where, $order_by, $direction) + { + return $this->_join_paginate ('user', 'user_id', $where, $page, $limit, $order_by, $direction, []); + } + + public function count_paginated ($where) + { + return count($this->_join ('user', 'user_id', $where, [])); + } + + + +} \ No newline at end of file diff --git a/application/models/Transaction_model.php b/application/models/Transaction_model.php new file mode 100755 index 0000000..a48d4a9 --- /dev/null +++ b/application/models/Transaction_model.php @@ -0,0 +1,132 @@ + 'Stripe', + 2 => 'Paypal', + ]; + } + + public function status_mapping () + { + return [ + 1 => 'Active', + 0 => 'Inactive', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/Url_redirect_model.php b/application/models/Url_redirect_model.php new file mode 100755 index 0000000..1637ac0 --- /dev/null +++ b/application/models/Url_redirect_model.php @@ -0,0 +1,89 @@ + 'No', + 1 => 'Yes', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/User_model.php b/application/models/User_model.php new file mode 100755 index 0000000..b32bec8 --- /dev/null +++ b/application/models/User_model.php @@ -0,0 +1,144 @@ + 'Inactive', + 1 => 'Active', + 2 => 'Suspend', + ]; + } + + + + +} \ No newline at end of file diff --git a/application/models/index.html b/application/models/index.html new file mode 100755 index 0000000..b702fbc --- /dev/null +++ b/application/models/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/services/User_service.php b/application/services/User_service.php new file mode 100755 index 0000000..f99cf69 --- /dev/null +++ b/application/services/User_service.php @@ -0,0 +1,458 @@ +_model = $credential_model; + $this->_factory = new User_factory($credential_model, $user_model, $member_profile_model); + } + + public function set_refer_log_model($refer_log_model) + { + $this->_refer_log_model = $refer_log_model; + } + + public function set_email_model($email_model) + { + $this->_email_model = $email_model; + } + + public function set_token_model($token_model) + { + $this->_token_model = $token_model; + } + + public function set_email_service($email_service) + { + $this->_email_service = $email_service; + } + + public function set_user_model($user_model) + { + $this->_user_model = $user_model; + } + + public function set_member_profile_model($member_profile_model) + { + $this->_member_profile_model = $member_profile_model; + } + + /** + * Register User + * + * @param string $email + * @param string $password + * @param integer $role + * @param string $refer + * @return integer|boolean + */ + public function register($email, $password, $role, $refer = '', $refer_type = 0) + { + $user_id = $this->_factory->create($this->_model, $email, $password, $role, 'n'); + + if ($user_id) + { + $refer_code = (isset($refer) && strlen($refer) > 0) ? $refer : ''; + if ($this->_refer_log_model && $refer_code != '') + { + $referrer_exist = $this->_model->get_by_field('refer', $refer_code); + + if ($referrer_exist) + { + $this->_refer_log_model->create([ + 'user_id' => $user_id, + 'referrer_user_id' => $referrer_exist->id, + 'status' => 0, + 'type' => $refer_type + ]); + } + } + + return $user_id; + } + + return FALSE; + } + + /** + * Register Social Login User + * + * @param string $email + * @param string $type + * @param integer $role + * @param string $refer + * @return integer|boolean + */ + public function register_social($email, $type, $role, $refer = '', $refer_type = 0) + { + $user_id = $this->_factory->create($this->_model, $email, ' ', $role, $type); + + if ($user_id) + { + $refer_code = (isset($refer) && strlen($refer) > 0) ? $refer : ''; + if ($this->_refer_log_model && $refer_code != '') + { + $referrer_exist = $this->_model->get_by_field('refer', $refer_code); + + if ($referrer_exist) + { + $this->_refer_log_model->create([ + 'user_id' => $user_id, + 'referrer_user_id' => $referrer_exist->id, + 'status' => 0, + 'type' => $refer_type + ]); + } + } + + return $user_id; + } + + return FALSE; + } + + /** + * Create Full User + * + * @param string $email + * @param string $password + * @param string $first_name + * @param string $last_name + * @param integer $role + * @param string $refer + * @return integer|boolean + */ + public function create($email, $password, $first_name, $last_name, $username, $role, $refer = '', $refer_type = 0) + { + $user_id = $this->_factory->create_full_user($this->_model, $email, $password, $first_name, $last_name, $username, $role, 'n'); + + if ($user_id) + { + $refer_code = (isset($refer) && strlen($refer) > 0) ? $refer : ''; + + if ($this->_refer_log_model && $refer_code != '') + { + $referrer_exist = $this->_model->get_by_field('refer', $refer_code); + + if ($referrer_exist) + { + $this->_refer_log_model->create([ + 'user_id' => $user_id, + 'referrer_user_id' => $referrer_exist->id, + 'status' => 0, + 'refer_type' => 0 + ]); + } + } + return $this->_model->get($user_id); + } + + return FALSE; + } + + /** + * login function. + * + * @access public + * @param mixed $email + * @param mixed $password + * @return bool true on success, false on failure + */ + public function login($email, $password) + { + $user = $this->_model->get_by_fields([ + 'email' => $email, + 'type' => 'n', + 'status' => $this->_model->get_mapping()::ACTIVE + ]); + + if ($user) + { + return password_verify($password, $user->password) ? $user : FALSE; + } + + return FALSE; + } + + /** + * login by role function. + * + * @access public + * @param mixed $email + * @param mixed $password + * @return bool true on success, false on failure + */ + public function login_by_role($email, $password, $role_id) + { + $user = $this->_model->get_by_fields([ + 'email' => $email, + 'type' => 'n', + 'role_id' => $role_id, + 'status' => $this->_model->get_mapping()::ACTIVE + ]); + + if ($user) + { + return password_verify($password, $user->password) ? $user : FALSE; + } + + return FALSE; + } + + /** + * get_redirect function. + * + * @access public + * @param string $redirect + * @return string + */ + public function get_redirect($redirect, $default = '') + { + return (strlen($redirect) > 0) ? $redirect : $default; + } + + /** + * Edit User Profile + * + * @param mixed $data + * @param integer $id + * @return boolean + */ + public function edit_user($data, $id) + { + foreach ($data as $key => $value) + { + if (is_string($value) && $data[$key] == '') + { + unset($data[$key]); + } + } + + if (isset($data['password']) && strlen($data['password']) > 0) + { + $data['password'] = str_replace('$2y$', '$2b$', password_hash($data['password'], PASSWORD_BCRYPT)); + } + + return $this->_model->edit($data, $id); + } + + /** + * Reset Password Token + * + * @param integer $user_id + * @return string + */ + public function reset_password_token($user_id, $limit_chars = false) + { + $token = rand(1000000, 9999999) . rand(1000000, 9999999) . rand(1000000, 9999999); + + if ($limit_chars) + { + $token = substr($token, 0, 7); + } + + $ttl_seconds = (24 * 60 * 60); + $this->_token_model->create([ + 'token' => $token, + 'data' => '{}', + 'type' => 0, + 'user_id' => $user_id, + 'ttl' => $ttl_seconds, + 'issue_at' => date('Y-m-j H:i:s'), + 'expire_at' => date('Y-m-j H:i:s', time() + $ttl_seconds), + 'status' => 1 + ]); + return $token; + } + + /** + * Forgot Password + * + * @param integer $id + * @param string $from_email + * @param string $link + * @return boolean + */ + public function forgot_password($email, $from_email, $link, $role) + { + $user = $this->_model->get_by_fields([ + 'email' => $email, + 'type' => 'n' + ]); + + if ($user && $user->status == $this->_model->get_mapping()::ACTIVE) + { + $token = $this->reset_password_token($user->id, TRUE); + $to = $email; + + if (!$this->_email_model) + { + throw new Exception('Missing Email Model'); + } + + $template = $this->_email_model->get_template('reset-password', [ + 'email' => $email, + 'reset_token' => $token, + 'link' => $link + ]); + + $html = $template->html; + $html .= "
    Thanks,"; + $html .= "

    The OutlineGurus Team"; + $html .= "
    "; + + return $this->_email_service->send($from_email, $to, $template->subject, $html); + } + + return FALSE; + } + + public function send_verify_token($email, $from_email, $link, $role) + { + $user = $this->_model->get_by_fields([ + 'email' => $email, + 'type' => 'n' + ]); + + if ($user && $user->status == $this->_model->get_mapping()::ACTIVE) + { + $token = $this->reset_password_token($user->user_id, TRUE); + $to = $email; + + if (!$this->_email_model) + { + throw new Exception('Missing Email Model'); + } + + $template = $this->_email_model->get_template('verify', [ + 'code' => $token + ]); + return $this->_email_service->send($from_email, $to, $template->subject, $template->html); + } + + return FALSE; + } + + /** + * Validate Reset Token + * + * @param string $token + * @param integer $user_id + * @return boolean|mixed + */ + public function valid_reset_token($token) + { + $token_found = $this->_token_model->get_by_fields([ + 'token' => $token, + 'status' => 1 + ]); + + if ($token_found) + { + return $this->_model->get($token_found->user_id); + } + + return FALSE; + } + + /** + * Invalidate Token + * + * @param string $token + * @param integer $user_id + * @return boolean + */ + public function invalidate_token($token, $user_id) + { + $token_found = $this->_token_model->get_by_fields([ + 'token' => $token, + 'user_id' => $user_id + ]); + + if ($token_found) + { + return $this->_token_model->edit([ + 'status' => 0 + ], $token_found->id); + } + + return FALSE; + } + + /** + * Reset Password + * + * @param integer $user_id + * @param string $password + * @return boolean + */ + public function reset_password($user_id, $password) + { + $user = $this->_model->get($user_id); + + if ($user->status == $this->_model->get_mapping()::ACTIVE) + { + return $this->_model->edit([ + 'password' => str_replace('$2y$', '$2b$', password_hash($password, PASSWORD_BCRYPT)) + ], $user_id); + } + + return FALSE; + } + + /** + * existing_google_user_from_email function that find if user is google user. + * + * @access private + * @param mixed $email + * @return int the user id + */ + public function is_google_user($user) + { + return ($user->type == $this->_model->get_mapping()::GOOGLE_LOGIN_TYPE) && ($user->status == $this->_model->get_mapping()::ACTIVE); + } + + /** + * existing_github_user_from_email function that find if user is github user. + * + * @access private + * @param mixed $email + * @return int the user id + */ + private function is_github_user($user) + { + return ($user->type == $this->_model->get_mapping()::GITHUB_LOGIN_TYPE) && ($user->status == $this->_model->get_mapping()::ACTIVE); + } + + /** + * existing_facebook_user_from_email function that find if user is facebook user. + * + * @access private + * @param mixed $email + * @return int the user id + */ + public function is_facebook_user($user) + { + return ($user->type == 'f') && ($user->status == $this->_model->get_mapping()::ACTIVE); + } +} diff --git a/application/services/index.html b/application/services/index.html new file mode 100755 index 0000000..b702fbc --- /dev/null +++ b/application/services/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/view_models/Admin_profile_credential_view_model.php b/application/view_models/Admin_profile_credential_view_model.php new file mode 100755 index 0000000..cb91ee8 --- /dev/null +++ b/application/view_models/Admin_profile_credential_view_model.php @@ -0,0 +1,62 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_email = $model->email; + } + + public function get_email () + { + return $this->_email; + } + + public function set_email ($email) + { + $this->_email = $email; + } +} \ No newline at end of file diff --git a/application/view_models/Admin_profile_view_model.php b/application/view_models/Admin_profile_view_model.php new file mode 100755 index 0000000..6504a00 --- /dev/null +++ b/application/view_models/Admin_profile_view_model.php @@ -0,0 +1,87 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_first_name = $model->first_name; + $this->_last_name = $model->last_name; + } + + public function get_first_name () + { + return $this->_first_name; + } + + public function set_first_name ($first_name) + { + $this->_first_name = $first_name; + } + + public function get_email () + { + return $this->_email; + } + + public function set_email ($email) + { + $this->_email = $email; + } + + public function get_last_name () + { + return $this->_last_name; + } + + public function set_last_name ($last_name) + { + $this->_last_name = $last_name; + } +} \ No newline at end of file diff --git a/application/view_models/Attribute_type_admin_add_view_model.php b/application/view_models/Attribute_type_admin_add_view_model.php new file mode 100755 index 0000000..4d15a2e --- /dev/null +++ b/application/view_models/Attribute_type_admin_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Attribute_type_admin_edit_view_model.php b/application/view_models/Attribute_type_admin_edit_view_model.php new file mode 100755 index 0000000..da712c4 --- /dev/null +++ b/application/view_models/Attribute_type_admin_edit_view_model.php @@ -0,0 +1,139 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_type = $model->type; + $this->_field = $model->field; + $this->_options = $model->options; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_type () + { + return $this->_type; + } + + public function set_type ($type) + { + $this->_type = $type; + } + + public function get_field () + { + return $this->_field; + } + + public function set_field ($field) + { + $this->_field = $field; + } + + public function get_options () + { + return $this->_options; + } + + public function set_options ($options) + { + $this->_options = $options; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Attribute_type_admin_list_paginate_view_model.php b/application/view_models/Attribute_type_admin_list_paginate_view_model.php new file mode 100755 index 0000000..0700e3e --- /dev/null +++ b/application/view_models/Attribute_type_admin_list_paginate_view_model.php @@ -0,0 +1,493 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_type () + { + return $this->_type; + } + + public function set_type ($type) + { + $this->_type = $type; + } + + public $_type = NULL; + + public function get_field () + { + return $this->_field; + } + + public function set_field ($field) + { + $this->_field = $field; + } + + public $_field = NULL; + + public function get_options () + { + return $this->_options; + } + + public function set_options ($options) + { + $this->_options = $options; + } + + public $_options = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['type'] = $list[$key]->type; + $clean_list_entry['field'] = $list[$key]->field; + $clean_list_entry['options'] = $list[$key]->options; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['type'] = $list[$key]->type; + $clean_list_entry['field'] = $list[$key]->field; + $clean_list_entry['options'] = $list[$key]->options; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Attribute_type_admin_view_view_model.php b/application/view_models/Attribute_type_admin_view_view_model.php new file mode 100755 index 0000000..42d72cd --- /dev/null +++ b/application/view_models/Attribute_type_admin_view_view_model.php @@ -0,0 +1,149 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_type = $model->type; + $this->_field = $model->field; + $this->_options = $model->options; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_type () + { + return $this->_type; + } + + public function set_type ($type) + { + $this->_type = $type; + } + + public function get_field () + { + return $this->_field; + } + + public function set_field ($field) + { + $this->_field = $field; + } + + public function get_options () + { + return $this->_options; + } + + public function set_options ($options) + { + $this->_options = $options; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'type' => $this->get_type(), + 'field' => $this->get_field(), + 'options' => $this->get_options(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Cart_admin_add_view_model.php b/application/view_models/Cart_admin_add_view_model.php new file mode 100755 index 0000000..991ff06 --- /dev/null +++ b/application/view_models/Cart_admin_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Cart_admin_edit_view_model.php b/application/view_models/Cart_admin_edit_view_model.php new file mode 100755 index 0000000..f5eaf8b --- /dev/null +++ b/application/view_models/Cart_admin_edit_view_model.php @@ -0,0 +1,175 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_product_id = $model->product_id; + $this->_user_id = $model->user_id; + $this->_session_id = $model->session_id; + $this->_subtotal = $model->subtotal; + $this->_quantity = $model->quantity; + $this->_total = $model->total; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_product_id () + { + return $this->_product_id; + } + + public function set_product_id ($product_id) + { + $this->_product_id = $product_id; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_session_id () + { + return $this->_session_id; + } + + public function set_session_id ($session_id) + { + $this->_session_id = $session_id; + } + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public function get_quantity () + { + return $this->_quantity; + } + + public function set_quantity ($quantity) + { + $this->_quantity = $quantity; + } + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Cart_admin_list_paginate_view_model.php b/application/view_models/Cart_admin_list_paginate_view_model.php new file mode 100755 index 0000000..be76221 --- /dev/null +++ b/application/view_models/Cart_admin_list_paginate_view_model.php @@ -0,0 +1,535 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_product_id () + { + return $this->_product_id; + } + + public function set_product_id ($product_id) + { + $this->_product_id = $product_id; + } + + public $_product_id = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_session_id () + { + return $this->_session_id; + } + + public function set_session_id ($session_id) + { + $this->_session_id = $session_id; + } + + public $_session_id = NULL; + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public $_subtotal = NULL; + + public function get_quantity () + { + return $this->_quantity; + } + + public function set_quantity ($quantity) + { + $this->_quantity = $quantity; + } + + public $_quantity = NULL; + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public $_total = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['product_id'] = $list[$key]->product_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['session_id'] = $list[$key]->session_id; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['quantity'] = $list[$key]->quantity; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['product_id'] = $list[$key]->product_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['session_id'] = $list[$key]->session_id; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['quantity'] = $list[$key]->quantity; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Cart_admin_view_view_model.php b/application/view_models/Cart_admin_view_view_model.php new file mode 100755 index 0000000..5583b67 --- /dev/null +++ b/application/view_models/Cart_admin_view_view_model.php @@ -0,0 +1,188 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_product_id = $model->product_id; + $this->_user_id = $model->user_id; + $this->_session_id = $model->session_id; + $this->_subtotal = $model->subtotal; + $this->_quantity = $model->quantity; + $this->_total = $model->total; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_product_id () + { + return $this->_product_id; + } + + public function set_product_id ($product_id) + { + $this->_product_id = $product_id; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_session_id () + { + return $this->_session_id; + } + + public function set_session_id ($session_id) + { + $this->_session_id = $session_id; + } + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public function get_quantity () + { + return $this->_quantity; + } + + public function set_quantity ($quantity) + { + $this->_quantity = $quantity; + } + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'product_id' => $this->get_product_id(), + 'user_id' => $this->get_user_id(), + 'session_id' => $this->get_session_id(), + 'subtotal' => $this->get_subtotal(), + 'quantity' => $this->get_quantity(), + 'total' => $this->get_total(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Cart_member_add_view_model.php b/application/view_models/Cart_member_add_view_model.php new file mode 100755 index 0000000..c09393e --- /dev/null +++ b/application/view_models/Cart_member_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Cart_member_edit_view_model.php b/application/view_models/Cart_member_edit_view_model.php new file mode 100755 index 0000000..c18b8d6 --- /dev/null +++ b/application/view_models/Cart_member_edit_view_model.php @@ -0,0 +1,175 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_product_id = $model->product_id; + $this->_user_id = $model->user_id; + $this->_session_id = $model->session_id; + $this->_subtotal = $model->subtotal; + $this->_quantity = $model->quantity; + $this->_total = $model->total; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_product_id () + { + return $this->_product_id; + } + + public function set_product_id ($product_id) + { + $this->_product_id = $product_id; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_session_id () + { + return $this->_session_id; + } + + public function set_session_id ($session_id) + { + $this->_session_id = $session_id; + } + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public function get_quantity () + { + return $this->_quantity; + } + + public function set_quantity ($quantity) + { + $this->_quantity = $quantity; + } + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Cart_member_list_paginate_view_model.php b/application/view_models/Cart_member_list_paginate_view_model.php new file mode 100755 index 0000000..bf1fbd9 --- /dev/null +++ b/application/view_models/Cart_member_list_paginate_view_model.php @@ -0,0 +1,535 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_product_id () + { + return $this->_product_id; + } + + public function set_product_id ($product_id) + { + $this->_product_id = $product_id; + } + + public $_product_id = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_session_id () + { + return $this->_session_id; + } + + public function set_session_id ($session_id) + { + $this->_session_id = $session_id; + } + + public $_session_id = NULL; + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public $_subtotal = NULL; + + public function get_quantity () + { + return $this->_quantity; + } + + public function set_quantity ($quantity) + { + $this->_quantity = $quantity; + } + + public $_quantity = NULL; + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public $_total = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['product_id'] = $list[$key]->product_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['session_id'] = $list[$key]->session_id; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['quantity'] = $list[$key]->quantity; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['product_id'] = $list[$key]->product_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['session_id'] = $list[$key]->session_id; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['quantity'] = $list[$key]->quantity; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Cart_member_view_view_model.php b/application/view_models/Cart_member_view_view_model.php new file mode 100755 index 0000000..b97a474 --- /dev/null +++ b/application/view_models/Cart_member_view_view_model.php @@ -0,0 +1,188 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_product_id = $model->product_id; + $this->_user_id = $model->user_id; + $this->_session_id = $model->session_id; + $this->_subtotal = $model->subtotal; + $this->_quantity = $model->quantity; + $this->_total = $model->total; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_product_id () + { + return $this->_product_id; + } + + public function set_product_id ($product_id) + { + $this->_product_id = $product_id; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_session_id () + { + return $this->_session_id; + } + + public function set_session_id ($session_id) + { + $this->_session_id = $session_id; + } + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public function get_quantity () + { + return $this->_quantity; + } + + public function set_quantity ($quantity) + { + $this->_quantity = $quantity; + } + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'product_id' => $this->get_product_id(), + 'user_id' => $this->get_user_id(), + 'session_id' => $this->get_session_id(), + 'subtotal' => $this->get_subtotal(), + 'quantity' => $this->get_quantity(), + 'total' => $this->get_total(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Category_admin_add_view_model.php b/application/view_models/Category_admin_add_view_model.php new file mode 100755 index 0000000..09d0eee --- /dev/null +++ b/application/view_models/Category_admin_add_view_model.php @@ -0,0 +1,89 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Category_admin_edit_view_model.php b/application/view_models/Category_admin_edit_view_model.php new file mode 100755 index 0000000..95658f9 --- /dev/null +++ b/application/view_models/Category_admin_edit_view_model.php @@ -0,0 +1,133 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_name = $model->name; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Category_admin_list_paginate_view_model.php b/application/view_models/Category_admin_list_paginate_view_model.php new file mode 100755 index 0000000..f1803f5 --- /dev/null +++ b/application/view_models/Category_admin_list_paginate_view_model.php @@ -0,0 +1,487 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public $_name = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Class_admin_add_view_model.php b/application/view_models/Class_admin_add_view_model.php new file mode 100755 index 0000000..44e6ab3 --- /dev/null +++ b/application/view_models/Class_admin_add_view_model.php @@ -0,0 +1,89 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Class_admin_edit_view_model.php b/application/view_models/Class_admin_edit_view_model.php new file mode 100755 index 0000000..09dbb0e --- /dev/null +++ b/application/view_models/Class_admin_edit_view_model.php @@ -0,0 +1,133 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_name = $model->name; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Class_admin_list_paginate_view_model.php b/application/view_models/Class_admin_list_paginate_view_model.php new file mode 100755 index 0000000..b1e8ed2 --- /dev/null +++ b/application/view_models/Class_admin_list_paginate_view_model.php @@ -0,0 +1,487 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public $_name = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Color_admin_add_view_model.php b/application/view_models/Color_admin_add_view_model.php new file mode 100755 index 0000000..b2e9ebe --- /dev/null +++ b/application/view_models/Color_admin_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Color_admin_edit_view_model.php b/application/view_models/Color_admin_edit_view_model.php new file mode 100755 index 0000000..4e02200 --- /dev/null +++ b/application/view_models/Color_admin_edit_view_model.php @@ -0,0 +1,127 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_name = $model->name; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Color_admin_list_paginate_view_model.php b/application/view_models/Color_admin_list_paginate_view_model.php new file mode 100755 index 0000000..ce2f806 --- /dev/null +++ b/application/view_models/Color_admin_list_paginate_view_model.php @@ -0,0 +1,479 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public $_name = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Color_admin_view_view_model.php b/application/view_models/Color_admin_view_view_model.php new file mode 100755 index 0000000..93c8735 --- /dev/null +++ b/application/view_models/Color_admin_view_view_model.php @@ -0,0 +1,136 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_name = $model->name; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'name' => $this->get_name(), + 'status' => $this->get_status(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Contact_us_admin_list_paginate_view_model.php b/application/view_models/Contact_us_admin_list_paginate_view_model.php new file mode 100755 index 0000000..1f5ce21 --- /dev/null +++ b/application/view_models/Contact_us_admin_list_paginate_view_model.php @@ -0,0 +1,497 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public $_name = NULL; + + public function get_email () + { + return $this->_email; + } + + public function set_email ($email) + { + $this->_email = $email; + } + + public $_email = NULL; + + public function get_message () + { + return $this->_message; + } + + public function set_message ($message) + { + $this->_message = $message; + } + + public $_message = NULL; + + public function get_created_at () + { + return $this->_created_at; + } + + public function set_created_at ($created_at) + { + $this->_created_at = $created_at; + } + + public $_created_at = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Contact_us_admin_view_view_model.php b/application/view_models/Contact_us_admin_view_view_model.php new file mode 100755 index 0000000..dcb19af --- /dev/null +++ b/application/view_models/Contact_us_admin_view_view_model.php @@ -0,0 +1,109 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function to_json () + { + return [ + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Content_admin_add_view_model.php b/application/view_models/Content_admin_add_view_model.php new file mode 100755 index 0000000..db904c5 --- /dev/null +++ b/application/view_models/Content_admin_add_view_model.php @@ -0,0 +1,95 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function content_type_mapping () + { + return $this->_entity->content_type_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Content_admin_edit_view_model.php b/application/view_models/Content_admin_edit_view_model.php new file mode 100755 index 0000000..dfb0ff2 --- /dev/null +++ b/application/view_models/Content_admin_edit_view_model.php @@ -0,0 +1,163 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_content_name = $model->content_name; + $this->_content_type = $model->content_type; + $this->_content = $model->content; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function content_type_mapping () + { + return $this->_entity->content_type_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_content_name () + { + return $this->_content_name; + } + + public function set_content_name ($content_name) + { + $this->_content_name = $content_name; + } + + public function get_content_type () + { + return $this->_content_type; + } + + public function set_content_type ($content_type) + { + $this->_content_type = $content_type; + } + + public function get_content () + { + return $this->_content; + } + + public function set_content ($content) + { + $this->_content = $content; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Content_admin_list_paginate_view_model.php b/application/view_models/Content_admin_list_paginate_view_model.php new file mode 100755 index 0000000..8889443 --- /dev/null +++ b/application/view_models/Content_admin_list_paginate_view_model.php @@ -0,0 +1,501 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_content_name () + { + return $this->_content_name; + } + + public function set_content_name ($content_name) + { + $this->_content_name = $content_name; + } + + public $_content_name = NULL; + + public function get_content_type () + { + return $this->_content_type; + } + + public function set_content_type ($content_type) + { + $this->_content_type = $content_type; + } + + public $_content_type = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function content_type_mapping () + { + return $this->_entity->content_type_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->content_type = $this->content_type_mapping()[$value->content_type]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->content_type = $this->content_type_mapping()[$value->content_type]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Dispute_admin_add_view_model.php b/application/view_models/Dispute_admin_add_view_model.php new file mode 100755 index 0000000..45d6da5 --- /dev/null +++ b/application/view_models/Dispute_admin_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Dispute_admin_edit_view_model.php b/application/view_models/Dispute_admin_edit_view_model.php new file mode 100755 index 0000000..5c4dd9d --- /dev/null +++ b/application/view_models/Dispute_admin_edit_view_model.php @@ -0,0 +1,187 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_order_id = $model->order_id; + $this->_user_id = $model->user_id; + $this->_reason = $model->reason; + $this->_explanation = $model->explanation; + $this->_stripe_charge_id = $model->stripe_charge_id; + $this->_stripe_dispute_id = $model->stripe_dispute_id; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_reason () + { + return $this->_reason; + } + + public function set_reason ($reason) + { + $this->_reason = $reason; + } + + public function get_explanation () + { + return $this->_explanation; + } + + public function set_explanation ($explanation) + { + $this->_explanation = $explanation; + } + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public function get_stripe_dispute_id () + { + return $this->_stripe_dispute_id; + } + + public function set_stripe_dispute_id ($stripe_dispute_id) + { + $this->_stripe_dispute_id = $stripe_dispute_id; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Dispute_admin_list_paginate_view_model.php b/application/view_models/Dispute_admin_list_paginate_view_model.php new file mode 100755 index 0000000..7635ade --- /dev/null +++ b/application/view_models/Dispute_admin_list_paginate_view_model.php @@ -0,0 +1,537 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public $_order_id = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_reason () + { + return $this->_reason; + } + + public function set_reason ($reason) + { + $this->_reason = $reason; + } + + public $_reason = NULL; + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public $_stripe_charge_id = NULL; + + public function get_stripe_dispute_id () + { + return $this->_stripe_dispute_id; + } + + public function set_stripe_dispute_id ($stripe_dispute_id) + { + $this->_stripe_dispute_id = $stripe_dispute_id; + } + + public $_stripe_dispute_id = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['reason'] = $list[$key]->reason; + $clean_list_entry['explanation'] = $list[$key]->explanation; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['stripe_dispute_id'] = $list[$key]->stripe_dispute_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['reason'] = $list[$key]->reason; + $clean_list_entry['explanation'] = $list[$key]->explanation; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['stripe_dispute_id'] = $list[$key]->stripe_dispute_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Dispute_member_list_paginate_view_model.php b/application/view_models/Dispute_member_list_paginate_view_model.php new file mode 100755 index 0000000..6d61114 --- /dev/null +++ b/application/view_models/Dispute_member_list_paginate_view_model.php @@ -0,0 +1,537 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public $_order_id = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_reason () + { + return $this->_reason; + } + + public function set_reason ($reason) + { + $this->_reason = $reason; + } + + public $_reason = NULL; + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public $_stripe_charge_id = NULL; + + public function get_stripe_dispute_id () + { + return $this->_stripe_dispute_id; + } + + public function set_stripe_dispute_id ($stripe_dispute_id) + { + $this->_stripe_dispute_id = $stripe_dispute_id; + } + + public $_stripe_dispute_id = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['reason'] = $list[$key]->reason; + $clean_list_entry['explanation'] = $list[$key]->explanation; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['stripe_dispute_id'] = $list[$key]->stripe_dispute_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['reason'] = $list[$key]->reason; + $clean_list_entry['explanation'] = $list[$key]->explanation; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['stripe_dispute_id'] = $list[$key]->stripe_dispute_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Dispute_member_view_view_model.php b/application/view_models/Dispute_member_view_view_model.php new file mode 100755 index 0000000..d832fd4 --- /dev/null +++ b/application/view_models/Dispute_member_view_view_model.php @@ -0,0 +1,201 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_order_id = $model->order_id; + $this->_user_id = $model->user_id; + $this->_reason = $model->reason; + $this->_explanation = $model->explanation; + $this->_stripe_charge_id = $model->stripe_charge_id; + $this->_stripe_dispute_id = $model->stripe_dispute_id; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_reason () + { + return $this->_reason; + } + + public function set_reason ($reason) + { + $this->_reason = $reason; + } + + public function get_explanation () + { + return $this->_explanation; + } + + public function set_explanation ($explanation) + { + $this->_explanation = $explanation; + } + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public function get_stripe_dispute_id () + { + return $this->_stripe_dispute_id; + } + + public function set_stripe_dispute_id ($stripe_dispute_id) + { + $this->_stripe_dispute_id = $stripe_dispute_id; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'order_id' => $this->get_order_id(), + 'user_id' => $this->get_user_id(), + 'reason' => $this->get_reason(), + 'explanation' => $this->get_explanation(), + 'stripe_charge_id' => $this->get_stripe_charge_id(), + 'stripe_dispute_id' => $this->get_stripe_dispute_id(), + 'status' => $this->get_status(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Email_admin_add_view_model.php b/application/view_models/Email_admin_add_view_model.php new file mode 100755 index 0000000..0a7f89b --- /dev/null +++ b/application/view_models/Email_admin_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Email_admin_edit_view_model.php b/application/view_models/Email_admin_edit_view_model.php new file mode 100755 index 0000000..d5fec82 --- /dev/null +++ b/application/view_models/Email_admin_edit_view_model.php @@ -0,0 +1,163 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_subject = $model->subject; + $this->_email_header = $model->email_header; + $this->_html = $model->html; + $this->_email_footer = $model->email_footer; + $this->_tag = $model->tag; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_subject () + { + return $this->_subject; + } + + public function set_subject ($subject) + { + $this->_subject = $subject; + } + + public function get_email_header () + { + return $this->_email_header; + } + + public function set_email_header ($email_header) + { + $this->_email_header = $email_header; + } + + public function get_html () + { + return $this->_html; + } + + public function set_html ($html) + { + $this->_html = $html; + } + + public function get_email_footer () + { + return $this->_email_footer; + } + + public function set_email_footer ($email_footer) + { + $this->_email_footer = $email_footer; + } + + public function get_tag () + { + return $this->_tag; + } + + public function set_tag ($tag) + { + $this->_tag = $tag; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Email_admin_list_paginate_view_model.php b/application/view_models/Email_admin_list_paginate_view_model.php new file mode 100755 index 0000000..022a69a --- /dev/null +++ b/application/view_models/Email_admin_list_paginate_view_model.php @@ -0,0 +1,493 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_slug () + { + return $this->_slug; + } + + public function set_slug ($slug) + { + $this->_slug = $slug; + } + + public $_slug = NULL; + + public function get_subject () + { + return $this->_subject; + } + + public function set_subject ($subject) + { + $this->_subject = $subject; + } + + public $_subject = NULL; + + public function get_tag () + { + return $this->_tag; + } + + public function set_tag ($tag) + { + $this->_tag = $tag; + } + + public $_tag = NULL; + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['slug'] = $list[$key]->slug; + $clean_list_entry['subject'] = $list[$key]->subject; + $clean_list_entry['tag'] = $list[$key]->tag; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['slug'] = $list[$key]->slug; + $clean_list_entry['subject'] = $list[$key]->subject; + $clean_list_entry['tag'] = $list[$key]->tag; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Email_admin_view_view_model.php b/application/view_models/Email_admin_view_view_model.php new file mode 100755 index 0000000..2e753bd --- /dev/null +++ b/application/view_models/Email_admin_view_view_model.php @@ -0,0 +1,188 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_slug = $model->slug; + $this->_subject = $model->subject; + $this->_tag = $model->tag; + $this->_email_header = $model->email_header; + $this->_html = $model->html; + $this->_email_footer = $model->email_footer; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_slug () + { + return $this->_slug; + } + + public function set_slug ($slug) + { + $this->_slug = $slug; + } + + public function get_subject () + { + return $this->_subject; + } + + public function set_subject ($subject) + { + $this->_subject = $subject; + } + + public function get_tag () + { + return $this->_tag; + } + + public function set_tag ($tag) + { + $this->_tag = $tag; + } + + public function get_email_header () + { + return $this->_email_header; + } + + public function set_email_header ($email_header) + { + $this->_email_header = $email_header; + } + + public function get_html () + { + return $this->_html; + } + + public function set_html ($html) + { + $this->_html = $html; + } + + public function get_email_footer () + { + return $this->_email_footer; + } + + public function set_email_footer ($email_footer) + { + $this->_email_footer = $email_footer; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'slug' => $this->get_slug(), + 'subject' => $this->get_subject(), + 'tag' => $this->get_tag(), + 'email_header' => $this->get_email_header(), + 'html' => $this->get_html(), + 'email_footer' => $this->get_email_footer(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Image_admin_add_view_model.php b/application/view_models/Image_admin_add_view_model.php new file mode 100755 index 0000000..41f17a8 --- /dev/null +++ b/application/view_models/Image_admin_add_view_model.php @@ -0,0 +1,89 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function type_mapping () + { + return $this->_entity->type_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Image_admin_list_paginate_view_model.php b/application/view_models/Image_admin_list_paginate_view_model.php new file mode 100755 index 0000000..c4551cb --- /dev/null +++ b/application/view_models/Image_admin_list_paginate_view_model.php @@ -0,0 +1,461 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function type_mapping () + { + return $this->_entity->type_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->type = $this->type_mapping()[$value->type]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['url'] = $list[$key]->url; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->type = $this->type_mapping()[$value->type]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['url'] = $list[$key]->url; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Image_admin_view_view_model.php b/application/view_models/Image_admin_view_view_model.php new file mode 100755 index 0000000..61f400b --- /dev/null +++ b/application/view_models/Image_admin_view_view_model.php @@ -0,0 +1,141 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_url = $model->url; + $this->_type = $model->type; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function type_mapping () + { + return $this->_entity->type_mapping(); + + } + + public function get_url () + { + return $this->_url; + } + + public function set_url ($url) + { + $this->_url = $url; + } + + public function get_type () + { + return $this->_type; + } + + public function set_type ($type) + { + $this->_type = $type; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function to_json () + { + return [ + 'url' => $this->get_url(), + 'type' => $this->get_type(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Image_asset_paginate_view_model.php b/application/view_models/Image_asset_paginate_view_model.php new file mode 100755 index 0000000..ea1b914 --- /dev/null +++ b/application/view_models/Image_asset_paginate_view_model.php @@ -0,0 +1,277 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = (int) $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_url () + { + return $this->_url; + } + + public function set_url ($url) + { + $this->_url = $url; + } + + public function get_type () + { + return $this->_type; + } + + public function set_type ($type) + { + $this->_type = $type; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function type_mapping () + { + return $this->_entity->type_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->type = $this->type_mapping()[$value->type]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['url'] = $list[$key]->url; + $clean_list_entry['type'] = $list[$key]->type; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'per_page' => $this->get_per_page(), + 'item' => $clean_list + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_admin_add_view_model.php b/application/view_models/Inventory_admin_add_view_model.php new file mode 100755 index 0000000..da91f95 --- /dev/null +++ b/application/view_models/Inventory_admin_add_view_model.php @@ -0,0 +1,107 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function note_type_mapping () + { + return $this->_entity->note_type_mapping(); + + } + + public function pin_to_top_mapping () + { + return $this->_entity->pin_to_top_mapping(); + + } + + public function approve_mapping () + { + return $this->_entity->approve_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_admin_edit_view_model.php b/application/view_models/Inventory_admin_edit_view_model.php new file mode 100755 index 0000000..09fe457 --- /dev/null +++ b/application/view_models/Inventory_admin_edit_view_model.php @@ -0,0 +1,363 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_title = $model->title; + $this->_school_id = $model->school_id; + $this->_professor_id = $model->professor_id; + $this->_class_id = $model->class_id; + $this->_textbook_id = $model->textbook_id; + $this->_word_count = $model->word_count; + $this->_year = $model->year; + $this->_isbn = $model->isbn; + $this->_paypal_email = $model->paypal_email; + $this->_file = $model->file; + $this->_feature_image = $model->feature_image; + $this->_feature_image2 = $model->feature_image2; + $this->_feature_image3 = $model->feature_image3; + $this->_note_type = $model->note_type; + $this->_description = $model->description; + $this->_inventory_note = $model->inventory_note; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function note_type_mapping () + { + return $this->_entity->note_type_mapping(); + + } + + public function pin_to_top_mapping () + { + return $this->_entity->pin_to_top_mapping(); + + } + + public function approve_mapping () + { + return $this->_entity->approve_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_title () + { + return $this->_title; + } + + public function set_title ($title) + { + $this->_title = $title; + } + + public function get_school_id () + { + return $this->_school_id; + } + + public function set_school_id ($school_id) + { + $this->_school_id = $school_id; + } + + public function get_professor_id () + { + return $this->_professor_id; + } + + public function set_professor_id ($professor_id) + { + $this->_professor_id = $professor_id; + } + + public function get_class_id () + { + return $this->_class_id; + } + + public function set_class_id ($class_id) + { + $this->_class_id = $class_id; + } + + public function get_textbook_id () + { + return $this->_textbook_id; + } + + public function set_textbook_id ($textbook_id) + { + $this->_textbook_id = $textbook_id; + } + + public function get_word_count () + { + return $this->_word_count; + } + + public function set_word_count ($word_count) + { + $this->_word_count = $word_count; + } + + public function get_year () + { + return $this->_year; + } + + public function set_year ($year) + { + $this->_year = $year; + } + + public function get_isbn () + { + return $this->_isbn; + } + + public function set_isbn ($isbn) + { + $this->_isbn = $isbn; + } + + public function get_paypal_email () + { + return $this->_paypal_email; + } + + public function set_paypal_email ($paypal_email) + { + $this->_paypal_email = $paypal_email; + } + + public function get_file () + { + return $this->_file; + } + + public function set_file ($file) + { + $this->_file = $file; + } + + public function get_file_id () + { + return $this->_file_id; + } + + public function set_file_id ($file) + { + $this->_file_id = $file; + } + + public function get_feature_image () + { + return $this->_feature_image; + } + + public function set_feature_image ($feature_image) + { + $this->_feature_image = $feature_image; + } + + public function get_feature_image_id () + { + return $this->_feature_image_id; + } + + public function set_feature_image_id ($feature_image) + { + $this->_feature_image_id = $feature_image; + } + + public function get_feature_image2 () + { + return $this->_feature_image2; + } + + public function set_feature_image2 ($feature_image2) + { + $this->_feature_image2 = $feature_image2; + } + + public function get_feature_image2_id () + { + return $this->_feature_image2_id; + } + + public function set_feature_image2_id ($feature_image2) + { + $this->_feature_image2_id = $feature_image2; + } + + public function get_feature_image3 () + { + return $this->_feature_image3; + } + + public function set_feature_image3 ($feature_image3) + { + $this->_feature_image3 = $feature_image3; + } + + public function get_feature_image3_id () + { + return $this->_feature_image3_id; + } + + public function set_feature_image3_id ($feature_image3) + { + $this->_feature_image3_id = $feature_image3; + } + + public function get_note_type () + { + return $this->_note_type; + } + + public function set_note_type ($note_type) + { + $this->_note_type = $note_type; + } + + public function get_description () + { + return $this->_description; + } + + public function set_description ($description) + { + $this->_description = $description; + } + + public function get_inventory_note () + { + return $this->_inventory_note; + } + + public function set_inventory_note ($inventory_note) + { + $this->_inventory_note = $inventory_note; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_admin_list_paginate_view_model.php b/application/view_models/Inventory_admin_list_paginate_view_model.php new file mode 100755 index 0000000..9d288a9 --- /dev/null +++ b/application/view_models/Inventory_admin_list_paginate_view_model.php @@ -0,0 +1,617 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_title () + { + return $this->_title; + } + + public function set_title ($title) + { + $this->_title = $title; + } + + public $_title = NULL; + + public function get_school_id () + { + return $this->_school_id; + } + + public function set_school_id ($school_id) + { + $this->_school_id = $school_id; + } + + public $_school_id = NULL; + + public function get_professor_id () + { + return $this->_professor_id; + } + + public function set_professor_id ($professor_id) + { + $this->_professor_id = $professor_id; + } + + public $_professor_id = NULL; + + public function get_class_id () + { + return $this->_class_id; + } + + public function set_class_id ($class_id) + { + $this->_class_id = $class_id; + } + + public $_class_id = NULL; + + public function get_textbook_id () + { + return $this->_textbook_id; + } + + public function set_textbook_id ($textbook_id) + { + $this->_textbook_id = $textbook_id; + } + + public $_textbook_id = NULL; + + public function get_word_count () + { + return $this->_word_count; + } + + public function set_word_count ($word_count) + { + $this->_word_count = $word_count; + } + + public $_word_count = NULL; + + public function get_year () + { + return $this->_year; + } + + public function set_year ($year) + { + $this->_year = $year; + } + + public $_year = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function note_type_mapping () + { + return $this->_entity->note_type_mapping(); + + } + + public function pin_to_top_mapping () + { + return $this->_entity->pin_to_top_mapping(); + + } + + public function approve_mapping () + { + return $this->_entity->approve_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->note_type = $this->note_type_mapping()[$value->note_type]; + $list[$key]->pin_to_top = $this->pin_to_top_mapping()[$value->pin_to_top]; + $list[$key]->approve = $this->approve_mapping()[$value->approve]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['title'] = $list[$key]->title; + $clean_list_entry['school_id'] = $list[$key]->school_id; + $clean_list_entry['professor_id'] = $list[$key]->professor_id; + $clean_list_entry['class_id'] = $list[$key]->class_id; + $clean_list_entry['textbook_id'] = $list[$key]->textbook_id; + $clean_list_entry['word_count'] = $list[$key]->word_count; + $clean_list_entry['year'] = $list[$key]->year; + $clean_list_entry['isbn'] = $list[$key]->isbn; + $clean_list_entry['paypal_email'] = $list[$key]->paypal_email; + $clean_list_entry['file'] = $list[$key]->file; + $clean_list_entry['file_id'] = $list[$key]->file_id; + $clean_list_entry['feature_image'] = $list[$key]->feature_image; + $clean_list_entry['feature_image_id'] = $list[$key]->feature_image_id; + $clean_list_entry['note_type'] = $list[$key]->note_type; + $clean_list_entry['description'] = $list[$key]->description; + $clean_list_entry['inventory_note'] = $list[$key]->inventory_note; + $clean_list_entry['pin_to_top'] = $list[$key]->pin_to_top; + $clean_list_entry['approve'] = $list[$key]->approve; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->note_type = $this->note_type_mapping()[$value->note_type]; + $list[$key]->pin_to_top = $this->pin_to_top_mapping()[$value->pin_to_top]; + $list[$key]->approve = $this->approve_mapping()[$value->approve]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['title'] = $list[$key]->title; + $clean_list_entry['school_id'] = $list[$key]->school_id; + $clean_list_entry['professor_id'] = $list[$key]->professor_id; + $clean_list_entry['class_id'] = $list[$key]->class_id; + $clean_list_entry['textbook_id'] = $list[$key]->textbook_id; + $clean_list_entry['word_count'] = $list[$key]->word_count; + $clean_list_entry['year'] = $list[$key]->year; + $clean_list_entry['isbn'] = $list[$key]->isbn; + $clean_list_entry['paypal_email'] = $list[$key]->paypal_email; + $clean_list_entry['file'] = $list[$key]->file; + $clean_list_entry['file_id'] = $list[$key]->file_id; + $clean_list_entry['feature_image'] = $list[$key]->feature_image; + $clean_list_entry['feature_image_id'] = $list[$key]->feature_image_id; + $clean_list_entry['note_type'] = $list[$key]->note_type; + $clean_list_entry['description'] = $list[$key]->description; + $clean_list_entry['inventory_note'] = $list[$key]->inventory_note; + $clean_list_entry['pin_to_top'] = $list[$key]->pin_to_top; + $clean_list_entry['approve'] = $list[$key]->approve; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Inventory_admin_view_view_model.php b/application/view_models/Inventory_admin_view_view_model.php new file mode 100755 index 0000000..fb57e08 --- /dev/null +++ b/application/view_models/Inventory_admin_view_view_model.php @@ -0,0 +1,425 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_title = $model->title; + $this->_school_id = $model->school_id; + $this->_professor_id = $model->professor_id; + $this->_class_id = $model->class_id; + $this->_textbook_id = $model->textbook_id; + $this->_word_count = $model->word_count; + $this->_year = $model->year; + $this->_isbn = $model->isbn; + $this->_paypal_email = $model->paypal_email; + $this->_file = $model->file; + $this->_feature_image = $model->feature_image; + $this->_feature_image2 = $model->feature_image2; + $this->_feature_image3 = $model->feature_image3; + $this->_note_type = $model->note_type; + $this->_description = $model->description; + $this->_inventory_note = $model->inventory_note; + $this->_pin_to_top = $model->pin_to_top; + $this->_approve = $model->approve; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function note_type_mapping () + { + return $this->_entity->note_type_mapping(); + + } + + public function pin_to_top_mapping () + { + return $this->_entity->pin_to_top_mapping(); + + } + + public function approve_mapping () + { + return $this->_entity->approve_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_title () + { + return $this->_title; + } + + public function set_title ($title) + { + $this->_title = $title; + } + + public function get_school_id () + { + return $this->_school_id; + } + + public function set_school_id ($school_id) + { + $this->_school_id = $school_id; + } + + public function get_professor_id () + { + return $this->_professor_id; + } + + public function set_professor_id ($professor_id) + { + $this->_professor_id = $professor_id; + } + + public function get_class_id () + { + return $this->_class_id; + } + + public function set_class_id ($class_id) + { + $this->_class_id = $class_id; + } + + public function get_textbook_id () + { + return $this->_textbook_id; + } + + public function set_textbook_id ($textbook_id) + { + $this->_textbook_id = $textbook_id; + } + + public function get_word_count () + { + return $this->_word_count; + } + + public function set_word_count ($word_count) + { + $this->_word_count = $word_count; + } + + public function get_year () + { + return $this->_year; + } + + public function set_year ($year) + { + $this->_year = $year; + } + + public function get_isbn () + { + return $this->_isbn; + } + + public function set_isbn ($isbn) + { + $this->_isbn = $isbn; + } + + public function get_paypal_email () + { + return $this->_paypal_email; + } + + public function set_paypal_email ($paypal_email) + { + $this->_paypal_email = $paypal_email; + } + + public function get_file () + { + return $this->_file; + } + + public function set_file ($file) + { + $this->_file = $file; + } + + public function get_file_id () + { + return $this->_file_id; + } + + public function set_file_id ($file) + { + $this->_file_id = $file; + } + + public function get_feature_image () + { + return $this->_feature_image; + } + + public function set_feature_image ($feature_image) + { + $this->_feature_image = $feature_image; + } + + public function get_feature_image_id () + { + return $this->_feature_image_id; + } + + public function set_feature_image_id ($feature_image) + { + $this->_feature_image_id = $feature_image; + } + + public function get_feature_image2 () + { + return $this->_feature_image2; + } + + public function set_feature_image2 ($feature_image2) + { + $this->_feature_image2 = $feature_image2; + } + + public function get_feature_image2_id () + { + return $this->_feature_image2_id; + } + + public function set_feature_image2_id ($feature_image2) + { + $this->_feature_image2_id = $feature_image2; + } + + public function get_feature_image3 () + { + return $this->_feature_image3; + } + + public function set_feature_image3 ($feature_image3) + { + $this->_feature_image3 = $feature_image3; + } + + public function get_feature_image3_id () + { + return $this->_feature_image3_id; + } + + public function set_feature_image3_id ($feature_image3) + { + $this->_feature_image3_id = $feature_image3; + } + + public function get_note_type () + { + return $this->_note_type; + } + + public function set_note_type ($note_type) + { + $this->_note_type = $note_type; + } + + public function get_description () + { + return $this->_description; + } + + public function set_description ($description) + { + $this->_description = $description; + } + + public function get_inventory_note () + { + return $this->_inventory_note; + } + + public function set_inventory_note ($inventory_note) + { + $this->_inventory_note = $inventory_note; + } + + public function get_pin_to_top () + { + return $this->_pin_to_top; + } + + public function set_pin_to_top ($pin_to_top) + { + $this->_pin_to_top = $pin_to_top; + } + + public function get_approve () + { + return $this->_approve; + } + + public function set_approve ($approve) + { + $this->_approve = $approve; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'title' => $this->get_title(), + 'school_id' => $this->get_school_id(), + 'professor_id' => $this->get_professor_id(), + 'class_id' => $this->get_class_id(), + 'textbook_id' => $this->get_textbook_id(), + 'word_count' => $this->get_word_count(), + 'year' => $this->get_year(), + 'isbn' => $this->get_isbn(), + 'paypal_email' => $this->get_paypal_email(), + 'file' => $this->get_file(), + 'feature_image' => $this->get_feature_image(), + 'feature_image2' => $this->get_feature_image2(), + 'feature_image3' => $this->get_feature_image3(), + 'note_type' => $this->get_note_type(), + 'description' => $this->get_description(), + 'inventory_note' => $this->get_inventory_note(), + 'pin_to_top' => $this->get_pin_to_top(), + 'approve' => $this->get_approve(), + 'status' => $this->get_status(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_attribute_admin_add_view_model.php b/application/view_models/Inventory_attribute_admin_add_view_model.php new file mode 100755 index 0000000..6a68e77 --- /dev/null +++ b/application/view_models/Inventory_attribute_admin_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_attribute_admin_edit_view_model.php b/application/view_models/Inventory_attribute_admin_edit_view_model.php new file mode 100755 index 0000000..0224ebf --- /dev/null +++ b/application/view_models/Inventory_attribute_admin_edit_view_model.php @@ -0,0 +1,139 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_inventory_id = $model->inventory_id; + $this->_attribute_id = $model->attribute_id; + $this->_value = $model->value; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_inventory_id () + { + return $this->_inventory_id; + } + + public function set_inventory_id ($inventory_id) + { + $this->_inventory_id = $inventory_id; + } + + public function get_attribute_id () + { + return $this->_attribute_id; + } + + public function set_attribute_id ($attribute_id) + { + $this->_attribute_id = $attribute_id; + } + + public function get_value () + { + return $this->_value; + } + + public function set_value ($value) + { + $this->_value = $value; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_attribute_admin_list_paginate_view_model.php b/application/view_models/Inventory_attribute_admin_list_paginate_view_model.php new file mode 100755 index 0000000..03e0929 --- /dev/null +++ b/application/view_models/Inventory_attribute_admin_list_paginate_view_model.php @@ -0,0 +1,493 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_inventory_id () + { + return $this->_inventory_id; + } + + public function set_inventory_id ($inventory_id) + { + $this->_inventory_id = $inventory_id; + } + + public $_inventory_id = NULL; + + public function get_attribute_id () + { + return $this->_attribute_id; + } + + public function set_attribute_id ($attribute_id) + { + $this->_attribute_id = $attribute_id; + } + + public $_attribute_id = NULL; + + public function get_value () + { + return $this->_value; + } + + public function set_value ($value) + { + $this->_value = $value; + } + + public $_value = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['inventory_id'] = $list[$key]->inventory_id; + $clean_list_entry['attribute_id'] = $list[$key]->attribute_id; + $clean_list_entry['value'] = $list[$key]->value; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['inventory_id'] = $list[$key]->inventory_id; + $clean_list_entry['attribute_id'] = $list[$key]->attribute_id; + $clean_list_entry['value'] = $list[$key]->value; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Inventory_attribute_admin_view_view_model.php b/application/view_models/Inventory_attribute_admin_view_view_model.php new file mode 100755 index 0000000..5e8428e --- /dev/null +++ b/application/view_models/Inventory_attribute_admin_view_view_model.php @@ -0,0 +1,149 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_inventory_id = $model->inventory_id; + $this->_attribute_id = $model->attribute_id; + $this->_value = $model->value; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_inventory_id () + { + return $this->_inventory_id; + } + + public function set_inventory_id ($inventory_id) + { + $this->_inventory_id = $inventory_id; + } + + public function get_attribute_id () + { + return $this->_attribute_id; + } + + public function set_attribute_id ($attribute_id) + { + $this->_attribute_id = $attribute_id; + } + + public function get_value () + { + return $this->_value; + } + + public function set_value ($value) + { + $this->_value = $value; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'inventory_id' => $this->get_inventory_id(), + 'attribute_id' => $this->get_attribute_id(), + 'value' => $this->get_value(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_gallery_image_list_admin_add_view_model.php b/application/view_models/Inventory_gallery_image_list_admin_add_view_model.php new file mode 100755 index 0000000..e25fc6a --- /dev/null +++ b/application/view_models/Inventory_gallery_image_list_admin_add_view_model.php @@ -0,0 +1,89 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_gallery_image_list_admin_edit_view_model.php b/application/view_models/Inventory_gallery_image_list_admin_edit_view_model.php new file mode 100755 index 0000000..91bc9ae --- /dev/null +++ b/application/view_models/Inventory_gallery_image_list_admin_edit_view_model.php @@ -0,0 +1,179 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_inventory_id = $model->inventory_id; + $this->_gallery_image = $model->gallery_image; + $this->_gallery_image_id = $model->gallery_image_id; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_inventory_id () + { + return $this->_inventory_id; + } + + public function set_inventory_id ($inventory_id) + { + $this->_inventory_id = $inventory_id; + } + + public function get_gallery_image () + { + return $this->_gallery_image; + } + + public function set_gallery_image ($gallery_image) + { + $this->_gallery_image = $gallery_image; + } + + public function get_gallery_image_id () + { + return $this->_gallery_image_id; + } + + public function set_gallery_image_id ($gallery_image) + { + $this->_gallery_image_id = $gallery_image; + } + + public function get_gallery_image_id () + { + return $this->_gallery_image_id; + } + + public function set_gallery_image_id ($gallery_image_id) + { + $this->_gallery_image_id = $gallery_image_id; + } + + public function get_gallery_image_id_id () + { + return $this->_gallery_image_id_id; + } + + public function set_gallery_image_id_id ($gallery_image_id) + { + $this->_gallery_image_id_id = $gallery_image_id; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_gallery_image_list_admin_list_paginate_view_model.php b/application/view_models/Inventory_gallery_image_list_admin_list_paginate_view_model.php new file mode 100755 index 0000000..0dd6128 --- /dev/null +++ b/application/view_models/Inventory_gallery_image_list_admin_list_paginate_view_model.php @@ -0,0 +1,515 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_inventory_id () + { + return $this->_inventory_id; + } + + public function set_inventory_id ($inventory_id) + { + $this->_inventory_id = $inventory_id; + } + + public $_inventory_id = NULL; + + public function get_gallery_image () + { + return $this->_gallery_image; + } + + public function set_gallery_image ($gallery_image) + { + $this->_gallery_image = $gallery_image; + } + + public $_gallery_image = NULL; + + public function get_gallery_image_id () + { + return $this->_gallery_image_id; + } + + public function set_gallery_image_id ($gallery_image_id) + { + $this->_gallery_image_id = $gallery_image_id; + } + + public $_gallery_image_id = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['inventory_id'] = $list[$key]->inventory_id; + $clean_list_entry['gallery_image'] = $list[$key]->gallery_image; + $clean_list_entry['gallery_image_id'] = $list[$key]->gallery_image_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['inventory_id'] = $list[$key]->inventory_id; + $clean_list_entry['gallery_image'] = $list[$key]->gallery_image; + $clean_list_entry['gallery_image_id'] = $list[$key]->gallery_image_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Inventory_gallery_image_list_admin_view_view_model.php b/application/view_models/Inventory_gallery_image_list_admin_view_view_model.php new file mode 100755 index 0000000..a4e931e --- /dev/null +++ b/application/view_models/Inventory_gallery_image_list_admin_view_view_model.php @@ -0,0 +1,190 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_inventory_id = $model->inventory_id; + $this->_gallery_image = $model->gallery_image; + $this->_gallery_image_id = $model->gallery_image_id; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_inventory_id () + { + return $this->_inventory_id; + } + + public function set_inventory_id ($inventory_id) + { + $this->_inventory_id = $inventory_id; + } + + public function get_gallery_image () + { + return $this->_gallery_image; + } + + public function set_gallery_image ($gallery_image) + { + $this->_gallery_image = $gallery_image; + } + + public function get_gallery_image_id () + { + return $this->_gallery_image_id; + } + + public function set_gallery_image_id ($gallery_image) + { + $this->_gallery_image_id = $gallery_image; + } + + public function get_gallery_image_id () + { + return $this->_gallery_image_id; + } + + public function set_gallery_image_id ($gallery_image_id) + { + $this->_gallery_image_id = $gallery_image_id; + } + + public function get_gallery_image_id_id () + { + return $this->_gallery_image_id_id; + } + + public function set_gallery_image_id_id ($gallery_image_id) + { + $this->_gallery_image_id_id = $gallery_image_id; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'inventory_id' => $this->get_inventory_id(), + 'gallery_image' => $this->get_gallery_image(), + 'gallery_image_id' => $this->get_gallery_image_id(), + 'status' => $this->get_status(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_member_add_view_model.php b/application/view_models/Inventory_member_add_view_model.php new file mode 100755 index 0000000..3fad883 --- /dev/null +++ b/application/view_models/Inventory_member_add_view_model.php @@ -0,0 +1,107 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function note_type_mapping () + { + return $this->_entity->note_type_mapping(); + + } + + public function pin_to_top_mapping () + { + return $this->_entity->pin_to_top_mapping(); + + } + + public function approve_mapping () + { + return $this->_entity->approve_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Inventory_member_list_paginate_view_model.php b/application/view_models/Inventory_member_list_paginate_view_model.php new file mode 100755 index 0000000..c63f471 --- /dev/null +++ b/application/view_models/Inventory_member_list_paginate_view_model.php @@ -0,0 +1,617 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_title () + { + return $this->_title; + } + + public function set_title ($title) + { + $this->_title = $title; + } + + public $_title = NULL; + + public function get_school_id () + { + return $this->_school_id; + } + + public function set_school_id ($school_id) + { + $this->_school_id = $school_id; + } + + public $_school_id = NULL; + + public function get_professor_id () + { + return $this->_professor_id; + } + + public function set_professor_id ($professor_id) + { + $this->_professor_id = $professor_id; + } + + public $_professor_id = NULL; + + public function get_class_id () + { + return $this->_class_id; + } + + public function set_class_id ($class_id) + { + $this->_class_id = $class_id; + } + + public $_class_id = NULL; + + public function get_textbook_id () + { + return $this->_textbook_id; + } + + public function set_textbook_id ($textbook_id) + { + $this->_textbook_id = $textbook_id; + } + + public $_textbook_id = NULL; + + public function get_word_count () + { + return $this->_word_count; + } + + public function set_word_count ($word_count) + { + $this->_word_count = $word_count; + } + + public $_word_count = NULL; + + public function get_year () + { + return $this->_year; + } + + public function set_year ($year) + { + $this->_year = $year; + } + + public $_year = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function note_type_mapping () + { + return $this->_entity->note_type_mapping(); + + } + + public function pin_to_top_mapping () + { + return $this->_entity->pin_to_top_mapping(); + + } + + public function approve_mapping () + { + return $this->_entity->approve_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->note_type = $this->note_type_mapping()[$value->note_type]; + $list[$key]->pin_to_top = $this->pin_to_top_mapping()[$value->pin_to_top]; + $list[$key]->approve = $this->approve_mapping()[$value->approve]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['title'] = $list[$key]->title; + $clean_list_entry['school_id'] = $list[$key]->school_id; + $clean_list_entry['professor_id'] = $list[$key]->professor_id; + $clean_list_entry['class_id'] = $list[$key]->class_id; + $clean_list_entry['textbook_id'] = $list[$key]->textbook_id; + $clean_list_entry['word_count'] = $list[$key]->word_count; + $clean_list_entry['year'] = $list[$key]->year; + $clean_list_entry['isbn'] = $list[$key]->isbn; + $clean_list_entry['paypal_email'] = $list[$key]->paypal_email; + $clean_list_entry['file'] = $list[$key]->file; + $clean_list_entry['file_id'] = $list[$key]->file_id; + $clean_list_entry['feature_image'] = $list[$key]->feature_image; + $clean_list_entry['feature_image_id'] = $list[$key]->feature_image_id; + $clean_list_entry['note_type'] = $list[$key]->note_type; + $clean_list_entry['description'] = $list[$key]->description; + $clean_list_entry['inventory_note'] = $list[$key]->inventory_note; + $clean_list_entry['pin_to_top'] = $list[$key]->pin_to_top; + $clean_list_entry['approve'] = $list[$key]->approve; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->note_type = $this->note_type_mapping()[$value->note_type]; + $list[$key]->pin_to_top = $this->pin_to_top_mapping()[$value->pin_to_top]; + $list[$key]->approve = $this->approve_mapping()[$value->approve]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['title'] = $list[$key]->title; + $clean_list_entry['school_id'] = $list[$key]->school_id; + $clean_list_entry['professor_id'] = $list[$key]->professor_id; + $clean_list_entry['class_id'] = $list[$key]->class_id; + $clean_list_entry['textbook_id'] = $list[$key]->textbook_id; + $clean_list_entry['word_count'] = $list[$key]->word_count; + $clean_list_entry['year'] = $list[$key]->year; + $clean_list_entry['isbn'] = $list[$key]->isbn; + $clean_list_entry['paypal_email'] = $list[$key]->paypal_email; + $clean_list_entry['file'] = $list[$key]->file; + $clean_list_entry['file_id'] = $list[$key]->file_id; + $clean_list_entry['feature_image'] = $list[$key]->feature_image; + $clean_list_entry['feature_image_id'] = $list[$key]->feature_image_id; + $clean_list_entry['note_type'] = $list[$key]->note_type; + $clean_list_entry['description'] = $list[$key]->description; + $clean_list_entry['inventory_note'] = $list[$key]->inventory_note; + $clean_list_entry['pin_to_top'] = $list[$key]->pin_to_top; + $clean_list_entry['approve'] = $list[$key]->approve; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Inventory_member_view_view_model.php b/application/view_models/Inventory_member_view_view_model.php new file mode 100755 index 0000000..b5a3cb8 --- /dev/null +++ b/application/view_models/Inventory_member_view_view_model.php @@ -0,0 +1,377 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_title = $model->title; + $this->_school_id = $model->school_id; + $this->_professor_id = $model->professor_id; + $this->_class_id = $model->class_id; + $this->_textbook_id = $model->textbook_id; + $this->_word_count = $model->word_count; + $this->_year = $model->year; + $this->_isbn = $model->isbn; + $this->_paypal_email = $model->paypal_email; + $this->_file = $model->file; + $this->_feature_image = $model->feature_image; + $this->_note_type = $model->note_type; + $this->_description = $model->description; + $this->_inventory_note = $model->inventory_note; + $this->_pin_to_top = $model->pin_to_top; + $this->_approve = $model->approve; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function note_type_mapping () + { + return $this->_entity->note_type_mapping(); + + } + + public function pin_to_top_mapping () + { + return $this->_entity->pin_to_top_mapping(); + + } + + public function approve_mapping () + { + return $this->_entity->approve_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_title () + { + return $this->_title; + } + + public function set_title ($title) + { + $this->_title = $title; + } + + public function get_school_id () + { + return $this->_school_id; + } + + public function set_school_id ($school_id) + { + $this->_school_id = $school_id; + } + + public function get_professor_id () + { + return $this->_professor_id; + } + + public function set_professor_id ($professor_id) + { + $this->_professor_id = $professor_id; + } + + public function get_class_id () + { + return $this->_class_id; + } + + public function set_class_id ($class_id) + { + $this->_class_id = $class_id; + } + + public function get_textbook_id () + { + return $this->_textbook_id; + } + + public function set_textbook_id ($textbook_id) + { + $this->_textbook_id = $textbook_id; + } + + public function get_word_count () + { + return $this->_word_count; + } + + public function set_word_count ($word_count) + { + $this->_word_count = $word_count; + } + + public function get_year () + { + return $this->_year; + } + + public function set_year ($year) + { + $this->_year = $year; + } + + public function get_isbn () + { + return $this->_isbn; + } + + public function set_isbn ($isbn) + { + $this->_isbn = $isbn; + } + + public function get_paypal_email () + { + return $this->_paypal_email; + } + + public function set_paypal_email ($paypal_email) + { + $this->_paypal_email = $paypal_email; + } + + public function get_file () + { + return $this->_file; + } + + public function set_file ($file) + { + $this->_file = $file; + } + + public function get_file_id () + { + return $this->_file_id; + } + + public function set_file_id ($file) + { + $this->_file_id = $file; + } + + public function get_feature_image () + { + return $this->_feature_image; + } + + public function set_feature_image ($feature_image) + { + $this->_feature_image = $feature_image; + } + + public function get_feature_image_id () + { + return $this->_feature_image_id; + } + + public function set_feature_image_id ($feature_image) + { + $this->_feature_image_id = $feature_image; + } + + public function get_note_type () + { + return $this->_note_type; + } + + public function set_note_type ($note_type) + { + $this->_note_type = $note_type; + } + + public function get_description () + { + return $this->_description; + } + + public function set_description ($description) + { + $this->_description = $description; + } + + public function get_inventory_note () + { + return $this->_inventory_note; + } + + public function set_inventory_note ($inventory_note) + { + $this->_inventory_note = $inventory_note; + } + + public function get_pin_to_top () + { + return $this->_pin_to_top; + } + + public function set_pin_to_top ($pin_to_top) + { + $this->_pin_to_top = $pin_to_top; + } + + public function get_approve () + { + return $this->_approve; + } + + public function set_approve ($approve) + { + $this->_approve = $approve; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'title' => $this->get_title(), + 'school_id' => $this->get_school_id(), + 'professor_id' => $this->get_professor_id(), + 'class_id' => $this->get_class_id(), + 'textbook_id' => $this->get_textbook_id(), + 'word_count' => $this->get_word_count(), + 'year' => $this->get_year(), + 'isbn' => $this->get_isbn(), + 'paypal_email' => $this->get_paypal_email(), + 'file' => $this->get_file(), + 'feature_image' => $this->get_feature_image(), + 'note_type' => $this->get_note_type(), + 'description' => $this->get_description(), + 'inventory_note' => $this->get_inventory_note(), + 'pin_to_top' => $this->get_pin_to_top(), + 'approve' => $this->get_approve(), + 'status' => $this->get_status(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Marketing_admin_add_view_model.php b/application/view_models/Marketing_admin_add_view_model.php new file mode 100755 index 0000000..01a1495 --- /dev/null +++ b/application/view_models/Marketing_admin_add_view_model.php @@ -0,0 +1,184 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_header_templates () + { + $mydir = __DIR__ . '/../views/Layout'; + $dir_name = 'Layout'; + $myfiles = array_diff(scandir($mydir), ['.', '..']); + $header_file = []; + + if(!empty($myfiles) && is_array($myfiles)) + { + $header_file[''] = 'None'; + $word = $word ? $word : 'Header'; + + foreach ($myfiles as $value) + { + if (strpos($value,$word) !== FALSE) + { + $header_file[$dir_name .'/' . $value] = $value; + } + } + } + + return $header_file; + } + + public function get_content_templates () + { + $mydir = __DIR__ . '/../views'; + + $myfiles = array_diff(scandir($mydir), ['.', '..']); + + $header_file = []; + $main_dir = []; + + if(!empty($myfiles) && is_array($myfiles)) + { + $word = '.php'; + $exception_dir_1 = 'Layout'; + $exception_dir_2 = 'errors'; + $main_dir[''] = [ '' => 'None']; + + foreach($myfiles as $value) + { + switch ($value) + { + case $exception_dir_1: + break; + + case $exception_dir_2 : + break; + + default: + + $my_dynamicdir = __DIR__ . '/../views/' . $value; + + if(is_dir($my_dynamicdir)) + { + $files = []; + $mydynamicfiles = array_diff(scandir($my_dynamicdir), ['.', '..']); + + if(!empty($mydynamicfiles) && is_array($mydynamicfiles)) + { + foreach($mydynamicfiles as $name) + { + if(strpos($name,$word)) + { + $files[$value . "/" . $name] = $name; + } + } + } + + $main_dir[$value] = $files; + } + break; + } + } + } + return $main_dir; + } + + public function get_footer_templates () + { + return $this->get_header_templates('Footer'); + } + + /** + * Custom functions below + * for portal views + * function to return the slug + */ + public function marketing_slug_url() + { + $slug_url = base_url() . 'a/'; + return $slug_url; + } + +} \ No newline at end of file diff --git a/application/view_models/Marketing_admin_edit_view_model.php b/application/view_models/Marketing_admin_edit_view_model.php new file mode 100755 index 0000000..9bd6933 --- /dev/null +++ b/application/view_models/Marketing_admin_edit_view_model.php @@ -0,0 +1,333 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_title = $model->title; + $this->_seo_title = $model->seo_title; + $this->_seo_description = $model->seo_description; + $this->_content = $model->content; + $this->_slug = $model->slug; + $this->_password_protect = $model->password_protect; + $this->_header_template_path = $model->header_template_path; + $this->_content_template_path = $model->content_template_path; + $this->_footer_template_path = $model->footer_template_path; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_title () + { + return $this->_title; + } + + public function set_title ($title) + { + $this->_title = $title; + } + + public function get_seo_title () + { + return $this->_seo_title; + } + + public function set_seo_title ($seo_title) + { + $this->_seo_title = $seo_title; + } + + public function get_seo_description () + { + return $this->_seo_description; + } + + public function set_seo_description ($seo_description) + { + $this->_seo_description = $seo_description; + } + + public function get_content () + { + return $this->_content; + } + + public function set_content ($content) + { + $this->_content = $content; + } + + public function get_slug () + { + if($this->_slug) + { + $this->_slug = explode('a/',$this->_slug); + if(count($this->_slug) == 2) + { + $this->_slug = $this->_slug[1]; + } + } + + return $this->_slug; + } + + public function set_slug ($slug) + { + + $this->_slug = $slug; + } + + public function get_password_protect () + { + return $this->_password_protect; + } + + public function set_password_protect ($password_protect) + { + $this->_password_protect = $password_protect; + } + + public function get_header_template_path () + { + return $this->_header_template_path; + } + + public function set_header_template_path ($header_template_path) + { + $this->_header_template_path = $header_template_path; + } + + public function get_content_template_path () + { + return $this->_content_template_path; + } + + public function set_content_template_path ($content_template_path) + { + $this->_content_template_path = $content_template_path; + } + + public function get_footer_template_path () + { + return $this->_footer_template_path; + } + + public function set_footer_template_path ($footer_template_path) + { + $this->_footer_template_path = $footer_template_path; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + /** + * Custom functions below + * for portal views + * function to return the slug + */ + public function marketing_slug_url() + { + $slug_url = base_url() . 'a/'; + return $slug_url; + } + + public function get_header_templates () + { + $mydir = __DIR__ . '/../views/Layout'; + $dir_name = 'Layout'; + $myfiles = array_diff(scandir($mydir), ['.', '..']); + $header_file = []; + + if(!empty($myfiles) && is_array($myfiles)) + { + $header_file[''] = 'None'; + $word = $word ? $word : 'Header'; + + foreach ($myfiles as $value) + { + if (strpos($value,$word) !== FALSE) + { + $header_file[$dir_name .'/' . $value] = $value; + } + } + } + + return $header_file; + } + + public function get_content_templates () + { + $mydir = __DIR__ . '/../views'; + + $myfiles = array_diff(scandir($mydir), ['.', '..']); + + $header_file = []; + $main_dir = []; + + if(!empty($myfiles) && is_array($myfiles)) + { + $word = '.php'; + $exception_dir_1 = 'Layout'; + $exception_dir_2 = 'errors'; + $main_dir[''] = [ '' => 'None']; + + foreach($myfiles as $value) + { + switch ($value) + { + case $exception_dir_1: + break; + + case $exception_dir_2 : + break; + + default: + + $my_dynamicdir = __DIR__ . '/../views/' . $value; + + if(is_dir($my_dynamicdir)) + { + $files = []; + $mydynamicfiles = array_diff(scandir($my_dynamicdir), ['.', '..']); + + if(!empty($mydynamicfiles) && is_array($mydynamicfiles)) + { + foreach($mydynamicfiles as $name) + { + if(strpos($name,$word)) + { + $files[$value . "/" . $name] = $name; + } + } + } + + $main_dir[$value] = $files; + } + break; + } + } + } + return $main_dir; + } + + public function get_footer_templates () + { + return $this->get_header_templates('Footer'); + } +} \ No newline at end of file diff --git a/application/view_models/Marketing_admin_list_paginate_view_model.php b/application/view_models/Marketing_admin_list_paginate_view_model.php new file mode 100755 index 0000000..967ac7c --- /dev/null +++ b/application/view_models/Marketing_admin_list_paginate_view_model.php @@ -0,0 +1,519 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_publish_date () + { + return $this->_publish_date; + } + + public function set_publish_date ($publish_date) + { + $this->_publish_date = $publish_date; + } + + public $_publish_date = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_title () + { + return $this->_title; + } + + public function set_title ($title) + { + $this->_title = $title; + } + + public $_title = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['title'] = $list[$key]->title; + $clean_list_entry['seo_title'] = $list[$key]->seo_title; + $clean_list_entry['seo_description'] = $list[$key]->seo_description; + $clean_list_entry['slug'] = $list[$key]->slug; + $clean_list_entry['publish_date'] = $list[$key]->publish_date; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['title'] = $list[$key]->title; + $clean_list_entry['seo_title'] = $list[$key]->seo_title; + $clean_list_entry['seo_description'] = $list[$key]->seo_description; + $clean_list_entry['slug'] = $list[$key]->slug; + $clean_list_entry['publish_date'] = $list[$key]->publish_date; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Marketing_admin_view_view_model.php b/application/view_models/Marketing_admin_view_view_model.php new file mode 100755 index 0000000..32afa7a --- /dev/null +++ b/application/view_models/Marketing_admin_view_view_model.php @@ -0,0 +1,271 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_title = $model->title; + $this->_seo_title = $model->seo_title; + $this->_seo_description = $model->seo_description; + $this->_content = $model->content; + $this->_slug = $model->slug; + $this->_password_protect = $model->password_protect; + $this->_header_template_path = $model->header_template_path; + $this->_content_template_path = $model->content_template_path; + $this->_footer_template_path = $model->footer_template_path; + $this->_status = $model->status; + $this->_publish_date = $model->publish_date; + $this->_user_id = $model->user_id; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_title () + { + return $this->_title; + } + + public function set_title ($title) + { + $this->_title = $title; + } + + public function get_seo_title () + { + return $this->_seo_title; + } + + public function set_seo_title ($seo_title) + { + $this->_seo_title = $seo_title; + } + + public function get_seo_description () + { + return $this->_seo_description; + } + + public function set_seo_description ($seo_description) + { + $this->_seo_description = $seo_description; + } + + public function get_content () + { + return $this->_content; + } + + public function set_content ($content) + { + $this->_content = $content; + } + + public function get_slug () + { + return $this->_slug; + } + + public function set_slug ($slug) + { + $this->_slug = $slug; + } + + public function get_password_protect () + { + return $this->_password_protect; + } + + public function set_password_protect ($password_protect) + { + $this->_password_protect = $password_protect; + } + + public function get_header_template_path () + { + return $this->_header_template_path; + } + + public function set_header_template_path ($header_template_path) + { + $this->_header_template_path = $header_template_path; + } + + public function get_content_template_path () + { + return $this->_content_template_path; + } + + public function set_content_template_path ($content_template_path) + { + $this->_content_template_path = $content_template_path; + } + + public function get_footer_template_path () + { + return $this->_footer_template_path; + } + + public function set_footer_template_path ($footer_template_path) + { + $this->_footer_template_path = $footer_template_path; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_publish_date () + { + return $this->_publish_date; + } + + public function set_publish_date ($publish_date) + { + $this->_publish_date = $publish_date; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function to_json () + { + return [ + 'title' => $this->get_title(), + 'seo_title' => $this->get_seo_title(), + 'seo_description' => $this->get_seo_description(), + 'content' => $this->get_content(), + 'slug' => $this->get_slug(), + 'password_protect' => $this->get_password_protect(), + 'header_template_path' => $this->get_header_template_path(), + 'content_template_path' => $this->get_content_template_path(), + 'footer_template_path' => $this->get_footer_template_path(), + 'status' => $this->get_status(), + 'publish_date' => $this->get_publish_date(), + 'user_id' => $this->get_user_id(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Member_profile_credential_view_model.php b/application/view_models/Member_profile_credential_view_model.php new file mode 100755 index 0000000..e950444 --- /dev/null +++ b/application/view_models/Member_profile_credential_view_model.php @@ -0,0 +1,62 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_email = $model->email; + } + + public function get_email () + { + return $this->_email; + } + + public function set_email ($email) + { + $this->_email = $email; + } +} \ No newline at end of file diff --git a/application/view_models/Member_profile_view_model.php b/application/view_models/Member_profile_view_model.php new file mode 100755 index 0000000..3609c67 --- /dev/null +++ b/application/view_models/Member_profile_view_model.php @@ -0,0 +1,87 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_first_name = $model->first_name; + $this->_last_name = $model->last_name; + } + + public function get_first_name () + { + return $this->_first_name; + } + + public function set_first_name ($first_name) + { + $this->_first_name = $first_name; + } + + public function get_email () + { + return $this->_email; + } + + public function set_email ($email) + { + $this->_email = $email; + } + + public function get_last_name () + { + return $this->_last_name; + } + + public function set_last_name ($last_name) + { + $this->_last_name = $last_name; + } +} \ No newline at end of file diff --git a/application/view_models/Order_admin_list_paginate_view_model.php b/application/view_models/Order_admin_list_paginate_view_model.php new file mode 100755 index 0000000..11738be --- /dev/null +++ b/application/view_models/Order_admin_list_paginate_view_model.php @@ -0,0 +1,603 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_purchase_user_id () + { + return $this->_purchase_user_id; + } + + public function set_purchase_user_id ($purchase_user_id) + { + $this->_purchase_user_id = $purchase_user_id; + } + + public $_purchase_user_id = NULL; + + public function get_sale_user_id () + { + return $this->_sale_user_id; + } + + public function set_sale_user_id ($sale_user_id) + { + $this->_sale_user_id = $sale_user_id; + } + + public $_sale_user_id = NULL; + + public function get_inventory_id () + { + return $this->_inventory_id; + } + + public function set_inventory_id ($inventory_id) + { + $this->_inventory_id = $inventory_id; + } + + public $_inventory_id = NULL; + + public function get_order_date () + { + return $this->_order_date; + } + + public function set_order_date ($order_date) + { + $this->_order_date = $order_date; + } + + public $_order_date = NULL; + + public function get_order_time () + { + return $this->_order_time; + } + + public function set_order_time ($order_time) + { + $this->_order_time = $order_time; + } + + public $_order_time = NULL; + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public $_subtotal = NULL; + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public $_tax = NULL; + + public function get_discount () + { + return $this->_discount; + } + + public function set_discount ($discount) + { + $this->_discount = $discount; + } + + public $_discount = NULL; + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public $_total = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['purchase_user_id'] = $list[$key]->purchase_user_id; + $clean_list_entry['sale_user_id'] = $list[$key]->sale_user_id; + $clean_list_entry['inventory_id'] = $list[$key]->inventory_id; + $clean_list_entry['order_date'] = $list[$key]->order_date; + $clean_list_entry['order_time'] = $list[$key]->order_time; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['tax'] = $list[$key]->tax; + $clean_list_entry['discount'] = $list[$key]->discount; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['stripe_intent'] = $list[$key]->stripe_intent; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['purchase_user_id'] = $list[$key]->purchase_user_id; + $clean_list_entry['sale_user_id'] = $list[$key]->sale_user_id; + $clean_list_entry['inventory_id'] = $list[$key]->inventory_id; + $clean_list_entry['order_date'] = $list[$key]->order_date; + $clean_list_entry['order_time'] = $list[$key]->order_time; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['tax'] = $list[$key]->tax; + $clean_list_entry['discount'] = $list[$key]->discount; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['stripe_intent'] = $list[$key]->stripe_intent; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Order_admin_view_view_model.php b/application/view_models/Order_admin_view_view_model.php new file mode 100755 index 0000000..bbb272d --- /dev/null +++ b/application/view_models/Order_admin_view_view_model.php @@ -0,0 +1,272 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_purchase_user_id = $model->purchase_user_id; + $this->_sale_user_id = $model->sale_user_id; + $this->_inventory_id = $model->inventory_id; + $this->_order_date = $model->order_date; + $this->_order_time = $model->order_time; + $this->_subtotal = $model->subtotal; + $this->_tax = $model->tax; + $this->_discount = $model->discount; + $this->_total = $model->total; + $this->_stripe_charge_id = $model->stripe_charge_id; + $this->_stripe_intent = $model->stripe_intent; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_purchase_user_id () + { + return $this->_purchase_user_id; + } + + public function set_purchase_user_id ($purchase_user_id) + { + $this->_purchase_user_id = $purchase_user_id; + } + + public function get_sale_user_id () + { + return $this->_sale_user_id; + } + + public function set_sale_user_id ($sale_user_id) + { + $this->_sale_user_id = $sale_user_id; + } + + public function get_inventory_id () + { + return $this->_inventory_id; + } + + public function set_inventory_id ($inventory_id) + { + $this->_inventory_id = $inventory_id; + } + + public function get_order_date () + { + return $this->_order_date; + } + + public function set_order_date ($order_date) + { + $this->_order_date = $order_date; + } + + public function get_order_time () + { + return $this->_order_time; + } + + public function set_order_time ($order_time) + { + $this->_order_time = $order_time; + } + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public function get_discount () + { + return $this->_discount; + } + + public function set_discount ($discount) + { + $this->_discount = $discount; + } + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public function get_stripe_intent () + { + return $this->_stripe_intent; + } + + public function set_stripe_intent ($stripe_intent) + { + $this->_stripe_intent = $stripe_intent; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'purchase_user_id' => $this->get_purchase_user_id(), + 'sale_user_id' => $this->get_sale_user_id(), + 'inventory_id' => $this->get_inventory_id(), + 'order_date' => $this->get_order_date(), + 'order_time' => $this->get_order_time(), + 'subtotal' => $this->get_subtotal(), + 'tax' => $this->get_tax(), + 'discount' => $this->get_discount(), + 'total' => $this->get_total(), + 'stripe_charge_id' => $this->get_stripe_charge_id(), + 'stripe_intent' => $this->get_stripe_intent(), + 'status' => $this->get_status(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Payout_admin_list_paginate_view_model.php b/application/view_models/Payout_admin_list_paginate_view_model.php new file mode 100755 index 0000000..6a0f6c9 --- /dev/null +++ b/application/view_models/Payout_admin_list_paginate_view_model.php @@ -0,0 +1,533 @@ +','Id','Order Id','User','Paypal Email','Amount','Status','Action']; + protected $_field_column = ['','id','order_id','user_id','','amount','status','']; + protected $_list = []; + protected $_links = ''; + protected $_sort_base_url = ''; + protected $_order_by = ''; + protected $_sort = ''; + protected $_entity; + + public function __construct($entity, $library, $base_url) + { + $this->_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public $_order_id = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_amount () + { + return $this->_amount; + } + + public function set_amount ($amount) + { + $this->_amount = $amount; + } + + public $_amount = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + public function get_paypal_email () + { + return $this->_paypal_email; + } + + public function set_paypal_email ($paypal_email) + { + $this->_paypal_email = $paypal_email; + } + + + public $_paypal_email = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['paypal_email'] = $value->paypal_email; + $clean_list_entry['amount'] = $list[$key]->amount; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + + foreach ($list as $key => $value) + { + + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['paypal_email'] = $value->paypal_email; + $clean_list_entry['amount'] = $list[$key]->amount; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields) || in_array($key,['paypal_email'])) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Professor_admin_add_view_model.php b/application/view_models/Professor_admin_add_view_model.php new file mode 100755 index 0000000..1837211 --- /dev/null +++ b/application/view_models/Professor_admin_add_view_model.php @@ -0,0 +1,89 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Professor_admin_edit_view_model.php b/application/view_models/Professor_admin_edit_view_model.php new file mode 100755 index 0000000..e0ff92e --- /dev/null +++ b/application/view_models/Professor_admin_edit_view_model.php @@ -0,0 +1,133 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_name = $model->name; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Professor_admin_list_paginate_view_model.php b/application/view_models/Professor_admin_list_paginate_view_model.php new file mode 100755 index 0000000..57bcaca --- /dev/null +++ b/application/view_models/Professor_admin_list_paginate_view_model.php @@ -0,0 +1,487 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public $_name = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Purchases_member_list_paginate_view_model.php b/application/view_models/Purchases_member_list_paginate_view_model.php new file mode 100755 index 0000000..aa8498a --- /dev/null +++ b/application/view_models/Purchases_member_list_paginate_view_model.php @@ -0,0 +1,569 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows() + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout() + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page() + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page() + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links() + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by() + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column() + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort() + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url() + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page() + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file($file) + { + $images = ['.jpg', '.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach ($needle as $query) + { + if (strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list() + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links() + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading() + { + return $this->_heading; + } + + public function set_column($column) + { + $this->_column = $column; + } + + public function get_column() + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = ['second', 'minute', 'hour', 'day', 'month', 'year']; + $length = ['60', '60', '24', '30', '12', '10']; + + $currentTime = time(); + if ($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for ($i = 0; $diff >= $length[$i] && $i < count($length) - 1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping() + { + $results = []; + for ($i = 0; $i < 24; $i++) + { + for ($j = 0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = [ + 'order_by', + 'direction' + ]; + $query_list = []; + foreach ($get_parameter as $key => $value) + { + if (!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + public function get_id() + { + return $this->_id; + } + + public function set_id($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + // custom start + public function get_school_id() + { + return $this->_school_id; + } + + public function set_school_id($school_id) + { + $this->_school_id = $school_id; + } + + public $_school_id = NULL; + + + public function get_professor_id() + { + return $this->_professor_id; + } + + public function set_professor_id($professor_id) + { + $this->_professor_id = $professor_id; + } + + public $_professor_id = NULL; + // custom end + + public function get_purchase_user_id() + { + return $this->_purchase_user_id; + } + + public function set_purchase_user_id($purchase_user_id) + { + $this->_purchase_user_id = $purchase_user_id; + } + + public $_purchase_user_id = NULL; + + public function get_sale_user_id() + { + return $this->_sale_user_id; + } + + public function set_sale_user_id($sale_user_id) + { + $this->_sale_user_id = $sale_user_id; + } + + public $_sale_user_id = NULL; + + public function get_inventory_id() + { + return $this->_inventory_id; + } + + public function set_inventory_id($inventory_id) + { + $this->_inventory_id = $inventory_id; + } + + public $_inventory_id = NULL; + + public function get_order_date() + { + return $this->_order_date; + } + + public function set_order_date($order_date) + { + $this->_order_date = $order_date; + } + + public $_order_date = NULL; + + public function get_status() + { + return $this->_status; + } + + public function set_status($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function status_mapping() + { + return $this->_entity->status_mapping(); + + } + + public function to_json() + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['purchase_user_id'] = $list[$key]->purchase_user_id; + $clean_list_entry['sale_user_id'] = $list[$key]->sale_user_id; + $clean_list_entry['inventory_id'] = $list[$key]->inventory_id; + $clean_list_entry['order_date'] = $list[$key]->order_date; + $clean_list_entry['order_time'] = $list[$key]->order_time; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['tax'] = $list[$key]->tax; + $clean_list_entry['discount'] = $list[$key]->discount; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['stripe_intent'] = $list[$key]->stripe_intent; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv() + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['purchase_user_id'] = $list[$key]->purchase_user_id; + $clean_list_entry['sale_user_id'] = $list[$key]->sale_user_id; + $clean_list_entry['inventory_id'] = $list[$key]->inventory_id; + $clean_list_entry['order_date'] = $list[$key]->order_date; + $clean_list_entry['order_time'] = $list[$key]->order_time; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['tax'] = $list[$key]->tax; + $clean_list_entry['discount'] = $list[$key]->discount; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['stripe_intent'] = $list[$key]->stripe_intent; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns, ['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach ($clean_list as $row) + { + $row_csv = []; + foreach ($row as $key => $column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; + } + +} diff --git a/application/view_models/Purchases_member_view_view_model.php b/application/view_models/Purchases_member_view_view_model.php new file mode 100755 index 0000000..50ec60d --- /dev/null +++ b/application/view_models/Purchases_member_view_view_model.php @@ -0,0 +1,272 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_purchase_user_id = $model->purchase_user_id; + $this->_sale_user_id = $model->sale_user_id; + $this->_inventory_id = $model->inventory_id; + $this->_order_date = $model->order_date; + $this->_order_time = $model->order_time; + $this->_subtotal = $model->subtotal; + $this->_tax = $model->tax; + $this->_discount = $model->discount; + $this->_total = $model->total; + $this->_stripe_charge_id = $model->stripe_charge_id; + $this->_stripe_intent = $model->stripe_intent; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_purchase_user_id () + { + return $this->_purchase_user_id; + } + + public function set_purchase_user_id ($purchase_user_id) + { + $this->_purchase_user_id = $purchase_user_id; + } + + public function get_sale_user_id () + { + return $this->_sale_user_id; + } + + public function set_sale_user_id ($sale_user_id) + { + $this->_sale_user_id = $sale_user_id; + } + + public function get_inventory_id () + { + return $this->_inventory_id; + } + + public function set_inventory_id ($inventory_id) + { + $this->_inventory_id = $inventory_id; + } + + public function get_order_date () + { + return $this->_order_date; + } + + public function set_order_date ($order_date) + { + $this->_order_date = $order_date; + } + + public function get_order_time () + { + return $this->_order_time; + } + + public function set_order_time ($order_time) + { + $this->_order_time = $order_time; + } + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public function get_discount () + { + return $this->_discount; + } + + public function set_discount ($discount) + { + $this->_discount = $discount; + } + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public function get_stripe_intent () + { + return $this->_stripe_intent; + } + + public function set_stripe_intent ($stripe_intent) + { + $this->_stripe_intent = $stripe_intent; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'purchase_user_id' => $this->get_purchase_user_id(), + 'sale_user_id' => $this->get_sale_user_id(), + 'inventory_id' => $this->get_inventory_id(), + 'order_date' => $this->get_order_date(), + 'order_time' => $this->get_order_time(), + 'subtotal' => $this->get_subtotal(), + 'tax' => $this->get_tax(), + 'discount' => $this->get_discount(), + 'total' => $this->get_total(), + 'stripe_charge_id' => $this->get_stripe_charge_id(), + 'stripe_intent' => $this->get_stripe_intent(), + 'status' => $this->get_status(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Refund_admin_add_view_model.php b/application/view_models/Refund_admin_add_view_model.php new file mode 100755 index 0000000..128e90f --- /dev/null +++ b/application/view_models/Refund_admin_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Refund_admin_edit_view_model.php b/application/view_models/Refund_admin_edit_view_model.php new file mode 100755 index 0000000..f8141b9 --- /dev/null +++ b/application/view_models/Refund_admin_edit_view_model.php @@ -0,0 +1,211 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_order_id = $model->order_id; + $this->_user_id = $model->user_id; + $this->_amount = $model->amount; + $this->_reason = $model->reason; + $this->_explanation = $model->explanation; + $this->_receipt_url = $model->receipt_url; + $this->_stripe_charge_id = $model->stripe_charge_id; + $this->_stripe_invoice_id = $model->stripe_invoice_id; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_amount () + { + return $this->_amount; + } + + public function set_amount ($amount) + { + $this->_amount = $amount; + } + + public function get_reason () + { + return $this->_reason; + } + + public function set_reason ($reason) + { + $this->_reason = $reason; + } + + public function get_explanation () + { + return $this->_explanation; + } + + public function set_explanation ($explanation) + { + $this->_explanation = $explanation; + } + + public function get_receipt_url () + { + return $this->_receipt_url; + } + + public function set_receipt_url ($receipt_url) + { + $this->_receipt_url = $receipt_url; + } + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public function get_stripe_invoice_id () + { + return $this->_stripe_invoice_id; + } + + public function set_stripe_invoice_id ($stripe_invoice_id) + { + $this->_stripe_invoice_id = $stripe_invoice_id; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Refund_admin_list_paginate_view_model.php b/application/view_models/Refund_admin_list_paginate_view_model.php new file mode 100755 index 0000000..3b866b9 --- /dev/null +++ b/application/view_models/Refund_admin_list_paginate_view_model.php @@ -0,0 +1,553 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public $_order_id = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_amount () + { + return $this->_amount; + } + + public function set_amount ($amount) + { + $this->_amount = $amount; + } + + public $_amount = NULL; + + public function get_reason () + { + return $this->_reason; + } + + public function set_reason ($reason) + { + $this->_reason = $reason; + } + + public $_reason = NULL; + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public $_stripe_charge_id = NULL; + + public function get_stripe_invoice_id () + { + return $this->_stripe_invoice_id; + } + + public function set_stripe_invoice_id ($stripe_invoice_id) + { + $this->_stripe_invoice_id = $stripe_invoice_id; + } + + public $_stripe_invoice_id = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['amount'] = $list[$key]->amount; + $clean_list_entry['reason'] = $list[$key]->reason; + $clean_list_entry['explanation'] = $list[$key]->explanation; + $clean_list_entry['receipt_url'] = $list[$key]->receipt_url; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['stripe_invoice_id'] = $list[$key]->stripe_invoice_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['amount'] = $list[$key]->amount; + $clean_list_entry['reason'] = $list[$key]->reason; + $clean_list_entry['explanation'] = $list[$key]->explanation; + $clean_list_entry['receipt_url'] = $list[$key]->receipt_url; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['stripe_invoice_id'] = $list[$key]->stripe_invoice_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Review_admin_list_paginate_view_model.php b/application/view_models/Review_admin_list_paginate_view_model.php new file mode 100755 index 0000000..40e124d --- /dev/null +++ b/application/view_models/Review_admin_list_paginate_view_model.php @@ -0,0 +1,529 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public $_order_id = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_comment () + { + return $this->_comment; + } + + public function set_comment ($comment) + { + $this->_comment = $comment; + } + + public $_comment = NULL; + + public function get_rating () + { + return $this->_rating; + } + + public function set_rating ($rating) + { + $this->_rating = $rating; + } + + public $_rating = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function rating_mapping () + { + return $this->_entity->rating_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->rating = $this->rating_mapping()[$value->rating]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['comment'] = $list[$key]->comment; + $clean_list_entry['rating'] = $list[$key]->rating; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->rating = $this->rating_mapping()[$value->rating]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['comment'] = $list[$key]->comment; + $clean_list_entry['rating'] = $list[$key]->rating; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Sales_member_list_paginate_view_model.php b/application/view_models/Sales_member_list_paginate_view_model.php new file mode 100755 index 0000000..88c7583 --- /dev/null +++ b/application/view_models/Sales_member_list_paginate_view_model.php @@ -0,0 +1,529 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public $_order_id = NULL; + + public function get_amount () + { + return $this->_amount; + } + + public function set_amount ($amount) + { + $this->_amount = $amount; + } + + public $_amount = NULL; + + public function get_created_at () + { + return $this->_created_at; + } + + public function set_created_at ($created_at) + { + $this->_created_at = $created_at; + } + + public $_created_at = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['amount'] = $list[$key]->amount; + $clean_list_entry['created_at'] = $list[$key]->created_at; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['amount'] = $list[$key]->amount; + $clean_list_entry['created_at'] = $list[$key]->created_at; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/School_admin_add_view_model.php b/application/view_models/School_admin_add_view_model.php new file mode 100755 index 0000000..5d8f64f --- /dev/null +++ b/application/view_models/School_admin_add_view_model.php @@ -0,0 +1,89 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/School_admin_edit_view_model.php b/application/view_models/School_admin_edit_view_model.php new file mode 100755 index 0000000..752c178 --- /dev/null +++ b/application/view_models/School_admin_edit_view_model.php @@ -0,0 +1,133 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_name = $model->name; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/School_admin_list_paginate_view_model.php b/application/view_models/School_admin_list_paginate_view_model.php new file mode 100755 index 0000000..928f549 --- /dev/null +++ b/application/view_models/School_admin_list_paginate_view_model.php @@ -0,0 +1,487 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public $_name = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping1(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Setting_admin_edit_view_model.php b/application/view_models/Setting_admin_edit_view_model.php new file mode 100755 index 0000000..0c935e6 --- /dev/null +++ b/application/view_models/Setting_admin_edit_view_model.php @@ -0,0 +1,127 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_value = $model->value; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function type_mapping () + { + return $this->_entity->type_mapping(); + + } + + public function maintenance_mapping () + { + return $this->_entity->maintenance_mapping(); + + } + + public function get_value () + { + return $this->_value; + } + + public function set_value ($value) + { + $this->_value = $value; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Setting_admin_list_paginate_view_model.php b/application/view_models/Setting_admin_list_paginate_view_model.php new file mode 100755 index 0000000..a621dbb --- /dev/null +++ b/application/view_models/Setting_admin_list_paginate_view_model.php @@ -0,0 +1,489 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_key () + { + return $this->_key; + } + + public function set_key ($key) + { + $this->_key = $key; + } + + public $_key = NULL; + + public function get_value () + { + return $this->_value; + } + + public function set_value ($value) + { + $this->_value = $value; + } + + public $_value = NULL; + + public function type_mapping () + { + return $this->_entity->type_mapping(); + + } + + public function maintenance_mapping () + { + return $this->_entity->maintenance_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->type = $this->type_mapping()[$value->type]; + $list[$key]->maintenance = $this->maintenance_mapping()[$value->maintenance]; + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->type = $this->type_mapping()[$value->type]; + $list[$key]->maintenance = $this->maintenance_mapping()[$value->maintenance]; + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Sms_admin_add_view_model.php b/application/view_models/Sms_admin_add_view_model.php new file mode 100755 index 0000000..7c75ade --- /dev/null +++ b/application/view_models/Sms_admin_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Sms_admin_edit_view_model.php b/application/view_models/Sms_admin_edit_view_model.php new file mode 100755 index 0000000..225b8c2 --- /dev/null +++ b/application/view_models/Sms_admin_edit_view_model.php @@ -0,0 +1,139 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_content = $model->content; + $this->_tag = $model->tag; + $this->_slug = $model->slug; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_content () + { + return $this->_content; + } + + public function set_content ($content) + { + $this->_content = $content; + } + + public function get_tag () + { + return $this->_tag; + } + + public function set_tag ($tag) + { + $this->_tag = $tag; + } + + public function get_slug () + { + return $this->_slug; + } + + public function set_slug ($slug) + { + $this->_slug = $slug; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Sms_admin_list_view_model.php b/application/view_models/Sms_admin_list_view_model.php new file mode 100755 index 0000000..c9818fc --- /dev/null +++ b/application/view_models/Sms_admin_list_view_model.php @@ -0,0 +1,156 @@ +_entity = $entity; + } + + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + public function set_list ($list) + { + $this->_list = $list; + } + + public function get_list () + { + return $this->_list; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return count($this->_list); + } + + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['slug'] = $list[$key]->slug; + $clean_list_entry['tag'] = $list[$key]->tag; + $clean_list_entry['content'] = $list[$key]->content; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => 1, + 'num_page' => 1, + 'num_item' => count($clean_list), + 'item' => $clean_list + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Sms_admin_view_view_model.php b/application/view_models/Sms_admin_view_view_model.php new file mode 100755 index 0000000..1b8b697 --- /dev/null +++ b/application/view_models/Sms_admin_view_view_model.php @@ -0,0 +1,149 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_slug = $model->slug; + $this->_tag = $model->tag; + $this->_content = $model->content; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_slug () + { + return $this->_slug; + } + + public function set_slug ($slug) + { + $this->_slug = $slug; + } + + public function get_tag () + { + return $this->_tag; + } + + public function set_tag ($tag) + { + $this->_tag = $tag; + } + + public function get_content () + { + return $this->_content; + } + + public function set_content ($content) + { + $this->_content = $content; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'slug' => $this->get_slug(), + 'tag' => $this->get_tag(), + 'content' => $this->get_content(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Spreadsheet_admin_add_view_model.php b/application/view_models/Spreadsheet_admin_add_view_model.php new file mode 100755 index 0000000..7042f14 --- /dev/null +++ b/application/view_models/Spreadsheet_admin_add_view_model.php @@ -0,0 +1,89 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Spreadsheet_admin_edit_view_model.php b/application/view_models/Spreadsheet_admin_edit_view_model.php new file mode 100755 index 0000000..9e98372 --- /dev/null +++ b/application/view_models/Spreadsheet_admin_edit_view_model.php @@ -0,0 +1,145 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_name = $model->name; + $this->_value = $model->value; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public function get_value () + { + return $this->_value; + } + + public function set_value ($value) + { + $this->_value = $value; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Spreadsheet_admin_list_paginate_view_model.php b/application/view_models/Spreadsheet_admin_list_paginate_view_model.php new file mode 100755 index 0000000..8056716 --- /dev/null +++ b/application/view_models/Spreadsheet_admin_list_paginate_view_model.php @@ -0,0 +1,517 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public $_name = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function get_created_at () + { + return $this->_created_at; + } + + public function set_created_at ($created_at) + { + $this->_created_at = $created_at; + } + + public $_created_at = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['value'] = $list[$key]->value; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list_entry['created_at'] = $list[$key]->created_at; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['value'] = $list[$key]->value; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list_entry['created_at'] = $list[$key]->created_at; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Suggestion_admin_list_paginate_view_model.php b/application/view_models/Suggestion_admin_list_paginate_view_model.php new file mode 100755 index 0000000..ea26cfd --- /dev/null +++ b/application/view_models/Suggestion_admin_list_paginate_view_model.php @@ -0,0 +1,537 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public $_name = NULL; + + public function get_email () + { + return $this->_email; + } + + public function set_email ($email) + { + $this->_email = $email; + } + + public $_email = NULL; + + public function get_suggestion_type () + { + return $this->_suggestion_type; + } + + public function set_suggestion_type ($suggestion_type) + { + $this->_suggestion_type = $suggestion_type; + } + + public $_suggestion_type = NULL; + + public function get_additional_notes () + { + return $this->_additional_notes; + } + + public function set_additional_notes ($additional_notes) + { + $this->_additional_notes = $additional_notes; + } + + public $_additional_notes = NULL; + + public function get_created_at () + { + return $this->_created_at; + } + + public function set_created_at ($created_at) + { + $this->_created_at = $created_at; + } + + public $_created_at = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function suggestion_type_mapping () + { + return $this->_entity->suggestion_type_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->suggestion_type = $this->suggestion_type_mapping()[$value->suggestion_type]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->suggestion_type = $this->suggestion_type_mapping()[$value->suggestion_type]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Suggestion_admin_view_view_model.php b/application/view_models/Suggestion_admin_view_view_model.php new file mode 100755 index 0000000..2b92ed6 --- /dev/null +++ b/application/view_models/Suggestion_admin_view_view_model.php @@ -0,0 +1,121 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function suggestion_type_mapping () + { + return $this->_entity->suggestion_type_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function to_json () + { + return [ + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Tax_admin_add_view_model.php b/application/view_models/Tax_admin_add_view_model.php new file mode 100755 index 0000000..927db3e --- /dev/null +++ b/application/view_models/Tax_admin_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Tax_admin_edit_view_model.php b/application/view_models/Tax_admin_edit_view_model.php new file mode 100755 index 0000000..b5e6dfb --- /dev/null +++ b/application/view_models/Tax_admin_edit_view_model.php @@ -0,0 +1,115 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_tax = $model->tax; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Tax_admin_list_paginate_view_model.php b/application/view_models/Tax_admin_list_paginate_view_model.php new file mode 100755 index 0000000..e23c1e8 --- /dev/null +++ b/application/view_models/Tax_admin_list_paginate_view_model.php @@ -0,0 +1,465 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public $_tax = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['tax'] = $list[$key]->tax; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['tax'] = $list[$key]->tax; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Tax_admin_view_view_model.php b/application/view_models/Tax_admin_view_view_model.php new file mode 100755 index 0000000..e687c64 --- /dev/null +++ b/application/view_models/Tax_admin_view_view_model.php @@ -0,0 +1,123 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_tax = $model->tax; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'tax' => $this->get_tax(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Test_image_admin_add_view_model.php b/application/view_models/Test_image_admin_add_view_model.php new file mode 100755 index 0000000..45748bc --- /dev/null +++ b/application/view_models/Test_image_admin_add_view_model.php @@ -0,0 +1,83 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + +} \ No newline at end of file diff --git a/application/view_models/Test_image_admin_edit_view_model.php b/application/view_models/Test_image_admin_edit_view_model.php new file mode 100755 index 0000000..90831b9 --- /dev/null +++ b/application/view_models/Test_image_admin_edit_view_model.php @@ -0,0 +1,126 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_image = $model->image; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function get_image () + { + return $this->_image; + } + + public function set_image ($image) + { + $this->_image = $image; + } + + public function get_image_id () + { + return $this->_image_id; + } + + public function set_image_id ($image) + { + $this->_image_id = $image; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Test_image_admin_list_paginate_view_model.php b/application/view_models/Test_image_admin_list_paginate_view_model.php new file mode 100755 index 0000000..d07086a --- /dev/null +++ b/application/view_models/Test_image_admin_list_paginate_view_model.php @@ -0,0 +1,465 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_created_at () + { + return $this->_created_at; + } + + public function set_created_at ($created_at) + { + $this->_created_at = $created_at; + } + + public $_created_at = NULL; + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['created_at'] = $list[$key]->created_at; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['created_at'] = $list[$key]->created_at; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Textbook_admin_add_view_model.php b/application/view_models/Textbook_admin_add_view_model.php new file mode 100755 index 0000000..27b49d2 --- /dev/null +++ b/application/view_models/Textbook_admin_add_view_model.php @@ -0,0 +1,89 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Textbook_admin_edit_view_model.php b/application/view_models/Textbook_admin_edit_view_model.php new file mode 100755 index 0000000..a95c729 --- /dev/null +++ b/application/view_models/Textbook_admin_edit_view_model.php @@ -0,0 +1,145 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_name = $model->name; + $this->_isbn = $model->isbn; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public function get_isbn () + { + return $this->_isbn; + } + + public function set_isbn ($isbn) + { + $this->_isbn = $isbn; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Textbook_admin_list_paginate_view_model.php b/application/view_models/Textbook_admin_list_paginate_view_model.php new file mode 100755 index 0000000..a02961e --- /dev/null +++ b/application/view_models/Textbook_admin_list_paginate_view_model.php @@ -0,0 +1,489 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_name () + { + return $this->_name; + } + + public function set_name ($name) + { + $this->_name = $name; + } + + public $_name = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['isbn'] = $list[$key]->isbn; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['name'] = $list[$key]->name; + $clean_list_entry['isbn'] = $list[$key]->isbn; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Ticket_admin_list_paginate_view_model.php b/application/view_models/Ticket_admin_list_paginate_view_model.php new file mode 100755 index 0000000..0e21ffa --- /dev/null +++ b/application/view_models/Ticket_admin_list_paginate_view_model.php @@ -0,0 +1,501 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public $_order_id = NULL; + + public function get_message () + { + return $this->_message; + } + + public function set_message ($message) + { + $this->_message = $message; + } + + public $_message = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function receive_status_mapping () + { + return $this->_entity->receive_status_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->receive_status = $this->receive_status_mapping()[$value->receive_status]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->receive_status = $this->receive_status_mapping()[$value->receive_status]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Ticket_member_list_paginate_view_model.php b/application/view_models/Ticket_member_list_paginate_view_model.php new file mode 100755 index 0000000..295d4c4 --- /dev/null +++ b/application/view_models/Ticket_member_list_paginate_view_model.php @@ -0,0 +1,513 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public $_order_id = NULL; + + public function get_message () + { + return $this->_message; + } + + public function set_message ($message) + { + $this->_message = $message; + } + + public $_message = NULL; + + public function get_receive_status () + { + return $this->_receive_status; + } + + public function set_receive_status ($receive_status) + { + $this->_receive_status = $receive_status; + } + + public $_receive_status = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function receive_status_mapping () + { + return $this->_entity->receive_status_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->receive_status = $this->receive_status_mapping()[$value->receive_status]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->receive_status = $this->receive_status_mapping()[$value->receive_status]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Transaction_admin_add_view_model.php b/application/view_models/Transaction_admin_add_view_model.php new file mode 100755 index 0000000..90b11d3 --- /dev/null +++ b/application/view_models/Transaction_admin_add_view_model.php @@ -0,0 +1,95 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function payment_method_mapping () + { + return $this->_entity->payment_method_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Transaction_admin_edit_view_model.php b/application/view_models/Transaction_admin_edit_view_model.php new file mode 100755 index 0000000..68450a9 --- /dev/null +++ b/application/view_models/Transaction_admin_edit_view_model.php @@ -0,0 +1,235 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_payment_method = $model->payment_method; + $this->_order_id = $model->order_id; + $this->_transaction_date = $model->transaction_date; + $this->_transaction_time = $model->transaction_time; + $this->_user_id = $model->user_id; + $this->_tax = $model->tax; + $this->_discount = $model->discount; + $this->_subtotal = $model->subtotal; + $this->_total = $model->total; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function payment_method_mapping () + { + return $this->_entity->payment_method_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_payment_method () + { + return $this->_payment_method; + } + + public function set_payment_method ($payment_method) + { + $this->_payment_method = $payment_method; + } + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public function get_transaction_date () + { + return $this->_transaction_date; + } + + public function set_transaction_date ($transaction_date) + { + $this->_transaction_date = $transaction_date; + } + + public function get_transaction_time () + { + return $this->_transaction_time; + } + + public function set_transaction_time ($transaction_time) + { + $this->_transaction_time = $transaction_time; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public function get_discount () + { + return $this->_discount; + } + + public function set_discount ($discount) + { + $this->_discount = $discount; + } + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Transaction_admin_list_paginate_view_model.php b/application/view_models/Transaction_admin_list_paginate_view_model.php new file mode 100755 index 0000000..92aa299 --- /dev/null +++ b/application/view_models/Transaction_admin_list_paginate_view_model.php @@ -0,0 +1,607 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_payment_method () + { + return $this->_payment_method; + } + + public function set_payment_method ($payment_method) + { + $this->_payment_method = $payment_method; + } + + public $_payment_method = NULL; + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public $_order_id = NULL; + + public function get_transaction_date () + { + return $this->_transaction_date; + } + + public function set_transaction_date ($transaction_date) + { + $this->_transaction_date = $transaction_date; + } + + public $_transaction_date = NULL; + + public function get_transaction_time () + { + return $this->_transaction_time; + } + + public function set_transaction_time ($transaction_time) + { + $this->_transaction_time = $transaction_time; + } + + public $_transaction_time = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public $_tax = NULL; + + public function get_discount () + { + return $this->_discount; + } + + public function set_discount ($discount) + { + $this->_discount = $discount; + } + + public $_discount = NULL; + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public $_subtotal = NULL; + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public $_total = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function payment_method_mapping () + { + return $this->_entity->payment_method_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->payment_method = $this->payment_method_mapping()[$value->payment_method]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['payment_method'] = $list[$key]->payment_method; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['transaction_date'] = $list[$key]->transaction_date; + $clean_list_entry['transaction_time'] = $list[$key]->transaction_time; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['tax'] = $list[$key]->tax; + $clean_list_entry['discount'] = $list[$key]->discount; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->payment_method = $this->payment_method_mapping()[$value->payment_method]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['payment_method'] = $list[$key]->payment_method; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['transaction_date'] = $list[$key]->transaction_date; + $clean_list_entry['transaction_time'] = $list[$key]->transaction_time; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['tax'] = $list[$key]->tax; + $clean_list_entry['discount'] = $list[$key]->discount; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Transaction_admin_view_view_model.php b/application/view_models/Transaction_admin_view_view_model.php new file mode 100755 index 0000000..cd9943d --- /dev/null +++ b/application/view_models/Transaction_admin_view_view_model.php @@ -0,0 +1,252 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_payment_method = $model->payment_method; + $this->_order_id = $model->order_id; + $this->_transaction_date = $model->transaction_date; + $this->_transaction_time = $model->transaction_time; + $this->_user_id = $model->user_id; + $this->_tax = $model->tax; + $this->_discount = $model->discount; + $this->_subtotal = $model->subtotal; + $this->_total = $model->total; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function payment_method_mapping () + { + return $this->_entity->payment_method_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_payment_method () + { + return $this->_payment_method; + } + + public function set_payment_method ($payment_method) + { + $this->_payment_method = $payment_method; + } + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public function get_transaction_date () + { + return $this->_transaction_date; + } + + public function set_transaction_date ($transaction_date) + { + $this->_transaction_date = $transaction_date; + } + + public function get_transaction_time () + { + return $this->_transaction_time; + } + + public function set_transaction_time ($transaction_time) + { + $this->_transaction_time = $transaction_time; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public function get_discount () + { + return $this->_discount; + } + + public function set_discount ($discount) + { + $this->_discount = $discount; + } + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'payment_method' => $this->get_payment_method(), + 'order_id' => $this->get_order_id(), + 'transaction_date' => $this->get_transaction_date(), + 'transaction_time' => $this->get_transaction_time(), + 'user_id' => $this->get_user_id(), + 'tax' => $this->get_tax(), + 'discount' => $this->get_discount(), + 'subtotal' => $this->get_subtotal(), + 'total' => $this->get_total(), + 'status' => $this->get_status(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/Transaction_member_add_view_model.php b/application/view_models/Transaction_member_add_view_model.php new file mode 100755 index 0000000..ed052a2 --- /dev/null +++ b/application/view_models/Transaction_member_add_view_model.php @@ -0,0 +1,95 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function payment_method_mapping () + { + return $this->_entity->payment_method_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/Transaction_member_edit_view_model.php b/application/view_models/Transaction_member_edit_view_model.php new file mode 100755 index 0000000..9b5f4e7 --- /dev/null +++ b/application/view_models/Transaction_member_edit_view_model.php @@ -0,0 +1,247 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_order_id = $model->order_id; + $this->_user_id = $model->user_id; + $this->_transaction_date = $model->transaction_date; + $this->_transaction_time = $model->transaction_time; + $this->_subtotal = $model->subtotal; + $this->_tax = $model->tax; + $this->_discount = $model->discount; + $this->_total = $model->total; + $this->_stripe_charge_id = $model->stripe_charge_id; + $this->_payment_method = $model->payment_method; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function payment_method_mapping () + { + return $this->_entity->payment_method_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_transaction_date () + { + return $this->_transaction_date; + } + + public function set_transaction_date ($transaction_date) + { + $this->_transaction_date = $transaction_date; + } + + public function get_transaction_time () + { + return $this->_transaction_time; + } + + public function set_transaction_time ($transaction_time) + { + $this->_transaction_time = $transaction_time; + } + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public function get_discount () + { + return $this->_discount; + } + + public function set_discount ($discount) + { + $this->_discount = $discount; + } + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public function get_payment_method () + { + return $this->_payment_method; + } + + public function set_payment_method ($payment_method) + { + $this->_payment_method = $payment_method; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/Transaction_member_list_paginate_view_model.php b/application/view_models/Transaction_member_list_paginate_view_model.php new file mode 100755 index 0000000..189e9d2 --- /dev/null +++ b/application/view_models/Transaction_member_list_paginate_view_model.php @@ -0,0 +1,621 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public $_order_id = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_transaction_date () + { + return $this->_transaction_date; + } + + public function set_transaction_date ($transaction_date) + { + $this->_transaction_date = $transaction_date; + } + + public $_transaction_date = NULL; + + public function get_transaction_time () + { + return $this->_transaction_time; + } + + public function set_transaction_time ($transaction_time) + { + $this->_transaction_time = $transaction_time; + } + + public $_transaction_time = NULL; + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public $_subtotal = NULL; + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public $_tax = NULL; + + public function get_discount () + { + return $this->_discount; + } + + public function set_discount ($discount) + { + $this->_discount = $discount; + } + + public $_discount = NULL; + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public $_total = NULL; + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public $_stripe_charge_id = NULL; + + public function get_payment_method () + { + return $this->_payment_method; + } + + public function set_payment_method ($payment_method) + { + $this->_payment_method = $payment_method; + } + + public $_payment_method = NULL; + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public $_status = NULL; + + public function payment_method_mapping () + { + return $this->_entity->payment_method_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->payment_method = $this->payment_method_mapping()[$value->payment_method]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['transaction_date'] = $list[$key]->transaction_date; + $clean_list_entry['transaction_time'] = $list[$key]->transaction_time; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['tax'] = $list[$key]->tax; + $clean_list_entry['discount'] = $list[$key]->discount; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['payment_method'] = $list[$key]->payment_method; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->payment_method = $this->payment_method_mapping()[$value->payment_method]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['order_id'] = $list[$key]->order_id; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['transaction_date'] = $list[$key]->transaction_date; + $clean_list_entry['transaction_time'] = $list[$key]->transaction_time; + $clean_list_entry['subtotal'] = $list[$key]->subtotal; + $clean_list_entry['tax'] = $list[$key]->tax; + $clean_list_entry['discount'] = $list[$key]->discount; + $clean_list_entry['total'] = $list[$key]->total; + $clean_list_entry['stripe_charge_id'] = $list[$key]->stripe_charge_id; + $clean_list_entry['payment_method'] = $list[$key]->payment_method; + $clean_list_entry['status'] = $list[$key]->status; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/Transaction_member_view_view_model.php b/application/view_models/Transaction_member_view_view_model.php new file mode 100755 index 0000000..b8b8eec --- /dev/null +++ b/application/view_models/Transaction_member_view_view_model.php @@ -0,0 +1,265 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_order_id = $model->order_id; + $this->_user_id = $model->user_id; + $this->_transaction_date = $model->transaction_date; + $this->_transaction_time = $model->transaction_time; + $this->_subtotal = $model->subtotal; + $this->_tax = $model->tax; + $this->_discount = $model->discount; + $this->_total = $model->total; + $this->_stripe_charge_id = $model->stripe_charge_id; + $this->_payment_method = $model->payment_method; + $this->_status = $model->status; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function payment_method_mapping () + { + return $this->_entity->payment_method_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_order_id () + { + return $this->_order_id; + } + + public function set_order_id ($order_id) + { + $this->_order_id = $order_id; + } + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public function get_transaction_date () + { + return $this->_transaction_date; + } + + public function set_transaction_date ($transaction_date) + { + $this->_transaction_date = $transaction_date; + } + + public function get_transaction_time () + { + return $this->_transaction_time; + } + + public function set_transaction_time ($transaction_time) + { + $this->_transaction_time = $transaction_time; + } + + public function get_subtotal () + { + return $this->_subtotal; + } + + public function set_subtotal ($subtotal) + { + $this->_subtotal = $subtotal; + } + + public function get_tax () + { + return $this->_tax; + } + + public function set_tax ($tax) + { + $this->_tax = $tax; + } + + public function get_discount () + { + return $this->_discount; + } + + public function set_discount ($discount) + { + $this->_discount = $discount; + } + + public function get_total () + { + return $this->_total; + } + + public function set_total ($total) + { + $this->_total = $total; + } + + public function get_stripe_charge_id () + { + return $this->_stripe_charge_id; + } + + public function set_stripe_charge_id ($stripe_charge_id) + { + $this->_stripe_charge_id = $stripe_charge_id; + } + + public function get_payment_method () + { + return $this->_payment_method; + } + + public function set_payment_method ($payment_method) + { + $this->_payment_method = $payment_method; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'order_id' => $this->get_order_id(), + 'user_id' => $this->get_user_id(), + 'transaction_date' => $this->get_transaction_date(), + 'transaction_time' => $this->get_transaction_time(), + 'subtotal' => $this->get_subtotal(), + 'tax' => $this->get_tax(), + 'discount' => $this->get_discount(), + 'total' => $this->get_total(), + 'stripe_charge_id' => $this->get_stripe_charge_id(), + 'payment_method' => $this->get_payment_method(), + 'status' => $this->get_status(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/User_admin_add_view_model.php b/application/view_models/User_admin_add_view_model.php new file mode 100755 index 0000000..c362a89 --- /dev/null +++ b/application/view_models/User_admin_add_view_model.php @@ -0,0 +1,107 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function verify_mapping () + { + return $this->_entity->verify_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function role_id_mapping () + { + return $this->_entity->role_id_mapping(); + + } + + public function type_mapping () + { + return $this->_entity->type_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/User_admin_edit_view_model.php b/application/view_models/User_admin_edit_view_model.php new file mode 100755 index 0000000..4f232a0 --- /dev/null +++ b/application/view_models/User_admin_edit_view_model.php @@ -0,0 +1,222 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_email = $model->email; + $this->_first_name = $model->first_name; + $this->_last_name = $model->last_name; + $this->_phone = $model->phone; + $this->_role_id = $model->role_id; + $this->_status = $model->status; + $this->_image = $model->image; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + + public function verify_mapping () + { + return $this->_entity->verify_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function role_id_mapping () + { + return $this->_entity->role_id_mapping(); + + } + + public function type_mapping () + { + return $this->_entity->type_mapping(); + + } + + public function get_email () + { + return $this->_email; + } + + public function set_email ($email) + { + $this->_email = $email; + } + + public function get_first_name () + { + return $this->_first_name; + } + + public function set_first_name ($first_name) + { + $this->_first_name = $first_name; + } + + public function get_last_name () + { + return $this->_last_name; + } + + public function set_last_name ($last_name) + { + $this->_last_name = $last_name; + } + + public function get_phone () + { + return $this->_phone; + } + + public function set_phone ($phone) + { + $this->_phone = $phone; + } + + public function get_role_id () + { + return $this->_role_id; + } + + public function set_role_id ($role_id) + { + $this->_role_id = $role_id; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_image () + { + return $this->_image; + } + + public function set_image ($image) + { + $this->_image = $image; + } + + public function get_image_id () + { + return $this->_image_id; + } + + public function set_image_id ($image) + { + $this->_image_id = $image; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/User_admin_list_paginate_view_model.php b/application/view_models/User_admin_list_paginate_view_model.php new file mode 100755 index 0000000..a9f7314 --- /dev/null +++ b/application/view_models/User_admin_list_paginate_view_model.php @@ -0,0 +1,525 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function get_email () + { + return $this->_email; + } + + public function set_email ($email) + { + $this->_email = $email; + } + + public $_email = NULL; + + public function get_first_name () + { + return $this->_first_name; + } + + public function set_first_name ($first_name) + { + $this->_first_name = $first_name; + } + + public $_first_name = NULL; + + public function get_last_name () + { + return $this->_last_name; + } + + public function set_last_name ($last_name) + { + $this->_last_name = $last_name; + } + + public $_last_name = NULL; + + public function verify_mapping () + { + return $this->_entity->verify_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function role_id_mapping () + { + return $this->_entity->role_id_mapping(); + + } + + public function type_mapping () + { + return $this->_entity->type_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->verify = $this->verify_mapping()[$value->verify]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $list[$key]->role_id = $this->role_id_mapping()[$value->role_id]; + $list[$key]->type = $this->type_mapping()[$value->type]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['email'] = $list[$key]->email; + $clean_list_entry['first_name'] = $list[$key]->first_name; + $clean_list_entry['last_name'] = $list[$key]->last_name; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->verify = $this->verify_mapping()[$value->verify]; + $list[$key]->status = $this->status_mapping()[$value->status]; + $list[$key]->role_id = $this->role_id_mapping()[$value->role_id]; + $list[$key]->type = $this->type_mapping()[$value->type]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['email'] = $list[$key]->email; + $clean_list_entry['first_name'] = $list[$key]->first_name; + $clean_list_entry['last_name'] = $list[$key]->last_name; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/User_admin_view_view_model.php b/application/view_models/User_admin_view_view_model.php new file mode 100755 index 0000000..8e90357 --- /dev/null +++ b/application/view_models/User_admin_view_view_model.php @@ -0,0 +1,223 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_email = $model->email; + $this->_first_name = $model->first_name; + $this->_last_name = $model->last_name; + $this->_image = $model->image; + $this->_phone = $model->phone; + $this->_role_id = $model->role_id; + + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function verify_mapping () + { + return $this->_entity->verify_mapping(); + + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + + } + + public function role_id_mapping () + { + return $this->_entity->role_id_mapping(); + + } + + public function type_mapping () + { + return $this->_entity->type_mapping(); + + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public function get_email () + { + return $this->_email; + } + + public function set_email ($email) + { + $this->_email = $email; + } + + public function get_first_name () + { + return $this->_first_name; + } + + public function set_first_name ($first_name) + { + $this->_first_name = $first_name; + } + + public function get_last_name () + { + return $this->_last_name; + } + + public function set_last_name ($last_name) + { + $this->_last_name = $last_name; + } + + public function get_image () + { + return $this->_image; + } + + public function set_image ($image) + { + $this->_image = $image; + } + + public function get_image_id () + { + return $this->_image_id; + } + + public function set_image_id ($image) + { + $this->_image_id = $image; + } + + public function get_phone () + { + return $this->_phone; + } + + public function set_phone ($phone) + { + $this->_phone = $phone; + } + + public function get_role_id () + { + return $this->_role_id; + } + + public function set_role_id ($role_id) + { + $this->_role_id = $role_id; + } + + public function to_json () + { + return [ + 'id' => $this->get_id(), + 'email' => $this->get_email(), + 'first_name' => $this->get_first_name(), + 'last_name' => $this->get_last_name(), + 'image' => $this->get_image(), + 'phone' => $this->get_phone(), + 'role_id' => $this->get_role_id(), + ]; + } + +} \ No newline at end of file diff --git a/application/view_models/User_card_admin_list_paginate_view_model.php b/application/view_models/User_card_admin_list_paginate_view_model.php new file mode 100755 index 0000000..8e9518c --- /dev/null +++ b/application/view_models/User_card_admin_list_paginate_view_model.php @@ -0,0 +1,509 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_last4 () + { + return $this->_last4; + } + + public function set_last4 ($last4) + { + $this->_last4 = $last4; + } + + public $_last4 = NULL; + + public function get_is_default () + { + return $this->_is_default; + } + + public function set_is_default ($is_default) + { + $this->_is_default = $is_default; + } + + public $_is_default = NULL; + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function is_default_mapping () + { + return $this->_entity->is_default_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->is_default = $this->is_default_mapping()[$value->is_default]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['is_default'] = $list[$key]->is_default; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['stripe_card_id'] = $list[$key]->stripe_card_id; + $clean_list_entry['last4'] = $list[$key]->last4; + $clean_list_entry['brand'] = $list[$key]->brand; + $clean_list_entry['exp_month'] = $list[$key]->exp_month; + $clean_list_entry['exp_year'] = $list[$key]->exp_year; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->is_default = $this->is_default_mapping()[$value->is_default]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['is_default'] = $list[$key]->is_default; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['stripe_card_id'] = $list[$key]->stripe_card_id; + $clean_list_entry['last4'] = $list[$key]->last4; + $clean_list_entry['brand'] = $list[$key]->brand; + $clean_list_entry['exp_month'] = $list[$key]->exp_month; + $clean_list_entry['exp_year'] = $list[$key]->exp_year; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/User_card_member_add_view_model.php b/application/view_models/User_card_member_add_view_model.php new file mode 100755 index 0000000..aca971d --- /dev/null +++ b/application/view_models/User_card_member_add_view_model.php @@ -0,0 +1,89 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function is_default_mapping () + { + return $this->_entity->is_default_mapping(); + + } + +} \ No newline at end of file diff --git a/application/view_models/User_card_member_list_paginate_view_model.php b/application/view_models/User_card_member_list_paginate_view_model.php new file mode 100755 index 0000000..82f8d94 --- /dev/null +++ b/application/view_models/User_card_member_list_paginate_view_model.php @@ -0,0 +1,509 @@ +_entity = $entity; + $this->_library = $library; + $this->_base_url = str_replace('/0', '/', $base_url); + } + + /** + * set_total_rows function + * + * @param integer $total_rows + * @return void + */ + public function set_total_rows ($total_rows) + { + $this->_total_rows = $total_rows; + } + + /** + * set_per_page function + * + * @param integer $per_page + * @return void + */ + public function set_per_page ($per_page) + { + $this->_per_page = $per_page; + } + /** + * format_layout function + * + * @param integer $_format_layout + * @return void + */ + public function set_format_layout ($_format_layout) + { + $this->_format_layout = $_format_layout; + } + + /** + * set_order_by function + * + * @param string $order_by + * @return void + */ + public function set_order_by ($order_by) + { + $this->_order_by = $order_by; + } + + /** + * set_sort function + * + * @param string $sort + * @return void + */ + public function set_sort ($sort) + { + $this->_sort = $sort; + } + + /** + * set_sort_base_url function + * + * @param string $sort_base_url + * @return void + */ + public function set_sort_base_url ($sort_base_url) + { + $this->_sort_base_url = $sort_base_url; + } + + /** + * set_page function + * + * @param integer $page + * @return void + */ + public function set_page ($page) + { + $this->_page = $page; + } + + /** + * set_list function + * + * @param mixed $list + * @return void + */ + public function set_list ($list) + { + $this->_list = $list; + } + + /** + * get_total_rows function + * + * @return integer + */ + public function get_total_rows () + { + return $this->_total_rows; + } + + /** + * get_format_layout function + * + * @return integer + */ + public function get_format_layout () + { + return $this->_format_layout; + } + + /** + * get_per_page function + * + * @return integer + */ + public function get_per_page () + { + return $this->_per_page; + } + + /** + * get_page function + * + * @return integer + */ + public function get_page () + { + return $this->_page; + } + + /** + * num_links function + * + * @return integer + */ + public function get_num_links () + { + return $this->_num_links; + } + + /** + * set_order_by function + * + */ + public function get_order_by () + { + return $this->_order_by; + } + + /** + * get_field_column function + * + */ + public function get_field_column () + { + return $this->_field_column; + } + + /** + * set_sort function + * + */ + public function get_sort () + { + return $this->_sort; + } + + /** + * set_sort_base_url function + * + */ + public function get_sort_base_url () + { + return $this->_sort_base_url; + } + + /** + * num_pages function + * + * @return integer + */ + public function get_num_page () + { + $num = ceil($this->_total_rows / $this->_per_page); + return ($num > 0) ? (int) $num : 1; + } + + public function image_or_file ($file) + { + $images = ['.jpg','.png', '.gif', '.jpeg', '.bmp']; + $is_image = FALSE; + if ($this->strposa($file, $images)) + { + return "
    "; + } + + return "{$file}"; + } + + /** + * Strpos for array + * + * @param string $haystack + * @param array $needle + * @return boolean + */ + private function strposa($haystack, $needle) + { + foreach($needle as $query) + { + if(strpos($haystack, $query) !== FALSE) + { + return TRUE; + } + } + return FALSE; + } + + /** + * get_list function + * + * @return mixed + */ + public function get_list () + { + $this->_library->initialize([ + 'reuse_query_string' => TRUE, + 'base_url' => $this->_base_url, + 'total_rows' => $this->_total_rows, + 'per_page' => $this->_per_page, + 'num_links' => $this->_num_links, + 'full_tag_open' => '
      ', + 'full_tag_close' => '
    ', + 'attributes' => ['class' => 'page-link'], + 'first_link' => FALSE, + 'last_link' => FALSE, + 'first_tag_open' => '
  • ', + 'first_tag_close' => '
  • ', + 'prev_link' => '«', + 'prev_tag_open' => '
  • ', + 'prev_tag_close' => '
  • ', + 'next_link' => '»', + 'next_tag_open' => '
  • ', + 'next_tag_close' => '
  • ', + 'last_tag_open' => '
  • ', + 'last_tag_close' => '
  • ', + 'cur_tag_open' => '
  • ', + 'cur_tag_close' => '(current)
  • ', + 'num_tag_open' => '
  • ', + 'num_tag_close' => '
  • ' + ]); + return $this->_list; + } + + /** + * get_links function + * + * @return mixed + */ + public function get_links () + { + $this->_links = $this->_library->create_links(); + return $this->_links; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_column ($column) + { + $this->_column = $column; + } + + public function get_column () + { + return $this->_column; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function get_query_parameter() + { + $get_parameter = $_GET; + $blacklist = array( + 'order_by', + 'direction' + ); + $query_list = array(); + foreach($get_parameter as $key => $value) + { + if(!in_array($key, $blacklist)) + { + $query_list[] = "$key=$value"; + } + } + return "&" . implode("&", $query_list); + } + + + public function get_is_default () + { + return $this->_is_default; + } + + public function set_is_default ($is_default) + { + $this->_is_default = $is_default; + } + + public $_is_default = NULL; + + public function get_user_id () + { + return $this->_user_id; + } + + public function set_user_id ($user_id) + { + $this->_user_id = $user_id; + } + + public $_user_id = NULL; + + public function get_last4 () + { + return $this->_last4; + } + + public function set_last4 ($last4) + { + $this->_last4 = $last4; + } + + public $_last4 = NULL; + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + + public $_id = NULL; + + public function is_default_mapping () + { + return $this->_entity->is_default_mapping(); + + } + + public function to_json () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->is_default = $this->is_default_mapping()[$value->is_default]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['is_default'] = $list[$key]->is_default; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['stripe_card_id'] = $list[$key]->stripe_card_id; + $clean_list_entry['last4'] = $list[$key]->last4; + $clean_list_entry['brand'] = $list[$key]->brand; + $clean_list_entry['exp_month'] = $list[$key]->exp_month; + $clean_list_entry['exp_year'] = $list[$key]->exp_year; + $clean_list[] = $clean_list_entry; + } + + return [ + 'page' => $this->get_page(), + 'num_page' => $this->get_num_page(), + 'num_item' => $this->get_total_rows(), + 'item' => $clean_list + ]; + } + + public function to_csv () + { + $list = $this->get_list(); + + $clean_list = []; + + foreach ($list as $key => $value) + { + $list[$key]->is_default = $this->is_default_mapping()[$value->is_default]; + $clean_list_entry = []; + $clean_list_entry['id'] = $list[$key]->id; + $clean_list_entry['is_default'] = $list[$key]->is_default; + $clean_list_entry['user_id'] = $list[$key]->user_id; + $clean_list_entry['stripe_card_id'] = $list[$key]->stripe_card_id; + $clean_list_entry['last4'] = $list[$key]->last4; + $clean_list_entry['brand'] = $list[$key]->brand; + $clean_list_entry['exp_month'] = $list[$key]->exp_month; + $clean_list_entry['exp_year'] = $list[$key]->exp_year; + $clean_list[] = $clean_list_entry; + } + + $columns = $this->get_column(); + $columns = array_diff($columns,['Action']); + $csv = implode(",", $columns) . "\n"; + $fields = array_filter($this->get_field_column()); + foreach($clean_list as $row) + { + $row_csv = []; + foreach($row as $key =>$column) + { + if (in_array($key, $fields)) + { + $row_csv[] = '"' . $column . '"'; + } + } + $csv = $csv . implode(',', $row_csv) . "\n"; + } + return $csv; +} + +} \ No newline at end of file diff --git a/application/view_models/User_credentials_admin_edit_view_model.php b/application/view_models/User_credentials_admin_edit_view_model.php new file mode 100755 index 0000000..55384a7 --- /dev/null +++ b/application/view_models/User_credentials_admin_edit_view_model.php @@ -0,0 +1,223 @@ +_entity = $entity; + } + + public function get_entity () + { + return $this->_entity; + } + + /** + * set_heading function + * + * @param string $heading + * @return void + */ + public function set_heading ($heading) + { + $this->_heading = $heading; + } + + /** + * get_heading function + * + * @return string + */ + public function get_heading () + { + return $this->_heading; + } + + public function set_model ($model) + { + $this->_model = $model; + $this->_id = $model->id; + $this->_email = $model->email; + $this->_password = $model->password; + $this->_status = $model->status; + } + + public function timeago($date) + { + $timestamp = strtotime($date); + + $strTime = array('second', 'minute', 'hour', 'day', 'month', 'year'); + $length = array('60', '60', '24', '30', '12', '10'); + + $currentTime = time(); + if($currentTime >= $timestamp) + { + $diff = time() - $timestamp; + + for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) + { + $diff = $diff / $length[$i]; + } + + $diff = round($diff); + return $diff . ' ' . $strTime[$i] . '(s) ago '; + } + } + + public function time_default_mapping () + { + $results = []; + for ($i=0; $i < 24; $i++) + { + for ($j=0; $j < 60; $j++) + { + $hour = ($i < 10) ? '0' . $i : $i; + $min = ($j < 10) ? '0' . $j : $j; + $results[($i * 60) + $j] = "$hour:$min"; + } + } + return $results; + } + + public function verify_mapping () + { + return $this->_entity->verify_mapping(); + } + + public function status_mapping () + { + return $this->_entity->status_mapping(); + } + + public function role_id_mapping () + { + return $this->_entity->role_id_mapping(); + } + + public function type_mapping () + { + return $this->_entity->type_mapping(); + } + + public function get_email () + { + return $this->_email; + } + + public function set_email ($email) + { + $this->_email = $email; + } + + public function get_password () + { + return $this->_password; + } + + public function set_password ($password) + { + $this->_password = $password; + } + + public function get_first_name () + { + return $this->_first_name; + } + + public function set_first_name ($first_name) + { + $this->_first_name = $first_name; + } + + public function get_last_name () + { + return $this->_last_name; + } + + public function set_last_name ($last_name) + { + $this->_last_name = $last_name; + } + + public function get_phone () + { + return $this->_phone; + } + + public function set_phone ($phone) + { + $this->_phone = $phone; + } + + public function get_role_id () + { + return $this->_role_id; + } + + public function set_role_id ($role_id) + { + $this->_role_id = $role_id; + } + + public function get_image () + { + return $this->_image; + } + + public function set_image ($image) + { + $this->_image = $image; + } + + public function get_image_id () + { + return $this->_image_id; + } + + public function set_image_id ($image) + { + $this->_image_id = $image; + } + + public function get_status () + { + return $this->_status; + } + + public function set_status ($status) + { + $this->_status = $status; + } + + public function get_id () + { + return $this->_id; + } + + public function set_id ($id) + { + $this->_id = $id; + } + +} \ No newline at end of file diff --git a/application/view_models/index.html b/application/view_models/index.html new file mode 100755 index 0000000..b702fbc --- /dev/null +++ b/application/view_models/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + diff --git a/application/views/.DS_Store b/application/views/.DS_Store new file mode 100644 index 0000000..b314ac9 Binary files /dev/null and b/application/views/.DS_Store differ diff --git a/application/views/Admin/Attribute_type.php b/application/views/Admin/Attribute_type.php new file mode 100755 index 0000000..d74c0f4 --- /dev/null +++ b/application/views/Admin/Attribute_type.php @@ -0,0 +1,356 @@ + + + +#content{padding:0px !important;}'; + echo ''; + echo ''; +} +?> + + + + + + + + + + + + + + \ No newline at end of file diff --git a/application/views/Admin/Attribute_typeAdd.php b/application/views/Admin/Attribute_typeAdd.php new file mode 100755 index 0000000..53bb766 --- /dev/null +++ b/application/views/Admin/Attribute_typeAdd.php @@ -0,0 +1,68 @@ +#content{padding:0px !important;}'; +} +?> + + \ No newline at end of file diff --git a/application/views/Admin/Attribute_typeEdit.php b/application/views/Admin/Attribute_typeEdit.php new file mode 100755 index 0000000..4220b25 --- /dev/null +++ b/application/views/Admin/Attribute_typeEdit.php @@ -0,0 +1,67 @@ +#content{padding:0px !important;}'; +} +?> +