<?

$LISTS[calendar][0]["sql_select"]="SELECT * FROM calendar WHERE %[PERM]% ";
$LISTS[calendar][0]["options"]="perpage::50||defordfield::day||defordtype::asc||defordfield2::time||defordtype2::asc||exp::0";
$LISTS[calendar][0]["titles"]=" ||".CALENDAR_ADATE."::ord||".CALENDAR_ATIME."::ord||".CALENDAR_ADESC."::ord||".FW_CODE."::ord||".CALENDAR_USERS."||".CALENDAR_REF_PRATICA."::ord";
$LISTS[calendar][0]["fields"]="note::func=>calendar_note_pic||day::date||time||title::linkid=>".$CONF[url_base].$CONF[dir_modules]."calendar/pages/appunt_show.php?id=%ID%||codice||calendar_operator::func=>calendar_shortoper||ref_prat::func=>calendar_format_prat";
//$LISTS[calendar][0]["action"]="id;;".FW_SHOW.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/appunt_show.php?id=%ID%||id;;".FW_MODIFY.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/new_app.php?id=%ID%||id;;".FW_DELETE.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/app_view.php?action=del&id=%ID%";

$LISTS[calendar][1]["sql_select"]="SELECT * FROM calendar WHERE %[PERM]% ";
$LISTS[calendar][1]["options"]="perpage::10000||defordfield::day||defordtype::asc||defordfield2::time||defordtype2::asc||exp::0";
$LISTS[calendar][1]["titles"]=CALENDAR_ADATE."||".CALENDAR_ATIME."||".CALENDAR_ADESC."||".FW_CODE."||".CALENDAR_USERS."||".CALENDAR_REF_PRATICA;
$LISTS[calendar][1]["fields"]="day::date||time||title||codice||calendar_operator::func=>calendar_shortoper||ref_prat::[SELECT * FROM pratiche WHERE id='%ID%';;pr_codice]";


//INPAGE LISTING FOR PRATICHE
$LISTS[calendar][3]["sql_select"]="SELECT * FROM pratiche p, calendar m WHERE  p.id=m.ref_prat AND m.ref_prat=".$_GET[id];
$LISTS[calendar][3]["options"]="perpage::20||defordfield::day||defordtype::asc||defordfield2::time||defordtype2::desc||exp::0";
$LISTS[calendar][3]["titles"]=" ||".CALENDAR_ADATE."::ord||".CALENDAR_ATIME."||".CALENDAR_ADESC."||".FW_CODE."||".CALENDAR_USERS."||".CALENDAR_REF_PRATICA;
$LISTS[calendar][3]["fields"]="note::func=>calendar_note_pic||day::date||time||title::linkid=>".$CONF[url_base].$CONF[dir_modules]."calendar/pages/appunt_show.php?id=%ID%||codice||calendar_operator::func=>calendar_shortoper||ref_prat::func=>calendar_format_prat";
$LISTS[calendar][3]["action"]="id;;".FW_SHOW.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/appunt_show.php?id=%ID%||id;;".FW_MODIFY.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/new_app.php?id=%ID%||id;;".FW_DELETE.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/app_view.php?action=del&id=%ID%";

//HOME LISTING FOR EVERYTHING
$LISTS[calendar][2]["sql_select"]="SELECT * FROM pratiche p, calendar m WHERE (operator LIKE '".$_SESSION[fw_userid].",,%' OR operator LIKE '".$_SESSION[fw_userid]."' OR operator LIKE '%,,".$_SESSION[fw_userid]."' OR operator LIKE '%,,".$_SESSION[fw_userid].",,%') AND p.id=m.ref_prat";
$LISTS[calendar][2]["options"]="perpage::20||defordfield::day||defordtype::asc||defordfield2::time||defordtype2::desc||exp::0";
$LISTS[calendar][2]["titles"]=" ||".CALENDAR_ADATE."::ord||".CALENDAR_ATIME."||".CALENDAR_ADESC."||".FW_CODE."||".CALENDAR_USERS."||".CALENDAR_REF_PRATICA;
$LISTS[calendar][2]["fields"]="note::func=>calendar_note_pic||day::date||time||title::linkid=>".$CONF[url_base].$CONF[dir_modules]."calendar/pages/appunt_show.php?id=%ID%||codice||calendar_operator::func=>calendar_shortoper||ref_prat::func=>calendar_format_prat";
$LISTS[calendar][2]["action"]="id;;".FW_SHOW.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/appunt_show.php?id=%ID%||id;;".FW_MODIFY.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/new_app.php?id=%ID%||id;;".FW_DELETE.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/app_view.php?action=del&id=%ID%";

