Ejemplo n.º 1
0
function insert_program($program, &$out, $indexNumber)
{
    $ret = true;
    $data_plug = get_data_plug($program[0]['selected_plug'], $out, $indexNumber);
    $tmp = array();
    if (count($program > 0)) {
        clean_program($program[0]['selected_plug'], $program[0]['number'], $out);
    }
    if (count($data_plug) == 0) {
        foreach ($program as $progr) {
            $prg[] = array("time_start" => str_replace(':', '', $progr['start_time']), "time_stop" => str_replace(':', '', $progr['end_time']), "value" => $progr['value_program'], "type" => $progr['type'], "number" => $progr['number']);
        }
        $tmp = purge_program($prg);
    } else {
        foreach ($program as $progr) {
            $type = $progr['type'];
            $number = $progr['number'];
            if (count($tmp) > 0) {
                $data_plug = $tmp;
                unset($tmp);
                $tmp = array();
            }
            $data_plug[] = array("time_start" => "240000", "time_stop" => "240000", "value" => "0", "type" => "{$type}", "number" => $number);
            $start_time = str_replace(':', '', $progr['start_time']);
            $end_time = str_replace(':', '', $progr['end_time']);
            $value = $progr['value_program'];
            $current = array("time_start" => "{$start_time}", "time_stop" => "{$end_time}", "value" => "{$value}", "type" => "{$type}", "number" => $number);
            $first = array("time_start" => "000000", "time_stop" => "000000", "value" => "0", "type" => "{$type}", "number" => $number);
            asort($data_plug);
            $continue = "1";
            $chk_stop = false;
            $chk_test = true;
            while (!$chk_stop) {
                foreach ($data_plug as $data) {
                    if (!$chk_test) {
                        $tmp[] = $data;
                    } else {
                        $chk_stop = true;
                        if (!isset($last) || empty($last)) {
                            $last = $data;
                        }
                        if ("{$continue}" == "1") {
                            $continue = compare_data_program($first, $last, $current, $tmp);
                        } else {
                            $continue = "1";
                        }
                        if ("{$continue}" != "2") {
                            $first = $last;
                            unset($last);
                        } else {
                            unset($last);
                            unset($first);
                            $chk_test = false;
                        }
                    }
                }
                if (!$chk_test) {
                    $chk_stop = false;
                    $first = array("time_start" => "000000", "time_stop" => "000000", "value" => "0", "type" => "{$type}", "number" => $number);
                    $continue = "1";
                    unset($data_plug);
                    $data_plug = $tmp;
                    asort($data_plug);
                    unset($tmp);
                    $tmp = array();
                    $chk_test = true;
                }
            }
            if ($GLOBALS['DEBUG_TRACE']) {
                echo "Before purge:<br />";
                print_r($tmp);
                echo "<br />";
            }
            $tmp = purge_program($tmp);
            if ($GLOBALS['DEBUG_TRACE']) {
                echo "<br />Before optimize:<br />";
                print_r($tmp);
                echo "<br />";
            }
            $tmp = optimize_program($tmp);
            if ($GLOBALS['DEBUG_TRACE']) {
                echo "<br />Program to be recorded:<br />";
                print_r($tmp);
                echo "<br />";
            }
        }
    }
    if (count($tmp) > 0) {
        if (!insert_program_value($program[0]['selected_plug'], $tmp, $out)) {
            $ret = false;
        }
    }
    return $ret;
}
Ejemplo n.º 2
0
$limit = false;
$last_action = 0;
if ($remove_1000_change_limit == "False") {
    //Pour vérifier que l'on ne dépasse pas la limite de changement d'état des prises:
    //On génère le fichier plugv depuis la base de données et on compte le nombre de ligne,
    //Si cela dépasse la limite, on affiche une erreur/warning après calcul de l'heure de la dernière action
    $tmp_prog = create_program_from_database($main_error, $program_index);
    if (count($tmp_prog) > $GLOBALS['PLUGV_MAX_CHANGEMENT'] - 1) {
        $last_action = substr($tmp_prog[$GLOBALS['PLUGV_MAX_CHANGEMENT'] - 1], 0, 5);
        $main_error[] = __('ERROR_MAX_PROGRAM') . " " . date('H:i:s', $last_action);
        $limit = true;
    }
}
// For each plug gets pogramm
for ($i = 0; $i < $nb_plugs; $i++) {
    $data_plug = get_data_plug($i + 1, $main_error, $program_index);
    $plugs_infos[$i]["data"] = format_program_highchart_data($data_plug, "");
    // Translate
    $plugs_infos[$i]['translate'] = translate_PlugType($plugs_infos[$i]['PLUG_TYPE']);
}
// Create summary for tooltip
$resume = format_data_sumary($plugs_infos);
$real_resume[] = "";
$tmp_resume[] = "";
foreach ($resume as $res) {
    $tmp_res = explode("<br />", $res);
    $real_resume[] = implode("<br />", array_slice($tmp_res, 2));
    if (count($tmp_res) > 30) {
        $tmpr = array_chunk($tmp_res, 29);
        $tmpr[0][] = "[...]";
        $tmpr[0][] = "<p class='p_center'><button id='show_program_details'>" . __('DISPLAY_ACTIONS') . "</button></p>";