function custom_function_default_roadmap_print_issue($p_issue_id, $p_issue_level = 0)
{
    static $t_status;
    $t_bug = bug_get($p_issue_id);
    if (bug_is_resolved($p_issue_id)) {
        $t_strike_start = '<strike>';
        $t_strike_end = '</strike>';
    } else {
        $t_strike_start = $t_strike_end = '';
    }
    if ($t_bug->category_id) {
        $t_category_name = category_get_name($t_bug->category_id);
    } else {
        $t_category_name = '';
    }
    $t_category = is_blank($t_category_name) ? '' : '<b>[' . string_display_line($t_category_name) . ']</b> ';
    echo utf8_str_pad('', $p_issue_level * 6, '&#160;'), '- ', $t_strike_start, string_get_bug_view_link($p_issue_id), ': ', $t_category, string_display_line_links($t_bug->summary);
    if ($t_bug->handler_id != 0) {
        echo ' (', prepare_user_name($t_bug->handler_id), ')';
    }
    if (!isset($t_status[$t_bug->status])) {
        $t_status[$t_bug->status] = get_enum_element('status', $t_bug->status, auth_get_current_user_id(), $t_bug->project_id);
    }
    echo ' - ', $t_status[$t_bug->status], $t_strike_end, '.<br />';
}
Пример #2
0
 public function test()
 {
     $toPad = '<IñtërnëT>';
     // 10 characters
     $padding = 'ø__';
     // 4 characters
     $this->assertEqual(utf8_str_pad($toPad, 20), $toPad . '          ');
     $this->assertEqual(utf8_str_pad($toPad, 20, ' ', STR_PAD_LEFT), '          ' . $toPad);
     $this->assertEqual(utf8_str_pad($toPad, 20, ' ', STR_PAD_BOTH), '     ' . $toPad . '     ');
     $this->assertEqual(utf8_str_pad($toPad, 10), $toPad);
     $this->assertEqual(str_pad('5char', 4), '5char');
     // str_pos won't truncate input string
     $this->assertEqual(utf8_str_pad($toPad, 8), $toPad);
     $this->assertEqual(utf8_str_pad($toPad, 20, $padding, STR_PAD_RIGHT), $toPad . 'ø__ø__ø__ø');
     $this->assertEqual(utf8_str_pad($toPad, 20, $padding, STR_PAD_LEFT), 'ø__ø__ø__ø' . $toPad);
     $this->assertEqual(utf8_str_pad($toPad, 20, $padding, STR_PAD_BOTH), 'ø__ø_' . $toPad . 'ø__ø_');
 }
function print_version_header($p_version_row)
{
    $t_project_id = $p_version_row['project_id'];
    $t_version_id = $p_version_row['id'];
    $t_version_name = $p_version_row['version'];
    $t_project_name = project_get_field($t_project_id, 'name');
    $t_release_title = '<a href="roadmap_page.php?project_id=' . $t_project_id . '">' . string_display_line($t_project_name) . '</a> - <a href="roadmap_page.php?version_id=' . $t_version_id . '">' . string_display_line($t_version_name) . '</a>';
    if (config_get('show_roadmap_dates')) {
        $t_version_timestamp = $p_version_row['date_order'];
        $t_scheduled_release_date = ' (' . lang_get('scheduled_release') . ' ' . string_display_line(date(config_get('short_date_format'), $t_version_timestamp)) . ')';
    } else {
        $t_scheduled_release_date = '';
    }
    echo '<tt>';
    echo '<br />', $t_release_title, $t_scheduled_release_date, lang_get('word_separator'), print_bracket_link('view_all_set.php?type=1&temporary=y&' . FILTER_PROPERTY_PROJECT_ID . '=' . $t_project_id . '&' . filter_encode_field_and_value(FILTER_PROPERTY_TARGET_VERSION, $t_version_name), lang_get('view_bugs_link')), '<br />';
    $t_release_title_without_hyperlinks = $t_project_name . ' - ' . $t_version_name . $t_scheduled_release_date;
    echo utf8_str_pad('', utf8_strlen($t_release_title_without_hyperlinks), '='), '<br />';
}
/**
 * Print header for the specified project version.
 * @param int $p_version_id a valid version id
 * @return null
 */
function print_version_header($p_version_id)
{
    $t_project_id = version_get_field($p_version_id, 'project_id');
    $t_version_name = version_get_field($p_version_id, 'version');
    $t_project_name = project_get_field($t_project_id, 'name');
    $t_release_title = '<a href="changelog_page.php?project_id=' . $t_project_id . '">' . string_display_line($t_project_name) . '</a> - <a href="changelog_page.php?version_id=' . $p_version_id . '">' . string_display_line($t_version_name) . '</a>';
    if (config_get('show_changelog_dates')) {
        $t_version_released = version_get_field($p_version_id, 'released');
        $t_release_timestamp = version_get_field($p_version_id, 'date_order');
        if ((bool) $t_version_released) {
            $t_release_date = ' (' . lang_get('released') . ' ' . string_display_line(date(config_get('short_date_format'), $t_release_timestamp)) . ')';
        } else {
            $t_release_date = ' (' . lang_get('not_released') . ')';
        }
    } else {
        $t_release_date = '';
    }
    echo '<br />', $t_release_title, $t_release_date, lang_get('word_separator'), print_bracket_link('view_all_set.php?type=1&temporary=y&' . FILTER_PROPERTY_PROJECT_ID . '=' . $t_project_id . '&' . filter_encode_field_and_value(FILTER_PROPERTY_FIXED_IN_VERSION, $t_version_name), lang_get('view_bugs_link')), '<br />';
    $t_release_title_without_hyperlinks = $t_project_name . ' - ' . $t_version_name . $t_release_date;
    echo utf8_str_pad('', utf8_strlen($t_release_title_without_hyperlinks), '='), '<br />';
}
Пример #5
0
/**
 * return formatted string with all the details on the requested relationship
 * @param integer             $p_bug_id       A bug identifier.
 * @param BugRelationshipData $p_relationship A bug relationship object.
 * @param boolean             $p_html         Whether to return html or text output.
 * @param boolean             $p_html_preview Whether to include style/hyperlinks - if preview is false, we prettify the output.
 * @param boolean             $p_show_project Show Project details.
 * @return string
 */
