Changeset 2900796
- Timestamp:
- 04/18/2023 03:11:48 PM (3 years ago)
- Location:
- time-tracker/trunk
- Files:
-
- 15 added
- 18 edited
-
inc/CF7 (added)
-
inc/CF7/class-time-tracker-activator-forms-cf7.php (added)
-
inc/CF7/class-tt-hook-save-form-data-cf7.php (added)
-
inc/CF7/function-tt-custom-cf7-field-categories-from-settings.php (added)
-
inc/CF7/function-tt-custom-cf7-field-client-dropdown.php (added)
-
inc/CF7/function-tt-custom-cf7-field-datetime.php (added)
-
inc/CF7/function-tt-custom-cf7-field-project-dropdown.php (added)
-
inc/CF7/function-tt-custom-cf7-field-task-dropdown.php (added)
-
inc/CF7/function-tt-recaptcha-cf7.php (added)
-
inc/WPF (added)
-
inc/WPF/class-time-tracker-activator-forms-wpf.php (added)
-
inc/WPF/class-time-tracker-wpf-custom-post-types.php (added)
-
inc/WPF/class-time-tracker-wpf-fields-add-properties.php (added)
-
inc/WPF/class-time-tracker-wpf-select-fields-dynamic-options.php (added)
-
inc/WPF/class-tt-hook-save-form-data-wpf.php (added)
-
inc/class-time-tracker-activator-forms.php (modified) (17 diffs)
-
inc/class-time-tracker-activator-pages.php (modified) (8 diffs)
-
inc/class-time-tracker-activator.php (modified) (2 diffs)
-
inc/class-time-tracker-updater.php (modified) (1 diff)
-
inc/class-time-tracker.php (modified) (9 diffs)
-
inc/class-tt-hook-after-form-data-saved.php (modified) (3 diffs)
-
inc/class-tt-save-form-input.php (modified) (13 diffs)
-
inc/css/time-tracker.php (modified) (3 diffs)
-
inc/function-tt-utilities.php (modified) (4 diffs)
-
inc/js/filter_time_log.js (modified) (2 diffs)
-
inc/js/get_projects_for_client.js (modified) (2 diffs)
-
inc/js/get_tasks_for_client.js (modified) (2 diffs)
-
inc/js/set_date_picker_default_value.js (modified) (1 diff)
-
inc/js/update_end_timer.js (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
templates/tt-page-template.php (modified) (1 diff)
-
templates/tt-sidebar.php (modified) (1 diff)
-
time-tracker.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
time-tracker/trunk/inc/class-time-tracker-activator-forms.php
r2862272 r2900796 22 22 public static $form_details = array(); 23 23 public static $form_content = array(); 24 public static $mail_meta = array(); 25 public static $mail_2_meta = array(); 26 public static $msg_meta = array(); 27 public static $additional_settings = ""; 28 29 /** 30 * Constructor 31 * 32 */ 33 public function __construct() { 34 //$form_details = self::create_form_details_array(); 35 //self::create_forms(); 24 public static $post_typ = ""; 25 public static $form_class = ""; 26 27 28 /** 29 * Define form details 30 * 31 */ 32 private static function define_forms() { 33 if (self::$post_typ == "") { 34 self::get_post_type(); 35 } 36 if (self::$form_class == "") { 37 self::get_form_class_name(); 38 } 39 if (self::$form_content == array()) { 40 self::create_form_content_array(); 41 } 42 if (self::$form_details == array()) { 43 self::create_form_details_array(); 44 } 36 45 } 37 46 … … 42 51 */ 43 52 public static function setup() { 44 self::create_form_details_array(); 45 self::create_form_content_array(); 46 self::get_mail_meta(); 47 self::get_mail_2_meta(); 48 self::get_msg_meta(); 49 self::get_additional_settings(); 53 self::define_forms(); 50 54 self::create_forms('false'); 51 55 } … … 53 57 54 58 /** 55 * Update Version 59 * Update Version - Check for updates 56 60 * 57 61 */ … … 63 67 64 68 /** 65 * Update Version 69 * Update Version - Force updates 66 70 * 67 71 */ … … 70 74 self::create_forms('true'); 71 75 } 76 77 /** 78 * Get expected form content based on definitions herein and post id, if exists 79 * 80 */ 81 private static function get_expected_form_content($form_index, $post_id = 0) { 82 if ($form_index < count(self::$form_content)) { 83 if (TT_PLUGIN_FORM_TYPE == "CF7") { 84 return self::$form_content[$form_index]; 85 } elseif (TT_PLUGIN_FORM_TYPE == "WPF") { 86 $content = self::$form_class::decode_form_content(self::$form_content[$form_index]); 87 $content["id"] = $post_id; 88 return self::$form_class::encode_form_content($content); 89 } 90 } 91 } 72 92 73 93 … … 79 99 $installed_form = get_post($form_post_id); 80 100 $installed_form_content = $installed_form->post_content; 81 $updated_content = self::$form_content[$i]; 82 //does the content match the current version} 83 if (($installed_form_content != $updated_content) || ($force_update == true)) { 84 $updated_form = array( 85 'ID' => $form_post_id, 86 'post_content' => $updated_content 87 ); 88 $result = wp_update_post($updated_form); 89 $result_meta = update_post_meta($form_post_id, '_form', $updated_content); 90 } 101 self::define_forms(); 102 if (count(self::$form_content) > $i) { 103 $updated_content = self::get_expected_form_content($i, $form_post_id); 104 105 //does the content match the current version} 106 if ((wp_slash($installed_form_content) != $updated_content) || ($force_update == true)) { 107 $updated_form = array( 108 'ID' => $form_post_id, 109 'post_content' => $updated_content 110 ); 111 $result = wp_update_post($updated_form); 112 $result_meta = update_post_meta($form_post_id, '_form', $updated_content); 113 } 114 } 91 115 return $form_post_id; 92 116 } … … 99 123 public static function create_forms($force_update) { 100 124 $i = 0; 101 if (self::$form_details == array() || self::$form_content == array()) { 102 self::setup(); 103 } 104 $number_forms = count(self::$form_details); 105 for ($i==0; $i<$number_forms; $i++) { 125 self::define_forms(); 126 for ($i == 0; $i < count(self::$form_details); $i++) { 106 127 $form_arr = self::get_form_details($i); 107 128 … … 109 130 $form_exists = get_posts(array( 110 131 'title'=> $form_arr['post_title'], 111 'post_type' => 'wpcf7_contact_form'132 'post_type' => $form_arr['post_type'] 112 133 ), ARRAY_A); 134 113 135 //if form does not exist, create it 114 115 136 if (empty($form_exists)) { 116 137 $post_id = wp_insert_post($form_arr); 138 139 //WPForms has the form id embedded in the post content, now that we have the id, update the content json 140 if (TT_PLUGIN_FORM_TYPE == "WPF") { 141 self::$form_class::update_form_id_in_database($form_arr, $post_id); 142 } 143 144 //post meta 117 145 if ($post_id) { 118 add_post_meta($post_id, '_form', self::$form_content[$i]); 119 add_post_meta($post_id, '_mail', self::$mail_meta); 120 add_post_meta($post_id, '_mail_2', self::$mail_2_meta); 121 add_post_meta($post_id, '_messages', self::$msg_meta); 122 add_post_meta($post_id, '_additional_settings', self::$additional_settings); 123 add_post_meta($post_id, '_locale', self::get_user_location() ); 146 self::$form_class::add_form_post_meta($post_id, $i); 124 147 } 125 148 … … 130 153 } 131 154 } 132 133 134 /** 135 * post locale information for post meta 136 * 137 */ 138 public static function get_user_location() { 139 $users_location = ""; 140 $users_location = get_user_locale(); 141 if ($users_location) { 142 return $users_location; 143 } else { 144 return "en_US"; 145 } 146 } 147 148 149 /** 150 * Define arguments for creating form (CF7 post type) 155 156 157 /** 158 * Define arguments for creating form 151 159 * 152 160 */ 153 161 public static function get_form_details($arr_index) { 162 if (self::$post_typ == "") { 163 self::get_post_type(); 164 } 154 165 $arr = array( 155 166 'post_author' => '', … … 160 171 'post_excerpt' => '', 161 172 'post_status' => 'publish', 162 'post_type' => 'wpcf7_contact_form',173 'post_type' => self::$post_typ, 163 174 'page_template' => '', 164 175 'comment_status' => 'closed', … … 184 195 $details = array(); 185 196 $all_details = array(); 186 197 if (self::$form_class == "") { 198 self::get_form_class_name(); 199 } 187 200 //add new client 188 201 $details = array( 189 202 "Title" => "Add New Client", 190 203 "Slug" => "form-add-new-client", 191 "Content" => self:: get_form_content_new_client() . "\r\n" . implode("\r\n", self::$mail_meta) . "\r\n" . implode("\r\n", self::$msg_meta)204 "Content" => self::$form_class::get_form_content_new_client() 192 205 ); 193 206 array_push($all_details, $details); … … 197 210 "Title" => "Add New Project", 198 211 "Slug" => "form-add-new-project", 199 "Content" => self:: get_form_content_new_project() . "\r\n" . implode("\r\n", self::$mail_meta) . "\r\n" . implode("\r\n", self::$msg_meta)212 "Content" => self::$form_class::get_form_content_new_project() 200 213 ); 201 214 array_push($all_details, $details); … … 205 218 "Title" => "Add New Recurring Task", 206 219 "Slug" => "form-add-new-recurring-task", 207 "Content" => self:: get_form_content_new_recurring_task() . "\r\n" . implode("\r\n", self::$mail_meta) . "\r\n" . implode("\r\n", self::$msg_meta)220 "Content" => self::$form_class::get_form_content_new_recurring_task() 208 221 ); 209 222 array_push($all_details, $details); … … 213 226 "Title" => "Add New Task", 214 227 "Slug" => "form-add-new-task", 215 "Content" => self:: get_form_content_new_task() . "\r\n" . implode("\r\n", self::$mail_meta) . "\r\n" . implode("\r\n", self::$msg_meta)228 "Content" => self::$form_class::get_form_content_new_task() 216 229 ); 217 230 array_push($all_details, $details); … … 221 234 "Title" => "Add Time Entry", 222 235 "Slug" => "form-add-time-entry", 223 "Content" => self:: get_form_content_add_time_entry() . "\r\n" . implode("\r\n", self::$mail_meta) . "\r\n" . implode("\r\n", self::$msg_meta)236 "Content" => self::$form_class::get_form_content_add_time_entry() 224 237 ); 225 238 array_push($all_details, $details); … … 229 242 "Title" => "Filter Time", 230 243 "Slug" => "form-filter-time", 231 "Content" => self:: get_form_content_filter_time() . "\r\n" . implode("\r\n", self::$mail_meta) . "\r\n" . implode("\r\n", self::$msg_meta)244 "Content" => self::$form_class::get_form_content_filter_time() 232 245 ); 233 246 array_push($all_details, $details); … … 243 256 */ 244 257 public static function create_form_content_array() { 245 $content = array(); 246 array_push($content, self::get_form_content_new_client()); 247 array_push($content, self::get_form_content_new_project()); 248 array_push($content, self::get_form_content_new_recurring_task()); 249 array_push($content, self::get_form_content_new_task()); 250 array_push($content, self::get_form_content_add_time_entry()); 251 array_push($content, self::get_form_content_filter_time()); 252 self::$form_content = $content; 253 } 254 255 256 257 /** 258 * Create form content - New Client Form 259 * 260 */ 261 public static function get_form_content_new_client() { 262 $html = ""; 263 $html .= self::create_33_33_33_row( 264 "<label> Company (required)</label>[text* company maxlength:100]", 265 "<label> Bill To (required)</label>[bill_to_name bill-to id:bill-to-name-dropdown]", 266 "<label> Billing Rate</label>[number billing-rate min:0 max:99999999999 \"" . tt_get_default_billing_rate() . "\"]" 267 ); 268 $html .= self::create_50_50_row( 269 "<label> Source (required)</label>[client_category client-source id:client-source-dropdown]", 270 "<label> Source Details</label>[client_sub_category client-source-details id:client-source-details-dropdown]" 271 ); 272 $html .= self::create_33_33_33_row( 273 "<label> Contact Name</label>[text contact-name maxlength:100]", 274 "<label> Contact Email </label>[email contact-email maxlength:100]", 275 "<label> Telephone #</label>[text contact-telephone]" 276 ); 277 $html .= "<label> Comments</label>[textarea comments maxlength:1000 x3]"; 278 $html .= "[submit id:add-client-submit \"Submit\"]"; 279 return $html; 280 } 281 282 283 /** 284 * Create form content - New Project 285 * 286 */ 287 public static function get_form_content_new_project() { 288 $html = ""; 289 $html .= "<label> Project Name (required)</label>[text* project-name maxlength:100]"; 290 $html .= self::create_50_50_row( 291 "<label> Client (required)</label>[client_name client-name]", 292 "<label> Category</label>[work_category project-category id:project-category-dropdown]" 293 ); 294 $html .= self::create_50_50_row( 295 "<label>Time Estimate (hrs)</label>[number time-estimate]", 296 "<label>Due Date (required)</label>[date* due-date]" 297 ); 298 $html .= "<label> Details</label>[textarea project-details maxlength:500 x3]"; 299 $html .= "[submit id:add-project-submit \"Submit\"]"; 300 return $html; 301 } 302 303 304 /** 305 * Create form content - New Recurring Task 306 * 307 */ 308 public static function get_form_content_new_recurring_task() { 309 $html = ""; 310 $html .= self::create_66_33_row( 311 "<label> Task Name (required)</label>[textarea* task-name 20x1 maxlength:1500]", 312 "Recurring Frequency (required)[select* recur-freq use_label_element \"Monthly\" \"Weekly\"]" 313 ); 314 $html .= self::create_50_50_row( 315 "<label> Client (required)</label>[client_name client-name]", 316 "<label> Project</label>[project_name project-name id:project-dropdown]" 317 ); 318 $html .= self::create_33_33_33_row( 319 "<label> Category</label>[work_category task-category id:task-category-dropdown]", 320 "<label> Time Estimate in Hours (required)</label>[text* time-estimate]", 321 "<label> End Repeat</label>[date end-repeat]" 322 ); 323 $html .= "<label> Task Notes</label>[textarea task-desc x3]"; 324 $html .= "[submit id:add-task-submit \"Send\"]"; 325 return $html; 326 } 327 328 329 /** 330 * Create form content - New Task 331 * 332 */ 333 public static function get_form_content_new_task() { 334 $html = ""; 335 $html .= self::create_66_33_row( 336 "<label> Task Description (required)</label>[textarea* task-description 20x1 maxlength:500]", 337 "<label> Due Date</label>[date due-date \"today\"]" 338 ); 339 $html .= self::create_50_50_row( 340 "<label> Client (required)</label>[client_name client-name]", 341 "<label> Project</label>[project_name project-name id:project-dropdown]" 342 ); 343 $html .= self::create_50_50_row( 344 "<label> Category</label>[work_category task-category id:task-category-dropdown]", 345 "<label> Time Estimate (hrs)</label>[text time-estimate]" 346 ); 347 $html .= "<label> Notes </label>[textarea notes x3]"; 348 $html .= "[hidden what-next default:\"SaveTask\"]<input type=\"submit\" name=\"submit-save\" class=\"tt-button tt-form-button tt-inline-button\" value=\"SaveTask\"><input type=\"submit\" name=\"submit-start\" class=\"tt-button tt-form-button tt-inline-button\" value=\"StartWorking\" onclick=\"save_new_task_and_start_timer()\">"; 349 return $html; 350 } 351 352 353 /** 354 * Create form content - New Time Entry 355 * 356 */ 357 public static function get_form_content_add_time_entry() { 358 $html = ""; 359 $html .= self::create_50_50_row( 360 "<label> Client (required)</label>[client_name client-name default:get]", 361 "<label> Ticket (required)</label>[task_name task-name default:get id:task-dropdown]" 362 ); 363 $html .= self::create_33_33_33_row( 364 "<label> Start Time (required)</label>[datetime start-time id:start-time]", 365 "<label> End Time (required)</label>[datetime end-time id:end-time]", 366 "<label> New Task Status</label>[select new-task-status id:new-task-status include_blank \"In Process\" \"Not Started\" \"Ongoing\" \"Waiting Client\" \"Complete\" \"Canceled\"]" 367 ); 368 $html .= "<label> Notes (required)</label>[textarea* time-notes maxlength:1999 x7]"; 369 $html .= self::create_33_33_33_row( 370 "<label> Invoiced?</label> [text invoiced id:invoiced]", 371 "<label> Invoice #</label> [text invoice-number id:invoice-number]", 372 "<label> Invoiced Time</label> [text invoiced-time id:invoiced-time]" 373 ); 374 $html .= self::create_50_50_row( 375 "<label> Invoice Notes</label> [text invoice-notes id:invoice-notes]", 376 "<label> Follow Up (Create New Task)</label>[text follow-up maxlength:500]" 377 ); 378 $html .= "[submit id:add-time-submit \"Send\"]"; 379 return $html; 380 } 381 382 383 /** 384 * Create form content - Time Entry Filter 385 * 386 */ 387 public static function get_form_content_filter_time() { 388 $html = ""; 389 $html .= self::create_33_66_row( 390 "<label> First Date</label>[date first-date id:first-date default:get]", 391 "<label> Client</label>[client_name client-name id:client-name default:get]" 392 ); 393 $html .= self::create_33_66_row( 394 "<label> Last Date</label>[date last-date id:last-date default:get]", 395 "<label> Project</label>[project_name project-name id:project-name default:get]" 396 ); 397 $html .= self::create_33_66_row( 398 "<label> Ticket</label>[task_name task-name id:task-name default:get]", 399 "<label> Notes </label>[text notes id:time-notes default:get]" 400 ); 401 $html .= self::create_100_row ( 402 "[hidden form-type default:\"filter\"][submit id:filter-time-submit \"Filter Time Entries\"]" 403 ); 404 return $html; 405 } 406 407 408 /** 409 * Layout Classes and Divs 410 * 411 */ 412 private static function create_33_33_33_row($first, $second, $third) { 413 $out = self::start_form_row(); 414 $out .= self::start_col_one_third("left") . $first . self::end_form_column(); 415 $out .= self::start_col_one_third("middle") . $second . self::end_form_column(); 416 $out .= self::start_col_one_third("right") . $third . self::end_form_column(); 417 $out .= self::end_form_row(); 418 return $out; 419 } 420 421 422 /** 423 * Layout Classes and Divs 424 * 425 */ 426 private static function create_100_row($first) { 427 $out = self::start_form_row() . $first . self::end_form_row(); 428 return $out; 429 } 430 431 432 /** 433 * Layout Classes and Divs 434 * 435 */ 436 private static function create_33_66_row($first, $second) { 437 $out = self::start_form_row(); 438 $out .= self::start_col_one_third("left") . $first . self::end_form_column(); 439 $out .= self::start_col_two_thirds("right") . $second . self::end_form_column(); 440 $out .= self::end_form_row(); 441 return $out; 442 } 443 444 445 /** 446 * Layout Classes and Divs 447 * 448 */ 449 private static function create_66_33_row($first, $second) { 450 $out = self::start_form_row(); 451 $out .= self::start_col_two_thirds("left") . $first . self::end_form_column(); 452 $out .= self::start_col_one_third("right") . $second . self::end_form_column(); 453 $out .= self::end_form_row(); 454 return $out; 455 } 456 457 458 /** 459 * Layout Classes and Divs 460 * 461 */ 462 private static function create_50_50_row($first, $second) { 463 $out = self::start_form_row(); 464 $out .= self::start_col_half("left") . $first . self::end_form_column(); 465 $out .= self::start_col_half("right") . $second . self::end_form_column(); 466 $out .= self::end_form_row(); 467 return $out; 468 } 469 470 471 472 /** 473 * Layout Classes and Divs 474 * 475 */ 476 private static function start_form_row() { 477 return "<div class=\"tt-form-row\">"; 478 } 479 480 481 /** 482 * Layout Classes and Divs 483 * 484 */ 485 private static function end_form_row() { 486 return "</div>"; 487 } 488 489 490 /** 491 * Layout Classes and Divs 492 * 493 */ 494 private static function end_form_column() { 495 return "</div>"; 496 } 497 498 499 /** 500 * Start Half width column 501 * 502 */ 503 private static function start_col_half($side) { 504 return "<div class=\"tt-form-element tt-one-half tt-col-" . $side . "\">"; 505 } 506 507 508 /** 509 * Start one third width column 510 * 511 */ 512 private static function start_col_one_third($side) { 513 return "<div class=\"tt-form-element tt-one-third tt-col-" . $side . "\">"; 514 } 515 516 517 /** 518 * Start two thirds width column 519 * 520 */ 521 private static function start_col_two_thirds($side) { 522 return "<div class=\"tt-form-element tt-two-thirds tt-col-" . $side . "\">"; 523 } 524 525 /** 526 * Get Additional Settings 527 * 528 */ 529 public static function get_additional_settings() { 530 $settings = "skip_mail: on"; 531 self::$additional_settings = $settings; 532 } 533 534 535 /** 536 * Get Mail Meta 537 * 538 */ 539 public static function get_mail_meta() { 540 $body = ""; 541 $body = "From: [your-name] <[your-email]>\r\n"; 542 $body .= "Subject: [your-subject]\r\n"; 543 $body .= "\r\n"; 544 $body .= "Message Body:\r\n"; 545 $body .= "[your-message]\r\n"; 546 $body .= "\r\n"; 547 $body .= "-- \r\n"; 548 $body .= "This e-mail was sent from a contact form on " . tt_get_site_name() . " (" . tt_get_site_url() . ")"; 549 550 $mail = array(); 551 $mail["active"] = true; 552 $mail["subject"] = tt_get_site_name() . " \"[your-subject]\""; 553 $mail["sender"] = tt_get_site_name() . " <" . tt_get_wordpress_email() . ">"; 554 $mail["recipient"] = tt_get_site_admin_email(); 555 $mail["body"] = $body; 556 $mail["additional headers"] = "Reply-To: " . tt_get_site_admin_email() . "\r\n"; 557 $mail["attachments"] = "\r\n"; 558 $mail["use_html"] = false; 559 $mail["exclude_blank"] = false; 560 self::$mail_meta = $mail; 561 } 562 563 564 /** 565 * Get Mail 2 Meta 566 * 567 */ 568 public static function get_mail_2_meta() { 569 $mail2 = array(); 570 $mail2 = self::$mail_meta; 571 $mail2["active"] = false; 572 self::$mail_2_meta = $mail2; 573 } 574 575 576 /** 577 * Get Message Meta 578 * 579 */ 580 public static function get_msg_meta() { 581 $msg = array(); 582 $msg["mail_sent_ok"] = "Form submitted successfully."; 583 $msg["mail_sent_ng"] = "There was an error submitting this form. Please try again later."; 584 $msg["validation_error"] = "One or more fields have an error. Please check and try again."; 585 $msg["spam"] = "There was an error trying to send your message. Please try again later."; 586 $msg["accept_terms"] = "You must accept the terms and conditions before sending your message."; 587 $msg["invalid_required"] = "Please verify all required fields have been filled in."; 588 $msg["invalid_too_long"] = "The field is too long."; 589 $msg["invalid_too_short"] = "The field is too short."; 590 $msg["invalid_date"] = "The date format is incorrect."; 591 $msg["date_too_early"] = "The date is before the earliest one allowed."; 592 $msg["date_too_late"] = "The date is after the latest one allowed."; 593 $msg["upload_failed"] = "There was an unknown error uploading the file."; 594 $msg["upload_file_type_invalid"] = "You are not allowed to upload files of this type."; 595 $msg["upload_file_too_large"] = "The file is too big."; 596 $msg["upload_failed_php_error"] = "There was an error uploading the file."; 597 $msg["invalid_number"] = "The number format is invalid."; 598 $msg["number_too_small"] = "The number is smaller than the minimum allowed."; 599 $msg["number_too_large"] = "The number is larger than the maximum allowed."; 600 $msg["quiz_answer_not_correct"] = "The answer to the quiz is incorrect."; 601 $msg["invalid_email"] = "The e-mail address entered is invalid."; 602 $msg["invalid_url"] = "The URL is invalid."; 603 $msg["invalid_tel"] = "The telephone number is invalid."; 604 self::$msg_meta = $msg; 258 if (self::$form_class == "") { 259 self::get_form_class_name(); 260 } 261 self::$form_class::create_form_content_array(); 262 self::$form_content = self::$form_class::$form_content; 263 } 264 265 266 /** 267 * Get Post Type for WP-Posts Database Setting 268 * 269 */ 270 public static function get_post_type() { 271 if (TT_PLUGIN_FORM_TYPE == "CF7") { 272 self::$post_typ = "wpcf7_contact_form"; 273 } 274 elseif (TT_PLUGIN_FORM_TYPE == "WPF") { 275 self::$post_typ = "wpforms"; 276 } 277 return self::$post_typ; 278 } 279 280 281 /** 282 * Get Form Class Namespace and Class Name Based on Form Plugin Being Used 283 * 284 */ 285 private static function get_form_class_name() { 286 self::$form_class = __NAMESPACE__ . "\\" . TT_PLUGIN_FORM_TYPE . "\\" . "Time_Tracker_Activator_Forms_" . TT_PLUGIN_FORM_TYPE; 605 287 } 606 288 -
time-tracker/trunk/inc/class-time-tracker-activator-pages.php
r2862272 r2900796 100 100 101 101 $updated_content = self::get_page_details($i)['post_content']; 102 103 102 //does the content match the current version 104 103 if ($installed_page_content != $updated_content) { … … 183 182 self::$page_details = $details_all; 184 183 } 184 185 186 /** 187 * Get shortcode for form 188 * 189 */ 190 private static function get_form_shortcode($nm) { 191 if (TT_PLUGIN_FORM_TYPE == "CF7") { 192 return "[contact-form-7 id=\"" . tt_get_form_id($nm) . "\" title=\"" . $nm . "\" html_class=\"tt-form\"]"; 193 } 194 elseif (TT_PLUGIN_FORM_TYPE == "WPF") { 195 return "[wpforms id=\"" . tt_get_form_id($nm) . "\"]"; 196 } 197 else { 198 return "Error: Either Contact Form 7 or WPForms must be activated to use the Time Tracker plugin."; 199 } 200 } 185 201 186 202 … … 210 226 "Parent" => $parent, 211 227 "Slug" => "new-client", 212 "Content" => "[contact-form-7 id=\"" . tt_get_form_id("Add New Client") . "\" title=\"Add New Client\" html_class=\"tt-form\"]", 228 //"Content" => "[contact-form-7 id=\"" . tt_get_form_id("Add New Client") . "\" title=\"Add New Client\" html_class=\"tt-form\"]", 229 "Content" => self::get_form_shortcode("Add New Client"), 213 230 "Paginate" => array( 214 231 "Flag" => false … … 222 239 "Parent" => $parent, 223 240 "Slug" => "new-project", 224 "Content" => "[contact-form-7 id=\"" . tt_get_form_id("Add New Project") . "\" title=\"Add New Project\" html_class=\"tt-form\"]", 241 //"Content" => "[contact-form-7 id=\"" . tt_get_form_id("Add New Project") . "\" title=\"Add New Project\" html_class=\"tt-form\"]", 242 "Content" => self::get_form_shortcode("Add New Project"), 225 243 "Paginate" => array( 226 244 "Flag" => false … … 234 252 "Parent" => $parent, 235 253 "Slug" => "new-recurring-task", 236 "Content" => "[contact-form-7 id=\"" . tt_get_form_id("Add New Recurring Task") . "\" title=\"Add New Recurring Task\" html_class=\"tt-form\"]", 254 //"Content" => "[contact-form-7 id=\"" . tt_get_form_id("Add New Recurring Task") . "\" title=\"Add New Recurring Task\" html_class=\"tt-form\"]", 255 "Content" => self::get_form_shortcode("Add New Recurring Task"), 237 256 "Paginate" => array( 238 257 "Flag" => false … … 246 265 "Parent" => $parent, 247 266 "Slug" => "new-task", 248 "Content" => "[contact-form-7 id=\"" . tt_get_form_id("Add New Task") . "\" title=\"Add New Task\" html_class=\"tt-form\"]", 267 //"Content" => "[contact-form-7 id=\"" . tt_get_form_id("Add New Task") . "\" title=\"Add New Task\" html_class=\"tt-form\"]", 268 "Content" => self::get_form_shortcode("Add New Task"), 249 269 "Paginate" => array( 250 270 "Flag" => false … … 258 278 "Parent" => $parent, 259 279 "Slug" => "new-time-entry", 260 "Content" => "[contact-form-7 id=\"" . tt_get_form_id("Add Time Entry") . "\" title=\"Add Time Entry\" html_class=\"tt-form\"]", 280 //"Content" => "[contact-form-7 id=\"" . tt_get_form_id("Add Time Entry") . "\" title=\"Add Time Entry\" html_class=\"tt-form\"]", 281 "Content" => self::get_form_shortcode("Add Time Entry"), 261 282 "Paginate" => array( 262 283 "Flag" => false … … 346 367 "Parent" => $parent, 347 368 "Slug" => "time-log", 348 "Content" => "<div class=\"tt-accordion\">Search</div><div class=\"tt-accordion-panel\">[contact-form-7 id=\"" . tt_get_form_id("Filter Time") . "\" title=\"Filter Time\" html_class=\"filter-time-form\" html_class=\"tt-form\"]</div>[tt_time_log_table type=\'summary\']<br/>[tt_year_summary]<h3>Time Details</h3>[tt_time_log_table type=\'detail\']", 349 "Paginate" => array( 369 //"Content" => "<div class=\"tt-accordion\">Search</div><div class=\"tt-accordion-panel\">[contact-form-7 id=\"" . tt_get_form_id("Filter Time") . "\" title=\"Filter Time\" html_class=\"filter-time-form\" html_class=\"tt-form\"]</div>[tt_time_log_table type=\'summary\']<br/>[tt_year_summary]<h3>Time Details</h3>[tt_time_log_table type=\'detail\']", 370 "Content" => "<div class=\"tt-accordion\">Search</div><div class=\"tt-accordion-panel\">" . self::get_form_shortcode("Filter Time") . "</div>[tt_time_log_table type=\'summary\']<br/>[tt_year_summary]<h3>Time Details</h3>[tt_time_log_table type=\'detail\']", 371 "Paginate" => array( 350 372 "Flag" => true, 351 373 "RecordsPerPage" => 100, -
time-tracker/trunk/inc/class-time-tracker-activator.php
r2870230 r2900796 25 25 class Time_Tracker_Activator { 26 26 27 private static $cf7_active = false;28 27 private static $default_client = null; 29 28 private static $default_task = null; 30 29 31 32 30 public static function activate() { 33 31 self::define_plugin_variables(); 34 self::cf7_plugin_activated(); 35 if (self::$cf7_active) { 36 include_once(TT_PLUGIN_DIR_INC . 'function-tt-cron-recurring-tasks.php'); 37 require_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-activator-tables.php'); 38 require_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-activator-forms.php'); 39 require_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-activator-pages.php'); 40 Time_Tracker_Activator_Tables::setup(); 41 Time_Tracker_Activator_Forms::setup(); 42 Time_Tracker_Activator_Pages::setup(); 43 self::add_default_client(); 44 self::add_default_task(); 45 self::set_initial_database_options(); 32 if (TT_PLUGIN_FORM_TYPE == "CF7") { 33 self::setup(); 34 } elseif (TT_PLUGIN_FORM_TYPE == "WPF") { 35 /**?> 36 <script type="text/javascript"> 37 window.alert('Time Tracker is not yet compatible with WPForms. Please install the Contact Form 7 plugin before activating Time Tracker.'); 38 </script> 39 <?php 40 **/ 41 self::setup(); 46 42 } else { 47 43 ?> … … 64 60 65 61 66 private static function cf7_plugin_activated() { 67 if (class_exists('WPCF7')) { 68 self::$cf7_active = true; 69 } 62 private static function setup() { 63 include_once(TT_PLUGIN_DIR_INC . 'function-tt-cron-recurring-tasks.php'); 64 require_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-activator-tables.php'); 65 require_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-activator-forms.php'); 66 require_once(TT_PLUGIN_DIR_INC . TT_PLUGIN_FORM_TYPE . '/class-time-tracker-activator-forms-' . strtolower(TT_PLUGIN_FORM_TYPE) . '.php'); 67 require_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-activator-pages.php'); 68 Time_Tracker_Activator_Tables::setup(); 69 Time_Tracker_Activator_Forms::setup(); 70 Time_Tracker_Activator_Pages::setup(); 71 self::add_default_client(); 72 self::add_default_task(); 73 self::set_initial_database_options(); 70 74 } 71 75 -
time-tracker/trunk/inc/class-time-tracker-updater.php
r2866551 r2900796 155 155 private function tt_update_forms($force_update = false) { 156 156 require_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-activator-forms.php'); 157 require_once(TT_PLUGIN_DIR_INC . TT_PLUGIN_FORM_TYPE . '/class-time-tracker-activator-forms-' . strtolower(TT_PLUGIN_FORM_TYPE) . '.php'); 157 158 if ($force_update) { 158 159 $tt_forms = Time_Tracker_Activator_Forms::force_form_updates(); -
time-tracker/trunk/inc/class-time-tracker.php
r2862272 r2900796 36 36 self::$instance->setup_constants(); 37 37 self::$instance->load_dependencies(); 38 self::$instance->load_form_dependencies(); 38 39 self::$instance->add_scripts(); 39 40 self::$instance->add_styles(); … … 53 54 54 55 55 /**56 * Log Install Time57 *58 **/56 /** 57 * Log Install Time 58 * 59 **/ 59 60 private function log_plugin_installation() { 60 61 if (! get_option('time_tracker_install_time')) { … … 64 65 65 66 66 /**67 /** 67 68 * Check Plugin Version 68 69 * 69 */70 **/ 70 71 private function check_plugin_version() { 71 72 $installed_version = get_option('time_tracker_version'); 72 if ($installed_version != TIME_TRACKER_VERSION) { 73 include_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-updater.php'); 74 $updater = New Time_Tracker_Updater; 75 $new_version = $updater->tt_update_from($installed_version); 73 if ($installed_version) { 74 //updates 75 if ($installed_version != TIME_TRACKER_VERSION) { 76 include_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-updater.php'); 77 $updater = New Time_Tracker_Updater; 78 $new_version = $updater->tt_update_from($installed_version); 79 } 80 } else { 81 //new installations 82 add_option('time_tracker_version', TIME_TRACKER_VERSION); 76 83 } 77 84 } … … 94 101 define('TT_PLUGIN_WEB_DIR_ADMIN', plugin_dir_url(__FILE__) . '../admin/'); 95 102 define('TT_PLUGIN_WEB_DIR_INC', plugin_dir_url(__FILE__)); 103 } 104 105 106 /** 107 * Form Plugin Dependent Items Init 108 * 109 */ 110 private function load_form_dependencies() { 111 //load time tracker functions based on form plugin being used 112 if (TT_PLUGIN_FORM_TYPE == "CF7") { 113 self::$instance->load_dependencies_cf7(); 114 } 115 elseif (TT_PLUGIN_FORM_TYPE == "WPF") { 116 self::$instance->load_dependencies_wpf(); 117 } 96 118 } 97 119 … … 106 128 include_once(TT_PLUGIN_DIR_INC . 'function-tt-utilities.php'); 107 129 include_once(TT_PLUGIN_DIR_INC . 'function-tt-get-IDs-from-common-names.php'); 108 include_once(TT_PLUGIN_DIR_INC . 'function-tt-custom-cf7-field-datetime.php');109 include_once(TT_PLUGIN_DIR_INC . 'function-tt-custom-cf7-field-task-dropdown.php');110 include_once(TT_PLUGIN_DIR_INC . 'function-tt-custom-cf7-field-project-dropdown.php');111 include_once(TT_PLUGIN_DIR_INC . 'function-tt-custom-cf7-field-client-dropdown.php');112 include_once(TT_PLUGIN_DIR_INC . 'function-tt-custom-cf7-field-categories-from-settings.php');113 130 include_once(TT_PLUGIN_DIR_INC . 'function-tt-clear-sql-error.php'); 114 131 include_once(TT_PLUGIN_DIR_INC . 'function-tt-cron-recurring-tasks.php'); … … 119 136 include_once(TT_PLUGIN_DIR_INC . 'function-tt-load-dynamic-stylesheets.php'); 120 137 include_once(TT_PLUGIN_DIR_INC . 'function-tt-get-new-task-details.php'); 121 include_once(TT_PLUGIN_DIR_INC . 'function-tt-recaptcha.php');122 138 123 139 //CLASSES … … 148 164 //CONTACT FORM 7 HOOKS 149 165 include_once(TT_PLUGIN_DIR_INC . 'class-tt-hook-after-form-data-saved.php'); 150 include_once(TT_PLUGIN_DIR_INC . 'class-tt-hook-save-form-data.php');151 166 152 167 //SHORTCODES … … 163 178 require_once(TT_PLUGIN_DIR_INC . 'class-tt-shortcode-delete-confirmation-content.php'); 164 179 require_once(TT_PLUGIN_DIR_ADMIN . 'class-tt-shortcode-error-alert.php'); 165 166 180 } 167 181 182 /** 183 * Load Dependencies - CF7 184 * 185 */ 186 public function load_dependencies_cf7() { 187 include_once(TT_PLUGIN_DIR_INC . 'CF7/function-tt-custom-cf7-field-datetime.php'); 188 include_once(TT_PLUGIN_DIR_INC . 'CF7/function-tt-custom-cf7-field-task-dropdown.php'); 189 include_once(TT_PLUGIN_DIR_INC . 'CF7/function-tt-custom-cf7-field-project-dropdown.php'); 190 include_once(TT_PLUGIN_DIR_INC . 'CF7/function-tt-custom-cf7-field-client-dropdown.php'); 191 include_once(TT_PLUGIN_DIR_INC . 'CF7/function-tt-custom-cf7-field-categories-from-settings.php'); 192 include_once(TT_PLUGIN_DIR_INC . 'CF7/function-tt-recaptcha-cf7.php'); 193 194 //CONTACT FORM 7 HOOKS 195 include_once(TT_PLUGIN_DIR_INC . 'CF7/class-tt-hook-save-form-data-cf7.php'); 196 } 197 198 199 /** 200 * Load Dependencies - WPForms 201 * 202 */ 203 public function load_dependencies_wpf() { 204 include_once(TT_PLUGIN_DIR_INC . 'WPF/class-time-tracker-activator-forms-wpf.php'); 205 include_once(TT_PLUGIN_DIR_INC . 'WPF/class-time-tracker-wpf-select-fields-dynamic-options.php'); 206 include_once(TT_PLUGIN_DIR_INC . 'WPF/class-time-tracker-wpf-fields-add-properties.php'); 207 208 //WPFORMS HOOKS 209 include_once(TT_PLUGIN_DIR_INC . 'WPF/class-tt-hook-save-form-data-wpf.php'); 210 } 168 211 169 212 /** … … 186 229 wp_enqueue_script( 'tt_accordion', TT_PLUGIN_WEB_DIR_INC . 'js/tt_accordion.js', array(), null, true ); 187 230 188 //wp_enqueue_script( 'tt_watch_for_client_change_project', TT_PLUGIN_WEB_DIR_INC . 'js/watch_for_client_change_to_update_project.js', array(), null, true);189 231 wp_enqueue_script( 'tt_update_project_dropdown', TT_PLUGIN_WEB_DIR_INC . 'js/get_projects_for_client.js', array('jquery'), null, true); 190 191 //wp_enqueue_script( 'tt_watch_for_client_change_task', TT_PLUGIN_WEB_DIR_INC . 'js/watch_for_client_change_to_update_task.js', array(), null, true);192 232 wp_enqueue_script( 'tt_update_task_dropdown', TT_PLUGIN_WEB_DIR_INC . 'js/get_tasks_for_client.js', array('jquery'), null, true); 193 233 -
time-tracker/trunk/inc/class-tt-hook-after-form-data-saved.php
r2862272 r2900796 4 4 * 5 5 * Action to happen after form data saved to database (if necessary) 6 * Either go back to TT homepage or stay on same page and filter data if it's a filter form 6 * Either: 7 * - go back to TT homepage 8 * - stay on same page and filter data (if it's a filter form) 9 * - go to time entry form to start tracking time (if 'start working' selected) 7 10 * 8 11 * @since 1.0 … … 33 36 */ 34 37 public function _construct() { 35 36 38 } 37 39 … … 42 44 */ 43 45 public function after_save() { 44 //wp_enqueue_script( 'start_timer_for_task', TT_PLUGIN_WEB_DIR_INC . 'js/start_timer_for_task.js', array(), null, true); 45 //add_action('wp_enqueue_scripts', array($this,'time_tracker_scripts')); 46 ?> 47 <script type='text/javascript'> 48 49 document.addEventListener('DOMContentLoaded', function () { //make sure doc is done loading before looking for element 46 if (TT_PLUGIN_FORM_TYPE == "WPF") { 47 ?> 48 <script type='text/javascript'> 49 document.addEventListener('DOMContentLoaded', function () { 50 jQuery(document).find("form[id^='wpforms-form']").each(function(i, form) { 51 if (window.location.pathname.includes('time-tracker')) { 52 53 var redirect = function() { location = <?php $home = "'" . TT_HOME . "'"; echo $home; ?>; }; 54 var submitandwork = function() { tt_start_timer_for_new_task(); }; 55 var filtertime = function(e) { tt_filter_time_log(e); }; 56 57 jQuery(form).on('wpformsAjaxSubmitSuccess', redirect); 58 jQuery(form).find('button').each(function(i, btn) { 59 if (btn.name == 'wpforms[submit]' && btn.innerHTML == 'Search') { 60 jQuery(form).off('wpformsAjaxSubmitSuccess', redirect); 61 jQuery(form).on('wpformsAjaxSubmitSuccess', filtertime); 62 } else { 63 if (btn.name == 'wpforms[submit]' && btn.innerHTML == 'Start Working') { 64 jQuery(btn).on('click', function() { 65 jQuery(form).off('wpformsAjaxSubmitSuccess', redirect); 66 jQuery(form).on('wpformsAjaxSubmitSuccess', submitandwork); 67 }) 68 } 69 } 70 }); 71 72 }; 73 }); 74 }, false); 50 75 51 document.addEventListener( 'wpcf7mailsent', function (event) { 76 </script> 77 <?php 78 79 } elseif (TT_PLUGIN_FORM_TYPE == "CF7") { 80 ?> 81 <script type='text/javascript'> 82 83 document.addEventListener('DOMContentLoaded', function () { 52 84 53 //console.log(event); 54 var str = window.location.pathname; 55 //var tthome = document.location.origin + '/time-tracker/'; 56 var formtype = ""; 57 var startworking = false; 58 var client = ""; 59 var taskdesc = ""; 85 if (window.location.pathname.includes('time-tracker')) { 60 86 61 for (var i=0; i < event.detail.inputs.length; i++) { 62 if (event.detail.inputs[i].name == 'form-type') { 63 formtype = event.detail.inputs[i].value; 64 } else { 65 if ( (event.detail.inputs[i].name == 'what-next') && (event.detail.inputs[i].value == 'StartWorking') ) { 66 startworking = true; 67 } else { 68 if (event.detail.inputs[i].name == 'client-name') { 69 client = event.detail.inputs[i].value; 87 document.addEventListener( 'wpcf7mailsent', function (event) { 88 89 var formtype = ""; 90 var startworking = false; 91 //var client = ""; 92 //var taskdesc = ""; 93 94 for (var i=0; i < event.detail.inputs.length; i++) { 95 if (event.detail.inputs[i].name == 'form-type') { 96 formtype = event.detail.inputs[i].value; 70 97 } else { 71 if (event.detail.inputs[i].name == 'task-description') { 72 taskdesc = event.detail.inputs[i].value; 98 if ( (event.detail.inputs[i].name == 'what-next') && (event.detail.inputs[i].value == 'StartWorking') ) { 99 startworking = true; 100 //} else { 101 //if (event.detail.inputs[i].name == 'client-name') { 102 // client = event.detail.inputs[i].value; 103 //} else { 104 // if (event.detail.inputs[i].name == 'task-description') { 105 // taskdesc = event.detail.inputs[i].value; 106 // } 107 //} 73 108 } 74 109 } 75 110 } 76 }77 }78 111 79 //if we're filtering data 80 if (formtype == 'filter') { 81 tt_filter_time_log(event); 112 if (formtype == 'filter') { 113 tt_filter_time_log(event); 114 115 } else { 116 if (startworking) { 117 tt_start_timer_for_new_task(); 118 } else { 119 location = <?php $home = "'" . TT_HOME . "'"; echo $home; ?>; 120 } 121 } 82 122 83 //we added a new task and want to start working 84 } else { 85 if (startworking) { 86 tt_start_timer_for_new_task(); 87 } else { 88 //if it's a time tracker form submission, go back to tt homepage after submit 89 if (str.includes('time-tracker')) { 90 location = <?php $home = "'" . TT_HOME . "'"; echo $home; ?>; 91 } 92 } 93 } 123 }, false ); //end wpcf7submit event listener 124 125 }; //if on tt page 94 126 95 }, false ); //end wpcf7submit event listener 96 97 }, false ); //end domcontentloaded event listener 98 </script> 99 <?php 100 } //after save function 101 127 }, false ); //end domcontentloaded event listener 128 </script> 129 <?php 130 } //if wpcf7 131 } //after save function 102 132 } //close class 103 133 } //if class does not exist 104 134 105 135 $aftersave = new Time_Tracker_After_Form_Data_Saved(); 106 107 136 add_action( 'wp_footer', array($aftersave, 'after_save') ); -
time-tracker/trunk/inc/class-tt-save-form-input.php
r2870230 r2900796 32 32 * 33 33 */ 34 private $data;34 //private $data; 35 35 private $form_post_id; 36 private $original_submission; 36 37 private $result; 37 38 private $client_id; … … 44 45 * 45 46 */ 46 public function __construct($ raw_data, $id) {47 public function __construct($cleaned_data, $id) { 47 48 //removed $form added insertid 48 49 $this->form_post_id = $id; 49 $data = $this->clean_data($raw_data); 50 //$data = $this->clean_data($raw_data); 51 $data = $cleaned_data; 52 50 53 $this->original_submission = $this->serialize_data($data); 51 54 $this->client_id = $this->get_client_id($data); … … 55 58 /*** Add new task ***/ 56 59 if ( $this->form_post_id == tt_get_form_id('Add New Task') ) { 57 $this->save_new_task($data,$this->client_id,$this->project_id,$this->task_id,$this->original_submission); 58 } 60 $this->save_new_task($data, $this->client_id, $this->project_id, $this->task_id, $this->original_submission); 59 61 60 62 /*** Add new project ***/ 61 if ( $this->form_post_id == tt_get_form_id('Add New Project') ) { 62 $this->save_new_project($data,$this->client_id,$this->original_submission); 63 } 63 } elseif ( $this->form_post_id == tt_get_form_id('Add New Project') ) { 64 $this->save_new_project($data, $this->client_id, $this->original_submission); 64 65 65 66 /*** Add new client ***/ 66 if ( $this->form_post_id == tt_get_form_id('Add New Client') ) { 67 $this->save_new_client($data,$this->original_submission); 68 } 67 } elseif ( $this->form_post_id == tt_get_form_id('Add New Client') ) { 68 $this->save_new_client($data, $this->original_submission); 69 69 70 70 /*** Add new recurring task ***/ 71 if ( $this->form_post_id == tt_get_form_id('Add New Recurring Task') ) { 72 $this->save_new_recurring_task($data,$this->client_id,$this->project_id,$this->original_submission); 73 } 71 } elseif ( $this->form_post_id == tt_get_form_id('Add New Recurring Task') ) { 72 $this->save_new_recurring_task($data, $this->client_id, $this->project_id, $this->original_submission); 74 73 75 74 /*** Add new time entry ***/ 76 if ( $this->form_post_id == tt_get_form_id('Add Time Entry') ) {75 } elseif ( $this->form_post_id == tt_get_form_id('Add Time Entry') ) { 77 76 $this->save_new_time_entry($data); 78 77 … … 88 87 } 89 88 } 90 91 92 /**93 * Sanitize data94 *95 */96 private function clean_data($raw_data) {97 $clean_data = array();98 foreach ($raw_data as $key => $data) {99 if (is_array($data)) {100 //$clean_data[$key] = filter_var(htmlspecialchars_decode($data[0], ENT_NOQUOTES), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);101 //$raw = $data[0];102 //$clean_data[$key] = htmlspecialchars_decode(filter_var($raw, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES), ENT_NO_QUOTES);103 $clean_data[$key] = filter_var($data[0], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);104 } else {105 //$clean_data[$key] = filter_var(htmlspecialchars_decode($data, ENT_NOQUOTES), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);106 //$clean_data[$key] = htmlspecialchars_decode(filter_var($data, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES), ENT_NOQUOTES);107 $clean_data[$key] = filter_var($data, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);108 }109 }110 return $clean_data;111 }112 89 113 90 … … 132 109 //Add New Record to Database 133 110 //wpdb class prepares this so it doesn't need to be SQL escaped 134 if ( ($data['time-estimate'] == null) or ($data['time-estimate'] == "") ) { 135 $time_est = 0; 136 } else { 137 $time_est = tt_convert_fraction_to_time($data['time-estimate']); 138 } 111 foreach ($data as $key => $val) { 112 //supports task-category and category 113 if (strpos(strtolower($key), "category") !== false) { 114 $cat = $val; 115 } 116 } 117 139 118 $wpdb->insert( $table_name, array( 140 119 'TDescription' => $data['task-description'], 141 120 'ClientID' => $this->client_id, 142 121 'ProjectID' => $this->project_id, 143 'TCategory' => $ data['task-category'],122 'TCategory' => $cat, 144 123 'TStatus' => "New", 145 'TTimeEstimate' => $time_est, 146 'TDueDate' => $data['due-date'], 124 'TTimeEstimate' => $this->get_time_estimate($data), 147 125 'TDateAdded' => date('Y-m-d H:i:s'), 126 'TDueDate' => $this->reformat_date($data, "due-date"), 148 127 'TNotes' => $data['notes'], 149 128 'TSubmission' => $this->original_submission … … 163 142 //Add New Record to Database 164 143 //wpdb class prepares this so it doesn't need to be SQL escaped 165 if ( ($data['time-estimate'] == null) or ($data['time-estimate'] == "") ) { 166 $time_est = 0; 167 } else { 168 $time_est = tt_convert_fraction_to_time($data['time-estimate']); 169 } 144 145 //CF7 vs WPF 146 $freq = "Monthly"; 147 if ( array_key_exists("recur-freq", $data) ) { 148 $freq = $data["recur-freq"]; 149 } elseif ( array_key_exists("frequency", $data)) { 150 $freq = $data["frequency"]; 151 } 152 153 $desc = ""; 154 if ( array_key_exists("task-desc", $data) ) { 155 $desc = $data["task-desc"]; 156 } elseif ( array_key_exists("task-notes", $data)) { 157 $desc = $data["task-notes"]; 158 } 159 170 160 $wpdb->insert( $table_name, array( 171 161 'RTName' => $data['task-name'], 172 162 'ClientID' => $this->client_id, 173 163 'ProjectID' => $this->project_id, 174 'RTTimeEstimate' => $time_est, 175 'RTDescription' => $data['task-desc'], 176 'Frequency' => $data['recur-freq'], 177 'EndRepeat' => $data['end-repeat'], 164 'RTTimeEstimate' => $this->get_time_estimate($data), 165 'RTDescription' => $desc, 166 'RTCategory' => $data['category'], 167 'Frequency' => $freq, 168 'EndRepeat' => $this->reformat_date($data, "end-repeat"), 178 169 'RTSubmission' => $this->original_submission 179 170 ) ); … … 191 182 192 183 //Add New Record to Database 193 if ( ($data['time-estimate'] == null) or ($data['time-estimate'] == "") ) {194 $time_est = 0;195 } else {196 $time_est = tt_convert_fraction_to_time($data['time-estimate']);197 }198 184 $wpdb->insert( $table_name, array( 199 185 'PName' => $data['project-name'], … … 201 187 'PCategory' => $data['project-category'], 202 188 'PStatus' => "New", 203 'PTimeEstimate' => $time_est, 204 'PDueDate' => $data['due-date'], 189 'PTimeEstimate' => $this->get_time_estimate($data), 205 190 'PDateStarted' => date('Y-m-d H:i:s'), 191 'PDueDate' => $this->reformat_date($data, "due-date"), 206 192 'PDetails' => $data['project-details'], 207 193 'PSubmission' => $this->original_submission … … 248 234 $end = \DateTime::createFromFormat('n/j/y g:i A', $data['end-time'])->format('Y-m-d H:i:ss'); 249 235 236 //find follow up field 237 $follow_up = ""; 238 foreach ($data as $key => $val) { 239 if (strpos(strtolower($key), "follow-up") !== false) { 240 if ($val != null && $val != "") { 241 $follow_up = $val; 242 } 243 } 244 } 245 250 246 //Add New Record to Database 251 247 $wpdb->insert( $table_name, array( … … 259 255 'InvoicedTime' => $data['invoiced-time'] == "" ? Null : $data['invoiced-time'], 260 256 'InvoiceComments' => $data['invoice-notes'], 261 'FollowUp' => $ data['follow-up'],257 'FollowUp' => $follow_up, 262 258 'NewTaskStatus' => $data['new-task-status'], 263 259 'TimeSubmission' => $this->original_submission … … 312 308 */ 313 309 private function get_client_id($data) { 314 //no client information passed 315 if ( !array_key_exists('client-name', $data) or $data['client-name'] == '' or $data['client-name'] == null) { 310 if (array_key_exists("client-name", $data) && $data["client-name"] !="" && $data["client-name"] != null ) { 311 return get_client_id_from_name($data['client-name']); 312 } elseif (array_key_exists("client", $data) && $data["client"] !="" && $data["client"] != null ) { 313 return get_client_id_from_name($data['client']); 314 } else { 316 315 //use default client if one exists, if not just enter null 317 316 return array_key_exists('default_client', get_option('time_tracker_categories')) ? get_option('time_tracker_categories')['default_client'] : null; 318 } else {319 return get_client_id_from_name($data['client-name']);320 317 } 321 318 } … … 328 325 private function get_project_id($data) { 329 326 //Project field in table requires a valid Project ID or null value, won't except empty string 330 if ( !array_key_exists('project-name', $data) or $data['project-name'] == '' or $data['project-name'] == null) {331 return null;332 } else {333 $project = $data['project-name'];334 return get_project_id_from_name($project);335 }327 if (array_key_exists('project-name', $data) && $data['project-name'] != '' && $data['project-name'] != null) { 328 return get_project_id_from_name(($data["project-name"])); 329 } elseif (array_key_exists('project', $data) && $data['project'] != '' && $data['project'] != null) { 330 return get_project_id_from_name(($data["project"])); 331 } 332 return null; 336 333 } 337 334 … … 343 340 private function get_task_id($data) { 344 341 //Task field in table requires a valid Task ID or null value, won't except empty string 345 if (!array_key_exists('task-name', $data) or $data['task-name'] == '' or $data['task-name'] == null) { 346 return array_key_exists('default_task', get_option('time_tracker_categories')) ? get_option('time_tracker_categories')['default_task'] : null; 347 } else { 342 if (array_key_exists('task-name', $data) and $data['task-name'] != '' and $data['task-name'] != null) { 348 343 $task = $data['task-name']; 349 $task_number_from_string = substr($task, 0,strpos($task,'-'));344 $task_number_from_string = substr($task, 0, strpos($task,'-')); 350 345 return $task_number_from_string; 346 } elseif (array_key_exists('ticket', $data) and $data['ticket'] != '' and $data['ticket'] != null) { 347 $task = $data['ticket']; 348 $task_number_from_string = substr($task, 0, strpos($task,'-')); 349 return $task_number_from_string; 350 } 351 return array_key_exists('default_task', get_option('time_tracker_categories')) ? get_option('time_tracker_categories')['default_task'] : null; 352 } 353 354 355 /** 356 * Get time estimate 357 * 358 */ 359 private function get_time_estimate($data) { 360 $time_est = 0; 361 foreach ($data as $key => $val) { 362 if (strpos(strtolower($key), "time-estimate") !== false) { 363 if ($val != null && $val != "") { 364 $time_est = tt_convert_fraction_to_time($val); 365 } 366 } 367 } 368 return $time_est; 369 } 370 371 372 /** 373 * Get date from field and reformat for db 374 * 375 */ 376 private function reformat_date($data, $key) { 377 if (array_key_exists($key, $data)) { 378 //return \DateTime::createFromFormat('m/d/Y', $data[$key])->format('Y-m-d'); 379 //if it is already in correct format pass it back 380 if (\DateTime::createFromFormat('Y-m-d', $data[$key])) { 381 return $data[$key]; 382 } 383 $obj = \DateTime::createFromFormat('m/d/Y', $data[$key]); 384 if ($obj) { 385 return $obj->format('Y-m-d'); 386 } 387 return $data[$key]; 351 388 } 352 389 } -
time-tracker/trunk/inc/css/time-tracker.php
r2862272 r2900796 111 111 font-size: 1.3em; 112 112 display: block; 113 padding: 5px0;113 padding: 0; 114 114 } 115 115 … … 166 166 width: 100%; 167 167 } 168 169 div#tt-primary { 170 width: 100%; 171 max-width: 100%; 172 } 168 173 169 174 .content-area .site { … … 564 569 .tt-form label, 565 570 .tt-form select, 566 .tt-form span { 571 .tt-form span, 572 .tt-form p:has(input[type="datetime"]) { 567 573 display: inline-block; 568 574 width: 90%; -
time-tracker/trunk/inc/function-tt-utilities.php
r2866551 r2900796 224 224 function tt_get_form_id($form_name) { 225 225 //$forms = WPCF7_ContactForm::find(array("title" => $form_name)); 226 require_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-activator-forms.php'); 226 227 $forms = get_posts(array( 227 228 'title'=> $form_name, 228 'post_type' => 'wpcf7_contact_form'229 'post_type' => Time_Tracker_Activator_Forms::get_post_type() 229 230 ), ARRAY_A); 230 231 if ($forms) { … … 259 260 } 260 261 require_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-activator-forms.php'); 261 $tt_forms = new Time_Tracker_Activator_Forms(); 262 $tt_forms_arr = $tt_forms->create_form_details_array(); 262 require_once(TT_PLUGIN_DIR_INC . '/' . TT_PLUGIN_FORM_TYPE . '/class-time-tracker-activator-forms-' . strtolower(TT_PLUGIN_FORM_TYPE) . '.php'); 263 //$tt_forms = new Time_Tracker_Activator_Forms(); 264 $tt_forms_arr = Time_Tracker_Activator_Forms::create_form_details_array(); 263 265 foreach ($tt_forms_arr as $tt_form) { 264 266 if ($form_name == $tt_form['Title']) { … … 266 268 } 267 269 } 270 return false; 268 271 } 269 272 … … 611 614 } 612 615 } 616 617 618 /** 619 * Query db 620 * 621 */ 622 function tt_query_db($sql_string, $return_type="object") { 623 global $wpdb; 624 if ($return_type == "array") { 625 $sql_result = $wpdb->get_results(esc_sql($sql_string), ARRAY_A ); 626 } else { 627 //default return type for get_results is object 628 $sql_result = $wpdb->get_results(esc_sql($sql_string)); 629 } 630 \Logically_Tech\Time_Tracker\Inc\catch_sql_errors(__FILE__, __FUNCTION__, $wpdb->last_query, $wpdb->last_error); 631 return $sql_result; 632 } 633 634 635 /** 636 * Get user options 637 * 638 */ 639 function tt_get_user_options($option_name, $sub_option_name) { 640 $optns = get_option($option_name); 641 if (array_key_exists($sub_option_name, $optns)) { 642 //var_dump(nl2br($optns[$sub_option_name])); 643 //var_dump(sanitize_text_field(nl2br($optns[$sub_option_name]))); 644 return $optns[$sub_option_name]; 645 } 646 return ""; 647 } 648 649 650 /** 651 * Get clients 652 * 653 */ 654 function tt_get_clients() { 655 return tt_query_db("SELECT ClientID, Company FROM tt_client ORDER BY Company ASC"); 656 } 657 658 659 /** 660 * Get tasks 661 * 662 */ 663 function tt_get_tasks() { 664 return tt_query_db("SELECT TaskID, TDescription FROM tt_task ORDER BY TaskID ASC"); 665 } 666 667 668 /** 669 * Get projects 670 * 671 */ 672 function tt_get_projects() { 673 return tt_query_db("SELECT ProjectID, PName FROM tt_project ORDER BY ProjectID ASC"); 674 } -
time-tracker/trunk/inc/js/filter_time_log.js
r2862272 r2900796 1 1 //Initiates when filter button pressed on page showing all time entries 2 2 function tt_filter_time_log(event) { 3 var inputs = event.detail.inputs; 3 4 4 var first_date = ""; 5 5 var last_date = ""; … … 10 10 var task = ""; 11 11 var project = ""; 12 13 for (var i = 0; i < inputs.length; i++) { 14 var input = inputs[i]; 15 if (input.name == 'first-date') { 16 first_date = input.value; 17 } else if (input.name == 'last-date') { 18 last_date = input.value; 19 } else if (input.name == 'client-name' && input.value != "null") { 20 client = input.value; 21 } else if (input.name == 'notes' && input.value != "null") { 22 notes = input.value; 23 } else if (input.name == 'project-name' && input.value != "null") { 24 project = input.value; 25 } else if (input.name == 'task-name' && input.value != "null") { 26 //pull out task number, to the left of the hyphen 27 task = input.value; 28 if (input.value.includes("-")) { 29 ticket = task.split("-", 1); 30 ticketname = task.split("-", 2); 12 13 if (event.detail !== undefined && event.detail !== null && event.detail !== false) { 14 //cf7 15 var inputs = event.detail.inputs; 16 for (var i = 0; i < inputs.length; i++) { 17 var input = inputs[i]; 18 if (input.name == 'first-date') { 19 first_date = input.value; 20 } else if (input.name == 'last-date') { 21 last_date = input.value; 22 } else if (input.name == 'client-name' && input.value != "null") { 23 client = input.value; 24 } else if (input.name == 'notes' && input.value != "null") { 25 notes = input.value; 26 } else if (input.name == 'project-name' && input.value != "null") { 27 project = input.value; 28 } else if (input.name == 'task-name' && input.value != "null") { 29 //pull out task number, to the left of the hyphen 30 task = input.value; 31 if (input.value.includes("-")) { 32 ticket = task.split("-", 1); 33 ticketname = task.split("-", 2); 34 } 35 //ticket = inputs[i].value; 36 } //end if 37 } //end for loop 38 } else { 39 if (event.target !== undefined && event.target !== null && event.target !== false) { 40 //wpf 41 var targets = event.target; 42 for (var i = 0; i < targets.length; i++) { 43 var ttfieldname = jQuery(event.target[i]).attr('data-tt-field'); 44 if (ttfieldname !== undefined && ttfieldname !== false && event.target[i].value !== "" && event.target[i].value !== null) { 45 if (ttfieldname == 'client') { 46 client = event.target[i].value; 47 } else if (ttfieldname == 'project') { 48 project = event.target[i].value; 49 } else if (ttfieldname == 'task') { 50 task = event.target[i].value; 51 if (task.includes("-")) { 52 ticket = task.split("-", 1); 53 ticketname = task.split("-", 2); 54 } 55 } else if (ttfieldname == 'notes') { 56 notes = event.target[i].value; 57 } else if (ttfieldname == "first-date") { 58 first_date = event.target[i].value; 59 } else if (ttfieldname == "last-date") { 60 last_date = event.target[i].value; 61 } 62 } 31 63 } 32 //ticket = inputs[i].value; 33 } //end if 34 } //end for loop 64 } 65 } 35 66 36 67 client = encodeURIComponent(client); -
time-tracker/trunk/inc/js/get_projects_for_client.js
r2862272 r2900796 1 1 //Update Project List When Client Name is Updated 2 2 function tt_update_project_dropdown() { 3 var clientField = document.getElementsByName('client-name'); 4 var projectField = document.getElementsByName('project-name'); 5 if (clientField.length > 0 && projectField.length > 0) { 6 var clientName = encodeURIComponent(clientField[0].value); 3 var clientField = jQuery(".tt-form").find("#client-name")[0]; 4 if (!clientField) { 5 clientField = document.getElementById(jQuery(".tt-form").find("label:contains(Client)").prop("for")); 6 } 7 8 var projectField = jQuery(".tt-form").find("#project-name")[0]; 9 if (!projectField) { 10 projectField = document.getElementById(jQuery(".tt-form").find("label:contains(Project)").prop("for")); 11 } 12 13 if (clientField && projectField) { 14 var clientName = encodeURIComponent(clientField.value); 7 15 var send = { 8 16 'security': wp_ajax_object_tt_update_project_list.security, … … 18 26 if (response.success) { 19 27 //success 20 //console.log(response.data.details); 21 projectField[0].innerHTML = response.data.details; 28 projectField.innerHTML = response.data.details; 22 29 } else { 23 30 //failed -
time-tracker/trunk/inc/js/get_tasks_for_client.js
r2862272 r2900796 1 1 function tt_update_task_dropdown() { 2 var taskField = document.getElementsByName('task-name'); 3 var clientField = document.getElementsByName('client-name'); 4 if (clientField.length > 0 && taskField.length > 0) { 5 var clientName = encodeURIComponent(clientField[0].value); 2 var taskField = jQuery(".tt-form").find("[name='task-name']")[0]; 3 if (!taskField) { 4 taskField = document.getElementById(jQuery(".tt-form").find("label:contains(Task)").prop("for")); 5 } 6 7 var clientField = jQuery(".tt-form").find("[name='client-name']")[0]; 8 if (!clientField) { 9 clientField = document.getElementById(jQuery(".tt-form").find("label:contains(Client)").prop("for")); 10 } 11 12 if (clientField && taskField) { 13 var clientName = encodeURIComponent(clientField.value); 6 14 var send = { 7 15 'security': wp_ajax_object_tt_update_task_list.security, … … 17 25 if (response.success) { 18 26 //success 19 //console.log(response.data.details); 20 taskField[0].innerHTML = response.data.details; 27 taskField.innerHTML = response.data.details; 21 28 } else { 22 29 //failed -
time-tracker/trunk/inc/js/set_date_picker_default_value.js
r2862272 r2900796 1 //Set default values for date pickers, if they exist in get value 1 //Set default values for date pickers, if they exist in get value, filter time form 2 2 document.addEventListener('DOMContentLoaded', function () { //make sure doc is done loading before looking for element 3 3 var startDateField = document.getElementById('first-date'); 4 if (!startDateField) { 5 var id = jQuery("label:contains(First Date)").prop("for"); 6 if (id) { 7 startDateField = document.getElementById(id); 8 } 9 } 10 4 11 var endDateField = document.getElementById('last-date'); 12 if (!endDateField) { 13 var id = jQuery("label:contains(End Date)").prop("for"); 14 if (id) { 15 endDateField = document.getElementById(id); 16 } 17 } 5 18 6 19 if (startDateField || endDateField ) { -
time-tracker/trunk/inc/js/update_end_timer.js
r2866551 r2900796 1 1 //Update the "End" Timer for a Time Entry to the Current Time 2 3 function update_end_timer() { 2 function tt_update_timer(timer) { 4 3 var d = new Date(); 5 4 … … 24 23 var dstring = month + "/" + day + "/" + year + " " + hour + ":" + minutes + " " + ampm; 25 24 26 document.getElementById('end-time').value = dstring; 25 //document.getElementById('end-time').value = dstring; 26 timer.value = dstring; 27 27 } 28 28 29 jQuery(window).on("load", function() { 30 var endtimer = document.getElementById('end-time'); 31 if (endtimer) { 32 var autoupdate = setInterval(function() { 33 update_end_timer(); 34 }, 60000); 29 jQuery(window).on('load', function() { 30 //look for cf7 end timer 31 var endtimer = jQuery('.tt-form').find('#end-time')[0]; 32 //if not found look for wpf end timer 33 if (!endtimer) { 34 endtimer = document.getElementById(jQuery('.tt-form').find('label:contains(End Time)').prop('for')); 35 } 36 if (endtimer) { 37 //update every 600 milliseconds 38 var autoupdate = setInterval(function() { 39 tt_update_timer(endtimer); 40 }, 600); 35 41 36 jQuery(endtimer).on("input", function() { 42 //if user enters data stop updating 43 jQuery(endtimer).on('input', function() { 37 44 clearInterval(autoupdate); 38 45 }); 39 } 46 } 47 48 //wpf only 49 var starttimer = document.getElementById(jQuery('.tt-form').find('label:contains(Start Time)').prop('for')); 50 if (starttimer) { 51 if (starttimer.value == '' || starttimer.value == null) { 52 tt_update_timer(starttimer); 53 } 54 } 40 55 }); -
time-tracker/trunk/readme.txt
r2876570 r2900796 6 6 Tested up to: 6.1 7 7 Requires PHP: 7.0 8 Stable tag: 2.4.78 Stable tag: 3.0.2 9 9 License: GPLv3 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 98 98 99 99 == Changelog == 100 101 = 3.0.2 = 102 * Improvement: Extended plugin requirement to EITHER Contact Forms 7 OR WP Forms as per their preference 103 * Improvement: Moved 'Time Tracker Home' button to top of Time Tracker menu to clean up layout 104 * Improvement: Mobile layout and usability tweaks 100 105 101 106 = 2.4.7 = -
time-tracker/trunk/templates/tt-page-template.php
r2862272 r2900796 78 78 79 79 ?> 80 <a href="<?php echo TT_HOME ?>" class="tt-header-button">Home</a>81 80 </header> 82 81 <!----------end page header-----------> -
time-tracker/trunk/templates/tt-sidebar.php
r2862272 r2900796 12 12 ?> 13 13 <div id="tt-favorite-functions"> 14 <a href=<?php echo TT_HOME ?> class="tt-sidebar-button">Time Tracker Home</a> 14 15 <div class="tt-sidebar-header">Favorites</div> 15 16 <a href=<?php echo TT_HOME . "open-task-list" ?> class="tt-sidebar-button">Open Tasks</a> -
time-tracker/trunk/time-tracker.php
r2876570 r2900796 12 12 * Plugin URI: https://www.logicallytech.com/services/wordpress-plugins/time-tracker/ 13 13 * Description: A task and time tracking program. Perfect for freelancers or indivdiuals keeping track of to do lists and time worked and billed to clients. 14 * Version: 2.4.714 * Version: 3.0.2 15 15 * Requires at least: 5.3 16 16 * Requires PHP: 7.0 … … 40 40 * Use SemVer - https://semver.org 41 41 */ 42 define('TIME_TRACKER_VERSION', ' 2.4.7');42 define('TIME_TRACKER_VERSION', '3.0.2'); 43 43 define('TIME_TRACKER_PLUGIN_BASENAME', plugin_basename(__FILE__)); 44 44
Note: See TracChangeset
for help on using the changeset viewer.