예제 #1
0
function human_time_comparation($timestamp)
{
    global $config;
    if (!is_numeric($timestamp)) {
        $timestamp = strtotime($timestamp);
    }
    $seconds = get_system_time() - $timestamp;
    return human_time_description_raw($seconds);
}
예제 #2
0
 public function defaultFooter()
 {
     $system = System::getInstance();
     if ($system->getConfig('enteprise') == 1) {
         $enterprise = "Enterprise Edition";
     } else {
         $enterprise = "OpenSource Edition";
     }
     if (isset($_SERVER['REQUEST_TIME'])) {
         $time = $_SERVER['REQUEST_TIME'];
     } else {
         $time = get_system_time();
     }
     return "<div id='footer' style='font-size: 12px; text-align: center;'>\n" . "Integria IMS {$enterprise} " . "<br />\n" . $system->getConfig('version') . " - Build " . $system->getConfig('build_version') . "<br />\n" . "</div>";
 }
예제 #3
0
function inventories_load_file($objects_file)
{
    $file_handle = fopen($objects_file, "r");
    global $config;
    while (!feof($file_handle)) {
        $create = true;
        $line = fgets($file_handle);
        if ($line == '' || !isset($line)) {
            continue;
        }
        preg_match_all('/(.*),/', $line, $matches);
        $values = explode(',', $line);
        $id_object_type = $values[0];
        $owner = $values[1];
        $name = $values[2];
        $public = $values[3];
        $description = $values[4];
        $id_contract = $values[5];
        $id_manufacturer = $values[6];
        $id_parent = $values[7];
        $id_companies = $values[8];
        $id_users = $values[9];
        $status = $values[10];
        if ($id_companies != '') {
            $id_companies_arr = explode(';', $id_companies);
        } else {
            $id_companies_arr = array();
        }
        if ($id_users != '') {
            $id_users_arr = explode(';', $id_users);
        } else {
            $id_users_arr = array();
        }
        $value = array('id_object_type' => $id_object_type, 'owner' => $owner, 'name' => safe_input($name), 'public' => $public, 'description' => safe_input($description), 'id_contract' => $id_contract, 'id_manufacturer' => $id_manufacturer, 'id_parent' => $id_parent, 'status' => $status, 'last_update' => date("Y/m/d", get_system_time()));
        if ($name == '') {
            echo "<h3 class='error'>" . __('Inventory name empty') . "</h3>";
            $create = false;
        } else {
            $inventory_id = get_db_value('id', 'tinventory', 'name', $name);
            if ($inventory_id != false) {
                echo "<h3 class='error'>" . __('Inventory ') . $name . __(' already exists') . "</h3>";
                $create = false;
            }
        }
        if ($id_contract != 0 && $id_contract != '') {
            $exists = get_db_value('id', 'tcontract', 'id', $id_contract);
            if (!$exists) {
                echo "<h3 class='error'>" . __('Contract ') . $id_contract . __(' doesn\'t exist') . "</h3>";
                $create = false;
            }
        }
        if ($id_manufacturer != 0 && $id_manufacturer != '') {
            $exists = get_db_value('id', 'tmanufacturer', 'id', $id_manufacturer);
            if (!$exists) {
                echo "<h3 class='error'>" . __('Manufacturer ') . $id_manufacturer . __(' doesn\'t exist') . "</h3>";
                $create = false;
            }
        }
        if ($id_object_type != 0 && $id_object_type != '') {
            $exists_object_type = get_db_value('id', 'tobject_type', 'id', $id_object_type);
            if (!$exists_object_type) {
                echo "<h3 class='error'>" . __('Object type ') . $id_object_type . __(' doesn\'t exist') . "</h3>";
                $create = false;
            } else {
                //~ $all_fields = inventories_get_all_type_field ($id_object_type);
                $sql = "SELECT * FROM tobject_type_field WHERE id_object_type=" . $id_object_type;
                $all_fields = get_db_all_rows_sql($sql);
                if ($all_fields == false) {
                    $all_fields = array();
                }
                $value_data = array();
                $i = 11;
                $j = 0;
                foreach ($all_fields as $key => $field) {
                    $data = $values[$i];
                    switch ($field['type']) {
                        case 'combo':
                            $combo_val = explode(",", $field['combo_value']);
                            $k = array_search($data, $combo_val);
                            if ($k === false) {
                                echo "<h3 class='error'>" . __('Field ') . $field['label'] . __(' doesn\'t match. Valid values: ') . $field['combo_value'] . "</h3>";
                                $create = false;
                            }
                            break;
                        case 'numeric':
                            $res = is_numeric($data);
                            if (!$res) {
                                echo "<h3 class='error'>" . __('Field ') . $field['label'] . __(' must be numeric') . "</h3>";
                                $create = false;
                            }
                            break;
                        case 'external':
                            $table_ext = $field['external_table_name'];
                            $exists_table = get_db_sql("SHOW TABLES LIKE '{$table_ext}'");
                            if (!$exists_table) {
                                echo "<h3 class='error'>" . __('External table ') . $table_ext . __(' doesn\'t exist') . "</h3>";
                                $create = false;
                            }
                            $id = $field['external_reference_field'];
                            $exists_id = get_db_sql("SELECT {$id} FROM {$table_ext}");
                            if (!$exists_id) {
                                echo "<h3 class='error'>" . __('Id ') . $id . __(' doesn\'t exist') . "</h3>";
                                $create = false;
                            }
                            break;
                    }
                    if ($field['inherit']) {
                        $ok = inventories_check_unique_field($data, $field['type']);
                        if (!$ok) {
                            echo "<h3 class='error'>" . __('Field ') . $field['label'] . __(' must be unique') . "</h3>";
                            $create = false;
                        }
                    }
                    $value_data[$j]['id_object_type_field'] = $field['id'];
                    $value_data[$j]['data'] = safe_input($data);
                    $i++;
                    $j++;
                }
            }
        }
        if ($create) {
            $result_id = process_sql_insert('tinventory', $value);
            if ($result_id) {
                foreach ($value_data as $k => $val_data) {
                    $val_data['id_inventory'] = $result_id;
                    process_sql_insert('tobject_field_data', $val_data);
                }
                if (!empty($id_companies_arr)) {
                    foreach ($id_companies_arr as $id_company) {
                        $values_company['id_inventory'] = $result_id;
                        $values_company['id_reference'] = $id_company;
                        $values_company['type'] = 'company';
                        process_sql_insert('tinventory_acl', $values_company);
                    }
                }
                if (!empty($id_users_arr)) {
                    foreach ($id_users_arr as $id_user) {
                        $values_user['id_inventory'] = $result_id;
                        $values_user['id_reference'] = $id_user;
                        $values_user['type'] = 'user';
                        process_sql_insert('tinventory_acl', $values_user);
                    }
                }
            }
        }
    }
    //end while
    fclose($file_handle);
    echo "<h3 class='info'>" . __('File loaded') . "</h3>";
    return;
}
예제 #4
0
function flot_slicesbar_graph($graph_data, $period, $width, $height, $legend, $colors, $fontpath, $round_corner, $homeurl, $watermark = '', $adapt_key = '', $stat_win = false)
{
    global $config;
    include_javascript_dependencies_flot_graph();
    $height += 20;
    $stacked_str = 'stack: stack,';
    // Get a unique identifier to graph
    $graph_id = uniqid('graph_');
    // Set some containers to legend, graph, timestamp tooltip, etc.
    if ($stat_win) {
        $return = "<div id='{$graph_id}' class='graph {$adapt_key}' style='width: " . $width . "px; height: " . $height . "px; display: inline-block;'></div>";
    } else {
        $return = "<div id='{$graph_id}' class='graph {$adapt_key}' style='width: " . $width . "px; height: " . $height . "px;'></div>";
    }
    $return .= "<div id='value_{$graph_id}' style='display:none; position:absolute; background:#fff; border: solid 1px #aaa; padding: 2px'></div>";
    // Set a weird separator to serialize and unserialize passing data from php to javascript
    $separator = ';;::;;';
    $separator2 = ':,:,,,:,:';
    // Transform data from our format to library format
    $labels = array();
    $a = array();
    $vars = array();
    $datacolor = array();
    $max = 0;
    $i = count($graph_data);
    $intervaltick = $period / $i;
    $leg_max_length = 0;
    foreach ($legend as $l) {
        if (strlen($l) > $leg_max_length) {
            $leg_max_length = strlen($l);
        }
    }
    $fontsize = 7;
    $extra_height = 15;
    if (defined("METACONSOLE")) {
        $extra_height = 20;
    }
    $return .= "<div id='extra_{$graph_id}' style='font-size: " . $fontsize . "pt; display:none; position:absolute; overflow: auto; height: " . $extra_height . "px; background:#fff; padding: 2px 2px 2px 2px; border: solid #000 1px;'></div>";
    $maxticks = (int) ($width / ($fontsize * $leg_max_length));
    $i_aux = $i;
    while (1) {
        if ($i_aux <= $maxticks) {
            break;
        }
        $intervaltick *= 2;
        $i_aux /= 2;
    }
    $intervaltick = (int) $intervaltick;
    $acumulate = 0;
    $c = 0;
    $acumulate_data = array();
    foreach ($graph_data as $label => $values) {
        $labels[] = io_safe_output($label);
        $i--;
        foreach ($values as $key => $value) {
            $jsvar = "d_" . $graph_id . "_" . $i;
            if ($key == 'data') {
                $datacolor[$jsvar] = $colors[$value];
                continue;
            }
            $data[$jsvar][] = $value;
            $acumulate_data[$c] = $acumulate;
            $acumulate += $value;
            $c++;
            //$return .= "<div id='value_".$i."_$graph_id' class='values_$graph_id' style='color: #000; position:absolute;'>$value</div>";
            if ($value > $max) {
                $max = $value;
            }
        }
    }
    // Store serialized data to use it from javascript
    $labels = implode($separator, $labels);
    $datacolor = implode($separator, $datacolor);
    $legend = io_safe_output(implode($separator, $legend));
    $acumulate_data = io_safe_output(implode($separator, $acumulate_data));
    // Store data series in javascript format
    $jsvars = '';
    $jsseries = array();
    $date = get_system_time();
    $datelimit = ($date - $period) * 1000;
    $i = 0;
    $values2 = array();
    foreach ($data as $jsvar => $values) {
        $values2[] = implode($separator, $values);
        $i++;
    }
    $values = implode($separator2, $values2);
    // Javascript code
    $return .= "<script type='text/javascript'>";
    $return .= "//<![CDATA[\n";
    $return .= "integriaFlotSlicebar('{$graph_id}', '{$values}', '{$datacolor}', '{$labels}', '{$legend}', '{$acumulate_data}', {$intervaltick}, false, {$max}, '{$separator}', '{$separator2}')";
    $return .= "\n//]]>";
    $return .= "</script>";
    return $return;
}
예제 #5
0
/**
 * Create a new user
 *
 * @return bool false
 */