function relationship_get_details($p_bug_id, BugRelationshipData $p_relationship, $p_html = false, $p_html_preview = false, $p_show_project = false)
{
    $t_summary_wrap_at = utf8_strlen(config_get('email_separator2')) - 28;
    $t_icon_path = config_get('icon_path');
    if ($p_bug_id == $p_relationship->src_bug_id) {
        # root bug is in the source side, related bug in the destination side
        $t_related_bug_id = $p_relationship->dest_bug_id;
        $t_related_project_name = project_get_name($p_relationship->dest_project_id);
        $t_relationship_descr = relationship_get_description_src_side($p_relationship->type);
    } else {
        # root bug is in the dest side, related bug in the source side
        $t_related_bug_id = $p_relationship->src_bug_id;
        $t_related_project_name = project_get_name($p_relationship->src_project_id);
        $t_relationship_descr = relationship_get_description_dest_side($p_relationship->type);
    }
    # related bug not existing...
    if (!bug_exists($t_related_bug_id)) {
        return '';
    }
    # user can access to the related bug at least as a viewer
    if (!access_has_bug_level(VIEWER, $t_related_bug_id)) {
        return '';
    }
    if ($p_html_preview == false) {
        $t_td = '<td>';
    } else {
        $t_td = '<td class="print">';
    }
    # get the information from the related bug and prepare the link
    $t_bug = bug_get($t_related_bug_id, false);
    $t_status_string = get_enum_element('status', $t_bug->status, auth_get_current_user_id(), $t_bug->project_id);
    $t_resolution_string = get_enum_element('resolution', $t_bug->resolution, auth_get_current_user_id(), $t_bug->project_id);
    $t_relationship_info_html = $t_td . string_no_break($t_relationship_descr) . '&#160;</td>';
    if ($p_html_preview == false) {
        $t_relationship_info_html .= '<td><a href="' . string_get_bug_view_url($t_related_bug_id) . '">' . string_display_line(bug_format_id($t_related_bug_id)) . '</a></td>';
        $t_relationship_info_html .= '<td><span class="issue-status" title="' . string_attribute($t_resolution_string) . '">' . string_display_line($t_status_string) . '</span></td>';
    } else {
        $t_relationship_info_html .= $t_td . string_display_line(bug_format_id($t_related_bug_id)) . '</td>';
        $t_relationship_info_html .= $t_td . string_display_line($t_status_string) . '&#160;</td>';
    }
    $t_relationship_info_text = utf8_str_pad($t_relationship_descr, 20);
    $t_relationship_info_text .= utf8_str_pad(bug_format_id($t_related_bug_id), 8);
    # get the handler name of the related bug
    $t_relationship_info_html .= $t_td;
    if ($t_bug->handler_id > 0) {
        $t_relationship_info_html .= string_no_break(prepare_user_name($t_bug->handler_id));
    }
    $t_relationship_info_html .= '&#160;</td>';
    # add project name
    if ($p_show_project) {
        $t_relationship_info_html .= $t_td . string_display_line($t_related_project_name) . '&#160;</td>';
    }
    # add summary
    if ($p_html == true) {
        $t_relationship_info_html .= $t_td . string_display_line_links($t_bug->summary);
        if (VS_PRIVATE == $t_bug->view_state) {
            $t_relationship_info_html .= sprintf(' <img src="%s" alt="(%s)" title="%s" />', $t_icon_path . 'protected.gif', lang_get('private'), lang_get('private'));
        }
    } else {
        if (utf8_strlen($t_bug->summary) <= $t_summary_wrap_at) {
            $t_relationship_info_text .= string_email_links($t_bug->summary);
        } else {
            $t_relationship_info_text .= utf8_substr(string_email_links($t_bug->summary), 0, $t_summary_wrap_at - 3) . '...';
        }
    }
    # add delete link if bug not read only and user has access level
    if (!bug_is_readonly($p_bug_id) && !current_user_is_anonymous() && $p_html_preview == false) {
        if (access_has_bug_level(config_get('update_bug_threshold'), $p_bug_id)) {
            $t_relationship_info_html .= ' [<a class="small" href="bug_relationship_delete.php?bug_id=' . $p_bug_id . '&amp;rel_id=' . $p_relationship->id . htmlspecialchars(form_security_param('bug_relationship_delete')) . '">' . lang_get('delete_link') . '</a>]';
        }
    }
    $t_relationship_info_html .= '&#160;</td>';
    $t_relationship_info_text .= "\n";
    if ($p_html_preview == false) {
        # choose color based on status
        $t_status_label = html_get_status_css_class($t_bug->status, auth_get_current_user_id(), $t_bug->project_id);
        $t_relationship_info_html = '<tr class="' . $t_status_label . '">' . $t_relationship_info_html . '</tr>' . "\n";
    } else {
        $t_relationship_info_html = '<tr>' . $t_relationship_info_html . '</tr>';
    }
    if ($p_html == true) {
        return $t_relationship_info_html;
    } else {
        return $t_relationship_info_text;
    }
}
Пример #6
0
function project_format_id($p_project_id)
{
    $t_padding = config_get('display_project_padding');
    return utf8_str_pad($p_project_id, $t_padding, '0', STR_PAD_LEFT);
}
Пример #7
0
/**
 * Pad the bugnote id with the appropriate number of zeros for printing
 * @param int $p_bugnote_id bugnote id
 * @return string
 * @access public
 */
