<xml version="1.0" encoding="UTF-8">
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="UTF-8">
</head>
<div class="planner" id="planner">
<script src="./scheduler/dhtmlxscheduler.js" type="text/javascript" charset="utf-8"></script>
<script src="./scheduler/locale/locale_ar.js" type="text/javascript" charset="utf-8"></script>
<script src='./scheduler/ext/dhtmlxscheduler_minical.js' type="text/javascript"></script>
<script src="./scheduler/ext/dhtmlxscheduler_agenda_view.js" ></script>
<script type="text/javascript">
function show_minical(){
if (scheduler.isCalendarVisible()){
scheduler.destroyCalendar();
} else {
scheduler.renderCalendar({
position:"dhx_minical_icon",
date:scheduler._date,
navigation:true,
handler:function(date,calendar){
scheduler.setCurrentView(date);
scheduler.destroyCalendar()
}
});
}
}
</script>
<link rel="stylesheet" href="./codebase/dhtmlxscheduler_flat.css" type="text/css" charset="utf-8">
<div id='scheduler_here' class='dhx_cal_container' style='width:100%;height:100%;'>
<div class='dhx_cal_navline'>
<div class='dhx_cal_prev_button'> </div>
<div class='dhx_cal_next_button'> </div>
<div class='dhx_cal_today_button'></div>
<div class='dhx_cal_date'></div>
<div class='dhx_cal_tab' name='month_tab' style='left:204px;'></div>
<div class='dhx_cal_tab' name='week_tab' style='left:140px;'></div>
<div class='dhx_cal_tab' name='day_tab' style='left:76px;'></div>
<div class="dhx_cal_date"></div>
<div class="dhx_minical_icon" id="dhx_minical_icon"
onclick="show_minical()"> </div>
<div class="dhx_cal_tab" name="agenda_tab" style="right:280px;"></div>
</div>
<div class='dhx_cal_header'></div>
<div class='dhx_cal_data'></div>
</div>
<script>
scheduler.locale.labels.agenda_tab="aymen";
scheduler.config.serverLists = {};
scheduler.config.details_on_create = true;
scheduler.config.details_on_dblclick = true;
//scheduler.config.skin = 'terrace';
scheduler.config.dblclick_create = true;
scheduler.init('scheduler_here',new Date(2017, 3, 12, 16, 54, 8));
scheduler.locale.labels.agenda_tab="My Agenda";
//scheduler.config.prevent_cache = true;
scheduler.load("events.html", "json");
//scheduler.parse("events.html","xml");
var dp = new dataProcessor("events.html");
//dp.enableUTFencoding(false);
dp.init(scheduler);
//dp.enableUTFencoding(false);
dp.setTransactionMode("GET", false);
dp.enableUTFencoding(true);
</script></div>
</html>[/code]
[code]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%= getEvents(request,response)%>
<%@ page import="com.dhtmlx.planner.DHXEventsManager ,com.dhtmlx.demo.*, com.dhtmlx.planner.DHXEv,com.google.gson.Gson"%>
<%!
String getEvents(HttpServletRequest request , HttpServletResponse response ) throws Exception {
//DHXEv event=null;
EventsManager evs = new EventsManager(request);
System.out.println(request);
System.out.println(response);
//String json = new Gson().toJson(request); // anyObject = List<Bean>, Map<K, Bean>, Bean, String, etc..
//response.setContentType("application/json");
//response.setCharacterEncoding("UTF-8");
//response.getWriter().write(json);
String contentType= "text/html;charset=UTF-8";
response.setContentType(contentType);
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
System.out.println(request);
System.out.println(response);
return evs.run();
}
%>
[/code]
[code]package com.dhtmlx.demo;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.dhtmlx.planner.DHXEv;
import com.dhtmlx.planner.DHXEvent;
import com.dhtmlx.planner.DHXEventsManager;
import com.dhtmlx.planner.DHXStatus;
public class EventsManager extends DHXEventsManager{
public EventsManager(HttpServletRequest request) {
super(request);
// TODO Auto-generated constructor stub
}
public Iterable<DHXEv>getEvents(){
DHXEventsManager.date_format="yyyy-MM-dd HH:mm:ss";
List<DHXEv> evs = new ArrayList<DHXEv>();
try{
java.sql.Connection conn = DatabaseConnection.getConnection();
java.sql.Statement statement = conn.createStatement();
String query = "SELECT id , end_date , start_date , text FROM events";
ResultSet resultset = statement.executeQuery(query);
while (resultset.next()){
DHXEvent e = new DHXEvent();
e.setId(Integer.parseInt(resultset.getString("id")));
e.setText(resultset.getString("text"));
e.setStart_date(resultset.getString("start_date"));
e.setEnd_date(resultset.getString("end_date"));
evs.add(e);
}
conn.close();
}catch (SQLException e1 ){
e1.printStackTrace();
}
DHXEventsManager.date_format="MM/dd/yyyy HH:mm";
return evs;
}
@Override
public DHXStatus saveEvent(DHXEv event, DHXStatus status) {
java.sql.Connection conn = DatabaseConnection.getConnection();
java.sql.PreparedStatement ps = null;
java.sql.ResultSet result = null;
try {
String query = null;
String start_date = new SimpleDateFormat("yyyy-dd-MM HH:mm:ss")
.format(event.getStart_date());
String end_date = new SimpleDateFormat("yyyy-dd-MM HH:mm:ss")
.format(event.getEnd_date());
if (status == DHXStatus.UPDATE) {
query = "UPDATE events SET text=? , start_date=? , end_date=? WHERE id=?";
ps = conn.prepareStatement(query,
Statement.RETURN_GENERATED_KEYS);
ps.setString(1, event.getText());
ps.setString(2, start_date);
ps.setString(3, end_date);
ps.setInt(4, event.getId());
} else if (status == DHXStatus.INSERT) {
query = "INSERT INTO events (end_date,start_date,text) VALUES( ? ,? ,?)";
ps = conn.prepareStatement(query,
Statement.RETURN_GENERATED_KEYS);
ps.setString(1, end_date);
ps.setString(2, start_date);
ps.setString(3, event.getText());
} else if (status == DHXStatus.DELETE) {
query = " DELETE FROM events WHERE id=? ";
ps = conn.prepareStatement(query,
Statement.RETURN_GENERATED_KEYS);
ps.setInt(1, event.getId());
}
if (ps != null) {
ps.executeUpdate();
result = ps.getGeneratedKeys();
if (result.next())
;
event.setId(result.getInt(1));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (result != null)
try {
result.close();
} catch (SQLException e) {
}
if (ps != null)
try {
ps.close();
} catch (SQLException e) {
}
if (conn != null)
try {
conn.close();
} catch (SQLException e) {
}
}
return status;
}
@Override
public DHXEv createEvent(String id, DHXStatus status) {
return new DHXEvent();
}
}