/** * returns a target project file that can make $name */ public function handle($project, $file) { $deps = $this->dependency($project, $file); $recipe = $this->recipe($project, $file); $def = new TargetDefinition(array('name' => $file->name(), 'type' => TARGET)); if (is_array($deps)) { foreach ($deps as $dep) { $def->add_dependency($dep); } } $def->add_recipe($recipe); return ProjectFile::create($project, $def); }
function files_my_tasks_dropdown() { //if (logged_user()->getProjectPermission(active_project(), PermissionManager::CAN_MANAGE_FILES)) { echo '<li class="header"><a href="' . get_url('files', 'index') . '">' . lang('files') . '</a></li>'; //} // if if (ProjectFile::canAdd(logged_user(), active_project())) { echo '<li><a href="' . get_url('files', 'add_file') . '">' . lang('add file') . '</a></li>'; } // if if (ProjectFolder::canAdd(logged_user(), active_project())) { echo '<li><a href="' . get_url('files', 'add_folder') . '">' . lang('add folder') . '</a></li>'; } // if }
function files_my_tasks_dropdown() { if (use_permitted(logged_user(), active_project(), 'files')) { echo '<li class="header"><a href="' . get_url('files', 'index') . '">' . lang('files') . '</a></li>'; if (ProjectFile::canAdd(logged_user(), active_project())) { echo '<li><a href="' . get_url('files', 'add_file') . '">' . lang('add file') . '</a></li>'; } // if if (ProjectFolder::canAdd(logged_user(), active_project())) { echo '<li><a href="' . get_url('files', 'add_folder') . '">' . lang('add folder') . '</a></li>'; } // if } // if }
function uploadDocument($doc_name, $ws_id, $path) { if (str_starts_with($doc_name, "~")) { return; } try { DB::beginWork(); $project = Projects::findById($ws_id); //$file = ProjectFiles::findOne(array("conditions" => "`filename` = '$doc_name'")); $files = ProjectFiles::getAllByFilename($doc_name, $ws_id); if (is_array($files) && count($files) > 0) { $file = $files[0]; } else { $file = null; } if (!$file instanceof ProjectFile) { $file = new ProjectFile(); $file->setFilename($doc_name); $file->setIsVisible(true); $file->setIsPrivate(false); $file->setIsImportant(false); $file->setCommentsEnabled(true); $file->setAnonymousCommentsEnabled(false); //$file->setCreatedOn(new DateTimeValue(time()) ); } $sourcePath = $path . $doc_name; $handle = fopen($sourcePath, "r"); $size = filesize($sourcePath); $file_content = fread($handle, $size); fclose($handle); $file_dt['name'] = $file->getFilename(); $file_dt['size'] = strlen($file_content); $file_dt['tmp_name'] = $sourcePath; //TEMP_PATH . DIRECTORY_SEPARATOR . rand() ; $extension = trim(get_file_extension($sourcePath)); $file_dt['type'] = Mime_Types::instance()->get_type($extension); if (!trim($file_dt['type'])) { $file_dt['type'] = 'text/html'; } $file->save(); $file->removeFromAllWorkspaces(); $file->addToWorkspace($project); $old_revs = $file->getRevisions(); foreach ($old_revs as $rev) { $rev->delete(); } $revision = $file->handleUploadedFile($file_dt, true, ''); $file_date = new DateTimeValue(filemtime($sourcePath)); $revision->setCreatedOn($file_date); $revision->setUpdatedOn($file_date); $revision->save(); $file->setCreatedOn($file_date); $file->setUpdatedOn($file_date); $file->save(); $ws = $file->getWorkspaces(); ApplicationLogs::createLog($file, $ws, ApplicationLogs::ACTION_ADD); ImportLogger::instance()->log(" File: {$doc_name} [{$ws_id}]"); print " File: {$doc_name} [{$ws_id}]\r\n"; DB::commit(); } catch (Exception $e) { DB::rollback(); ImportLogger::instance()->logError("{$e}\r\n**************************************************"); print "\r\n\r\nERROR: {$e}\r\n"; } }
function fckimagesupload(){ try { if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) ) { $oFile = $_FILES['NewFile'] ; }else{ $sErrorNumber = '202'; echo $this->SendUploadResults( $sErrorNumber ) ; return; } $sErrorNumber = '0' ; $sFileName = $oFile['name'] ; $file = new ProjectFile(); $file->setFilename($sFileName); $file->setIsVisible(true); $file->setCreatedOn(new DateTimeValue(time())); DB::beginWork(); $file->save(); //FIXME $workspaces = array(personal_project()); /*FIXME if (is_array($workspaces)) { foreach ($workspaces as $ws) { $file->addToWorkspace($ws); } }*/ $revision = $file->handleUploadedFile($oFile, true, ''); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ADD); DB::commit(); echo $this->SendUploadResults( $sErrorNumber, $file->getDownloadUrl() , $file->getFilename() ) ; } catch (Exception $e) { DB::rollback(); $sErrorNumber = '202'; echo $this->SendUploadResults( $sErrorNumber ) ; } }
/** * Empty implementation of abstract methods. Messages determine does user have * permissions to add comment * * @param void * @return null */ function canAdd(User $user, Project $project) { return $user->isAdministrator() || ProjectFile::canUpload($user, $project); }
function classifyFile($classification_data, $email, $parsedEmail, $validWS, $mantainWs = true, $csv = '') { if (!is_array($classification_data)) { $classification_data = array(); } if (!isset($parsedEmail["Attachments"])) { throw new Exception(lang('no attachments found for email')); } 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"]); } try { $file = ProjectFiles::findOne(array('conditions' => "`filename` = " . DB::escape($fName) . " AND `mail_id` = " . $email->getId())); DB::beginWork(); if ($file == null) { $fileIsNew = true; $file = new ProjectFile(); $file->setFilename($fName); $file->setIsVisible(true); $file->setIsPrivate(false); $file->setIsImportant(false); $file->setCommentsEnabled(true); $file->setAnonymousCommentsEnabled(false); $file->setMailId($email->getId()); $file->save(); } else { $fileIsNew = false; } if (!$mantainWs && !$fileIsNew) { $file->removeFromWorkspaces(logged_user()->getWorkspacesQuery()); } foreach ($validWS as $w) { if (!$file->hasWorkspace($w)) { $file->addToWorkspace($w); } } $file->setTagsFromCSV($csv); $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 } if ($fileIsNew) { $tempFileName = ROOT . "/tmp/" . logged_user()->getId() . "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)); $revision = $file->handleUploadedFile($fileToSave, true, lang('attachment from email', $email->getSubject())); // handle uploaded file $email->linkObject($file); ApplicationLogs::createLog($file, $email->getWorkspaces(), ApplicationLogs::ACTION_ADD); } DB::commit(); // Error... } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } if (isset($tempFileName) && is_file($tempFileName)) { unlink($tempFileName); } } } }
private function file_toxml(ProjectFile $f) { $this->instance->startElement('file'); $this->instance->startElement('id'); $this->instance->text($f->getId()); $this->instance->endElement(); $this->instance->startElement('name'); $this->instance->text(clean($f->getFilename())); $this->instance->endElement(); $this->instance->startElement('description'); $this->instance->text(clean($f->getDescription())); $this->instance->endElement(); $this->instance->startElement('version'); $this->instance->text($f->getRevisionNumber()); $this->instance->endElement(); $this->instance->startElement('modifiedOn'); $this->instance->text($f->getLastRevision()->getCreatedOn()->format('d/m/Y')); $this->instance->endElement(); $this->instance->startElement('modifiedBy'); $creator = $f->getLastRevision()->getCreatedBy(); $this->instance->text(clean($creator ? $creator->getDisplayName() : 'unknown')); $this->instance->endElement(); $this->instance->startElement('workspaces'); $this->instance->text($f->getWorkspacesIdsCSV()); $this->instance->endElement(); $this->instance->startElement('tags'); $this->instance->text(implode(', ', $f->getTagNames())); $this->instance->endElement(); $this->instance->startElement('uid'); $this->instance->text('d' . str_pad($f->getId(), 3, '0', STR_PAD_LEFT) . 'r' . $f->getRevisionNumber()); $this->instance->endElement(); $this->instance->endElement(); }
/** * Return detach file URL * * @param ProjectFile $file * @return string */ function getDetachFileUrl(ProjectFile $file) { return get_url('files', 'detach_from_object', array('manager' => get_class($this->manager()), 'object_id' => $this->getObjectId(), 'file_id' => $file->getId(), 'active_project' => $this->getProject()->getId())); // get_url }
/** * Handle files uploaded using helper forms. This function will return array of uploaded * files when finished * * @param string $files_var_prefix If value of this variable is set only elements in $_FILES * with key starting with $files_var_prefix will be handled * @return array */ static function handleHelperUploads($context, $files_var_prefix = null) { //FIXME return null; if (!isset($_FILES) || !is_array($_FILES) || !count($_FILES)) { return null; // no files to handle } $uploaded_files = array(); foreach ($_FILES as $uploaded_file_name => $uploaded_file) { if (trim($files_var_prefix) != '' && !str_starts_with($uploaded_file_name, $files_var_prefix)) { continue; } if (!isset($uploaded_file['name']) || !isset($uploaded_file['tmp_name']) || !is_file($uploaded_file['tmp_name'])) { continue; } $uploaded_files[$uploaded_file_name] = $uploaded_file; } if (!count($uploaded_file)) { return null; } $result = array(); // we'll put all files here $expiration_time = DateTimeValueLib::now()->advance(1800, false); foreach ($uploaded_files as $uploaded_file) { $file = new ProjectFile(); $file->setProjectId($project->getId()); $file->setFilename($uploaded_file['name']); $file->setIsVisible(false); $file->setExpirationTime($expiration_time); $file->save(); $file->handleUploadedFile($uploaded_file); // initial version $result[] = $file; } return count($result) ? $result : null; }
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); } } }
<?php set_page_title($folder->isNew() ? lang('add folder') : lang('edit folder')); if(ProjectFile::canAdd(logged_user(), active_context())) { add_page_action(lang('add file'), get_url('files', 'add_file'), 'ico-add'); } // if ?> <form class="internalForm" action="<?php echo ($folder->isNew())? get_url('files', 'add_folder') : $folder->getEditUrl()?>" method="post"> <?php tpl_display(get_template_path('form_errors')) ?> <div> <?php echo label_tag(lang('name'), 'folderFormName') ?> <?php echo text_field('folder[name]', array_var($folder_data, 'name'), array('id' => 'folderFormName')) ?> </div> <?php echo submit_button($folder->isNew() ? lang('add folder') : lang('edit folder')) ?> </form>
private function construct(&$files) { // the root node $this->nodes = array(); $this->intermediate_files = array(); $this->errors = array(); foreach ($files as $name => $file) { $this->files[$name] =& $file; } $this->files = $files; $filenames = array_keys($files); $no_rules = array(); foreach ($this->files as $name => $file) { if (!$file->makable()) { $default = $this->default_rule($file); // wiki_debug("default $name", $default); if ($default === NULL) { $this->add_error($name, "undefined"); } else { $file = $default; $this->files[$name] = $file; } } $this->nodes[$name] = new MakeNode($name, $file->is_target()); } // link nodes reversly with dependency, i.e, if one node changed, // which other nodes need to be upated while ((list($name, $node) = each($this->nodes)) != false) { $deps = $this->files[$name]->dependency(); if ($deps) { foreach ($deps as $dep) { if (!isset($this->nodes[$dep])) { $missing = ProjectFile::create($this->project, new TargetDefinition(array('name' => $dep, 'type' => TARGET))); $default = $this->default_rule($missing); // wiki_debug("default $dep", $default); if ($default == NULL) { $this->add_error($name, array('dependency' => $dep)); continue; } $this->intermediate_files[] = $dep; $this->files[$dep] = $default; $dep_node = new MakeNode($dep, true); $this->nodes[$dep] = $dep_node; } else { $dep_node = $this->nodes[$dep]; } $dep_node->link($node); } } } foreach ($this->nodes as $node) { $node->find_affected($this->errors); } // find those which are affected by the error nodes $errors = array_intersect(array_keys($this->errors), array_keys($this->nodes)); foreach ($errors as $name) { $this->nodes[$name]->mark_invalid($this->errors); } $invalid = array_keys($this->errors); // drop the invalid nodes $nodes = array(); // relink valid nodes foreach ($this->nodes as $name => $node) { if ($node->valid) { $nodes[$name] = new MakeNode($name, $node->is_target()); } } foreach ($nodes as $name => $node) { $deps = array_diff($this->files[$name]->dependency(), $invalid); foreach ($deps as $dep) { $nodes[$dep]->link($node); } } $this->nodes = $nodes; }
/** *Make Mn *@return string */ function MakeMindMap(){ // header xml data freemind $content = "<map version=\"0.9.0\">\n"; $content .= "<!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->\n"; $mytime = time(); // is logged ? if (!logged_user()->isProjectUser(active_project())) { echo $content; echo "<node CREATED=\"$mytime\" ID=\"Freemind_Link_558888646\" MODIFIED=\"$mytime\" STYLE=\"bubble\" TEXT=\"Disconnected\">\n"; echo "</node>\n"; echo "</map>\n"; die; } // if // is user can view this project ?? if (!ProjectFile::canView(logged_user(), active_project())) { echo $content; echo "<node CREATED=\"$mytime\" ID=\"Freemind_Link_558888646\" MODIFIED=\"$mytime\" STYLE=\"bubble\" TEXT=\"Not Allowed\">\n"; echo "</node>\n"; echo "</map>\n"; die; } //if /* * xml data construction freemind for project */ $project = active_project(); $project_name = $project->getName(); $this->epure($project_name); //Project title $url = externalUrl(get_url('task','index')); $content .= "<node CREATED=\"$mytime\" LINK=\"$url\" MODIFIED=\"$mytime\" STYLE=\"bubble\" TEXT=\"$project_name\">\n"; //milestones $milestones = $project->getMilestones(); $mymilestone = array(); if (is_array($milestones)) { foreach($milestones as $milestone){ $url = externalUrl(get_url('milestone','view',array('id' => $milestone->getId()))); $content .= "<node CREATED=\"$mytime\" LINK=\"$url\" POSITION=\"right\" MODIFIED=\"$mytime\" TEXT=\" [" . $milestone->getName() . ' ' . Localization::instance()->formatDate($milestone->getDueDate()) . "]\">\n"; $content .= "<font NAME=\"SansSerif\" BOLD=\"true\" SIZE=\"12\"/>"; $content .= "<icon BUILTIN=\"messagebox_warning\"/>\n"; $content .= "<icon BUILTIN=\"messagebox_warning\"/>\n"; $content .= "</node>\n"; } } $task_lists = $project->getTaskLists(); if (is_array($task_lists)) { //Tasks lists $positions = array('right','left'); $actualpos = 0; foreach ($task_lists as $task_list) { /* * security access */ //security access User can view this task_list ? if (!ProjectTaskList::canView(logged_user(), $task_list->getId())) continue; // task list name $task_list_name=$task_list->getName(); //Complete or not complete $progress = $this->progress($task_list); $icon = null; $tasklistComplete = false; if ($progress[0] == '100'){ $icon .= "<icon BUILTIN=\"button_ok\"/>\n"; $tasklistComplete = true; } $kt_tl_var = 'tl:' . $task_list_name; $this->epure($kt_tl_var); if (strlen($task_list_name) > 40) $task_list_name = substr($task_list_name,0,40) . "..."; $position = $positions[$actualpos]; $url = externalUrl(get_url('task','view_list',array('id' => $task_list->getId()))); $content .= "<node CREATED=\"$mytime\" LINK=\"$url\" MODIFIED=\"$mytime\" POSITION=\"$position\" TEXT=\"$task_list_name\">\n"; $content .= "$icon"; if ($actualpos == 0){ $actualpos =1; }else{ $actualpos =0; } //if //tasks $tasks = $task_list->getTasks(); if (is_array($tasks)) { foreach($tasks as $task) { /* * security access */ //security access User can view this task ? if (!ProjectTask::canView(logged_user(), $task->getId())) continue; // icon freeming ok | cancel $icon = null; if (!$tasklistComplete){ if ($task->isCompleted()) { //complete : icon ok $icon .= "<icon BUILTIN=\"button_ok\"/>\n"; $dateclose = " []"; }else{ //incomplete : icon cancel $icon .= "<icon BUILTIN=\"button_cancel\"/>\n"; $dateclose = " []"; } //if } //if //task name $task_text = $task->getText(); $this->epure($task_text); if (strlen($task_text) > 40) $task_text = substr($task_text,0,40) . "..."; $url = externalUrl(get_url('task','view_task',array('id' => $task->getId()))); $content .= "<node CREATED=\"$mytime\" LINK=\"$url\" MODIFIED=\"$mytime\" TEXT=\"" . $task_text . "\">\n"; $content .= $icon; $content .= "</node>\n"; } } $content .= "</node>\n"; } // if } // if //footer xml data freemind $content .= "</node>\n"; $content .= "</map>"; //send data $type = "x-freemind/mm"; $name = "projectpier.mm"; $size = strlen($content); header("Content-Type: $type"); header("Content-Disposition: attachment; filename=\"$name\""); header("Content-Length: " . (string) $size); echo $content; die; //end process do not send other informations } //MakeMm
/** * Add file * * @access public * @param void * @return null */ function add_file() { if (!ProjectFile::canAdd(logged_user(), active_project())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('files')); } // if $file = new ProjectFile(); $file_data = array_var($_POST, 'file'); if (!is_array($file_data)) { $file_data = array( 'folder_id' => get_id('folder_id'), 'is_private' => config_option('default_private', false) ); // array } // if tpl_assign('file', $file); tpl_assign('file_data', $file_data); if (is_array(array_var($_POST, 'file'))) { try { DB::beginWork(); $uploaded_file = array_var($_FILES, 'file_file'); // move uploaded file to folder where I can read and write move_uploaded_file($uploaded_file['tmp_name'], ROOT . '/tmp/' . $uploaded_file['name']); $uploaded_file['tmp_name'] = ROOT . '/tmp/' . $uploaded_file['name']; $file->setFromAttributes($file_data); if (!logged_user()->isMemberOfOwnerCompany()) { $file->setIsPrivate(false); $file->setIsImportant(false); $file->setCommentsEnabled(true); $file->setAnonymousCommentsEnabled(false); } // if $file->setFilename(array_var($uploaded_file, 'name')); $file->setProjectId(active_project()->getId()); $file->setIsVisible(true); $file->save(); if (plugin_active('tags')) { $file->setTagsFromCSV(array_var($file_data, 'tags')); } $revision = $file->handleUploadedFile($uploaded_file, true); // handle uploaded file ApplicationLogs::createLog($file, active_project(), ApplicationLogs::ACTION_ADD); DB::commit(); // Try to send notifications but don't break submission in case of an error // define all the users to be notified - here all project users, from all companies. // Restrictions if comment is private is taken into account in newOtherComment() try { $notify_people = array(); $project_companies = active_project()->getCompanies(); foreach ($project_companies as $project_company) { $company_users = $project_company->getUsersOnProject(active_project()); if (is_array($company_users)) { foreach ($company_users as $company_user) { if ((array_var($file_data, 'notify_company_' . $project_company->getId()) == 'checked') || (array_var($file_data, 'notify_user_' . $company_user->getId()))) { $notify_people[] = $company_user; } // if } // if } // if } // if Notifier::newFile($file, $notify_people); // send notification email... } catch(Exception $e) { Logger::log("Error: Notification failed, " . $e->getMessage(), Logger::ERROR); } // try flash_success(lang('success add file', $file->getFilename())); $this->redirectToUrl($file->getDetailsUrl()); } catch(Exception $e) { DB::rollback(); tpl_assign('error', $e); tpl_assign('file', new ProjectFile()); // reset file // If we uploaded the file remove it from repository if (isset($revision) && ($revision instanceof ProjectFileRevision) && FileRepository::isInRepository($revision->getRepositoryId())) { FileRepository::deleteFile($revision->getRepositoryId()); } // if } // try } // if } // add_file
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); } } } } }
/** * Remove all relations by file * * @param ProjectFile $file * @return boolean */ static function clearRelationsByFile(ProjectFile $file) { return self::delete(array('`file_id` = ?', $file->getId())); }
/** * Copy project * * @param void * @return null */ function copy() { trace(__FILE__, "copy():begin"); if (!Project::canAdd(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $this->setTemplate('copy_project'); $this->setLayout('administration'); $project_data = array_var($_POST, 'project'); tpl_assign('project_data', $project_data); // Submitted... if (is_array($project_data)) { $source = Projects::findById($project_data['source']); if (!$source instanceof Project) { flash_error(lang('project dnx')); $this->redirectTo('administration', 'projects'); } // if try { $shift_dates = isset($project_data['shift_dates']) ? $project_data['shift_dates'] == 'checked' : false; $copy_details = isset($project_data['copy_details']) ? $project_data['copy_details'] == 'checked' : false; $copy_tasks = isset($project_data['copy_tasks']) ? $project_data['copy_tasks'] == 'checked' : false; $copy_milestones = isset($project_data['copy_milestones']) ? $project_data['copy_milestones'] == 'checked' : false; $copy_messages = isset($project_data['copy_messages']) ? $project_data['copy_messages'] == 'checked' : false; $copy_links = isset($project_data['copy_links']) ? $project_data['copy_links'] == 'checked' : false; $copy_files = isset($project_data['copy_files']) ? $project_data['copy_files'] == 'checked' : false; $copy_users = isset($project_data['copy_users']) ? $project_data['copy_users'] == 'checked' : false; $copy_pages = isset($project_data['copy_pages']) ? $project_data['copy_pages'] == 'checked' : false; DB::beginWork(); $project = new Project(); $new_name = lang('projects copy new name', $source->getName()); $new_name .= date(' z H:i:s'); $project->setName($new_name); if ($copy_details) { $project->setDescription($source->getDescription()); $project->setPriority($source->getPriority()); $project->setShowDescriptionInOverview($source->getShowDescriptionInOverview()); } $project->save(); $project_id = $project->getId(); $add_seconds = 0; if (isset($project_data['add_days'])) { $add_days = 0 + trim($project_data['add_days']); $add_seconds = $add_days * 24 * 60 * 60; } $source_created_on = $source->getCreatedOn(); //var_dump($source_created_on); $milestone_map = array(0 => 0); // project milestones if ($copy_milestones) { $source_milestones = $source->getAllMilestones(); if (is_array($source_milestones)) { foreach ($source_milestones as $source_milestone) { $milestone = new ProjectMilestone(); //$milestone->copy($source_milestone); $milestone->setName($source_milestone->getName()); $milestone->setDescription($source_milestone->getDescription()); if ($shift_dates) { trace(__FILE__, "copy():shift dates"); $milestone->setDueDate(DateTimeValueLib::now()); $seconds = $source_milestone->getDueDate()->difference($source_created_on); $milestone->getDueDate()->advance($seconds); } else { $milestone->setDueDate($source_milestone->getDueDate()); } $milestone->getDueDate()->advance($add_seconds); $milestone->setIsPrivate($source_milestone->getIsPrivate()); $milestone->setAssignedToUserId($source_milestone->getAssignedToUserId()); $milestone->setAssignedToCompanyId($source_milestone->getAssignedToCompanyId()); $milestone->setProjectId($project_id); $milestone->save(); $milestone_map[$source_milestone->getId()] = $milestone->getId(); } // foreach } // if } // if // project tasks if ($copy_tasks) { $source_task_lists = $source->getAllTaskLists(); if (is_array($source_task_lists)) { foreach ($source_task_lists as $source_task_list) { $task_list = new ProjectTaskList(); //$task_list->copy($source_milestone); $task_list->setName($source_task_list->getName()); $task_list->setPriority($source_task_list->getPriority()); $task_list->setDescription($source_task_list->getDescription()); if ($copy_milestones) { $task_list->setMilestoneId($milestone_map[$source_task_list->getMilestoneId()]); } $task_list->setDueDate($source_task_list->getDueDate()); if ($task_list->getDueDate() instanceof DateTimeValue) { if ($shift_dates) { trace(__FILE__, "copy():task list shift dates"); $task_list->setDueDate(DateTimeValueLib::now()); $seconds = $source_task_list->getDueDate()->difference($source_created_on); $task_list->getDueDate()->advance($seconds); } $task_list->getDueDate()->advance($add_seconds); } $task_list->setIsPrivate($source_task_list->getIsPrivate()); $task_list->setOrder($source_task_list->getOrder()); $task_list->setProjectId($project_id); $task_list->save(); $source_tasks = $source_task_list->getTasks(); if (is_array($source_tasks)) { foreach ($source_tasks as $source_task) { $task = new ProjectTask(); $task->setOrder($source_task->getOrder()); $task->setDueDate($source_task->getDueDate()); if ($task->getDueDate() instanceof DateTimeValue) { if ($shift_dates) { trace(__FILE__, "copy():task shift dates"); $task->setDueDate(DateTimeValueLib::now()); $seconds = $source_task->getDueDate()->difference($source_created_on); $task->getDueDate()->advance($seconds); } $task->getDueDate()->advance($add_seconds); } $task->setText($source_task->getText()); $task->getAssignedToUserId($source_task->getAssignedToUserId()); $task->getAssignedToCompanyId($source_task->getAssignedToCompanyId()); $task_list->attachTask($task); } } } // foreach } // if } // if // project messages if ($copy_messages) { $source_messages = $source->getAllMessages(); if (is_array($source_messages)) { foreach ($source_messages as $source_message) { $message = new ProjectMessage(); //$message->copy($source_message); $message->setTitle($source_message->getTitle()); $message->setText($source_message->getText()); $message->setAdditionalText($source_message->getAdditionalText()); if ($copy_milestones) { $message->setMilestoneId($milestone_map[$source_message->getMilestoneId()]); } $message->setIsImportant($source_message->getIsImportant()); $message->setIsPrivate($source_message->getIsPrivate()); $message->setCommentsEnabled($source_message->getCommentsEnabled()); $message->setAnonymousCommentsEnabled($source_message->getAnonymousCommentsEnabled()); $message->setProjectId($project_id); $message->save(); } // foreach } // if } // if // project links if ($copy_links) { $source_links = ProjectLinks::getAllProjectLinks($source); if (is_array($source_links)) { foreach ($source_links as $source_link) { $link = new ProjectLink(); //$folder->copy($source_link); $link->setTitle($source_link->getTitle()); $link->setUrl($source_link->getUrl()); $link->setProjectId($project_id); $link->save(); } // foreach } // if } // if // project folders & files if ($copy_files) { $folder_map = array(0 => 0); $source_folders = $source->getFolders(); if (is_array($source_folders)) { foreach ($source_folders as $source_folder) { $folder = new ProjectFolder(); //$folder->copy($source_folder); $folder->setName($source_folder->getName()); $folder->setProjectId($project_id); $folder->save(); $folder_map[$source_folder->getId()] = $folder->getId(); } // foreach } // if $source_files = ProjectFiles::getAllFilesByProject($source); if (is_array($source_files)) { foreach ($source_files as $source_file) { $file = new ProjectFile(); $file->setProjectId($project_id); $file->setFolderId($folder_map[$source_file->getFolderId()]); $file->setFileName($source_file->getFileName()); $file->setDescription($source_file->getDescription()); $file->setIsPrivate($source_file->getIsPrivate()); $file->setIsImportant($source_file->getIsImportant()); $file->setIsLocked($source_file->getIsLocked()); $file->setIsVisible($source_file->getIsVisible()); $file->setExpirationTime($source_file->getExpirationTime()); $file->setCommentsEnabled($source_file->getCommentsEnabled()); $file->setAnonymousCommentsEnabled($source_file->getAnonymousCommentsEnabled()); $file->save(); $source_revision = $source_file->getLastRevision(); if ($source_revision instanceof ProjectFileRevision) { $revision = new ProjectFileRevision(); $revision->setFileId($file->getId()); $revision->setRevisionNumber($source_revision->getRevisionNumber()); $revision->setRepositoryId($source_revision->getRepositoryId()); $revision->setFilesize($source_revision->getFilesize()); $revision->setFilename($source_revision->getFileName()); $revision->setTypeString($source_revision->getTypeString()); $revision->setThumbFilename($source_revision->getThumbFilename()); $revision->setFileTypeId($source_revision->getFileTypeId()); $revision->setComment($source_revision->getComment()); $revision->save(); } } // foreach } // if } // if if ($copy_pages) { $source_pages = Wiki::getAllProjectPages($source); if (is_array($source_pages)) { foreach ($source_pages as $source_page) { $page = new WikiPage(); $page->setProjectId($project_id); $page->setProjectIndex($source_page->getProjectIndex()); $page->setProjectSidebar($source_page->getProjectSidebar()); if (plugin_active('tags')) { //$page->setTags($source_page->getTagNames()); } //Make a new revision of this page $revision = $page->makeRevision(); $source_revision = $source_page->getLatestRevision(); //Set attributes $revision->setName($source_revision->getName()); $revision->setContent($source_revision->getContent()); $revision->setLogMessage($source_revision->getLogMessage()); //Save the page $page->save(); } // foreach } // if } // if if ($copy_users) { $source_companies = ProjectCompanies::instance()->getCompaniesByProject($source); if (is_array($source_companies)) { foreach ($source_companies as $source_company) { $project_company = new ProjectCompany(); $project_company->setCompanyId($source_company->getId()); $project_company->setProjectId($project_id); $project_company->save(); } // foreach } $source_users = ProjectUsers::instance()->getUsersByProject($source); if (is_array($source_users)) { foreach ($source_users as $source_user) { $project_user = new ProjectUser(); $project_user->setUserId($source_user->getId()); $project_user->setProjectId($project_id); $project_user->save(); } // foreach } } /* $permissions = array_keys(PermissionManager::getPermissionsText()); $auto_assign_users = owner_company()->getAutoAssignUsers(); // We are getting the list of auto assign users. If current user is not in the list // add it. He's creating the project after all... if (is_array($auto_assign_users)) { $auto_assign_logged_user = false; foreach ($auto_assign_users as $user) { if ($user->getId() == logged_user()->getId()) { $auto_assign_logged_user = true; } } // if if (!$auto_assign_logged_user) { $auto_assign_users[] = logged_user(); } } else { $auto_assign_users[] = logged_user(); } // if foreach ($auto_assign_users as $user) { $project_user = new ProjectUser(); $project_user->setProjectId($project->getId()); $project_user->setUserId($user->getId()); if (is_array($permissions)) { foreach ($permissions as $permission) { $user = Users::findById($project_user->getUserId()); $user->setProjectPermission($project,$permission,true); } } // if $project_user->save(); } // foreach */ ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_ADD, false, true); DB::commit(); flash_success(lang('success copy project', $source->getName(), $project->getName())); $this->redirectToUrl($project->getPermissionsUrl()); } catch (Exception $e) { echo $e->getMessage(); tpl_assign('error', $e); DB::rollback(); } // try } // if (submitted) }
/** * Add file * * @access public * @param void * @return null */ function add_file() { if (!ProjectFile::canAdd(logged_user(), active_project())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('files')); } // if $file = new ProjectFile(); $file_data = array_var($_POST, 'file'); if (!is_array($file_data)) { $file_data = array('is_private' => config_option('default_private', false)); // array } // if $folder = null; $folder_id = get_id('folder_id'); if ($folder_id) { $folder = ProjectFolders::findById($folder_id); } // if if ($folder instanceof ProjectFolder) { if (!is_array($file_data)) { $file_data = array('folder_id' => $folder->getId(), 'is_private' => config_option('default_private', false)); // array } else { $file_data['is_private'] = config_option('default_private', false); } } // if tpl_assign('file', $file); tpl_assign('file_data', $file_data); if (is_array(array_var($_POST, 'file'))) { try { DB::beginWork(); $uploaded_file = array_var($_FILES, 'file_file'); $file->setFromAttributes($file_data); if (!logged_user()->isMemberOfOwnerCompany()) { $file->setIsPrivate(false); $file->setIsImportant(false); $file->setCommentsEnabled(true); $file->setAnonymousCommentsEnabled(false); } // if $file->setFilename(array_var($uploaded_file, 'name')); $file->setProjectId(active_project()->getId()); $file->setIsVisible(true); $file->save(); if (plugin_active('tags')) { $file->setTagsFromCSV(array_var($file_data, 'tags')); } $revision = $file->handleUploadedFile($uploaded_file, true); // handle uploaded file ApplicationLogs::createLog($file, active_project(), ApplicationLogs::ACTION_ADD); DB::commit(); flash_success(lang('success add file', $file->getFilename())); $this->redirectToUrl($file->getDetailsUrl()); } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); tpl_assign('file', new ProjectFile()); // reset file // If we uploaded the file remove it from repository if (isset($revision) && $revision instanceof ProjectFileRevision && FileRepository::isInRepository($revision->getRepositoryId())) { FileRepository::deleteFile($revision->getRepositoryId()); } // if } // try } // if }
public function delete($project_path, $delete_log = false) { parent::delete($project_path); if ($delete_log) { $path = $this->path($project_path) . '.make.log'; if (file_exists($path)) { unlink($path); } } }
<?php set_page_title($file->getObjectName()); project_tabbed_navigation(PROJECT_TAB_FILES); $files_crumbs = array(0 => array(lang('files'), get_url('files'))); // array if ($folder instanceof ProjectFolder) { $files_crumbs[] = array($folder->getName(), $folder->getBrowseUrl()); } // if $files_crumbs[] = lang('file details'); project_crumbs($files_crumbs); if (ProjectFile::canAdd(logged_user(), active_project())) { if ($folder instanceof ProjectFolder) { add_page_action(lang('add file'), $folder->getAddFileUrl()); } else { add_page_action(lang('add file'), get_url('files', 'add_file')); } // if } // if if (ProjectFolder::canAdd(logged_user(), active_project())) { add_page_action(lang('add folder'), get_url('files', 'add_folder')); } // if add_stylesheet_to_page('project/files.css'); ?> <div id="fileDetails" class="block"> <?php if ($file->isPrivate()) { ?>
public function update_file($file) { $file = $this->handle($file); if ($file == NULL) { return true; } if (!$this->mutex->acquire()) { return false; } // let the plugins handle the file, if needed $name = $file->name(); // check if it is a new file not registered in the project if (!isset($this->files[$name])) { $this->files[$name] = ProjectFile::create($this, $file); } else { $old = $this->files[$name]; // check if two files are the same type, if not, delete the old if ($old->type() != $file->type()) { $this->mutex->release(); if (!$this->remove_file_without_remake($name, false)) { return false; } return $this->update_file($file); } // check if two files are the same if ($old->equal($this->project_path, $file)) { $this->mutex->release(); return true; } // copy to the project $old->copy($this->project_path, $file); } // this file has been changed, project needs to be remade $this->modified = true; $this->save_project(); $this->mutex->release(); $this->remake(array($name)); return true; }