2011-04-01 14:28:50 +02:00
|
|
|
<?php
|
|
|
|
// Copyright (c) 2011-2011 Ártica Soluciones Tecnológicas
|
|
|
|
// http://www.artica.es <info@artica.es>
|
|
|
|
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; version 2
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
2011-06-13 13:12:32 +02:00
|
|
|
function serialize_in_temp($array = array(), $serial_id = null, $ttl = 1) {
|
2011-04-01 14:28:50 +02:00
|
|
|
$json = json_encode($array);
|
|
|
|
|
2011-04-05 18:11:53 +02:00
|
|
|
if ($serial_id === null) {
|
2011-04-01 14:28:50 +02:00
|
|
|
$serial_id = uniqid();
|
|
|
|
}
|
2013-02-01 14:28:49 +01:00
|
|
|
|
2011-06-13 13:12:32 +02:00
|
|
|
$file_path = sys_get_temp_dir()."/pandora_serialize_".$serial_id."__1__".$ttl;
|
2013-02-01 14:28:49 +01:00
|
|
|
|
2011-04-05 18:11:53 +02:00
|
|
|
if (file_put_contents($file_path, $json) === false) {
|
2011-04-01 14:28:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-02-01 14:28:49 +01:00
|
|
|
|
2011-04-01 14:28:50 +02:00
|
|
|
return $serial_id;
|
|
|
|
}
|
|
|
|
|
2011-06-13 13:12:32 +02:00
|
|
|
function unserialize_in_temp($serial_id = null, $delete = true, $ttl = 1) {
|
2011-04-05 18:11:53 +02:00
|
|
|
if ($serial_id === null) {
|
2011-04-01 14:28:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-13 13:12:32 +02:00
|
|
|
$volume = -1;
|
|
|
|
|
2013-02-01 14:28:49 +01:00
|
|
|
for ($i = 1 ; $i <= $ttl ; $i++) {
|
2011-06-13 13:12:32 +02:00
|
|
|
$file_path = sys_get_temp_dir()."/pandora_serialize_".$serial_id."__".$i."__".$ttl;
|
|
|
|
|
2013-02-01 14:28:49 +01:00
|
|
|
if (file_exists($file_path)) {
|
2011-06-13 13:12:32 +02:00
|
|
|
$volume = $i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-02-01 14:28:49 +01:00
|
|
|
|
2011-04-01 14:28:50 +02:00
|
|
|
$content = file_get_contents($file_path);
|
2013-02-01 14:28:49 +01:00
|
|
|
|
2011-04-05 18:11:53 +02:00
|
|
|
if ($content === false) {
|
2011-04-01 14:28:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$array = json_decode($content, true);
|
|
|
|
|
2011-04-05 18:11:53 +02:00
|
|
|
if ($delete) {
|
2011-06-13 13:12:32 +02:00
|
|
|
if($volume == $ttl) {
|
|
|
|
unlink($file_path);
|
|
|
|
}
|
|
|
|
else {
|
2011-06-13 18:55:19 +02:00
|
|
|
$next_volume = $volume + 1;
|
2011-06-13 13:12:32 +02:00
|
|
|
rename($file_path, sys_get_temp_dir()."/pandora_serialize_".$serial_id."__".$next_volume."__".$ttl);
|
|
|
|
}
|
2011-04-01 14:28:50 +02:00
|
|
|
}
|
2013-02-01 14:28:49 +01:00
|
|
|
|
2011-04-01 14:28:50 +02:00
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete_unserialize_in_temp($serial_id = null) {
|
2011-04-05 18:11:53 +02:00
|
|
|
if ($serial_id === null) {
|
2011-04-01 14:28:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_path = sys_get_temp_dir()."/pandora_serialize_".$serial_id;
|
2013-02-01 14:28:49 +01:00
|
|
|
|
2011-04-01 14:28:50 +02:00
|
|
|
return unlink($file_path);
|
|
|
|
}
|
2011-04-08 10:56:43 +02:00
|
|
|
|
|
|
|
function reverse_data($array) {
|
|
|
|
$array2 = array();
|
2013-02-01 14:28:49 +01:00
|
|
|
foreach ($array as $index => $values) {
|
|
|
|
foreach ($values as $index2 => $value) {
|
|
|
|
$array2[$index2][$index] = $value;
|
2011-04-08 10:56:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $array2;
|
|
|
|
}
|
2011-04-11 18:45:03 +02:00
|
|
|
|
|
|
|
function stack_data(&$chart_data, &$legend = null, &$color = null) {
|
|
|
|
foreach ($chart_data as $val_x => $graphs) {
|
|
|
|
$prev_val = 0;
|
|
|
|
$key = 1000;
|
|
|
|
foreach ($graphs as $graph => $val_y) {
|
|
|
|
$chart_data[$val_x][$graph] += $prev_val;
|
|
|
|
$prev_val = $chart_data[$val_x][$graph];
|
|
|
|
$temp_data[$val_x][$key] = $chart_data[$val_x][$graph];
|
2013-02-01 14:28:49 +01:00
|
|
|
if (isset($color[$graph])) {
|
2011-04-11 18:45:03 +02:00
|
|
|
$temp_color[$key] = $color[$graph];
|
|
|
|
}
|
2013-02-01 14:28:49 +01:00
|
|
|
if (isset($legend[$graph])) {
|
2011-04-11 18:45:03 +02:00
|
|
|
$temp_legend[$key] = $legend[$graph];
|
|
|
|
}
|
|
|
|
$key--;
|
|
|
|
}
|
|
|
|
ksort($temp_data[$val_x]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$chart_data = $temp_data;
|
|
|
|
if (isset($legend)) {
|
|
|
|
$legend = $temp_legend;
|
|
|
|
ksort($legend);
|
|
|
|
}
|
|
|
|
if (isset($color)) {
|
|
|
|
$color = $temp_color;
|
|
|
|
ksort($color);
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 19:42:50 +01:00
|
|
|
|
|
|
|
function graph_get_max_index($legend_values) {
|
|
|
|
$max_chars = 0;
|
|
|
|
foreach ($legend_values as $string_legend) {
|
|
|
|
if (empty($string_legend)) continue;
|
2013-02-01 14:28:49 +01:00
|
|
|
|
2011-12-22 19:42:50 +01:00
|
|
|
$string_legend = explode("\n",$string_legend);
|
2013-02-01 14:28:49 +01:00
|
|
|
|
|
|
|
foreach ($string_legend as $st_lg) {
|
2011-12-22 19:42:50 +01:00
|
|
|
$len = strlen($st_lg);
|
|
|
|
if ($len > $max_chars) {
|
|
|
|
$max_chars = $len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $max_chars;
|
|
|
|
}
|
2012-03-01 17:41:02 +01:00
|
|
|
|
|
|
|
function setup_watermark($water_mark, &$water_mark_file, &$water_mark_url) {
|
2013-02-01 14:28:49 +01:00
|
|
|
if (!is_array($water_mark)) {
|
2012-03-01 17:41:02 +01:00
|
|
|
$water_mark['file'] = $water_mark;
|
|
|
|
}
|
|
|
|
|
2013-02-01 14:28:49 +01:00
|
|
|
if (isset($water_mark['file'])) {
|
2012-03-01 17:41:02 +01:00
|
|
|
$water_mark_file = $water_mark['file'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$water_mark_file = '';
|
|
|
|
}
|
|
|
|
|
2013-02-01 14:28:49 +01:00
|
|
|
if (isset($water_mark['url'])) {
|
2012-03-01 17:41:02 +01:00
|
|
|
$water_mark_url = $water_mark['url'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$water_mark_url = '';
|
|
|
|
}
|
|
|
|
}
|
2013-02-01 14:28:49 +01:00
|
|
|
?>
|