opencats / OpenCATS

Applicant Tracking System (maintained code base)
http://www.opencats.org
Other
528 stars 245 forks source link

Update activity wrongly set activity date #318

Open skrchnavy opened 7 years ago

skrchnavy commented 7 years ago

Expected behavior and actual behavior.

Activity date shall be updated based on data/time when update was submitted. Strange date is provided

Steps to reproduce the problem.

What version of opencats are you running? WAMP or LAMP?

0.9.4 demo site

attach appropriate error logs. Please attach [apache/mysql] error/access logs as needed.

for example: http://demo.opencats.org/index.php?m=candidates&a=show&candidateID=1143

skrchnavy commented 7 years ago

I checked what is sent via ajax ant this is form data

f:editActivity
notes:qweqweqw
date:05-08-19
hour:10
minute:16
ampm:AM
activityID:1741
type:600
jobOrderID:NULL
rhash:84356416

so the issue is in js code, it sends not proper date. it is in js/activity.js function Activity_editEntry

        /* Date editor. */
        var dateSpan = document.createElement('span');
        var dateAndTime = unEscapeHTML(dateTD.innerHTML.replace(/(<([^>]+)>)/ig,""));
        dateSpan.innerHTML = DateInputForDOM('dateEditActivity' + activityID, true, 'MM-DD-YY', dateAndTime.substr(0,dateAndTime.indexOf(' ')), -1);

        var timeString = dateAndTime.substr(dateAndTime.indexOf(' ')+2);
        var hourString = timeString.substr(0,timeString.indexOf(':'));
        var timeString = timeString.substr(timeString.indexOf(':')+1);
        var minuteString = timeString.substr(0,timeString.indexOf(' '));
        var timeString = timeString.substr(timeString.indexOf(' ')+1);
        var amPmString = timeString.substr(0,timeString.indexOf(')'));

where is created date selector with wrongly parsed data. This date is then send to server.

RussH commented 7 years ago

It's because it's hard coded to expect MM-DD-YY?

skrchnavy commented 7 years ago

probably not, realy strange processing, html formated text is parsed as date and then displayed in date picker.

skrchnavy commented 7 years ago

There is different processing of add activity and edit activity. File: lib/ActivityEntries.php

add activity is added using

            "INSERT INTO activity (
                data_item_id,
                data_item_type,
                joborder_id,
                entered_by,
                type,
                notes,
                site_id,
                date_created,
                date_modified
            )
            VALUES (
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                NOW(),
                NOW()
            )",

edit activity when $date provided is updated using

                "UPDATE
                    activity
                SET
                    date_created  = DATE_SUB(%s, INTERVAL %s HOUR),
                    date_modified = NOW()
                WHERE
                    activity_id = %s
                AND
                    site_id = %s",
                $this->_db->makeQueryString($date),
                $this->_db->makeQueryInteger($timezoneOffset),
                $this->_db->makeQueryInteger($activityID),
                $this->_siteID

and date comes from ajax request. Why shall be date_created modified by user?

olenchenko commented 7 years ago

Any updates on this one ar maybe some temporary workaround?

RussH commented 7 years ago

needs confirmation - but from @skrchnavy investigation - I'd just comment out the 'SET date_created' during edit activity. As @skrchnavy says, there's no need to mess with this during an update.

wjcheers commented 6 years ago

js\activity.js

dateSpan.innerHTML = DateInputForDOM('dateEditActivity' + activityID, true, 'MM-DD-YY', dateAndTime.substr(0,dateAndTime.indexOf(' ')), -1);

the expected format of date is MM-DD-YY here. However, the input date is DD-MM-YY.

HTML: http://demo.opencats.org/index.php?m=candidates&a=show&candidateID=1143

<td align="left" valign="top" id="activityDate2070">14-11-17 (06:13 AM)</td>

the demo site date format is UK (DD-MM-YYYY) which is conflict to activity.js (MM-DD-YY).

Simply, config to US (MM-DD-YYYY) format would fix your problem. index.php?m=settings&a=administration&s=localization.

BTW, there is a bug in the time format while editing activity . strtotime("9:0 AM"); output nothing. It lead the new date of activity to 00:00:00.

ajax\editActivity.php

$time = strtotime(
    sprintf('%s:%s %s', $activityHour, $activityMinute, $activityAMPM)
);
change to:
$time = strtotime(
    sprintf('%02d:%02d %s', $activityHour, $activityMinute, $activityAMPM)
);