protected function initParams(&$params)
 {
     CoreUtils::checkConstraint(is_null($params) || is_array($params));
     if (!empty($params)) {
         $this->params = $params;
     } else {
         $this->params = array();
     }
 }
    public function getChildrenCount(&$record)
    {
        CoreUtils::checkConstraint(!empty($record['id']));
        $db = CoreServices2::getDB();
        $sql = '
			SELECT COUNT(*) AS num
			FROM subpage
			WHERE
				subpageParentId = ' . $db->prepareInputValue($record['id']);
        $row = $db->getRow($sql);
        return $row['num'];
    }
 protected function addDynamicImageInfo(&$imageData)
 {
     if (count($imageData) < 4 || count($imageData) > 7) {
         throw new CoreException('Invalid number of arguments supplied for image from database in email template!');
     }
     $image = $fileDAO->getRecordById($imageData[1]);
     CoreUtils::checkConstraint(!empty($image['id']));
     $fullName = $image['fileBaseName'] . '.' . $image['fileExtension'];
     $options = $this->getDynamicImageOptions($imageData);
     $resizedImagePath = $files->getResizedImageDiskPath($image['fileBaseName'], $image['fileExtension'], $options);
     if (!file_exists($resizedImagePath)) {
         $imagePath = $files->getDiskPath($image['fileBaseName'], $image['fileExtension']);
         $files->resizeImage($resizedImagePath, $image['fileBaseName'], $image['fileExtension'], $options);
     }
     $this->attachments[] = array('cid' => $cid, 'fileName' => $fullName, 'filePath' => $resizedImagePath, 'mimeType' => $image['fileMimeType']);
 }
 protected function decodePHPUploadError($errorCode)
 {
     CoreUtils::checkConstraint($errorCode != UPLOAD_ERR_OK);
     switch ($errorCode) {
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             return 'fileTooBig';
         case UPLOAD_ERR_PARTIAL:
             return 'fileUploadedPartially';
         case UPLOAD_ERR_NO_FILE:
             return 'fileNotUploaded';
         case UPLOAD_ERR_NO_TMP_DIR:
         case UPLOAD_ERR_NO_TMP_DIR:
         case UPLOAD_ERR_EXTENSION:
         default:
             return 'fileUploadUnknownError';
     }
 }
 protected function checkDataConsistency()
 {
     $attachmentTypes = CoreConfig::get('FileUpload', 'swfUploadAttachmentTypes');
     $fileCategory = $this->fileRecord['fileCategory'];
     $recordType = $this->fileRecord['recordType'];
     if ($recordType == '_tmpRecord') {
         return;
     }
     $filePosition = $this->fileRecord['filePosition'];
     CoreUtils::checkConstraint(is_array($attachmentTypes[$recordType][$filePosition]));
     $minItems = $attachmentTypes[$recordType][$filePosition]['minItems'];
     if (!empty($minItems)) {
         $currentItems = $this->fileDAO->getCountByRecord($recordType, $this->baseRecord['id'], $fileCategory, $filePosition);
         if ($currentItems - 1 < $minItems) {
             $this->messageManager->addMessage('fileDeleteErrorTooFewAttachments');
             return;
         }
     }
 }
 public function save(&$record, &$uploadStruct = null)
 {
     CoreUtils::checkConstraint(!empty($uploadStruct) || !empty($record['id']));
     if (!empty($uploadStruct)) {
         $this->saveDiskFile($record, $uploadStruct, $record['fileCategory']);
     }
     if (empty($record['fileOrder'])) {
         $record['fileOrder'] = 0;
     }
     parent::save($record);
 }
 protected function checkSWFUploadLists()
 {
     CoreUtils::checkConstraint(!empty($this->errorMessageContainer));
     foreach ($this->swfAttachmentTypes as $listName => $listInfo) {
         if ($listInfo['minItems'] > 0 && sizeof($this->fileListOldValues[$listName]) < $listInfo['minItems']) {
             $this->errorMessageContainer->addMessage('errorTooFewItems_' . $listName);
         }
     }
 }
 protected function prepareData()
 {
     CoreUtils::checkConstraint(!empty($this->params['userRecord']['userEmail']));
 }
 public function checkTypeAndGetExtension($uploadStruct, $fileCategory)
 {
     CoreUtils::checkConstraint(is_array($uploadStruct));
     $allowedMimeTypes = CoreConfig::get('CoreFiles', 'allowedMimeTypes');
     $defaultExtensions = CoreConfig::get('CoreFiles', 'defaultExtensions');
     $mimeType = mime_content_type($uploadStruct['tmp_name']);
     if (!array_key_exists($mimeType, $defaultExtensions) || !array_key_exists($fileCategory, $allowedMimeTypes) || !in_array($mimeType, $allowedMimeTypes[$fileCategory])) {
         return null;
     }
     return $defaultExtensions[$mimeType];
 }
 protected function getPatternArray($pattern)
 {
     $patternLength = strlen($pattern);
     $patternArray = array();
     $patternArrayIndex = 0;
     for ($i = 0; $i < $patternLength; $i++) {
         if ($pattern[$i] == '<') {
             $patternArrayIndex++;
             $patternArray[$patternArrayIndex] = array('column', '');
         } elseif ($pattern[$i] == '>') {
             $patternArrayIndex++;
             $patternArray[$patternArrayIndex] = array('text', '');
         } else {
             CoreUtils::checkConstraint(isset($patternArray[$patternArrayIndex][1]));
             $patternArray[$patternArrayIndex][1] .= $pattern[$i];
         }
     }
     return $patternArray;
 }
 protected function setMessage($recordId, $message)
 {
     CoreUtils::checkConstraint(!empty($recordId));
     $this->messages[$recordId] = !empty($message) ? $message : false;
     CoreUtils::checkConstraint(isset($this->messages[$recordId]));
 }
 protected function checkDataConsistency()
 {
     $attachmentTypes = CoreConfig::get('FileUpload', 'swfUploadAttachmentTypes');
     $fileCategory = $this->form->getField('fileCategory')->getValue();
     $recordType = $this->form->getField('recordType')->getValue();
     CoreUtils::checkConstraint($recordType != '_tmpRecord');
     $filePosition = $this->form->getField('filePosition')->getValue();
     $record = $this->getBaseRecord();
     if (empty($record)) {
         $this->messageManager->addMessage('fileUploadErrorInvalidBaseRecordId');
         return;
     }
     if (!$this->hasUserPermissionsForRecord($recordType, $record)) {
         $this->messageManager->addMessage('fileUploadErrorNoPermission');
         return;
     }
     if (!array_key_exists($recordType, $attachmentTypes)) {
         $this->messageManager->addMessage('fileUploadErrorInvalidRecordType');
         return;
     }
     if (!array_key_exists($filePosition, $attachmentTypes[$recordType])) {
         $this->messageManager->addMessage('fileUploadErrorInvalidFilePosition');
         return;
     }
     if ($fileCategory != $attachmentTypes[$recordType][$filePosition]['fileCategory']) {
         $this->messageManager->addMessage('fileUploadErrorWrongCategory');
         return;
     }
     $maxItems = $attachmentTypes[$recordType][$filePosition]['maxItems'];
     if (!empty($maxItems)) {
         $currentItems = $this->fileDAO->getCountByRecord($recordType, $record['id'], $fileCategory, $filePosition);
         if ($currentItems + 1 > $maxItems) {
             $this->messageManager->addMessage('fileUploadErrorTooManyAttachments');
             return;
         }
     }
 }