function dbreassign() { global $dcl_info, $g_oSec; commonHeader(); if (($iID = @DCL_Sanitize::ToInt($_REQUEST['jcn'])) === null || ($iSeq = @DCL_Sanitize::ToInt($_REQUEST['seq'])) === null || ($iResponsible = @DCL_Sanitize::ToInt($_REQUEST['responsible'])) === null || ($fEstHours = @DCL_Sanitize::ToDecimal($_REQUEST['esthours'])) === null || ($fEtcHours = @DCL_Sanitize::ToDecimal($_REQUEST['etchours'])) === null || ($iSeverity = @DCL_Sanitize::ToInt($_REQUEST['severity'])) === null || ($iPriority = @DCL_Sanitize::ToInt($_REQUEST['priority'])) === null || ($deadlineon = @DCL_Sanitize::ToDate($_REQUEST['deadlineon'])) === null || ($eststarton = @DCL_Sanitize::ToDate($_REQUEST['eststarton'])) === null || ($estendon = @DCL_Sanitize::ToDate($_REQUEST['estendon'])) === null) { trigger_error('Data sanitize failed.'); return; } if (!$g_oSec->HasPerm(DCL_ENTITY_WORKORDER, DCL_PERM_ASSIGN, $iID, $iSeq)) { return PrintPermissionDenied(); } $objWO =& CreateObject('dcl.dbWorkorders'); if ($objWO->Load($iID, $iSeq) == -1) { return; } if ($objWO->responsible != $iResponsible || $objWO->deadlineon != $deadlineon || $objWO->eststarton != $eststarton || $objWO->estendon != $estendon || $objWO->esthours != $fEstHours || $objWO->etchours != $fEtcHours || $objWO->priority != $iPriority || $objWO->status == $dcl_info['DCL_DEF_STATUS_UNASSIGN_WO'] || $objWO->severity != $iSeverity) { $objWO->responsible = $iResponsible; $objWO->deadlineon = $deadlineon; $objWO->eststarton = $eststarton; $objWO->estendon = $estendon; $objWO->esthours = $fEstHours; $oStatus =& CreateObject("dcl.dbStatuses"); if ($oStatus->GetStatusType($objWO->status) != 2) { $objWO->etchours = $fEtcHours; if ($objWO->status == $dcl_info['DCL_DEF_STATUS_UNASSIGN_WO']) { $objWO->status = $dcl_info['DCL_DEF_STATUS_ASSIGN_WO']; $objWO->statuson = $objWO->GetDateSQL(); } } else { $objWO->etchours = 0.0; } $objWO->priority = $iPriority; $objWO->severity = $iSeverity; $objWO->Edit(); $objWtch =& CreateObject('dcl.boWatches'); $objWtch->sendNotification($objWO, '4'); } $objHTMLWO =& CreateObject('dcl.htmlWorkOrderDetail'); $objHTMLWO->Show($iID, $iSeq); }
function Add($targeted_version_id = 0, $fixed_version_id = 0) { global $dcl_info, $g_oSec; if (($fEtcHours = DCL_Sanitize::ToDecimal($_REQUEST['etchours'])) === null) { trigger_error('Data sanitize failed.'); return; } $objWO = CreateObject('dcl.dbWorkorders'); if ($objWO->Load($this->jcn, $this->seq) == -1) { trigger_error(printf(STR_DB_WORKORDERLOADERR, $this->jcn, $this->seq)); return; } $currstatus = $objWO->status; $justStarted = $objWO->IsFieldNull('starton'); $idSQL = $this->GetNewIDSQLForTable('timecards'); $query = 'INSERT INTO timecards ('; if ($idSQL != '') { $query .= 'id,'; } $query .= 'jcn, seq, actionon, inputon, actionby, status, action, hours, summary, description, is_public, reassign_from_id, reassign_to_id'; $query .= ') VALUES ('; if ($idSQL != '') { $query .= $idSQL . ','; } $query .= $this->jcn . ',' . $this->seq . ','; $query .= $this->DisplayToSQL($this->actionon) . ','; $query .= $this->GetDateSQL() . ',' . $this->actionby . ','; $query .= $this->status . ',' . $this->action . ',' . $this->hours; $query .= ',' . $this->Quote($this->summary); $query .= ',' . $this->Quote($this->description); $query .= ',' . $this->Quote($this->is_public); // Reassign if selected and able if ($this->reassign_to_id > 0 && $g_oSec->HasPerm(DCL_ENTITY_WORKORDER, DCL_PERM_ASSIGN) && $objWO->responsible != $this->reassign_to_id) { $query .= ',' . $objWO->responsible; $query .= ',' . $this->reassign_to_id; $objWO->responsible = $this->reassign_to_id; } else { $query .= ', NULL, NULL'; } $query .= ')'; $objWO->lastactionon = date($dcl_info['DCL_TIMESTAMP_FORMAT']); $objWO->totalhours = $objWO->totalhours + $this->hours; $objWO->etchours = $_REQUEST['etchours']; if ($currstatus != $this->status) { $objWO->status = $this->status; $objWO->statuson = date($dcl_info['DCL_TIMESTAMP_FORMAT']); $oStatus = CreateObject('dcl.dbStatuses'); if ($oStatus->GetStatusType($this->status) == 2 && $oStatus->GetStatusType($currstatus) != 2) { $objWO->closedby = $this->actionby; $objWO->closedon = $this->actionon; } else { if ($oStatus->GetStatusType($currstatus) == 2) { $objWO->closedby = 0; $objWO->closedon = ''; } } } // Check for version updates if ((int) $targeted_version_id > 0) { $objWO->targeted_version_id = $targeted_version_id; } if ((int) $fixed_version_id > 0) { $objWO->fixed_version_id = $fixed_version_id; } // ensure the etc hours do not get anything but zero when closed $oStatus = CreateObject('dcl.dbStatuses'); if ($oStatus->GetStatusType($objWO->status) == 2) { $objWO->etchours = 0.0; } if ($justStarted == 1) { $objWO->starton = $this->actionon; } $this->BeginTransaction(); $this->Insert($query); $objWO->Edit(); $this->EndTransaction(); }
/** * Helper function to properly represent data for SQL statements * @param string the field this value represents * @param string the value of this field * @return mixed NULL if the value is NULL or empty, otherwise proper SQL formatted value */ function FieldValueToSQL($sField, $sValue) { $aField =& $GLOBALS['phpgw_baseline'][$this->TableName]['fd'][$sField]; if (is_null($sValue) || trim($sValue) === '') { if ($aField['type'] == 'timestamp') { return $this->emptyTimestamp; } return 'NULL'; } switch ($aField['type']) { case 'varchar': case 'char': case 'text': return $this->Quote($sValue); case 'date': case 'datetime': case 'timestamp': if ($sValue == DCL_NOW) { return $this->GetDateSQL(); } return $this->DisplayToSQL($sValue); case 'int': case 'auto': return DCL_Sanitize::ToInt($sValue); case 'float': return DCL_Sanitize::ToDecimal($sValue); default: return $sValue; } }