/** * Method used to add a new time entry in the system. * * @access public * @return integer 1 if the update worked, -1 otherwise */ function insertEntry() { global $HTTP_POST_VARS; if (!empty($HTTP_POST_VARS["date"])) { // format the date from the form $created_date = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $HTTP_POST_VARS["date"]["Year"], $HTTP_POST_VARS["date"]["Month"], $HTTP_POST_VARS["date"]["Day"], $HTTP_POST_VARS["date"]["Hour"], $HTTP_POST_VARS["date"]["Minute"], 0); // convert the date to GMT timezone $created_date = Date_API::getDateGMT($created_date); } else { $created_date = Date_API::getCurrentDateGMT(); } $usr_id = Auth::getUserID(); $stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "time_tracking\n (\n ttr_ttc_id,\n ttr_iss_id,\n ttr_usr_id,\n ttr_created_date,\n ttr_time_spent,\n ttr_summary\n ) VALUES (\n " . $HTTP_POST_VARS["category"] . ",\n " . $HTTP_POST_VARS["issue_id"] . ",\n {$usr_id},\n '{$created_date}',\n " . $HTTP_POST_VARS["time_spent"] . ",\n '" . Misc::escapeString($HTTP_POST_VARS["summary"]) . "'\n )"; $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } else { Issue::markAsUpdated($HTTP_POST_VARS["issue_id"], 'time added'); // need to save a history entry for this History::add($HTTP_POST_VARS["issue_id"], $usr_id, History::getTypeID('time_added'), 'Time tracking entry submitted by ' . User::getFullName($usr_id)); return 1; } }
/** * Method used to add a phone support entry using the user * interface form available in the application. * * @access public * @return integer 1 if the insert worked, -1 or -2 otherwise */ function insert() { global $HTTP_POST_VARS; $usr_id = Auth::getUserID(); // format the date from the form $created_date = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $HTTP_POST_VARS["date"]["Year"], $HTTP_POST_VARS["date"]["Month"], $HTTP_POST_VARS["date"]["Day"], $HTTP_POST_VARS["date"]["Hour"], $HTTP_POST_VARS["date"]["Minute"], 0); // convert the date to GMT timezone $created_date = Date_API::getDateGMT($created_date); $stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support\n (\n phs_iss_id,\n phs_usr_id,\n phs_phc_id,\n phs_created_date,\n phs_type,\n phs_phone_number,\n phs_description,\n phs_phone_type,\n phs_call_from_lname,\n phs_call_from_fname,\n phs_call_to_lname,\n phs_call_to_fname\n ) VALUES (\n " . Misc::escapeInteger($HTTP_POST_VARS["issue_id"]) . ",\n {$usr_id},\n " . Misc::escapeInteger($HTTP_POST_VARS["phone_category"]) . ",\n '" . Misc::escapeString($created_date) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["type"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["phone_number"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["description"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["phone_type"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["from_lname"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["from_fname"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["to_lname"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["to_fname"]) . "'\n )"; $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } else { // enter the time tracking entry about this phone support entry $phs_id = $GLOBALS["db_api"]->get_last_insert_id(); $HTTP_POST_VARS['category'] = Time_Tracking::getCategoryID('Telephone Discussion'); $HTTP_POST_VARS['time_spent'] = $HTTP_POST_VARS['call_length']; $HTTP_POST_VARS['summary'] = 'Time entry inserted from phone call.'; Time_Tracking::insertEntry(); $stmt = "SELECT\n max(ttr_id)\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "time_tracking\n WHERE\n ttr_iss_id = " . Misc::escapeInteger($HTTP_POST_VARS["issue_id"]) . " AND\n ttr_usr_id = {$usr_id}"; $ttr_id = $GLOBALS["db_api"]->dbh->getOne($stmt); Issue::markAsUpdated($HTTP_POST_VARS['issue_id'], 'phone call'); // need to save a history entry for this History::add($HTTP_POST_VARS['issue_id'], $usr_id, History::getTypeID('phone_entry_added'), 'Phone Support entry submitted by ' . User::getFullName($usr_id)); // XXX: send notifications for the issue being updated (new notification type phone_support?) // update phone record with time tracking ID. if (!empty($phs_id) && !empty($ttr_id)) { $stmt = "UPDATE\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support\n SET\n phs_ttr_id = {$ttr_id}\n WHERE\n phs_id = " . Misc::escapeInteger($phs_id); $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } } return 1; } }