summaryrefslogtreecommitdiff
path: root/includes/funktion_cron.php
blob: 3a0e984b7d268eeeede4776b9fec439aaad9871b (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
  function UID2DECT($UID) {
    global $con;
    $SQL = "SELECT DECT FROM `User` WHERE UID='$UID'";
    $Erg = mysql_query($SQL, $con);

    if(mysql_num_rows( $Erg) == 1)
      return mysql_result($Erg, 0);
    else
      return "";
  }

  function RID2Room($RID) {
    global $con;
    $SQL = "SELECT Name FROM `Room` WHERE RID='$RID'";
    $Erg = mysql_query($SQL, $con);

    if(mysql_num_rows( $Erg) == 1)
      return mysql_result($Erg, 0);
    else
      return "";
  }

  function TID2Engeltype($TID) {
    global $con;
    $SQL = "SELECT Name FROM `EngelType` WHERE TID='$TID'";
    $Erg = mysql_query($SQL, $con);

    if(mysql_num_rows( $Erg) == 1)
      return mysql_result($Erg, 0);
    else
      return "";
  }


  function DialNumberIAX( $DECTnumber, $Time, $RID, $TID) {
    global $IAXenable, $IAXcontent, $IAXserver, $AnrufDelay, $DebugDECT, $Tempdir, $AsteriskOutputDir;
  
    // Parameter verarbeiten
    $TimeH = substr( $Time, 11, 2);
    $TimeM = substr( $Time, 14, 2);
    $TimeM = substr( $Time, 14, 2) + $AnrufDelay;

    if($TimeM < 0) {
      $TimeM += 60;
      $TimeH -= 1;
    }

    if($TimeH < 0)
      $TimeH += 24;
  
    if(strlen( $TimeH) == 1)
      $TimeH = "0" . $TimeH;
  
    if($IAXenable) {
      $Message = "die-nee shisht beh-kinned, in where-neegin me-nooten . . . your shift beginns in a few minutes";

      if(isset($SetHttpIAX)) {
        $post_data = array();
        $post_data['code'] = "89o8eu9cg4";
        $post_data['callerid'] = "1023";
        $post_data['nr'] = "$DECTnumber";
        //$post_data['message'] = "Deine schicht beginnt in ein paar minuten . . . your shift beginns in a few minutes ";
        $post_data['message'] = "die-nee shisht beh-kinned , in where-neegin me-nooten . . . your shift beginns in a few minutes ";
        $url = "https://23c3.eventphone.de/~bef/call.php";

        $o = "";
        foreach ($post_data as $k => $v) {
          $o.= "$k=" . urlencode(utf8_encode($v)) . "&";
        }

        $post_data = substr($o, 0, -1);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);   
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $result = curl_exec($ch);
        echo curl_error($ch);
        curl_close($ch);
      } else {
        // IAX file Schareiebn
        $CallFile = $Tempdir. "/call_". date("Ymd_His"). "_$DECTnumber";
  
        if($DebugDECT)
          echo "IAX create file for dialing Number $DECTnumber\n";

        $file = fopen( $CallFile, 'w');

        if($file != false) {
          fputs($file, "Channel: SIP/$DECTnumber@$IAXserver\n");
          fputs($file, "Callerid: Engelserver\n");
          fputs($file, "Extension: s\n");
          fputs($file, "MaxRetries: 1\n");
          fputs($file, "RetryTime: 10\n");
          fputs($file, "SetVar: msg=$Message\n");
          fclose($file);
          system("chmod 777 " . $CallFile);
          system("mv " . $CallFile . " " . $AsteriskOutputDir);
        } else
          echo "error: $CallFile not created";
      }
    } else
      if($DebugDECT)
        echo "IAX is disable\n";
  }

  function DialNumberModem($DECTnumber, $Time) {
    global $AnrufDelay;
  
    // Parameter verarbeiten
    $TimeH = substr($Time, 11, 2);
    $TimeM = substr($Time, 14, 2);
    $TimeM = substr($Time, 14, 2) + $AnrufDelay;

    if($TimeM < 0) {
      $TimeM += 60;
      $TimeH -= 1;
    }

    if($TimeH < 0)
      $TimeH += 24;
  
    if(strlen( $TimeH) == 1)
      $TimeH = "0" . $TimeH;
  
    SetWackeup($DECTnumber, $TimeH, $TimeM);
  }
?>