function renderPreviewList() { $options = array('date_min' => getDateTimeFieldValue('time_start'), 'date_max' => getDateTimeFieldValue('time_end')); ### author if (intval(get('person'))) { $options['modified_by'] = get('person'); } ### Object types $types = array(); if (get('type_task') || get('type_topic')) { $types[] = ITEM_TASK; } if (get('type_comment')) { $types[] = ITEM_COMMENT; } $options['type'] = $types; $items = DbProjectItem::getAll($options); echo "<ol>"; foreach ($items as $item) { if ($item->type == ITEM_COMMENT) { $comment = Comment::getById($item->id); if (get('only_spam_comments') && !isSpam($comment->name . " " . $comment->description)) { continue; } renderRemovalPreviewComment($comment); } if ($item->type == ITEM_TASK) { $task = Task::getById($item->id); renderRemovalPreviewTask($task); } } echo "</ol>"; }
/** * constructor */ function __construct($id_or_array = NULL) { global $projectperson_fields; $this->fields =& $projectperson_fields; parent::__construct($id_or_array); $this->type = ITEM_PROJECTPERSON; }
function __construct($id_or_array = false) { $this->fields =& self::$fields_static; parent::__construct($id_or_array); if (!$this->type) { $this->type = ITEM_TASK; } }
function __construct($id_or_array = NULL) { global $effort_fields; $this->fields =& $effort_fields; parent::__construct($id_or_array); if (!$this->type) { $this->type = ITEM_EFFORT; } }
function getItemModified() { if ($i = DbProjectItem::getById($this->item)) { $mod_date = $i->modified; return $mod_date; } else { return NULL; } }
function __construct($id_or_array = NULL) { global $g_issue_fields; $this->fields =& $g_issue_fields; parent::__construct($id_or_array); if (!$this->type) { $this->type = ITEM_ISSUE; } }
/** * constructor */ function __construct($id_or_array = NULL) { global $g_task_person_fields; $this->fields =& $g_task_person_fields; parent::__construct($id_or_array); if (!$this->type) { $this->type = ITEM_TASKPERSON; } }
/** * constructor */ function __construct($id_or_array = NULL) { global $g_employment_fields; $this->fields =& $g_employment_fields; parent::__construct($id_or_array); if (!$this->type) { $this->type = ITEM_EMPLOYMENT; } }
function __construct($id_or_array = NULL) { global $g_company_fields; $this->fields =& $g_company_fields; parent::__construct($id_or_array); if (!$this->type) { $this->type = ITEM_COMPANY; } }
function __construct($id_or_array = false) { global $comment_fields; $this->fields =& $comment_fields; parent::__construct($id_or_array); if (!$this->type) { $this->type = ITEM_COMMENT; } $this->num_children = 0; }
/** * Remove items of certain type and autho */ function itemsRemoveManySubmit() { global $PH; global $auth; ### cancel ? ### if (get('form_do_cancel')) { if (!$PH->showFromPage()) { $PH->show('home', array()); } exit; } $count_removed_items = 0; $item_ids = get('item_*'); foreach ($item_ids as $id) { if ($item = DbProjectItem::getById($id)) { if ($item->type == ITEM_COMMENT) { if ($comment = Comment::getById($id)) { revertDateOfCommentParent($comment); $comment->deleteFromDb(); $count_removed_items++; } } else { if ($item->type == ITEM_TASK) { if ($task = Task::getById($id)) { #revertDateOfCommentParent($comment); $task->deleteFromDb(); $count_removed_items++; } } } } } new FeedbackMessage(sprintf(__("Removed %s items"), $count_removed_items)); ### display taskView #### if (!$PH->showFromPage()) { $PH->show('home'); } }
/** * Submit information to a file @ingroup pages * * read more at http://www.streber-pm.org/3658 */ function fileEditSubmit() { global $PH; ### Validate form crc if (!validateFormCrc()) { $PH->abortWarning(__('Invalid checksum for hidden form elements')); } $id = getOnePassedId('file'); ### temp new file-object #### if ($id == 0) { $file = new File(array('id' => 0)); $file->mimetype = get('file_mimetype') ? urldecode(get('file_mimetype')) : NULL; $file->org_filename = get('file_org_filename') ? urldecode(get('file_org_filename')) : NULL; $file->tmp_filename = get('file_tmp_filename') ? urldecode(get('file_tmp_filename')) : NULL; $file->tmp_dir = get('file_tmp_dir') ? get('file_tmp_dir') : NULL; ### make sure file is not already uploaded ### #if(!file_exists("_uploads/". $file->tmp_dir)) { # $PH->abortWarning("Not again"); #} $file->filesize = intval(get('file_filesize')); $file->is_image = intval(get('file_is_image')); $file->version = intval(get('file_version')); $file->parent_item = intval(get('file_parent_item')); $file->org_file = intval(get('file_org_file')); } else { $file = File::getEditableById($id); if (!$file) { $PH->abortWarning(__("Could not get file")); return; } } ### cancel ### if (get('form_do_cancel')) { if (!$PH->showFromPage()) { $PH->show('projView', array('prj' => $file->project)); } exit; } $file->project = get('file_project'); if (!($project = Project::getVisibleById($file->project))) { $PH->abortWarning(__("Could not get project of file")); } if (!is_null(get('file_name'))) { $file->name = get('file_name'); } if (!is_null(get('file_description'))) { $file->description = get('file_description'); } if (!is_null(get('file_status'))) { $file->status = get('file_status'); } ### pub level ### if ($pub_level = get('file_pub_level')) { ### not a new file ### if ($file->id) { if ($pub_level > $file->getValidUserSetPublicLevels()) { $PH->abortWarning('invalid data', ERROR_RIGHTS); } } else { #@@@ check for person create rights $foo = true; } $file->pub_level = $pub_level; } ### go back to from if validation fails ### $failure = false; if ($file->name == "") { $failure = true; $PH->messages[] = __("Please enter a proper filename"); } if ($failure) { $PH->show('fileEdit', NULL, $file); exit; } ### write to db ### if ($file->id == 0) { $latest_file = NULL; if ($file->org_file) { if (!($org_file = File::getEditableById($file->org_file))) { $PH->abortWarning("unable to write parent file", ERROR_RIGHTS); } if (!($latest_file = $org_file->getLatest())) { $PH->abortWarning("unable to get latest file", ERROR_RIGHTS); } } if (!$file->insert()) { $PH->abortWarning("Could not insert file to db"); } ### updated former latest file? ### if ($latest_file) { $latest_file->is_latest = 0; $latest_file->update(); new FeedbackMessage(sprintf(__("Uploaded new version of file with Id %s"), $file->id)); } else { new FeedbackMessage(sprintf(__("Uploaded new file with Id %s"), $file->id)); } } else { new FeedbackMessage(sprintf(__("Updated file with Id %s"), $file->id)); $file->update(); } ### update date of parent items ? ### if ($item = DbProjectItem::getEditableById($file->parent_item)) { $item->update(array()); } ### display taskView #### if (!$PH->showFromPage()) { $PH->show('projView', array('prj' => $file->project)); } }
/** * internal function to add update markers to wiki texts * these markers will later be replaced by render_wiki (see render_wiki.inc.php FormatBlockChangemarks) */ public function getTextfieldWithUpdateNotes($fieldname) { require_once confGet('DIR_STREBER') . "db/db_itemchange.inc.php"; require_once confGet('DIR_STREBER') . 'db/db_itemperson.inc.php'; global $auth; ### has user last edited this item? ### if ($this->modified_by == $auth->cur_user->id) { return $this->{$fieldname}; } else { if ($item_people = ItemPerson::getAll(array('person' => $auth->cur_user->id, 'item' => $this->id))) { $ip = $item_people[0]; if ($ip->viewed_last > $this->modified) { return $this->{$fieldname}; } } else { return $this->{$fieldname}; } } $new_version = $this->{$fieldname}; $changes = ItemChange::getItemChanges(array('item' => $this->id, 'field' => $fieldname, 'order_by' => 'modified', 'date_min' => $ip->viewed_last)); if (!$changes) { return $this->{$fieldname}; } $old_version = $changes[0]->value_old; require_once confGet('DIR_STREBER') . "std/difference_engine.inc.php"; $ota = explode("\n", str_replace("\r\n", "\n", $old_version)); $nta = explode("\n", str_replace("\r\n", "\n", $new_version)); $diffs = new Diff($ota, $nta); $new_lines = array(); foreach ($diffs as $d) { foreach ($d as $do) { if ($do->type == 'copy') { $new_lines[] .= join("\n", $do->orig); } else { if ($do->type == 'add') { $new_lines[] = "[added word]" . join("\n", $do->closing) . "[/added word]"; } else { if ($do->type == 'delete') { $new_lines[] = '[deleted word]' . join("\n", $do->orig) . '[/deleted word]'; } else { if ($do->type == 'change') { ### render word level differences $wld = new WordLevelDiff($do->orig, $do->closing); $change_ratio = DbProjectItem::getEditRatioOfWordLevelDiff($wld); if ($change_ratio > 0.1) { $new_lines[] = "[deleted word]" . join("\n", $do->orig) . "[/deleted word]"; $new_lines[] = "[added word]" . join("\n", $do->closing) . "[/added word]"; } else { $new_lines[] = formatWordLevelDiff($wld); } } } } } } } $buffer = join($new_lines, "\n"); #debugMessage($old_version); #debugMessage( htmlspecialchars($buffer)); return $buffer; }
/** * insert uploaded files to database is done AFTER moving the * file to the appropriate project directory * * overwrites original insert function of DbProjectItem * */ public function insert() { $upload_filepath = confGet('DIR_TEMP') . 'uploads/' . $this->tmp_filename; if (!file_exists($upload_filepath)) { trigger_error("Uploaded field no longer exists in {$upload_filepath}", E_USER_WARNING); return NULL; } if (!file_exists(confGet('DIR_FILES'))) { trigger_error("Directory for files '" . confGet('DIR_FILES') . "' does not exists", E_USER_WARNING); return NULL; } ### create project directory ### $this->tmp_dir = "prj{$this->project}"; if (!file_exists(confGet('DIR_FILES') . $this->tmp_dir)) { if (!mkdir(confGet('DIR_FILES') . $this->tmp_dir, 0777)) { trigger_error("could not create target directory for uploaded file '" . confGet('DIR_FILES') . $this->tmp_dir . "/'", E_USER_WARNING); return NULL; } } /** * insert into DB to get the item-id as prefix for temp-name * * This has to be done before moving the file, because we need the * new item id for the filename. */ if (!parent::insert() || !$this->id) { trigger_error("inserting file object failed"); return NULL; } $this->tmp_filename = $this->id . "_" . $this->tmp_filename; ### use original function to write to Db parent::update(); ### move file ### if (!rename($upload_filepath, confGet('DIR_FILES') . $this->tmp_dir . "/" . $this->tmp_filename)) { trigger_error("could not move uploaded file from '{$upload_filepath}' to '" . confGet('DIR_FILES') . $this->tmp_dir . "/" . $this->tmp_filename . "'", E_USER_WARNING); ### remove invalid database entry ### $this->DeleteFromDb(); return NULL; } return true; }
/** * Restoring (i.e. undelete) items @ingroup pages */ function itemsRestore() { global $PH; ### get effort #### $ids = getPassedIds('item', 'items_*'); if (!$ids) { $PH->abortWarning(__("Select some items to restore")); return; } $counter = 0; $errors = 0; foreach ($ids as $id) { $i = DbProjectItem::getEditableById($id); if (!$i) { $PH->abortWarning("Invalid item-id!"); } if ($i->state != -1) { new FeedbackMessage(sprintf(__('Item %s does not need to be restored'), $i->id)); $errors++; continue; } $i->state = 1; if ($i->update()) { $counter++; } else { $errors++; } } if ($errors) { new FeedbackWarning(sprintf(__("Failed to restore %s items"), $errors)); } else { new FeedbackMessage(sprintf(__("Restored %s items"), $counter)); } if (!$PH->showFromPage()) { $PH->show('home'); } }
/** * delete together with all belonging tasks */ public function delete() { #--- first delete all tasks --- foreach ($this->getTasks() as $t) { $t->delete(); } #--- delete myself --- return parent::delete(); }
/** * tries to build a valid a href-link to an item. * * - uses $this->name * - sets -this-html * - does all the neccessary security checks, styles and conversions */ static function renderLinkFromItemId($target_id, $name = "") { global $PH; $target_id = intval($target_id); $html = ""; if (!($item = DbProjectItem::getVisibleById($target_id))) { $html = '<em>' . sprintf(__("Unkwown item %s"), $target_id) . '</em>'; } else { switch ($item->type) { case ITEM_TASK: if ($task = Task::getVisibleById($item->id)) { $style_isdone = $task->status >= STATUS_COMPLETED ? 'isDone' : ''; if ($name) { $html = $PH->getLink('taskView', $name, array('tsk' => $task->id), $style_isdone, true); } else { $html = $task->getLink(false); } } break; case ITEM_FILE: require_once confGet('DIR_STREBER') . "db/class_file.inc.php"; if ($file = File::getVisibleById($item->id)) { if ($name) { $html = $PH->getLink('fileDownloadAsImage', $name, array('file' => $file->id), NULL, true); } else { $html = $PH->getLink('fileDownloadAsImage', $file->name, array('file' => $file->id)); } } break; case ITEM_COMMENT: require_once confGet('DIR_STREBER') . "db/class_comment.inc.php"; if ($comment = Comment::getVisibleById($item->id)) { if ($name) { $html = $PH->getLink('commentView', $name, array('comment' => $comment->id), NULL, true); } else { $html = $PH->getLink('commentView', $comment->name, array('comment' => $comment->id)); } } break; case ITEM_PERSON: if ($person = Person::getVisibleById($item->id)) { if ($name) { $html = $PH->getLink('personView', $name, array('person' => $person->id), NULL, true); } else { $html = $PH->getLink('personView', $person->name, array('person' => $person->id)); } } break; case ITEM_PROJECT: if ($project = Project::getVisibleById($item->id)) { if ($name == "") { $name = asHtml($project->name); } $html = $PH->getLink('projView', $name, array('prj' => $project->id), NULL, true); } break; default: $html = '<em>' . sprintf(__('Cannot link to item #%s of type %s'), intval($target_id), $item->type) . '</em>'; break; } } return $html; }
function render_tr(&$item, $style = "") { global $PH; $str_date = ''; $str_name = ''; $str_url = ''; if ($i = DbProjectItem::getById($item->id)) { if ($i->modified) { $mod_date = $i->modified; $str_date = renderDateHtml($mod_date); if ($i->modified_by) { if ($person = Person::getVisibleById($i->modified_by)) { $str_name = asHtml($person->name); $str_url = $person->getLink(); } } print '<td><span class=date>' . $str_date . '</span><br><span class="sub who">' . __('by') . ' ' . $str_url . '</span></td>'; } else { print "<td class='nowrap'> </td>"; } } else { $PH->abortWarning("Could not get modification date of the element.", ERROR_BUG); print "<td class='nowrap'> </td>"; } }
/** * save field value of an item which has been edited inplace * and return formatted html code. * * If only a chapter has been edited, number defined in "chapter" */ function itemSaveField() { header("Content-type: text/html; charset=utf-8"); ### disable page caching ### header("Expires: -1"); header("Cache-Control: post-check=0, pre-check=0"); header("Pragma: no-cache"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); $value = get('value'); if (is_null($value)) { return; } if (!($item_id = get('item'))) { print "Failure"; return; } global $g_wiki_project; if (!($item = DbProjectItem::getEditableById($item_id))) { print "Failure"; return; } if (!($object = DbProjectItem::getObjectById($item_id))) { print "Failure"; return; } if ($item->type == ITEM_PROJECT) { if (!($project = Project::getVisibleById($item->id))) { print "Failure getting project"; return; } } else { if (!($project = Project::getVisibleById($item->project))) { print "Failure getting project"; return; } } $g_wiki_project = $project; $field_name = 'description'; if (get('field')) { $field_name = asCleanString(get('field')); } if (!isset($object->fields[$field_name])) { return NULL; } require_once confGet('DIR_STREBER') . 'render/render_wiki.inc.php'; $chapter = intVal(get('chapter')); ### replace complete field ### if (is_null($chapter)) { $object->{$field_name} = $value; } else { require_once confGet('DIR_STREBER') . 'render/render_wiki.inc.php'; /** * split originial wiki block into chapters * start with headline and belonging text */ $org = $object->{$field_name}; if ($object->type == ITEM_TASK) { global $g_wiki_task; $g_wiki_task = $object; } $parts = getWikiChapters($org); ### replace last line return (added by textarea) ### if (!preg_match("/\n\$/", $value)) { $value .= "\n"; } #$value= str_replace("\\'", "'", $value); #$value= str_replace('\\"', "\"", $value); $parts[$chapter] = $value; $new_wiki_text = implode('', $parts); $object->{$field_name} = $new_wiki_text; } ### update $object->update(array($field_name)); ### mark parent of comment as changes if ($item->type == ITEM_COMMENT) { if ($parent_task = Task::getById($object->task)) { print "calling now changed by user"; $parent_task->nowChangedByUser(); } } print wiki2purehtml($object->{$field_name}); $item->nowChangedByUser(); }
function render_tr(&$file, $style = "") { global $PH; if (!isset($file) || !$file instanceof File) { return; } require_once confGet('DIR_STREBER') . 'render/render_wiki.inc.php'; $buffer = '<b>'; $buffer .= $PH->getLink('fileDownload', $file->name, array('file' => $file->id)); $buffer .= '</b>' . '<br />'; ### name ### #$buffer = '<b>' # . $PH->getLink('fileView',$file->name, array('file'=>$file->id),'item file') # .'</b>' # . '<br>'; ### parent task ### $diz_buffer = ""; if ($file->parent_item && ($item = DbProjectItem::getVisibleById($file->parent_item))) { if ($item->type == ITEM_TASK) { if ($task = Task::getVisibleById($file->parent_item)) { $tmp = $task->getFolderLinks(); if ($tmp) { $tmp = $tmp . ">"; } $diz_buffer .= __("in", "... folder") . ": " . $tmp . $task->getLink(false) . "<br/>"; } } } ### details ### $diz_buffer .= $file->filesize . " bytes" . ' / ' . asHtml($file->mimetype) . ' / ' . sprintf(__("ID %s"), $file->id) . ' / ' . "<span class=sub>" . $PH->getLink('fileView', __('Show Details'), array('file' => $file->id)) . "</span>" . "<br/>"; ### description ### $diz_buffer .= wikifieldAsHtml($file, 'description'); if ($diz_buffer) { $buffer .= '<span class=sub>' . $diz_buffer . "</span>"; } echo '<td>' . $buffer . '</td>'; #$str= $PH->getLink('fileView',$obj->name, array('file'=>$obj->id),'item file'); #print "<td>$str</td>"; }
function render_tr(&$person, $style = "", $format = "html") { global $PH; global $auth; global $g_prio_names; global $csv_args; global $csv_count; $changes = DbProjectItem::getAll(array('modified_by' => $person->id, 'date_min' => $auth->cur_user->last_logout, 'not_modified_by' => $auth->cur_user->id)); if ($format == 'csv') { if (count($changes)) { $csv_args[$csv_count++] = count($changes); } else { $csv_args[$csv_count++] = ''; } } else { if (count($changes)) { print "<td>" . count($changes) . "</td>"; } else { print "<td></td>"; } } }
/** * renders a comparision between two versions of an item @ingroup pages */ function itemViewDiff() { global $PH; global $auth; require_once confGet('DIR_STREBER') . 'render/render_wiki.inc.php'; ### get task #### $item_id = get('item'); if (!($item = DbProjectItem::getObjectById($item_id))) { $PH->abortWarning("invalid item-id", ERROR_FATAL); } if (!($project = Project::getVisibleById($item->project))) { $PH->abortWarning("this item has an invalid project id", ERROR_DATASTRUCTURE); } require_once confGet('DIR_STREBER') . "db/db_itemchange.inc.php"; $versions = ItemVersion::getFromItem($item); $date1 = get('date1'); $date2 = get('date2'); if (!$date1) { #if(count($versions) > 1) { # if($auth->cur_user->last_logout < $versions[count($versions)-2]->date_to) # { # $date1 = $auth->cur_user->last_logout; # } # else { # $date1 = $versions[count($versions)-2]->date_from; # } #} #else { foreach (array_reverse($versions) as $v) { if ($v->author == $auth->cur_user->id) { $date1 = $v->date_from; break; } } #} } if (!$date2) { $date2 = getGMTString(); } $page = new Page(); $page->cur_tab = 'projects'; $page->crumbs = build_project_crumbs($project); $page->options = build_projView_options($project); $page->title = $item->name; $page->title_minor = __('changes'); $page->add_function(new PageFunction(array('target' => 'itemView', 'params' => array('item' => $item->id), 'icon' => 'edit', 'name' => __('View item')))); ### render title ### echo new PageHeader(); echo new PageContentOpen(); if ($date1 > $date2) { new FeedbackMessage(__("date1 should be smaller than date2. Swapped")); $t = $date1; $date1 = $date2; $date2 = $t; } if (count($versions) == 1) { echo __("item has not been edited history"); } else { $old_version = NULL; $version_right = NULL; $version_left = $versions[0]; foreach ($versions as $v) { if ($v->date_from <= $date1) { $version_left = $v; } if ($v->date_from >= $date2) { if (isset($version_right)) { if ($version_right->date_from > $v->date_from) { $version_right = $v; } } else { $version_right = $v; } } } if (!isset($version_right)) { $version_right = $versions[count($versions) - 1]; } $options_left = array(); $options_right = array(); ### list versions left ### for ($i = 0; $i < count($versions) - 1; $i++) { $v = $versions[$i]; if ($person = Person::getVisibleById($v->author)) { $author = $person->name; } else { $author = __('unknown'); } if ($v->version_number == $version_left->version_number) { $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $versions[$i]->date_to)); $name = ' v.' . $v->version_number . ' -- ' . $author . " -- " . $v->date_from; $options_left[] = "<option selected=1 value='" . $str_link . "'>" . $name . "</option>"; } else { if ($v->version_number > $version_left->version_number) { if ($v->version_number < $version_right->version_number) { $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $versions[$i]->date_to)); $name = '> v.' . $v->version_number . ' -- ' . $author . " -- " . renderDate($v->date_from); } else { $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $version_right->date_to)); $name = '>> v.' . $v->version_number . ' -- ' . $author . " -- " . renderDate($v->date_from); } $options_left[] = "<option value='" . $str_link . "'>" . $name . "</option>"; } else { $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $version_right->date_from)); $name = '< v.' . $v->version_number . ' -- ' . $author . " -- " . renderDate($v->date_from); $options_left[] = "<option value='" . $str_link . "'>" . $name . "</option>"; } } } ### list versions right ### for ($i = 1; $i < count($versions); $i++) { $v = $versions[$i]; if ($person = Person::getVisibleById($v->author)) { $author = $person->name; } else { $author = __('unknown'); } if ($v->version_number == $version_right->version_number) { $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $versions[$i]->date_to)); $name = ' v.' . $v->version_number . ' -- ' . $author . " -- " . $v->date_from; $options_right[] = "<option selected=1 value='" . $str_link . "'>" . $name . "</option>"; } else { if ($v->version_number > $version_right->version_number) { $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $version_left->date_from, 'date2' => $versions[$i]->date_from)); $name = '> v.' . $v->version_number . ' -- ' . $author . ' -- ' . renderDate($v->date_from); $options_right[] = "<option value='" . $str_link . "'>" . $name . "</option>"; } else { if ($v->version_number > $version_left->version_number) { $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $version_left->date_from, 'date2' => $versions[$i]->date_from)); $name = '< v.' . $v->version_number . ' -- ' . $author . " -- " . renderDate($v->date_from); } else { $str_link = $PH->getUrl('itemViewDiff', array('item' => $item->id, 'date1' => $versions[$i]->date_from, 'date2' => $versions[$i]->date_to)); $name = '<< v.' . $v->version_number . ' -- ' . $author . ' -- ' . renderDate($v->date_from); } $options_right[] = "<option value='" . $str_link . "'>" . $name . "</option>"; } } } ### prev ### if ($version_left->version_number > 1) { $link_prev = $PH->getLink('itemViewDiff', '<< ' . __('prev change'), array('item' => $item->id, 'date1' => $versions[$version_left->version_number - 2]->date_from, 'date2' => $versions[$version_left->version_number - 2]->date_to), NULL, true); } else { $link_prev = ''; } ### next ### if ($version_right->version_number < count($versions)) { $link_next = $PH->getLink('itemViewDiff', __('next') . '>>', array('item' => $item->id, 'date1' => $versions[$version_right->version_number - 1]->date_from, 'date2' => $versions[$version_right->version_number - 1]->date_to), NULL, true); } else { $link_next = ''; } ### summary ### $link_summary = $PH->getLink('itemViewDiff', __('summary'), array('item' => $item->id, 'date1' => $auth->cur_user->last_logout, 'date2' => getGMTString()), NULL, true); echo "<div class=diff>"; echo "<table class=nav><tr>"; echo "<td class=older>" . "<select onChange='location.href=this.options[this.selectedIndex].value'>" . join(array_reverse($options_left)) . "</select>" . '<br><b class=doclear></b>' . $link_prev . "</td>"; echo "<td class=newer>" . "<select onChange='location.href=this.options[this.selectedIndex].value'>" . join(array_reverse($options_right)) . "</select>" . '<br><b class=doclear></b>' . $link_next . $link_summary . "</td>"; echo "</table>"; #if(!$date2 || !$date1) { # echo sprintf(__("Item did not exists at %s"), renderTime($date2)); #} if ($old_version == $version_right) { echo sprintf(__('no changes between %s and %s'), renderTime($date1), renderTime($date2)); } ### collect changes ### $old_field_values = array(); $new_field_values = array(); foreach ($versions as $v) { if ($v->version_number <= $version_left->version_number) { foreach ($v->values as $name => $value) { $old_field_values[$name] = $value; } } if ($v->version_number >= $version_left->version_number && $v->version_number < $version_right->version_number) { foreach ($v->values_next as $name => $value) { $new_field_values[$name] = $value; } } } foreach ($new_field_values as $field_name => $value) { echo "<h2>{$field_name}</h2>"; $old_value = isset($old_field_values[$field_name]) ? $old_field_values[$field_name] : ""; $new_value = isset($new_field_values[$field_name]) ? $new_field_values[$field_name] : ''; $field_type = $item->fields[$field_name]->type; if ($field_type == 'FieldText') { echo render_changes($old_value, $new_value); } else { if ($field_type == 'FieldOption') { if ($field_name == 'status') { global $g_status_names; $old_value = isset($g_status_names[$old_value]) ? $g_status_names[$old_value] : __('undefined'); $new_value = isset($g_status_names[$new_value]) ? $g_status_names[$new_value] : __('undefined'); } else { if ($field_name == 'label') { if ($project = Project::getVisibleById($item->project)) { $labels = explode(",", $project->labels); $old_value = isset($labels[$old_value - 1]) ? $labels[$old_value - 1] : __('undefined'); $new_value = isset($labels[$new_value - 1]) ? $labels[$new_value - 1] : __('undefined'); } } } echo render_changes($old_value, $new_value); } else { if ($field_type == 'FieldInternal') { if ($field_name == 'parent_item') { if ($task_parent_old = Task::getVisibleById($old_value)) { $ar = array(); foreach ($task_parent_old->getFolder() as $f) { $ar[] = $f->name; } $ar[] = $task_parent_old->name; $old_value = join($ar, " > "); } if ($task_parent_new = Task::getVisibleById($new_value)) { $ar = array(); foreach ($task_parent_new->getFolder() as $f) { $ar[] = $f->name; } $ar[] = $task_parent_new->name; $new_value = join($ar, " > "); } } else { if ($field_name == 'state') { $old_value = $old_value == -1 ? __('deleted') : __('ok'); $new_value = $new_value == -1 ? __('deleted') : __('ok'); } else { if ($field_name == 'pub_level') { global $g_pub_level_names; $old_value = isset($g_pub_level_names[$old_value]) ? $g_pub_level_names[$old_value] : __('undefined'); $new_value = isset($g_pub_level_names[$new_value]) ? $g_pub_level_names[$new_value] : __('undefined'); } } } echo render_changes($old_value, $new_value); } else { if ($field_type == 'FieldPercentage') { echo render_changes($old_value, $new_value); } else { if ($field_type == 'FieldInt') { echo render_changes($old_value, $new_value); } else { if ($field_type == 'FieldString') { echo render_changes($old_value, $new_value); } else { if ($field_type == 'FieldDate') { echo render_changes(renderDate($old_value), renderDate($new_value)); } else { if ($field_type == 'FieldDatetime') { echo render_changes(renderTimestamp($old_value), renderTimestamp($new_value)); } } } } } } } } } } echo "</div>"; echo new PageContentClose(); echo new PageHtmlEnd(); }
/** * edit several bookmarks @ingroup pages */ function itemBookmarkEditMultiple($thebookmarks = NULL) { global $PH; global $auth; global $g_notitychange_period; $is_already_bookmark = array(); $bookmarks = array(); $items = array(); $edit_fields = array('notify_if_unchanged', 'notify_on_change'); $different_fields = array(); # hash containing fieldnames which are different in bookmarks if (!$thebookmarks) { $item_ids = getPassedIds('bookmark', 'bookmarks_*'); foreach ($item_ids as $is) { if ($bookmark = ItemPerson::getAll(array('item' => $is, 'person' => $auth->cur_user->id))) { if ($item = DbProjectItem::getById($bookmark[0]->item)) { $bookmarks[] = $bookmark[0]; $items[] = $item; $is_already_bookmark[$bookmark[0]->id] = true; } } } } else { $item_ids = $thebookmarks; foreach ($item_ids as $is) { if ($bookmark = ItemPerson::getAll(array('item' => $is, 'person' => $auth->cur_user->id, 'is_bookmark' => 0))) { if ($item = DbProjectItem::getById($bookmark[0]->item)) { $bookmarks[] = $bookmark[0]; $items[] = $item; $is_already_bookmark[$bookmark[0]->id] = false; } } elseif ($bookmark = ItemPerson::getAll(array('item' => $is, 'person' => $auth->cur_user->id, 'is_bookmark' => 1))) { if ($item = DbProjectItem::getById($bookmark[0]->item)) { $bookmarks[] = $bookmark[0]; $items[] = $item; $is_already_bookmark[$bookmark[0]->id] = true; } } else { $date = getGMTString(); $bookmark = new ItemPerson(array('id' => 0, 'item' => $is, 'person' => $auth->cur_user->id, 'is_bookmark' => 1, 'notify_if_unchanged' => 0, 'notify_on_change' => 0, 'created' => $date)); if ($item = DbProjectItem::getById($is)) { $bookmarks[] = $bookmark; $items[] = $item; $is_already_bookmark[$bookmark->id] = false; } } } } if (!$items) { $PH->abortWarning(__("Please select some items")); } $page = new Page(); $page->cur_tab = 'home'; $page->options = array(new NaviOption(array('target_id' => 'itemBookmarkEdit', 'name' => __('Edit bookmarks')))); $page->type = __('Edit multiple bookmarks', 'page title'); $page->title = sprintf(__('Edit %s bookmark(s)'), count($items)); $page->title_minor = __('Edit'); echo new PageHeader(); echo new PageContentOpen(); echo "<ol>"; foreach ($items as $item) { ## get item name ## $str_link = ''; if ($type = $item->type) { switch ($type) { case ITEM_TASK: require_once "db/class_task.inc.php"; if ($task = Task::getVisibleById($item->id)) { $str_link = $task->getLink(false); } break; case ITEM_COMMENT: require_once "db/class_comment.inc.php"; if ($comment = Comment::getVisibleById($item->id)) { $str_link = $comment->getLink(false); } break; case ITEM_PERSON: require_once "db/class_person.inc.php"; if ($person = Person::getVisibleById($item->id)) { $str_link = $person->getLink(false); } break; case ITEM_EFFORT: require_once "db/class_effort.inc.php"; if ($e = Effort::getVisibleById($item->id)) { $str_link = $e->getLink(false); } break; case ITEM_FILE: require_once "db/class_file.inc.php"; if ($f = File::getVisibleById($item->id)) { $str_link = $f->getLink(false); } break; case ITEM_PROJECT: require_once "db/class_project.inc.php"; if ($prj = Project::getVisibleById($item->id)) { $str_link = $prj->getLink(false); } break; case ITEM_COMPANY: require_once "db/class_company.inc.php"; if ($c = Company::getVisibleById($item->id)) { $str_link = $c->getLink(false); } break; case ITEM_VERSION: require_once "db/class_task.inc.php"; if ($tsk = Task::getVisibleById($item->id)) { $str_link = $tsk->getLink(false); } break; default: break; } } echo "<li>" . $str_link . "</li>"; } echo "</ol>"; foreach ($bookmarks as $bookmark) { foreach ($edit_fields as $field_name) { if ($bookmark->{$field_name} != $bookmarks[0]->{$field_name}) { $different_fields[$field_name] = true; } } } $block = new PageBlock(array('id' => 'functions')); $block->render_blockStart(); $form = new PageForm(); $form->button_cancel = true; $b = array(); $b[0] = __('no'); $b[1] = __('yes'); if (isset($different_fields['notify_on_change'])) { $b[-1] = '-- ' . __('keep different') . ' --'; $form->add(new Form_Dropdown('notify_on_change', __("Notify on change"), array_flip($b), -1)); } else { $form->add(new Form_Dropdown('notify_on_change', __("Notify on change"), array_flip($b), $bookmarks[0]->notify_on_change)); } $a = array(); foreach ($g_notitychange_period as $key => $value) { $a[$key] = $value; } if (isset($different_fields['notify_if_unchanged'])) { $a[-1] = '-- ' . __('keep different') . ' --'; $form->add(new Form_Dropdown('notify_if_unchanged', __("Notify if unchanged in"), array_flip($a), -1)); } else { $form->add(new Form_Dropdown('notify_if_unchanged', __("Notify if unchanged in"), array_flip($a), $bookmarks[0]->notify_if_unchanged)); } $number = 0; foreach ($bookmarks as $bm) { $form->add(new Form_HiddenField("bookmark_id_{$number}", '', $bm->id)); $form->add(new Form_HiddenField("bookmark_item_{$number}", '', $bm->item)); $form->add(new Form_HiddenField("is_already_bookmark_{$number}", '', $is_already_bookmark[$bm->id])); $number++; } $form->add(new Form_HiddenField("number", '', $number)); echo $form; $block->render_blockEnd(); $PH->go_submit = 'itemBookmarkEditMultipleSubmit'; echo new PageContentClose(); echo new PageHtmlEnd(); }
private function addUntouchedMonitoredItems() { $unchanged_headline_html = ''; $unchanged_headline_txt = ''; $unchanged_body_html = ''; $unchanged_body_plaintext = ''; $monitored_items_unchanged = ItemPerson::getAll(array('is_bookmark' => 1, 'notify_if_unchanged_min' => NOTIFY_1DAY, 'person' => $this->recipient->id)); if (!$monitored_items_unchanged) { return; } foreach ($monitored_items_unchanged as $miu) { ## reminder period ## $period = ''; switch ($miu->notify_if_unchanged) { case NOTIFY_1DAY: $period = 24 * 60 * 60; break; case NOTIFY_2DAYS: $period = 2 * 24 * 60 * 60; break; case NOTIFY_3DAYS: $period = 3 * 24 * 60 * 60; break; case NOTIFY_4DAYS: $period = 4 * 24 * 60 * 60; break; case NOTIFY_5DAYS: $period = 5 * 24 * 60 * 60; break; case NOTIFY_1WEEK: $period = 7 * 24 * 60 * 60; break; case NOTIFY_2WEEKS: $period = 2 * 7 * 24 * 60 * 60; break; case NOTIFY_3WEEKS: $period = 3 * 7 * 24 * 60 * 60; break; case NOTIFY_1MONTH: $period = 4 * 7 * 24 * 60 * 60; break; case NOTIFY_2MONTH: $period = 2 * 4 * 7 * 24 * 60 * 60; break; } $date = $miu->notify_date; if ($pi = DbProjectItem::getVisibleById($miu->item)) { $mod_date = $pi->modified; if ($date != '0000-00-00 00:00:00') { $date = strToGMTime($date) + $period; $date = date('Y-m-d H:i:s', $date); if ($date >= $mod_date && strToGMTime($date) <= time()) { $diff = strToGMTime($date) - strToGMTime($mod_date); if ($diff >= $period) { ### diff in days ### $information_count++; $days = round((time() - strToGMTime($miu->notify_date)) / 60 / 60 / 24); $object = DbProjectItem::getObjectById($pi->id); $unchanged_body_html .= '<li>' . sprintf(__("%s (not touched since %s day(s))"), asHtml($object->name), $days) . '</li>'; $unchanged_body_plaintext .= '- ' . sprintf(__("%s (not touched since %s day(s))"), $object->name, $days) . '\\n\\r'; } } } } } if ($unchanged_body_html) { $this->information_count++; $this->body_html .= "<h3>" . __('Unchanged monitored items:', 'notification') . "</h3>" . "<ul>" . $unchanged_body_html . "</ul>"; $this->body_plaintext .= "\n\r" . __('Unchanged monitored items:', 'notification') . "\n\r" . $unchanged_body_plaintext; } }
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; }
/** * revert changes of a person * * Notes: * - This function is only available of people with RIGHT_PROJECT_EDIT. * - This will only effect changes to fields. * - Following changes will not be reverted: * - Creation of new items (Tasks, Topis, Efforts, Projects, etc.) * - Task-assignments * - Uploading of files * * person - id of person who did the changes * data - date to with revert changes * delete_history (Default off) - Reverting can't be undone! The person's modification are lost forever! * This can be useful on massive changes to avoid sending huge * notification mails. */ function personRevertChanges() { global $PH; global $auth; ### check rights ### if (!$auth->cur_user->user_rights & RIGHT_PROJECT_EDIT) { $PH->abortWarning("You require the right to edit projects."); } ### get person ### $person_id = getOnePassedId('person', 'people_*'); if (!($person = Person::getVisibleById($person_id))) { $PH->abortWarning(sprintf(__("invalid Person #%s"), $person_id)); return; } $page = new Page(); $page->tabs['admin'] = array('target' => "index.php?go=systemInfo", 'title' => __('Admin', 'top navigation tab'), 'bg' => "misc"); $page->cur_tab = 'admin'; $page->crumbs[] = new NaviCrumb(array('target_id' => 'systemInfo')); $page->title = __("Reverting user changes"); $page->type = __("Admin"); #$page->title_minor=get('go'); echo new PageHeader(); echo new PageContentOpen(); $block = new PageBlock(array('title' => __('Overview'), 'id' => 'overview')); $block->render_blockStart(); echo "<div class=text>"; echo "<ul>"; ### get changes of person ### $count_reverted_fields = 0; $changes = ItemChange::getItemChanges(array('person' => $person_id, 'order_by' => 'id DESC')); foreach ($changes as $c) { if (!($project_item = DbProjectItem::getObjectById($c->item))) { #print "unable to get item %s" % $c->item; } else { ### Only revert changes, if item has not be editted by other person if ($project_item->modified_by == $person_id) { $field_name = $c->field; echo "<li>" . "<strong>" . asHtml($project_item->name) . "." . asHtml($field_name) . "</strong>" . " '" . asHtml($project_item->{$field_name}) . "' = '" . asHtml($c->value_old) . "'" . "</li>"; $count_reverted_fields++; if ($field_name == 'state') { if ($project_item->state == -1 && $c->value_old == 1) { $project_item->deleted_by = "0"; $project_item->deleted = "0000-00-00 00-00-00"; } } $project_item->{$field_name} = $c->value_old; $project_item->update(array($field_name, 'deleted_by', 'deleted'), false, false); } else { echo "<li>" . sprintf(__("Skipped recently editted item #%s: <b>%s<b>"), $project_item->id, asHtml($project_item->name)) . "</li>"; } $c->deleteFull(); } } echo "</ul>"; echo "<p>" . sprintf(__("Reverted all changes (%s) of user %s"), $count_reverted_fields, asHtml($person->nickname)) . "</p>"; echo "<p>" . __("newly created items by this user remain unaffected.") . "</p>"; echo "</div>"; $block->render_blockEnd(); ### close page echo new PageContentClose(); echo new PageHtmlEnd(); }
public function print_automatic() { global $PH; if (!($this->active_block_function = $this->getBlockStyleFromCookie())) { $this->active_block_function = 'list'; } $this->query_options['alive_only'] = false; $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 ### foreach ($this->filters as $f) { foreach ($f->getQuerryAttributes() as $k => $v) { $this->query_options[$k] = $v; } } ### grouped view ### if ($this->active_block_function == 'grouped') { /** * @@@ 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]); } ### 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(); } } else { $pass = true; } $changes = DbProjectItem::getChanges($this->query_options); $this->render_list($changes); }