示例#1
0
/**
 * XXX: A mess,remove my in 1.0. No time for that, sorry.
 */
function event_description($history)
{
    $return = '';
    global $fs, $baseurl, $details, $proj;
    $translate = array('item_summary' => 'summary', 'project_id' => 'attachedtoproject', 'task_type' => 'tasktype', 'product_category' => 'category', 'item_status' => 'status', 'task_priority' => 'priority', 'operating_system' => 'operatingsystem', 'task_severity' => 'severity', 'product_version' => 'reportedversion', 'mark_private' => 'visibility', 'estimated_effort' => 'estimatedeffort');
    // if somehing gets double escaped, add it here.
    $noescape = array('new_value', 'old_value');
    foreach ($history as $key => $value) {
        if (!in_array($key, $noescape)) {
            $history[$key] = Filters::noXSS($value);
        }
    }
    $new_value = $history['new_value'];
    $old_value = $history['old_value'];
    switch ($history['event_type']) {
        case '3':
            //Field changed
            if (!$new_value && !$old_value) {
                $return .= eL('taskedited');
                break;
            }
            $field = $history['field_changed'];
            switch ($field) {
                case 'item_summary':
                case 'project_id':
                case 'task_type':
                case 'product_category':
                case 'item_status':
                case 'task_priority':
                case 'operating_system':
                case 'task_severity':
                case 'product_version':
                    if ($field == 'task_priority') {
                        $old_value = $fs->priorities[$old_value];
                        $new_value = $fs->priorities[$new_value];
                    } elseif ($field == 'task_severity') {
                        $old_value = $fs->severities[$old_value];
                        $new_value = $fs->severities[$new_value];
                    } elseif ($field == 'item_summary') {
                        $old_value = Filters::noXSS($old_value);
                        $new_value = Filters::noXSS($new_value);
                    } else {
                        $old_value = $history[$field . '1'];
                        $new_value = $history[$field . '2'];
                    }
                    $field = eL($translate[$field]);
                    break;
                case 'closedby_version':
                    $field = eL('dueinversion');
                    $old_value = $old_value == '0' ? eL('undecided') : $history['product_version1'];
                    $new_value = $new_value == '0' ? eL('undecided') : $history['product_version2'];
                    break;
                case 'due_date':
                    $field = eL('duedate');
                    $old_value = formatDate($old_value, false, eL('undecided'));
                    $new_value = formatDate($new_value, false, eL('undecided'));
                    break;
                case 'percent_complete':
                    $field = eL('percentcomplete');
                    $old_value .= '%';
                    $new_value .= '%';
                    break;
                case 'mark_private':
                    $field = eL($translate[$field]);
                    if ($old_value == 1) {
                        $old_value = eL('private');
                    } else {
                        $old_value = eL('public');
                    }
                    if ($new_value == 1) {
                        $new_value = eL('private');
                    } else {
                        $new_value = eL('public');
                    }
                    break;
                case 'detailed_desc':
                    $field = "<a href=\"javascript:getHistory('{$history['task_id']}', '{$baseurl}', 'history', '{$history['history_id']}');showTabById('history', true);\">" . eL('details') . '</a>';
                    if (!empty($details)) {
                        $details_previous = TextFormatter::render($old_value);
                        $details_new = TextFormatter::render($new_value);
                    }
                    $old_value = '';
                    $new_value = '';
                    break;
                case 'estimated_effort':
                    $field = eL($translate[$field]);
                    $old_value = effort::SecondsToString($old_value, $proj->prefs['hours_per_manday'], $proj->prefs['estimated_effort_format']);
                    $new_value = effort::SecondsToString($new_value, $proj->prefs['hours_per_manday'], $proj->prefs['estimated_effort_format']);
                    break;
            }
            $return .= eL('fieldchanged') . ": {$field}";
            if ($old_value || $new_value) {
                $return .= " ({$old_value} &rarr; {$new_value})";
            }
            break;
        case '1':
            //Task opened
            $return .= eL('taskopened');
            break;
        case '2':
            //Task closed
            $return .= eL('taskclosed');
            $return .= " ({$history['resolution_name']}";
            if (!empty($old_value)) {
                $return .= ': ' . TextFormatter::render($old_value, true);
            }
            $return .= ')';
            break;
        case '4':
            //Comment added
            $return .= '<a href="#comments">' . eL('commentadded') . '</a>';
            break;
        case '5':
            //Comment edited
            $return .= "<a href=\"javascript:getHistory('{$history['task_id']}', '{$baseurl}', 'history', '{$history['history_id']}');\">" . eL('commentedited') . "</a>";
            if ($history['c_date_added']) {
                $return .= " (" . eL('commentby') . ' ' . tpl_userlink($history['c_user_id']) . " - " . formatDate($history['c_date_added'], true) . ")";
            }
            if ($details) {
                $details_previous = TextFormatter::render($old_value);
                $details_new = TextFormatter::render($new_value);
            }
            break;
        case '6':
            //Comment deleted
            $return .= "<a href=\"javascript:getHistory('{$history['task_id']}', '{$baseurl}', 'history', '{$history['history_id']}');\">" . eL('commentdeleted') . "</a>";
            if ($new_value != '' && $history['field_changed'] != '') {
                $return .= " (" . eL('commentby') . ' ' . tpl_userlink($new_value) . " - " . formatDate($history['field_changed'], true) . ")";
            }
            if (!empty($details)) {
                $details_previous = TextFormatter::render($old_value);
                $details_new = '';
            }
            break;
        case '7':
            //Attachment added
            $return .= eL('attachmentadded');
            if ($history['orig_name']) {
                $return .= ": <a href=\"{$baseurl}?getfile=" . intval($new_value) . '">' . "{$history['orig_name']}</a>";
            } else {
                if ($history['old_value']) {
                    $return .= ': ' . $history['old_value'];
                }
            }
            break;
        case '8':
            //Attachment deleted
            $return .= eL('attachmentdeleted') . ': ' . Filters::noXSS($new_value);
            break;
        case '9':
            //Notification added
            $return .= eL('notificationadded') . ': ' . tpl_userlink($new_value);
            break;
        case '10':
            //Notification deleted
            $return .= eL('notificationdeleted') . ': ' . tpl_userlink($new_value);
            break;
        case '11':
            //Related task added
            $return .= eL('relatedadded') . ': ' . tpl_tasklink($new_value);
            break;
        case '12':
            //Related task deleted
            $return .= eL('relateddeleted') . ': ' . tpl_tasklink($new_value);
            break;
        case '13':
            //Task reopened
            $return .= eL('taskreopened');
            break;
        case '14':
            //Task assigned
            if (empty($old_value)) {
                $users = explode(' ', trim($new_value));
                $users = array_map('tpl_userlink', $users);
                $return .= eL('taskassigned') . ' ';
                $return .= implode(', ', $users);
            } elseif (empty($new_value)) {
                $return .= eL('assignmentremoved');
            } else {
                $users = explode(' ', trim($new_value));
                $users = array_map('tpl_userlink', $users);
                $return .= eL('taskreassigned') . ' ';
                $return .= implode(', ', $users);
            }
            break;
            // Mentioned in docs, not used anywhere. Will implement if suitable
            // translations already exist, otherwise leave to 1.1. (Found translations)
        // Mentioned in docs, not used anywhere. Will implement if suitable
        // translations already exist, otherwise leave to 1.1. (Found translations)
        case '15':
            // This task was added to another task's related list
            $return .= eL('addedasrelated') . ': ' . tpl_tasklink($new_value);
            break;
        case '16':
            // This task was removed from another task's related list
            $return .= eL('deletedasrelated') . ': ' . tpl_tasklink($new_value);
            break;
        case '17':
            //Reminder added
            $return .= eL('reminderadded') . ': ' . tpl_userlink($new_value);
            break;
        case '18':
            //Reminder deleted
            $return .= eL('reminderdeleted') . ': ' . tpl_userlink($new_value);
            break;
        case '19':
            //User took ownership
            $return .= eL('ownershiptaken') . ': ' . tpl_userlink($new_value);
            break;
        case '20':
            //User requested task closure
            $return .= eL('closerequestmade') . ' - ' . $new_value;
            break;
        case '21':
            //User requested task
            $return .= eL('reopenrequestmade') . ' - ' . $new_value;
            break;
        case '22':
            // Dependency added
            $return .= eL('depadded') . ' ' . tpl_tasklink($new_value);
            break;
        case '23':
            // Dependency added to other task
            $return .= eL('depaddedother') . ' ' . tpl_tasklink($new_value);
            break;
        case '24':
            // Dependency removed
            $return .= eL('depremoved') . ' ' . tpl_tasklink($new_value);
            break;
        case '25':
            // Dependency removed from other task
            $return .= eL('depremovedother') . ' ' . tpl_tasklink($new_value);
            break;
            // 26 and 27 replaced by 0 (mark_private)
        // 26 and 27 replaced by 0 (mark_private)
        case '28':
            // PM request denied
            $return .= eL('pmreqdenied') . ' - ' . $new_value;
            break;
        case '29':
            // User added to assignees list
            $return .= eL('addedtoassignees');
            break;
        case '30':
            // user created
            $return .= eL('usercreated');
            break;
        case '31':
            // user deleted
            $return .= eL('userdeleted');
            break;
        case '32':
            // Subtask added
            $return .= eL('subtaskadded') . ' ' . tpl_tasklink($new_value);
            break;
        case '33':
            // Subtask removed
            $return .= eL('subtaskremoved') . ' ' . tpl_tasklink($new_value);
            break;
        case '34':
            // supertask added
            $return .= eL('supertaskadded') . ' ' . tpl_tasklink($new_value);
            break;
        case '35':
            // supertask removed
            $return .= eL('supertaskremoved') . ' ' . tpl_tasklink($new_value);
            break;
    }
    if (isset($details_previous)) {
        $GLOBALS['details_previous'] = $details_previous;
    }
    if (isset($details_new)) {
        $GLOBALS['details_new'] = $details_new;
    }
    return $return;
}
示例#2
0
文件: index.php 项目: peklov/flyspray
function tpl_draw_cell($task, $colname, $format = "<td class='%s'>%s</td>")
{
    global $fs, $proj, $page, $user;
    $indexes = array('id' => 'task_id', 'project' => 'project_title', 'tasktype' => 'task_type', 'tasktypename' => 'tasktype_name', 'category' => 'category_name', 'severity' => '', 'priority' => '', 'summary' => 'item_summary', 'dateopened' => 'date_opened', 'status' => 'status_name', 'openedby' => 'opened_by_name', 'assignedto' => 'assigned_to_name', 'lastedit' => 'max_date', 'reportedin' => 'product_version_name', 'dueversion' => 'closedby_version_name', 'duedate' => 'due_date', 'comments' => 'num_comments', 'votes' => 'num_votes', 'attachments' => 'num_attachments', 'dateclosed' => 'date_closed', 'progress' => '', 'os' => 'os_name', 'private' => 'mark_private', 'parent' => 'supertask_id', 'estimatedeffort' => 'estimated_effort');
    //must be an array , must contain elements and be alphanumeric (permitted  "_")
    if (!is_array($task) || empty($task) || preg_match('![^A-Za-z0-9_]!', $colname)) {
        //run away..
        return '';
    }
    $class = 'task_' . $colname;
    switch ($colname) {
        case 'id':
            $value = tpl_tasklink($task, $task['task_id']);
            break;
        case 'summary':
            $value = tpl_tasklink($task, utf8_substr($task['item_summary'], 0, 55));
            if (utf8_strlen($task['item_summary']) > 55) {
                $value .= '...';
            }
            break;
        case 'tasktype':
            $value = $task['tasktype_name'];
            $class .= ' typ' . $task['task_type'];
            break;
        case 'severity':
            $value = $task['task_severity'] == 0 ? '' : $fs->severities[$task['task_severity']];
            $class .= ' sev' . $task['task_severity'];
            break;
        case 'priority':
            $value = $task['task_priority'] == 0 ? '' : $fs->priorities[$task['task_priority']];
            $class .= ' pri' . $task['task_priority'];
            break;
        case 'lastedit':
        case 'duedate':
        case 'dateopened':
        case 'dateclosed':
            $value = formatDate($task[$indexes[$colname]]);
            break;
        case 'status':
            if ($task['is_closed']) {
                $value = eL('closed');
            } else {
                $value = htmlspecialchars($task[$indexes[$colname]], ENT_QUOTES, 'utf-8');
            }
            break;
        case 'progress':
            $value = tpl_img($page->get_image('percent-' . $task['percent_complete'], false), $task['percent_complete'] . '%');
            break;
        case 'assignedto':
            $value = htmlspecialchars($task[$indexes[$colname]], ENT_QUOTES, 'utf-8');
            if ($task['num_assigned'] > 1) {
                $value .= ', +' . ($task['num_assigned'] - 1);
            }
            break;
        case 'private':
            $value = $task[$indexes[$colname]] ? L('yes') : L('no');
            break;
        case 'parent':
            $value = '';
            if ($task['supertask_id'] > 0) {
                $value = tpl_tasklink($task, $task['supertask_id']);
            }
            break;
        case 'estimatedeffort':
            $value = '';
            if ($user->perms('view_estimated_effort')) {
                if ($task['estimated_effort'] > 0) {
                    $value = effort::SecondsToString($task['estimated_effort'], $proj->prefs['hours_per_manday'], $proj->prefs['estimated_effort_format']);
                }
            }
            break;
        case 'effort':
            $value = '';
            if ($user->perms('view_current_effort_done')) {
                if ($task['effort'] > 0) {
                    $value = effort::SecondsToString($task['effort'], $proj->prefs['hours_per_manday'], $proj->prefs['current_effort_done_format']);
                }
            }
            break;
        default:
            $value = '';
            // $colname here is NOT column name in database but a name that can appear
            // both in a projects visible fields and as a key in language translation
            // file, which is also used to draw a localized heading. Column names in
            // database customarily use _ t to separate words, translation file entries
            // instead do not and can be also be quite different. If you do see an empty
            // value when you expected something, check your usage, what visible fields
            // in database actually constains, and maybe add a mapping from $colname to
            // to the database column name to array $indexes at the beginning of this
            // function. Note that inconsistencies between $colname, database column
            // name, translation entry key and name in visible fields do occur sometimes
            // during development phase.
            if (array_key_exists($colname, $indexes)) {
                $value = htmlspecialchars($task[$indexes[$colname]], ENT_QUOTES, 'utf-8');
            }
            break;
    }
    return sprintf($format, $class, $value);
}
示例#3
0
function tpl_draw_cell($task, $colname, $format = "<td class='%s'>%s</td>")
{
    global $fs, $db, $proj, $page, $user;
    $indexes = array('id' => 'task_id', 'project' => 'project_title', 'tasktype' => 'task_type', 'tasktypename' => 'tasktype_name', 'category' => 'category_name', 'severity' => '', 'priority' => '', 'summary' => 'item_summary', 'dateopened' => 'date_opened', 'status' => 'status_name', 'openedby' => 'opened_by', 'openedbyname' => 'opened_by_name', 'assignedto' => 'assigned_to_name', 'lastedit' => 'max_date', 'editedby' => 'last_edited_by', 'reportedin' => 'product_version_name', 'dueversion' => 'closedby_version_name', 'duedate' => 'due_date', 'comments' => 'num_comments', 'votes' => 'num_votes', 'attachments' => 'num_attachments', 'dateclosed' => 'date_closed', 'closedby' => 'closed_by', 'commentedby' => 'commented_by', 'progress' => '', 'os' => 'os_name', 'private' => 'mark_private', 'parent' => 'supertask_id', 'estimatedeffort' => 'estimated_effort');
    //must be an array , must contain elements and be alphanumeric (permitted  "_")
    if (!is_array($task) || empty($task) || preg_match('![^A-Za-z0-9_]!', $colname)) {
        //run away..
        return '';
    }
    $class = 'task_' . $colname;
    switch ($colname) {
        case 'id':
            $value = tpl_tasklink($task, $task['task_id']);
            break;
        case 'summary':
            $value = tpl_tasklink($task, utf8_substr($task['item_summary'], 0, 55));
            if (utf8_strlen($task['item_summary']) > 55) {
                $value .= '...';
            }
            # <i> instead of <span> in future for smaller size
            # we need also some bytes for classes like <i class="tag t123">tagname</i>
            if ($task['tags'] != '') {
                $tags = explode(',', $task['tags']);
                $tagids = explode(',', $task['tagids']);
                $tagclass = explode(',', $task['tagclass']);
                $tgs = '';
                for ($i = 0; $i < count($tags); $i++) {
                    $tgs .= '<i class="tag t' . $tagids[$i] . ($tagclass[$i] ? ' ' . $tagclass[$i] : '') . '" title="' . $tags[$i] . '"></i>';
                }
                $value .= $tgs;
            }
            break;
        case 'tasktype':
            $value = $task['tasktype_name'];
            $class .= ' typ' . $task['task_type'];
            break;
        case 'severity':
            $value = $task['task_severity'] == 0 ? '' : $fs->severities[$task['task_severity']];
            $class .= ' sev' . $task['task_severity'];
            break;
        case 'priority':
            $value = $task['task_priority'] == 0 ? '' : $fs->priorities[$task['task_priority']];
            $class .= ' pri' . $task['task_priority'];
            break;
        case 'lastedit':
        case 'duedate':
        case 'dateopened':
        case 'dateclosed':
            $value = formatDate($task[$indexes[$colname]]);
            break;
        case 'status':
            if ($task['is_closed']) {
                $value = eL('closed');
            } else {
                $value = htmlspecialchars($task[$indexes[$colname]], ENT_QUOTES, 'utf-8');
            }
            break;
        case 'progress':
            $value = tpl_img($page->get_image('percent-' . $task['percent_complete'], false), $task['percent_complete'] . '%');
            break;
        case 'assignedto':
            # group_concat-ed for mysql/pgsql
            #$value = htmlspecialchars($task[$indexes[$colname]], ENT_QUOTES, 'utf-8');
            $value = '';
            $anames = explode(',', $task[$indexes[$colname]]);
            $aids = explode(',', $task['assignedids']);
            $aimages = explode(',', $task['assigned_image']);
            for ($a = 0; $a < count($anames); $a++) {
                if ($aids[$a]) {
                    if ($fs->prefs['enable_avatars'] == 1 && $aimages[$a]) {
                        $value .= tpl_userlinkavatar($aids[$a], 30);
                    } else {
                        $value .= tpl_userlink($aids[$a]);
                    }
                    #$value.='<a href="'.$aids[$a].'">'.htmlspecialchars($anames[$a], ENT_QUOTES, 'utf-8').'</a>';
                }
            }
            # fallback for DBs we haven't written sql string aggregation yet (currently with group_concat() mysql and array_agg() postgresql)
            if ('postgres' != $db->dblink->dataProvider && 'mysql' != $db->dblink->dataProvider && $task['num_assigned'] > 1) {
                $value .= ', +' . ($task['num_assigned'] - 1);
            }
            break;
        case 'private':
            $value = $task[$indexes[$colname]] ? L('yes') : L('no');
            break;
        case 'commentedby':
        case 'openedby':
        case 'editedby':
        case 'closedby':
            $value = '';
            # a bit expensive! tpl_userlinkavatar()  an additional sql query for each new user in the output table
            # at least tpl_userlink() uses a $cache array so query for repeated users
            if ($task[$indexes[$colname]] > 0) {
                if ($fs->prefs['enable_avatars'] == 1) {
                    $value = tpl_userlinkavatar($task[$indexes[$colname]], 30);
                } else {
                    $value = tpl_userlink($task[$indexes[$colname]]);
                }
            }
            break;
        case 'parent':
            $value = '';
            if ($task['supertask_id'] > 0) {
                $value = tpl_tasklink($task, $task['supertask_id']);
            }
            break;
        case 'estimatedeffort':
            $value = '';
            if ($user->perms('view_estimated_effort')) {
                if ($task['estimated_effort'] > 0) {
                    $value = effort::SecondsToString($task['estimated_effort'], $proj->prefs['hours_per_manday'], $proj->prefs['estimated_effort_format']);
                }
            }
            break;
        case 'effort':
            $value = '';
            if ($user->perms('view_current_effort_done')) {
                if ($task['effort'] > 0) {
                    $value = effort::SecondsToString($task['effort'], $proj->prefs['hours_per_manday'], $proj->prefs['current_effort_done_format']);
                }
            }
            break;
        default:
            $value = '';
            // $colname here is NOT column name in database but a name that can appear
            // both in a projects visible fields and as a key in language translation
            // file, which is also used to draw a localized heading. Column names in
            // database customarily use _ t to separate words, translation file entries
            // instead do not and can be also be quite different. If you do see an empty
            // value when you expected something, check your usage, what visible fields
            // in database actually constains, and maybe add a mapping from $colname to
            // to the database column name to array $indexes at the beginning of this
            // function. Note that inconsistencies between $colname, database column
            // name, translation entry key and name in visible fields do occur sometimes
            // during development phase.
            if (array_key_exists($colname, $indexes)) {
                $value = htmlspecialchars($task[$indexes[$colname]], ENT_QUOTES, 'utf-8');
            }
            break;
    }
    return sprintf($format, $class, $value);
}