function handleFileAPI($args, $that) { $session = mySession::getInstance(); // if ($that->method === 'POST') { if ($that->method === 'DELETE' && $session->isLoggedIn() && $session->isAdmin()) { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $file = File::getById($id); return $file->delete(); } } else { if ($that->method === 'POST' && $session->isLoggedIn() && $session->isAdmin()) { if ($that->verb === 'update') { $file = $that->file; return Dropzone::updateFile($file); } else { if (!empty($_POST)) { $info = json_decode($_POST['info']); } else { $info = null; } if ($info) { $ds = DIRECTORY_SEPARATOR; $storeFolder = 'uploads'; if (!empty($_FILES)) { $file = recast('Dropzone', $info); $file->file = new stdClass(); $file->file->error = $_FILES['uploadfile']['error'][0]; $file->file->name = $_FILES['uploadfile']['name'][0]; $file->file->size = $_FILES['uploadfile']['size'][0]; $file->file->tmp_name = $_FILES['uploadfile']['tmp_name'][0]; $file->file->type = $_FILES['uploadfile']['type'][0]; return $file->save(); } else { return false; } } } return false; } else { if ($that->method === 'GET') { if ($that->verb === 'getAll' && $session->isAdmin()) { return File::getAll(); } else { if ($that->verb === 'getTypeahead') { $type = isset($args[1]) ? $args[1] : 'person'; $limit = isset($args[2]) ? $args[2] : true; $val = $args[0]; if ($val === 'object' && $type === 'place') { $val = json_decode($_GET['place']); if (isset($val) && !empty($val)) { $val = $val[0]; } } return File::getByTagType($val, $type, $limit); return $type; } else { if ($that->verb === "getTags") { // Get all edit information required for file edits. $id = intval($args[0]); if (isset($id) && is_numeric($id)) { return Tag::getByFileId($id); } return false; } else { if ($that->verb === "") { // Get all edit information required for file edits. $id = intval($args[0]); if (isset($id) && is_numeric($id)) { $file = File::getById($id); return $file; } return false; } } } } } } } return "Only accepts GET AND POSTS requests"; }
/** * returns the latest version of a file (could be itself) */ public function getLatest() { if ($this->is_latest) { return $this; } $org_file = $this->org_file; if ($org_file == 0) { $org_file = $this->id; } if (!($project = Project::getVisibleById($this->project))) { trigger_error("file {$file->id} has no project", E_USER_WARNING); return NULL; } $files = File::getAll(array('latest_only' => true, 'org_file' => $org_file, 'project' => $project->id)); if (count($files) > 1) { foreach ($files as $f) { $list[] = $f->id; } trigger_error("unexpected number (" . join(",", $list) . ") of latest files for file id {$this->id}", E_USER_WARNING); $files[0]; } return $files[0]; }
/** * print a complete list as html * - use filters * - use check list style (tree, list, grouped) * - check customization-values * - check sorting * - get objects from database * */ public function print_automatic(&$project = NULL) { global $PH; if (!($this->active_block_function = $this->getBlockStyleFromCookie())) { $this->active_block_function = 'list'; } if ($project) { $this->query_options['project'] = $project->id; } $this->group_by = get("blockstyle_{$PH->cur_page->id}_{$this->id}_grouping"); $s_cookie = "sort_{$PH->cur_page->id}_{$this->id}_{$this->active_block_function}"; if ($sort = get($s_cookie)) { $this->query_options['order_by'] = $sort; } ### add filter options ### if (!$this->no_items_html) { $this->no_items_html = __("No files uploaded"); } ### grouped view ### if ($this->active_block_function == 'grouped') { ### prepend key to sorting ### if (isset($this->query_options['order_by'])) { $this->query_options['order_by'] = $this->groupings->getActiveFromCookie() . "," . $this->query_options['order_by']; } else { $this->query_options['order_by'] = $this->groupings->getActiveFromCookie(); } /** * @@@ later use only once... * * $this->columns= filterOptions($this->columns,"CURPAGE.BLOCKS[{$this->id}].STYLE[{$this->active_block_function}].COLUMNS"); */ if (isset($this->columns[$this->group_by])) { unset($this->columns[$this->group_by]); } } else { $foo = true; } $files = File::getAll($this->query_options); $this->render_list($files); }
static function getChangeLines($query_options) { global $PH; global $auth; fillMissingValues($query_options, array('alive_only' => false)); $date_compare = isset($query_options['date_min']) ? $query_options['date_min'] : "0000-00-00"; /** * get list of items touched by other people */ $changed_items = DbProjectItem::getAll($query_options); /** * go through list */ $changes = array(); foreach ($changed_items as $i) { $change_type = NULL; if (!isset($query_options['project'])) { $project = Project::getVisibleById($i->project); } else { $project = NULL; } /** * get item-change-type depeding on dates */ if ($i->deleted >= $i->modified) { $change_type = ITEM_DELETED; } else { if ($i->modified > $i->created) { $change_type = ITEM_MODIFIED; } else { $change_type = ITEM_NEW; } } /** * build up change-list */ switch ($change_type) { case ITEM_NEW: if ($i->type == ITEM_TASK) { if (!($task = Task::getVisibleById($i->id))) { continue; } if ($assigned_people = $task->getAssignedPeople()) { $tmp = array(); foreach ($assigned_people as $ap) { $tmp[] = $ap->getLink(); } $html_assignment = __('to', 'very short for assigned tasks TO...') . ' ' . implode(', ', $tmp); } else { $html_assignment = ''; } $html_details = ''; if ($tmp = $task->getFolderLinks(true, $project)) { $html_details .= __('in', 'very short for IN folder...') . ' ' . $tmp; } if ($task->prio != PRIO_NORMAL && $task->prio != PRIO_UNDEFINED) { global $g_prio_names; $html_details .= ' / ' . $g_prio_names[$task->prio]; } $change = new ChangeLine(array('item' => $task, 'person_by' => $i->created_by, 'timestamp' => $i->created, 'item_id' => $i->id, 'html_what' => '<span class=new>' . __('new') . ' ' . $task->getLabel() . '</span>', 'txt_what' => __('new') . ' ' . $task->getLabel(), 'type' => ChangeLine::NEW_TASK, 'html_assignment' => $html_assignment, 'html_details' => $html_details)); $changes[] = $change; } else { if ($i->type == ITEM_FILE) { require_once confGet('DIR_STREBER') . 'db/class_file.inc.php'; if ($file = File::getVisibleById($i->id)) { $change = new ChangeLine(array('item' => $file, 'person_by' => $i->created_by, 'timestamp' => $i->created, 'item_id' => $i->id, 'html_what' => __('New file'), 'txt_what' => __('New file'), 'type' => ChangeLine::NEW_FILE, 'html_details' => $file->name)); $changes[] = $change; } } } break; case ITEM_MODIFIED: $timestamp_last_change = $date_compare; # make sure we use the last occured change type /** * modified tasks */ $type = ChangeLine::UPDATED; if ($i->type == ITEM_TASK) { if (!($task = Task::getVisibleById($i->id))) { continue; } if ($assigned_people = $task->getAssignedPeople()) { $tmp = array(); foreach ($assigned_people as $ap) { $tmp[] = $ap->getLink(); } $html_assignment = __('to', 'very short for assigned tasks TO...') . ' ' . implode(', ', $tmp); } else { $html_assignment = ''; } $html_details = ''; if ($tmp = $task->getFolderLinks(true, $project)) { $html_details .= __('in', 'very short for IN folder...') . ' ' . $tmp; } $txt_what = $html_what = __('modified'); $type = ChangeLine::UPDATED; $html_comment = ''; if ($comments = Comment::getAll(array('person' => $i->modified_by, 'task' => $task->id, 'date_min' => $timestamp_last_change, 'order_by' => 'created ASC'))) { $last_comment = $comments[count($comments) - 1]; $timestamp_last_change = $last_comment->created; if ($last_comment->name && $last_comment->name != __('New Comment')) { # ignore default title $html_comment = strip_tags($last_comment->name) . ': '; } $html_comment .= strip_tags($last_comment->description); $html_comment = asHtml($html_comment); } ### get changed fields ### $changed_fields_hash = array(); $html_functions = false; if ($changed_fields_list = ItemChange::getItemChanges(array('item' => $i->id, 'person' => $i->modified_by, 'date_min' => $date_compare))) { foreach ($changed_fields_list as $cf) { $changed_fields_hash[$cf->field] = $cf; } if (isset($changed_fields_hash['status'])) { $status_old = $changed_fields_hash['status']->value_old; if ($task->status == STATUS_COMPLETED && $task->status > $status_old) { $txt_what = $html_what = __('completed') . ' ' . $task->getLabel(); $html_functions = $PH->getLink('tasksApproved', __('Approve Task'), array('tsk' => $task->id)); unset($changed_fields_hash['status']); } else { if ($task->status == STATUS_APPROVED && $task->status > $status_old) { $txt_what = $html_what = __('approved'); unset($changed_fields_hash['status']); } else { if ($task->status == STATUS_CLOSED && $task->status > $status_old) { $txt_what = $html_what = __('closed'); unset($changed_fields_hash['status']); } else { if ($task->status == STATUS_OPEN && $task->status < $status_old) { $txt_what = $html_what = __('reopened'); unset($changed_fields_hash['status']); } else { if ($task->status == STATUS_OPEN) { unset($changed_fields_hash['status']); } else { if ($task->status == STATUS_BLOCKED) { $txt_what = $html_what = __('is blocked'); unset($changed_fields_hash['status']); } } } } } } } } if (isset($changed_fields_hash['parent_task'])) { $txt_what = $html_what = __('moved'); $type = ChangeLine::MOVED; unset($changed_fields_hash['parent_task']); } else { if (count($changed_fields_hash) == 1 && isset($changed_fields_hash['name'])) { $txt_what = $html_what = __('renamed'); $type = ChangeLine::RENAMED; } else { if (count($changed_fields_hash) == 1 && isset($changed_fields_hash['description'])) { $txt_what = $html_what = __('edit wiki'); $type = ChangeLine::EDITED_WIKI; } else { if (count($changed_fields_hash)) { # status does not count $html_details .= ' / ' . __('changed:') . ' ' . implode(', ', array_keys($changed_fields_hash)); } else { if ($html_comment) { $txt_what = $html_what = __('commented'); $type = ChangeLine::COMMENTED; } } } } } if ($html_comment) { $html_details .= ' / ' . $html_comment; } /** * any recents assignments ? * - to avoid confusion only list assignmets if it was to last action, * */ require_once "db/class_taskperson.inc.php"; $count_assignments = 0; if ($assignments = TaskPerson::getTaskPeople(array('task' => $task->id, 'project' => $task->project, 'date_min' => $task->modified))) { $t_timestamp = ''; foreach ($assignments as $a) { if ($a->person != $task->modified_by && $a->created_by == $task->modified_by && $a->assigntype != ASSIGNTYPE_INITIAL) { $t_timestamp = $a->created; $count_assignments++; } } if ($count_assignments && $timestamp_last_change < $t_timestamp) { $type = ChangeLine::ASSIGNED; $txt_what = $html_what = __('assigned'); $timestamp_last_change = $t_timestamp; } if ($html_comment) { $html_details .= ' / ' . $html_comment; } } /** * any recents attachments by last editor ? */ require_once "db/class_file.inc.php"; if ($files = File::getAll(array('parent_item' => $task->id, 'project' => $task->project, 'date_min' => $date_compare, 'created_by' => $task->modified_by))) { $count_attached_files = 0; $html_attached = __("attached") . ": "; $t_timestamp = ''; $separator = ''; foreach ($files as $f) { if ($task->modified_by == $f->modified_by) { $t_timestamp = $f->created; $count_attached_files++; $html_attached .= $separator . $PH->getLink('fileView', $f->name, array('file' => $f->id)); $separator = ', '; } } if ($count_attached_files) { $type = ChangeLine::ATTACHED_FILE; $txt_what = $html_what = __('attached file to'); if ($timestamp_last_change < $t_timestamp) { $html_details .= ' / ' . $html_attached; $timestamp_last_change = $t_timestamp; } } } if (count($changed_fields_hash)) { $html_details .= " / " . $PH->getLink('itemViewDiff', NULL, array('item' => $task->id, 'date1' => $date_compare, 'date2' => gmdate("Y-m-d H:i:s"))); } if ($html_functions) { $html_details .= " | " . $html_functions; } $change = new ChangeLine(array('person_by' => $i->modified_by, 'timestamp' => $i->modified, 'item_id' => $i->id, 'item' => $task, 'type' => $type, 'txt_what' => $txt_what, 'html_what' => $html_what, 'html_assignment' => $html_assignment, 'html_details' => $html_details)); $changes[] = $change; } else { if ($i->type == ITEM_FILE) { require_once confGet('DIR_STREBER') . 'db/class_file.inc.php'; if ($file = File::getVisibleById($i->id)) { $change = new ChangeLine(array('item' => $file, 'person_by' => $i->created_by, 'timestamp' => $i->created, 'item_id' => $i->id, 'html_what' => __('changed File'), 'txt_what' => __('changed File'), 'type' => ChangeLine::NEW_FILE, 'html_details' => $file->name)); $changes[] = $change; } } } break; case ITEM_DELETED: /** * deleted tasks */ if ($i->type == ITEM_TASK) { if (!($task = Task::getVisibleById($i->id))) { continue; } if ($assigned_people = $task->getAssignedPeople()) { $tmp = array(); foreach ($assigned_people as $ap) { $tmp[] = $ap->getLink(); } $html_assignment = __('to', 'very short for assigned tasks TO...') . ' ' . implode(', ', $tmp); } else { $html_assignment = ''; } $html_details = ''; if ($tmp = $task->getFolderLinks(true, $project)) { $html_details .= __('in', 'very short for IN folder...') . ' ' . $tmp; } $html_details .= '|' . $PH->getLink('itemsRestore', __('restore'), array('item' => $task->id)); $txt_what = $html_what = __('deleted'); $change = new ChangeLine(array('item' => $task, 'person_by' => $i->deleted_by, 'timestamp' => $i->deleted, 'item_id' => $i->id, 'type' => ChangeLine::DELETED, 'txt_what' => $txt_what, 'html_what' => $html_what, 'html_assignment' => $html_assignment, 'html_details' => $html_details)); $changes[] = $change; } else { if ($i->type == ITEM_FILE) { require_once confGet('DIR_STREBER') . 'db/class_file.inc.php'; if ($file = File::getVisibleById($i->id)) { $change = new ChangeLine(array('item' => $file, 'person_by' => $i->created_by, 'timestamp' => $i->created, 'item_id' => $i->id, 'html_what' => __('deleted File'), 'txt_what' => ChangeLine::DELETED, 'html_details' => $file->name)); $changes[] = $change; } } } break; default: trigger_error("unknown change-type {$change_type}", E_USER_WARNING); break; } } return $changes; }
/** * View details of a file (versions, etc) @ingroup pages */ function fileView() { global $PH; global $auth; require_once confGet('DIR_STREBER') . 'render/render_wiki.inc.php'; ### get object #### $file_id = getOnePassedId('file'); if (!($file = File::getVisibleById($file_id))) { $PH->abortWarning("invalid file-id", ERROR_FATAL); } $file_org = $file->getOriginal(); if ($file->is_latest) { $file_latest = $file; } else { $file_latest = $file->getLatest(); } if (!($project = Project::getVisibleById($file->project))) { $PH->abortWarning("invalid project-id", ERROR_FATAL); } /** * parent item (not implemented yet) */ $parent_task = NULL; if ($file->parent_item) { #trigger_error('@@@not implemented yet', E_USER_ERROR); if (!($parent_task = Task::getVisibleById(intval($file->parent_item)))) { $PH->messages[] = sprintf(__("Could not access parent task Id:%s"), $file->parent_item); } } ### create from handle ### $from_handle = $PH->defineFromHandle(array('file' => $file->id)); ## is viewed by user ## $file->nowViewedByUser(); $page = new Page(); initPageForFile($page, $file, $project); #$page->title_minor=sprintf('#%d', $file_org->id);; if ($file->state == -1) { $page->title_minor = sprintf(__('(deleted %s)', 'page title add on with date of deletion'), renderTimestamp($file->deleted)); } ### page functions ### $page->add_function(new PageFunction(array('target' => 'fileEdit', 'params' => array('file' => $file->id), 'icon' => 'edit', 'tooltip' => __('Edit this file'), 'name' => __('Edit')))); $page->add_function(new PageFunction(array('target' => 'filesMoveToFolder', 'params' => array("file" => $file->id), 'tooltip' => __('Move this file to another task'), 'name' => __('Move')))); if ($auth->cur_user->settings & USER_SETTING_ENABLE_BOOKMARKS) { $item = ItemPerson::getAll(array('person' => $auth->cur_user->id, 'item' => $file->id)); if (!$item || $item[0]->is_bookmark == 0) { $page->add_function(new PageFunction(array('target' => 'itemsAsBookmark', 'params' => array('file' => $file->id), 'tooltip' => __('Mark this file as bookmark'), 'name' => __('Bookmark')))); } else { $page->add_function(new PageFunction(array('target' => 'itemsRemoveBookmark', 'params' => array('file' => $file->id), 'tooltip' => __('Remove this bookmark'), 'name' => __('Remove Bookmark')))); } } ### render title ### echo new PageHeader(); echo new PageContentOpen(); $block = new PageBlock(array('title' => __('Upload new version', 'block title'), 'id' => 'summary')); $block->render_blockStart(); echo "<div class=text>"; echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . confGet('FILE_UPLOAD_SIZE_MAX') . '" />'; echo '<input id="userfile" name="userfile" type="file" size="40" accept="*" />'; echo '<input type="submit" value="' . __('Upload') . '" />'; echo '</div>'; $block->render_blockEnd(); $block = new PageBlock(array('title' => sprintf(__('Version #%s (current): %s'), $file_latest->version, $file_latest->name), 'id' => 'description')); $block->render_blockStart(); echo "<div class=text>"; ### show thumbnail if ($file_latest->mimetype == "image/png" || $file_latest->mimetype == "image/x-png" || $file_latest->mimetype == "image/jpeg" || $file_latest->mimetype == "image/gif") { echo "<div class=image style='float:right;'><a href='index.php?go=fileDownloadAsImage&file={$file_latest->id}'>"; echo "<img src='index.php?go=fileDownloadAsImage&file={$file_latest->id}&max_size=128'>"; echo "</a></div>"; } if ($parent_task) { echo "<div class=labeled><label>" . __('For task') . "</label><span>" . $parent_task->getLink(false) . "</span></div>"; } echo "<div class=labeled><label>" . __('Filesize') . "</label><span>{$file_latest->filesize} bytes</span></div>"; echo "<div class=labeled><label>" . __('Type') . "</label><span>{$file_latest->mimetype}</span></div>"; echo "<div class=labeled><label>" . __('Uploaded') . "</label><span>" . renderDateHtml($file_latest->created) . "</span></div>"; if ($uploader = Person::getVisibleById($file->created_by)) { echo "<div class=labeled><label>" . __('Uploaded by') . "</label><span>" . $uploader->getLink() . "</span></div>"; } if ($file_latest->created != $file_latest->modified) { echo "<div class=labeled><label>" . __('Modified') . "</label><span>" . renderDateHtml($file_latest->created) . "</span></div>"; } echo "<div class=labeled><label>" . __('Download') . "</label><span>" . $PH->getLink('fileDownload', $file_latest->org_filename, array('file' => $file_latest->id)) . "</span></div>"; $str = wikifieldAsHtml($file_latest, 'description'); echo "<br>"; echo "{$str}"; echo "</div>"; $block->render_blockEnd(); /** * build list of old versions, * because org_file is zero for the original file, with have to append it */ $old_files = File::getAll(array('latest_only' => false, 'org_file' => $file_org->id, 'order_by' => 'version DESC', 'project' => $project->id)); if ($file_latest->id != $file_org->id) { $old_files[] = $file_org; } foreach ($old_files as $of) { if ($of->id != $file_latest->id) { $block = new PageBlock(array('title' => sprintf(__('Version #%s : %s'), $of->version, $of->name), 'id' => 'version_' . $of->id)); $block->render_blockStart(); echo "<div class=text>"; ### show thumbnail if ($of->mimetype == "image/png" || $of->mimetype == "image/x-png" || $of->mimetype == "image/jpeg" || $of->mimetype == "image/gif") { echo "<div class=image style='float:right;'><a href='index.php?go=fileDownloadAsImage&file={$of->id}'>"; echo "<img src='index.php?go=fileDownloadAsImage&file={$of->id}&max_size=128'>"; echo "</a></div>"; } $str = wikifieldAsHtml($of, 'description'); echo "{$str}"; echo "<div class=labeled><label>" . __('Filesize') . "</label><span>{$of->filesize} bytes</span></div>"; echo "<div class=labeled><label>" . __('Type') . "</label><span>{$of->mimetype}</span></div>"; echo "<div class=labeled><label>" . __('Uploaded') . "</label><span>" . renderDateHtml($of->created) . "</span></div>"; #echo "<div class=labeled><label>" . __('Version') . "</label><span>". intval($of->version) ."</span></div>"; echo "<div class=labeled>" . $PH->getLink('fileDownload', '', array('file' => $of->id)) . "</div>"; echo "</div>"; $block->render_blockEnd(); } } $PH->go_submit = 'fileUpdate'; /** * list comments * NOTE: can files have comments? */ /* { $comments= $file->getComments(); $list=new ListBlock_comments(); $list->no_items_html=$PH->getLink('commentNew','',array('parent_task'=>$task->id)); $list->render_list($comments); } */ echo '<input type="hidden" name="prj" value="' . $file->project . '">'; echo '<input type="hidden" name="org_file" value="' . $file->id . '">'; /** * give parameter for create of new items (subtasks, efforts, etc) */ #echo '<input type="hidden" name="parent_task" value="'.$task->id.'">'; echo new PageContentClose(); echo new PageHtmlEnd(); }