Beispiel #1
0
 public static function Approve($ID, $check_rights = true)
 {
     if ($check_rights) {
         $hasAccess = false;
         $arAccessUsers = CTimeMan::GetAccess();
         if (count($arAccessUsers['WRITE']) > 0) {
             $bCanEditAll = in_array('*', $arAccessUsers['WRITE']);
             $dbRes = CTimeManEntry::GetList(array(), array('ID' => $ID), false, false, array('*'));
             $arRes = $dbRes->Fetch();
             if ($arRes) {
                 $hasAccess = $bCanEditAll || in_array($arRes['USER_ID'], $arAccessUsers['WRITE']);
             }
         }
         if (!$hasAccess) {
             $GLOBALS['APPLICATION']->ThrowException('Access denied');
             return false;
         }
     }
     if (CTimeManEntry::Update($ID, array('ACTIVE' => 'Y'))) {
         CTimeManReport::Approve($ID);
         CTimeManReportDaily::SetActive($ID);
         CTimeManNotify::SendMessage($ID, 'U');
         return true;
     }
     return false;
 }
Beispiel #2
0
 function AddCommentToLog($arFields)
 {
     global $DB, $USER;
     CModule::IncludeModule("socialnetwork");
     $result = false;
     $LOG_ID = CTimeManNotify::SendMessage($arFields["ENTRY_ID"], 'A');
     $arMessFields = array("EVENT_ID" => "timeman_entry_comment", "ENTITY_ID" => $arFields["USER_ID"], "TEXT_MESSAGE" => $arFields["COMMENT_TEXT"], "MESSAGE" => $arFields["COMMENT_TEXT"], "USER_ID" => $arFields["USER_ID"], "ENTITY_TYPE" => SONET_TIMEMAN_ENTRY_ENTITY, "LOG_ID" => $LOG_ID, "=LOG_DATE" => $DB->CurrentTimeFunction());
     $result = CSocNetLogComments::Add($arMessFields, true, false);
     CSocNetLog::CounterIncrement($result, false, false, "LC");
     $curUser = $USER->GetID();
     $dbLogRights = CSocNetLogRights::GetList(array(), array("LOG_ID" => $LOG_ID));
     while ($arRight = $dbLogRights->Fetch()) {
         $arRights[] = $arRight["GROUP_CODE"];
     }
     if (!in_array("U" . $curUser, $arRights)) {
         CSocNetLogRights::Add($LOG_ID, "U" . $curUser);
     }
     return $result;
 }
Beispiel #3
0
 public function CloseDay($timestamp = false, $report = '', $bFieldsOnly = false)
 {
     global $APPLICATION;
     if (($last_entry = $this->_GetLastData(true)) && (!$last_entry['DATE_FINISH'] || $last_entry['PAUSED'] == 'Y')) {
         if ($this->OpenAction($bSkipCheck) === 'REOPEN') {
             $last_entry = $this->ReopenDay();
         }
         if ($timestamp <= 0) {
             $timestamp = false;
         } else {
             $timestamp = CTimeMan::ConvertShortTS($timestamp - CTimeZone::GetOffset(), ConvertTimeStamp(MakeTimeStamp($last_entry['DATE_START'], FORMAT_DATETIME), 'SHORT'));
         }
         if ($this->State() == 'EXPIRED' && !$timestamp) {
             $GLOBALS['APPLICATION']->ThrowException('Workday is expired', 'WD_EXPIRED');
             return false;
         }
         $arFields = array('USER_ID' => $this->USER_ID, 'DATE_START' => $last_entry['DATE_START'], 'DATE_FINISH' => ConvertTimeStamp(($timestamp ? $timestamp : time()) + CTimeZone::GetOffset(), 'FULL'), 'PAUSED' => 'N');
         if (!$this->isEntryValid('CLOSE', $timestamp)) {
             $arFields['ACTIVE'] = 'N';
             if (strlen($report) > 0) {
                 $arFields['REPORTS'] = array();
                 if ($ex = $APPLICATION->GetException()) {
                     $arFields['REPORTS'][] = array('REPORT_TYPE' => 'ERR_CLOSE', 'REPORT' => $ex->GetId() . ';' . date('c') . ';' . $ex->GetString());
                 }
                 $arFields['REPORTS'][] = array('REPORT_TYPE' => 'REPORT_CLOSE', 'REPORT' => $report);
             } else {
                 if ($ex = $APPLICATION->GetException()) {
                     $APPLICATION->ThrowException($ex->GetString(), 'REPORT_NEEDED');
                 }
                 return false;
             }
         }
         if ($timestamp === false) {
             $timestamp = time();
         }
         if ($timestamp + CTimeZone::GetOffset() < MakeTimeStamp($last_entry['DATE_START'])) {
             return false;
         }
         $arFields['IP_CLOSE'] = $_SERVER['REMOTE_ADDR'];
         if ($bFieldsOnly) {
             return $arFields;
         } else {
             if (CTimeManEntry::Update($last_entry['ID'], $arFields)) {
                 if (isset($arFields['ACTIVE']) && $arFields['ACTIVE'] == 'N') {
                     CTimeManNotify::SendMessage($last_entry['ID']);
                 }
                 return $this->_GetLastData(true);
             }
         }
     } else {
         $GLOBALS['APPLICATION']->ThrowException('WD_NOT_OPEN');
     }
     return false;
 }