19 my $wait=600;## 10 mn. wait between sms checking
20 my $dbh=C4
::Context
->dbh;
23 ($res,$ua)=get_sms_auth
();
26 if ($res->{pRetCode
}==200){
27 $result=read_sms
($ua,$res->{pSessionId
});
28 $errorcode=$result->{pErrCode
};
31 kill_sms
($ua,$res->{pSessionId
});
32 warn (error_codes
($res->{pErrCode
}),$res->{pErrcode
}) ;
36 if ($errorcode && $errorcode !=-9005){
37 kill_sms
($ua,$res->{pSessionId
});
38 warn error_codes
($errorcode) ;
41 } elsif ($errorcode ==-9005){
42 print "no more messages to read\n";
47 #Parse the message to a useful hash
48 my @action=parse_message
( $result->{pContent
});
49 ## Log the request in our database;
50 $smsid=write_sms
($action[1], $result->{pContent
},$result->{pMsisdn
});
51 print "message logged\n";
52 ##Now do the service required
53 if (uc($action[0]) eq "RN"){
54 print "dealing request\n";
55 my ($ok,$cardnumber)=C4
::Auth
::checkpw
($dbh,$action[1],$action[2]);
58 $message="Yanlis kullanici/sifre! :Wrong username/password!";
59 my $send=send_message
($result,$message,$smsid);
62 my $item=getiteminformation
(undef,0,$action[3]);
64 my $borrower=getmember
($cardnumber);
65 my $status=renewstatus
(undef,$borrower->{borrowernumber
},$item->{itemnumber
});
67 my $date=renewbook
(undef,$borrower->{borrowernumber
},$item->{itemnumber
});
68 $message="Uzatildi :Renewed ".$item->{barcode
}." : ".$date;
70 $message="Cok erken- yenilenmedi! :Too early-not renewed:".$item->{barcode
};
72 $message="Uzatamazsiniz GERI getiriniz! :No more renewals RETURN the item:".$item->{barcode
};
74 $message="Ayirtildi GERI getiriniz! :Reserved RETURN the item:".$item->{barcode
};
76 $message="Uzatilamaz! :Can not renew:".$item->{barcode
};
79 $message="Yanlis barkot! :Wrong barcode!";
83 $message="Yanlis mesaj formati! :Wrong message! :
84 RN usercardno password barcode";
86 send_message
($result,$message,$smsid);
92 ##Now send the messages waiting in queue
93 my $smssth=$dbh->prepare("SELECT smsid,user_phone,message from sms_messages where date_replied like '0000-00-00%' ");
96 while (my $data=$smssth->fetchrow_hashref){
101 foreach my $user(@phones){
102 print "replying $user->{user_phone}";
103 my $send=send_sms
($ua,$user->{user_phone
},$user->{message
},$res->{pSessionId
});
104 my $reply="--failed\n";
105 if ($send->{pRetCode
}==200){
106 $reply= "--replied\n";
107 mod_sms
($user->{smsid
},"Sent");
114 my ($mes,$message,$smsid)=@_;
115 my $send=send_sms
($ua,$mes->{pMsisdn
},$message,$res->{pSessionId
});
116 if ($send->{pRetCode
}==200){
117 mod_sms
($smsid,$message);
119 my $error=error_codes
($send->{pErrCode
});
120 mod_sms
($smsid,"Not replied error:".$error);