forked from ahit/belldandy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess.php
executable file
·51 lines (44 loc) · 1.53 KB
/
process.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
#!/usr/bin/php
<?php
$db = new SQLite3('bell.db');
//the command that will play the bell sound
$command = "/usr/bin/mpg321";
//user to run the command as
$user = "root";
//installation directory (where to find bells.xml)
$source_dir = "/var/www/belldandy/";
//read all of the schedules
$schedules = $db->query('SELECT * FROM SCHEDULE');
//where to store the temporary cron formatted stub file we generate
$filename="bell.stub";
$fh = fopen("".$source_dir.$filename,"w");
while ($schedule = $schedules->fetchArray()) {
if($schedule['ACTIVE'] =='true'){
//write a nice comment saying the name of the schedule
fwrite($fh,"### ".$schedule['NAME']." ###\n");
// get periods
$periods = $db->query('SELECT * FROM PERIODS where SCHEDULE_ID='.$schedule['ID']);
while ($period = $periods->fetchArray()) {
$name = $period['NAME'];
$start = $period['START_DATE'];
$end = $period['END_DATE'];
$dow = trim($period['DOW'], ",");
$sound = $period['SOUND'];
$stime = explode(":",$start);
$etime = explode(":",$end);
$shour = $stime[0];
$sminute = $stime[1];
$ehour = $etime[0];
$eminute = $etime[1];
//print out the actual cron statements, formatted nicely
if($dow!=""){
fwrite($fh,"\n #- $name -#\n");
fwrite($fh,"$sminute $shour * * $dow $user\t $command $source_dir$sound\n");
fwrite($fh,"$eminute $ehour * * $dow $user\t $command $source_dir$sound\n");
}
}
fwrite($fh,"\n");
}
}
fclose($fh);
?>