function bugnote_format_id($p_bugnote_id)
{
    $t_padding = config_get('display_bugnote_padding');
    return utf8_str_pad($p_bugnote_id, $t_padding, '0', STR_PAD_LEFT);
}
Пример #8
0
/**
 * Display a simple progress bar
 *
 * @param $width Width of the progress bar
 * @param $percent Percent of the progress bar
 * @param $options array options :
 *            - title : string title to display (default Progesssion)
 *            - simple : display a simple progress bar (no title / only percent)
 *            - forcepadding : boolean force str_pad to force refresh (default true)
 *
 * @return nothing
 **/
function displayProgressBar($width, $percent, $options = array())
{
    global $CFG_GLPI, $LANG;
    $param['title'] = $LANG['common'][47];
    $param['simple'] = false;
    $param['forcepadding'] = true;
    if (is_array($options) && count($options)) {
        foreach ($options as $key => $val) {
            $param[$key] = $val;
        }
    }
    $percentwidth = floor($percent * $width / 100);
    $output = "<div class='center'><table class='tab_cadre' width='" . ($width + 20) . "px'>";
    if (!$param['simple']) {
        $output .= "<tr><th class='center'>" . $param['title'] . "&nbsp;" . $percent . "%</th></tr>";
    }
    $output .= "<tr><td>\n               <table><tr><td class='center' style='background:url(" . $CFG_GLPI["root_doc"] . "/pics/loader.png) repeat-x; padding: 0px;font-size: 10px;' width='" . $percentwidth . "px' height='12'>";
    if ($param['simple']) {
        $output .= $percent . "%";
    } else {
        $output .= '&nbsp;';
    }
    $output .= "</td></tr></table></td>";
    $output .= "</tr></table>";
    $output .= "</div>";
    if (!$param['forcepadding']) {
        echo $output;
    } else {
        echo utf8_str_pad($output, 4096);
        glpi_flush();
    }
}
Пример #9
0
/**
 * Pads the bug id with the appropriate number of zeros.
 * @param int p_bug_id
 * @return string
 * @access public
 * @uses config_api.php
 */
function bug_format_id($p_bug_id)
{
    $t_padding = config_get('display_bug_padding');
    $t_string = utf8_str_pad($p_bug_id, $t_padding, '0', STR_PAD_LEFT);
    return event_signal('EVENT_DISPLAY_BUG_ID', $t_string, array($p_bug_id));
}
Пример #10
0
/**
 * if $p_visible_bug_data contains specified attribute the function
 * returns concatenated translated attribute name and original
 * attribute value. Else return empty string.
 * @param array $p_visible_bug_data
 * @param string $p_attribute_id
 * @return string
 */
