/
activity.php
117 lines (97 loc) · 3.61 KB
/
activity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
include 'access.php';
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once 'main.php';
require_once 'Connection.class.php';
require_once 'ActivityDAO.class.php';
require_once 'SongDAO.class.php';
$response = array('status'=>'1', 'message' => '');
$isAjax = isAjaxRequest();
$action = from_post_or_get('action','');
if (!isset($action)) {
die('accio no informada'); exit;
}
$id = -1;
if ($action !== 'new' && $action !== 'update' && $action !== 'delete') {
die('accio incorrecta: '.$action );
}
switch($action) {
case 'delete':
$id = $_GET['id'] or die('id de canço no informat');
break;
case 'update':
$id = $_POST['id'] or die('id de canço no informat');
case 'new':
$activity_name = $_POST['activity_name'] or die('nom de canço no informat');
$description = $_POST['description']; // or die('descripción no informada');;
$goals = $_POST['goals']; // or die('descripción no informada');;
$materials = isset($_POST['materials']) ? $_POST['materials'] : '';
$observations = isset($_POST['observations']) ? $_POST['observations'] : '';
$assesment = isset($_POST['assesment']) ? $_POST['assesment'] : '';
$comments = isset($_POST['comments']) ? $_POST['comments'] : '';
$keywords = isset($_POST['keywords']) ? $_POST['keywords'] : '';
$types = isset($_POST['type']) ? $_POST['type'] : array();
$song_themes = isset($_POST['song_themes']) ? $_POST['song_themes'] : array();
$ages = isset($_POST['ages']) ? $_POST['ages'] : array();
$song_names = isset($_POST['song_name']) ? $_POST['song_name'] : array();
$song_durations = isset($_POST['song_duration']) ? $_POST['song_duration'] : array();
$song_files = isset($_POST['song_file']) ? $_POST['song_file'] : array();
$activity = array(
'id' => $id,
'activity_name' => $activity_name,
'description' => $description,
'goals' => $goals,
'materials' => $materials,
'observations' => $observations,
'assesment' => $assesment,
'comments' => $comments,
'keywords' => $keywords,
'types' => join(',', $types),
'song_themes' => join(',',$song_themes),
'ages' => join(',',$ages)
);
/*echo 'SONG nameS:';
print_r($song_names);*/
$songs = array();
for ($i=0; $i < count($song_names) ; $i++) {
$songs[] = array('name' => $song_names[$i], 'duration' => (empty($song_durations[$i]) ? '' : $song_durations[$i]), 'file' => '');
}
/*echo 'SONGS:';
print_r($songs);*/
}
/*
echo 'action: '.$action;
echo '$activity';
print_r($activity);
*/
$c = new Connection();
$conn = $c->getConnection();
$activityDAO = new ActivityDAO($conn);
$songDAO = new SongDAO($conn);
$response = array('status'=>'1', 'message' => '');
switch($action) {
case 'new':
$insert_id = $activityDAO->create($activity);
if (count($songs) > 0 ) {
$songDAO->createSongs($insert_id, $songs);
}
break;
case 'update':
$activityDAO->update($activity);
$songDAO->unlinkFromActivity($activity['id']);
$songDAO->createSongs($activity['id'], $songs);
break;
case 'delete':
//echo 'delete dao'.$id; exit;
$songDAO->unlinkFromActivity($id);
$activityDAO->delete($id);
break;
}
if ($isAjax) {
echo json_encode($response);
exit;
} else {
header("Location: " . $siteUrl . "activity_list.php?r=" . mt_rand(0, 9999999));
}
?>