Example #1
0
/**
 * Create an array of arrays which hold the size of the pie chart elements
 * for every projects.
 * The first element in the inner arrays represents the unused budget costs,
 * the second element in the inner arrays represents the expense costs,
 * the third and all other elements in the inner arrays represents the
 * costs for individual events.
 * 
 * An visual example for two projects with the ID 2 and 5:
 * $array = {
 *   2 => array (budget left , expenses cost, task1, task2 ),
 *   5 => array (budget left , expenses cost, task1, task2 ),
 * };
 * 
 * @param array $projects IDs of all projects to include in the plot data
 * @param array $usedEvents array of all used events (each as an array of its data)
 * @return array containing arrays for every project which hold the size of the pie chart elements
 * 
 */
function budget_plot_data($projects, &$usedEvents, &$expensesOccured)
{
    $wages = array();
    $eventUsage = array();
    // track what events are used
    $usedEvents = array();
    $expensesOccured = false;
    $events = get_arr_evt("all");
    /*
     * sum up expenses
     */
    foreach ($projects as $project) {
        $pctId = $project['pct_ID'];
        $wages[$pctId]['budget'] = $project['pct_budget'];
        $wages[$pctId]['expenses'] = calculate_expenses_sum($project['pct_ID']);
        if ($wages[$pctId]['expenses'] != 0) {
            $expensesOccured = true;
        }
        if ($wages[$pctId]['budget'] < 0) {
            //Costs over budget, set remaining budget to 0.
            $wages[$pctId]['budget'] = 0;
        }
        // initialize entries for every event using its ID
        foreach ($events as $event) {
            $wages[$pctId][$event['evt_ID']] = 0;
        }
    }
    /*
     * sum up wages for every project and every event
     */
    foreach ($projects as $project) {
        $projectId = $project['pct_ID'];
        $zef_arr = get_arr_zef(0, time(), null, null, array($projectId));
        foreach ($zef_arr as $zef) {
            $pctId = $zef['zef_pctID'];
            if ($zef['wage_decimal'] == 0.0) {
                continue;
            }
            if (key_exists($zef['zef_evtID'], $wages[$pctId])) {
                $eventUsage[$zef['zef_evtID']] = true;
                $wages[$pctId][$zef['zef_evtID']] += $zef['wage_decimal'];
                $wages[$pctId]['budget'] -= $zef['wage_decimal'];
            }
            if ($wages[$pctId]['budget'] < 0) {
                //Costs over budget, set remaining budget to 0.
                $wages[$pctId]['budget'] = 0;
            }
        }
    }
    /*
     * Delete unused events.
     */
    foreach ($events as $event) {
        if (isset($eventUsage[$event['evt_ID']])) {
            $usedEvents[] = $event;
            continue;
        }
        foreach ($wages as $projectData) {
            unset($projectData[$event['evt_ID']]);
        }
    }
    /* 
     * Convert array of wages to javascript array for every project.
     */
    $plot_data = array();
    foreach ($wages as $project_id => $wage_array) {
        $plot_data[$project_id] = '[' . implode(',', $wage_array) . ']';
    }
    return $plot_data;
}
Example #2
0
      * used for them. If a project is set as filter via the pct parameter
      * only tasks for that project are shown.
      */
 /**
  * Return a list of tasks. Customers are only shown tasks which are
  * used for them. If a project is set as filter via the pct parameter
  * only tasks for that project are shown.
  */
 case 'reload_evt':
     if (isset($kga['customer'])) {
         $arr_evt = get_arr_evt_by_knd($kga['customer']['knd_ID']);
     } else {
         if (isset($_REQUEST['pct'])) {
             $arr_evt = get_arr_evt_by_pct($kga['usr']['usr_grp'], $_REQUEST['pct']);
         } else {
             $arr_evt = get_arr_evt($kga['usr']['usr_grp']);
         }
     }
     if (count($arr_evt) > 0) {
         $tpl->assign('arr_evt', $arr_evt);
     } else {
         $tpl->assign('arr_evt', 0);
     }
     $tpl->display("../lists/evt.tpl");
     break;
     /**
      * Add a new customer, project or event. This is a core function as it's
      * used at least by the admin panel and the timesheet extension.
      */
 /**
  * Add a new customer, project or event. This is a core function as it's
Example #3
0
         $tpl->assign('arr_pct', '0');
     }
     $tpl->display("pct.tpl");
     break;
 case "evt":
     if ($kga['usr']['usr_sts'] == 0) {
         $group = "all";
     } else {
         $group = $kga['usr']['usr_grp'];
     }
     if (!isset($_REQUEST['evt_filter'])) {
         $arr_evt = get_arr_evt($group);
     } else {
         switch ($_REQUEST['evt_filter']) {
             case -1:
                 $arr_evt = get_arr_evt($group);
                 break;
             case -2:
                 // -2 is to get unassigned events. As -2 is never
                 // an id of a project this will give us all unassigned
                 // events.
             // -2 is to get unassigned events. As -2 is never
             // an id of a project this will give us all unassigned
             // events.
             default:
                 $arr_evt = get_arr_evt_by_pct($group, $_REQUEST['evt_filter']);
         }
     }
     foreach ($arr_evt as $row => $evt_data) {
         $grp_names = array();
         foreach (evt_get_grps($evt_data['evt_ID']) as $grp_id) {
Example #4
0
function get_arr_evt_with_time($group, $user, $in, $out)
{
    global $kga, $conn;
    $arr_evts = get_arr_evt($group);
    $arr_time = get_arr_time_evt($user, $in, $out);
    $arr = array();
    $i = 0;
    foreach ($arr_evts as $evt) {
        $arr[$i]['evt_ID'] = $evt['evt_ID'];
        $arr[$i]['evt_name'] = $evt['evt_name'];
        $arr[$i]['evt_visible'] = $evt['evt_visible'];
        if (isset($arr_time[$evt['evt_ID']])) {
            $arr[$i]['zeit'] = formatDuration($arr_time[$evt['evt_ID']]);
        } else {
            $arr[$i]['zeit'] = formatDuration(0);
        }
        $i++;
    }
    return $arr;
}
Example #5
0
/**
 * Returns array for smarty's html_options funtion.
 *
 * <pre>
 * returns:
 * [0] -> pct/evt names
 * [1] -> values as IDs
 * </pre>
 *
 * @param string either 'pct', 'evt', 'knd', 'grp'
 * @return array
 * @author th, sl, kp
 */