function email_format_attribute($p_visible_bug_data, $attribute_id)
{
    if (array_key_exists($attribute_id, $p_visible_bug_data)) {
        return utf8_str_pad(lang_get($attribute_id) . ': ', config_get('email_padding_length'), ' ', STR_PAD_RIGHT) . $p_visible_bug_data[$attribute_id] . "\n";
    }
    return '';
}
function GetRelationshipContent($p_bug_id, $p_html = false, $p_html_preview = false, $p_summary = false, $p_icons = false)
{
    $t_summary = '';
    $t_icons = '';
    $t_show_project = false;
    $t_summary_wrap_at = utf8_strlen(config_get('email_separator2')) - 10;
    $t_relationship_all = relationship_get_all($p_bug_id, $t_show_project);
    $t_relationship_all_count = count($t_relationship_all);
    if ($p_summary) {
        for ($i = 0; $i < $t_relationship_all_count; $i++) {
            $p_relationship = $t_relationship_all[$i];
            if ($p_bug_id == $p_relationship->src_bug_id) {
                # root bug is in the src side, related bug in the dest side
                $t_related_bug_id = $p_relationship->dest_bug_id;
                $t_relationship_descr = relationship_get_description_src_side($p_relationship->type);
            } else {
                # root bug is in the dest side, related bug in the src side
                $t_related_bug_id = $p_relationship->src_bug_id;
                $t_relationship_descr = relationship_get_description_dest_side($p_relationship->type);
            }
            # get the information from the related bug and prepare the link
            $t_bug = bug_get($t_related_bug_id, false);
            $t_text = trim(utf8_str_pad($t_relationship_descr, 20)) . ' ';
            if ($p_html_preview == true) {
                $t_text .= '<a href="' . string_get_bug_view_url($t_related_bug_id) . '"';
                $t_text .= ' class="rcv_tooltip"';
                //$t_text .= ' title="' . utf8_str_pad (bug_format_id ($t_related_bug_id), 8) . "\n" . string_attribute ($t_bug->summary) . '"';
                $t_text .= '>';
            }
            $t_text .= string_display_line(bug_format_id($t_related_bug_id));
            if ($p_html_preview == true) {
                $t_text .= '<span class="rcv_tooltip_box">';
                $t_text .= '<span class="rcv_tooltip_title">' . bug_format_id($t_related_bug_id) . '</span>';
                $t_text .= '<span class="rcv_tooltip_content">' . utf8_substr(string_email_links($t_bug->summary), 0, MAX_TOOLTIP_CONTENT_LENGTH);
                $t_text .= MAX_TOOLTIP_CONTENT_LENGTH < strlen($t_bug->summary) ? '...' : '';
                $t_text .= '</span>';
                $t_text .= '</span>';
                $t_text .= '</a>';
            }
            if (plugin_config_get('ShowRelationshipsControl') && !bug_is_readonly($p_bug_id) && !current_user_is_anonymous() && true == $p_html_preview) {
                // bug not read only
                if (access_has_bug_level(config_get('update_bug_threshold'), $p_bug_id)) {
                    // user has access level
                    // add a delete link
                    $t_text .= ' [';
                    $t_text .= '<a class="small" href="bug_relationship_delete.php?bug_id=' . $p_bug_id;
                    $t_text .= '&amp;rel_id=' . $p_relationship->id;
                    $t_text .= '&amp;redirect_url=view_all_bug_page.php';
                    $t_text .= htmlspecialchars(form_security_param('bug_relationship_delete'));
                    $t_text .= '">' . lang_get('delete_link') . '</a>';
                    $t_text .= ']';
                }
            }
            // $t_text = relationship_get_details ($p_bug_id, $t_relationship_all[$i], true, false, $t_show_project);
            if (false == $p_html) {
                // p_html == No
                if ($i != 0) {
                    if ($p_html_preview == true) {
                        $t_summary .= ",<br/>";
                    } else {
                        $t_summary .= ", ";
                    }
                }
                $t_summary .= $t_text;
            } else {
                // p_html == Yes
                if ($p_html_preview == true) {
                    $t_summary .= '<tr bgcolor="' . get_status_color($t_bug->status, auth_get_current_user_id(), $t_bug->project_id) . '">';
                    $t_summary .= '<td>' . $t_text . '</td>';
                    $t_summary .= '</tr>' . "\n";
                } else {
                    if ($i != 0) {
                        $t_summary .= ", ";
                    }
                    $t_summary .= $t_text;
                }
            }
        }
    }
    if (plugin_config_get('ShowRelationshipIcons') && !current_user_is_anonymous() && true == $p_html_preview) {
        $t_text = RelationshipsUtils::GetBugSmybols($p_bug_id, !is_blank($t_summary));
        if (!is_blank($t_text)) {
            if (false == $p_html) {
                // p_html == No
                $t_icons .= $t_text;
            } else {
                // p_html == Yes
                if ($p_html_preview == true) {
                    $t_icons .= '<tr><td>' . $t_text . '</td></tr>' . "\n";
                } else {
                    $t_icons .= $t_text;
                }
            }
        }
    }
    if ($p_html_preview == true) {
        $t_icons_table = '';
        $t_summary_table = '';
        if (!is_blank($t_icons)) {
            $t_icons_table = '<table border="0" width="100%" cellpadding="0" cellspacing="1">' . $t_icons . '</table>';
        }
        if (!is_blank($t_summary)) {
            $t_summary_table = '<table border="0" width="100%" cellpadding="0" cellspacing="1">' . $t_summary . '</table>';
        }
        if (!is_blank($t_icons_table) && !is_blank($t_summary_table)) {
            return '<table border="0" width="100%" cellpadding="0" cellspacing="0">' . '<tr><td valign="top" style="padding:0px;">' . $t_summary_table . '</td><td valign="top" style="padding:0px;">' . $t_icons_table . '</td></tr>' . '</table>';
        } else {
            return $t_summary_table . $t_icons_table;
        }
    } else {
        $t_result = $t_icons;
        if (!is_blank($t_icons) && !is_blank($t_summary)) {
            $t_result .= '<br/>';
        }
        $t_result .= $t_summary;
        return $t_result;
    }
}
Пример #12
0
/**
 *  Format mail row
 *
 * @param $string string: label string
 * @param $value string: value string
 *
 * @return string
**/
function mailRow($string, $value)
{
    $row = utf8_str_pad($string . ': ', 25, ' ', STR_PAD_RIGHT) . $value . "\n";
    return $row;
}
Пример #13
0
 /**
  * UTF-8 aware alternative to str_pad()
  *
  * Pad a string to a certain length with another string.
  * $padStr may contain multi-byte characters.
  *
  * @param   string   $input   The input string.
  * @param   integer  $length  If the value is negative, less than, or equal to the length of the input string, no padding takes place.
  * @param   string   $padStr  The string may be truncated if the number of padding characters can't be evenly divided by the string's length.
  * @param   integer  $type    The type of padding to apply
  *
  * @return  string
  *
  * @see     http://www.php.net/str_pad
  * @since   1.4.0
  */
 public static function str_pad($input, $length, $padStr = ' ', $type = STR_PAD_RIGHT)
 {
     return utf8_str_pad($input, $length, $padStr, $type);
 }
