diff --git a/public/assets/ex/fonts/JennaSue.ttf b/public/assets/ex/fonts/JennaSue.ttf new file mode 100644 index 0000000..667a551 Binary files /dev/null and b/public/assets/ex/fonts/JennaSue.ttf differ diff --git a/src/ex/cli_controllers/app/home_ctrl.php b/src/ex/cli_controllers/app/home_ctrl.php new file mode 100644 index 0000000..ae375c6 --- /dev/null +++ b/src/ex/cli_controllers/app/home_ctrl.php @@ -0,0 +1,21 @@ +set_author("Robert Strutts, plus ME!"); $view = new \tts\view(); $view->set('html', $html); @@ -21,30 +19,44 @@ class home_ctrl { $view->render($this, "app/home_index"); } - public function name_demo() { - $input = \ex\inputs\app\home_in::name_demo(); - - \tts\main\registry::set('db', \tts\main\registry::get('di')->get_service('db_mocker') ); // Grabs DB - $model = new \ex\models\app\home_model(\tts\main\registry::get('db')); - $model->init_name_demo_table(); // Create Table if NOT exists! - $model->populate(10); // INSERT 10 random rows of data - $model->save_new_user($input); // Save user from Users Request Data - - $input['model'] = $model->get_users(); + public function name_demo() { + $view = new \tts\view(); + $view->set('html', new \tts\html_document()); + $view->set_template('main'); + $view->include("app/name_demo"); + $view->render($this); + } + + public function name_demo_post() { + \tts\main\registry::set('db', \tts\main\registry::get('di')->get_service('db_mocker') ); + + $input = \prj\ex\inputs\app\home_in::name_demo(); - $output = \ex\outputs\app\home_out::name_demo($input); -//asd(); - $html = new \tts\html_document(); - $html->set_footer('


By BBV-Soft'); + \prj\ex\logic\app\home_logic::name_demo($input); + + $output = \prj\ex\outputs\app\home_out::name_demo($input); $view = new \tts\view(); - $view->set('html', $html); // set view's local variables - $view->set_template('main'); + $view->set('html', new \tts\html_document()); $view->set('output', $output); - $view->include("app/name_demo"); // Alias to add_view/set_view + $view->set_template('main'); + $view->include("app/name_demo_post"); $view->render($this); } + public function test($id) { + \tts\common::real_time_output(); + + echo "bla $id"; + echo PHP_EOL; + + for ($i=0; $i<10;$i++){ + echo $i; + echo str_pad('', 14960); + sleep(1); + } + } + public function error() { tts_broken_error(); } // Needed: To show Live Page for Broken Pages } \ No newline at end of file diff --git a/src/ex/controllers/bills/notices_ctrl.php b/src/ex/controllers/bills/notices_ctrl.php new file mode 100644 index 0000000..4a8d8cb --- /dev/null +++ b/src/ex/controllers/bills/notices_ctrl.php @@ -0,0 +1,39 @@ +set('html', $html); + $view->set_template('main'); + } + $view->set('view_as_pdf', $view_as_pdf); + $view->set('template_assigns', $output); + $view->set('font_url', TTS_PROJECT_BASE_REF . 'assets/fonts/JennaSue.ttf'); + if (! $view_as_pdf) { + $view->add_view('bills/notice_of_late_payment_css.php'); + } + $view->add_view('bills/notice_of_late_payment_pdf.tpl'); + $html_code = $view->fetch($this); + + if (! $view_as_pdf) { + echo $html_code; + exit; + } + + // Makes PDF output + \prj\ex\outputs\bills\notices_out::gen_pdf_for_late_payment($html_code); + } + +} diff --git a/src/ex/controllers/cronjobs/daily_ctrl.php b/src/ex/controllers/cronjobs/daily_ctrl.php deleted file mode 100644 index 0975fb6..0000000 --- a/src/ex/controllers/cronjobs/daily_ctrl.php +++ /dev/null @@ -1,14 +0,0 @@ - - [ - 'input' => \tts\INPUTS::get, // Others: _post, _json (REQUIRED param) - 'skip_db' => false, // this is an Optional value (DEFAULT: false) - 'field' => \tts\FIELD_FILTER::raw, // Others: raw, (DEFAULT: string), email, url, float, int - 'html' => \tts\HTML_FLAG::purify, // Others: strip, encode, purify, (DEFAULT: escape) - 'rule' => 'required' // Others: email, valid_email_domain, - // min, max, between, same, secure (password), alphanumeric - ], - 'age' => - [ - 'input' => \tts\INPUTS::get, - 'field' => \tts\FIELD_FILTER::integer_number, - 'rule' => 'greater_than: 18', //'number_range: 18, 24' - 'message' => ['greater_than' => 'Must be an Adult!'] - ], - ]); + \tts\safer_io::init_json(); // Staticly set JSON data if any + + $required_post_string_field = new IO(); + $required_post_string_field->input_type = INPUTS::post; + $required_post_string_field->field_filter = FIELD_FILTER::raw_string; + $required_post_string_field->escape_html = HTML_FLAG::escape; + $required_post_string_field->validation_rule = 'required|max: 75'; + $required_post_string_field->use_db_filter = DB_FILTER::OFF; + $required_post_string_field->skip_the_db = false; + + $adult_post_int_age_field = new IO(); + $adult_post_int_age_field->input_type = INPUTS::post; + $adult_post_int_age_field->field_filter = FIELD_FILTER::integer_number; + $adult_post_int_age_field->validation_rule = 'greater_than: 18'; + $adult_post_int_age_field->validation_message = ['greater_than' => 'The %s must be an Adult over %d!']; - return $safer_data; // Makes an Array of: fields, html, and errrors + return [ + 'first_name' => $required_post_string_field, + 'last_name' => $required_post_string_field, + 'age' => $adult_post_int_age_field + ]; } } \ No newline at end of file diff --git a/src/ex/logic/app/home_logic.php b/src/ex/logic/app/home_logic.php new file mode 100644 index 0000000..54dca42 --- /dev/null +++ b/src/ex/logic/app/home_logic.php @@ -0,0 +1,37 @@ +init_name_demo_table(); // Create Table if NOT exists! + $model->populate(10); // INSERT 10 random rows of data + + $success = $model->save_new_user($input); // Save data from Request Data + $input['model'] = ($success===true) ? + $model->get_users(15) : + $model->get_users(0); + } else { + $input['model'] = $model->get_users(0); + } + } + +} diff --git a/src/ex/models/app/home_model.php b/src/ex/models/app/home_model.php index 7ac1bf0..6fb1e22 100644 --- a/src/ex/models/app/home_model.php +++ b/src/ex/models/app/home_model.php @@ -2,16 +2,36 @@ declare(strict_types=1); -namespace ex\models\app; +namespace prj\ex\models\app; class home_model { private $dbh; private $name_demo_table = "test_names"; + private $db_helper; public function __construct($dbh) { +// \tts\exceptions\DB_Exception::$error_message = "Home Model Error"; $this->dbh = $dbh; + $this->db_helper = new \tts\database\help_save($this->dbh, $this->name_demo_table); } - + + public function is_valid(array $data): bool { + return \tts\database\help_load::is_valid($data); + } + + public function pre_save(): bool { + $missing = $this->db_helper->get_missing(); + if (count($missing)) { + echo "Required fields not set " . implode(",", $missing) . "!"; + return false; + } + + if ($this->db_helper->dump_diff()) { + return false; // Opps forgot a field! + } + return true; + } + public function init_name_demo_table(): void { $create_table_sql = "CREATE TABLE IF NOT EXISTS `{$this->name_demo_table}`( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -19,7 +39,11 @@ class home_model { `last_name` TEXT, `age` INTEGER )"; + try { $this->dbh->query($create_table_sql); + } catch (\PDOException $e) { + echo \tts\exceptions\DB_Exception::customMessage($e, "Unable to make table!"); + } } public function populate($rows): void { @@ -27,45 +51,43 @@ class home_model { $data = [ 'first_name' => \tts\arrays\mocking\rnd_names::get_first_names(), 'last_name' => \tts\arrays\mocking\rnd_names::get_last_names(), 'age' => \tts\arrays\mocking\rnd_names::mock_age() ]; + try { $dummy->add_dummy_data($this->name_demo_table, $rows, $data); + } catch (\PDOException $e) { + echo \tts\exceptions\DB_Exception::customMessage($e, "Unable to populate table!"); + } } + public function get_member(string $member): ?string { + return $this->db_helper->get_member($member); + } + public function save_new_user(array $input): bool { - $db_helper = new \tts\database\help_save($this->dbh, $this->name_demo_table); - - $db_helper->set_member('last_name', "Manning"); // Needs this Missing field - - $set = $db_helper->set_members_by_array($input); + $set = $this->db_helper->set_members_by_generator($input); if ($set === false) { return false; // Found Validation issues in input } - - $status = $db_helper->save($this); - if ($status === $db_helper::successful_save) { - return true; + try { + $status = $this->db_helper->save($this); + } catch (\PDOException $e) { + echo \tts\exceptions\DB_Exception::customMessage($e, "Unable to save changes!"); + } + if ($status === $this->db_helper::successful_save) { + return true; // It saved } - return false; + return false; // It did not save } - - public function get_users(): array { - $sql = "SELECT * FROM {$this->name_demo_table} LIMIT 12"; - $result = $this->dbh->query($sql); - return $result->fetchAll(\PDO::FETCH_ASSOC); - } -/* - private function save(array $input) { - if ($input['errors']) { - return []; + + public function get_users(int $number_of_users_to_get = 12): \Generator { + if ($number_of_users_to_get === 0) { + return \tts\database\help_load::empty_generator(); } - - $insert_sql = "INSERT INTO `{$this->table}`" - . "(`first_name`, `last_name`, `age`)" - . " VALUES (:first_name, :last_name, :age)"; - $r = $this->dbh->prepare($insert_sql); - $r->bindParam(':first_name', $input['fields']['first_name'], \PDO::PARAM_STR); - $r->bindValue(':last_name', "Manning", \PDO::PARAM_STR); - $r->bindParam(':age', $input['fields']['age'], \PDO::PARAM_INT); - $r->execute(); + try { + $sql = "SELECT * FROM {$this->name_demo_table} LIMIT {$number_of_users_to_get}"; + $result = $this->dbh->query($sql); + return \tts\database\help_load::pdo_fetch_lazy($result); + } catch (\PDOException $e) { + echo \tts\exceptions\DB_Exception::customMessage($e); + } } -*/ } \ No newline at end of file diff --git a/src/ex/outputs/app/home_out.php b/src/ex/outputs/app/home_out.php index cd38eea..154b064 100644 --- a/src/ex/outputs/app/home_out.php +++ b/src/ex/outputs/app/home_out.php @@ -2,41 +2,49 @@ declare(strict_types=1); -namespace ex\outputs\app; +namespace prj\ex\outputs\app; + +use \tts\safer_io as SafeIO; class home_out { - public static function name_demo(array $input): array { - - $age = $input['html']['age']; + public static function name_demo(array & $input): array { + $ret['model'] = $input['model']; + unset($input['model']); // Free up some space - $first_name = $input['html']['first_name']; + $submitted = $input['submitted'] ?? false; - if ($first_name === "Chris") { - $more = "I think you will like this!"; - } else { - // Lets make a HyperLink as an Example for Chris - $more = "38,'first_name'=>"Chris"] - ) . "\">See Chris"; - } + if ($submitted) { + $html_output = []; + $errors = []; + foreach(SafeIO::html_escape_and_sanitize($input) as $html) { + $key = $html['name'] ?? ""; + $html_output[$key] = $html['html']; - if ($input['errors']) { - $ret['main'] = $more; + if (\tts\common::get_count($html['errors'])) { + $errors[$key] = $html['errors'][$key]; + } + } + + $age = $html_output['age'] ?? 0; + $first_name = $html_output['first_name'] ?? "Unknown"; + $last_name = $html_output['last_name'] ?? "Unknown"; + + $ret['main'] = (\tts\common::get_count($errors)) ? "" : "Hello, {$first_name} {$last_name}, you are {$age} years old!" . PHP_EOL; + $ret['errors'] = $errors; } else { - $ret['main'] = "Hello {$first_name}, You are {$age} years old!" . PHP_EOL . $more; + $ret['main'] = "Welcome"; + $ret['errors'] = []; } - $ret['errors'] = $input['errors']; - $ret['model'] = $input['model']; + unset($input); // Free up some space return $ret; } - + public static function show_errors(array $errors): string { if ($errors) { - $message = "Sorry, but we had the following errors: "; + $message = "Please correct the following errors: "; $i = 0; foreach($errors as $error) { $i++; @@ -44,14 +52,17 @@ class home_out { } return $message; } - return "Yeah, no errors were made!"; + return ""; // No Errors to return here } - public static function show_user_details(array $input): void { - if (! count($input)) { - return; + public static function show_user_details(\Generator $input): void { + if (! $input->current()) { + return; // No Data, so Bail here } - \tts\html::show_table(['ID', 'First Name', 'Last Name', 'Age'], $input); + \tts\html::show_table_from_generator( + ['ID', 'First Name', 'Last Name', 'Age'], + $input + ); } -} \ No newline at end of file +} diff --git a/src/ex/outputs/bills/notices_out.php b/src/ex/outputs/bills/notices_out.php new file mode 100644 index 0000000..edaf7ed --- /dev/null +++ b/src/ex/outputs/bills/notices_out.php @@ -0,0 +1,43 @@ + 'legal_date')); + $output['wrap'] = ($view_as_pdf) ? "" : 'class="non-pdf-paper-wrap"'; + $output['apt'] = '208'; + $output['signatures'] = [ + ['here' => 'Manager', 'name' => 'Mark Smith'], + ['here' => 'Customer'] + ]; + return $output; + } + + public static function gen_pdf_for_late_payment(string $html_code): void { + $style_sheet = file_get_contents(\tts\site_helper::get_root() . \tts\site_helper::get_project() . 'views/default/bills/notice_of_late_payment_css.php'); + + require_once TTS_VENDOR . 'autoload.php'; + $mpdf = new \Mpdf\Mpdf(['tempDir' => \tts\site_helper::get_root() . '/tmp/mpdf']); // chown www-data, chmod 775 + + $mpdf->AddFontDirectory(PROJECT_ASSETS_DIR . '/fonts'); + $mpdf->fontdata['jennasue'] = ['R'=>"JennaSue.ttf"]; + $mpdf->available_unifonts[] = 'jennasue'; + $mpdf->AddFont('jennasue', 'R'); + $mpdf->SetFont('jennasue'); + + $mpdf->WriteHTML($style_sheet,\Mpdf\HTMLParserMode::HEADER_CSS); + $mpdf->WriteHTML($html_code,\Mpdf\HTMLParserMode::HTML_BODY); + $mpdf->Output(); + } +} + diff --git a/src/ex/routes/cli_routes.php b/src/ex/routes/cli_routes.php new file mode 100644 index 0000000..7ad9806 --- /dev/null +++ b/src/ex/routes/cli_routes.php @@ -0,0 +1,15 @@ + - + diff --git a/src/ex/test_controllers/app/first_ctrl.php b/src/ex/test_controllers/app/first_ctrl.php new file mode 100644 index 0000000..bcc180f --- /dev/null +++ b/src/ex/test_controllers/app/first_ctrl.php @@ -0,0 +1,23 @@ + [], ]; +const JS_TSR = [ "js/trouble_shooting_routes.js" =>[] ]; + const JS_FILES = [ - "js/testing.js" => [], + "js/router_loader.js" => [], + "js/routes.js" => [], ]; -$JS = "tts_set_project(\"" . rtrim(\tts\site_helper::get_project(), '/') ."\");" . PHP_EOL; /* Set JS Error Handler */ -$JS .= "var ajax_folder = \"" . $AJAX_FOLDER . "\"" . PHP_EOL; /* assets AJAX foldername and path */ +$JS = "var ajax_folder = \"" . $AJAX_FOLDER . "\"" . PHP_EOL; /* assets AJAX foldername and path */ $JS .= "var debug = 1; /* Debug mode 1 = true */" . PHP_EOL; $JS .= "function debug_print(msg) { if (debug === 1) console.log(msg); }" . PHP_EOL; -$JS .= \tts\assets::get_ajax_files(\tts\site_helper::get_root() . $AJAX_FOLDER . "/"); +$JS .= \tts\assets::get_ajax_files(PROJECT_ASSETS_DIR . "/ajax/"); $html->add_to_javascript($JS); $html->set_assets_from_array(JS_CDN_FILES, 'main_js', 'cdn'); -//$html->set_assets_from_array(JS_FILES, 'main_js'); \ No newline at end of file +$html->set_assets_from_array(JS_TSR, 'js', 'assets'); +$html->set_assets_from_array(JS_FILES, 'js', 'project'); \ No newline at end of file diff --git a/src/ex/views/default/app/home_index.php b/src/ex/views/default/app/home_index.php index edfbc75..9cd570b 100644 --- a/src/ex/views/default/app/home_index.php +++ b/src/ex/views/default/app/home_index.php @@ -1,10 +1,16 @@ -

Welcome...to Example Codes

- -View Name Demo \ No newline at end of file +

Welcome...to your Example Project

+ +View Name Demo

+ +View Late Payment Signing \ No newline at end of file diff --git a/src/ex/views/default/app/name_demo.php b/src/ex/views/default/app/name_demo.php index cda9530..b971270 100644 --- a/src/ex/views/default/app/name_demo.php +++ b/src/ex/views/default/app/name_demo.php @@ -1,16 +1,19 @@ -

BLA BLA BLA okay...

+ - - - - +declare(strict_types=1); +$route_name_demo = "app/home"; +$method_name_demo_post = "name_demo_post"; +?>

-
+
+

- \ No newline at end of file +
+
+ +">Back to Main \ No newline at end of file diff --git a/src/ex/views/default/app/name_demo_post.php b/src/ex/views/default/app/name_demo_post.php new file mode 100644 index 0000000..562635a --- /dev/null +++ b/src/ex/views/default/app/name_demo_post.php @@ -0,0 +1,22 @@ + +Back + +

BLA BLA BLA okay...

+ +
+
+
+ + + + + +
+
+Back \ No newline at end of file diff --git a/src/ex/views/default/bills/notice_of_late_payment_css.php b/src/ex/views/default/bills/notice_of_late_payment_css.php new file mode 100644 index 0000000..a44694a --- /dev/null +++ b/src/ex/views/default/bills/notice_of_late_payment_css.php @@ -0,0 +1,124 @@ +'; ?> + +.page { + width: 8.5in; + height: 11in; + margin: 0mm auto; +} + +body { + font-family: FreeSans, sans-serif; + font-size: ; +} + +/* DivTable.com */ +.divTable{ + display: table; +} +.divTableRow { + display: table-row; +} +.divTableHeading { + display: table-header-group; +} +.divTableCell, .divTableHead { + display: table-cell; +} +.divTableHeading { + display: table-header-group; + font-weight: bold; +} +.divTableFoot { + display: table-footer-group; + font-weight: bold; +} +.divTableBody { + display: table-row-group; +} +/* End of DivTable */ + +.div-table-tr { + height: 35pt; +} + +.table-tr { + height: 35pt; +} + +.table-todays-date { font-weight: 500; } + +.div-table-todays-date { font-weight: 500; } + +.table-blank-td-space { + padding-left: 100px; +} + +.div-table-blank-td-space { + padding-left: 100px; +} + +.signers-table-fix { + font-size: 29pt; + height: 14pt; + line-height: 16px; + margin: 0; +} + +.signers-div-table-fix { + font-size: 32pt; + height: 18pt; + line-height: 26px; + margin: 0; +} + +.address { + max-width: 4in; + width: 3in; + margin-bottom: 2.5mm; + padding-bottom: 0.2mm; + border-bottom: 0.25mm solid #000000; +} + +.late-notice { + font-size: 15pt; + text-transform: uppercase; + text-align: center; +} + +.big-spaces { + padding-bottom: 0.75in; +} + +.small-spaces { + padding-bottom: 0.45in; +} + +.sign-here-line { + max-width: 3in; + width: 2.5in; + border-bottom: 0.25mm solid #000000; +} + +.non-pdf-paper-wrap { + width: 80ch; + word-break: break-normal; + white-space: normal; +} + +@font-face { + font-family: jennasue; + +} + +.cursive { + font-family: jennasue; + font-style: normal; + font-variant: normal; + font-weight: 400; +} + +.centered-text { + text-align:center; +} + +'; \ No newline at end of file diff --git a/src/ex/views/includes/bills/notice_of_late_payment_pdf.tpl b/src/ex/views/includes/bills/notice_of_late_payment_pdf.tpl new file mode 100644 index 0000000..cd01ea3 --- /dev/null +++ b/src/ex/views/includes/bills/notice_of_late_payment_pdf.tpl @@ -0,0 +1,20 @@ +{% for sign in signatures %} + + + + + + + + + + + + +
{{ todays_date }}  + {% unless sign.here == 'Tenant' %} + {{ sign.name }} + {% endunless %} +
Date {{ sign.here }}
+
+{% endfor %} \ No newline at end of file