include("funzioni_comuni.php");
setlocale (LC_TIME, "it_IT");
require_once($_SERVER['DOCUMENT_ROOT']."/config.inc.php");
function slash3 ($campo) {
$transf=$_POST[$campo];
//$transf=str_replace("'", "''", $_POST[$campo]); // per la query
//$transf=str_replace("\'", "''", $_POST[$campo]); // per la query
return($transf);
}
function rimuovi_apici($html) {
return str_replace('"', '"', str_replace("'", "´", $html));
}
/*
function slashsql($campo) {
#$transf=str_replace("'", "''",); // per la query
return($_POST[$campo]);
}
function slash_input($campo) {
$transf=htmlentities($campo, ENT_QUOTES);
return($transf);
}
*/
function codifica($stringa, $chiave, $verso=1) {
// $verso=1 -> Cripta
// $verso=2 -> Decripta
$comando=$verso==1?"AES_ENCRYPT":"AES_DECRYPT";
$query = mysql_query("Select ".$comando."('$stringa', '$chiave') as risultato");
$rigo = mysql_fetch_array($query);
return $rigo['risultato'];
//return "Select ".$comando."($stringa, $chiave) as risultato";
}
function calendario($mese=null,$anno=null)
{
if ($mese == NULL AND $anno == NULL){
$mese = date("m");
$anno = date("Y");
}
$meseumano = ucfirst(strftime("%B", strtotime("$anno-$mese-1")));
$prev = mktime(0, 0, 0, $mese -1, 1, $anno);
$next = mktime(0, 0, 0, $mese +1, 1, $anno);
$human_month = array("error", "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre" );
$settimana = array("Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa");
$giorni = date("t",mktime(0, 0, 0, $mese, 1, $anno));
$ore_lavorate = array();
$i==0;
$days = "
";
for($g=1;$g<=$giorni;$g++)
{
$appuntamenti = null;
$cg = date("w",mktime(0, 0, 0, $mese, $g, $anno));
if($i==0 AND $cg!=1)
{
$todo = $cg==0 ? 6:$cg-1;
for($e=1;$e<=$todo;$e++)
{
$days .= " | ";
}
}
else
{
if($cg==1) $days .= "
";
}
$st = ($cg==6 OR $cg==0) ? "color:red;":"";
if($g==23) {$appuntamenti = " jiso jio joIj ao aiojao ka k..
";
$appuntamenti .= " kooo joh hioo..
";}
$days .= "$g ".$settimana[$cg].$appuntamenti." | ";
if($cg==0) $days.="
";
$i++;
}
$days .= "";
/* $res_h = mysql_query("SELECT * FROM $tab_ore WHERE id_lavoro = $lavoro AND giorno = '$anno-$mese-$g'");
while($row = mysql_fetch_array($res_h))
{
extract($row);
$ore_lavorate[$id_staff][$g]['id'] = $id;
$ore_lavorate[$id_staff][$g]['num'] = $ore;
$ore_lavorate[$id_staff][$g]['type'] = $modalita;
}
}
$qu = "SELECT $tab_staff.nome, $tab_staff.id FROM $tab_staff LEFT JOIN $tab_ass_lavori ON $tab_ass_lavori.id_staff = $tab_staff.id WHERE $tab_ass_lavori.id_lavoro = $lavoro";
$res = mysql_query($qu);
if(mysql_num_rows($res)==0)
{
$ore_td = "| Non sono presenti risorse umane per questo progetto |
";
}
else
{
while($rigo = mysql_fetch_array($res))
{
extract($rigo);
$ore_td .= "| ".$nome." | ";
for($g=1;$g<=$giorni;$g++)
{
switch ($ore_lavorate[$id][$g]['type'])
{
//case 1: $col = "background-color: pink;"; break;
//case 2: $col = "background-color: #C3FFD2;"; break;
default: $col = '';
}
$link = $id==$_SESSION['id_utente'] ? "onClick='location.href=\"?page=operatori&id_lavoro=$lavoro&day=".$g.$mese.$anno."&id=".$ore_lavorate[$id][$g]['id']."&azione=orelav\"'":"";
if(time() < mktime(0,0,0,$mese,$g,$anno) OR strtotime("-10 days")>mktime(0,0,0,$mese,$g,$anno)) $link = "";
$st = $ore_lavorate[$id][$g]['id']>0 ? "class='ore' onMouseover='orelavorate(".$ore_lavorate[$id][$g]['id'].")' onMouseout='orelavorate(".$ore_lavorate[$id][$g]['id'].",1)' style='cursor:pointer; $col'":"";
$ore_td .= "".$ore_lavorate[$id][$g]['num']."
| ";
// le altre classi del tooltip sono nel file get.php
}
$ore_td .= "
";
}
}
*/
echo "| « $meseumano $anno » |
$days
";
}
/*
function get_info_ajax($valore,$table,$what)
{
switch($what)
{
case "livello": {
$what = "sys_livelli.nome";
$join = "INNER JOIN sys_livelli ON sys_livelli.id = $table.id_livello";
break;
}
default : {
}
}
$campo = $table.".".$campo;
$qu_str = "SELECT $what FROM $table $join WHERE ".$table.".id = '$valore'";
$query = mysql_query($qu_str);
while($row = mysql_fetch_array($query))
{
for($i=0;$i';
}
return "".$thumbs."
";
}
function close_lightbox($id=null,$nuovi=null,$funzione=null,$urlie=null)
{
if($id==null)
{
if($_REQUEST['naked']==1)
{
echo '';
return;
}
else
{
echo '';
return;
}
}
if($_REQUEST['naked']==1)
{
echo '';
}
else
{
echo '
';
}
}
// ++++++++ FUNZIONI PER INTERAZIONE CON IL DB ++++++++ //
function trova($campo, $valore, $requested = "*", $tab)
{
$query = mysql_query("SELECT $requested FROM $tab WHERE $campo = '$valore'");
$pos = strpos($requested, ",");
if ($requested != '*' AND $pos === false)
{
$rigo = mysql_fetch_array($query);
return $rigo[$requested];
}
else return mysql_fetch_array($query);
}
function ordina($tabella,$div = 'myList') {
$output="
";
return $output;
}
/*
function doc_list($idgruppo) {
global $upload_path, $url, $tab_files;
$query = "SELECT * FROM $tab_files WHERE id_gruppodl = $idgruppo AND tipo_allegato = 'documento'";
$res = mysql_query($query);
if (mysql_num_rows($res) == 0) return null;
while($rigo = mysql_fetch_array($res)) {
$dim=filesize("$upload_path/inc/files/".$rigo['nome_file']);
$dim=$dim/1024;
if ($dim>1000) {$dim=$dim/1000; $unit = "Mb";} else $unit = "Kb";
$dim=number_format($dim, 0, '.', '');
// file-'.$rigo['tipo'].'
$elenco .= ''.$rigo['nome_utf8'].' ('.$dim." ".$unit.')';
}
return "";
}
*/
// ******** FINE FUNZIONI PER INTERAZIONE CON IL DB ******** //
/*
/// FUNZIONI Su DATE - UTILI SE C'E' IL MODULO STATISTICHE
Function QuantiGiorni($data1,$data2)
{
//calcola i giorni di differenza tra due date
//data1 e 2 in formato yyyy-mm-dd
$query = mysql_query("select to_days('$data2')-to_days('$data1') as tot ");
return $total = mysql_result($query,0,'tot');
}
function giornidelmese($Mese, $Anno) {
$giorni_settimana = array("D","L","M","M","G","V","S");
$mese_testo = array(1 => "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre"," Dicembre");
$mese_testo_ing = array(1 => "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November"," December");
if (($Mese+1)>12) {
$M1=1;
$A1=$Anno+1;
} else {
$M1=$Mese+1;
$A1=$Anno;
}
$DD1=QuantiGiorni("2000-01-01",$Anno."-".$Mese."-01");
$DD2=QuantiGiorni("2000-01-01",$A1."-".$M1."-01");
$cicli= (($DD2)-$DD1);
$giornimese=array();
for ($i = 1; $i <= $cicli; $i++) {
$giorno=$giorni_settimana[date("w",strtotime ($i." $mese_testo_ing[$Mese] $Anno"))];
$dispdate=$i<10?"0".$i."-".$giorno:$i."-".$giorno;
//$dispdate=$giorno=="D"?"".$dispdate."":$dispdate;
$giornimese[] = $dispdate;
}
return $giornimese;
}
*/
function valid_email($email)
{
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) return true; else return false;
}
/*
function invia_newsletter($id)
{
global $tab_newsletter_storia;
mysql_query("UPDATE $tab_newsletter_storia SET bozza = 0 WHERE id = ".$id);
echo "";
echo"";
exit;
}
*/
function file_extension($fname)
{
return strtolower(substr(strrchr($fname, '.'), 1));
}
function resize_image($id, $tn_max_width=160, $tn_max_height=160)
{
global $path_up, $tab_files;
$fname = trova("id", $id, 'nome_file', $tab_files);
$picname = $fname;
$size = getimagesize($path_up.$fname);
$width = $size[0];
$height = $size[1];
if($width>$height)
{
mysql_query("UPDATE $tab_files SET orizzontale = 1 WHERE id = $id");
}
$max_width = 800;
$max_height = 600;
//IMG ORIG!
if (($width <= $max_width) AND ($height <= $max_height))
{
$orig_width = $width;
$orig_height = $height;
}
else
{
if ($height > $width)
{
$riduzione = $height / $max_height;
$orig_width = $width / $riduzione;
$orig_height = $max_height;
}
else
{
$riduzione = $width / $max_width;
$orig_height = $height / $riduzione;
$orig_width = $max_width;
}
}
$ext = file_extension($fname); // get the file extension
switch ($ext) {
case 'jpg': // jpg
$image = imagecreatefromjpeg($path_up.$fname);
break;
case 'png': // png
$image = imagecreatefrompng($path_up.$fname);
break;
case 'gif': // gif
$image = imagecreatefromgif($path_up.$fname);
break;
default:
exit('formato immagine non supportato');
}
unlink($path_up.$fname);
$image_orig = imagecreatetruecolor($orig_width, $orig_height);
switch ($ext) {
case 'jpg': // jpg
imagecopyresampled($image_orig, $image, 0, 0, 0, 0, $orig_width, $orig_height, $width, $height);
imagejpeg($image_orig, $path_up.$picname, 80);
break;
case 'png': // png
imagealphablending($image_orig, false);
imagecopyresampled($image_orig, $image, 0, 0, 0, 0, $orig_width, $orig_height, $width, $height);
imagesavealpha($image_orig, true);
imagepng($image_orig, $path_up.$picname, 80);
break;
case 'gif': // gif
$image_orig = imagecreatetruecolor($orig_width, $orig_height);
imagesavealpha($image_orig,true);
$white = imagecolorallocate($image_orig, 0xff, 0xff, 0xff);
imagefill($image_orig, 0, 0, $white);
imagecopyresampled($image_orig, $image, 0, 0, 0, 0, $orig_width, $orig_height, $width, $height);
imagegif($image_orig, $path_up.$picname);
}
imageDestroy($image);
imageDestroy($image_orig);
}
function delete_file($id, $type)
{
global $path_up, $tab_files;
if ($type=="single")
{
$query = "select nome_file from $tab_files where id = ".$id;
$rigo = mysql_fetch_array(mysql_query($query));
@unlink($path_up.$rigo['nome_file']);
@unlink($path_up."tn_".$rigo['nome_file']);
mysql_query("delete from $tab_files where id = ".$id);
}
if ($type=="all")
{
$query = "select nome_file from $tab_files where id_gruppodl = ".$id;
$res = mysql_query($query);
while ($rigo = mysql_fetch_array($res))
{
@unlink($path_up.$rigo['nome_file']);
@unlink($path_up."tn_".$rigo['nome_file']);
}
mysql_query("delete from $tab_files where id_gruppodl = ".$id);
}
}
function php_upload($file, $tab, $idgruppo, $userid) {
include("json.php");
global $tab_files, $path_up;
$result = array();
$file = $_FILES['fileupload']['tmp_name'];
$error = false;
$size = false;
if (!is_uploaded_file($file) || ($_FILES['fileupload']['size'] > 100 * 1024 * 1024) )
{
$error = 'Upload Fallito! Non è possibile caricare un file maggiore di 100MB';
}
if ($_FILES["fileupload"] != "") {
$nome_allegato = str_replace(" ", "", $_FILES["fileupload"]["name"]);
$trova_punto_allegato = explode(".", $nome_allegato);
$estensione_allegato = $trova_punto_allegato[count($trova_punto_allegato) - 1];
$estensione_allegato = strtolower($estensione_allegato);
}
$allegato_inserito=time()."_".rand(0,999999).".$estensione_allegato";
@move_uploaded_file($_FILES["fileupload"]["tmp_name"], $path_up.$allegato_inserito);
@chmod($path_up.$allegato_inserito, 0775);
if (file_exists($path_up.$allegato_inserito)) {
$sql="insert into $tab_files (id_gruppodl,nome_file,tipo,nome_utf8,tipo_allegato,id_utente,data_ins) VALUES ($idgruppo,'$allegato_inserito','$estensione_allegato', '".addslashes($nome_allegato)."', '".cerca_tipo($estensione_allegato)."', '".$userid."', NOW())";
$query = mysql_query ($sql) or die (mysql_error().$sql);
$id = mysql_insert_id();
$tipo_file = cerca_tipo(file_extension($_FILES["fileupload"]["name"]));
if ($tipo_file=="immagine") resize_image($id);
} else $error = "File Non caricato! $path_up $allegato_inserito";
if ($error) {
$result['result'] = 'failed';
$result['error'] = $error;
}
else {
$result['result'] = 'success';
$result['size'] = "File Caricato";
$result['post'] = '';
}
header('Content-type: application/json');
$json = new Services_JSON();
exit($json->encode($result));
}
// FUNZIONE AJAX UPLOADER //
// ---------------------- //
/*
@ input **
*
* FILE CARICABILI
*
* si può indicare nell'argomento input:
* - una stringa (tipo file ammesso per upload singolo)
* es. "immagine" permetterà l'upload di un file del tipo "immagine"
*
* - un array (per upload multipli) es. $array_upload
* con $array_upload = array ("immagine"=>3,"documento"=>0,"video"=>1,"dwg"=>1)
* che permetterà l'upload * di max 3 immagini, n documenti, max 1 video, max 1 file con estensione dwg
*
* macrosezioni tipi di file: immagine, documento, video
@ tab **
* nome tabella in cui vengono memorizzati i dati degli allegati
@ form **
*
* FORM (input, textarea, textarea con classe 'widgEditor')
*
* es.
@ id **
* IDENTIFICATIVO ARTICOLO / DOWNLOAD / PARAGRAFO / ETC
@ pagurl **
* URL destinazione FORM
* es. "?page=accreditamenti"
@ onsubmit **
* eventuale codice javascript da eseguire al submit del form dati. ES: onsubmit='onsubmit="return validate()"'
@ des **
* des=1 se serve il campo descrizione per ogni singolo allegato
@ tipouploader **
* valore della variabile tipo passato attraverso javascript per scopi diversi
*(Es: viene utilizzato il valore repository nel javascript che valida l'immissione di almeno un allegato
@ elencofiles **
* 1 = mostra nel form di immissione eventuale elenco di files già inseriti
* 0 = mostra nel form di immissione solo il link per immettere o sostituire l'allegato
*/
function ajax_uploader($input,$tab,$form,$id = 0,$pagurl,$onsubmit=null,$des=0,$tipouploader="standard", $elencofiles=1)
{
global $url;
global $upload_path;
global $ar_tipi_files;
global $tab_files;
// preg_match_all('/