Plugin Directory

Changeset 2900796


Ignore:
Timestamp:
04/18/2023 03:11:48 PM (3 years ago)
Author:
GermanPearls
Message:

ver 3.0.2

Location:
time-tracker/trunk
Files:
15 added
18 edited

Legend:

Unmodified
Added
Removed
  • time-tracker/trunk/inc/class-time-tracker-activator-forms.php

    r2862272 r2900796  
    2222        public static $form_details = array();
    2323        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            }
    3645        }
    3746
     
    4251         */
    4352        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();
    5054            self::create_forms('false');
    5155        }
     
    5357
    5458        /**
    55          * Update Version
     59         * Update Version - Check for updates
    5660         *
    5761         */
     
    6367
    6468        /**
    65          * Update Version
     69         * Update Version - Force updates
    6670         *
    6771         */
     
    7074            self::create_forms('true');
    7175        }
     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        }
    7292       
    7393       
     
    7999            $installed_form = get_post($form_post_id);
    80100            $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            }             
    91115            return $form_post_id;
    92116        }
     
    99123        public static function create_forms($force_update) {
    100124            $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++) {
    106127                $form_arr = self::get_form_details($i);
    107128               
     
    109130                $form_exists = get_posts(array(
    110131                    'title'=> $form_arr['post_title'],
    111                     'post_type' => 'wpcf7_contact_form'
     132                    'post_type' => $form_arr['post_type']
    112133                ), ARRAY_A);
     134
    113135                //if form does not exist, create it
    114 
    115136                if (empty($form_exists)) {
    116137                    $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
    117145                    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);
    124147                    }
    125148               
     
    130153            }
    131154        }
    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
    151159         *
    152160         */
    153161        public static function get_form_details($arr_index) {
     162            if (self::$post_typ == "") {
     163                self::get_post_type();
     164            }
    154165            $arr = array(
    155166                'post_author'           => '',
     
    160171                'post_excerpt'          => '',
    161172                'post_status'           => 'publish',
    162                 'post_type'             => 'wpcf7_contact_form',
     173                'post_type'             => self::$post_typ,
    163174                'page_template'         => '',
    164175                'comment_status'        => 'closed',
     
    184195            $details = array();
    185196            $all_details = array();
    186          
     197            if (self::$form_class == "") {
     198                self::get_form_class_name();
     199            }
    187200            //add new client
    188201            $details = array(
    189202                "Title" => "Add New Client",
    190203                "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()
    192205            );
    193206            array_push($all_details, $details);
     
    197210                "Title" => "Add New Project",
    198211                "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()
    200213            );
    201214            array_push($all_details, $details);
     
    205218                "Title" => "Add New Recurring Task",
    206219                "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()
    208221            );
    209222            array_push($all_details, $details);
     
    213226                "Title" => "Add New Task",
    214227                "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()
    216229            );
    217230            array_push($all_details, $details);
     
    221234                "Title" => "Add Time Entry",
    222235                "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()
    224237            );
    225238            array_push($all_details, $details);
     
    229242                "Title" => "Filter Time",
    230243                "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()
    232245            );
    233246            array_push($all_details, $details);
     
    243256         */
    244257        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;
    605287        }
    606288
  • time-tracker/trunk/inc/class-time-tracker-activator-pages.php

    r2862272 r2900796  
    100100
    101101                $updated_content = self::get_page_details($i)['post_content'];
    102 
    103102                //does the content match the current version
    104103                if ($installed_page_content != $updated_content) {
     
    183182            self::$page_details = $details_all;
    184183        }
     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        }
    185201           
    186202           
     
    210226                "Parent" => $parent,
    211227                "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"),
    213230                "Paginate" => array(
    214231                    "Flag" => false
     
    222239                "Parent" => $parent,
    223240                "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"),
    225243                "Paginate" => array(
    226244                    "Flag" => false
     
    234252                "Parent" => $parent,
    235253                "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"),
    237256                "Paginate" => array(
    238257                    "Flag" => false
     
    246265                "Parent" => $parent,
    247266                "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"),
    249269                "Paginate" => array(
    250270                    "Flag" => false
     
    258278                "Parent" => $parent,
    259279                "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"),
    261282                "Paginate" => array(
    262283                    "Flag" => false
     
    346367                "Parent" => $parent,
    347368                "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(
    350372                    "Flag" => true,
    351373                    "RecordsPerPage" => 100,
  • time-tracker/trunk/inc/class-time-tracker-activator.php

    r2870230 r2900796  
    2525    class Time_Tracker_Activator {
    2626
    27         private static $cf7_active = false;
    2827        private static $default_client = null;
    2928        private static $default_task = null;
    3029
    31 
    3230        public static function activate() {
    3331            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();
    4642            } else {
    4743                ?>
     
    6460
    6561
    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();
    7074        }
    7175       
  • time-tracker/trunk/inc/class-time-tracker-updater.php

    r2866551 r2900796  
    155155        private function tt_update_forms($force_update = false) {
    156156            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');
    157158            if ($force_update) {
    158159                $tt_forms = Time_Tracker_Activator_Forms::force_form_updates();
  • time-tracker/trunk/inc/class-time-tracker.php

    r2862272 r2900796  
    3636        self::$instance->setup_constants();
    3737        self::$instance->load_dependencies();
     38        self::$instance->load_form_dependencies();
    3839        self::$instance->add_scripts();
    3940        self::$instance->add_styles();
     
    5354 
    5455     
    55    /**
    56    * Log Install Time
    57    *
    58    **/
     56    /**
     57    * Log Install Time
     58    *
     59    **/
    5960    private function log_plugin_installation() {
    6061      if (! get_option('time_tracker_install_time')) {
     
    6465     
    6566     
    66      /**
     67    /**
    6768     * Check Plugin Version
    6869     *
    69      */ 
     70    **/ 
    7071    private function check_plugin_version() {
    7172      $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);
    7683      }
    7784    }
     
    94101      define('TT_PLUGIN_WEB_DIR_ADMIN', plugin_dir_url(__FILE__) . '../admin/');
    95102      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      }
    96118    }
    97119 
     
    106128      include_once(TT_PLUGIN_DIR_INC . 'function-tt-utilities.php');
    107129      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');
    113130      include_once(TT_PLUGIN_DIR_INC . 'function-tt-clear-sql-error.php');
    114131      include_once(TT_PLUGIN_DIR_INC . 'function-tt-cron-recurring-tasks.php');
     
    119136      include_once(TT_PLUGIN_DIR_INC . 'function-tt-load-dynamic-stylesheets.php');
    120137        include_once(TT_PLUGIN_DIR_INC . 'function-tt-get-new-task-details.php');
    121       include_once(TT_PLUGIN_DIR_INC . 'function-tt-recaptcha.php');
    122138     
    123139      //CLASSES 
     
    148164      //CONTACT FORM 7 HOOKS
    149165      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');
    151166
    152167      //SHORTCODES
     
    163178      require_once(TT_PLUGIN_DIR_INC . 'class-tt-shortcode-delete-confirmation-content.php');
    164179      require_once(TT_PLUGIN_DIR_ADMIN . 'class-tt-shortcode-error-alert.php'); 
    165 
    166180    }
    167181
     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    }
    168211
    169212    /**
     
    186229      wp_enqueue_script( 'tt_accordion', TT_PLUGIN_WEB_DIR_INC . 'js/tt_accordion.js', array(), null, true );
    187230
    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);
    189231      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);
    192232      wp_enqueue_script( 'tt_update_task_dropdown', TT_PLUGIN_WEB_DIR_INC . 'js/get_tasks_for_client.js', array('jquery'), null, true);
    193233     
  • time-tracker/trunk/inc/class-tt-hook-after-form-data-saved.php

    r2862272 r2900796  
    44 *
    55 * 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)
    710 *
    811 * @since 1.0
     
    3336        */
    3437        public function _construct() {
    35 
    3638        }
    3739
     
    4244        */
    4345        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);
    5075               
    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 () { 
    5284                   
    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')) {
    6086
    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;
    7097                                    } 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                                            //}
    73108                                        }
    74109                                    }
    75110                                }
    76                             }
    77                         }
    78111
    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                                }
    82122                       
    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
    94126                   
    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
    102132    }  //close class
    103133}   //if class does not exist
    104134
    105135$aftersave = new Time_Tracker_After_Form_Data_Saved();
    106 
    107136add_action( 'wp_footer', array($aftersave, 'after_save') );
  • time-tracker/trunk/inc/class-tt-save-form-input.php

    r2870230 r2900796  
    3232         *
    3333         */
    34         private $data;
     34        //private $data;
    3535        private $form_post_id;
     36        private $original_submission;
    3637        private $result;
    3738        private $client_id;
     
    4445         *
    4546         */
    46         public function __construct($raw_data, $id) {
     47        public function __construct($cleaned_data, $id) {
    4748            //removed $form added insertid
    4849            $this->form_post_id = $id;
    49             $data = $this->clean_data($raw_data);
     50            //$data = $this->clean_data($raw_data);
     51            $data = $cleaned_data;
     52
    5053            $this->original_submission = $this->serialize_data($data);
    5154            $this->client_id = $this->get_client_id($data);
     
    5558            /*** Add new task ***/
    5659            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);
    5961           
    6062            /*** 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);           
    6465
    6566            /*** 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);
    6969
    7070            /*** 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);
    7473
    7574            /*** 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') ) {
    7776                $this->save_new_time_entry($data);
    7877               
     
    8887            }
    8988        }
    90      
    91        
    92         /**
    93          * Sanitize data
    94          *
    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         }
    11289       
    11390       
     
    132109            //Add New Record to Database
    133110            //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
    139118            $wpdb->insert( $table_name, array(
    140119                'TDescription' => $data['task-description'],
    141120                'ClientID'   => $this->client_id,
    142121                'ProjectID'    => $this->project_id,
    143                 'TCategory' => $data['task-category'],
     122                'TCategory' => $cat,
    144123                'TStatus' => "New",
    145                 'TTimeEstimate' => $time_est,
    146                 'TDueDate' => $data['due-date'],
     124                'TTimeEstimate' => $this->get_time_estimate($data),
    147125                'TDateAdded' => date('Y-m-d H:i:s'),
     126                'TDueDate' => $this->reformat_date($data, "due-date"),
    148127                'TNotes' => $data['notes'],
    149128                'TSubmission' => $this->original_submission
     
    163142            //Add New Record to Database
    164143            //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
    170160            $wpdb->insert( $table_name, array(
    171161                'RTName' => $data['task-name'],
    172162                'ClientID'   => $this->client_id,
    173163                '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"),
    178169                'RTSubmission' => $this->original_submission
    179170            ) );
     
    191182
    192183            //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             }
    198184            $wpdb->insert( $table_name, array(
    199185                'PName' => $data['project-name'],
     
    201187                'PCategory'    => $data['project-category'],
    202188                'PStatus' => "New",
    203                 'PTimeEstimate' => $time_est,
    204                 'PDueDate' => $data['due-date'],
     189                'PTimeEstimate' => $this->get_time_estimate($data),
    205190                'PDateStarted' => date('Y-m-d H:i:s'),
     191                'PDueDate' => $this->reformat_date($data, "due-date"),
    206192                'PDetails' => $data['project-details'],
    207193                'PSubmission' => $this->original_submission
     
    248234            $end = \DateTime::createFromFormat('n/j/y g:i A', $data['end-time'])->format('Y-m-d H:i:ss');
    249235
     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
    250246            //Add New Record to Database
    251247            $wpdb->insert( $table_name, array(
     
    259255                'InvoicedTime' => $data['invoiced-time'] == "" ? Null : $data['invoiced-time'],
    260256                'InvoiceComments' => $data['invoice-notes'],
    261                 'FollowUp' => $data['follow-up'],
     257                'FollowUp' => $follow_up,
    262258                'NewTaskStatus' => $data['new-task-status'],
    263259                'TimeSubmission' => $this->original_submission
     
    312308         */
    313309        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 {
    316315                //use default client if one exists, if not just enter null
    317316                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']);
    320317            }
    321318        }
     
    328325        private function get_project_id($data) {
    329326            //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;
    336333        }
    337334
     
    343340        private function get_task_id($data) {
    344341            //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) {
    348343                $task = $data['task-name'];
    349                 $task_number_from_string = substr($task,0,strpos($task,'-'));
     344                $task_number_from_string = substr($task, 0, strpos($task,'-'));
    350345                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];
    351388            }
    352389        }
  • time-tracker/trunk/inc/css/time-tracker.php

    r2862272 r2900796  
    111111  font-size: 1.3em;
    112112  display: block;
    113   padding: 5px 0;
     113  padding: 0;
    114114}
    115115
     
    166166        width: 100%;
    167167    }
     168
     169    div#tt-primary {
     170        width: 100%;
     171        max-width: 100%;
     172    }
    168173
    169174    .content-area .site {
     
    564569.tt-form label,
    565570.tt-form select,
    566 .tt-form span {
     571.tt-form span,
     572.tt-form p:has(input[type="datetime"]) {
    567573    display: inline-block;
    568574    width: 90%;
  • time-tracker/trunk/inc/function-tt-utilities.php

    r2866551 r2900796  
    224224function tt_get_form_id($form_name) {
    225225    //$forms = WPCF7_ContactForm::find(array("title" => $form_name));
     226    require_once(TT_PLUGIN_DIR_INC . 'class-time-tracker-activator-forms.php');
    226227    $forms = get_posts(array(
    227228        'title'=> $form_name,
    228         'post_type' => 'wpcf7_contact_form'
     229        'post_type' => Time_Tracker_Activator_Forms::get_post_type()
    229230    ), ARRAY_A);
    230231    if ($forms) {
     
    259260    }
    260261    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();
    263265    foreach ($tt_forms_arr as $tt_form) {
    264266        if ($form_name == $tt_form['Title']) {
     
    266268        }
    267269    }
     270    return false;
    268271}
    269272
     
    611614    }
    612615}
     616
     617
     618/**
     619 * Query db
     620 *
     621 */
     622function 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 */
     639function 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 */
     654function 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 */
     663function 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 */
     672function 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  
    11//Initiates when filter button pressed on page showing all time entries
    22function tt_filter_time_log(event) {
    3     var inputs = event.detail.inputs;
     3
    44    var first_date = "";
    55    var last_date = "";
     
    1010    var task = "";
    1111    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                }
    3163            }
    32             //ticket = inputs[i].value;
    33         } //end if
    34     }  //end for loop
     64        }
     65    }
    3566
    3667    client = encodeURIComponent(client);
  • time-tracker/trunk/inc/js/get_projects_for_client.js

    r2862272 r2900796  
    11//Update Project List When Client Name is Updated
    22function 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);
    715    var send = {
    816        'security': wp_ajax_object_tt_update_project_list.security,
     
    1826        if (response.success) {
    1927          //success
    20           //console.log(response.data.details);
    21           projectField[0].innerHTML = response.data.details;
     28          projectField.innerHTML = response.data.details;
    2229        } else {
    2330          //failed
  • time-tracker/trunk/inc/js/get_tasks_for_client.js

    r2862272 r2900796  
    11function 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);
    614    var send = {
    715        'security': wp_ajax_object_tt_update_task_list.security,
     
    1725        if (response.success) {
    1826          //success
    19           //console.log(response.data.details);
    20           taskField[0].innerHTML = response.data.details;
     27          taskField.innerHTML = response.data.details;
    2128        } else {
    2229          //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
    22document.addEventListener('DOMContentLoaded', function () {  //make sure doc is done loading before looking for element 
    33  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
    411  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  }
    518
    619  if (startDateField || endDateField ) {
  • time-tracker/trunk/inc/js/update_end_timer.js

    r2866551 r2900796  
    11//Update the "End" Timer for a Time Entry to the Current Time
    2 
    3 function update_end_timer() {
     2function tt_update_timer(timer) {
    43    var d = new Date();
    54   
     
    2423    var dstring = month + "/" + day + "/" + year + " " + hour + ":" + minutes + " " + ampm;
    2524
    26     document.getElementById('end-time').value = dstring;
     25    //document.getElementById('end-time').value = dstring;
     26    timer.value = dstring;
    2727}
    2828
    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);
     29jQuery(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);
    3541
    36         jQuery(endtimer).on("input", function() {
     42        //if user enters data stop updating
     43        jQuery(endtimer).on('input', function() {
    3744            clearInterval(autoupdate);
    3845        });
    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    }
    4055});
  • time-tracker/trunk/readme.txt

    r2876570 r2900796  
    66Tested up to: 6.1
    77Requires PHP: 7.0
    8 Stable tag: 2.4.7
     8Stable tag: 3.0.2
    99License: GPLv3 or later
    1010License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    9898 
    9999== 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
    100105
    101106= 2.4.7 =
  • time-tracker/trunk/templates/tt-page-template.php

    r2862272 r2900796  
    7878
    7979                ?>
    80                 <a href="<?php echo TT_HOME ?>" class="tt-header-button">Home</a>
    8180                </header>
    8281            <!----------end page header----------->
  • time-tracker/trunk/templates/tt-sidebar.php

    r2862272 r2900796  
    1212 ?>
    1313<div id="tt-favorite-functions">
     14<a href=<?php echo TT_HOME ?> class="tt-sidebar-button">Time Tracker Home</a>
    1415<div class="tt-sidebar-header">Favorites</div>
    1516<a href=<?php echo TT_HOME . "open-task-list" ?> class="tt-sidebar-button">Open Tasks</a>
  • time-tracker/trunk/time-tracker.php

    r2876570 r2900796  
    1212 * Plugin URI:        https://www.logicallytech.com/services/wordpress-plugins/time-tracker/
    1313 * 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.7
     14 * Version:           3.0.2
    1515 * Requires at least: 5.3
    1616 * Requires PHP:      7.0
     
    4040 * Use SemVer - https://semver.org
    4141 */
    42 define('TIME_TRACKER_VERSION', '2.4.7');
     42define('TIME_TRACKER_VERSION', '3.0.2');
    4343define('TIME_TRACKER_PLUGIN_BASENAME', plugin_basename(__FILE__));
    4444
Note: See TracChangeset for help on using the changeset viewer.