17 my $wait=600;## 10 mn. wait between sms checking
18 my $dbh=C4
::Context
->dbh;
21 ($res,$ua)=get_sms_auth
();
24 if ($res->{pRetCode
}==200){
25 $result=read_sms
($ua,$res->{pSessionId
});
26 $errorcode=$result->{pErrCode
};
29 kill_sms
($ua,$res->{pSessionId
});
30 warn (error_codes
($res->{pErrCode
}),$res->{pErrcode
}) ;
34 if ($errorcode && $errorcode !=-9005){
35 kill_sms
($ua,$res->{pSessionId
});
36 warn error_codes
($errorcode) ;
39 } elsif ($errorcode ==-9005){
40 print "no more messages to read\n";
45 #Parse the message to a useful hash
46 my @action=parse_message
( $result->{pContent
});
47 ## Log the request in our database;
48 $smsid=write_sms
($action[1], $result->{pContent
},$result->{pMsisdn
});
49 print "message logged\n";
50 ##Now do the service required
51 if (uc($action[0]) eq "RN"){
52 print "dealing request\n";
53 my ($ok,$cardnumber)=C4
::Auth
::checkpw
($dbh,$action[1],$action[2]);
56 $message="Yanlis kullanici/sifre! :Wrong username/password!";
57 my $send=send_message
($result,$message,$smsid);
60 my $item=getiteminformation
(undef,0,$action[3]);
62 my $borrower=getmember
($cardnumber);
63 my $status=renewstatus
(undef,$borrower->{borrowernumber
},$item->{itemnumber
});
65 my $date=renewbook
(undef,$borrower->{borrowernumber
},$item->{itemnumber
});
66 $message="Uzatildi :Renewed ".$item->{barcode
}." : ".$date;
68 $message="Cok erken- yenilenmedi! :Too early-not renewed:".$item->{barcode
};
70 $message="Uzatamazsiniz GERI getiriniz! :No more renewals RETURN the item:".$item->{barcode
};
72 $message="Ayirtildi GERI getiriniz! :Reserved RETURN the item:".$item->{barcode
};
74 $message="Uzatilamaz! :Can not renew:".$item->{barcode
};
77 $message="Yanlis barkot! :Wrong barcode!";
81 $message="Yanlis mesaj formati! :Wrong message! :
82 RN usercardno password barcode";
84 send_message
($result,$message,$smsid);
90 ##Now send the messages waiting in queue
91 my $smssth=$dbh->prepare("SELECT smsid,user_phone,message from sms_messages where date_replied like '0000-00-00%' ");
94 while (my $data=$smssth->fetchrow_hashref){
99 foreach my $user(@phones){
100 print "replying $user->{user_phone}";
101 my $send=send_sms
($ua,$user->{user_phone
},$user->{message
},$res->{pSessionId
});
102 my $reply="--failed\n";
103 if ($send->{pRetCode
}==200){
104 $reply= "--replied\n";
105 mod_sms
($user->{smsid
},"Sent");
111 my ($mes,$message,$smsid)=@_;
112 my $send=send_sms
($ua,$mes->{pMsisdn
},$message,$res->{pSessionId
});
113 if ($send->{pRetCode
}==200){
114 mod_sms
($smsid,$message);
116 my $error=error_codes
($send->{pErrCode
});
117 mod_sms
($smsid,"Not replied error:".$error);