//HOME LISTING FOR INCOMBENZE
$LISTS[calendar][4]["sql_select"]="SELECT * FROM pratiche p, calendar m WHERE m.type=1 AND (operator LIKE '".$_SESSION[fw_userid].",,%' OR operator LIKE '".$_SESSION[fw_userid]."' OR operator LIKE '%,,".$_SESSION[fw_userid]."' OR operator LIKE '%,,".$_SESSION[fw_userid].",,%') AND p.id=m.ref_prat";
$LISTS[calendar][4]["options"]="perpage::20||defordfield::day||defordtype::asc||defordfield2::time||defordtype2::desc||exp::0";
$LISTS[calendar][4]["titles"]=" ||".CALENDAR_ADATE."::ord||".CALENDAR_ATIME."||".CALENDAR_ADESC."||".FW_CODE."||".CALENDAR_USERS."||".CALENDAR_REF_PRATICA;
$LISTS[calendar][4]["fields"]="note::func=>calendar_note_pic||day::date||time||title::linkid=>".$CONF[url_base].$CONF[dir_modules]."calendar/pages/appunt_show.php?id=%ID%||codice||calendar_operator::func=>calendar_shortoper||ref_prat::func=>calendar_format_prat";
$LISTS[calendar][4]["action"]="id;;".FW_SHOW.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/appunt_show.php?id=%ID%||id;;".FW_MODIFY.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/new_app.php?id=%ID%||id;;".FW_DELETE.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/app_view.php?action=del&id=%ID%";

//HOME LISTING FOR EVENTI
$LISTS[calendar][5]["sql_select"]="SELECT * FROM pratiche p, calendar m WHERE m.type=0 AND (operator LIKE '".$_SESSION[fw_userid].",,%' OR operator LIKE '".$_SESSION[fw_userid]."' OR operator LIKE '%,,".$_SESSION[fw_userid]."' OR operator LIKE '%,,".$_SESSION[fw_userid].",,%') AND p.id=m.ref_prat";
$LISTS[calendar][5]["options"]="perpage::20||defordfield::day||defordtype::asc||defordfield2::time||defordtype2::desc||exp::0";
$LISTS[calendar][5]["titles"]=" ||".CALENDAR_ADATE."::ord||".CALENDAR_ATIME."||".CALENDAR_ADESC."||".FW_CODE."||".CALENDAR_USERS."||".CALENDAR_REF_PRATICA;
$LISTS[calendar][5]["fields"]="note::func=>calendar_note_pic||day::date||time||title::linkid=>".$CONF[url_base].$CONF[dir_modules]."calendar/pages/appunt_show.php?id=%ID%||codice||calendar_operator::func=>calendar_shortoper||ref_prat::func=>calendar_format_prat";
$LISTS[calendar][5]["action"]="id;;".FW_SHOW.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/appunt_show.php?id=%ID%||id;;".FW_MODIFY.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/new_app.php?id=%ID%||id;;".FW_DELETE.";;".$CONF[url_base].$CONF[dir_modules]."calendar/pages/app_view.php?action=del&id=%ID%";


function calendar_note_pic($row)
{
	if (strlen($row[note])>0)
	{
		 $output="<img src=\"%[IMAGE_GPATH]%ico/ico_note_min.gif\"> ";
	}	
	
	if ($row[day] < date("Y-m-d") && $row[done] != 1)
	{
		$output.="<img src=\"%[IMAGE_GPATH]%ico/ico_appu_scad_min.gif\"> ";
	}

	return $output;
}

function calendar_format_prat($row)
{
	GLOBAL $DB,$CONF;
	
	$rs=$DB->Execute("SELECT * FROM pratiche WHERE id=".$row[ref_prat]);
	$prat=$rs->FetchRow();
	return "<a href=\"".$CONF[url_base].$CONF[dir_modules]."pratiche/pages/pratiche_show.php?id=".$prat[id]."\">".$prat[pr_codice]."</a>";
}

function calendar_shortoper($row)
{
	GLOBAL $DB,$CONF;
	
	if (strlen($row[operator]) > 0)
	{
		$cnt=0;
		foreach (explode(",,",$row[operator]) as $k=> $v)
		{
			$rs=$DB->Execute("SELECT * FROM users WHERE id=".$v);
			if ($rs->RecordCount() > 0)
			{
				$r = rand(1, 100000);
				$usr=$rs->FetchRow();
				if ($cnt==0)
				{$out.='<span onMouseOut="HideHelp(\'d' . $r . '\')" onMouseOver="ShowHelp(\'d' . $r . '\', \''. $usr[codice] . ' - '. $usr[nome] .'\', \'\')" >'.$usr[codice].'</span> <div style="display:none" id="d' . $r . '"></div>';}
				else {$out.=" - ".'<span onMouseOut="HideHelp(\'d' . $r . '\')" onMouseOver="ShowHelp(\'d' . $r . '\', \''. $usr[codice] . ' - '. $usr[nome] . '\', \'\')" >'.$usr[codice].'</span> <div style="display:none" id="d' . $r . '"></div>';}
				$cnt++;
			}
		}
	}
	return $out;
}




?>