$_SERVER['REQUEST_URI'])); $soap->addFunction('deliverSMS'); $soap->handle(file_get_contents("php://input")); /* ************************************************************************ * * Local functions * ************************************************************************ */ function deliverSMS($deviceId, $destinationId, $messageData, $messageType, $messageUDH) { // get the database idenitifier for this device $lances = db_fetch_imsi($deviceId); if( !$lances ) { // device not found return new M2mApiResponse($deviceId, 200, 7011); } // decode message $msg = base64_decode($messageData); // collect the recipients $now = time(); db_store_data("SET @t = FROM_UNIXTIME(" . $now . ")"); // IMSI numbers _should_ be unique, but it is possible that old data still // lingers in the database, even though the administrator should delete // old device (but "should" doesn't necessarily that is happens) foreach( $lances as $lance ) { $alarmnrs = array(); // first, get the regular alarm numbers $data = db_fetch_data( "SELECT alarmnr,servernr " . "FROM zkl_alarmnr " . "WHERE " . "zkl=" . $lance['id'] . " AND " . "(begin IS NULL OR begin <= @t) AND " . "(eind IS NULL OR @t < eind) AND " . "(begindow IS NULL OR einddow IS NULL OR " . // periodic assignments; we'll look at next week when the 'begindow' is already past "@t >= (ADDDATE(@t,IF((begindow - 1) < WEEKDAY(@t), 7 + (begindow - 1) - WEEKDAY(@t), (begindow - 1) - WEEKDAY(@t))) - INTERVAL TIME_TO_SEC(@t) SECOND + INTERVAL TIME_TO_SEC(begintijd) SECOND) " . "AND @t < (ADDDATE(@t,IF((begindow - 1) < WEEKDAY(@t), 7 + (einddow - 1) - WEEKDAY(@t), (einddow - 1) - WEEKDAY(@t))) - INTERVAL TIME_TO_SEC(@t) SECOND + INTERVAL TIME_TO_SEC(eindtijd) SECOND) " . ")" ); if( is_array($data) ) $alarmnrs = array_merge($alarmnrs, $data); // merge users with the correct rights from the project database $data = db_fetch_data( "SELECT alarmnr,0 AS servernr " . "FROM gebruiker " . "WHERE id IN (" . "SELECT gebruiker " . "FROM project_gebruiker,project " . "WHERE " . "project.parent IS NOT NULL AND " . "project_gebruiker.project=project.id AND " . "project.sstatus<>'niet vrijgegeven' AND " . "project.sstatus<>'verzoek tot vrijgeven' AND " . "project.id IN (" . "SELECT project " . "FROM project_zkl " . "WHERE zkl=" . $lance['id'] . ") AND " . "project_gebruiker.rol='schakelen' AND " . "(project_gebruiker.begin IS NULL OR project_gebruiker.begin <= @t) AND " . "(project_gebruiker.eind IS NULL OR @t < project_gebruiker.eind)" . ")" ); if( is_array($data) ) $alarmnrs = array_merge($alarmnrs, $data); // relay the message to the recipients, if there are any if( $alarmnrs ) { // and send it to all recipients foreach( $alarmnrs as $alarmnr ) { DBG("send sms, da: " . $alarmnr['alarmnr'] . ", msg: " . $msg); tcpclient_send_sms($alarmnr['alarmnr'], $msg); } } } return new M2mApiResponse($deviceId, 0, 0); } ?>