/** * This function will process uploaded file * * @param array $uploaded_file * @param boolean $create_revision Create new revision or update last one * @param string $revision_comment Revision comment, if any * @return ProjectFileRevision */ function handleUploadedFile($uploaded_file, $create_revision = true, $revision_comment = '') { $revision = null; if (!$create_revision) { $revision = $this->getLastRevision(); } // if if (!$revision instanceof ProjectFileRevision) { $revision = new ProjectFileRevision(); $revision->setFileId($this->getId()); $revision->setRevisionNumber($this->getNextRevisionNumber()); if (trim($revision_comment) == '' && $this->countRevisions() < 1) { $revision_comment = lang('initial versions'); } // if } // if $revision->deleteThumb(false); // remove thumb // We have a file to handle! //executes only while uploading files if (!is_array($uploaded_file) || !isset($uploaded_file['name']) || !isset($uploaded_file['size']) || !isset($uploaded_file['type']) || (!isset($uploaded_file['tmp_name']) || !is_readable($uploaded_file['tmp_name']))) { throw new InvalidUploadError($uploaded_file); } // if if (isset($uploaded_file['error']) && $uploaded_file['error'] > UPLOAD_ERR_OK) { throw new InvalidUploadError($uploaded_file); } // if //eyedoc MOD $extension = get_file_extension(basename($uploaded_file['name'])); if ($uploaded_file['type'] == 'application/octet-stream' && $extension == 'eyedoc') { $uploaded_file['type'] = 'text/html'; } //eyedoc MOD // calculate hash if ($revision->columnExists('hash')) { $hash = hash_file("sha256", $uploaded_file['tmp_name']); $revision->setColumnValue('hash', $hash); } $repository_id = FileRepository::addFile($uploaded_file['tmp_name'], array('name' => $uploaded_file['name'], 'type' => $uploaded_file['type'], 'size' => $uploaded_file['size'])); $revision->setRepositoryId($repository_id); $revision->deleteThumb(false); $revision->setFilesize($uploaded_file['size']); if (config_option('detect_mime_type_from_extension')) { $type = Mime_Types::instance()->get_type($extension); if ($type) { $revision->setTypeString($type); } else { $revision->setTypeString($uploaded_file['type']); } } else { $revision->setTypeString($uploaded_file['type']); } if (trim($extension)) { $file_type = FileTypes::getByExtension($extension); if ($file_type instanceof Filetype) { $revision->setFileTypeId($file_type->getId()); } // if } // if $revision->setComment($revision_comment); $revision->save(); $this->last_revision = $revision; // update last revision return $revision; }
/** * Edit file properties * * @access public * @param void * @return null */ function edit_file() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $this->setTemplate('add_file'); $file = ProjectFiles::findById(get_id()); if(!($file instanceof ProjectFile)) { flash_error(lang('file dnx')); ajx_current("empty"); return; } // if if(!$file->canEdit(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $file_data = array_var($_POST, 'file'); if(!is_array($file_data)) { $file_data = array( 'description' => $file->getDescription(), 'edit_name' => $file->getFilename(), 'file_id' => get_id() ); // array } // if tpl_assign('file', $file); tpl_assign('file_data', $file_data); if(is_array(array_var($_POST, 'file'))) { try { DB::beginWork(); $handle_file = array_var($file_data, 'update_file') == 'checked'; // change file? $post_revision = $handle_file && array_var($file_data, 'version_file_change') == 'checked'; // post revision? $revision_comment = trim(array_var($file_data, 'revision_comment')); // user comment? $file->setFromAttributes($file_data); $file->setFilename(array_var($file_data, 'name')); if ($file->getType() == ProjectFiles::TYPE_WEBLINK) { $url = array_var($file_data, 'url', ''); if ($url && strpos($url, ':') === false) { $url = $this->protocol . $url; } $file->setUrl($url); $revision = $file->getLastRevision(); /* @var $revision ProjectFileRevision */ if (!$revision instanceof ProjectFileRevision || array_var($file_data, 'version_file_change') == 'checked') { $revision = new ProjectFileRevision(); $revision->setFileId($file->getId()); $revision->setRevisionNumber($file->getNextRevisionNumber()); $revision->setFileTypeId(FileTypes::getByExtension('webfile')->getId()); $revision->setRepositoryId('webfile'); $revision->setComment($revision_comment); } $revision->setTypeString($file->getUrl()); $revision->save(); } $file->save(); if( $handle_file) { // handle uploaded file $upload_id = array_var($file_data, 'upload_id'); $uploaded_file = array_var($_SESSION, $upload_id, array()); $file->handleUploadedFile($uploaded_file, $post_revision, $revision_comment); // handle uploaded file @unlink($uploaded_file['tmp_name']); } // if $member_ids = json_decode(array_var($_POST, 'members')); $object_controller = new ObjectController(); $object_controller->add_to_members($file, $member_ids); $object_controller->link_to_new_object($file); $object_controller->add_subscribers($file); $object_controller->add_custom_properties($file); $file->resetIsRead(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_EDIT); DB::commit(); flash_success(lang('success edit file', $file->getFilename())); ajx_current("back"); } catch(Exception $e) { DB::rollback(); ajx_current("empty"); flash_error($e->getMessage()); } // try } // if } // edit_file
} $description .= '<tr><td>' . lang('date') . ':</td><td>' . format_datetime($email->getSentDate(), 'l, j F Y - '.$time_format, logged_user()->getTimezone()) . '</td></tr>'; if ($email->getHasAttachments() && is_array($attachments) && count($attachments) > 0) { $description .= '<tr><td colspan=2> <fieldset> <legend class="toggle_collapsed" onclick="og.toggle(\'mv_attachments\',this)">' . lang('attachments') . '</legend> <div id="mv_attachments" style="display:none"> <table>'; foreach($attachments as $att) { if (!array_var($att, 'hide')) { $size = $att['size'];//format_filesize(strlen($att["Data"])); $fName = str_starts_with($att["FileName"], "=?") ? iconv_mime_decode($att["FileName"], 0, "UTF-8") : utf8_safe($att["FileName"]); if (trim($fName) == "" && strlen($att["FileName"]) > 0) $fName = utf8_encode($att["FileName"]); $description .= '<tr><td style="padding-right: 10px">'; $ext = get_file_extension($fName); $fileType = FileTypes::getByExtension($ext); if (isset($fileType)) $icon = $fileType->getIcon(); else $icon = "unknown.png"; $download_url = get_url('mail', 'download_attachment', array('email_id' => $email->getId(), 'attachment_id' => $c)); include_once ROOT . "/library/browser/Browser.php"; if (Browser::instance()->getBrowser() == Browser::BROWSER_IE) { $download_url = "javascript:location.href = '$download_url';"; } $description .= '<img src="' . get_image_url("filetypes/" . $icon) .'"></td> <td><a target="_self" href="' . $download_url . '">' . clean($fName) . " ($size)" . '</a></td></tr>'; } $c++; } $description .= '</table></div></fieldset></td></tr>';
/** * Edit file properties * * @access public * @param void * @return null */ function edit_file() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $this->setTemplate('add_file'); $file = ProjectFiles::findById(get_id()); if (!$file instanceof ProjectFile) { flash_error(lang('file dnx')); ajx_current("empty"); return; } // if if (!$file->canEdit(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $file_data = array_var($_POST, 'file'); if (!is_array($file_data)) { // set layout for modal form if (array_var($_REQUEST, 'modal')) { $this->setLayout("json"); tpl_assign('modal', true); } $file_data = array('description' => $file->getDescription(), 'attach_to_notification' => $file->getAttachToNotification(), 'default_subject' => $file->getDefaultSubject(), 'file_id' => get_id()); // array } // if tpl_assign('file', $file); tpl_assign('file_data', $file_data); if (is_array(array_var($_POST, 'file'))) { foreach ($file_data as $k => &$v) { $v = remove_scripts($v); } try { DB::beginWork(); $handle_file = array_var($file_data, 'update_file'); // change file? $post_revision = $handle_file && array_var($file_data, 'version_file_change'); // post revision? $revision_comment = trim(array_var($file_data, 'revision_comment')); // user comment? $file->setFromAttributes($file_data); $file->setAttachToNotification(array_var($file_data, 'attach_to_notification')); if (array_var($file_data, 'default_subject_sel') == 'subject') { $file->setDefaultSubject(array_var($file_data, 'default_subject_text')); } else { $file->setDefaultSubject(''); } $fname = array_var($file_data, 'name'); $ext = trim(array_var($file_data, 'extension')); if ($ext != '') { $fname .= "." . $ext; } $file->setFilename($fname); if ($file->getType() == ProjectFiles::TYPE_WEBLINK) { $url = array_var($file_data, 'url', ''); if ($url && strpos($url, ':') === false) { $url = $this->protocol . $url; } $file->setUrl($url); $revision = $file->getLastRevision(); /* @var $revision ProjectFileRevision */ if (!$revision instanceof ProjectFileRevision || $post_revision) { $revision = new ProjectFileRevision(); $revision->setFileId($file->getId()); $revision->setRevisionNumber($file->getNextRevisionNumber()); $revision->setFileTypeId(FileTypes::getByExtension('webfile')->getId()); $revision->setRepositoryId('webfile'); $revision->setComment($revision_comment); } $revision->setTypeString($file->getUrl()); $revision->save(); } $file->save(); if ($handle_file) { // handle uploaded file $upload_id = array_var($file_data, 'upload_id'); $uploaded_file = array_var($_SESSION, $upload_id, array()); $file->handleUploadedFile($uploaded_file, $post_revision, $revision_comment); // handle uploaded file @unlink($uploaded_file['tmp_name']); } // if $member_ids = json_decode(array_var($_POST, 'members')); $object_controller = new ObjectController(); $object_controller->add_to_members($file, $member_ids); $object_controller->link_to_new_object($file); $object_controller->add_subscribers($file); $object_controller->add_custom_properties($file); $file->resetIsRead(); DB::commit(); set_user_config_option('notify_myself_too', array_var($file_data, 'notify_myself_too')); if (array_var($file_data, 'notify_myself_too')) { logged_user()->notify_myself = true; } ApplicationLogs::createLog($file, ApplicationLogs::ACTION_EDIT); if (array_var($file_data, 'notify_myself_too')) { logged_user()->notify_myself = false; } flash_success(lang('success edit file', $file->getFilename())); ajx_current("back"); if (array_var($_REQUEST, 'modal')) { evt_add("reload current panel"); } } catch (Exception $e) { DB::rollback(); if (array_var($_REQUEST, 'modal')) { $this->setLayout("json"); $this->setTemplate(get_template_path("empty")); print_modal_json_response(array('errorCode' => 1, 'errorMessage' => $e->getMessage(), 'showMessage' => 1), true, true); } else { flash_error($e->getMessage()); } ajx_current("empty"); } // try } // if }
/** * Edit file properties * * @access public * @param void * @return null */ function edit_file() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $this->setTemplate('add_file'); $file = ProjectFiles::findById(get_id()); if (!$file instanceof ProjectFile) { flash_error(lang('file dnx')); ajx_current("empty"); return; } // if if (!$file->canEdit(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $file_data = array_var($_POST, 'file'); if (!is_array($file_data)) { $tag_names = $file->getTagNames(); $file_data = array('description' => $file->getDescription(), 'is_private' => $file->getIsPrivate(), 'is_important' => $file->getIsImportant(), 'comments_enabled' => $file->getCommentsEnabled(), 'anonymous_comments_enabled' => $file->getAnonymousCommentsEnabled(), 'tags' => is_array($tag_names) && count($tag_names) ? implode(', ', $tag_names) : '', 'edit_name' => $file->getFilename(), 'file_id' => get_id()); // array } // if tpl_assign('file', $file); tpl_assign('file_data', $file_data); if (is_array(array_var($_POST, 'file'))) { try { $old_is_private = $file->isPrivate(); $old_is_important = $file->getIsImportant(); $old_comments_enabled = $file->getCommentsEnabled(); $old_anonymous_comments_enabled = $file->getAnonymousCommentsEnabled(); DB::beginWork(); $handle_file = array_var($file_data, 'update_file') == 'checked'; // change file? $post_revision = $handle_file && array_var($file_data, 'version_file_change') == 'checked'; // post revision? $revision_comment = trim(array_var($file_data, 'revision_comment')); // user comment? $file->setFromAttributes($file_data); $file->setFilename(array_var($file_data, 'name')); if ($file->getType() == ProjectFiles::TYPE_WEBLINK) { $url = array_var($file_data, 'url', ''); if ($url && strpos($url, ':') === false) { $url = "http://" . $url; } $file->setUrl($url); $revision = $file->getLastRevision(); if (!$revision instanceof ProjectFileRevision || array_var($file_data, 'version_file_change') == 'checked') { $revision = new ProjectFileRevision(); $revision->setFileId($file->getId()); $revision->setRevisionNumber($file->getNextRevisionNumber()); $revision->setFileTypeId(FileTypes::getByExtension('webfile')->getId()); $revision->setRepositoryId('webfile'); $revision->setComment($revision_comment); } $revision->setTypeString($file->getUrl()); $revision->save(); } if (!logged_user()->isMemberOfOwnerCompany()) { $file->setIsPrivate($old_is_private); $file->setIsImportant($old_is_important); $file->setCommentsEnabled($old_comments_enabled); $file->setAnonymousCommentsEnabled($old_anonymous_comments_enabled); } // if //$file->setFilename(array_var($file_data, 'name')); $file->save(); $file->setTagsFromCSV(array_var($file_data, 'tags')); if ($handle_file) { // handle uploaded file $upload_id = array_var($file_data, 'upload_id'); $uploaded_file = array_var($_SESSION, $upload_id, array()); $file->handleUploadedFile($uploaded_file, $post_revision, $revision_comment); // handle uploaded file @unlink($uploaded_file['tmp_name']); } // if $object_controller = new ObjectController(); $object_controller->add_to_workspaces($file); $object_controller->link_to_new_object($file); $object_controller->add_subscribers($file); $object_controller->add_custom_properties($file); $file->resetIsRead(); ApplicationLogs::createLog($file, $file->getWorkspaces(), ApplicationLogs::ACTION_EDIT); DB::commit(); flash_success(lang('success edit file', $file->getFilename())); ajx_current("back"); } catch (Exception $e) { //@unlink($file->getFilePath()); DB::rollback(); ajx_current("empty"); flash_error($e->getMessage()); } // try } // if }
/** * This function will process uploaded file * * @param array $uploaded_file * @param boolean $create_revision Create new revision or update last one * @param string $revision_comment Revision comment, if any * @return ProjectFileRevision */ function handleUploadedFile($uploaded_file, $create_revision = true, $revision_comment = '') { $revision = null; if (!$create_revision) { $revision = $this->getLastRevision(); } // if if (!$revision instanceof ProjectFileRevision) { $revision = new ProjectFileRevision(); $revision->setFileId($this->getId()); $revision->setRevisionNumber($this->getNextRevisionNumber()); if (trim($revision_comment) == '' && $this->countRevisions() < 1) { $revision_comment = lang('initial versions'); } // if } // if $revision->deleteThumb(false); // remove thumb // We have a file to handle! if (!is_array($uploaded_file) || !isset($uploaded_file['name']) || !isset($uploaded_file['size']) || !isset($uploaded_file['type']) || !isset($uploaded_file['tmp_name']) || !is_readable($uploaded_file['tmp_name'])) { throw new InvalidUploadError($uploaded_file); } // if if (isset($uploaded_file['error']) && $uploaded_file['error'] > UPLOAD_ERR_OK) { throw new InvalidUploadError($uploaded_file); } // if $repository_id = FileRepository::addFile($uploaded_file['tmp_name'], array('name' => $uploaded_file['name'], 'type' => $uploaded_file['type'], 'size' => $uploaded_file['size'])); $revision->setRepositoryId($repository_id); $revision->deleteThumb(false); $revision->setFilesize($uploaded_file['size']); $revision->setFilename($uploaded_file['name']); $revision->setTypeString($uploaded_file['type']); $extension = get_file_extension(basename($uploaded_file['name'])); if (trim($extension)) { $file_type = FileTypes::getByExtension($extension); if ($file_type instanceof Filetype) { $revision->setFileTypeId($file_type->getId()); } // if } // if $revision->setComment($revision_comment); $revision->save(); $this->last_revision = $revision; // update last revision return $revision; }
/** * Restore project file revisions from attributes.php * Use this when table ProjectFileRevisions is empty * @param void * @return null */ function repair() { $attributes = include ROOT . '/upload/attributes.php'; foreach ($attributes as $k => $v) { $files = ProjectFiles::findAll(array( 'conditions' => array('`filename` = ?', $v['name']) )); // findAll foreach ($files as $file) { $id = $file->getId(); $repository_id = $k; $revision = new ProjectFileRevision(); $revision->setFileId($id); $revision->setRepositoryId($repository_id); $revision->deleteThumb(false); $revision->setFilesize($v['size']); $revision->setFilename($v['name']); $revision->setTypeString($v['type']); $extension = get_file_extension(basename($v['name'])); if (trim($extension)) { $file_type = FileTypes::getByExtension($extension); if ($file_type instanceof Filetype) { $revision->setFileTypeId($file_type->getId()); } // if } // if $revision->setComment('-- Initial version --'); $revision->save(); } } $this->redirectTo('files', 'index'); }
/** * Validate before save * * @param array $error * @return null */ function validate(&$errors) { $extension = get_file_extension(basename($this->getFilename())); $known_type = FileTypes::getByExtension($extension); if (!$this->validatePresenceOf('name') || $this->getFilename() == "." . $extension && $known_type instanceof FileType) { $errors[] = lang('filename required'); } if ($this->getType() != ProjectFiles::TYPE_DOCUMENT) { if (!$this->validatePresenceOf('url') || $this->getUrl() == 'http://') { $errors[] = lang('weblink required'); } // if } }
function classifyFile($classification_data, $email, $parsedEmail, $members, $remove_prev, $use_transaction) { if (!is_array($classification_data)) { $classification_data = array(); } if (!isset($parsedEmail["Attachments"])) { return; //throw new Exception(lang('no attachments found for email')); } $account_owner = logged_user() instanceof contact ? logged_user() : Contacts::findById($email->getAccount()->getContactId()); for ($c = 0; $c < count($classification_data); $c++) { if (isset($classification_data["att_" . $c]) && $classification_data["att_" . $c] && isset($parsedEmail["Attachments"][$c])) { // dont classify inline images if (array_var($parsedEmail["Attachments"][$c], 'FileDisposition') == 'attachment') { $att = $parsedEmail["Attachments"][$c]; $fName = str_starts_with($att["FileName"], "=?") ? iconv_mime_decode($att["FileName"], 0, "UTF-8") : utf8_safe($att["FileName"]); if (trim($fName) == "" && strlen($att["FileName"]) > 0) { $fName = utf8_encode($att["FileName"]); } $extension = get_file_extension(basename($fName)); $type_file_allow = FileTypes::getByExtension($extension); if (!$type_file_allow instanceof FileType || $type_file_allow->getIsAllow() == 1) { try { $remove_previous_members = $remove_prev; // check for file name and size, if there are some then compare the contents, if content is equal do not classify the attachment. $file_exists = 0; $possible_equal_file_rows = DB::executeAll("SELECT * FROM " . TABLE_PREFIX . "project_file_revisions r \r\n\t\t\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "objects o ON o.id=r.file_id \r\n\t\t\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "project_files f ON f.object_id=r.file_id\r\n\t\t\t\t\t\t\t\tWHERE o.name=" . DB::escape($fName) . " AND r.filesize='" . strlen($att["Data"]) . "' \r\n\t\t\t\t\t\t\t\tAND r.revision_number=(SELECT max(r2.revision_number) FROM " . TABLE_PREFIX . "project_file_revisions r2 WHERE r2.file_id=r.file_id)"); if (is_array($possible_equal_file_rows)) { foreach ($possible_equal_file_rows as $row) { $content = FileRepository::getFileContent($row['repository_id']); if ($content == $att['Data']) { // file already exists $file_exists = $row['file_id']; //Logger::log($email->getId()." - ".$row['mail_id']." - $fName"); if ($remove_previous_members && $row['mail_id'] != $email->getId()) { $remove_previous_members = false; } break; } } } if ($file_exists > 0) { $file = ProjectFiles::findById($file_exists); } else { $file = ProjectFiles::findOne(array('conditions' => "mail_id = " . $email->getId() . " AND o.name = " . DB::escape($fName) . "")); } if ($use_transaction) { DB::beginWork(); } if ($file == null) { $fileIsNew = true; $file = new ProjectFile(); $file->setFilename($fName); $file->setIsVisible(true); $file->setMailId($email->getId()); $file->setCreatedById($account_owner->getId()); $file->save(); } else { $fileIsNew = false; } if ($remove_previous_members) { $dim_ids = array(0); foreach ($members as $m) { $dim_ids[$m->getDimensionId()] = $m->getDimensionId(); } ObjectMembers::delete('`object_id` = ' . $file->getId() . ' AND `member_id` IN (SELECT `m`.`id` FROM `' . TABLE_PREFIX . 'members` `m` WHERE `m`.`dimension_id` IN (' . implode(',', $dim_ids) . '))'); } $file->addToMembers($members); // fill sharing table in background add_object_to_sharing_table($file, $account_owner); //$file->addToSharingTable(); $enc = array_var($parsedMail, 'Encoding', 'UTF-8'); $ext = utf8_substr($fName, strrpos($fName, '.') + 1, utf8_strlen($fName, $enc), $enc); $mime_type = ''; if (Mime_Types::instance()->has_type($att["content-type"])) { $mime_type = $att["content-type"]; //mime type is listed & valid } else { $mime_type = Mime_Types::instance()->get_type($ext); //Attempt to infer mime type } $userid = logged_user() ? logged_user()->getId() : "0"; $tempFileName = ROOT . "/tmp/" . $userid . "x" . gen_id(); $fh = fopen($tempFileName, 'w') or die("Can't open file"); fwrite($fh, $att["Data"]); fclose($fh); $fileToSave = array("name" => $fName, "type" => $mime_type, "tmp_name" => $tempFileName, "error" => 0, "size" => filesize($tempFileName)); if ($fileIsNew || !$file->getLastRevision() instanceof ProjectFileRevision) { $revision = $file->handleUploadedFile($fileToSave, true, lang('attachment from email', $email->getSubject())); // handle uploaded file $revision->setCreatedById($account_owner->getId()); $revision->save(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ADD); /* }else{ $revision = $file->getLastRevision(); $new_hash = hash_file("sha256", $tempFileName); if ($revision->getHash() != $new_hash) { $revision = $file->handleUploadedFile($fileToSave, true, lang('attachment from email', $email->getSubject())); // handle uploaded file ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ADD); }*/ } if ($use_transaction) { DB::commit(); } // Error... } catch (Exception $e) { if ($use_transaction) { DB::rollback(); } flash_error($e->getMessage()); ajx_current("empty"); } } else { flash_error(lang('file extension no allow classify', $fName)); } if (isset($tempFileName) && is_file($tempFileName)) { unlink($tempFileName); } } } } }
function classifyFile($classification_data, $email, $parsedEmail, $members, $remove_prev) { if (!is_array($classification_data)) $classification_data = array(); if (!isset($parsedEmail["Attachments"])) { return; //throw new Exception(lang('no attachments found for email')); } $account_owner = logged_user() instanceof contact ? logged_user() : Contacts::findById($email->getAccount()->getContactId()); for ($c = 0; $c < count($classification_data); $c++) { if (isset($classification_data["att_".$c]) && $classification_data["att_".$c]) { $att = $parsedEmail["Attachments"][$c]; $fName = str_starts_with($att["FileName"], "=?") ? iconv_mime_decode($att["FileName"], 0, "UTF-8") : utf8_safe($att["FileName"]); if (trim($fName) == "" && strlen($att["FileName"]) > 0) $fName = utf8_encode($att["FileName"]); $extension = get_file_extension(basename($fName)); $type_file_allow = FileTypes::getByExtension($extension); if(!($type_file_allow instanceof FileType) || $type_file_allow->getIsAllow() == 1){ try { //$sql = "SELECT o.id FROM ".TABLE_PREFIX."objects o,".TABLE_PREFIX."project_files f WHERE o.id = f.object_id AND f.mail_id = ".$email->getId()." AND o.name = ".DB::escape($fName).""; $sql = "SELECT o.id FROM ".TABLE_PREFIX."objects o,".TABLE_PREFIX."project_files f WHERE o.id = f.object_id AND o.name = ".DB::escape($fName).""; $db_res = DB::execute($sql); $row = $db_res->fetchRow(); $file = ProjectFiles::findById($row['id']); DB::beginWork(); if ($file == null){ $fileIsNew = true; $file = new ProjectFile(); $file->setFilename($fName); $file->setIsVisible(true); $file->setMailId($email->getId()); $file->save(); $object_controller = new ObjectController(); $object_controller->add_to_members($file, array(), $account_owner); } else { $fileIsNew = false; } if($remove_prev){ $dim_ids = array(0); foreach ($members as $m) $dim_ids[$m->getDimensionId()] = $m->getDimensionId(); ObjectMembers::delete('`object_id` = ' . $file->getId() . ' AND `member_id` IN (SELECT `m`.`id` FROM `'.TABLE_PREFIX.'members` `m` WHERE `m`.`dimension_id` IN ('.implode(',',$dim_ids).'))'); } $file->addToMembers($members); $file->addToSharingTable(); $enc = array_var($parsedMail,'Encoding','UTF-8'); $ext = utf8_substr($fName, strrpos($fName, '.') + 1, utf8_strlen($fName, $enc), $enc); $mime_type = ''; if (Mime_Types::instance()->has_type($att["content-type"])) { $mime_type = $att["content-type"]; //mime type is listed & valid } else { $mime_type = Mime_Types::instance()->get_type($ext); //Attempt to infer mime type } $userid = logged_user() ? logged_user()->getId() : "0"; $tempFileName = ROOT ."/tmp/". $userid ."x". gen_id(); $fh = fopen($tempFileName, 'w') or die("Can't open file"); fwrite($fh, $att["Data"]); fclose($fh); $fileToSave = array( "name" => $fName, "type" => $mime_type, "tmp_name" => $tempFileName, "error" => 0, "size" => filesize($tempFileName) ); if ($fileIsNew) { $revision = $file->handleUploadedFile($fileToSave, true, lang('attachment from email', $email->getSubject())); // handle uploaded file ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ADD); }else{ $revision = $file->getLastRevision(); $new_hash = hash_file("sha256", $tempFileName); if ($revision->getHash() != $new_hash) { $revision = $file->handleUploadedFile($fileToSave, true, lang('attachment from email', $email->getSubject())); // handle uploaded file ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ADD); } } DB::commit(); // Error... } catch(Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } }else{ flash_error(lang('file extension no allow classify', $fName)); } if (isset($tempFileName) && is_file($tempFileName)) unlink($tempFileName); } } }