Example #1
0
	/**
	 * @param \CHelpdeskUser $oUser
	 * @param \CApiHelpdeskManager $oApiHelpdesk
	 * @param \CApiFilestorageManager $oApiFilestorage
	 */
	public function PopulateContent($oUser, $oApiHelpdesk, $oApiFilestorage)
	{
		$aHash = \CApi::DecodeKeyValues($this->Hash);
		if (isset($aHash['StorageType'], $aHash['Path'], $aHash['Name']) && $oApiHelpdesk && $oApiFilestorage)
		{
			$oHelpdeskUserFromAttachment = null;
			if (isset($aHash['HelpdeskUserID'], $aHash['HelpdeskTenantID']))
			{
				if ($oUser && $aHash['HelpdeskUserID'] === $oUser->IdHelpdeskUser)
				{
					$oHelpdeskUserFromAttachment = $oUser;
				}
				else
				{
					$oHelpdeskUserFromAttachment = $oApiHelpdesk->GetUserById(
						$aHash['HelpdeskTenantID'], $aHash['HelpdeskUserID']);
				}
			}

			if ($oHelpdeskUserFromAttachment && $oApiFilestorage->FileExists(
					$oHelpdeskUserFromAttachment, $aHash['StorageType'], $aHash['Path'], $aHash['Name']
			))
			{
				$mResult = $oApiFilestorage->GetFile(
					$oHelpdeskUserFromAttachment, $aHash['StorageType'], $aHash['Path'], $aHash['Name']
				);

				if (is_resource($mResult))
				{
					$this->Content = stream_get_contents($mResult);
				}
			}
		}
	}
Example #2
0
 public function AjaxHelpdeskPostCreate()
 {
     $oAccount = null;
     $oUser = $this->getHelpdeskAccountFromParam($oAccount);
     /* @var $oAccount CAccount */
     $iThreadId = (int) $this->getParamValue('ThreadId', 0);
     $sSubject = trim((string) $this->getParamValue('Subject', ''));
     $sText = trim((string) $this->getParamValue('Text', ''));
     $sCc = trim((string) $this->getParamValue('Cc', ''));
     $sBcc = trim((string) $this->getParamValue('Bcc', ''));
     $bIsInternal = '1' === (string) $this->getParamValue('IsInternal', '0');
     $mAttachments = $this->getParamValue('Attachments', null);
     if (0 === strlen($sText) || 0 === $iThreadId && 0 === strlen($sSubject)) {
         throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::InvalidInputParameter);
     }
     $mResult = false;
     $bIsNew = false;
     $oThread = null;
     if (0 === $iThreadId) {
         $bIsNew = true;
         $oThread = new \CHelpdeskThread();
         $oThread->IdTenant = $oUser->IdTenant;
         $oThread->IdOwner = $oUser->IdHelpdeskUser;
         $oThread->Type = \EHelpdeskThreadType::Pending;
         $oThread->Subject = $sSubject;
         if (!$this->ApiHelpdesk()->createThread($oUser, $oThread)) {
             $oThread = null;
         }
     } else {
         $oThread = $this->ApiHelpdesk()->getThreadById($oUser, $iThreadId);
     }
     if ($oThread && 0 < $oThread->IdHelpdeskThread) {
         $oPost = new \CHelpdeskPost();
         $oPost->IdTenant = $oUser->IdTenant;
         $oPost->IdOwner = $oUser->IdHelpdeskUser;
         $oPost->IdHelpdeskThread = $oThread->IdHelpdeskThread;
         $oPost->Type = $bIsInternal ? \EHelpdeskPostType::Internal : \EHelpdeskPostType::Normal;
         $oPost->SystemType = \EHelpdeskPostSystemType::None;
         $oPost->Text = $sText;
         $aResultAttachment = array();
         if (is_array($mAttachments) && 0 < count($mAttachments)) {
             foreach ($mAttachments as $sTempName => $sHash) {
                 $aDecodeData = \CApi::DecodeKeyValues($sHash);
                 if (!isset($aDecodeData['HelpdeskUserID'])) {
                     continue;
                 }
                 $rData = $this->ApiFileCache()->getFile($oUser, $sTempName);
                 if ($rData) {
                     $iFileSize = $this->ApiFileCache()->fileSize($oUser, $sTempName);
                     $sThreadID = (string) $oThread->IdHelpdeskThread;
                     $sThreadID = str_pad($sThreadID, 2, '0', STR_PAD_LEFT);
                     $sThreadIDSubFolder = substr($sThreadID, 0, 2);
                     $sThreadFolderName = API_HELPDESK_PUBLIC_NAME . '/' . $sThreadIDSubFolder . '/' . $sThreadID;
                     $this->oApiFilestorage->createFolder($oUser, \EFileStorageTypeStr::Corporate, '', $sThreadFolderName);
                     $sUploadName = isset($aDecodeData['Name']) ? $aDecodeData['Name'] : $sTempName;
                     $this->oApiFilestorage->createFile($oUser, \EFileStorageTypeStr::Corporate, $sThreadFolderName, $sUploadName, $rData, false);
                     $oAttachment = new \CHelpdeskAttachment();
                     $oAttachment->IdHelpdeskThread = $oThread->IdHelpdeskThread;
                     $oAttachment->IdHelpdeskPost = $oPost->IdHelpdeskPost;
                     $oAttachment->IdOwner = $oUser->IdHelpdeskUser;
                     $oAttachment->IdTenant = $oUser->IdTenant;
                     $oAttachment->FileName = $sUploadName;
                     $oAttachment->SizeInBytes = $iFileSize;
                     $oAttachment->encodeHash($oUser, $sThreadFolderName);
                     $aResultAttachment[] = $oAttachment;
                 }
             }
             if (is_array($aResultAttachment) && 0 < count($aResultAttachment)) {
                 $oPost->Attachments = $aResultAttachment;
             }
         }
         $mResult = $this->ApiHelpdesk()->createPost($oUser, $oThread, $oPost, $bIsNew, true, $sCc, $sBcc);
         if ($mResult) {
             $mResult = array('ThreadId' => $oThread->IdHelpdeskThread, 'ThreadIsNew' => $bIsNew);
         }
     }
     return $this->DefaultResponse($oAccount, __FUNCTION__, $mResult);
 }