-
Notifications
You must be signed in to change notification settings - Fork 4
/
copy_event.php
89 lines (73 loc) · 3.13 KB
/
copy_event.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
<?php
namespace gameme\PHPGamification;
use Exception;
use gameme\PHPGamification;
use gameme\PHPGamification\Model;
use gameme\PHPGamification\Model\Event;
use gameme\PHPGamification\Model\Badge;
define('AT_INCLUDE_PATH', '../../include/');
require (AT_INCLUDE_PATH.'vitals.inc.php');
$_GET["id"] = intval($_GET["id"]);
if($_GET["id"]!= ''){
global $_base_path;
$course_id = $_SESSION['course_id'];
$this_path = preg_replace ('#/get.php#','',$_SERVER['DOCUMENT_ROOT'].$_base_path);
$sql = "SELECT * FROM %sgm_events WHERE id=%d AND course_id=%d";
$default_event = queryDB($sql, array(TABLE_PREFIX, $_GET["id"], 0), TRUE);
require_once($this_path.'mods/gameme/gamify.lib.php');
require_once($this_path.'mods/gameme/PHPGamification/PHPGamification.class.php');
$gamification = new PHPGamification();
$gamification->setDAO(new DAO(DB_HOST, DB_NAME, DB_USER, DB_PASSWORD));
$event = new Event();
if($default_event['id']){
$event->setId($default_event['id'], $_SESSION['course_id']);
}
if(isset($_SESSION['course_id'])){
$event->setCourseId($_SESSION['course_id']);
}
$event->setAlias($default_event['alias']);
if($default_event['description']){
$event->setDescription($default_event['description']);
}
if($default_event['allow_repetitions']){
$event->setAllowRepetitions($default_event['allow_repetitions']);
}
if($default_event['reach_required_repetitions']){
$event->setReachRequiredRepetitions($default_event['reach_required_repetitions']);
}
if($default_event['max_points']){
$event->setMaxPointsGranted($default_event['max_points']);
}
if($default_event['each_points']){
$event->setEachPointsGranted($default_event['each_points']);
}
if($default_event['reach_points']){
$event->setReachPointsGranted($default_event['reach_points']);
//$event->setReachPointsGranted($_POST['reach_points']);
}
if($default_event['id_each_badge']){
$event->copyEachBadgeGranted($default_event['id']);
}
if($default_event['id_reach_badge']){
$event->copyReachBadgeGranted($default_event['id']);
}
if($default_event['each_callback']){
$event->setEachCallback($default_event['each_callback']);
}
if($default_event['reach_callback']){
$event->setReachCallback($default_event['reach_callback']);
}
if($default_event['reach_message']){
$event->setReachMessage($default_event['reach_message']);
}
if( $gamification->addEvent($event, $course_id)){
$msg->addFeedback('GM_EVENT_COPIED');
header("Location: ".AT_BASE_HREF."mods/gameme/index_instructor.php");
exit;
} else{
$msg->addError('GM_EVENT_COPY_FAILED');
header("Location: ".AT_BASE_HREF."mods/gameme/index_instructor.php");
exit;
}
}
?>