Пример #14
0
/**
 * Create a new name using a autoname field defined in a template
 *
 * @param $objectName autoname template
 * @param $field field to autoname
 * @param $isTemplate true if create an object from a template
 * @param $itemtype item type
 * @param $entities_id limit generation to an entity
 *
 * @return new auto string
**/
function autoName($objectName, $field, $isTemplate, $itemtype, $entities_id = -1)
{
    global $DB, $CFG_GLPI;
    $len = utf8_strlen($objectName);
    if ($isTemplate && $len > 8 && utf8_substr($objectName, 0, 4) === '&lt;' && utf8_substr($objectName, $len - 4, 4) === '&gt;') {
        $autoNum = utf8_substr($objectName, 4, $len - 8);
        $mask = '';
        if (preg_match("/\\#{1,10}/", $autoNum, $mask)) {
            $global = strpos($autoNum, '\\g') !== false && $itemtype != 'Infocom' ? 1 : 0;
            $autoNum = str_replace(array('\\y', '\\Y', '\\m', '\\d', '_', '%', '\\g'), array(date('y'), date('Y'), date('m'), date('d'), '\\_', '\\%', ''), $autoNum);
            $mask = $mask[0];
            $pos = strpos($autoNum, $mask) + 1;
            $len = utf8_strlen($mask);
            $like = str_replace('#', '_', $autoNum);
            if ($global == 1) {
                $query = "";
                $first = 1;
                $types = array('Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer');
                foreach ($types as $t) {
                    $table = getTableForItemType($t);
                    $query .= ($first ? "SELECT " : " UNION SELECT  ") . " {$field} AS code\n                         FROM `{$table}`\n                         WHERE `{$field}` LIKE '{$like}'\n                               AND `is_deleted` = '0'\n                               AND `is_template` = '0'";
                    if ($CFG_GLPI["use_autoname_by_entity"] && $entities_id >= 0) {
                        $query .= " AND `entities_id` = '{$entities_id}' ";
                    }
                    $first = 0;
                }
                $query = "SELECT CAST(SUBSTRING(code, {$pos}, {$len}) AS unsigned) AS no\n                      FROM ({$query}) AS codes";
            } else {
                $table = getTableForItemType($itemtype);
                $query = "SELECT CAST(SUBSTRING({$field}, {$pos}, {$len}) AS unsigned) AS no\n                      FROM `{$table}`\n                      WHERE `{$field}` LIKE '{$like}' ";
                if ($itemtype != INFOCOM_TYPE) {
                    $query .= " AND `is_deleted` = '0'\n                           AND `is_template` = '0'";
                    if ($CFG_GLPI["use_autoname_by_entity"] && $entities_id >= 0) {
                        $query .= " AND `entities_id` = '{$entities_id}' ";
                    }
                }
            }
            $query = "SELECT MAX(Num.no) AS lastNo\n                   FROM (" . $query . ") AS Num";
            $resultNo = $DB->query($query);
            if ($DB->numrows($resultNo) > 0) {
                $data = $DB->fetch_array($resultNo);
                $newNo = $data['lastNo'] + 1;
            } else {
                $newNo = 0;
            }
            $objectName = str_replace(array($mask, '\\_', '\\%'), array(utf8_str_pad($newNo, $len, '0', STR_PAD_LEFT), '_', '%'), $autoNum);
        }
    }
    return $objectName;
}
Пример #15
0
function gantt_chart($p_metrics, $p_title, $p_subtitle, $p_graph_width = 300, $p_graph_height = 380)
{
    $t_graph_font = graph_get_font();
    $t_metrics = $p_metrics['metrics'];
    $t_range = $p_metrics['range'];
    // Diff in weeks of the range:
    $t_60s = 60;
    // 1 minute
    $t_60min = 60;
    // 1 hour
    $t_24h = 24;
    // 1 day
    $t_7d = 7;
    // 1 week
    $t_minute = $t_60s;
    $t_hour = $t_60min * $t_minute;
    $t_day = $t_24h * $t_hour;
    $t_week = $t_7d * $t_day;
    $t_gantt_chart_max_rows = plugin_config_get('rows_max');
    error_check(is_array($t_metrics) ? count($t_metrics) : 0, $p_title . " (" . $p_subtitle . ")");
    if (plugin_config_get('eczlibrary') == ON) {
        // DO NOTHING SINCE eczlibrary DOES NOT SUPPORT GANTT CHART
    } else {
        // A new graph with automatic size
        $graph = new GanttGraph(0, 0, "auto");
        $graph->SetShadow();
        // Add title and subtitle
        $graph->title->Set($p_title);
        $graph->title->SetFont($t_graph_font, FS_BOLD, 12);
        $graph->subtitle->Set($p_subtitle);
        // Show day, week and month scale
        $graph->ShowHeaders(GANTT_HDAY | GANTT_HWEEK | GANTT_HMONTH);
        // Instead of week number show the date for the first day in the week
        // on the week scale
        $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
        // Make the week scale font smaller than the default
        $graph->scale->week->SetFont($t_graph_font, FS_NORMAL, 8);
        // Use the short name of the month together with a 2 digit year
        // on the month scale
        $graph->scale->month->SetStyle(MONTHSTYLE_SHORTNAMEYEAR4);
        $graph->scale->month->SetFontColor("white");
        $graph->scale->month->SetBackgroundColor("blue");
        // Setup a horizontal grid
        $graph->hgrid->Show();
        $graph->hgrid->SetRowFillColor('darkblue@0.9');
        // Setup a vertical grid
        //   $graph->vgrid->Show();
        //Setup the divider display
        $graph->scale->divider->SetWeight(3);
        $graph->scale->divider->SetColor("darkblue");
        $graph->scale->dividerh->SetWeight(3);
        $graph->scale->dividerh->SetColor("darkblue");
        $graph->scale->dividerh->Show();
        $graph->scale->actinfo->vgrid->SetStyle('solid');
        $graph->scale->actinfo->vgrid->SetColor('darkblue');
        $graph->scale->actinfo->vgrid->Show();
        //   // Set the column headers and font
        //   $graph->scale->actinfo->SetColTitles( array('Task','Start','End'),array(100));
        //   $graph->scale->actinfo->SetFont( $t_graph_font, FS_BOLD, 10 );
        //Adding columns:
        //The following is an example: 1st element, an array of the columns,
        //  2nd element an optional array of min width of the columns (here the min width of the 2 first columns)
        //$graph->scale->actinfo->SetColTitles(
        //  array('Note','Task','Duration','Start','Finish'),array(30,100));
        //Adding a table title
        $graph->scale->tableTitle->Set("{$p_subtitle}");
        $graph->scale->tableTitle->SetFont($t_graph_font, FS_NORMAL, 8);
        $graph->scale->SetTableTitleBackground('darkblue@0.6');
        $graph->scale->tableTitle->Show();
        //           if ( null != $t_constrain ){
        //           $t_activity->SetConstrain( $t_constrain, CONSTRAIN_ENDSTART );
        //         }
        //     if ( null != $t_constrain ){
        //       $t_activity->SetConstrain( $t_constrain['row'], $t_constrain['type'] );
        //     }
        // We first need to get the list of rows, in order to know whether to
        // display the constraint or not (in case of missing referenced row)
        $t_row_list = array();
        foreach ($t_metrics as $t_metric_row) {
            $t_row_list[] = $t_metric_row[0];
        }
        foreach ($t_metrics as $t_metric_row) {
            $t_row = $t_metric_row[0] % $t_gantt_chart_max_rows;
            $t_activity_type = $t_metric_row[1];
            $t_bug_id = $t_metric_row[2];
            $t_start_date = $t_metric_row[3];
            $t_end_date = $t_metric_row[4];
            $t_extra = " {$t_bug_id}" . $t_metric_row[5];
            $t_level = $t_metric_row[6];
            $t_constraints = $t_metric_row[7];
            if (isset($t_level)) {
                $t_row_label = utf8_str_pad('', $t_level * 2, ' ') . htmlspecialchars_decode(bug_format_summary($t_bug_id, SUMMARY_FIELD));
            } else {
                $t_row_label = htmlspecialchars_decode(bug_format_summary($t_bug_id, SUMMARY_FIELD));
            }
            // Limit the label to max defined
            $t_row_label = strlen($t_row_label) > plugin_config_get('label_max') ? substr($t_row_label, 0, plugin_config_get('label_max') - 3) . '...' : $t_row_label;
            $t_activity_arr = array('left' => null, 'main' => array('row' => $t_row, 'label' => $t_row_label, 'start' => $t_start_date, 'end' => $t_end_date, 'info' => $t_extra), 'right' => null);
            if ($t_end_date < $t_range['min']) {
                // complete left bar
                //   **  | o[ ]-[ ]o
                $t_activity_arr = array('left' => array('row' => $t_row, 'label' => $t_row_label, 'start' => $t_range['min'], 'end' => $t_range['min'], 'info' => "<- " . graph_date_format($t_start_date)), 'main' => null, 'right' => array('row' => $t_row, 'label' => "", 'start' => $t_range['min'] + $t_day, 'end' => $t_range['min'] + $t_day, 'info' => "<<- [" . graph_date_format($t_start_date) . " / " . graph_date_format($t_end_date) . "]" . $t_extra));
            } else {
                if ($t_range['max'] < $t_start_date) {
                    // complete right bar
                    //   o[ ]-[ ]o | **
                    $t_activity_arr = array('left' => array('row' => $t_row, 'label' => $t_row_label, 'start' => $t_range['max'] - $t_day, 'end' => $t_range['max'] - $t_day, 'info' => ""), 'main' => null, 'right' => array('row' => $t_row, 'label' => "", 'start' => $t_range['max'], 'end' => $t_range['max'], 'info' => "[" . graph_date_format($t_start_date) . " / " . graph_date_format($t_end_date) . "] ->>" . $t_extra));
                } else {
                    if ($t_start_date < $t_range['min']) {
                        // left bar
                        //   *  | o[ ]-[    ]
                        $t_activity_arr['left'] = array('row' => $t_row, 'label' => '', 'start' => $t_range['min'], 'end' => $t_range['min'], 'info' => "<- " . graph_date_format($t_start_date));
                        $t_activity_arr['main']['start'] = $t_range['min'] + $t_day;
                        //4 * $t_day;// @TODO: what happens if duration is less than that
                    }
                    if ($t_range['max'] < $t_end_date) {
                        // right bar
                        //  [     ]-[ ]o | *
                        $t_activity_arr['main']['end'] = $t_range['max'] - $t_day;
                        //4 * $t_day;
                        $t_activity_arr['main']['info'] = "";
                        $t_activity_arr['right'] = array('row' => $t_row, 'label' => "", 'start' => $t_range['max'], 'end' => $t_range['max'], 'info' => graph_date_format($t_end_date) . " ->" . $t_extra);
                    }
                }
            }
            switch ($t_activity_type) {
                case ACTYPE_NORMAL:
                    if (null != $t_activity_arr['left']) {
                        $t_activity_left = new GanttBar($t_activity_arr['left']['row'], $t_activity_arr['left']['label'], graph_date_format($t_activity_arr['left']['start']), graph_date_format($t_activity_arr['left']['end']), $t_activity_arr['left']['info']);
                        // Add a left marker
                        $t_activity_left->leftMark->Show();
                        $t_activity_left->leftMark->SetType(MARK_FILLEDCIRCLE);
                        $t_activity_left->leftMark->SetWidth(8);
                        //                        $t_activity_left->leftMark->SetColor( 'red' );
                        $t_activity_left->leftMark->SetFillColor('red');
                        $t_activity_left->leftMark->title->Set('');
                        $t_activity_left->leftMark->title->SetFont($t_graph_font, FS_NORMAL, 8);
                        $t_activity_left->leftMark->title->SetColor('white');
                        if (null != gantt_get_resolution_date($t_bug_id)) {
                            $t_activity_left->SetPattern(BAND_RDIAG, get_status_color(bug_get_field($t_bug_id, 'status')));
                        }
                        $t_activity_left->SetFillColor(get_status_color(bug_get_field($t_bug_id, 'status')));
                    }
                    if (null != $t_activity_arr['main']) {
                        $t_activity_main = new GanttBar($t_activity_arr['main']['row'], $t_activity_arr['main']['label'], graph_date_format($t_activity_arr['main']['start']), graph_date_format($t_activity_arr['main']['end']), $t_activity_arr['main']['info']);
                        if (null != gantt_get_resolution_date($t_bug_id)) {
                            $t_activity_main->SetPattern(BAND_RDIAG, get_status_color(bug_get_field($t_bug_id, 'status')));
                        }
                        $t_activity_main->SetFillColor(get_status_color(bug_get_field($t_bug_id, 'status')));
                        $t_activity_main->title->SetFont($t_graph_font, FS_NORMAL, 8);
                        // Set the constraint if any...
                        foreach ($t_constraints as $t_constraint) {
                            // ... and if possible
                            if (in_array($t_constraint['row'], $t_row_list)) {
                                $t_activity_main->SetConstrain($t_constraint['row'], $t_constraint['type']);
                            }
                        }
                        $graph->add($t_activity_main);
                    }
                    if (null != $t_activity_arr['right']) {
                        $t_activity_right = new GanttBar($t_activity_arr['right']['row'], $t_activity_arr['right']['label'], graph_date_format($t_activity_arr['right']['start']), graph_date_format($t_activity_arr['right']['end']), $t_activity_arr['right']['info']);
                        // Add a left marker
                        $t_activity_right->rightMark->Show();
                        $t_activity_right->rightMark->SetType(MARK_FILLEDCIRCLE);
                        $t_activity_right->rightMark->SetWidth(8);
                        $t_activity_right->rightMark->SetColor('red');
                        $t_activity_right->rightMark->SetFillColor('red');
                        $t_activity_right->rightMark->title->Set('');
                        $t_activity_right->rightMark->title->SetFont($t_graph_font, FS_NORMAL, 8);
                        $t_activity_right->rightMark->title->SetColor('white');
                        if (null != gantt_get_resolution_date($t_bug_id)) {
                            $t_activity_right->SetPattern(BAND_RDIAG, get_status_color(bug_get_field($t_bug_id, 'status')));
                        }
                        $t_activity_right->SetFillColor(get_status_color(bug_get_field($t_bug_id, 'status')));
                    }
                    if (isset($t_activity_left)) {
                        $graph->add($t_activity_left);
                    }
                    if (isset($t_activity_right)) {
                        $graph->add($t_activity_right);
                    }
                    break;
                case ACTYPE_MILESTONE:
                    $t_size = 5;
                    if ($t_start_date < $t_range['min']) {
                        $t_extra = "(<-- " . graph_date_format($t_start_date) . ")" . $t_extra;
                        $t_start_date = $t_range['min'];
                        $t_size = 8;
                    } else {
                        if ($t_range['max'] < $t_start_date) {
                            $t_extra = "(--> " . graph_date_format($t_start_date) . ")" . $t_extra;
                            $t_start_date = $t_range['max'];
                            $t_size = 8;
                        }
                    }
                    $t_milestone = new MileStone($t_row, $t_row_label, graph_date_format($t_start_date), $t_extra);
                    $t_milestone->title->SetFont($t_graph_font, FS_NORMAL, 8);
                    $t_milestone->mark->SetType(MARK_FILLEDCIRCLE);
                    $t_milestone->mark->SetWidth($t_size);
                    if (5 != $t_size) {
                        $t_milestone->mark->SetFillColor('red');
                    }
                    //         foreach( $t_constraints as $t_constraint){
                    //           $t_milestone->SetConstrain( $t_constraint['row'], $t_constraint['type'] );
                    //         }
                    $graph->add($t_milestone);
                    break;
            }
        }
        // Setting the min and max date:
        $t_minmax = $graph->GetBarMinMax();
        $t_week_in_seconds = 7 * 24 * 3600;
        // 1 week offset min:
        if ($t_minmax[0] - $t_week_in_seconds > 0) {
            $t_graph_offset_min = $t_minmax[0] - $t_week_in_seconds;
        } else {
            $t_graph_offset_min = $t_minmax[0];
        }
        // 2 weeks offset max:
        $t_graph_offset_max = $t_minmax[1] + 3 * $t_week_in_seconds;
        $graph->SetDateRange(graph_date_format($t_graph_offset_min), graph_date_format($t_graph_offset_max));
        // Add a vertical line for today if in the range of GetBarMinMax() (retruns an arry ($min, $max) ):
        $t_minmax = $graph->GetBarMinMax();
        $t_now = date(config_get('short_date_format'));
        if ($t_now >= graph_date_format($t_graph_offset_min) && $t_now <= graph_date_format($t_graph_offset_max)) {
            $t_today = new GanttVLine($t_now, "Today", "darkred", 2, "solid");
            $t_today->SetDayOffset(0.5);
            $graph->add($t_today);
        }
        //       $t_today = new GanttVLine( "2011-03-01" , "" , "darkred", 2, "solid");//
        //       $t_today->SetDayOffset(0.5);
        //       $graph->add( $t_today );
        $t_gantt_chart_height = gantt_chart_get_height($graph);
        $t_legend = gantt_chart_legend(false);
        $t_legend_height = 60;
        // Display the Gantt chart
        //     $graph->Stroke();
        //--------------------------------------
        // Create a combined graph
        //--------------------------------------
        $mgraph = new MGraph();
        $mgraph->Add($graph, 0, 0);
        $mgraph->Add($t_legend, 0, $t_gantt_chart_height + $t_legend_height);
        $mgraph->Stroke();
    }
}
 /**
  * checks relationships for a bug and assign relevant symbols
  *
  * @author Rainer Dierck
  * @param $bugId
  */
 public static function GetBugSmybols($bugId, $p_newline = false)
 {
     $t_text = '';
     $bugStatus = bug_get_field($bugId, 'status');
     $allRelationships = relationship_get_all($bugId, $t_show_project);
     $allRelationshipsCount = count($allRelationships);
     $stopFlag = false;
     $forbiddenFlag = false;
     $warningFlag = false;
     $bugEta = bug_get_field($bugId, 'eta');
     $useEta = $bugEta != ETA_NONE && config_get('enable_eta');
     $stopAltText = "";
     $forbiddenAltText = "";
     $warningAltText = "";
     $href = string_get_bug_view_url($bugId) . '#relationships_open';
     for ($index = 0; $index < $allRelationshipsCount; $index++) {
         $relationShip = $allRelationships[$index];
         if ($bugId == $relationShip->src_bug_id) {
             # root bug is in the src side, related bug in the dest side
             $destinationBugId = $relationShip->dest_bug_id;
             $relationshipDescription = relationship_get_description_src_side($relationShip->type);
         } else {
             # root bug is in the dest side, related bug in the src side
             $destinationBugId = $relationShip->src_bug_id;
             $relationshipDescription = relationship_get_description_dest_side($relationShip->type);
         }
         # get the information from the related bug and prepare the link
         $destinationBugStatus = bug_get_field($destinationBugId, 'status');
         if ($bugStatus < CLOSED && $destinationBugStatus < CLOSED && $relationShip->type != BUG_REL_NONE) {
             if ($relationShip->type == BUG_DEPENDANT) {
                 if ($bugId == $relationShip->src_bug_id) {
                     // Stop or Forbidden
                     if ($bugStatus == $destinationBugStatus) {
                         // Stop
                         if ($stopAltText != "") {
                             $stopAltText .= ", ";
                         }
                         if (!$stopFlag) {
                             $stopAltText .= trim(utf8_str_pad($relationshipDescription, 20)) . ' ';
                         }
                         $stopAltText .= string_display_line(bug_format_id($destinationBugId));
                         $stopFlag = true;
                     }
                     if ($bugStatus > $destinationBugStatus) {
                         // Forbidden
                         if ($forbiddenAltText != "") {
                             $forbiddenAltText .= ", ";
                         }
                         if (!$forbiddenFlag) {
                             $forbiddenAltText .= trim(utf8_str_pad($relationshipDescription, 20)) . ' ';
                         }
                         $forbiddenAltText .= string_display_line(bug_format_id($destinationBugId));
                         $forbiddenFlag = true;
                     }
                 } else {
                     // Warning
                     if ($bugStatus < $destinationBugStatus) {
                         // Warning
                         if ($warningAltText != "") {
                             $warningAltText .= ", ";
                         }
                         if (!$warningFlag) {
                             $warningAltText .= trim(utf8_str_pad($relationshipDescription, 20)) . ' ';
                         }
                         $warningAltText .= string_display_line(bug_format_id($destinationBugId));
                         $warningFlag = true;
                     }
                 }
             }
         }
     }
     //if ( $useEta )
     //{  // RELATIONSHIPS_UTILS_PLUGIN_URL
     //   $t_text .= '<img border="0" width="16" height="16" src="' . RELATIONSHIPS_UTILS_PLUGIN_URL . 'clock.png' . '" alt="clock" />';
     //}
     if ($forbiddenFlag) {
         if ($p_newline && !is_blank($t_text)) {
             $t_text .= '<br/>' . "\n";
         }
         $t_text .= '<a href="' . $href . '"><img border="0" width="16" height="16" src="' . RELATIONSHIPS_UTILS_PLUGIN_URL . 'sign_forbidden.png" alt="' . $forbiddenAltText . '" title="' . $forbiddenAltText . '" /></a>';
     }
     if ($stopFlag) {
         if ($p_newline && !is_blank($t_text)) {
             $t_text .= '<br/>' . "\n";
         }
         $t_text .= '<a href="' . $href . '"><img border="0" width="16" height="16" src="' . RELATIONSHIPS_UTILS_PLUGIN_URL . 'sign_stop.png" alt="' . $stopAltText . '" title="' . $stopAltText . '" /></a>';
     }
     if ($warningFlag) {
         if ($p_newline && !is_blank($t_text)) {
             $t_text .= '<br/>' . "\n";
         }
         $t_text .= '<a href="' . $href . '"><img border="0" width="16" height="16" src="' . RELATIONSHIPS_UTILS_PLUGIN_URL . 'sign_warning.png" alt="' . $warningAltText . '" title="' . $warningAltText . '" /></a>';
     }
     return $t_text;
 }