api.smszilla.php 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393
  1. <?php
  2. /**
  3. * Powerful SMS sending mechanics there
  4. */
  5. class SMSZilla {
  6. /**
  7. * System alter.ini config as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * Contains all of available tariffs data as tariffname=>data
  14. *
  15. * @var array
  16. */
  17. protected $allTariffs = array();
  18. /**
  19. * Contains available internet tariffs prices
  20. *
  21. * @var array
  22. */
  23. protected $allTariffPrices = array();
  24. /**
  25. * Contains available cities as cityid=>data
  26. *
  27. * @var array
  28. */
  29. protected $allCities = array();
  30. /**
  31. * Contains available swithes as swithid=>data
  32. *
  33. * @var array
  34. */
  35. protected $allSwitches = array();
  36. /**
  37. * Contains all users swithes as login=>switchid
  38. *
  39. * @var array
  40. */
  41. protected $allSwitchesUsers = array();
  42. /**
  43. * Contains data of all available Internet users as login=>data
  44. *
  45. * @var array
  46. */
  47. protected $allUserData = array();
  48. /**
  49. * Contains available tag types as id=>name
  50. *
  51. * @var array
  52. */
  53. protected $allTagTypes = array();
  54. /**
  55. * Contains available templates as id=>data
  56. *
  57. * @var array
  58. */
  59. protected $templates = array();
  60. /**
  61. * Contains available filters
  62. *
  63. * @var array
  64. */
  65. protected $filters = array();
  66. /**
  67. * System message helper placeholder
  68. *
  69. * @var object
  70. */
  71. protected $messages = '';
  72. /**
  73. * Available filter types
  74. *
  75. * @var array
  76. */
  77. protected $filterTypes = array();
  78. /**
  79. * Contains available filters names
  80. *
  81. * @var array
  82. */
  83. protected $filterNames = array();
  84. /**
  85. * Contains available direction names
  86. *
  87. * @var array
  88. */
  89. protected $directionNames = array();
  90. /**
  91. * Current run entities type
  92. *
  93. * @var strings
  94. */
  95. protected $entitiesType = '';
  96. /**
  97. * Contains entities that passed full filter set
  98. *
  99. * @var array
  100. */
  101. protected $filteredEntities = array();
  102. /**
  103. * Contains filtered numbers extracted from filtered entities
  104. *
  105. * @var array
  106. */
  107. protected $filteredNumbers = array();
  108. /**
  109. * FundsFlow object placeholder
  110. *
  111. * @var object
  112. */
  113. protected $fundsFlow = '';
  114. /**
  115. * Contains tags for internet users
  116. *
  117. * @var array
  118. */
  119. protected $inetTags = array();
  120. /**
  121. * Contains tags for UKV users
  122. *
  123. * @var array
  124. */
  125. protected $ukvTags = array();
  126. /**
  127. * Contains all users and their down state as login=>state
  128. *
  129. * @var array
  130. */
  131. protected $downUsers = array();
  132. /**
  133. * Caching flag
  134. *
  135. * @var bool
  136. */
  137. protected $useCache = true;
  138. /**
  139. * SMS abstraction layer placeholder
  140. *
  141. * @var object
  142. */
  143. protected $sms = '';
  144. /**
  145. * Branches object placeholder
  146. *
  147. * @var object
  148. */
  149. protected $branches = '';
  150. /**
  151. * Districts object placeholder
  152. *
  153. * @var object
  154. */
  155. protected $districts = '';
  156. /**
  157. * UKV object placeholder
  158. *
  159. * @var object
  160. */
  161. protected $ukv = '';
  162. /**
  163. * UKV debtors once loading flag
  164. *
  165. * @var bool
  166. */
  167. protected $ukvDebtorsLoaded = false;
  168. /**
  169. * Available UKV debtors
  170. *
  171. * @var string
  172. */
  173. protected $ukvDebtors = array();
  174. /**
  175. * Contains available employee list
  176. *
  177. * @var array
  178. */
  179. protected $employee = array();
  180. /**
  181. * Extended mobiles phonebase usage flag
  182. *
  183. * @var bool
  184. */
  185. protected $useExtMobiles = false;
  186. /**
  187. * Extended mobiles object placeholder
  188. *
  189. * @var object
  190. */
  191. protected $extMobiles = '';
  192. /**
  193. * Contains available internet users paymentIDs
  194. *
  195. * @var array
  196. */
  197. protected $opCustomers = array();
  198. /**
  199. * Contains count of extended mobiles if they are extracted
  200. *
  201. * @var int
  202. */
  203. protected $extMobilesCount = 0;
  204. /**
  205. * Contains filters workflow stats as name=>count
  206. *
  207. * @var array
  208. */
  209. protected $filterStats = array();
  210. /**
  211. * Contains maximum chars limit for one SMS
  212. *
  213. * @var int
  214. */
  215. protected $smsLenLimit = 160;
  216. /**
  217. * Contains country code for target country
  218. *
  219. * @var string
  220. */
  221. protected $countryCode = '380';
  222. /**
  223. * Contains full number length for some country without +
  224. *
  225. * @var int
  226. */
  227. protected $mobileLen = 12;
  228. /**
  229. * Phone normalizer debugging flag
  230. *
  231. * @var bool
  232. */
  233. protected $normalizerDebug = false;
  234. /**
  235. * Contains all numbers lists names as id=>name
  236. *
  237. * @var array
  238. */
  239. protected $allNumListsNames = array();
  240. /**
  241. * Contains all numbers lists numbers records ad id=>numlistdata
  242. *
  243. * @var array
  244. */
  245. protected $allNumListsNumbers = array();
  246. /**
  247. * Contains excludes numbers as mobile=>id
  248. *
  249. * @var array
  250. */
  251. protected $excludeNumbers = array();
  252. /**
  253. * Contains supported macro list for short help
  254. *
  255. * @var array
  256. */
  257. protected $supportedMacro = array();
  258. /**
  259. * System caching object placeholder
  260. *
  261. * @var object
  262. */
  263. protected $cache = '';
  264. /**
  265. * Base module URL
  266. */
  267. const URL_ME = '?module=smszilla';
  268. /**
  269. * Default macro help wiki URL
  270. */
  271. const URL_MACROHELP = 'http://wiki.ubilling.net.ua/doku.php?id=templating&#smszilla';
  272. /**
  273. * Contains SMS Pool saving path
  274. */
  275. const POOL_PATH = './exports/';
  276. /**
  277. * Contains temp files upload path
  278. */
  279. const UPLOAD_PATH = './exports/';
  280. /**
  281. * Creates new SMSZilla instance
  282. *
  283. * @return void
  284. */
  285. public function __construct() {
  286. $this->initMessages();
  287. $this->loadAlter();
  288. $this->setOptions();
  289. $this->initCache();
  290. $this->initSMS();
  291. $this->loadCities();
  292. $this->loadSwitches();
  293. $this->loadUsers();
  294. $this->loadOpCustomers();
  295. $this->loadDownUsers();
  296. $this->initUKV();
  297. $this->initBranches();
  298. $this->initDistricts();
  299. $this->loadTagTypes();
  300. $this->loadTariffs();
  301. $this->loadTemplates();
  302. $this->loadFilters();
  303. $this->loadNumLists();
  304. $this->loadExcludedNumbers();
  305. $this->loadInetTags();
  306. $this->loadUkvTags();
  307. $this->loadEmployee();
  308. }
  309. /**
  310. * Loads system alter config into private property for further usage
  311. *
  312. * @global object $ubillingConfig
  313. *
  314. * @return void
  315. */
  316. protected function loadAlter() {
  317. global $ubillingConfig;
  318. $this->altCfg = $ubillingConfig->getAlter();
  319. }
  320. /**
  321. * Loads all existing Internet users from database
  322. *
  323. * @return void
  324. */
  325. protected function loadUsers() {
  326. if ($this->useCache) {
  327. $this->allUserData = zb_UserGetAllDataCache();
  328. } else {
  329. $this->allUserData = zb_UserGetAllData();
  330. }
  331. }
  332. /**
  333. * Sets up OpenPayz paymentIDs array for further usage
  334. *
  335. * @return void
  336. */
  337. protected function loadOpCustomers() {
  338. if ($this->useCache) {
  339. $this->opCustomers = $this->cache->get('OP_CUSTOMERS', 86400);
  340. if (empty($this->opCustomers)) {
  341. $this->opCustomers = $this->getOpenPayzCustomers();
  342. $this->cache->set('OP_CUSTOMERS', $this->opCustomers, 86400);
  343. }
  344. } else {
  345. $this->opCustomers = $this->getOpenPayzCustomers();
  346. }
  347. }
  348. /**
  349. * Returns list of OpenPayz customers as login=>paymentid
  350. *
  351. * @return array
  352. */
  353. protected function getOpenPayzCustomers() {
  354. $result = array();
  355. if ($this->altCfg['OPENPAYZ_SUPPORT']) {
  356. if ($this->altCfg['OPENPAYZ_REALID']) {
  357. $query = "SELECT `realid`,`virtualid` from `op_customers`";
  358. $allcustomers = simple_queryall($query);
  359. if (!empty($allcustomers)) {
  360. foreach ($allcustomers as $io => $eachcustomer) {
  361. $result[$eachcustomer['realid']] = $eachcustomer['virtualid'];
  362. }
  363. }
  364. } else {
  365. if (!empty($this->allUserData)) {
  366. foreach ($this->allUserData as $io => $each) {
  367. $result[$each['login']] = ip2int($each['ip']);
  368. }
  369. }
  370. }
  371. }
  372. return ($result);
  373. }
  374. /**
  375. * Loads available users down states into separate property
  376. *
  377. * @return void
  378. */
  379. protected function loadDownUsers() {
  380. $query = "SELECT `login`,`Down` from `users`";
  381. $all = simple_queryall($query);
  382. if (!empty($all)) {
  383. foreach ($all as $io => $each) {
  384. $this->downUsers[$each['login']] = $each['Down'];
  385. }
  386. }
  387. }
  388. /**
  389. * Inits UKV object instance
  390. *
  391. * @return void
  392. */
  393. protected function initUKV() {
  394. $this->ukv = new UkvSystem();
  395. }
  396. /**
  397. * Loads existing tariffs from database into protected property for further usage
  398. *
  399. * @return void
  400. */
  401. protected function loadTariffs() {
  402. $query = "SELECT * from `tariffs`";
  403. $all = simple_queryall($query);
  404. if (!empty($all)) {
  405. foreach ($all as $io => $each) {
  406. $this->allTariffs[$each['name']] = $each;
  407. $this->allTariffPrices[$each['name']] = $each['Fee'];
  408. }
  409. }
  410. }
  411. /**
  412. * Loads existing cities from database
  413. *
  414. * @return void
  415. */
  416. protected function loadCities() {
  417. $all = zb_AddressGetCityAllData();
  418. if (!empty($all)) {
  419. foreach ($all as $io => $each) {
  420. $this->allCities[$each['id']] = $each;
  421. }
  422. }
  423. }
  424. /**
  425. * Loads existing switches from database
  426. *
  427. * @return void
  428. */
  429. protected function loadSwitches() {
  430. $query = "SELECT * from `switches` ORDER BY `location`";
  431. $all = simple_queryall($query);
  432. if (!empty($all)) {
  433. foreach ($all as $io => $each) {
  434. $this->allSwitches[$each['id']] = $each;
  435. }
  436. }
  437. $queryUsers = "SELECT * from `switchportassign`";
  438. $allUsers = simple_queryall($queryUsers);
  439. if (!empty($allUsers)) {
  440. foreach ($allUsers as $io => $each) {
  441. $this->allSwitchesUsers[$each['login']] = $each['switchid'];
  442. }
  443. }
  444. }
  445. /**
  446. * Loads existing tag types from database
  447. *
  448. * @return void
  449. */
  450. protected function loadTagTypes() {
  451. $query = "SELECT * from `tagtypes`";
  452. $all = simple_queryall($query);
  453. if (!empty($all)) {
  454. foreach ($all as $io => $each) {
  455. $this->allTagTypes[$each['id']] = $each['tagname'];
  456. }
  457. }
  458. }
  459. /**
  460. * Loads all existing SMS templates from database
  461. *
  462. * @return void
  463. */
  464. protected function loadTemplates() {
  465. $query = "SELECT * from `smz_templates` ORDER BY `id` ASC";
  466. $all = simple_queryall($query);
  467. if (!empty($all)) {
  468. foreach ($all as $io => $each) {
  469. $this->templates[$each['id']] = $each;
  470. }
  471. }
  472. }
  473. /**
  474. * Loads array of all tagtypes set to users
  475. *
  476. * @return void
  477. */
  478. protected function loadInetTags() {
  479. $query = "SELECT * from `tags`";
  480. $all = simple_queryall($query);
  481. if (!empty($all)) {
  482. foreach ($all as $io => $each) {
  483. $this->inetTags[$each['login']][] = $each['tagid'];
  484. }
  485. }
  486. }
  487. /**
  488. * Loads array of all tagtypes set to users
  489. *
  490. * @return void
  491. */
  492. protected function loadUkvTags() {
  493. $query = "SELECT * from `ukv_tags`";
  494. $all = simple_queryall($query);
  495. if (!empty($all)) {
  496. foreach ($all as $io => $each) {
  497. $this->ukvTags[$each['userid']][] = $each['tagtypeid'];
  498. }
  499. }
  500. }
  501. /**
  502. * Loads available employee from database
  503. *
  504. * @return void
  505. */
  506. protected function loadEmployee() {
  507. $query = "SELECT * from `employee`";
  508. $all = simple_queryall($query);
  509. if (!empty($all)) {
  510. foreach ($all as $io => $each) {
  511. $this->employee[$each['id']] = $each;
  512. }
  513. }
  514. }
  515. /**
  516. * Inits system messages helper into protected prop
  517. *
  518. * @return void
  519. */
  520. protected function initMessages() {
  521. $this->messages = new UbillingMessageHelper();
  522. }
  523. /**
  524. * Inits system caching object into protected prop
  525. *
  526. * @return void
  527. */
  528. protected function initCache() {
  529. $this->cache = new UbillingCache();
  530. }
  531. /**
  532. * Inits SMS queue abstraction layer
  533. *
  534. * @return void
  535. */
  536. protected function initSMS() {
  537. $this->sms = new UbillingSMS();
  538. }
  539. /**
  540. * Branches initalization
  541. *
  542. * @return void
  543. */
  544. protected function initBranches() {
  545. $this->branches = new UbillingBranches();
  546. }
  547. /**
  548. * Creates new districts instance
  549. *
  550. * @return void
  551. */
  552. protected function initDistricts() {
  553. $this->districts = new Districts(false);
  554. }
  555. /**
  556. * Inits funds flow object instance
  557. *
  558. * @return void
  559. */
  560. protected function initFundsFlow() {
  561. $this->fundsFlow = new FundsFlow();
  562. $this->fundsFlow->runDataLoders();
  563. }
  564. /**
  565. * Returns user online left days without additional DB queries
  566. * runDataLoaders() must be run once, before usage
  567. *
  568. * @param string $login existing users login
  569. *
  570. * @return int >=0: days left, -1: debt, -2: zero tariff price
  571. */
  572. protected function getUserOnlineLeftDayCount($login) {
  573. $result = 0;
  574. if (empty($this->fundsFlow)) {
  575. $this->initFundsFlow();
  576. }
  577. $onlineLeftCount = $this->fundsFlow->getOnlineLeftCountFast($login);
  578. if ($onlineLeftCount >= 0) {
  579. $result = $onlineLeftCount;
  580. }
  581. return ($result);
  582. }
  583. /**
  584. * Returns user online to date
  585. *
  586. * @param string $login existing users login
  587. *
  588. * @return string
  589. */
  590. protected function getUserOnlineToDate($login) {
  591. $result = date("d.m.Y");
  592. if (empty($this->fundsFlow)) {
  593. $this->initFundsFlow();
  594. }
  595. $daysOnLine = $this->fundsFlow->getOnlineLeftCountFast($login);
  596. if ($daysOnLine >= 0) {
  597. $result = date("d.m.Y", time() + ($daysOnLine * 24 * 60 * 60));
  598. }
  599. return ($result);
  600. }
  601. /**
  602. * Sets all necessary options
  603. *
  604. * @return void
  605. */
  606. protected function setOptions() {
  607. $this->filterTypes = array(
  608. self::URL_ME . '&filters=true&newfilterdirection=none' => __('No'),
  609. self::URL_ME . '&filters=true&newfilterdirection=login' => __('Internet'),
  610. self::URL_ME . '&filters=true&newfilterdirection=ukv' => __('UKV'),
  611. self::URL_ME . '&filters=true&newfilterdirection=employee' => __('Employee'),
  612. self::URL_ME . '&filters=true&newfilterdirection=numlist' => __('Numbers list')
  613. );
  614. $this->filterNames = array(
  615. 'atstart' => 'At begining',
  616. 'filterdirection' => 'SMS direction',
  617. 'filtername' => 'Filter name',
  618. 'filteraddress' => 'Address contains',
  619. 'filterao' => 'User is AlwaysOnline',
  620. 'filterbranch' => 'Branch',
  621. 'filternobranch' => 'No branch',
  622. 'filtercashdays' => 'Balance is enought less than days',
  623. 'filtercashgreater' => 'Balance is greater than',
  624. 'filtercashlesser' => 'Balance is less than',
  625. 'filtercashlesszero' => 'Balance is less than zero',
  626. 'filtercashzero' => 'Balance is zero',
  627. 'filtercreditset' => 'User have credit',
  628. 'filtercashmonth' => 'Balance is not enough for the next month',
  629. 'filtercity' => 'City',
  630. 'filterdown' => 'User is down',
  631. 'filteremployeeactive' => 'Employee is active',
  632. 'filteremployeeappointment' => 'Appointment',
  633. 'filterextmobiles' => 'Use additional mobiles',
  634. 'filterlogin' => 'Login contains',
  635. 'filterip' => 'IP contains',
  636. 'filternotariff' => 'User have no tariff assigned',
  637. 'filtertariffnm' => 'Planned tariff change',
  638. 'filterpassive' => 'User is frozen',
  639. 'filternotpassive' => 'User is not frozen',
  640. 'filteractive' => 'User is active',
  641. 'filtertags' => 'User have tag assigned',
  642. 'filtertariff' => 'User have tariff',
  643. 'filtertariffcontain' => 'User tariff contains',
  644. 'filterukvactive' => 'User is active',
  645. 'filterukvdebtor' => 'Debtors',
  646. 'filterukvtariff' => 'User have tariff',
  647. 'filterrealname' => 'Real Name contains',
  648. 'filternumlist' => 'Numbers list',
  649. 'filternumcontain' => 'Notes contains',
  650. 'filternumnotcontain' => 'Notes not contains',
  651. 'filternumnotouruser' => 'Is not our user',
  652. 'filterdistrict' => 'District',
  653. 'filterswitch' => 'Switch',
  654. );
  655. $this->directionNames = array(
  656. 'login' => 'Internet',
  657. 'ukv' => 'UKV',
  658. 'employee' => 'Employee',
  659. 'numlist' => 'Numbers list'
  660. );
  661. $this->supportedMacro = array(
  662. '{LOGIN}' => __('Login'),
  663. '{REALNAME}' => __('Real Name'),
  664. '{TARIFF}' => __('Tariff'),
  665. '{TARIFFPRICE}' => __('Tariff fee'),
  666. '{TARIFFPERIOD}' => __('Tariff period'),
  667. '{TARIFFNM}' => __('Tariff').' '.__('Next month'),
  668. '{TARIFFNMPRICE}' => __('Tariff fee').' '.__('Next month'),
  669. '{PAYMENTID}' => __('Payment ID'),
  670. '{CREDIT}' => __('Credit'),
  671. '{CASH}' => __('Balance'),
  672. '{LACK}' => __('Balance lack'),
  673. '{ROUNDCASH}' => __('Cash rounded to cents'),
  674. '{IP}' => __('IP'),
  675. '{MAC}' => __('MAC address'),
  676. '{FULLADDRESS}' => __('Full address'),
  677. '{PHONE}' => __('Phone') . ' ' . __('number'),
  678. '{MOBILE}' => __('Mobile') . ' ' . __('number'),
  679. '{CONTRACT}' => __('User contract'),
  680. '{EMAIL}' => __('Email'),
  681. '{CURDATE}' => __('Current date'),
  682. '{PASSWORD}' => __('Password'),
  683. '{USERONLINELEFTDAY}' => __('The remaining number of days to use the service'),
  684. '{USERONLINETODATE}' => __('Tariff period'),
  685. );
  686. if ((isset($this->altCfg['SMSZILLA_MOBILE_LEN'])) and ($this->altCfg['SMSZILLA_COUNTRY_CODE'])) {
  687. //custom countries number settings
  688. $this->countryCode = vf($this->altCfg['SMSZILLA_COUNTRY_CODE'], 3);
  689. $this->mobileLen = $this->altCfg['SMSZILLA_MOBILE_LEN'];
  690. }
  691. //cahing disabling
  692. if ((isset($this->altCfg['SMSZILLA_NOCACHE'])) and ($this->altCfg['SMSZILLA_NOCACHE'])) {
  693. $this->useCache = false;
  694. }
  695. }
  696. /**
  697. * Creates new SMS text template
  698. *
  699. * @param string $name
  700. * @param string $text
  701. *
  702. * @return int
  703. */
  704. public function createTemplate($name, $text) {
  705. $name = mysql_real_escape_string($name);
  706. $text = mysql_real_escape_string($text);
  707. $query = "INSERT INTO `smz_templates` (`id`,`name`,`text`) VALUES ";
  708. $query .= "(NULL,'" . $name . "','" . $text . "');";
  709. nr_query($query);
  710. $newId = simple_get_lastid('smz_templates');
  711. log_register('SMSZILLA TEMPLATE CREATE [' . $newId . ']');
  712. return ($newId);
  713. }
  714. /**
  715. * Deletes existing template
  716. *
  717. * @param int $templateId
  718. *
  719. * @return void/string on error
  720. */
  721. public function deleteTemplate($templateId) {
  722. $templateId = vf($templateId, 3);
  723. $result = '';
  724. if (isset($this->templates[$templateId])) {
  725. $query = "DELETE from `smz_templates` WHERE `id`='" . $templateId . "';";
  726. nr_query($query);
  727. log_register('SMSZILLA TEMPLATE DELETE [' . $templateId . ']');
  728. } else {
  729. $result = __('Something went wrong') . ': TEMPLATE_ID_NOT_EXISTS';
  730. }
  731. return ($result);
  732. }
  733. /**
  734. * Saves changes in existing template
  735. *
  736. * @param int $templateId
  737. * @param string $name
  738. * @param string $text
  739. *
  740. * @return void/string on error
  741. */
  742. public function saveTemplate($templateId, $name, $text) {
  743. $templateId = vf($templateId, 3);
  744. $result = '';
  745. if (isset($this->templates[$templateId])) {
  746. $where = "WHERE `id`='" . $templateId . "'";
  747. simple_update_field('smz_templates', 'name', $name, $where);
  748. simple_update_field('smz_templates', 'text', $text, $where);
  749. log_register('SMSZILLA TEMPLATE CHANGE [' . $templateId . ']');
  750. } else {
  751. $result = __('Something went wrong') . ': TEMPLATE_ID_NOT_EXISTS';
  752. }
  753. return ($result);
  754. }
  755. /**
  756. * Renders new template creation form
  757. *
  758. * @return string
  759. */
  760. public function renderTemplateCreateForm() {
  761. $result = '';
  762. $inputs = wf_TextInput('newtemplatename', __('Name'), '', true, '40');
  763. $inputs .= __('Template') . wf_tag('br');
  764. $inputs .= wf_TextArea('newtemplatetext', '', '', true, '45x5');
  765. $inputs .= wf_Submit(__('Create'));
  766. $form = wf_Form(self::URL_ME . '&templates=true', 'POST', $inputs, 'glamour');
  767. $cells = wf_TableCell($form, '50%', '', 'valign="top"');
  768. $cells .= wf_TableCell($this->renderMacroHelp(), '', '', 'valign="top"');
  769. $rows = wf_TableRow($cells);
  770. $result .= wf_TableBody($rows, '100%', 0);
  771. return ($result);
  772. }
  773. /**
  774. * Renders supported templating macro short help
  775. *
  776. * @return string
  777. */
  778. protected function renderMacroHelp() {
  779. $result = '';
  780. if (!empty($this->supportedMacro)) {
  781. $result .= wf_tag('strong') . __('Available macroses') . ':' . wf_tag('strong', true) . wf_delimiter();
  782. foreach ($this->supportedMacro as $io => $each) {
  783. $result .= wf_tag('b') . $io . wf_tag('b', true) . ' - ' . $each . wf_tag('br');
  784. }
  785. $result .= wf_tag('br') . wf_Link(self::URL_MACROHELP, __('Details'), false, '', 'target="_BLANK"');
  786. }
  787. return ($result);
  788. }
  789. /**
  790. * Renders existing template edit form
  791. *
  792. * @param int $templateId
  793. *
  794. * @return string
  795. */
  796. public function renderTemplateEditForm($templateId) {
  797. $templateId = vf($templateId, 3);
  798. $result = '';
  799. if (isset($this->templates[$templateId])) {
  800. $templateData = $this->templates[$templateId];
  801. $inputs = wf_HiddenInput('edittemplateid', $templateId);
  802. $inputs .= wf_TextInput('edittemplatename', __('Name'), $templateData['name'], true, '40');
  803. $inputs .= __('Template') . wf_tag('br');
  804. $inputs .= wf_TextArea('edittemplatetext', '', $templateData['text'], true, '45x5');
  805. $templateSize = mb_strlen($templateData['text'], 'utf-8');
  806. $inputs .= __('Text size') . ' ~' . $templateSize . wf_tag('br');
  807. $inputs .= wf_Submit(__('Save'));
  808. $form = wf_Form(self::URL_ME . '&templates=true&edittemplate=' . $templateId, 'POST', $inputs, 'glamour');
  809. $cells = wf_TableCell($form, '50%', '', 'valign="top"');
  810. $cells .= wf_TableCell($this->renderMacroHelp(), '', '', 'valign="top"');
  811. $rows = wf_TableRow($cells);
  812. $result .= wf_TableBody($rows, '100%', 0);
  813. } else {
  814. $result = $this->messages->getStyledMessage(__('Something went wrong') . ': TEMPLATE_ID_NOT_EXISTS', 'error');
  815. }
  816. return ($result);
  817. }
  818. /**
  819. * Renders existing templates list with some controls
  820. *
  821. * @return string
  822. */
  823. public function renderTemplatesList() {
  824. $result = '';
  825. if (!empty($this->templates)) {
  826. $cells = wf_TableCell(__('ID'));
  827. $cells .= wf_TableCell(__('Name'));
  828. $cells .= wf_TableCell(__('Text'));
  829. $cells .= wf_TableCell(__('Actions'));
  830. $rows = wf_TableRow($cells, 'row1');
  831. foreach ($this->templates as $io => $each) {
  832. $cells = wf_TableCell($each['id']);
  833. $cells .= wf_TableCell($each['name']);
  834. $cells .= wf_TableCell($each['text']);
  835. $actLinks = wf_JSAlert(self::URL_ME . '&templates=true&deletetemplate=' . $each['id'], web_delete_icon(), $this->messages->getDeleteAlert()) . ' ';
  836. $actLinks .= wf_JSAlert(self::URL_ME . '&templates=true&edittemplate=' . $each['id'], web_edit_icon(), $this->messages->getEditAlert());
  837. $cells .= wf_TableCell($actLinks);
  838. $rows .= wf_TableRow($cells, 'row5');
  839. }
  840. $result = wf_TableBody($rows, '100%', 0, 'sortable');
  841. } else {
  842. $result = $this->messages->getStyledMessage(__('No existing templates available'), 'warning');
  843. }
  844. return ($result);
  845. }
  846. /**
  847. * Loads existing numberlists from database
  848. *
  849. * @return void
  850. */
  851. protected function loadNumLists() {
  852. $query = "SELECT * from `smz_lists`";
  853. $all = simple_queryall($query);
  854. if (!empty($all)) {
  855. foreach ($all as $io => $each) {
  856. $this->allNumListsNames[$each['id']] = $each['name'];
  857. }
  858. }
  859. $query = "SELECT * from `smz_nums`";
  860. $all = simple_queryall($query);
  861. if (!empty($all)) {
  862. foreach ($all as $io => $each) {
  863. $this->allNumListsNumbers[$each['id']] = $each;
  864. }
  865. }
  866. }
  867. /**
  868. * Loads existing excluded numbers from database
  869. *
  870. * @return void
  871. */
  872. protected function loadExcludedNumbers() {
  873. $query = "SELECT * from `smz_excl`";
  874. $all = simple_queryall($query);
  875. if (!empty($all)) {
  876. foreach ($all as $io => $each) {
  877. $this->excludeNumbers[$each['mobile']] = $each['id'];
  878. }
  879. }
  880. }
  881. /**
  882. * Creates new mobile exclude in database
  883. *
  884. * @param string $mobileNum
  885. *
  886. * @return void
  887. */
  888. public function createExclude($mobileNum) {
  889. $mobileNumF = mysql_real_escape_string($mobileNum);
  890. if (!empty($mobileNumF)) {
  891. if (!isset($this->excludeNumbers[$mobileNumF])) {
  892. $query = "INSERT INTO `smz_excl` (`id`,`mobile`) VALUES ";
  893. $query .= "(NULL,'" . $mobileNumF . "');";
  894. nr_query($query);
  895. $newId = simple_get_lastid('smz_excl');
  896. log_register('SMSZILLA EXCLUDE CREATE [' . $newId . '] `' . $mobileNum . '`');
  897. }
  898. }
  899. }
  900. /**
  901. * Deletes existing excluded number from database
  902. *
  903. * @param int $excludeId
  904. *
  905. * @return void
  906. */
  907. public function deleteExlude($excludeId) {
  908. $excludeId = vf($excludeId, 3);
  909. $query = "DELETE from `smz_excl` WHERE `id`='" . $excludeId . "';";
  910. nr_query($query);
  911. log_register('SMSZILLA EXCLUDE DELETE [' . $excludeId . ']');
  912. }
  913. /**
  914. * Renders numlist creation form
  915. *
  916. * @return string
  917. */
  918. public function renderNumListCreateForm() {
  919. $result = '';
  920. $inputs = wf_TextInput('newnumlistname', __('Name'), '', false, 20) . ' ';
  921. $inputs .= wf_Submit(__('Create'));
  922. $result .= wf_Form(self::URL_ME . '&numlists=true', 'POST', $inputs, 'glamour');
  923. return ($result);
  924. }
  925. /**
  926. * Renders numeric list editing form
  927. *
  928. * @param int $numlistId
  929. *
  930. * @return string
  931. */
  932. public function renderNumListEditForm($numlistId) {
  933. $result = '';
  934. $numlistId = vf($numlistId, 3);
  935. if (isset($this->allNumListsNames[$numlistId])) {
  936. $inputs = wf_HiddenInput('editnumlistid', $numlistId);
  937. $inputs .= wf_TextInput('editnumlistname', __('Name'), $this->allNumListsNames[$numlistId], true, '20');
  938. $inputs .= wf_Submit(__('Save'));
  939. $result .= wf_Form(self::URL_ME . '&numlists=true', 'POST', $inputs, 'glamour');
  940. }
  941. return ($result);
  942. }
  943. /**
  944. * Saves numlist name changes into database
  945. *
  946. * @param int $numlistId
  947. * @param string $numlistName
  948. *
  949. * @return void
  950. */
  951. public function saveNumList($numlistId, $numlistName) {
  952. $numlistId = vf($numlistId, 3);
  953. if (isset($this->allNumListsNames[$numlistId])) {
  954. simple_update_field('smz_lists', 'name', $numlistName, "WHERE `id`='" . $numlistId . "';");
  955. log_register('SMSZILLA NUMLIST CHANGE [' . $numlistId . '] `' . $numlistName . '`');
  956. }
  957. }
  958. /**
  959. * Renders numlist list with some controls
  960. *
  961. * @return string
  962. */
  963. public function renderNumListsList() {
  964. $result = '';
  965. if (!empty($this->allNumListsNames)) {
  966. $cells = wf_TableCell(__('ID'));
  967. $cells .= wf_TableCell(__('Name'));
  968. $cells .= wf_TableCell(__('Actions'));
  969. $rows = wf_TableRow($cells, 'row1');
  970. foreach ($this->allNumListsNames as $io => $each) {
  971. $cells = wf_TableCell($io);
  972. $cells .= wf_TableCell($each);
  973. $actLinks = wf_JSAlert(self::URL_ME . '&numlists=true&deletenumlistid=' . $io, web_delete_icon(), $this->messages->getDeleteAlert()) . ' ';
  974. $actLinks .= wf_JSAlert(self::URL_ME . '&numlists=true&editnumlistid=' . $io, web_edit_icon(), $this->messages->getEditAlert());
  975. $cells .= wf_TableCell($actLinks);
  976. $rows .= wf_TableRow($cells, 'row3');
  977. }
  978. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  979. } else {
  980. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'info');
  981. }
  982. $result .= wf_tag('br');
  983. $result .= $this->renderNumListCreateForm();
  984. return ($result);
  985. }
  986. /**
  987. * Creates new numbers list in database
  988. *
  989. * @param string $name
  990. *
  991. * @return void/string on error
  992. */
  993. public function createNumList($name) {
  994. $result = '';
  995. $nameF = mysql_real_escape_string($name);
  996. if (!empty($nameF)) {
  997. $query = "INSERT INTO `smz_lists` (`id`,`name`) VALUES ";
  998. $query .= "(NULL,'" . $nameF . "');";
  999. nr_query($query);
  1000. $newId = simple_get_lastid('smz_lists');
  1001. log_register('SMSZILLA NUMLIST CREATE [' . $newId . '] `' . $name . '`');
  1002. } else {
  1003. $result = __('Oh no') . ': EX_EMPTY_NUMLIST_NAME';
  1004. }
  1005. }
  1006. /**
  1007. * Creates new numbers list in database
  1008. *
  1009. * @param string $name
  1010. *
  1011. * @return void/string on error
  1012. */
  1013. public function deleteNumList($numlistId) {
  1014. $numlistId = vf($numlistId, 3);
  1015. $result = '';
  1016. if (isset($this->allNumListsNames[$numlistId])) {
  1017. $query = "DELETE FROM `smz_lists` WHERE `id`='" . $numlistId . "';";
  1018. nr_query($query);
  1019. log_register('SMSZILLA NUMLIST DELETE [' . $numlistId . ']');
  1020. $query = "DELETE FROM `smz_nums` WHERE `numid`='" . $numlistId . "';";
  1021. nr_query($query);
  1022. log_register('SMSZILLA NUMLIST FLUSH [' . $numlistId . ']');
  1023. } else {
  1024. $result = __('Oh no') . ': EX_NUMLISTID_NOT_EXISTS';
  1025. }
  1026. return ($result);
  1027. }
  1028. /**
  1029. * Renders form for single number addition to number list
  1030. *
  1031. * @return string
  1032. */
  1033. public function createNumListNumberForm() {
  1034. $result = '';
  1035. if (!empty($this->allNumListsNames)) {
  1036. $inputs = wf_Selector('newsinglenumlistid', $this->allNumListsNames, __('Numbers list'), '', false);
  1037. $inputs .= wf_TextInput('newsinglenumlistmobile', __('Mobile'), '', false, 15, 'mobile');
  1038. $inputs .= wf_TextInput('newsinglenumlistnotes', __('Notes'), '', false, 30);
  1039. $inputs .= wf_Submit(__('Add'));
  1040. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  1041. }
  1042. return ($result);
  1043. }
  1044. /**
  1045. * Renders upload form for some mobile data
  1046. *
  1047. * @return string
  1048. */
  1049. public function uploadNumListNumbersForm() {
  1050. $result = '';
  1051. if (!empty($this->allNumListsNames)) {
  1052. $result .= wf_tag('form', false, 'glamour', 'action="" enctype="multipart/form-data" method="POST"');
  1053. $result .= wf_HiddenInput('uploadnumlistnumbers', 'true');
  1054. $result .= wf_Selector('newnumslistid', $this->allNumListsNames, __('Numbers list'), '', false);
  1055. $result .= wf_tag('input', false, '', 'id="fileselector" type="file" name="smznumlistcsv"');
  1056. $result .= wf_Submit('Upload');
  1057. $result .= wf_tag('form', true);
  1058. $result .= wf_CleanDiv();
  1059. } else {
  1060. $result .= $this->messages->getStyledMessage(__('No existing numbers lists available'), 'warning');
  1061. }
  1062. return ($result);
  1063. }
  1064. /**
  1065. * Creates new numlist phone record in database
  1066. *
  1067. * @param int $numlistId
  1068. * @param string $mobile
  1069. * @param string $notes
  1070. *
  1071. * @return void/string on error
  1072. */
  1073. public function createNumlistSingleNumber($numlistId, $mobile, $notes) {
  1074. $result = '';
  1075. $numlistId = vf($numlistId, 3);
  1076. if (isset($this->allNumListsNames[$numlistId])) {
  1077. $mobileF = mysql_real_escape_string($mobile);
  1078. $notes = mysql_real_escape_string($notes);
  1079. $query = "INSERT INTO `smz_nums` (`id`,`numid`,`mobile`,`notes`) VALUES ";
  1080. $query .= "(NULL, '" . $numlistId . "','" . $mobileF . "','" . $notes . "');";
  1081. nr_query($query);
  1082. $newId = simple_get_lastid('smz_nums');
  1083. log_register('SMSZILLA NUMLISTNUM CREATE [' . $numlistId . '] MOBILE `' . $mobile . '`');
  1084. } else {
  1085. $result .= __('Oh no') . ': EX_NUMLISTID_NOT_EXISTS';
  1086. }
  1087. return ($result);
  1088. }
  1089. /**
  1090. * Cleanups numlist from existing users phones
  1091. *
  1092. * @param int $numlistId
  1093. *
  1094. * @return void/string on error
  1095. */
  1096. public function cleanupNumlist($numlistId) {
  1097. $result = '';
  1098. $numlistId = vf($numlistId, 3);
  1099. $cleanupUserMobiles = array(); // contains temp array for deletion as mobile=>login
  1100. $extMobilesFlag = ($this->altCfg['MOBILES_EXT']) ? true : false;
  1101. if (wf_CheckPost(array('cleanupnumlistid', 'cleanupagree'))) {
  1102. if (!empty($this->allUserData)) {
  1103. if ($extMobilesFlag) {
  1104. $this->extMobiles = new MobilesExt();
  1105. }
  1106. foreach ($this->allUserData as $io => $each) {
  1107. $userLogin = $each['login'];
  1108. $primaryMobile = $this->normalizePhoneFormat($each['mobile']);
  1109. if (!empty($primaryMobile)) {
  1110. $cleanupUserMobiles[$primaryMobile] = $userLogin;
  1111. }
  1112. if ($this->extMobiles) {
  1113. $userExtMobiles = $this->extMobiles->getUserMobiles($userLogin);
  1114. if (!empty($userExtMobiles)) {
  1115. foreach ($userExtMobiles as $ia => $eachExt) {
  1116. $additionalMobile = $this->normalizePhoneFormat($eachExt['mobile']);
  1117. if (!empty($additionalMobile)) {
  1118. $cleanupUserMobiles[$additionalMobile] = $userLogin;
  1119. }
  1120. }
  1121. }
  1122. }
  1123. }
  1124. }
  1125. if ((!empty($cleanupUserMobiles)) and (!empty($this->allNumListsNumbers))) {
  1126. foreach ($this->allNumListsNumbers as $io => $each) {
  1127. if ($each['numid'] == $numlistId) {
  1128. $numlistNumber = $each['mobile'];
  1129. $numlistNumber = $this->normalizePhoneFormat($numlistNumber);
  1130. if (isset($cleanupUserMobiles[$numlistNumber])) {
  1131. $this->deleteNumlistNumber($each['id']);
  1132. }
  1133. }
  1134. }
  1135. }
  1136. } else {
  1137. $result .= __('You are not mentally prepared for this');
  1138. }
  1139. return ($result);
  1140. }
  1141. /**
  1142. * Renders numlist cleanup form
  1143. *
  1144. * @return string
  1145. */
  1146. public function renderCleanupNumlistForm() {
  1147. $result = '';
  1148. if (!empty($this->allNumListsNames)) {
  1149. $inputs = wf_Selector('cleanupnumlistid', $this->allNumListsNames, __('Numbers list'), '', false) . ' ';
  1150. $inputs .= wf_CheckInput('cleanupagree', __('I`m ready'), false, false) . ' ';
  1151. $inputs .= wf_Submit(__('Cleanup'));
  1152. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  1153. } else {
  1154. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'info');
  1155. }
  1156. return ($result);
  1157. }
  1158. /**
  1159. * Catches file upload
  1160. *
  1161. * @return string
  1162. */
  1163. public function catchFileUpload() {
  1164. $result = '';
  1165. $numListId = $_POST['newnumslistid'];
  1166. $allowedExtensions = array("csv", "txt");
  1167. $fileAccepted = true;
  1168. foreach ($_FILES as $file) {
  1169. if ($file['tmp_name'] > '') {
  1170. if (@!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) {
  1171. $fileAccepted = false;
  1172. }
  1173. }
  1174. }
  1175. if ($fileAccepted) {
  1176. $newFilename = zb_rand_string(6) . '_smz_nums.dat';
  1177. $newSavePath = self::UPLOAD_PATH . $newFilename;
  1178. move_uploaded_file($_FILES['smznumlistcsv']['tmp_name'], $newSavePath);
  1179. if (file_exists($newSavePath)) {
  1180. $uploadResult = $this->messages->getStyledMessage(__('Upload complete'), 'success');
  1181. $result = $newFilename;
  1182. } else {
  1183. $uploadResult = $this->messages->getStyledMessage(__('Upload failed'), 'error');
  1184. }
  1185. } else {
  1186. $uploadResult = $this->messages->getStyledMessage(__('Upload failed') . ': EX_WRONG_EXTENSION', 'error');
  1187. }
  1188. show_window('', $uploadResult);
  1189. if ($result) {
  1190. $this->preprocessNumList($result, $numListId);
  1191. }
  1192. return ($result);
  1193. }
  1194. /**
  1195. * Opens and inserts into database some numbers list data
  1196. *
  1197. * @param string $fileName
  1198. * @param int $numlistId
  1199. *
  1200. * @return string
  1201. */
  1202. protected function preprocessNumList($fileName, $numlistId) {
  1203. $result = '';
  1204. $numlistId = vf($numlistId, 3);
  1205. $count = 0;
  1206. if (file_exists(self::UPLOAD_PATH . $fileName)) {
  1207. $fileRawData = file_get_contents(self::UPLOAD_PATH . $fileName);
  1208. if (!empty($fileRawData)) {
  1209. $fileRawData = explodeRows($fileRawData);
  1210. if (!empty($fileRawData)) {
  1211. foreach ($fileRawData as $io => $line) {
  1212. if (!empty($line)) {
  1213. $lineExploded = explode(';', $line);
  1214. $newNumber = $this->normalizePhoneFormat($lineExploded[0]);
  1215. $newNumber = mysql_real_escape_string($newNumber);
  1216. $newNotes = '';
  1217. unset($lineExploded[0]);
  1218. foreach ($lineExploded as $ia => $nts) {
  1219. $newNotes .= $nts . ' ';
  1220. }
  1221. $newNotes = trim($newNotes);
  1222. $newNotes = mysql_real_escape_string($newNotes);
  1223. $query = "INSERT INTO `smz_nums` (`id`,`numid`,`mobile`,`notes`) VALUES ";
  1224. $query .= "(NULL,'" . $numlistId . "','" . $newNumber . "','" . $newNotes . "');";
  1225. nr_query($query);
  1226. $count++;
  1227. }
  1228. }
  1229. log_register('SMSZILLA NUMLISTNUM UPLOAD [' . $numlistId . '] COUNT `' . $count . '`');
  1230. }
  1231. }
  1232. }
  1233. return ($result);
  1234. }
  1235. /**
  1236. * Renders numbers list mobiles container
  1237. *
  1238. * @return string
  1239. */
  1240. public function renderNumsContainer() {
  1241. $result = '';
  1242. $columns = array('ID', 'Numbers list', 'Mobile', 'Notes', 'Actions');
  1243. $opts = '"dom": \'<"F"lfB>rti<"F"ps>\', buttons: [\'csv\', \'excel\', \'pdf\']';
  1244. $result .= wf_JqDtLoader($columns, self::URL_ME . '&numlists=true&ajnums=true', false, __('Mobile'), 100, $opts);
  1245. return ($result);
  1246. }
  1247. /**
  1248. * Renders numbers list ajax data tables reply
  1249. *
  1250. * @return void
  1251. */
  1252. public function ajaxNumbersReply() {
  1253. $json = new wf_JqDtHelper();
  1254. if (!empty($this->allNumListsNumbers)) {
  1255. foreach ($this->allNumListsNumbers as $io => $each) {
  1256. $data[] = $each['id'];
  1257. $data[] = @$this->allNumListsNames[$each['numid']];
  1258. $data[] = $each['mobile'];
  1259. $data[] = $each['notes'];
  1260. $actLinks = wf_JSAlertStyled(self::URL_ME . '&numlists=true&deletenumid=' . $each['id'], web_delete_icon(), $this->messages->getDeleteAlert());
  1261. $data[] = $actLinks;
  1262. $json->addRow($data);
  1263. unset($data);
  1264. }
  1265. }
  1266. $json->getJson();
  1267. }
  1268. /**
  1269. * Delete some single numlist mobile number from database
  1270. *
  1271. * @param int $numId
  1272. *
  1273. * @return void
  1274. */
  1275. public function deleteNumlistNumber($numId) {
  1276. $numId = vf($numId, 3);
  1277. if (isset($this->allNumListsNumbers[$numId])) {
  1278. $query = "DELETE from `smz_nums` WHERE `id`='" . $numId . "';";
  1279. nr_query($query);
  1280. log_register('SMSZILLA NUMLISTNUM DELETE [' . $numId . ']');
  1281. }
  1282. }
  1283. /**
  1284. * Renders existing excludes list with some controls
  1285. *
  1286. * @return string
  1287. */
  1288. public function renderExcludeNumsList() {
  1289. $result = '';
  1290. if (!empty($this->excludeNumbers)) {
  1291. $cells = wf_TableCell(__('ID'));
  1292. $cells .= wf_TableCell(__('Mobile'));
  1293. $cells .= wf_TableCell(__('Actions'));
  1294. $rows = wf_TableRow($cells, 'row1');
  1295. foreach ($this->excludeNumbers as $io => $each) {
  1296. $cells = wf_TableCell($each);
  1297. $cells .= wf_TableCell($io);
  1298. $actLinks = wf_JSAlertStyled(self::URL_ME . '&excludes=true&deleteexclnumid=' . $each, web_delete_icon(), $this->messages->getDeleteAlert());
  1299. $cells .= wf_TableCell($actLinks);
  1300. $rows .= wf_TableRow($cells, 'row5');
  1301. }
  1302. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  1303. } else {
  1304. $result .= $this->messages->getStyledMessage(__('Oh no') . ': ' . __('Nothing to show'), 'warning');
  1305. }
  1306. return ($result);
  1307. }
  1308. /**
  1309. * Renders exclude number creation form
  1310. *
  1311. * @return string
  1312. */
  1313. public function renderExcludeCreateForm() {
  1314. $result = '';
  1315. $inputs = wf_TextInput('newexcludenumber', __('Mobile'), '', false, '20', 'mobile');
  1316. $inputs .= wf_Submit(__('Create'));
  1317. $result .= wf_Form(self::URL_ME . '&excludes=true', 'POST', $inputs, 'glamour');
  1318. return ($result);
  1319. }
  1320. /**
  1321. * Renders default module control panel
  1322. *
  1323. * @return string
  1324. */
  1325. public function panel() {
  1326. $result = '';
  1327. $result .= wf_Link(self::URL_ME . '&sending=true', wf_img('skins/icon_sms_micro.gif') . ' ' . __('SMS sending'), false, 'ubButton') . ' ';
  1328. $result .= wf_Link(self::URL_ME . '&templates=true', wf_img('skins/icon_template.png') . ' ' . __('Templates'), false, 'ubButton') . ' ';
  1329. $result .= wf_Link(self::URL_ME . '&filters=true', web_icon_extended() . ' ' . __('Filters'), false, 'ubButton') . ' ';
  1330. $result .= wf_Link(self::URL_ME . '&numlists=true', wf_img('skins/icon_mobile.gif') . ' ' . __('Numbers lists'), false, 'ubButton') . ' ';
  1331. $result .= wf_Link(self::URL_ME . '&excludes=true', wf_img('skins/icon_deleterow.png') . ' ' . __('Excludes'), !$this->sms->smsRoutingFlag, 'ubButton') . ' ';
  1332. if ($this->sms->smsRoutingFlag) {
  1333. $cacheLnkId = wf_InputId();
  1334. $addServiceJS = wf_JSAjaxModalOpener(self::URL_ME, array('action' => 'RefreshBindingsCache'), $cacheLnkId, true);
  1335. $result .= wf_Link('#', wf_img('skins/refresh.gif') . ' ' . __('Refresh SMS services bindings cache'), true, 'ubButton', 'id="' . $cacheLnkId . '"') . $addServiceJS;
  1336. }
  1337. if (wf_CheckGet(array('action')) and $_GET['action'] == 'RefreshBindingsCache') {
  1338. $this->sms->smsDirections->refreshCacheForced();
  1339. $messageWindow = $this->messages->getStyledMessage(__('SMS services cache bindings updated succesfuly'), 'success', 'style="margin: auto 0; padding: 10px 3px; width: 100%;"');
  1340. die(wf_modalAutoForm('', $messageWindow, $_GET['modalWindowId'], '', true));
  1341. }
  1342. if (wf_CheckGet(array('templates'))) {
  1343. $result .= wf_tag('br');
  1344. if (wf_CheckGet(array('edittemplate'))) {
  1345. $result .= wf_BackLink(self::URL_ME . '&templates=true') . ' ';
  1346. } else {
  1347. $result .= wf_modalAuto(web_icon_create() . ' ' . __('Create new template'), __('Create new template'), $this->renderTemplateCreateForm(), 'ubButton');
  1348. }
  1349. }
  1350. return ($result);
  1351. }
  1352. /**
  1353. * Renders filter creation form
  1354. *
  1355. * @return string
  1356. */
  1357. public function renderFilterCreateForm() {
  1358. $result = '';
  1359. $result .= wf_AjaxLoader();
  1360. $inputs = wf_AjaxContainer('inputscontainer', '', $this->catchAjRequest(true));
  1361. $result .= wf_Form(self::URL_ME . '&filters=true', 'POST', $inputs, 'glamour');
  1362. return ($result);
  1363. }
  1364. /**
  1365. * Returns ajax inputs of required type
  1366. *
  1367. * @return string
  1368. */
  1369. public function catchAjRequest($remote = false) {
  1370. $inputs = '';
  1371. $direction = 'none';
  1372. if (wf_CheckGet(array('newfilterdirection'))) {
  1373. $direction = vf($_GET['newfilterdirection']);
  1374. }
  1375. $citiesParams = array('' => __('Any'));
  1376. if (!empty($this->allCities)) {
  1377. foreach ($this->allCities as $io => $each) {
  1378. $citiesParams[$each['cityname']] = $each['cityname'];
  1379. }
  1380. }
  1381. $tagsParams = array('' => __('-'));
  1382. if (!empty($this->allTagTypes)) {
  1383. foreach ($this->allTagTypes as $io => $each) {
  1384. $tagsParams[$io] = $each;
  1385. }
  1386. }
  1387. $tariffParams = array('' => __('Any'));
  1388. if (!empty($this->allTariffs)) {
  1389. foreach ($this->allTariffs as $io => $each) {
  1390. $tariffParams[$each['name']] = $each['name'];
  1391. }
  1392. }
  1393. $ukvTariffParams = array('' => __('Any'));
  1394. $ukvfTariffsAvail = $this->ukv->getTariffs();
  1395. if (!empty($ukvfTariffsAvail)) {
  1396. foreach ($ukvfTariffsAvail as $io => $each) {
  1397. $ukvTariffParams[$each['id']] = $each['tariffname'];
  1398. }
  1399. }
  1400. $numListParams = $this->allNumListsNames;
  1401. $branchParams = array('' => __('Any'));
  1402. $availBranches = $this->branches->getBranchesAvailable();
  1403. if (!empty($availBranches)) {
  1404. foreach ($availBranches as $io => $each) {
  1405. $branchParams[$io] = $each;
  1406. }
  1407. }
  1408. $switchesParams = array('' => __('Any'));
  1409. if (!empty($this->allSwitches)) {
  1410. foreach ($this->allSwitches as $io => $each) {
  1411. $switchesParams[$each['id']] = $each['ip'] . ' - ' . $each['location'];
  1412. }
  1413. }
  1414. $districtsParams = array('' => __('Any'));
  1415. $districtsParams += $this->districts->getDistricts();
  1416. $inputs .= wf_AjaxSelectorAC('inputscontainer', $this->filterTypes, __('SMS direction'), self::URL_ME . '&filters=true&newfilterdirection=' . $direction, true);
  1417. $inputs .= wf_tag('br');
  1418. if ($direction != 'none') {
  1419. $inputs .= wf_HiddenInput('newfilterdirection', $direction);
  1420. $inputs .= wf_TextInput('newfiltername', __('Filter name') . wf_tag('sup') . '*' . wf_tag('sup', true), '', true, '30');
  1421. if (($direction == 'login') or ($direction == 'ukv')) {
  1422. $inputs .= wf_Selector('newfiltercity', $citiesParams, __('City'), '', true, false);
  1423. $inputs .= wf_TextInput('newfilteraddress', __('Address contains'), '', true, '40');
  1424. }
  1425. if (($direction == 'login') or ($direction == 'ukv') or ($direction == 'employee')) {
  1426. $inputs .= wf_TextInput('newfilterrealname', __('Real Name') . ' ' . __('contains'), '', true, '30');
  1427. }
  1428. if (($direction == 'login')) {
  1429. $inputs .= wf_TextInput('newfilterlogin', __('Login contains'), '', true, '20');
  1430. $inputs .= wf_TextInput('newfilterip', __('IP contains'), '', true, '20');
  1431. $inputs .= wf_Selector('newfilterswitch', $switchesParams, __('Switch'), '', true, false);
  1432. $inputs .= wf_CheckInput('newfiltercashmonth', __('Balance is not enough for the next month'), true, false);
  1433. $inputs .= wf_TextInput('newfiltercashdays', __('Balance is enought less than days'), '', true, '5');
  1434. }
  1435. if ($direction == 'ukv') {
  1436. $inputs .= wf_Selector('newfilterukvtariff', $ukvTariffParams, __('User have tariff'), '', true, false);
  1437. $inputs .= wf_CheckInput('newfilterukvdebtor', __('Debtors'), true, false);
  1438. $inputs .= wf_CheckInput('newfilterukvactive', __('User is active'), true, false);
  1439. }
  1440. if (($direction == 'login') or ($direction == 'ukv')) {
  1441. $inputs .= wf_TextInput('newfiltercashgreater', __('Balance is greater than'), '', true, '5');
  1442. $inputs .= wf_TextInput('newfiltercashlesser', __('Balance is less than'), '', true, '5');
  1443. $inputs .= wf_CheckInput('newfiltercashlesszero', __('Balance is less than zero'), true, false);
  1444. $inputs .= wf_CheckInput('newfiltercashzero', __('Balance is zero'), true, false);
  1445. $inputs .= wf_Selector('newfiltertags', $tagsParams, __('User have tag assigned'), '', true, false);
  1446. }
  1447. if (($direction == 'login')) {
  1448. $inputs .= wf_CheckInput('newfiltercreditset', __('User have credit'), true, false);
  1449. $inputs .= wf_CheckInput('newfilterpassive', __('User is frozen'), true, false);
  1450. $inputs .= wf_CheckInput('newfilternotpassive', __('User is not frozen'), true, false);
  1451. $inputs .= wf_CheckInput('newfilteractive', __('User is active'), true, false);
  1452. $inputs .= wf_CheckInput('newfilterdown', __('User is down'), true, false);
  1453. $inputs .= wf_CheckInput('newfilterao', __('User is AlwaysOnline'), true, true);
  1454. $inputs .= wf_Selector('newfiltertariff', $tariffParams, __('User have tariff'), '', true, false);
  1455. $inputs .= wf_TextInput('newfiltertariffcontain', __('User tariff contains'), '', true, '15');
  1456. $inputs .= wf_CheckInput('newfilternotariff', __('User have no tariff assigned'), true, false);
  1457. $inputs .= wf_CheckInput('newfiltertariffnm', __('Planned tariff change'), true, false);
  1458. $inputs .= wf_CheckInput('newfilterextmobiles', __('Use additional mobiles'), true, false);
  1459. $inputs .= wf_Selector('newfilterbranch', $branchParams, __('Branch'), '', true, false);
  1460. $inputs .= wf_CheckInput('newfilternobranch', __('No branch'), true, false);
  1461. $inputs .= wf_Selector('newfilterdistrict', $districtsParams, __('District'), '', true, false);
  1462. }
  1463. if (($direction == 'numlist')) {
  1464. $inputs .= wf_Selector('newfilternumlist', $numListParams, __('Numbers list'), '', true, false);
  1465. $inputs .= wf_TextInput('newfilternumcontain', __('Notes contains'), '', true, '20');
  1466. $inputs .= wf_TextInput('newfilternumnotcontain', __('Notes not contains'), '', true, '20');
  1467. $inputs .= wf_CheckInput('newfilternumnotouruser', __('Is not our user'), true, false);
  1468. }
  1469. if ($direction == 'employee') {
  1470. $inputs .= wf_TextInput('newfilteremployeeappointment', __('Appointment'), '', true, '30');
  1471. $inputs .= wf_CheckInput('newfilteremployeeactive', __('Employee is active'), true, true);
  1472. }
  1473. $inputs .= wf_tag('br');
  1474. $inputs .= wf_Submit(__('Create'));
  1475. } else {
  1476. $inputs .= __('Please select SMS direction');
  1477. }
  1478. if (!$remote) {
  1479. die($inputs);
  1480. } else {
  1481. return ($inputs);
  1482. }
  1483. }
  1484. /**
  1485. * Creates new filter in database
  1486. *
  1487. * @return void/string
  1488. */
  1489. public function createFilter() {
  1490. $result = '';
  1491. if (wf_CheckPost(array('newfilterdirection'))) {
  1492. $filterName = $_POST['newfiltername'];
  1493. $filterNameF = mysql_real_escape_string($filterName);
  1494. if (!empty($filterNameF)) {
  1495. $filterParams = array();
  1496. foreach ($_POST as $io => $each) {
  1497. if (ispos($io, 'newfilter')) {
  1498. $filterParams[$io] = $each;
  1499. }
  1500. }
  1501. if (!empty($filterParams)) {
  1502. $filterParams = json_encode($filterParams);
  1503. $filterParams = mysql_real_escape_string($filterParams);
  1504. $query = "INSERT INTO `smz_filters` (`id`,`name`,`filters`) VALUES ";
  1505. $query .= "(NULL,'" . $filterNameF . "','" . $filterParams . "');";
  1506. nr_query($query);
  1507. $newId = simple_get_lastid('smz_filters');
  1508. log_register('SMSZILLA FILTER CREATE [' . $newId . '] `' . $filterName . '`');
  1509. }
  1510. } else {
  1511. $result = __('Something went wrong') . ': EX_FILTER_NAME_EMPTY';
  1512. }
  1513. }
  1514. return ($result);
  1515. }
  1516. /**
  1517. * Loads existing filters from database
  1518. *
  1519. * @return void
  1520. */
  1521. protected function loadFilters() {
  1522. $query = "SELECT * from `smz_filters` ORDER BY `id` ASC";
  1523. $all = simple_queryall($query);
  1524. if (!empty($all)) {
  1525. foreach ($all as $io => $each) {
  1526. $this->filters[$each['id']] = $each;
  1527. }
  1528. }
  1529. }
  1530. /**
  1531. * Renders existing filter preview
  1532. *
  1533. * @param string $filters
  1534. *
  1535. * @return string
  1536. */
  1537. protected function renderFilterPreview($filters) {
  1538. $result = '';
  1539. if (!empty($filters)) {
  1540. $unpack = json_decode($filters, true);
  1541. if (!empty($unpack)) {
  1542. $cells = wf_TableCell(__('Filter'));
  1543. $cells .= wf_TableCell(__('Parameter'));
  1544. $rows = wf_TableRow($cells, 'row1');
  1545. foreach ($unpack as $io => $each) {
  1546. $filterName = str_replace('new', '', $io);
  1547. if (isset($this->filterNames[$filterName])) {
  1548. $filterName = __($this->filterNames[$filterName]);
  1549. }
  1550. $cells = wf_TableCell($filterName);
  1551. $cells .= wf_TableCell($each);
  1552. $rows .= wf_TableRow($cells, 'row3');
  1553. }
  1554. $result .= wf_TableBody($rows, '100%', 0, '');
  1555. }
  1556. }
  1557. return ($result);
  1558. }
  1559. /**
  1560. * Renders available filters list
  1561. *
  1562. * @return string
  1563. */
  1564. public function renderFiltersList() {
  1565. $result = '';
  1566. if (!empty($this->filters)) {
  1567. $cells = wf_TableCell(__('ID'));
  1568. $cells .= wf_TableCell(__('Name'));
  1569. $cells .= wf_TableCell(__('Actions'));
  1570. $rows = wf_TableRow($cells, 'row1');
  1571. foreach ($this->filters as $io => $each) {
  1572. $cells = wf_TableCell($each['id']);
  1573. $cells .= wf_TableCell($each['name']);
  1574. $actLinks = wf_JSAlert(self::URL_ME . '&filters=true&deletefilterid=' . $each['id'], web_delete_icon(), $this->messages->getDeleteAlert()) . ' ';
  1575. $actLinks .= wf_modalAuto(web_icon_search(), __('Preview'), $this->renderFilterPreview($each['filters']));
  1576. $cells .= wf_TableCell($actLinks);
  1577. $rows .= wf_TableRow($cells, 'row5');
  1578. }
  1579. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  1580. } else {
  1581. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'warning');
  1582. }
  1583. return ($result);
  1584. }
  1585. /**
  1586. * Deletes existing filter from database
  1587. *
  1588. * @param int $filterId
  1589. *
  1590. * @return void/string
  1591. */
  1592. public function deleteFilter($filterId) {
  1593. $result = '';
  1594. $filterId = vf($filterId, 3);
  1595. if (isset($this->filters[$filterId])) {
  1596. $query = "DELETE FROM `smz_filters` WHERE `id`='" . $filterId . "';";
  1597. nr_query($query);
  1598. log_register('SMSZILLA FILTER DELETE [' . $filterId . ']');
  1599. } else {
  1600. $result = __('Something went wrong') . ': : FILTER_ID_NOT_EXISTS';
  1601. }
  1602. return ($result);
  1603. }
  1604. /**
  1605. * Checks have user some tag assigned
  1606. *
  1607. * @param string $login
  1608. * @param int $tagId
  1609. *
  1610. * @return bool
  1611. */
  1612. protected function checkInetTagId($login, $tagId) {
  1613. $result = false;
  1614. if (isset($this->inetTags[$login])) {
  1615. if (!empty($this->inetTags[$login])) {
  1616. foreach ($this->inetTags[$login] as $io => $each) {
  1617. if ($each == $tagId) {
  1618. $result = true;
  1619. return ($result);
  1620. }
  1621. }
  1622. }
  1623. }
  1624. return ($result);
  1625. }
  1626. /**
  1627. * Checks have user switchId
  1628. *
  1629. * @param string $login
  1630. * @param int $switchId
  1631. *
  1632. * @return bool
  1633. */
  1634. protected function checkSwitchId($login, $switchId) {
  1635. $result = false;
  1636. if (isset($this->allSwitchesUsers[$login])) {
  1637. if ($this->allSwitchesUsers[$login] == $switchId) {
  1638. $result = true;
  1639. return ($result);
  1640. }
  1641. }
  1642. return ($result);
  1643. }
  1644. /**
  1645. * Checks have UKV user some tag assigned
  1646. *
  1647. * @param int $userid
  1648. * @param int $tagId
  1649. *
  1650. * @return bool
  1651. */
  1652. protected function checkUkvTagId($userid, $tagId) {
  1653. $result = false;
  1654. if (isset($this->ukvTags[$userid])) {
  1655. if (!empty($this->ukvTags[$userid])) {
  1656. foreach ($this->ukvTags[$userid] as $io => $each) {
  1657. if ($each == $tagId) {
  1658. $result = true;
  1659. return ($result);
  1660. }
  1661. }
  1662. }
  1663. }
  1664. return ($result);
  1665. }
  1666. /**
  1667. * Renders template and filters selection form
  1668. *
  1669. * @return string
  1670. */
  1671. public function renderSendingForm() {
  1672. $result = '';
  1673. //saving previous selectors state
  1674. $curTemplateId = (wf_CheckPost(array('sendingtemplateid'))) ? $_POST['sendingtemplateid'] : '';
  1675. $curFilterId = (wf_CheckPost(array('sendingfilterid'))) ? $_POST['sendingfilterid'] : '';
  1676. $curVisualFlag = (wf_CheckPost(array('sendingvisualfilters'))) ? true : false;
  1677. $curTranslitFlag = (wf_CheckPost(array('forcetranslit'))) ? true : false;
  1678. if (!(empty($this->templates)) and (!empty($this->filters))) {
  1679. $templatesParams = array();
  1680. foreach ($this->templates as $io => $each) {
  1681. $templatesParams[$each['id']] = $each['name'];
  1682. }
  1683. $filterParams = array();
  1684. foreach ($this->filters as $io => $each) {
  1685. $filterUnpack = json_decode($each['filters'], true);
  1686. $filterDirection = $filterUnpack['newfilterdirection'];
  1687. $filterDirection = $this->directionNames[$filterDirection];
  1688. $filterParams[$each['id']] = __($filterDirection) . ' ⇒ ' . $each['name'];
  1689. }
  1690. $inputs = wf_Selector('sendingtemplateid', $templatesParams, __('Template'), $curTemplateId, false) . ' ';
  1691. $inputs .= wf_Selector('sendingfilterid', $filterParams, __('Filter'), $curFilterId, false) . ' ';
  1692. $inputs .= wf_CheckInput('sendingvisualfilters', __('Visual'), false, $curVisualFlag) . ' ';
  1693. $inputs .= wf_CheckInput('forcetranslit', __('Forced transliteration'), false, $curTranslitFlag) . ' ';
  1694. $inputs .= wf_CheckInput('sendingperform', __('Perform real sending'), false, false) . ' ';
  1695. $inputs .= wf_Submit(__('Send SMS'));
  1696. $result .= wf_Form(self::URL_ME . '&sending=true', 'POST', $inputs, 'glamour');
  1697. } else {
  1698. $result .= $this->messages->getStyledMessage(__('No existing templates or filters available'), 'warning');
  1699. $result .= wf_CleanDiv();
  1700. $result .= wf_delimiter();
  1701. $result .= wf_tag('center') . wf_img('skins/gojiracry.jpg') . wf_tag('center', true);
  1702. }
  1703. return ($result);
  1704. }
  1705. /**
  1706. * Normalizes mobile number to E164 phone format.
  1707. *
  1708. * @param string $mobile
  1709. *
  1710. * @return string/void on error
  1711. */
  1712. protected function normalizePhoneFormat($mobile) {
  1713. $mobile = vf($mobile, 3);
  1714. if (!empty($mobile)) {
  1715. $inputLen = strlen($mobile);
  1716. $codeLen = strlen($this->countryCode);
  1717. if ($inputLen < $this->mobileLen) {
  1718. //trying to append country code if number is not ok by default or too short
  1719. $mobileTmp = $mobile;
  1720. for ($i = 1; $i <= $codeLen; $i++) {
  1721. $appendedLen = strlen($mobileTmp);
  1722. if ($appendedLen < $this->mobileLen) {
  1723. $appendCode = substr($this->countryCode, 0, $i);
  1724. $mobileTmp = $appendCode . $mobile;
  1725. $appendedLen = $appendedLen = strlen($mobileTmp);
  1726. if ($this->normalizerDebug) {
  1727. show_warning('Try to append: ' . $appendCode . ' to ' . $mobile . ' now len of (' . $mobileTmp . ') is ' . strlen($mobileTmp));
  1728. }
  1729. if ($appendedLen == $this->mobileLen) {
  1730. $mobile = $mobileTmp;
  1731. if ($this->normalizerDebug) {
  1732. show_success('Yeah! now mobile normalized to ' . $mobile);
  1733. }
  1734. }
  1735. } else {
  1736. $mobile = $mobileTmp;
  1737. if ($this->normalizerDebug) {
  1738. show_success('Number len normalized: ' . $mobileTmp);
  1739. }
  1740. }
  1741. }
  1742. } else {
  1743. if ($this->normalizerDebug) {
  1744. show_info('Number is ok by default: ' . $mobile);
  1745. }
  1746. }
  1747. //checking is number starting from full country code?
  1748. if (strpos($mobile, $this->countryCode) === false) {
  1749. if ($this->normalizerDebug) {
  1750. show_error('Number doesnt start with ' . $this->countryCode . ': ' . $mobile);
  1751. }
  1752. $mobile = '';
  1753. }
  1754. //appending plus symbol due E164 standard
  1755. $newLen = strlen($mobile);
  1756. if ($newLen == $this->mobileLen) {
  1757. $mobile = '+' . $mobile;
  1758. } else {
  1759. $mobile = '';
  1760. }
  1761. }
  1762. return ($mobile);
  1763. }
  1764. /**
  1765. * Extract mobile numbers from filtered entities array
  1766. *
  1767. * @return void
  1768. */
  1769. protected function extractEntitiesNumbers() {
  1770. if (!empty($this->filteredEntities)) {
  1771. switch ($this->entitiesType) {
  1772. case 'login':
  1773. if ($this->useExtMobiles) {
  1774. $this->extMobiles = new MobilesExt();
  1775. }
  1776. foreach ($this->filteredEntities as $io => $each) {
  1777. $userLogin = $each['login'];
  1778. $primaryMobile = $this->normalizePhoneFormat($each['mobile']);
  1779. if ((!empty($primaryMobile) and (!isset($this->excludeNumbers[$primaryMobile])))) {
  1780. $this->filteredNumbers[$userLogin][] = $primaryMobile;
  1781. }
  1782. if ($this->useExtMobiles) {
  1783. $userExtMobiles = $this->extMobiles->getUserMobiles($userLogin);
  1784. if (!empty($userExtMobiles)) {
  1785. foreach ($userExtMobiles as $ia => $eachExt) {
  1786. $additionalMobile = $this->normalizePhoneFormat($eachExt['mobile']);
  1787. if ((!empty($additionalMobile)) and (!isset($this->excludeNumbers[$additionalMobile]))) {
  1788. $this->filteredNumbers[$userLogin][] = $additionalMobile;
  1789. $this->extMobilesCount++;
  1790. }
  1791. }
  1792. }
  1793. }
  1794. }
  1795. break;
  1796. case 'ukv':
  1797. foreach ($this->filteredEntities as $io => $each) {
  1798. $userPrimaryMobile = $this->normalizePhoneFormat($each['mobile']);
  1799. if ((!empty($userPrimaryMobile)) and (!isset($this->excludeNumbers[$userPrimaryMobile]))) {
  1800. $this->filteredNumbers[$each['id']] = $userPrimaryMobile;
  1801. }
  1802. }
  1803. break;
  1804. case 'employee':
  1805. foreach ($this->filteredEntities as $io => $each) {
  1806. $employeeMobile = $this->normalizePhoneFormat($each['mobile']);
  1807. if ((!empty($employeeMobile) and (!isset($this->excludeNumbers[$employeeMobile])))) {
  1808. $this->filteredNumbers[$each['id']] = $employeeMobile;
  1809. }
  1810. }
  1811. break;
  1812. case 'numlist':
  1813. foreach ($this->filteredEntities as $io => $each) {
  1814. $numlistMobile = $this->normalizePhoneFormat($each['mobile']);
  1815. if ((!empty($numlistMobile) and (!isset($this->excludeNumbers[$numlistMobile])))) {
  1816. $this->filteredNumbers[$each['id']] = $numlistMobile;
  1817. }
  1818. }
  1819. break;
  1820. }
  1821. }
  1822. }
  1823. /**
  1824. * Saves each filter workflow stats
  1825. *
  1826. * @param string $filterName
  1827. * @param int $entityCount
  1828. *
  1829. * @return void
  1830. */
  1831. protected function saveFilterStats($filterName, $entityCount) {
  1832. $this->filterStats[$filterName] = $entityCount;
  1833. }
  1834. /**
  1835. * Renders some filtered processing stats and charts
  1836. *
  1837. * @return string
  1838. */
  1839. protected function renderFilterStats() {
  1840. $result = '';
  1841. $params = array();
  1842. $params[] = array(__('Filter'), __('Entities count'));
  1843. $chartsOptions = "
  1844. 'focusTarget': 'category',
  1845. 'hAxis': {
  1846. 'color': 'none',
  1847. 'baselineColor': 'none',
  1848. },
  1849. 'vAxis': {
  1850. 'color': 'none',
  1851. 'baselineColor': 'none',
  1852. },
  1853. 'curveType': 'function',
  1854. 'pointSize': 5,
  1855. 'crosshair': {
  1856. trigger: 'none'
  1857. },";
  1858. if (!empty($this->filterStats)) {
  1859. foreach ($this->filterStats as $filterName => $entityCount) {
  1860. $filterNormalName = (isset($this->filterNames[$filterName])) ? __($this->filterNames[$filterName]) : $filterName;
  1861. $params[] = array($filterNormalName, $entityCount);
  1862. }
  1863. $result .= wf_gchartsLine($params, __('Filters'), '100%', '300px', $chartsOptions);
  1864. }
  1865. return ($result);
  1866. }
  1867. /**
  1868. * Performs draft filter entities preprocessing
  1869. *
  1870. * @param int $filterId
  1871. * @param int $templateId
  1872. *
  1873. * @return string
  1874. */
  1875. public function filtersPreprocessing($filterId, $templateId) {
  1876. $result = array();
  1877. $unknownFilters = array();
  1878. if (isset($this->filters[$filterId])) {
  1879. $filterData = $this->filters[$filterId]['filters'];
  1880. $filterData = json_decode($filterData, true);
  1881. if (isset($filterData['newfilterdirection'])) {
  1882. $direction = $filterData['newfilterdirection'];
  1883. $this->entitiesType = $direction;
  1884. switch ($direction) {
  1885. case 'login':
  1886. $this->filteredEntities = $this->allUserData;
  1887. break;
  1888. case 'ukv':
  1889. $this->filteredEntities = $this->ukv->getUsers();
  1890. break;
  1891. case 'employee':
  1892. $this->filteredEntities = $this->employee;
  1893. break;
  1894. case 'numlist':
  1895. $this->filteredEntities = $this->allNumListsNumbers;
  1896. break;
  1897. }
  1898. //setting base entities count
  1899. $this->saveFilterStats('atstart', sizeof($this->filteredEntities));
  1900. /**
  1901. * Knowing that I pack your things up in lie
  1902. * I guess I'll beware of love with a bite
  1903. * Roll on, girl. Roll, roll to tomorrow
  1904. * Rollin' on, girl without feeling tonight
  1905. */
  1906. foreach ($filterData as $eachFilter => $eachFilterParam) {
  1907. if ((ispos($eachFilter, 'newfilter')) and ($eachFilter != 'newfilterdirection') and ($eachFilter != 'newfiltername')) {
  1908. $filterMethodName = str_replace('new', '', $eachFilter);
  1909. if (method_exists($this, $filterMethodName)) {
  1910. $this->$filterMethodName($direction, $eachFilterParam);
  1911. //saving filter stats
  1912. if (!empty($eachFilterParam)) {
  1913. $this->saveFilterStats($filterMethodName, sizeof($this->filteredEntities));
  1914. }
  1915. } else {
  1916. show_error(__('Something went wrong') . ': UNKNOWN_FILTER_METHOD ' . $filterMethodName);
  1917. }
  1918. }
  1919. }
  1920. }
  1921. }
  1922. if ((!empty($this->filteredEntities)) and (!empty($this->entitiesType))) {
  1923. if (wf_CheckPost(array('sendingvisualfilters'))) {
  1924. show_window(__('Filters workflow visualization'), $this->renderFilterStats());
  1925. }
  1926. $this->extractEntitiesNumbers();
  1927. $sendingStats = $this->messages->getStyledMessage(__('Entities filtered') . ': ' . sizeof($this->filteredEntities) . ' ' . __('Numbers extracted') . ': ' . (sizeof($this->filteredNumbers) + $this->extMobilesCount), 'info');
  1928. if (wf_CheckPost(array('sendingperform'))) {
  1929. $sendingStats .= $this->messages->getStyledMessage(__('SMS for all of extracted numbers stored in sending queue'), 'success');
  1930. }
  1931. show_window('', $sendingStats);
  1932. $this->generateSmsPool($filterId, $templateId);
  1933. show_window(__('Preview'), $this->renderSmsPoolPreviewContainer($filterId, $templateId));
  1934. } else {
  1935. show_warning(__('Nothing found'));
  1936. }
  1937. return ($result);
  1938. }
  1939. /**
  1940. * Renders SMS pool preview container
  1941. *
  1942. * @param int $filterId
  1943. * @param int $templateId
  1944. *
  1945. * @return string
  1946. */
  1947. protected function renderSmsPoolPreviewContainer($filterId, $templateId) {
  1948. $result = '';
  1949. if ($this->sms->smsRoutingFlag) {
  1950. $columns = array('SMS direction', 'Mobile', 'Text', 'Size', __('Count') . ' ' . 'SMS', __('SMS service'));
  1951. } else {
  1952. $columns = array('SMS direction', 'Mobile', 'Text', 'Size', __('Count') . ' ' . 'SMS');
  1953. }
  1954. $result = wf_JqDtLoader($columns, self::URL_ME . '&sending=true&ajpreview=true&filterid=' . $filterId . '&templateid=' . $templateId, false, __('SMS'), 100);
  1955. return ($result);
  1956. }
  1957. /**
  1958. * Renders previously cached preview JSON data
  1959. *
  1960. * @param int $filterId
  1961. * @param int $templateId
  1962. *
  1963. * @return void
  1964. */
  1965. public function ajaxPreviewReply($filterId, $templateId) {
  1966. $result = '';
  1967. $previewCacheName = self::POOL_PATH . 'SMZ_PREVIEW_' . $filterId . '_' . $templateId;
  1968. if (file_exists($previewCacheName)) {
  1969. die(file_get_contents($previewCacheName));
  1970. } else {
  1971. $reply = array('aaData' => array());
  1972. die(json_encode($reply));
  1973. }
  1974. }
  1975. /**
  1976. * Generates SMS text for sending/preview
  1977. *
  1978. * @param int $templateId
  1979. * @param array $entity
  1980. * @param bool $forceTranslit
  1981. *
  1982. * @return strings
  1983. */
  1984. protected function generateSmsText($templateId, $entity, $forceTranslit) {
  1985. $result = '';
  1986. $result = $this->templates[$templateId]['text'];
  1987. switch ($this->entitiesType) {
  1988. case 'login':
  1989. $result = str_ireplace('{LOGIN}', $this->filteredEntities[$entity]['login'], $result);
  1990. $result = str_ireplace('{REALNAME}', $this->filteredEntities[$entity]['realname'], $result);
  1991. $result = str_ireplace('{TARIFF}', $this->filteredEntities[$entity]['Tariff'], $result);
  1992. $result = str_ireplace('{TARIFFPRICE}', @$this->allTariffPrices[$this->filteredEntities[$entity]['Tariff']], $result);
  1993. $result = str_ireplace('{TARIFFNM}', $this->filteredEntities[$entity]['TariffChange'], $result);
  1994. $result = str_ireplace('{TARIFFNMPRICE}', @$this->allTariffPrices[$this->filteredEntities[$entity]['TariffChange']], $result);
  1995. $result = str_ireplace('{TARIFFPERIOD}', __(@$this->allTariffs[$this->filteredEntities[$entity]['Tariff']]['period']), $result);
  1996. $result = str_ireplace('{PAYMENTID}', @$this->opCustomers[$this->filteredEntities[$entity]['login']], $result);
  1997. $result = str_ireplace('{CREDIT}', $this->filteredEntities[$entity]['Credit'], $result);
  1998. $result = str_ireplace('{CASH}', $this->filteredEntities[$entity]['Cash'], $result);
  1999. if (@empty($this->filteredEntities[$entity]['TariffChange'])) {
  2000. $lackCash = @$this->allTariffPrices[$this->filteredEntities[$entity]['Tariff']] - $this->filteredEntities[$entity]['Cash'];
  2001. } else {
  2002. $lackCash = @$this->allTariffPrices[$this->filteredEntities[$entity]['TariffChange']] - $this->filteredEntities[$entity]['Cash'];
  2003. }
  2004. $result = str_ireplace('{LACK}', $lackCash, $result);
  2005. $result = str_ireplace('{ROUNDCASH}', round($this->filteredEntities[$entity]['Cash'], 2), $result);
  2006. $result = str_ireplace('{IP}', $this->filteredEntities[$entity]['ip'], $result);
  2007. $result = str_ireplace('{MAC}', $this->filteredEntities[$entity]['mac'], $result);
  2008. $result = str_ireplace('{FULLADDRESS}', $this->filteredEntities[$entity]['fulladress'], $result);
  2009. $result = str_ireplace('{PHONE}', $this->filteredEntities[$entity]['phone'], $result);
  2010. $result = str_ireplace('{MOBILE}', $this->filteredEntities[$entity]['mobile'], $result);
  2011. $result = str_ireplace('{CONTRACT}', $this->filteredEntities[$entity]['contract'], $result);
  2012. $result = str_ireplace('{EMAIL}', $this->filteredEntities[$entity]['email'], $result);
  2013. $result = str_ireplace('{CURDATE}', date("Y-m-d"), $result);
  2014. $result = str_ireplace('{PASSWORD}', $this->filteredEntities[$entity]['Password'], $result);
  2015. $result = str_ireplace('{USERONLINELEFTDAY}', $this->getUserOnlineLeftDayCount($entity), $result);
  2016. $result = str_ireplace('{USERONLINETODATE}', $this->getUserOnlineToDate($entity), $result);
  2017. break;
  2018. case 'ukv':
  2019. $result = str_ireplace('{REALNAME}', $this->filteredEntities[$entity]['realname'], $result);
  2020. $result = str_ireplace('{TARIFF}', $this->ukv->tariffGetName($this->filteredEntities[$entity]['tariffid']), $result);
  2021. $result = str_ireplace('{CASH}', $this->filteredEntities[$entity]['cash'], $result);
  2022. $result = str_ireplace('{ROUNDCASH}', round($this->filteredEntities[$entity]['cash'], 2), $result);
  2023. $result = str_ireplace('{FULLADDRESS}', $this->ukv->userGetFullAddress($entity), $result);
  2024. $result = str_ireplace('{PHONE}', $this->filteredEntities[$entity]['phone'], $result);
  2025. $result = str_ireplace('{MOBILE}', $this->filteredEntities[$entity]['mobile'], $result);
  2026. $result = str_ireplace('{CONTRACT}', $this->filteredEntities[$entity]['contract'], $result);
  2027. $result = str_ireplace('{CURDATE}', date("Y-m-d"), $result);
  2028. break;
  2029. }
  2030. if ($forceTranslit) {
  2031. $result = zb_TranslitString($result, true);
  2032. }
  2033. return ($result);
  2034. }
  2035. /**
  2036. * Returns nearest sending SMS count for multibyte encodings
  2037. *
  2038. * @param string $messageText
  2039. *
  2040. * @return int
  2041. */
  2042. protected function getSmsCount($textLen) {
  2043. $result = 0;
  2044. $result = ceil($textLen / $this->smsLenLimit);
  2045. return ($result);
  2046. }
  2047. /**
  2048. * Generates SMS pool for preview rendering or further sending
  2049. *
  2050. * @param type $filterId
  2051. * @param type $templateId
  2052. *
  2053. * @return void
  2054. */
  2055. protected function generateSmsPool($filterId, $templateId) {
  2056. $json = new wf_JqDtHelper();
  2057. $data = array();
  2058. $realSending = (wf_CheckPost(array('sendingperform'))) ? true : false;
  2059. $forceTranslit = (wf_CheckPost(array('forcetranslit'))) ? true : false;
  2060. if (!$realSending) {
  2061. //Remote API background call
  2062. $realSending = (wf_CheckGet(array('key', 'action', 'filterid', 'templateid'))) ? true : false;
  2063. }
  2064. if (!$forceTranslit) {
  2065. //Remote API translit option instead
  2066. $forceTranslit = (wf_CheckGet(array('translit'))) ? true : false;
  2067. }
  2068. $sendCounter = 0;
  2069. //changing nearest SMS bytes limit
  2070. if ($forceTranslit) {
  2071. $this->smsLenLimit = 160;
  2072. } else {
  2073. $this->smsLenLimit = 70;
  2074. }
  2075. if (!empty($this->filteredNumbers)) {
  2076. switch ($this->entitiesType) {
  2077. case 'login':
  2078. foreach ($this->filteredNumbers as $entityId => $numbers) {
  2079. if (!empty($numbers)) {
  2080. foreach ($numbers as $io => $eachNumber) {
  2081. $userLogin = $entityId;
  2082. $userLink = wf_Link('?module=userprofile&username=' . $userLogin, web_profile_icon() . ' ' . $this->filteredEntities[$userLogin]['fulladress']);
  2083. $messageText = $this->generateSmsText($templateId, $userLogin, $forceTranslit);
  2084. $textLen = mb_strlen($messageText, 'utf-8');
  2085. $smsCount = $this->getSmsCount($textLen);
  2086. $messageDirection = '';
  2087. $data[] = $userLink . ' ' . $this->filteredEntities[$userLogin]['realname'];
  2088. $data[] = $eachNumber;
  2089. $data[] = $messageText;
  2090. $data[] = $textLen;
  2091. $data[] = $smsCount;
  2092. if ($this->sms->smsRoutingFlag) {
  2093. $messageDirection = $this->sms->smsDirections->getDirection('user_login', $userLogin);
  2094. $data[] = $this->sms->smsDirections->getDirectionNameById($messageDirection);
  2095. }
  2096. $json->addRow($data);
  2097. unset($data);
  2098. //pushing some messages into queue
  2099. if ($realSending) {
  2100. $queueFile = $this->sms->sendSMS($eachNumber, $messageText, false, 'SMSZILLA');
  2101. $this->sms->setDirection($queueFile, 'user_login', $userLogin, $messageDirection);
  2102. $sendCounter++;
  2103. }
  2104. }
  2105. }
  2106. }
  2107. break;
  2108. case 'ukv':
  2109. foreach ($this->filteredNumbers as $entityId => $number) {
  2110. if (!empty($number)) {
  2111. $userId = $entityId;
  2112. $userLink = wf_Link('?module=ukv&users=true&showuser=' . $userId, web_profile_icon() . ' ' . $this->ukv->userGetFullAddress($userId));
  2113. $messageText = $this->generateSmsText($templateId, $userId, $forceTranslit);
  2114. $textLen = mb_strlen($messageText, 'utf-8');
  2115. $smsCount = $this->getSmsCount($textLen);
  2116. $data[] = $userLink . ' ' . $this->filteredEntities[$userId]['realname'];
  2117. $data[] = $number;
  2118. $data[] = $messageText;
  2119. $data[] = $textLen;
  2120. $data[] = $smsCount;
  2121. if ($this->sms->smsRoutingFlag) {
  2122. $data[] = $this->sms->smsDirections->getDirectionNameById();
  2123. }
  2124. $json->addRow($data);
  2125. unset($data);
  2126. //pushing some messages into queue
  2127. if ($realSending) {
  2128. $this->sms->sendSMS($number, $messageText, false, 'SMSZILLA');
  2129. $sendCounter++;
  2130. }
  2131. }
  2132. }
  2133. break;
  2134. case 'employee':
  2135. foreach ($this->filteredNumbers as $entityId => $number) {
  2136. if (!empty($number)) {
  2137. $employeeId = $entityId;
  2138. $employeeLink = wf_Link('?module=employee&edit=' . $employeeId, web_profile_icon() . ' ' . $this->employee[$employeeId]['name']);
  2139. $messageText = $this->generateSmsText($templateId, $employeeId, $forceTranslit);
  2140. $textLen = mb_strlen($messageText, 'utf-8');
  2141. $smsCount = $this->getSmsCount($textLen);
  2142. $data[] = $employeeLink;
  2143. $data[] = $number;
  2144. $data[] = $messageText;
  2145. $data[] = $textLen;
  2146. $data[] = $smsCount;
  2147. if ($this->sms->smsRoutingFlag) {
  2148. $data[] = $this->sms->smsDirections->getDirectionNameById();
  2149. }
  2150. $json->addRow($data);
  2151. unset($data);
  2152. //pushing some messages into queue
  2153. if ($realSending) {
  2154. $this->sms->sendSMS($number, $messageText, false, 'SMSZILLA');
  2155. $sendCounter++;
  2156. }
  2157. }
  2158. }
  2159. break;
  2160. case 'numlist':
  2161. foreach ($this->filteredNumbers as $entityId => $number) {
  2162. if (!empty($number)) {
  2163. $numId = $entityId;
  2164. $messageText = $this->generateSmsText($templateId, $numId, $forceTranslit);
  2165. $textLen = mb_strlen($messageText, 'utf-8');
  2166. $smsCount = $this->getSmsCount($textLen);
  2167. $data[] = $this->allNumListsNumbers[$numId]['notes'];
  2168. $data[] = $number;
  2169. $data[] = $messageText;
  2170. $data[] = $textLen;
  2171. $data[] = $smsCount;
  2172. if ($this->sms->smsRoutingFlag) {
  2173. $data[] = $this->sms->smsDirections->getDirectionNameById();
  2174. }
  2175. $json->addRow($data);
  2176. unset($data);
  2177. //pushing some messages into queue
  2178. if ($realSending) {
  2179. $this->sms->sendSMS($number, $messageText, false, 'SMSZILLA');
  2180. $sendCounter++;
  2181. }
  2182. }
  2183. }
  2184. break;
  2185. }
  2186. //logging if SMS really sent
  2187. if ($realSending) {
  2188. log_register('SMSZILLA SENDING TEMPLATE [' . $templateId . '] FILTER [' . $filterId . '] COUNT `' . $sendCounter . '`');
  2189. }
  2190. }
  2191. //saving preview data
  2192. file_put_contents(self::POOL_PATH . 'SMZ_PREVIEW_' . $filterId . '_' . $templateId, $json->extractJson());
  2193. }
  2194. /**
  2195. * City filter
  2196. *
  2197. * @param string $direction
  2198. * @param string $param
  2199. *
  2200. * @return void
  2201. */
  2202. protected function filtercity($direction, $param) {
  2203. if (!empty($param)) {
  2204. if (!empty($this->filteredEntities)) {
  2205. switch ($direction) {
  2206. case 'login':
  2207. foreach ($this->filteredEntities as $io => $entity) {
  2208. if ($entity['cityname'] != $param) {
  2209. unset($this->filteredEntities[$entity['login']]);
  2210. }
  2211. }
  2212. break;
  2213. case 'ukv':
  2214. foreach ($this->filteredEntities as $io => $entity) {
  2215. if ($entity['city'] != $param) {
  2216. unset($this->filteredEntities[$entity['id']]);
  2217. }
  2218. }
  2219. break;
  2220. }
  2221. }
  2222. }
  2223. }
  2224. /**
  2225. * Address filter
  2226. *
  2227. * @param string $direction
  2228. * @param string $param
  2229. *
  2230. * @return void
  2231. */
  2232. protected function filteraddress($direction, $param) {
  2233. if (!empty($param)) {
  2234. if (!empty($this->filteredEntities)) {
  2235. switch ($direction) {
  2236. case 'login':
  2237. $search = trim($param);
  2238. foreach ($this->filteredEntities as $io => $entity) {
  2239. if (!ispos($entity['fulladress'], $search)) {
  2240. unset($this->filteredEntities[$entity['login']]);
  2241. }
  2242. }
  2243. break;
  2244. case 'ukv':
  2245. $search = trim($param);
  2246. foreach ($this->filteredEntities as $io => $entity) {
  2247. $userAddress = $this->ukv->userGetFullAddress($entity['id']);
  2248. if (!ispos($userAddress, $search)) {
  2249. unset($this->filteredEntities[$entity['id']]);
  2250. }
  2251. }
  2252. break;
  2253. }
  2254. }
  2255. }
  2256. }
  2257. /**
  2258. * Login filter
  2259. *
  2260. * @param string $direction
  2261. * @param string $param
  2262. *
  2263. * @return void
  2264. */
  2265. protected function filterlogin($direction, $param) {
  2266. if (!empty($param)) {
  2267. if (!empty($this->filteredEntities)) {
  2268. switch ($direction) {
  2269. case 'login':
  2270. $search = trim($param);
  2271. foreach ($this->filteredEntities as $io => $entity) {
  2272. if (!ispos($entity['login'], $search)) {
  2273. unset($this->filteredEntities[$entity['login']]);
  2274. }
  2275. }
  2276. break;
  2277. }
  2278. }
  2279. }
  2280. }
  2281. /**
  2282. * IP substring filter
  2283. *
  2284. * @param string $direction
  2285. * @param string $param
  2286. *
  2287. * @return void
  2288. */
  2289. protected function filterip($direction, $param) {
  2290. if (!empty($param)) {
  2291. if (!empty($this->filteredEntities)) {
  2292. switch ($direction) {
  2293. case 'login':
  2294. $search = trim($param);
  2295. foreach ($this->filteredEntities as $io => $entity) {
  2296. if (!ispos($entity['ip'], $search)) {
  2297. unset($this->filteredEntities[$entity['login']]);
  2298. }
  2299. }
  2300. break;
  2301. }
  2302. }
  2303. }
  2304. }
  2305. /**
  2306. * Month cash filter
  2307. *
  2308. * @param string $direction
  2309. * @param string $param
  2310. *
  2311. * @return void
  2312. */
  2313. protected function filtercashmonth($direction, $param) {
  2314. if (!empty($param)) {
  2315. if (!empty($this->filteredEntities)) {
  2316. //init slow funds flow object if required
  2317. if (empty($this->fundsFlow)) {
  2318. $this->initFundsFlow();
  2319. }
  2320. switch ($direction) {
  2321. case 'login':
  2322. foreach ($this->filteredEntities as $io => $entity) {
  2323. $daysLeft = $this->fundsFlow->getOnlineLeftCountFast($entity['login']);
  2324. if ($daysLeft > 0) {
  2325. $curMonthDays = date("t");
  2326. $curDate = date("j");
  2327. /**
  2328. * ─────█─▄▀█──█▀▄─█─────
  2329. * ────▐▌──────────▐▌────
  2330. * ────█▌▀▄──▄▄──▄▀▐█────
  2331. * ───▐██──▀▀──▀▀──██▌───
  2332. * ──▄████▄──▐▌──▄████▄──
  2333. */
  2334. $curMonthOffset = strtotime(date("Y-m-05"));
  2335. /**
  2336. * remember remember the 5th of november
  2337. */
  2338. $nextMonthDays = date("t", strtotime(date('Y-m-d', strtotime('+1 month', $curMonthOffset))));
  2339. $expr = ($curMonthDays - $curDate) + $nextMonthDays;
  2340. if ($daysLeft > $expr) {
  2341. unset($this->filteredEntities[$entity['login']]);
  2342. }
  2343. } else {
  2344. unset($this->filteredEntities[$entity['login']]);
  2345. }
  2346. }
  2347. break;
  2348. }
  2349. }
  2350. }
  2351. }
  2352. /**
  2353. * Days less cash filter
  2354. *
  2355. * @param string $direction
  2356. * @param string $param
  2357. *
  2358. * @return void
  2359. */
  2360. protected function filtercashdays($direction, $param) {
  2361. if (!empty($param)) {
  2362. if (!empty($this->filteredEntities)) {
  2363. //init slow funds flow object if required
  2364. if (empty($this->fundsFlow)) {
  2365. $this->initFundsFlow();
  2366. }
  2367. switch ($direction) {
  2368. case 'login':
  2369. foreach ($this->filteredEntities as $io => $entity) {
  2370. $daysLeft = $this->fundsFlow->getOnlineLeftCountFast($entity['login']);
  2371. if ($daysLeft > 0) {
  2372. if ($daysLeft > $param) {
  2373. unset($this->filteredEntities[$entity['login']]);
  2374. }
  2375. } else {
  2376. unset($this->filteredEntities[$entity['login']]);
  2377. }
  2378. }
  2379. break;
  2380. }
  2381. }
  2382. }
  2383. }
  2384. /**
  2385. * Greater cash filter
  2386. *
  2387. * @param string $direction
  2388. * @param string $param
  2389. *
  2390. * @return void
  2391. */
  2392. protected function filtercashgreater($direction, $param) {
  2393. if (!empty($param)) {
  2394. if (!empty($this->filteredEntities)) {
  2395. switch ($direction) {
  2396. case 'login':
  2397. foreach ($this->filteredEntities as $io => $entity) {
  2398. if ($entity['Cash'] < $param) {
  2399. unset($this->filteredEntities[$entity['login']]);
  2400. }
  2401. }
  2402. break;
  2403. case 'ukv':
  2404. foreach ($this->filteredEntities as $io => $entity) {
  2405. if ($entity['cash'] < $param) {
  2406. unset($this->filteredEntities[$entity['id']]);
  2407. }
  2408. }
  2409. break;
  2410. }
  2411. }
  2412. }
  2413. }
  2414. /**
  2415. * Lesser cash filter
  2416. *
  2417. * @param string $direction
  2418. * @param string $param
  2419. *
  2420. * @return void
  2421. */
  2422. protected function filtercashlesser($direction, $param) {
  2423. if (!empty($param)) {
  2424. if (!empty($this->filteredEntities)) {
  2425. switch ($direction) {
  2426. case 'login':
  2427. foreach ($this->filteredEntities as $io => $entity) {
  2428. if ($entity['Cash'] > $param) {
  2429. unset($this->filteredEntities[$entity['login']]);
  2430. }
  2431. }
  2432. break;
  2433. case 'ukv':
  2434. foreach ($this->filteredEntities as $io => $entity) {
  2435. if ($entity['cash'] > $param) {
  2436. unset($this->filteredEntities[$entity['id']]);
  2437. }
  2438. }
  2439. break;
  2440. }
  2441. }
  2442. }
  2443. }
  2444. /**
  2445. * Lesser zero cash filter
  2446. *
  2447. * @param string $direction
  2448. * @param string $param
  2449. *
  2450. * @return void
  2451. */
  2452. protected function filtercashlesszero($direction, $param) {
  2453. if (!empty($param)) {
  2454. if (!empty($this->filteredEntities)) {
  2455. switch ($direction) {
  2456. case 'login':
  2457. foreach ($this->filteredEntities as $io => $entity) {
  2458. if ($entity['Cash'] >= 0) {
  2459. unset($this->filteredEntities[$entity['login']]);
  2460. }
  2461. }
  2462. break;
  2463. case 'ukv':
  2464. foreach ($this->filteredEntities as $io => $entity) {
  2465. if ($entity['cash'] >= 0) {
  2466. unset($this->filteredEntities[$entity['id']]);
  2467. }
  2468. }
  2469. break;
  2470. }
  2471. }
  2472. }
  2473. }
  2474. /**
  2475. * Zero cash filter
  2476. *
  2477. * @param string $direction
  2478. * @param string $param
  2479. *
  2480. * @return void
  2481. */
  2482. protected function filtercashzero($direction, $param) {
  2483. if (!empty($param)) {
  2484. if (!empty($this->filteredEntities)) {
  2485. switch ($direction) {
  2486. case 'login':
  2487. foreach ($this->filteredEntities as $io => $entity) {
  2488. if ($entity['Cash'] != 0) {
  2489. unset($this->filteredEntities[$entity['login']]);
  2490. }
  2491. }
  2492. break;
  2493. case 'ukv':
  2494. foreach ($this->filteredEntities as $io => $entity) {
  2495. if ($entity['cash'] != 0) {
  2496. unset($this->filteredEntities[$entity['id']]);
  2497. }
  2498. }
  2499. break;
  2500. }
  2501. }
  2502. }
  2503. }
  2504. /**
  2505. * Credit filter
  2506. *
  2507. * @param string $direction
  2508. * @param string $param
  2509. *
  2510. * @return void
  2511. */
  2512. protected function filtercreditset($direction, $param) {
  2513. if (!empty($param)) {
  2514. if (!empty($this->filteredEntities)) {
  2515. switch ($direction) {
  2516. case 'login':
  2517. foreach ($this->filteredEntities as $io => $entity) {
  2518. if ($entity['Credit'] == 0) {
  2519. unset($this->filteredEntities[$entity['login']]);
  2520. }
  2521. }
  2522. break;
  2523. }
  2524. }
  2525. }
  2526. }
  2527. /**
  2528. * Tags filter
  2529. *
  2530. * @param string $direction
  2531. * @param string $param
  2532. *
  2533. * @return void
  2534. */
  2535. protected function filtertags($direction, $param) {
  2536. if (!empty($param)) {
  2537. if (!empty($this->filteredEntities)) {
  2538. switch ($direction) {
  2539. case 'login':
  2540. foreach ($this->filteredEntities as $io => $entity) {
  2541. if (!$this->checkInetTagId($entity['login'], $param)) {
  2542. unset($this->filteredEntities[$entity['login']]);
  2543. }
  2544. }
  2545. break;
  2546. case 'ukv':
  2547. foreach ($this->filteredEntities as $io => $entity) {
  2548. if (!$this->checkUkvTagId($entity['id'], $param)) {
  2549. unset($this->filteredEntities[$entity['id']]);
  2550. }
  2551. }
  2552. break;
  2553. }
  2554. }
  2555. }
  2556. }
  2557. /**
  2558. * AlwaysOnline filter
  2559. *
  2560. * @param string $direction
  2561. * @param string $param
  2562. *
  2563. * @return void
  2564. */
  2565. protected function filterao($direction, $param) {
  2566. if (!empty($param)) {
  2567. if (!empty($this->filteredEntities)) {
  2568. switch ($direction) {
  2569. case 'login':
  2570. foreach ($this->filteredEntities as $io => $entity) {
  2571. if ($entity['AlwaysOnline'] != '1') {
  2572. unset($this->filteredEntities[$entity['login']]);
  2573. }
  2574. }
  2575. break;
  2576. }
  2577. }
  2578. }
  2579. }
  2580. /**
  2581. * Passive filter
  2582. *
  2583. * @param string $direction
  2584. * @param string $param
  2585. *
  2586. * @return void
  2587. */
  2588. protected function filterpassive($direction, $param) {
  2589. if (!empty($param)) {
  2590. if (!empty($this->filteredEntities)) {
  2591. switch ($direction) {
  2592. case 'login':
  2593. foreach ($this->filteredEntities as $io => $entity) {
  2594. if ($entity['Passive'] != '1') {
  2595. unset($this->filteredEntities[$entity['login']]);
  2596. }
  2597. }
  2598. break;
  2599. }
  2600. }
  2601. }
  2602. }
  2603. /**
  2604. * Switch filter
  2605. *
  2606. * @param string $direction
  2607. * @param string $param
  2608. *
  2609. * @return void
  2610. */
  2611. protected function filterswitch($direction, $param) {
  2612. if (!empty($param)) {
  2613. if (!empty($this->filteredEntities)) {
  2614. switch ($direction) {
  2615. case 'login':
  2616. foreach ($this->filteredEntities as $io => $entity) {
  2617. if (!$this->checkSwitchId($entity['login'], $param)) {
  2618. unset($this->filteredEntities[$entity['login']]);
  2619. }
  2620. }
  2621. break;
  2622. }
  2623. }
  2624. }
  2625. }
  2626. /**
  2627. * Not passive filter
  2628. *
  2629. * @param string $direction
  2630. * @param string $param
  2631. *
  2632. * @return void
  2633. */
  2634. protected function filternotpassive($direction, $param) {
  2635. if (!empty($param)) {
  2636. if (!empty($this->filteredEntities)) {
  2637. switch ($direction) {
  2638. case 'login':
  2639. foreach ($this->filteredEntities as $io => $entity) {
  2640. if ($entity['Passive'] != '0') {
  2641. unset($this->filteredEntities[$entity['login']]);
  2642. }
  2643. }
  2644. break;
  2645. }
  2646. }
  2647. }
  2648. }
  2649. /**
  2650. * User activity filter
  2651. *
  2652. * @param string $direction
  2653. * @param string $param
  2654. *
  2655. * @return void
  2656. */
  2657. protected function filteractive($direction, $param) {
  2658. if (!empty($param)) {
  2659. if (!empty($this->filteredEntities)) {
  2660. switch ($direction) {
  2661. case 'login':
  2662. foreach ($this->filteredEntities as $io => $entity) {
  2663. if ($entity['Passive'] == '1') {
  2664. unset($this->filteredEntities[$entity['login']]);
  2665. }
  2666. if ($entity['Down'] == '1') {
  2667. unset($this->filteredEntities[$entity['login']]);
  2668. }
  2669. if ($entity['AlwaysOnline'] == '0') {
  2670. unset($this->filteredEntities[$entity['login']]);
  2671. }
  2672. if ($entity['Cash'] < '-' . $entity['Credit']) {
  2673. unset($this->filteredEntities[$entity['login']]);
  2674. }
  2675. }
  2676. break;
  2677. }
  2678. }
  2679. }
  2680. }
  2681. /**
  2682. * Down filter
  2683. *
  2684. * @param string $direction
  2685. * @param string $param
  2686. *
  2687. * @return void
  2688. */
  2689. protected function filterdown($direction, $param) {
  2690. if (!empty($param)) {
  2691. if (!empty($this->filteredEntities)) {
  2692. switch ($direction) {
  2693. case 'login':
  2694. foreach ($this->filteredEntities as $io => $entity) {
  2695. if ($this->downUsers[$entity['login']] != '1') {
  2696. unset($this->filteredEntities[$entity['login']]);
  2697. }
  2698. }
  2699. break;
  2700. }
  2701. }
  2702. }
  2703. }
  2704. /**
  2705. * Tariff filter
  2706. *
  2707. * @param string $direction
  2708. * @param string $param
  2709. *
  2710. * @return void
  2711. */
  2712. protected function filtertariff($direction, $param) {
  2713. if (!empty($param)) {
  2714. if (!empty($this->filteredEntities)) {
  2715. switch ($direction) {
  2716. case 'login':
  2717. foreach ($this->filteredEntities as $io => $entity) {
  2718. if ($entity['Tariff'] != $param) {
  2719. unset($this->filteredEntities[$entity['login']]);
  2720. }
  2721. }
  2722. break;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. /**
  2728. * Tariff filter
  2729. *
  2730. * @param string $direction
  2731. * @param string $param
  2732. *
  2733. * @return void
  2734. */
  2735. protected function filtertariffcontain($direction, $param) {
  2736. if (!empty($param)) {
  2737. if (!empty($this->filteredEntities)) {
  2738. switch ($direction) {
  2739. case 'login':
  2740. foreach ($this->filteredEntities as $io => $entity) {
  2741. if (!ispos($entity['Tariff'], $param)) {
  2742. unset($this->filteredEntities[$entity['login']]);
  2743. }
  2744. }
  2745. break;
  2746. }
  2747. }
  2748. }
  2749. }
  2750. /**
  2751. * Branch filter
  2752. *
  2753. * @param string $direction
  2754. * @param string $param
  2755. *
  2756. * @return void
  2757. */
  2758. protected function filterbranch($direction, $param) {
  2759. if (!empty($param)) {
  2760. if (!empty($this->filteredEntities)) {
  2761. switch ($direction) {
  2762. case 'login':
  2763. foreach ($this->filteredEntities as $io => $entity) {
  2764. if ($this->branches->userGetBranch($entity['login']) != $param) {
  2765. unset($this->filteredEntities[$entity['login']]);
  2766. }
  2767. }
  2768. break;
  2769. }
  2770. }
  2771. }
  2772. }
  2773. /**
  2774. * Users without branch filter
  2775. *
  2776. * @param string $direction
  2777. * @param string $param
  2778. *
  2779. * @return void
  2780. */
  2781. protected function filternobranch($direction, $param) {
  2782. if (!empty($param)) {
  2783. if (!empty($this->filteredEntities)) {
  2784. switch ($direction) {
  2785. case 'login':
  2786. foreach ($this->filteredEntities as $io => $entity) {
  2787. if ($this->branches->userGetBranch($entity['login'])) {
  2788. unset($this->filteredEntities[$entity['login']]);
  2789. }
  2790. }
  2791. break;
  2792. }
  2793. }
  2794. }
  2795. }
  2796. /**
  2797. * Districts filter
  2798. *
  2799. * @param string $direction
  2800. * @param string $param
  2801. *
  2802. * @return void
  2803. */
  2804. protected function filterdistrict($direction, $param) {
  2805. if (!empty($param)) {
  2806. if (!empty($this->filteredEntities)) {
  2807. switch ($direction) {
  2808. case 'login':
  2809. foreach ($this->filteredEntities as $io => $entity) {
  2810. if (!$this->districts->checkUserDistrictFast($entity['login'], $param)) {
  2811. unset($this->filteredEntities[$entity['login']]);
  2812. }
  2813. }
  2814. break;
  2815. }
  2816. }
  2817. }
  2818. }
  2819. /**
  2820. * No tariff users filter
  2821. *
  2822. * @param string $direction
  2823. * @param string $param
  2824. *
  2825. * @return void
  2826. */
  2827. protected function filternotariff($direction, $param) {
  2828. if (!empty($param)) {
  2829. if (!empty($this->filteredEntities)) {
  2830. switch ($direction) {
  2831. case 'login':
  2832. foreach ($this->filteredEntities as $io => $entity) {
  2833. if ($entity['Tariff'] != '*_NO_TARIFF_*') {
  2834. unset($this->filteredEntities[$entity['login']]);
  2835. }
  2836. }
  2837. break;
  2838. }
  2839. }
  2840. }
  2841. }
  2842. /**
  2843. * Users with scheduled tariff change filter
  2844. *
  2845. * @param string $direction
  2846. * @param string $param
  2847. *
  2848. * @return void
  2849. */
  2850. protected function filtertariffnm($direction, $param) {
  2851. if (!empty($param)) {
  2852. if (!empty($this->filteredEntities)) {
  2853. switch ($direction) {
  2854. case 'login':
  2855. foreach ($this->filteredEntities as $io => $entity) {
  2856. if (empty($entity['TariffChange'])) {
  2857. unset($this->filteredEntities[$entity['login']]);
  2858. }
  2859. }
  2860. break;
  2861. }
  2862. }
  2863. }
  2864. }
  2865. /**
  2866. * UKV tariff users filter
  2867. *
  2868. * @param string $direction
  2869. * @param string $param
  2870. *
  2871. * @return void
  2872. */
  2873. protected function filterukvtariff($direction, $param) {
  2874. if (!empty($param)) {
  2875. if (!empty($this->filteredEntities)) {
  2876. switch ($direction) {
  2877. case 'ukv':
  2878. foreach ($this->filteredEntities as $io => $entity) {
  2879. if ($entity['tariffid'] != $param) {
  2880. unset($this->filteredEntities[$entity['id']]);
  2881. }
  2882. }
  2883. break;
  2884. }
  2885. }
  2886. }
  2887. }
  2888. /**
  2889. * Numlist ID filter
  2890. *
  2891. * @param string $direction
  2892. * @param string $param
  2893. *
  2894. * @return void
  2895. */
  2896. protected function filternumlist($direction, $param) {
  2897. if (!empty($param)) {
  2898. if (!empty($this->filteredEntities)) {
  2899. switch ($direction) {
  2900. case 'numlist':
  2901. foreach ($this->filteredEntities as $io => $entity) {
  2902. if ($entity['numid'] != $param) {
  2903. unset($this->filteredEntities[$entity['id']]);
  2904. }
  2905. }
  2906. break;
  2907. }
  2908. }
  2909. }
  2910. }
  2911. /**
  2912. * Numlist notes contains filter
  2913. *
  2914. * @param string $direction
  2915. * @param string $param
  2916. *
  2917. * @return void
  2918. */
  2919. protected function filternumcontain($direction, $param) {
  2920. if (!empty($param)) {
  2921. if (!empty($this->filteredEntities)) {
  2922. switch ($direction) {
  2923. case 'numlist':
  2924. foreach ($this->filteredEntities as $io => $entity) {
  2925. if (!ispos($entity['notes'], $param)) {
  2926. unset($this->filteredEntities[$entity['id']]);
  2927. }
  2928. }
  2929. break;
  2930. }
  2931. }
  2932. }
  2933. }
  2934. /**
  2935. * Numlist notes not contains filter
  2936. *
  2937. * @param string $direction
  2938. * @param string $param
  2939. *
  2940. * @return void
  2941. */
  2942. protected function filternumnotcontain($direction, $param) {
  2943. if (!empty($param)) {
  2944. if (!empty($this->filteredEntities)) {
  2945. switch ($direction) {
  2946. case 'numlist':
  2947. foreach ($this->filteredEntities as $io => $entity) {
  2948. if (ispos($entity['notes'], $param)) {
  2949. unset($this->filteredEntities[$entity['id']]);
  2950. }
  2951. }
  2952. break;
  2953. }
  2954. }
  2955. }
  2956. }
  2957. /**
  2958. * Numlist not our user filter by mobile number
  2959. *
  2960. * @param string $direction
  2961. * @param string $param
  2962. *
  2963. * @return void
  2964. */
  2965. protected function filternumnotouruser($direction, $param) {
  2966. if (!empty($param)) {
  2967. if (!empty($this->filteredEntities)) {
  2968. switch ($direction) {
  2969. case 'numlist':
  2970. $this->extMobiles = new MobilesExt();
  2971. foreach ($this->filteredEntities as $io => $entity) {
  2972. $numlistMobile = $this->normalizePhoneFormat($entity['mobile']);
  2973. if (!empty($this->allUserData)) {
  2974. foreach ($this->allUserData as $eachUserLogin => $eachUserData) {
  2975. //base numbers comparison
  2976. if (ispos($this->normalizePhoneFormat($eachUserData['mobile']), $numlistMobile)) {
  2977. unset($this->filteredEntities[$entity['id']]);
  2978. break;
  2979. }
  2980. //check for additional mobile
  2981. $userExtMobiles = $this->extMobiles->getUserMobiles($eachUserLogin);
  2982. if (!empty($userExtMobiles)) {
  2983. foreach ($userExtMobiles as $ia => $eachExt) {
  2984. $additionalMobile = $this->normalizePhoneFormat($eachExt['mobile']);
  2985. if (!empty($additionalMobile)) {
  2986. if (ispos($this->normalizePhoneFormat($additionalMobile), $numlistMobile)) {
  2987. unset($this->filteredEntities[$entity['id']]);
  2988. break;
  2989. }
  2990. }
  2991. }
  2992. }
  2993. }
  2994. }
  2995. }
  2996. break;
  2997. }
  2998. }
  2999. }
  3000. }
  3001. /**
  3002. * UKV activity filter
  3003. *
  3004. * @param string $direction
  3005. * @param string $param
  3006. *
  3007. * @return void
  3008. */
  3009. protected function filterukvactive($direction, $param) {
  3010. if (!empty($param)) {
  3011. if (!empty($this->filteredEntities)) {
  3012. switch ($direction) {
  3013. case 'ukv':
  3014. foreach ($this->filteredEntities as $io => $entity) {
  3015. if ($entity['active'] != '1') {
  3016. unset($this->filteredEntities[$entity['id']]);
  3017. }
  3018. }
  3019. break;
  3020. }
  3021. }
  3022. }
  3023. }
  3024. /**
  3025. * Employee appointment filter
  3026. *
  3027. * @param string $direction
  3028. * @param string $param
  3029. *
  3030. * @return void
  3031. */
  3032. protected function filteremployeeappointment($direction, $param) {
  3033. if (!empty($param)) {
  3034. if (!empty($this->filteredEntities)) {
  3035. switch ($direction) {
  3036. case 'employee':
  3037. $search = trim($param);
  3038. foreach ($this->filteredEntities as $io => $entity) {
  3039. if (!ispos($entity['appointment'], $search)) {
  3040. unset($this->filteredEntities[$entity['id']]);
  3041. }
  3042. }
  3043. break;
  3044. }
  3045. }
  3046. }
  3047. }
  3048. /**
  3049. * Employee activity filter
  3050. *
  3051. * @param string $direction
  3052. * @param string $param
  3053. *
  3054. * @return void
  3055. */
  3056. protected function filteremployeeactive($direction, $param) {
  3057. if (!empty($param)) {
  3058. if (!empty($this->filteredEntities)) {
  3059. switch ($direction) {
  3060. case 'employee':
  3061. foreach ($this->filteredEntities as $io => $entity) {
  3062. if ($entity['active'] != '1') {
  3063. unset($this->filteredEntities[$entity['id']]);
  3064. }
  3065. }
  3066. break;
  3067. }
  3068. }
  3069. }
  3070. }
  3071. /**
  3072. * UKV debtors filter
  3073. *
  3074. * @param string $direction
  3075. * @param string $param
  3076. *
  3077. * @return void
  3078. */
  3079. protected function filterukvdebtor($direction, $param) {
  3080. if (!empty($param)) {
  3081. if (!empty($this->filteredEntities)) {
  3082. switch ($direction) {
  3083. case 'ukv':
  3084. //one time debtors loading on filter run
  3085. if (!$this->ukvDebtorsLoaded) {
  3086. $this->ukvDebtors = $this->ukv->getDebtors();
  3087. $this->ukvDebtorsLoaded = true;
  3088. }
  3089. foreach ($this->filteredEntities as $io => $entity) {
  3090. if (!isset($this->ukvDebtors[$entity['id']])) {
  3091. unset($this->filteredEntities[$entity['id']]);
  3092. }
  3093. }
  3094. break;
  3095. }
  3096. }
  3097. }
  3098. }
  3099. /**
  3100. * Just sets ext mobiles extraction flag
  3101. *
  3102. * @param string $direction
  3103. * @param string $param
  3104. *
  3105. * @return void
  3106. */
  3107. protected function filterextmobiles($direction, $param) {
  3108. $this->useExtMobiles = true;
  3109. }
  3110. /**
  3111. *
  3112. * @param string $direction
  3113. * @param string $param
  3114. *
  3115. * @return void
  3116. */
  3117. protected function filterrealname($direction, $param) {
  3118. if (!empty($param)) {
  3119. if (!empty($this->filteredEntities)) {
  3120. switch ($direction) {
  3121. case 'login':
  3122. $search = trim($param);
  3123. foreach ($this->filteredEntities as $io => $entity) {
  3124. if (!ispos($entity['realname'], $search)) {
  3125. unset($this->filteredEntities[$entity['login']]);
  3126. }
  3127. }
  3128. break;
  3129. case 'ukv':
  3130. $search = trim($param);
  3131. foreach ($this->filteredEntities as $io => $entity) {
  3132. $userRealName = $entity['realname'];
  3133. if (!ispos($userRealName, $search)) {
  3134. unset($this->filteredEntities[$entity['id']]);
  3135. }
  3136. }
  3137. break;
  3138. case 'employee':
  3139. $search = trim($param);
  3140. foreach ($this->filteredEntities as $io => $entity) {
  3141. $employeeRealName = $this->filteredEntities[$entity['id']]['name'];
  3142. if (!ispos($employeeRealName, $search)) {
  3143. unset($this->filteredEntities[$entity['id']]);
  3144. }
  3145. }
  3146. break;
  3147. }
  3148. }
  3149. }
  3150. }
  3151. }