function makeSelectBox($subject, $user, $selection = null)
{
    global $kga;
    $sel = array();
    $sel[0] = array();
    $sel[1] = array();
    switch ($subject) {
        case 'pct':
            $arr_pct = get_arr_pct($user);
            $i = 0;
            foreach ($arr_pct as $pct) {
                if ($pct['pct_visible']) {
                    if ($kga['conf']['flip_pct_display']) {
                        $sel[0][$i] = $pct['knd_name'] . ": " . $pct['pct_name'];
                        if ($kga['conf']['pct_comment_flag']) {
                            $sel[0][$i] .= "(" . $pct['pct_comment'] . ")";
                        }
                    } else {
                        $sel[0][$i] = $pct['pct_name'] . " (" . $pct['knd_name'] . ")";
                        if ($kga['conf']['pct_comment_flag']) {
                            $sel[0][$i] .= "(" . $pct['pct_comment'] . ")";
                        }
                    }
                    $sel[1][$i] = $pct['pct_ID'];
                    $i++;
                }
            }
            break;
        case 'evt':
            $arr_evt = get_arr_evt($user);
            $i = 0;
            foreach ($arr_evt as $evt) {
                if ($evt['evt_visible']) {
                    $sel[0][$i] = $evt['evt_name'];
                    $sel[1][$i] = $evt['evt_ID'];
                    $i++;
                }
            }
            break;
        case 'knd':
            $arr_knd = get_arr_knd($user);
            $i = 0;
            $selectionFound = false;
            foreach ($arr_knd as $knd) {
                if ($knd['knd_visible']) {
                    $sel[0][$i] = $knd['knd_name'];
                    $sel[1][$i] = $knd['knd_ID'];
                    $i++;
                    if ($selection == $knd['knd_ID']) {
                        $selectionFound = true;
                    }
                }
            }
            if ($selection != null && !$selectionFound) {
                $data = knd_get_data($selection);
                $sel[0][$i] = $data['knd_name'];
                $sel[1][$i] = $data['knd_ID'];
            }
            break;
        case 'grp':
            $arr_grp = get_arr_grp();
            $i = 0;
            foreach ($arr_grp as $grp) {
                if (!$grp['grp_trash']) {
                    $sel[0][$i] = $grp['grp_name'];
                    $sel[1][$i] = $grp['grp_ID'];
                    $i++;
                }
            }
            break;
        default:
            // TODO leave default options empty ???
            break;
    }
    return $sel;
}