function create_user($id_user, $password, $user_info)
{
    $values = $user_info;
    $values["id_usuario"] = $id_user;
    $values["password"] = md5($password);
    //$values["last_connect"] = 0;
    $values["fecha_registro"] = get_system_time();
    return @process_sql_insert("tusuario", $values) !== false;
}
예제 #6
0
        $result_msg = '<h3 class="error">' . __('There was an error updating inventory object') . '</h3>';
    }
    if (defined('AJAX')) {
        echo $result_msg;
        echo $msg_err;
        return;
    }
}
if ($create) {
    if (!$write_permission) {
        audit_db($config['id_user'], $config["REMOTE_ADDR"], "ACL Violation", "Trying to create inventory #" . $id);
        include "general/noaccess.php";
        exit;
    }
    $err_message = __('Could not be created');
    $last_update = date("Y/m/d", get_system_time());
    if ($inventory_status == 'issued') {
        $issue_date = date('Y-m-d');
    } else {
        $issue_date = '';
    }
    $inventory_id = get_db_value('id', 'tinventory', 'name', $name);
    if ($name == '') {
        $err_message .= ". " . __('Name cannot be empty') . ".";
        $id = false;
    } else {
        $sql = sprintf('INSERT INTO tinventory (name, description,
				id_contract, id_parent, id_manufacturer, owner, public, id_object_type, last_update, status, receipt_date, issue_date)
				VALUES ("%s", "%s", %d, %d, %d, "%s", %d, %d, "%s", "%s", "%s", "%s")', $name, $description, $id_contract, $id_parent, $id_manufacturer, $owner, $public, $id_object_type, $last_update, $inventory_status, $receipt_date, $issue_date);
        $id = process_sql($sql, 'insert_id');
    }