api.taskman.php 153 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905
  1. <?php
  2. /**
  3. * Returns tag id selector
  4. *
  5. * @param string $name
  6. * @param string $label
  7. * @return string
  8. */
  9. function em_TagSelector($name, $label = '', $selected = '', $br = false) {
  10. $alltypes = stg_get_alltagnames();
  11. $allltags = array('NULL' => '-');
  12. if (!empty($alltypes)) {
  13. foreach ($alltypes as $io => $eachtype) {
  14. $allltags[$io] = $eachtype . " (" . $io . ")";
  15. }
  16. }
  17. $result = wf_Selector($name, $allltags, $label, $selected, $br);
  18. return ($result);
  19. }
  20. /**
  21. * Renders employee list with required controls and creation form
  22. *
  23. * @return void
  24. */
  25. function em_EmployeeRenderList() {
  26. $result = '';
  27. $allEmployee = ts_GetAllEmployeeData();
  28. $allTagNames = stg_get_alltagnames();
  29. $messages = new UbillingMessageHelper();
  30. if (!empty($allEmployee)) {
  31. $cells = wf_TableCell(__('ID'));
  32. $cells .= wf_TableCell(__('Real Name'));
  33. $cells .= wf_TableCell(__('Active'));
  34. $cells .= wf_TableCell(__('Appointment'));
  35. $cells .= wf_TableCell(__('Mobile'));
  36. $cells .= wf_TableCell(__('Chat ID') . ' ' . __('Telegram'));
  37. $cells .= wf_TableCell(__('Administrator'));
  38. $cells .= wf_TableCell(__('Tag'));
  39. $cells .= wf_TableCell(__('Monthly top up limit'));
  40. $cells .= wf_TableCell(__('Actions'));
  41. $rows = wf_TableRow($cells, 'row1');
  42. foreach ($allEmployee as $ion => $eachemployee) {
  43. $cells = wf_TableCell($eachemployee['id']);
  44. $cells .= wf_TableCell($eachemployee['name']);
  45. $cells .= wf_TableCell(web_bool_led($eachemployee['active']), '', '', 'sorttable_customkey="' . $eachemployee['active'] . '"');
  46. $cells .= wf_TableCell($eachemployee['appointment']);
  47. $cells .= wf_TableCell($eachemployee['mobile']);
  48. $cells .= wf_TableCell($eachemployee['telegram']);
  49. $admlogin = $eachemployee['admlogin'];
  50. if (!empty($admlogin)) {
  51. if (file_exists(USERS_PATH . $admlogin)) {
  52. $admlogin = wf_Link('?module=permissions&edit=' . $admlogin, web_profile_icon() . ' ' . $admlogin, false);
  53. }
  54. }
  55. $cells .= wf_TableCell($admlogin);
  56. $employeeTagId = $eachemployee['tagid'];
  57. $employeeTagName = (!empty($employeeTagId)) ? $allTagNames[$employeeTagId] : '';
  58. $employeeTagLabel = (!empty($employeeTagName)) ? $employeeTagName . ' (' . $employeeTagId . ')' : '';
  59. $cells .= wf_TableCell($employeeTagLabel);
  60. $cells .= wf_TableCell($eachemployee['amountLimit']);
  61. $urlDelete = '?module=employee&deleteemployee=' . $eachemployee['id'];
  62. $urlEdit = '?module=employee&editemployee=' . $eachemployee['id'];
  63. $urlCancel = '?module=employee';
  64. $actions = wf_ConfirmDialog($urlDelete, web_delete_icon(), $messages->getDeleteAlert(), '', $urlCancel, __('Delete') . '?');
  65. $actions .= wf_Link($urlEdit, web_edit_icon());
  66. $cells .= wf_TableCell($actions);
  67. $rows .= wf_TableRow($cells, 'row5');
  68. }
  69. //existing employee list
  70. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  71. } else {
  72. $result .= $messages->getStyledMessage(__('Nothing to show'), 'warning');
  73. }
  74. $creationLink = wf_modalAuto(wf_img_sized('skins/add_icon.png', __('Create new employee')), __('Create new employee'), em_EmployeeCreateForm());
  75. show_window(__('Employee') . ' ' . $creationLink, $result);
  76. }
  77. /**
  78. * Renders employee creation form
  79. *
  80. * @return string
  81. */
  82. function em_EmployeeCreateForm() {
  83. $result = '';
  84. $inputs = wf_HiddenInput('addemployee', 'true');
  85. $inputs .= wf_TextInput('employeename', 'Employee real name', '', true, 25);
  86. $inputs .= wf_TextInput('employeejob', 'Appointment', '', true, 15);
  87. $inputs .= wf_TextInput('employeemobile', 'Mobile', '', true, 15, 'mobile');
  88. $inputs .= wf_TextInput('employeetelegram', 'Chat ID', '', true, 15, 'sigint');
  89. $inputs .= wf_TextInput('employeeadmlogin', 'Administrator', '', true, 15);
  90. $inputs .= em_TagSelector('editadtagid', __('Tag'));
  91. $inputs .= wf_delimiter(0);
  92. $inputs .= wf_TextInput('amountLimit', 'Monthly top up limit', '', true, 5, 'finance');
  93. $inputs .= wf_delimiter(0);
  94. $inputs .= wf_Submit(__('Create new employee'));
  95. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  96. return ($result);
  97. }
  98. /**
  99. * Saves changes in existing employee
  100. *
  101. * @param int $editemployee
  102. *
  103. * @return void
  104. */
  105. function em_EmployeeSave($editemployee) {
  106. $editemployee = ubRouting::filters($editemployee, 'int');
  107. if (ubRouting::checkPost('editname')) {
  108. $employeeDb = new NyanORM('employee');
  109. $actFlag = (ubRouting::checkPost('editactive')) ? 1 : 0;
  110. $amountLim = (ubRouting::checkPost('amountLimit')) ? ubRouting::post('amountLimit') : 0;
  111. $employeeDb->data('name', ubRouting::post('editname', 'mres'));
  112. $employeeDb->data('appointment', ubRouting::post('editappointment', 'mres'));
  113. $employeeDb->data('mobile', ubRouting::post('editmobile', 'mres'));
  114. $employeeDb->data('telegram', ubRouting::post('edittelegram', 'mres'));
  115. $employeeDb->data('admlogin', ubRouting::post('editadmlogin', 'mres'));
  116. $employeeDb->data('tagid', ubRouting::post('editadtagid', 'int'));
  117. $employeeDb->data('amountLimit', $amountLim);
  118. $employeeDb->data('active', $actFlag);
  119. $employeeDb->where('id', '=', $editemployee);
  120. $employeeDb->save();
  121. log_register('EMPLOYEE CHANGE [' . $editemployee . ']');
  122. }
  123. }
  124. /**
  125. * Renders employee editing form
  126. *
  127. * @param int $editemployee
  128. *
  129. * @return string
  130. */
  131. function em_employeeEditForm($editemployee) {
  132. $result = '';
  133. $editemployee = ubRouting::filters($editemployee, 'int');
  134. $employeedata = stg_get_employee_data($editemployee);
  135. $actflag = ($employeedata['active']) ? true : false;
  136. $editinputs = wf_TextInput('editname', 'Real Name', $employeedata['name'], true, 20);
  137. $editinputs .= wf_TextInput('editappointment', 'Appointment', $employeedata['appointment'], true, 20);
  138. $editinputs .= wf_TextInput('editmobile', __('Mobile'), $employeedata['mobile'], true, 20);
  139. $editinputs .= wf_TextInput('edittelegram', __('Chat ID') . ' ' . __('Telegram'), $employeedata['telegram'], true, 20, 'sigint');
  140. $editinputs .= wf_TextInput('editadmlogin', __('Administrator'), $employeedata['admlogin'], true, 20);
  141. $editinputs .= em_TagSelector('editadtagid', __('Tag'), $employeedata['tagid'], true);
  142. $editinputs .= wf_TextInput('amountLimit', __('Monthly top up limit'), $employeedata['amountLimit'], true, 20, 'finance');
  143. $editinputs .= wf_CheckInput('editactive', 'Active', true, $actflag);
  144. $editinputs .= wf_Submit('Save');
  145. $result .= wf_Form('', 'POST', $editinputs, 'glamour');
  146. return ($result);
  147. }
  148. /**
  149. * Renders existing job type editing form
  150. *
  151. * @param int $editjobId
  152. *
  153. * @return string
  154. */
  155. function em_JobTypeEditForm($editjobId) {
  156. $result = '';
  157. $editjobId = ubRouting::filters($editjobId, 'int');
  158. $jobdata = stg_get_jobtype_name($editjobId);
  159. $jobcolor = stg_get_jobtype_color($editjobId);
  160. $jobinputs = wf_TextInput('editjobtype', 'Job type', $jobdata, true, 20);
  161. $jobinputs .= wf_ColPicker('editjobcolor', __('Color'), $jobcolor, true, 10);
  162. $jobinputs .= wf_Submit('Save');
  163. $result .= wf_Form('', 'POST', $jobinputs, 'glamour');
  164. return ($result);
  165. }
  166. /**
  167. * Saves changes in existing job type
  168. *
  169. * @param type $editjobId
  170. *
  171. * @return void
  172. */
  173. function em_JobTypeSave($editjobId) {
  174. if (ubRouting::checkPost('editjobtype')) {
  175. $jobTypesDb = new NyanORM('jobtypes');
  176. $jobTypesDb->data('jobname', ubRouting::post('editjobtype', 'mres'));
  177. $jobTypesDb->data('jobcolor', ubRouting::post('editjobcolor', 'mres'));
  178. $jobTypesDb->where('id', '=', $editjobId);
  179. $jobTypesDb->save();
  180. log_register('JOBTYPE CHANGE [' . $editjobId . '] `' . ubRouting::post('editjobtype') . '`');
  181. }
  182. }
  183. /**
  184. * Renders jobtypes edit/creation/deletion form and list
  185. *
  186. * @return void
  187. */
  188. function em_JobTypeRenderList() {
  189. $result = '';
  190. $messages = new UbillingMessageHelper();
  191. $allJobTypes = ts_GetAllJobtypesData();
  192. if (!empty($allJobTypes)) {
  193. $cells = wf_TableCell(__('ID'));
  194. $cells .= wf_TableCell(__('Job type'));
  195. $cells .= wf_TableCell(__('Color'));
  196. $cells .= wf_TableCell(__('Actions'));
  197. $rows = wf_TableRow($cells, 'row1');
  198. foreach ($allJobTypes as $ion => $eachjob) {
  199. $cells = wf_TableCell($eachjob['id']);
  200. $cells .= wf_TableCell($eachjob['jobname']);
  201. $jobColor = (!empty($eachjob['jobcolor'])) ? wf_tag('font', false, '', 'color="' . $eachjob['jobcolor'] . '"') . $eachjob['jobcolor'] . wf_tag('font', true) : '';
  202. $cells .= wf_TableCell($jobColor);
  203. $urlDelete = '?module=employee&deletejob=' . $eachjob['id'];
  204. $urlEdit = '?module=employee&editjob=' . $eachjob['id'];
  205. $urlCancel = '?module=employee';
  206. $actionlinks = wf_ConfirmDialog($urlDelete, web_delete_icon(), $messages->getDeleteAlert(), '', $urlCancel, __('Delete') . '?');
  207. $actionlinks .= wf_Link($urlEdit, web_edit_icon());
  208. $cells .= wf_TableCell($actionlinks);
  209. $rows .= wf_TableRow($cells, 'row5');
  210. }
  211. $result .= wf_TableBody($rows, '100%', '0', 'sortable');
  212. } else {
  213. $result .= $messages->getStyledMessage(__('Nothing to show'), 'warning');
  214. }
  215. $createJtLabel = __('Create') . ' ' . __('Job type');
  216. $creationLink = wf_modalAuto(wf_img_sized('skins/add_icon.png', $createJtLabel), $createJtLabel, em_JobTypeCreateForm());
  217. show_window(__('Job types') . ' ' . $creationLink, $result);
  218. }
  219. /**
  220. * Returns new job type creation form
  221. *
  222. * @return string
  223. */
  224. function em_JobTypeCreateForm() {
  225. $result = '';
  226. $inputs = wf_HiddenInput('addjobtype', 'true');
  227. $inputs .= wf_TextInput('newjobtype', __('Job type'), '', true, 30);
  228. $inputs .= wf_ColPicker('newjobcolor', __('Color'), '', true, 8);
  229. $inputs .= wf_Submit(__('Create'));
  230. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  231. return ($result);
  232. }
  233. /**
  234. * Creates new employee in database
  235. *
  236. * @param string $name
  237. * @param string $job
  238. * @param string $mobile
  239. * @param string $admlogin
  240. *
  241. * @return void
  242. */
  243. function em_EmployeeAdd($name, $job, $mobile = '', $telegram = '', $admlogin = '', $tagid = '', $amountLimit = '') {
  244. $name = mysql_real_escape_string(trim($name));
  245. $job = mysql_real_escape_string(trim($job));
  246. $mobile = mysql_real_escape_string($mobile);
  247. $telegram = mysql_real_escape_string($telegram);
  248. $admlogin = mysql_real_escape_string($admlogin);
  249. $tagid = mysql_real_escape_string($tagid);
  250. $amountLimit = (empty($amountLimit)) ? 0 : $amountLimit;
  251. $query = "INSERT INTO `employee` (`id` , `name` , `appointment`, `mobile`, `telegram`, `admlogin`, `active`, `tagid`, `amountLimit`)
  252. VALUES (NULL , '" . $name . "', '" . $job . "','" . $mobile . "','" . $telegram . "' ,'" . $admlogin . "' , '1', " . $tagid . ", " . $amountLimit . "); ";
  253. nr_query($query);
  254. $employee_id = simple_query("SELECT LAST_INSERT_ID() as id");
  255. $employee_id = $employee_id['id'];
  256. log_register('EMPLOYEE ADD [' . $employee_id . ']`' . $name . '` JOB `' . $job . '`');
  257. }
  258. /**
  259. * Deletes existing employee from database
  260. *
  261. * @param int $id
  262. *
  263. * @return void
  264. */
  265. function em_EmployeeDelete($id) {
  266. $id = vf($id, 3);
  267. $query = "DELETE from `employee` WHERE `id`=" . $id;
  268. nr_query($query);
  269. log_register('EMPLOYEE DEL [' . $id . ']');
  270. }
  271. /**
  272. * Creates new jobtype in database
  273. *
  274. * @param string $jobtype
  275. * @param string $jobcolor
  276. *
  277. * @return void
  278. */
  279. function stg_add_jobtype($jobtype, $jobcolor) {
  280. $jobtype = mysql_real_escape_string(trim($jobtype));
  281. $jobcolor = mysql_real_escape_string($jobcolor);
  282. $query = "INSERT INTO `jobtypes` (`id` , `jobname`, `jobcolor`)
  283. VALUES (NULL , '" . $jobtype . "', '" . $jobcolor . "');";
  284. nr_query($query);
  285. log_register('JOBTYPE ADD `' . $jobtype . '`');
  286. }
  287. /**
  288. * Deletes existing job type from database
  289. *
  290. * @param int $id
  291. *
  292. * @return void
  293. */
  294. function stg_delete_jobtype($id) {
  295. $id = vf($id, 3);
  296. $query = "DELETE from `jobtypes` WHERE `id`=" . $id;
  297. nr_query($query);
  298. log_register('JOBTYPE DEL [' . $id . ']');
  299. }
  300. /**
  301. * Returns employee name from database by its ID
  302. *
  303. * @param int $id
  304. * @return string
  305. */
  306. function stg_get_employee_name($id) {
  307. $id = vf($id, 3);
  308. $query = 'SELECT `name` from `employee` WHERE `id`="' . $id . '"';
  309. $employee = simple_query($query);
  310. return ($employee['name']);
  311. }
  312. /**
  313. * Returns employee data array by its ID
  314. *
  315. * @param int $id
  316. * @return array
  317. */
  318. function stg_get_employee_data($id) {
  319. $id = vf($id, 3);
  320. $query = 'SELECT * from `employee` WHERE `id`="' . $id . '"';
  321. $employee = simple_query($query);
  322. return ($employee);
  323. }
  324. /**
  325. * Returns jobtype name by its ID
  326. *
  327. * @param int $id
  328. * @return string
  329. */
  330. function stg_get_jobtype_name($id) {
  331. $query = 'SELECT `jobname` from `jobtypes` WHERE `id`="' . $id . '"';
  332. $jobtype = simple_query($query);
  333. return ($jobtype['jobname']);
  334. }
  335. /**
  336. * Returns jobtype color by its ID
  337. *
  338. * @param int $id
  339. * @return string
  340. */
  341. function stg_get_jobtype_color($id) {
  342. $query = 'SELECT `jobcolor` from `jobtypes` WHERE `id`="' . $id . '"';
  343. $jobcolor = simple_query($query);
  344. return ($jobcolor['jobcolor']);
  345. }
  346. /**
  347. * Renders list with controls for jobs done for some user
  348. *
  349. * @param string $username
  350. *
  351. * @return void
  352. */
  353. function web_showPreviousJobs($username) {
  354. $query_jobs = 'SELECT * FROM `jobs` WHERE `login`="' . $username . '" ORDER BY `id` DESC';
  355. $alljobs = simple_queryall($query_jobs);
  356. $allemployee = ts_GetAllEmployee();
  357. $alljobtypes = ts_GetAllJobtypes();
  358. $activeemployee = ts_GetActiveEmployee();
  359. $cells = wf_TableCell(__('ID'));
  360. $cells .= wf_tableCell(__('Date'));
  361. $cells .= wf_TableCell(__('Worker'));
  362. $cells .= wf_TableCell(__('Job type'));
  363. $cells .= wf_TableCell(__('Notes'));
  364. if (cfr('JOBSMGMT')) {
  365. $cells .= wf_TableCell(__('Actions'));
  366. }
  367. $rows = wf_TableRow($cells, 'row1');
  368. if (!empty($alljobs)) {
  369. foreach ($alljobs as $ion => $eachjob) {
  370. //backlink to taskman if some TASKID inside
  371. if (ispos($eachjob['note'], 'TASKID:[')) {
  372. $taskid = vf($eachjob['note'], 3);
  373. $jobnote = wf_Link("?module=taskman&&edittask=" . $taskid, __('Task is done') . ' #' . $taskid, false, '');
  374. } else {
  375. $jobnote = $eachjob['note'];
  376. }
  377. $cells = wf_TableCell($eachjob['id']);
  378. $cells .= wf_tableCell($eachjob['date']);
  379. $cells .= wf_TableCell(@$allemployee[$eachjob['workerid']]);
  380. $cells .= wf_TableCell(@$alljobtypes[$eachjob['jobid']]);
  381. $cells .= wf_TableCell($jobnote);
  382. if (cfr('JOBSMGMT')) {
  383. $cells .= wf_TableCell(wf_JSAlert('?module=jobs&username=' . $username . '&deletejob=' . $eachjob['id'] . '', web_delete_icon(), 'Are you serious'));
  384. }
  385. $rows .= wf_TableRow($cells, 'row3');
  386. }
  387. }
  388. if (cfr('JOBSMGMT')) {
  389. //onstruct job create form
  390. $curdatetime = curdatetime();
  391. $inputs = wf_HiddenInput('addjob', 'true');
  392. $inputs .= wf_HiddenInput('jobdate', $curdatetime);
  393. $inputs .= wf_TableCell('');
  394. $inputs .= wf_tableCell($curdatetime);
  395. $inputs .= wf_TableCell(wf_Selector('worker', $activeemployee, '', '', false));
  396. $inputs .= wf_TableCell(wf_Selector('jobtype', $alljobtypes, '', '', false));
  397. $inputs .= wf_TableCell(wf_TextInput('notes', '', '', false, '20'));
  398. $inputs .= wf_TableCell(wf_Submit('Create'));
  399. $inputs = wf_TableRow($inputs, 'row2');
  400. $addform = wf_Form("", 'POST', $inputs, '');
  401. if ((!empty($activeemployee)) and (!empty($alljobtypes))) {
  402. $rows .= $addform;
  403. } else {
  404. show_error(__('No job types and employee available'));
  405. }
  406. }
  407. $result = wf_TableBody($rows, '100%', '0', '');
  408. show_window(__('Jobs'), $result);
  409. }
  410. /**
  411. * Deletes some job from database by its ID
  412. *
  413. * @param int $jobid
  414. *
  415. * @return void
  416. */
  417. function stg_delete_job($jobid) {
  418. $jobid = vf($jobid, 3);
  419. $query = "DELETE from `jobs` WHERE `id`='" . $jobid . "'";
  420. nr_query($query);
  421. log_register('JOB DELETE [' . $jobid . ']');
  422. }
  423. /**
  424. * Creates new job in database
  425. *
  426. * @param string $login
  427. * @param string $date
  428. * @param int $worker_id
  429. * @param int $jobtype_id
  430. * @param string $job_notes
  431. *
  432. * @return void
  433. */
  434. function stg_add_new_job($login, $date, $worker_id, $jobtype_id, $job_notes) {
  435. $job_notes = mysql_real_escape_string(trim($job_notes));
  436. $datetime = curdatetime();
  437. $query = "INSERT INTO `jobs` (`id` , `date` , `jobid` , `workerid` , `login` ,`note`) VALUES (
  438. NULL , '" . $datetime . "', '" . $jobtype_id . "', '" . $worker_id . "', '" . $login . "', '" . $job_notes . "'); ";
  439. nr_query($query);
  440. log_register('JOB ADD W:[' . $worker_id . '] J:[' . $jobtype_id . '] (' . $login . ')');
  441. }
  442. //
  443. // New Task management API - old is shitty and exists only for backward compatibility
  444. //
  445. /**
  446. * Returns login detected by address
  447. *
  448. * @param string $address
  449. * @return string
  450. */
  451. function ts_DetectUserByAddress($address) {
  452. $telepathy = new Telepathy(false, true);
  453. return ($telepathy->getLogin($address));
  454. }
  455. /**
  456. * Returns array of all existing employees as id=>name
  457. *
  458. * @return array
  459. */
  460. function ts_GetAllEmployee() {
  461. $query = "SELECT * from `employee`";
  462. $allemployee = simple_queryall($query);
  463. $result = array();
  464. if (!empty($allemployee)) {
  465. foreach ($allemployee as $io => $each) {
  466. $result[$each['id']] = $each['name'];
  467. }
  468. }
  469. return ($result);
  470. }
  471. /**
  472. * Returns array of all existing employees as id=>employeeData
  473. *
  474. * @return array
  475. */
  476. function ts_GetAllEmployeeData() {
  477. $query = "SELECT * from `employee`";
  478. $allemployee = simple_queryall($query);
  479. $result = array();
  480. if (!empty($allemployee)) {
  481. foreach ($allemployee as $io => $each) {
  482. $result[$each['id']] = $each;
  483. }
  484. }
  485. return ($result);
  486. }
  487. /**
  488. * Returns array of available jobtypes as id=>name
  489. *
  490. * @return array
  491. */
  492. function ts_GetAllJobtypes() {
  493. $query = "SELECT * from `jobtypes`";
  494. $alljt = simple_queryall($query);
  495. $result = array();
  496. if (!empty($alljt)) {
  497. foreach ($alljt as $io => $each) {
  498. $result[$each['id']] = $each['jobname'];
  499. }
  500. }
  501. return ($result);
  502. }
  503. /**
  504. * Returns array of available jobtype colors as id=>color
  505. *
  506. * @return array
  507. */
  508. function ts_GetAllJobColors() {
  509. $query = "SELECT * from `jobtypes`";
  510. $alljt = simple_queryall($query);
  511. $result = array();
  512. if (!empty($alljt)) {
  513. foreach ($alljt as $io => $each) {
  514. $color = (!empty($each['jobcolor'])) ? $each['jobcolor'] : '';
  515. $result[$each['id']] = $color;
  516. }
  517. }
  518. return ($result);
  519. }
  520. /**
  521. * Returns array of all jobtypes data as id=>jobtype data
  522. *
  523. * @return array
  524. */
  525. function ts_GetAllJobtypesData() {
  526. $query = "SELECT * from `jobtypes`";
  527. $alljt = simple_queryall($query);
  528. $result = array();
  529. if (!empty($alljt)) {
  530. foreach ($alljt as $io => $each) {
  531. $result[$each['id']] = $each;
  532. }
  533. }
  534. return ($result);
  535. }
  536. /**
  537. * Returns all jobtypes custom stylesheets for jq fullcalendar listing
  538. *
  539. * @return string
  540. */
  541. function ts_GetAllJobtypesColorStyles() {
  542. $customJobColorStyle = '<style>';
  543. $alljobcolors = ts_GetAllJobColors();
  544. if (!empty($alljobcolors)) {
  545. foreach ($alljobcolors as $jcio => $eachjobcolor) {
  546. if (!empty($eachjobcolor)) {
  547. $customJobColorStyleName = 'jobcolorcustom_' . $jcio;
  548. $customJobColorStyle .= '.' . $customJobColorStyleName . ',
  549. .' . $customJobColorStyleName . ' div,
  550. .' . $customJobColorStyleName . ' span {
  551. background-color: ' . $eachjobcolor . ';
  552. border-color: ' . $eachjobcolor . ';
  553. color: #FFFFFF;
  554. }';
  555. }
  556. }
  557. }
  558. //anyone optional coloring
  559. $customJobColorStyle .= '.jobcoloranyone,
  560. .jobcoloranyone div,
  561. .jobcoloranyone span {
  562. background-color: #d04e00;
  563. border-color: #d04e00;
  564. color: #FFFFFF;
  565. }';
  566. $customJobColorStyle .= '</style>' . "\n";
  567. return ($customJobColorStyle);
  568. }
  569. /**
  570. * Returns array of active employees as id=>name
  571. *
  572. * @return array
  573. */
  574. function ts_GetActiveEmployee() {
  575. $query = "SELECT * from `employee` WHERE `active`='1'";
  576. $allemployee = simple_queryall($query);
  577. $result = array();
  578. if (!empty($allemployee)) {
  579. foreach ($allemployee as $io => $each) {
  580. $result[$each['id']] = $each['name'];
  581. }
  582. }
  583. return ($result);
  584. }
  585. /**
  586. * Returns array of active employees as id=>login
  587. *
  588. * @return array
  589. */
  590. function ts_GetActiveEmployeeLogins() {
  591. $query = "SELECT * from `employee` WHERE `active`='1'";
  592. $allemployee = simple_queryall($query);
  593. $result = array();
  594. if (!empty($allemployee)) {
  595. foreach ($allemployee as $io => $each) {
  596. if (!empty($each['admlogin'])) {
  597. $result[$each['id']] = $each['admlogin'];
  598. }
  599. }
  600. }
  601. return ($result);
  602. }
  603. /**
  604. * Returns jq fullcalendar data for jobreport module
  605. *
  606. * @return string
  607. */
  608. function ts_JGetJobsReport() {
  609. $allemployee = ts_GetAllEmployee();
  610. $alljobtypes = ts_GetAllJobtypes();
  611. $cyear = curyear();
  612. $query = "SELECT * from `jobs` WHERE `date` LIKE '" . $cyear . "-%' ORDER BY `id` DESC";
  613. $alljobs = simple_queryall($query);
  614. $i = 1;
  615. $jobcount = sizeof($alljobs);
  616. $result = '';
  617. if (!empty($alljobs)) {
  618. foreach ($alljobs as $io => $eachjob) {
  619. if ($i != $jobcount) {
  620. $thelast = ',';
  621. } else {
  622. $thelast = '';
  623. }
  624. $startdate = strtotime($eachjob['date']);
  625. $startdate = date("Y, n-1, j", $startdate);
  626. $result .= "
  627. {
  628. title: '" . $allemployee[$eachjob['workerid']] . " - " . @$alljobtypes[$eachjob['jobid']] . "',
  629. start: new Date(" . $startdate . "),
  630. end: new Date(" . $startdate . "),
  631. url: '?module=userprofile&username=" . $eachjob['login'] . "'
  632. }
  633. " . $thelast;
  634. $i++;
  635. }
  636. }
  637. return ($result);
  638. }
  639. /**
  640. * Returns data for jq fullcalendar widget with undone tasks
  641. *
  642. * @global object $ubillingConfig
  643. * @return string
  644. */
  645. function ts_JGetUndoneTasks() {
  646. global $ubillingConfig;
  647. $altCfg = $ubillingConfig->getAlter();
  648. if (@$altCfg['TASKMAN_ANYONE_COLORING']) {
  649. $anyoneId = $altCfg['TASKMAN_ANYONE_COLORING'];
  650. } else {
  651. $anyoneId = false;
  652. }
  653. $showAllYearsTasks = $ubillingConfig->getAlterParam('TASKMAN_SHOW_ALL_YEARS_TASKS');
  654. $advFiltersEnabled = $ubillingConfig->getAlterParam('TASKMAN_ADV_FILTERS');
  655. $branchConsider = ($ubillingConfig->getAlterParam('BRANCHES_ENABLED')
  656. and $ubillingConfig->getAlterParam('TASKMAN_BRANCHES_CONSIDER_ON'));
  657. $depthMonthLimit = $ubillingConfig->getAlterParam('TASKMAN_DEPTH_LIMIT', 0);
  658. $depthMonthLimit = ubRouting::filters($depthMonthLimit, 'int');
  659. //ADcomments init
  660. if ($altCfg['ADCOMMENTS_ENABLED']) {
  661. $adcomments = new ADcomments('TASKMAN');
  662. $adcFlag = true;
  663. } else {
  664. $adcFlag = false;
  665. }
  666. $allemployee = ts_GetAllEmployee();
  667. $alljobdata = ts_getAllJobtypesData();
  668. $curyear = curyear();
  669. $curmonth = date("m");
  670. $appendQuery = '';
  671. $dateFilter = '';
  672. $appendQueryJOIN = '';
  673. $appendQuerySelect = '';
  674. //date filters
  675. if (!$showAllYearsTasks and ($curmonth != 1 and $curmonth != 12)) {
  676. $dateFilter = "AND `startdate` LIKE '" . $curyear . "-%'";
  677. }
  678. if ($depthMonthLimit) {
  679. $depthDate = date("Y-m-d", strtotime('-' . $depthMonthLimit . ' months'));
  680. $dateFilter = "AND `startdate` > '" . $depthDate . "-%'";
  681. }
  682. $appendQuery .= $dateFilter;
  683. //per employee filtering
  684. $displaytype = (isset($_POST['displaytype'])) ? $_POST['displaytype'] : 'all';
  685. //administrator is cursed of some branch
  686. if (ts_isMeBranchCursed()) {
  687. $displaytype = 'onlyme';
  688. }
  689. if ($displaytype == 'onlyme') {
  690. $whoami = whoami();
  691. $curempid = ts_GetEmployeeByLogin($whoami);
  692. $appendQuery .= " AND `employee`='" . $curempid . "'";
  693. } else {
  694. if (ispos($displaytype, 'displayempid')) {
  695. $displayEmployeeId = ubRouting::filters($displaytype, 'int');
  696. $appendQuery .= " AND `employee`='" . $displayEmployeeId . "'";
  697. }
  698. }
  699. if ($advFiltersEnabled) {
  700. $appendQuery .= ts_AdvFiltersQuery();
  701. }
  702. if ($branchConsider) {
  703. $appendQueryJOIN = " LEFT JOIN `branchesusers` USING(`login`)
  704. LEFT JOIN `branches` ON `branchesusers`.`branchid` = `branches`.`id` ";
  705. $appendQuerySelect = ", `branches`.`name` AS `branch_name` ";
  706. }
  707. $query = "SELECT `taskman`.*, `jobtypes`.`jobname`" . $appendQuerySelect . " FROM `taskman`
  708. LEFT JOIN `jobtypes` ON `taskman`.`jobtype` = `jobtypes`.`id`
  709. " . $appendQueryJOIN . "
  710. WHERE `status`='0' " . $appendQuery . " ORDER BY `date` ASC";
  711. $allUndoneTasks = simple_queryall($query);
  712. $result = '';
  713. $i = 1;
  714. $taskcount = sizeof($allUndoneTasks);
  715. $branchName = '';
  716. if (!empty($allUndoneTasks)) {
  717. foreach ($allUndoneTasks as $io => $eachtask) {
  718. if ($i != $taskcount) {
  719. $thelast = ',';
  720. } else {
  721. $thelast = '';
  722. }
  723. $startdate = strtotime($eachtask['startdate']);
  724. $startdate = date("Y, n-1, j", $startdate);
  725. if ($eachtask['enddate'] != '') {
  726. $enddate = strtotime($eachtask['enddate']);
  727. $enddate = date("Y, n-1, j", $enddate);
  728. } else {
  729. $enddate = $startdate;
  730. }
  731. //custom task color preprocessing
  732. if (isset($alljobdata[$eachtask['jobtype']])) {
  733. if (!empty($alljobdata[$eachtask['jobtype']]['jobcolor'])) {
  734. $jobColorClass = 'jobcolorcustom_' . $eachtask['jobtype'];
  735. } else {
  736. $jobColorClass = 'undone';
  737. }
  738. } else {
  739. $jobColorClass = 'undone';
  740. }
  741. //anyone employee coloring
  742. if ($anyoneId) {
  743. if ($eachtask['employee'] == $anyoneId) {
  744. $jobColorClass = 'jobcoloranyone';
  745. }
  746. }
  747. //time ordering
  748. if (!empty($eachtask['starttime'])) {
  749. $startTime = $eachtask['starttime'];
  750. $startTime = substr($startTime, 0, 5) . ' ';
  751. $startTimeTimestamp = ', ' . str_replace(':', ', ', $startTime);
  752. } else {
  753. $startTime = '';
  754. $startTimeTimestamp = '';
  755. }
  756. //adcomments detect
  757. if ($adcFlag) {
  758. $adcommentsCount = $adcomments->getCommentsCount($eachtask['id']);
  759. } else {
  760. $adcommentsCount = 0;
  761. }
  762. if ($adcommentsCount > 0) {
  763. $adcText = ' (' . $adcommentsCount . ')';
  764. } else {
  765. $adcText = '';
  766. }
  767. // get users's branch
  768. $branchName = ($branchConsider) ? ' ' . $eachtask['branch_name'] . ' ' : '';
  769. $result .= "
  770. {
  771. id: " . $eachtask['id'] . ",
  772. title: '" . $startTime . $branchName . $eachtask['address'] . " - " . @$alljobdata[$eachtask['jobtype']]['jobname'] . $adcText . "',
  773. start: new Date(" . $startdate . $startTimeTimestamp . "),
  774. end: new Date(" . $enddate . "),
  775. className : '" . $jobColorClass . "',
  776. url: '?module=taskman&edittask=" . $eachtask['id'] . "'
  777. }
  778. " . $thelast;
  779. }
  780. }
  781. return ($result);
  782. }
  783. /**
  784. * Returns data for jq fullcalendar widget with done tasks
  785. *
  786. * @global object $ubillingConfig
  787. * @return string
  788. */
  789. function ts_JGetDoneTasks() {
  790. global $ubillingConfig;
  791. $altCfg = $ubillingConfig->getAlter();
  792. $showAllYearsTasks = $ubillingConfig->getAlterParam('TASKMAN_SHOW_ALL_YEARS_TASKS');
  793. $showExtendedDone = $ubillingConfig->getAlterParam('TASKMAN_SHOW_DONE_EXTENDED');
  794. $extendedDoneAlterStyling = $ubillingConfig->getAlterParam('TASKMAN_DONE_EXTENDED_ALTERSTYLING');
  795. $advFiltersEnabled = $ubillingConfig->getAlterParam('TASKMAN_ADV_FILTERS');
  796. $branchConsider = ($ubillingConfig->getAlterParam('BRANCHES_ENABLED')
  797. and $ubillingConfig->getAlterParam('TASKMAN_BRANCHES_CONSIDER_ON'));
  798. $depthMonthLimit = $ubillingConfig->getAlterParam('TASKMAN_DEPTH_LIMIT', 0);
  799. $depthMonthLimit = ubRouting::filters($depthMonthLimit, 'int');
  800. //ADcomments init
  801. if ($altCfg['ADCOMMENTS_ENABLED']) {
  802. $adcomments = new ADcomments('TASKMAN');
  803. $adcFlag = true;
  804. } else {
  805. $adcFlag = false;
  806. }
  807. $allemployee = ts_GetAllEmployee();
  808. $curyear = curyear();
  809. $curmonth = date("m");
  810. $appendQuery = '';
  811. $dateFilter = '';
  812. $appendQueryJOIN = '';
  813. $appendQuerySelect = '';
  814. //date filters
  815. if (!$showAllYearsTasks and ($curmonth != 1 and $curmonth != 12)) {
  816. $dateFilter = "AND `startdate` LIKE '" . $curyear . "-%'";
  817. }
  818. if ($depthMonthLimit) {
  819. $depthDate = date("Y-m-d", strtotime('-' . $depthMonthLimit . ' months'));
  820. $dateFilter = "AND `startdate` > '" . $depthDate . "-%'";
  821. }
  822. $appendQuery .= $dateFilter;
  823. //per employee filtering
  824. $displaytype = (isset($_POST['displaytype'])) ? $_POST['displaytype'] : 'all';
  825. //administrator is cursed of some branch
  826. if (ts_isMeBranchCursed()) {
  827. $displaytype = 'onlyme';
  828. }
  829. if ($displaytype == 'onlyme') {
  830. $whoami = whoami();
  831. $curempid = ts_GetEmployeeByLogin($whoami);
  832. $appendQuery .= " AND `employee`='" . $curempid . "'";
  833. } else {
  834. if (ispos($displaytype, 'displayempid')) {
  835. $displayEmployeeId = ubRouting::filters($displaytype, 'int');
  836. $appendQuery .= " AND `employee`='" . $displayEmployeeId . "'";
  837. }
  838. }
  839. if ($advFiltersEnabled) {
  840. $appendQuery .= ts_AdvFiltersQuery();
  841. }
  842. if ($branchConsider) {
  843. $appendQueryJOIN = " LEFT JOIN `branchesusers` USING(`login`)
  844. LEFT JOIN `branches` ON `branchesusers`.`branchid` = `branches`.`id` ";
  845. $appendQuerySelect = ", `branches`.`name` AS `branch_name` ";
  846. }
  847. $query = "SELECT `taskman`.*, `jobtypes`.`jobname`" . $appendQuerySelect . " FROM `taskman`
  848. LEFT JOIN `jobtypes` ON `taskman`.`jobtype` = `jobtypes`.`id`
  849. " . $appendQueryJOIN . "
  850. WHERE `status`='1' " . $appendQuery . " ORDER BY `date` ASC";
  851. $allDoneTasks = simple_queryall($query);
  852. $result = '';
  853. $i = 1;
  854. $taskcount = sizeof($allDoneTasks);
  855. $branchName = '';
  856. if (!empty($allDoneTasks)) {
  857. foreach ($allDoneTasks as $io => $eachtask) {
  858. if ($i != $taskcount) {
  859. $thelast = ',';
  860. } else {
  861. $thelast = '';
  862. }
  863. $startdate = strtotime($eachtask['startdate']);
  864. $startdate = date("Y, n-1, j", $startdate);
  865. if ($eachtask['enddate'] != '') {
  866. $enddate = strtotime($eachtask['enddate']);
  867. $enddate = date("Y, n-1, j", $enddate);
  868. } else {
  869. $enddate = $startdate;
  870. }
  871. //adcomments detect
  872. if ($adcFlag) {
  873. $adcommentsCount = $adcomments->getCommentsCount($eachtask['id']);
  874. } else {
  875. $adcommentsCount = 0;
  876. }
  877. if ($adcommentsCount > 0) {
  878. $adcText = ' (' . $adcommentsCount . ')';
  879. } else {
  880. $adcText = '';
  881. }
  882. $doneemploee = (!empty($allemployee[$eachtask['employeedone']])) ? $allemployee[$eachtask['employeedone']] : '';
  883. if ($showExtendedDone) {
  884. if ($extendedDoneAlterStyling) {
  885. $jobtype = (!empty($eachtask['jobname'])) ? ' - <span style="color: #1d1ab2;"><b>' . __('Job type') . ': </b></span>' . $eachtask['jobname'] : '';
  886. $jobnote = (!empty($eachtask['jobnote'])) ? ' - <span style="color: #1d1ab2;"><b>' . __('Job note') . ': </b></span>' . $eachtask['jobnote'] : '';
  887. $donenote = (!empty($eachtask['donenote'])) ? ' - <span style="color: #1d1ab2;"><b>' . __('Finish note') . ': </b></span>' . $eachtask['donenote'] : '';
  888. $donedate = (!empty($eachtask['enddate'])) ? ' - <span style="color: #1d1ab2;"><b>' . __('Finish date') . ': </b></span>' . $eachtask['enddate'] : '';
  889. $doneemploee = (!empty($allemployee[$eachtask['employeedone']])) ? '<b>' . $allemployee[$eachtask['employeedone']] . '</b>' : '';
  890. } else {
  891. $jobtype = (!empty($eachtask['jobname'])) ? ' - ' . __('Job type') . ': ' . $eachtask['jobname'] : '';
  892. $jobnote = (!empty($eachtask['jobnote'])) ? ' - ' . __('Job note') . ': ' . $eachtask['jobnote'] : '';
  893. $donenote = (!empty($eachtask['donenote'])) ? ' - ' . __('Finish note') . ': ' . $eachtask['donenote'] : '';
  894. $donedate = (!empty($eachtask['enddate'])) ? ' - ' . __('Finish date') . ': ' . $eachtask['enddate'] : '';
  895. }
  896. $extendInfo = $jobtype . $jobnote . $donenote . $donedate;
  897. } else {
  898. $extendInfo = '';
  899. }
  900. // get users's branch
  901. $branchName = ($branchConsider) ? ' ' . $eachtask['branch_name'] . ' ' : '';
  902. $result .= "
  903. {
  904. id: " . $eachtask['id'] . ",
  905. title: '" . $branchName . $eachtask['address'] . " - " . $doneemploee . $adcText . mysql_real_escape_string($extendInfo) . "',
  906. start: new Date(" . $startdate . "),
  907. end: new Date(" . $enddate . "),
  908. url: '?module=taskman&edittask=" . $eachtask['id'] . "',
  909. constraint: {start: '00:00', end: '00:00', dow: []}
  910. }
  911. " . $thelast;
  912. }
  913. }
  914. return ($result);
  915. }
  916. /**
  917. * Returns data for jq fullcalendar widget with all tasks
  918. *
  919. * @global object $ubillingConfig
  920. * @return string
  921. */
  922. function ts_JGetAllTasks() {
  923. global $ubillingConfig;
  924. $altCfg = $ubillingConfig->getAlter();
  925. $showAllYearsTasks = $ubillingConfig->getAlterParam('TASKMAN_SHOW_ALL_YEARS_TASKS');
  926. $advFiltersEnabled = $ubillingConfig->getAlterParam('TASKMAN_ADV_FILTERS');
  927. $branchConsider = ($ubillingConfig->getAlterParam('BRANCHES_ENABLED')
  928. and $ubillingConfig->getAlterParam('TASKMAN_BRANCHES_CONSIDER_ON'));
  929. $depthMonthLimit = $ubillingConfig->getAlterParam('TASKMAN_DEPTH_LIMIT', 0);
  930. $depthMonthLimit = ubRouting::filters($depthMonthLimit, 'int');
  931. //ADcomments init
  932. if ($altCfg['ADCOMMENTS_ENABLED']) {
  933. $adcomments = new ADcomments('TASKMAN');
  934. $adcFlag = true;
  935. } else {
  936. $adcFlag = false;
  937. }
  938. $allemployee = ts_GetAllEmployee();
  939. $alljobdata = ts_GetAllJobtypesData();
  940. $curyear = curyear();
  941. $curmonth = date("m");
  942. $appendQuery = '';
  943. $dateFilter = '';
  944. $appendQueryJOIN = '';
  945. $appendQuerySelect = '';
  946. //date filters
  947. if (!$showAllYearsTasks and ($curmonth != 1 and $curmonth != 12)) {
  948. $dateFilter = "AND `startdate` LIKE '" . $curyear . "-%'";
  949. }
  950. if ($depthMonthLimit) {
  951. $depthDate = date("Y-m-d", strtotime('-' . $depthMonthLimit . ' months'));
  952. $dateFilter = "AND `startdate` > '" . $depthDate . "-%'";
  953. }
  954. $appendQuery .= $dateFilter;
  955. //per employee filtering
  956. $displaytype = (isset($_POST['displaytype'])) ? $_POST['displaytype'] : 'all';
  957. //administrator is cursed of some branch
  958. if (ts_isMeBranchCursed()) {
  959. $displaytype = 'onlyme';
  960. }
  961. if ($displaytype == 'onlyme') {
  962. $whoami = whoami();
  963. $curempid = ts_GetEmployeeByLogin($whoami);
  964. $appendQuery .= " AND `employee`='" . $curempid . "'";
  965. } else {
  966. if (ispos($displaytype, 'displayempid')) {
  967. $displayEmployeeId = ubRouting::filters($displaytype, 'int');
  968. $appendQuery .= " AND `employee`='" . $displayEmployeeId . "'";
  969. }
  970. }
  971. if ($advFiltersEnabled) {
  972. $appendQuery .= ts_AdvFiltersQuery();
  973. }
  974. if ($branchConsider) {
  975. $appendQueryJOIN = " LEFT JOIN `branchesusers` USING(`login`)
  976. LEFT JOIN `branches` ON `branchesusers`.`branchid` = `branches`.`id` ";
  977. $appendQuerySelect = ", `branches`.`name` AS `branch_name` ";
  978. }
  979. if ($appendQuery) {
  980. $appendQuery = preg_replace('/AND/', 'WHERE', $appendQuery, 1);
  981. }
  982. $query = "SELECT `taskman`.*, `jobtypes`.`jobname`" . $appendQuerySelect . " FROM `taskman`
  983. LEFT JOIN `jobtypes` ON `taskman`.`jobtype` = `jobtypes`.`id`
  984. " . $appendQueryJOIN . "
  985. " . $appendQuery . " ORDER BY `date` ASC";
  986. $allTasks = simple_queryall($query);
  987. $result = '';
  988. $i = 1;
  989. $taskcount = sizeof($allTasks);
  990. $branchName = '';
  991. if (!empty($allTasks)) {
  992. foreach ($allTasks as $io => $eachtask) {
  993. if ($i != $taskcount) {
  994. $thelast = ',';
  995. } else {
  996. $thelast = '';
  997. }
  998. $startdate = strtotime($eachtask['startdate']);
  999. $startdate = date("Y, n-1, j", $startdate);
  1000. //time ordering
  1001. if (!empty($eachtask['starttime'])) {
  1002. $startTime = $eachtask['starttime'];
  1003. $startTime = substr($startTime, 0, 5) . ' ';
  1004. $startTimeTimestamp = ', ' . str_replace(':', ', ', $startTime);
  1005. } else {
  1006. $startTime = '';
  1007. $startTimeTimestamp = '';
  1008. }
  1009. if ($eachtask['enddate'] != '') {
  1010. $enddate = strtotime($eachtask['enddate']);
  1011. $enddate = date("Y, n-1, j", $enddate);
  1012. } else {
  1013. $enddate = $startdate;
  1014. }
  1015. if ($eachtask['status'] == 0) {
  1016. $coloring = "className : 'undone',";
  1017. if (isset($alljobdata[$eachtask['jobtype']])) {
  1018. if (!empty($alljobdata[$eachtask['jobtype']]['jobcolor'])) {
  1019. $coloring = "className : 'jobcolorcustom_" . $eachtask['jobtype'] . "',";
  1020. } else {
  1021. $coloring = "className : 'undone',";
  1022. }
  1023. } else {
  1024. $jobColorClass = "className : 'undone',";
  1025. }
  1026. } else {
  1027. $coloring = '';
  1028. }
  1029. //adcomments detect
  1030. if ($adcFlag) {
  1031. $adcommentsCount = $adcomments->getCommentsCount($eachtask['id']);
  1032. } else {
  1033. $adcommentsCount = 0;
  1034. }
  1035. if ($adcommentsCount > 0) {
  1036. $adcText = ' (' . $adcommentsCount . ')';
  1037. } else {
  1038. $adcText = '';
  1039. }
  1040. // get users's branch
  1041. $branchName = ($branchConsider) ? ' ' . $eachtask['branch_name'] . ' ' : '';
  1042. $result .= "
  1043. {
  1044. id: " . $eachtask['id'] . ",
  1045. title: '" . $startTime . $branchName . $eachtask['address'] . " - " . @$alljobdata[$eachtask['jobtype']]['jobname'] . $adcText . "',
  1046. start: new Date(" . $startdate . $startTimeTimestamp . "),
  1047. end: new Date(" . $enddate . "),
  1048. " . $coloring . "
  1049. url: '?module=taskman&edittask=" . $eachtask['id'] . "',
  1050. " . ($eachtask['status'] == 1 ? "constraint: {start: '00:00', end: '00:00', dow: []}" : "") . "
  1051. }
  1052. " . $thelast;
  1053. }
  1054. }
  1055. return ($result);
  1056. }
  1057. /**
  1058. * Returns typical notes selector for task creation dialogues
  1059. *
  1060. * @param bool $settings
  1061. * @return string
  1062. */
  1063. function ts_TaskTypicalNotesSelector($settings = true) {
  1064. global $ubillingConfig;
  1065. $noLengthCut = $ubillingConfig->getAlterParam('TASKMAN_NO_TYPICALNOTES_CUT');
  1066. $rawNotes = zb_StorageGet('PROBLEMS');
  1067. if ($settings) {
  1068. $settingsControl = wf_Link("?module=tasksprobcfg", wf_img('skins/settings.png', __('Settings')), false, '');
  1069. } else {
  1070. $settingsControl = '';
  1071. }
  1072. if (!empty($rawNotes)) {
  1073. $rawNotes = base64_decode($rawNotes);
  1074. $rawNotes = unserialize($rawNotes);
  1075. } else {
  1076. $emptyArray = array();
  1077. $newNotes = serialize($emptyArray);
  1078. $newNotes = base64_encode($newNotes);
  1079. zb_StorageSet('PROBLEMS', $newNotes);
  1080. $rawNotes = $emptyArray;
  1081. }
  1082. $typycalNotes = array('' => '-');
  1083. if (!empty($rawNotes)) {
  1084. foreach ($rawNotes as $eachnote) {
  1085. if (!$noLengthCut and mb_strlen($eachnote, 'utf-8') > 20) {
  1086. $shortNote = mb_substr($eachnote, 0, 20, 'utf-8') . '...';
  1087. } else {
  1088. $shortNote = $eachnote;
  1089. }
  1090. $typycalNotes[$eachnote] = $shortNote;
  1091. }
  1092. }
  1093. $selectorAlterWidth = ($noLengthCut) ? 'style="width: 70%"' : '';
  1094. $selector = wf_Selector('typicalnote', $typycalNotes, __('Problem') . ' ' . $settingsControl, '', true, false, '', '', $selectorAlterWidth);
  1095. return ($selector);
  1096. }
  1097. /**
  1098. * Returns task creation form
  1099. *
  1100. * @global object $ubillingConfig
  1101. * @return string
  1102. */
  1103. function ts_TaskCreateForm() {
  1104. global $ubillingConfig;
  1105. $altercfg = $ubillingConfig->getAlter();
  1106. $alljobtypes = ts_GetAllJobtypes();
  1107. $allemployee = ts_GetActiveEmployee();
  1108. $preselectedEmployee = $ubillingConfig->getAlterParam('TASKMAN_ANYONE_EMPLOYEEID', '');
  1109. if (!empty($alljobtypes) and !empty($allemployee)) {
  1110. //construct sms sending inputs
  1111. if ($altercfg['SENDDOG_ENABLED']) {
  1112. $smsCheckBox = (@$altercfg['TASKMAN_SMS_PROFILE_CHECK']) ? true : false;
  1113. $smsInputs = wf_CheckInput('newtasksendsms', __('Send SMS'), false, $smsCheckBox);
  1114. // SET checkbed TELEGRAM for creating task from Userprofile if TASKMAN_TELEGRAM_PROFILE_CHECK == 1
  1115. $telegramInputsCheck = (isset($altercfg['TASKMAN_TELEGRAM_PROFILE_CHECK']) && $altercfg['TASKMAN_TELEGRAM_PROFILE_CHECK']) ? TRUE : FALSE;
  1116. $telegramInputs = wf_CheckInput('newtasksendtelegram', __('Telegram'), false, $telegramInputsCheck);
  1117. } else {
  1118. $smsInputs = '';
  1119. $telegramInputs = '';
  1120. }
  1121. $inputs = '<!--ugly hack to prevent datepicker autoopen --> <input type="text" name="shittyhack" style="width: 0; height: 0; top: -100px; position: absolute;"/>';
  1122. $inputs .= wf_HiddenInput('createtask', 'true');
  1123. $inputs .= wf_DatePicker('newstartdate');
  1124. $inputs .= wf_TimePickerPreset('newstarttime', '', '', false);
  1125. $inputs .= wf_tag('label') . __('Target date') . wf_tag('sup') . '*' . wf_tag('sup', true) . wf_tag('label', true);
  1126. $inputs .= wf_delimiter();
  1127. if (!$altercfg['SEARCHADDR_AUTOCOMPLETE']) {
  1128. $inputs .= wf_TextInput('newtaskaddress', __('Address') . '<sup>*</sup>', '', true, '30');
  1129. } else {
  1130. if (!@$altercfg['TASKMAN_SHORT_AUTOCOMPLETE']) {
  1131. $allAddress = zb_AddressGetFulladdresslistCached();
  1132. } else {
  1133. $allAddress = zb_AddressGetStreetsWithBuilds();
  1134. }
  1135. $inputs .= wf_AutocompleteTextInput('newtaskaddress', $allAddress, __('Address') . '<sup>*</sup>', '', true, '30');
  1136. }
  1137. $inputs .= wf_tag('br');
  1138. //hidden for new task login input
  1139. $inputs .= wf_HiddenInput('newtasklogin', '');
  1140. $inputs .= wf_TextInput('newtaskphone', __('Phone') . '<sup>*</sup>', '', true, '30');
  1141. $inputs .= wf_tag('br');
  1142. $inputs .= wf_Selector('newtaskjobtype', $alljobtypes, __('Job type'), '', true);
  1143. $inputs .= wf_tag('br');
  1144. $inputs .= wf_Selector('newtaskemployee', $allemployee, __('Who should do'), $preselectedEmployee, true);
  1145. $inputs .= wf_tag('br');
  1146. $inputs .= ts_TaskTypicalNotesSelector();
  1147. $inputs .= wf_tag('label') . __('Job note') . wf_tag('label', true) . wf_tag('br');
  1148. $inputs .= wf_TextArea('newjobnote', '', '', true, '35x5');
  1149. $inputs .= $smsInputs;
  1150. $inputs .= $telegramInputs;
  1151. $inputs .= wf_Submit(__('Create new task'));
  1152. $result = wf_Form("", 'POST', $inputs, 'glamour');
  1153. $result .= __('All fields marked with an asterisk are mandatory');
  1154. } else {
  1155. $messages = new UbillingMessageHelper();
  1156. $result = $messages->getStyledMessage(__('No job types and employee available'), 'error');
  1157. }
  1158. return ($result);
  1159. }
  1160. /**
  1161. * Returns task creation form for userprofile usage
  1162. * DEPRECATED: use ts_TaskCreateFormUnified instead this
  1163. *
  1164. * @param string $address
  1165. * @param string $mobile
  1166. * @param string $phone
  1167. * @param string $login
  1168. * @return string
  1169. */
  1170. function ts_TaskCreateFormProfile($address, $mobile, $phone, $login) {
  1171. global $ubillingConfig;
  1172. $alljobtypes = ts_GetAllJobtypes();
  1173. $allemployee = ts_GetActiveEmployee();
  1174. $preselectedEmployee = $ubillingConfig->getAlterParam('TASKMAN_ANYONE_EMPLOYEEID', '');
  1175. if (!empty($alljobtypes) and !empty($allemployee)) {
  1176. // telepaticheskoe ugadivanie po tegu, kto dolzhen vipolnit rabotu
  1177. $query = "SELECT `employee`.`id` FROM `tags` INNER JOIN employee USING (tagid) WHERE `login` = '" . $login . "'";
  1178. $telepat_who_should_do = simple_query($query);
  1179. //construct sms sending inputs
  1180. if ($ubillingConfig->getAlterParam('SENDDOG_ENABLED')) {
  1181. $smsCheckBox = ($ubillingConfig->getAlterParam('TASKMAN_SMS_PROFILE_CHECK')) ? true : false;
  1182. $smsInputs = wf_CheckInput('newtasksendsms', __('Send SMS'), false, $smsCheckBox);
  1183. // SET checkbed TELEGRAM for creating task from Userprofile if TASKMAN_TELEGRAM_PROFILE_CHECK == 1
  1184. $telegramInputsCheck = ($ubillingConfig->getAlterParam('TASKMAN_TELEGRAM_PROFILE_CHECK')) ? TRUE : FALSE;
  1185. $telegramInputs = wf_CheckInput('newtasksendtelegram', __('Telegram'), false, $telegramInputsCheck);
  1186. } else {
  1187. $smsInputs = '';
  1188. $telegramInputs = '';
  1189. }
  1190. //new task creation data/time generation
  1191. if ($ubillingConfig->getAlterParam('TASKMAN_NEWTASK_AUTOTIME') == 1) {
  1192. $TaskDate = new DateTime();
  1193. $TaskDate->add(new DateInterval('PT1H'));
  1194. $newTaskDate = $TaskDate->format('Y-m-d');
  1195. $newTaskTime = $TaskDate->format('H:i');
  1196. } elseif ($ubillingConfig->getAlterParam('TASKMAN_NEWTASK_AUTOTIME') == 2) {
  1197. $TaskDate = new DateTime();
  1198. $TaskDate->add(new DateInterval('P1D'));
  1199. $TaskDate->setTime(8, 00);
  1200. // В воскресенье работать не хочу
  1201. if ($newTaskDate = $TaskDate->format('w') == 0) {
  1202. $TaskDate->add(new DateInterval('P1D'));
  1203. }
  1204. $newTaskDate = $TaskDate->format('Y-m-d');
  1205. $newTaskTime = $TaskDate->format('H:i');
  1206. } elseif ($ubillingConfig->getAlterParam('TASKMAN_NEWTASK_AUTOTIME') == 3) {
  1207. $TaskDate = new DateTime();
  1208. $TaskDate->add(new DateInterval('P1D'));
  1209. $TaskDate->setTime(8, 00);
  1210. $newTaskDate = $TaskDate->format('Y-m-d');
  1211. $newTaskTime = $TaskDate->format('H:i');
  1212. } else {
  1213. $newTaskDate = '';
  1214. $newTaskTime = '';
  1215. }
  1216. $employeeSorting = ($ubillingConfig->getAlterParam('TASKMAN_NEWTASK_EMPSORT')) ? true : false;
  1217. $sup = wf_tag('sup', false) . '*' . wf_tag('sup', true);
  1218. $inputs = '<!--ugly hack to prevent datepicker autoopen --> <input type="text" name="shittyhack" style="width: 0; height: 0; top: -100px; position: absolute;"/>';
  1219. $inputs .= wf_HiddenInput('createtask', 'true');
  1220. $inputs .= wf_DatePickerPreset('newstartdate', $newTaskDate);
  1221. $inputs .= wf_TimePickerPreset('newstarttime', $newTaskTime, '', false);
  1222. $inputs .= wf_tag('label') . __('Target date') . $sup . wf_tag('label', true);
  1223. $inputs .= wf_delimiter();
  1224. $inputs .= wf_TextInput('newtaskaddress', __('Address') . $sup, $address, true, '30');
  1225. //hidden for new task login input
  1226. $inputs .= wf_HiddenInput('newtasklogin', $login);
  1227. $inputs .= wf_tag('br');
  1228. $inputs .= wf_TextInput('newtaskphone', __('Phone') . $sup, $mobile . ' ' . $phone, true, '30');
  1229. $inputs .= wf_tag('br');
  1230. $inputs .= wf_Selector('newtaskjobtype', $alljobtypes, __('Job type'), '', true);
  1231. $inputs .= wf_tag('br');
  1232. if (!empty($telepat_who_should_do)) {
  1233. $telepat_who_should_do = $telepat_who_should_do['id'];
  1234. } else {
  1235. $telepat_who_should_do = $preselectedEmployee;
  1236. }
  1237. $inputs .= wf_Selector('newtaskemployee', $allemployee, __('Who should do'), $telepat_who_should_do, true, $employeeSorting);
  1238. $inputs .= wf_tag('br');
  1239. $inputs .= wf_tag('label') . __('Job note') . wf_tag('label', true) . wf_tag('br');
  1240. $inputs .= ts_TaskTypicalNotesSelector();
  1241. $inputs .= wf_TextArea('newjobnote', '', '', true, '35x5');
  1242. $inputs .= $smsInputs;
  1243. $inputs .= $telegramInputs;
  1244. $inputs .= wf_Submit(__('Create new task'));
  1245. if (!empty($login)) {
  1246. $inputs .= wf_AjaxLoader();
  1247. $inputs .= ' ' . wf_AjaxLink('?module=prevtasks&username=' . $login, wf_img_sized('skins/icon_search_small.gif', __('Previous user tasks')), 'taskshistorycontainer', false, '');
  1248. $inputs .= wf_tag('br');
  1249. $inputs .= wf_tag('div', false, '', 'id="taskshistorycontainer"') . wf_tag('div', true);
  1250. }
  1251. $result = wf_Form("?module=taskman&gotolastid=true", 'POST', $inputs, 'glamour');
  1252. $result .= __('All fields marked with an asterisk are mandatory');
  1253. } else {
  1254. $messages = new UbillingMessageHelper();
  1255. $result = $messages->getStyledMessage(__('No job types and employee available'), 'error');
  1256. }
  1257. return ($result);
  1258. }
  1259. /**
  1260. * Renders list of all previous user tasks by all time
  1261. *
  1262. * @param string $login
  1263. * @param string $address
  1264. * @param bool $noFixedWidth
  1265. * @param bool $arrayResult
  1266. *
  1267. * @return string/array
  1268. */
  1269. function ts_PreviousUserTasksRender($login, $address = '', $noFixedWidth = false, $arrayResult = false) {
  1270. $result = '';
  1271. $userTasks = array();
  1272. $telepathyTasks = array();
  1273. $telepathy = new Telepathy(false, true);
  1274. $cache = new UbillingCache();
  1275. $addressLoginsCache = $cache->get('ADDRESSTELEPATHY', 2592000);
  1276. if (empty($addressLoginsCache)) {
  1277. $addressLoginsCache = array();
  1278. }
  1279. $alljobtypes = ts_GetAllJobtypes();
  1280. $allemployee = ts_GetAllEmployee();
  1281. $query = "SELECT * from `taskman` ORDER BY `id` DESC;";
  1282. $rawTasks = simple_queryall($query);
  1283. if (!empty($rawTasks)) {
  1284. if (!$noFixedWidth) {
  1285. $result .= wf_tag('hr');
  1286. }
  1287. foreach ($rawTasks as $io => $each) {
  1288. if (!empty($login)) {
  1289. if ($each['login'] == $login) {
  1290. $userTasks[$each['id']] = $each;
  1291. }
  1292. //address guessing
  1293. if (isset($addressLoginsCache[$each['address']])) {
  1294. $guessedLogin = $addressLoginsCache[$each['address']];
  1295. } else {
  1296. $guessedLogin = $telepathy->getLogin($each['address']);
  1297. if ($guessedLogin) {
  1298. @$addressLoginsCache[$each['address']] = $guessedLogin;
  1299. }
  1300. }
  1301. if ($guessedLogin == $login) {
  1302. if (!isset($userTasks[$each['id']])) {
  1303. $userTasks[$each['id']] = $each;
  1304. $telepathyTasks[$each['id']] = $each['id'];
  1305. }
  1306. }
  1307. } else {
  1308. //just address guessing
  1309. if (!empty($address)) {
  1310. if ($address == $each['address']) {
  1311. $userTasks[$each['id']] = $each;
  1312. $telepathyTasks[$each['id']] = $each['id'];
  1313. }
  1314. }
  1315. }
  1316. }
  1317. //cache update
  1318. $cache->set('ADDRESSTELEPATHY', $addressLoginsCache, 2592000);
  1319. if (!$arrayResult) {
  1320. if (!empty($userTasks)) {
  1321. foreach ($userTasks as $io => $each) {
  1322. $telepathyFlag = (isset($telepathyTasks[$each['id']])) ? wf_tag('sup') . wf_tag('abbr', false, '', 'title="' . __('telepathically guessed') . '"') . '(?)' . wf_tag('abbr', true) . wf_tag('sup', true) : '';
  1323. $taskColor = ($each['status']) ? 'donetask' : 'undone';
  1324. $divStyle = ($noFixedWidth) ? 'style="padding: 2px; margin: 2px;"' : 'style="width:400px;"';
  1325. $result .= wf_tag('div', false, $taskColor, $divStyle);
  1326. $taskdata = $each['startdate'] . ' - ' . @$alljobtypes[$each['jobtype']] . ', ' . @$allemployee[$each['employee']] . ' ' . $telepathyFlag;
  1327. $result .= wf_link('?module=taskman&edittask=' . $each['id'], wf_img('skins/icon_edit.gif')) . ' ' . $taskdata;
  1328. $result .= wf_tag('div', true);
  1329. }
  1330. }
  1331. } else {
  1332. $result = $userTasks;
  1333. }
  1334. }
  1335. return ($result);
  1336. }
  1337. /**
  1338. * Renders list of all previous build user tasks by all time
  1339. *
  1340. * @param int $buildId
  1341. * @param bool $noFixedWidth
  1342. * @param bool $arrayResult
  1343. *
  1344. * @return string/array
  1345. */
  1346. function ts_PreviousBuildTasksRender($buildId, $noFixedWidth = false, $arrayResult = false) {
  1347. $result = '';
  1348. $buildTasks = array();
  1349. $tmpResult = array(
  1350. 'today' => '',
  1351. 'month' => '',
  1352. 'year' => '',
  1353. );
  1354. $allJobTypes = ts_GetAllJobtypes();
  1355. $allEmployee = ts_GetAllEmployee();
  1356. $allUserBuilds = zb_AddressGetBuildUsers();
  1357. $curYear = curyear();
  1358. $curMonth = curmonth();
  1359. $curDay = curdate();
  1360. $query = "SELECT * from `taskman` WHERE `startdate` LIKE '" . $curYear . "-%' ORDER BY `id` DESC;";
  1361. $rawTasks = simple_queryall($query);
  1362. if (!empty($rawTasks)) {
  1363. if (!$noFixedWidth) {
  1364. $result .= wf_tag('hr');
  1365. }
  1366. foreach ($rawTasks as $io => $each) {
  1367. if (!empty($each['login'])) {
  1368. if (isset($allUserBuilds[$each['login']])) {
  1369. $taskBuildId = $allUserBuilds[$each['login']];
  1370. if ($taskBuildId == $buildId) {
  1371. $buildTasks[$each['id']] = $each;
  1372. }
  1373. }
  1374. }
  1375. }
  1376. if (!$arrayResult) {
  1377. if (!empty($buildTasks)) {
  1378. foreach ($buildTasks as $io => $each) {
  1379. $resultScope = 'year'; //default scope
  1380. $taskColor = ($each['status']) ? 'donetask' : 'undone';
  1381. $divStyle = ($noFixedWidth) ? 'style="padding: 2px; margin: 2px;"' : 'style="width:400px;"';
  1382. $taskdata = $each['startdate'] . ' ' . $each['address'] . ' - ' . @$allJobTypes[$each['jobtype']] . ', ' . @$allEmployee[$each['employee']];
  1383. //this month?
  1384. if (ispos($each['startdate'], $curMonth)) {
  1385. $resultScope = 'month';
  1386. }
  1387. //or today?
  1388. if (ispos($each['startdate'], $curDay)) {
  1389. $resultScope = 'today';
  1390. }
  1391. $tmpResult[$resultScope] .= wf_tag('div', false, $taskColor, $divStyle);
  1392. $tmpResult[$resultScope] .= wf_link('?module=taskman&edittask=' . $each['id'], wf_img('skins/icon_edit.gif')) . ' ' . $taskdata;
  1393. $tmpResult[$resultScope] .= wf_tag('div', true);
  1394. }
  1395. //build result body
  1396. if (!empty($tmpResult['today'])) {
  1397. $result .= wf_tag('fieldset') . wf_tag('legend') . __('Today') . wf_tag('legend', true)
  1398. . $tmpResult['today'] . wf_tag('fieldset', true);
  1399. }
  1400. if (!empty($tmpResult['month'])) {
  1401. $result .= wf_tag('fieldset') . wf_tag('legend') . __('Month') . wf_tag('legend', true)
  1402. . $tmpResult['month'] . wf_tag('fieldset', true);
  1403. }
  1404. if (!empty($tmpResult['year'])) {
  1405. $result .= wf_tag('fieldset') . wf_tag('legend') . __('Year') . ' ' . $curYear . wf_tag('legend', true)
  1406. . $tmpResult['year'] . wf_tag('fieldset', true);
  1407. }
  1408. }
  1409. } else {
  1410. $result = $buildTasks;
  1411. }
  1412. }
  1413. return ($result);
  1414. }
  1415. /**
  1416. * Returns task creation form unified (use this shit in your further code!)
  1417. *
  1418. * @param string $address
  1419. * @param string $mobile
  1420. * @param string $phone
  1421. * @param string $login
  1422. * @param string $customData
  1423. * @param string $notes
  1424. *
  1425. * @return string
  1426. */
  1427. function ts_TaskCreateFormUnified($address, $mobile, $phone, $login = '', $customData = '', $notes = '') {
  1428. global $ubillingConfig;
  1429. $altercfg = $ubillingConfig->getAlter();
  1430. $alljobtypes = ts_GetAllJobtypes();
  1431. $allemployee = ts_GetActiveEmployee();
  1432. $preselectedEmployee = $ubillingConfig->getAlterParam('TASKMAN_ANYONE_EMPLOYEEID', '');
  1433. if (!empty($alljobtypes) and !empty($allemployee)) {
  1434. //construct sms sending inputs
  1435. if ($altercfg['SENDDOG_ENABLED']) {
  1436. $smsCheckBox = ($ubillingConfig->getAlterParam('TASKMAN_SMS_PROFILE_CHECK')) ? true : false;
  1437. $smsInputs = wf_CheckInput('newtasksendsms', __('Send SMS'), false, $smsCheckBox);
  1438. // SET checkbed TELEGRAM for creating task from Userprofile if TASKMAN_TELEGRAM_PROFILE_CHECK == 1
  1439. $telegramInputsCheck = (isset($altercfg['TASKMAN_TELEGRAM_PROFILE_CHECK']) && $altercfg['TASKMAN_TELEGRAM_PROFILE_CHECK']) ? TRUE : FALSE;
  1440. $telegramInputs = wf_CheckInput('newtasksendtelegram', __('Telegram'), false, $telegramInputsCheck);
  1441. } else {
  1442. $smsInputs = '';
  1443. $telegramInputs = '';
  1444. }
  1445. $sup = wf_tag('sup') . '*' . wf_tag('sup', true);
  1446. $inputs = '<!--ugly hack to prevent datepicker autoopen -->';
  1447. $inputs .= wf_tag('input', false, '', 'type="text" name="shittyhack" style="width: 0; height: 0; top: -100px; position: absolute;"');
  1448. $inputs .= wf_HiddenInput('createtask', 'true');
  1449. $inputs .= wf_DatePicker('newstartdate');
  1450. $inputs .= wf_TimePickerPreset('newstarttime', '', '', false);
  1451. $inputs .= wf_tag('label') . __('Target date') . $sup . wf_tag('label', true);
  1452. $inputs .= wf_delimiter();
  1453. $inputs .= wf_TextInput('newtaskaddress', __('Address') . $sup, $address, true, '30');
  1454. $inputs .= wf_HiddenInput('newtasklogin', $login);
  1455. $inputs .= wf_tag('br');
  1456. $inputs .= wf_TextInput('newtaskphone', __('Phone') . $sup, $mobile . ' ' . $phone, true, '30');
  1457. $inputs .= wf_tag('br');
  1458. $inputs .= wf_Selector('newtaskjobtype', $alljobtypes, __('Job type'), '', true);
  1459. $inputs .= wf_tag('br');
  1460. $inputs .= wf_Selector('newtaskemployee', $allemployee, __('Who should do'), $preselectedEmployee, true);
  1461. $inputs .= wf_tag('br');
  1462. $inputs .= wf_tag('label') . __('Job note') . wf_tag('label', true) . wf_tag('br');
  1463. $inputs .= ts_TaskTypicalNotesSelector();
  1464. $notesPreset = (!empty($notes)) ? $notes : '';
  1465. $inputs .= wf_TextArea('newjobnote', '', $notesPreset, true, '35x5');
  1466. if (!empty($customData)) {
  1467. $inputs .= $customData;
  1468. }
  1469. $inputs .= $smsInputs;
  1470. $inputs .= $telegramInputs;
  1471. $inputs .= wf_Submit(__('Create new task'));
  1472. $result = wf_Form("?module=taskman&gotolastid=true", 'POST', $inputs, 'glamour');
  1473. $result .= __('All fields marked with an asterisk are mandatory');
  1474. } else {
  1475. $messages = new UbillingMessageHelper();
  1476. $result = $messages->getStyledMessage(__('No job types and employee available'), 'error');
  1477. }
  1478. return ($result);
  1479. }
  1480. /**
  1481. * Returns task creation form for sigreq usage
  1482. * DEPRECATED: use ts_TaskCreateFormUnified instead this
  1483. *
  1484. * @param string $address
  1485. * @param string $phone
  1486. * @return string
  1487. */
  1488. function ts_TaskCreateFormSigreq($address, $phone) {
  1489. global $ubillingConfig;
  1490. $altercfg = $ubillingConfig->getAlter();
  1491. $alljobtypes = ts_GetAllJobtypes();
  1492. $allemployee = ts_GetActiveEmployee();
  1493. $preselectedEmployee = $ubillingConfig->getAlterParam('TASKMAN_ANYONE_EMPLOYEEID', '');
  1494. if (!empty($alljobtypes) and !empty($allemployee)) {
  1495. //construct sms sending inputs
  1496. if ($altercfg['SENDDOG_ENABLED']) {
  1497. $smsCheckBox = ($ubillingConfig->getAlterParam('TASKMAN_SMS_PROFILE_CHECK')) ? true : false;
  1498. $smsInputs = wf_CheckInput('newtasksendsms', __('Send SMS'), false, $smsCheckBox);
  1499. // SET checkbed TELEGRAM for creating task from Userprofile if TASKMAN_TELEGRAM_PROFILE_CHECK == 1
  1500. $telegramInputsCheck = (isset($altercfg['TASKMAN_TELEGRAM_PROFILE_CHECK']) && $altercfg['TASKMAN_TELEGRAM_PROFILE_CHECK']) ? TRUE : FALSE;
  1501. $telegramInputs = wf_CheckInput('newtasksendtelegram', __('Telegram'), false, $telegramInputsCheck);
  1502. } else {
  1503. $smsInputs = '';
  1504. $telegramInputs = '';
  1505. }
  1506. $inputs = '<!--ugly hack to prevent datepicker autoopen --> <input type="text" name="shittyhack" style="width: 0; height: 0; top: -100px; position: absolute;"/>';
  1507. $inputs .= wf_HiddenInput('createtask', 'true');
  1508. $inputs .= wf_DatePicker('newstartdate');
  1509. $inputs .= wf_TimePickerPreset('newstarttime', '', '', false);
  1510. $inputs .= wf_tag('label') . __('Target date') . wf_tag('sup') . '*' . wf_tag('sup', true) . wf_tag('label', true);
  1511. $inputs .= wf_delimiter();
  1512. $inputs .= wf_TextInput('newtaskaddress', __('Address') . '<sup>*</sup>', $address, true, '30');
  1513. //hidden for new task login input
  1514. $inputs .= wf_HiddenInput('newtasklogin', '');
  1515. $inputs .= wf_tag('br');
  1516. $inputs .= wf_TextInput('newtaskphone', __('Phone') . '<sup>*</sup>', $phone, true, '30');
  1517. $inputs .= wf_tag('br');
  1518. $inputs .= wf_Selector('newtaskjobtype', $alljobtypes, __('Job type'), '', true);
  1519. $inputs .= wf_tag('br');
  1520. $inputs .= wf_Selector('newtaskemployee', $allemployee, __('Who should do'), $preselectedEmployee, true);
  1521. $inputs .= wf_tag('br');
  1522. $inputs .= wf_tag('label') . __('Job note') . wf_tag('label', true) . wf_tag('br');
  1523. $inputs .= ts_TaskTypicalNotesSelector();
  1524. $inputs .= wf_TextArea('newjobnote', '', '', true, '35x5');
  1525. $inputs .= $smsInputs;
  1526. $inputs .= $telegramInputs;
  1527. $inputs .= wf_Submit(__('Create new task'));
  1528. $result = wf_Form("?module=taskman&gotolastid=true", 'POST', $inputs, 'glamour');
  1529. $result .= __('All fields marked with an asterisk are mandatory');
  1530. } else {
  1531. $messages = new UbillingMessageHelper();
  1532. $result = $messages->getStyledMessage(__('No job types and employee available'), 'error');
  1533. }
  1534. return ($result);
  1535. }
  1536. /**
  1537. * Returns taskman controls
  1538. *
  1539. * @return string
  1540. */
  1541. function ts_ShowPanel() {
  1542. global $ubillingConfig;
  1543. $altCfg = $ubillingConfig->getAlter();
  1544. $branchCurseFlag = ts_isMeBranchCursed();
  1545. $tools = '';
  1546. $result = '';
  1547. if (!$branchCurseFlag) {
  1548. $createform = ts_TaskCreateForm();
  1549. $result .= wf_modal(wf_img('skins/add_icon.png') . ' ' . __('Create task'), __('Create task'), $createform, 'ubButton', '450', '550');
  1550. }
  1551. $result .= wf_Link('?module=taskman&show=undone', wf_img('skins/undone_icon.png') . ' ' . __('Undone tasks'), false, 'ubButton');
  1552. $result .= wf_Link('?module=taskman&show=done', wf_img('skins/done_icon.png') . ' ' . __('Done tasks'), false, 'ubButton');
  1553. $result .= wf_Link('?module=taskman&show=all', wf_img('skins/icon_calendar.gif') . ' ' . __('All tasks'), false, 'ubButton');
  1554. if (cfr('TASKMANSEARCH')) {
  1555. $tools .= wf_Link('?module=tasksearch', web_icon_search() . ' ' . __('Tasks search'), false, 'ubButton');
  1556. }
  1557. if (cfr('TASKMANTRACK')) {
  1558. $tools .= wf_Link('?module=taskmantrack', wf_img('skins/track_icon.png') . ' ' . __('Tracking'), false, 'ubButton');
  1559. }
  1560. if (cfr('TASKMANTIMING')) {
  1561. $tools .= wf_Link('?module=taskmantiming', wf_img('skins/clock.png') . ' ' . __('Task timing report'), false, 'ubButton');
  1562. }
  1563. if (cfr('TASKMANADMREP')) {
  1564. $tools .= wf_Link('?module=taskmanadmreport', wf_img('skins/mcdonalds.png') . ' ' . __('Hataraku Maou-sama!'), false, 'ubButton');
  1565. }
  1566. if (cfr('TASKMANNWATCHLOG')) {
  1567. $tools .= wf_Link('?module=taskman&show=logs', wf_img('skins/icon_note.gif') . ' ' . __('Logs'), false, 'ubButton');
  1568. }
  1569. if (cfr('TASKMANSEARCH')) {
  1570. $tools .= wf_Link(TasksDuplicates::URL_ME, wf_img('skins/icon_clone.png') . ' ' . __('Tasks duplicates'), false, 'ubButton');
  1571. }
  1572. $tools .= wf_Link('?module=report_taskmanmap', wf_img('skins/swmapsmall.png') . ' ' . __('Tasks map'), false, 'ubButton');
  1573. $tools .= wf_Link('?module=taskman&print=true', wf_img('skins/icon_print.png') . ' ' . __('Tasks printing'), false, 'ubButton');
  1574. if (cfr(('SALARY'))) {
  1575. if ($ubillingConfig->getAlterParam('SALARY_ENABLED')) {
  1576. $tools .= wf_Link(TasksLaborTime::URL_ME, wf_img('skins/icon_time_small.png') . ' ' . __('Employee timeline'), false, 'ubButton');
  1577. }
  1578. }
  1579. if (!$branchCurseFlag) {
  1580. $result .= wf_modalAuto(web_icon_extended() . ' ' . __('Tools'), __('Tools'), $tools, 'ubButton');
  1581. }
  1582. //calendar filters panel
  1583. if (!ubRouting::checkGet('edittask')) {
  1584. //show type selector
  1585. $whoami = whoami();
  1586. $employeeid = ts_GetEmployeeByLogin($whoami);
  1587. $advFiltersEnabled = $ubillingConfig->getAlterParam('TASKMAN_ADV_FILTERS');
  1588. if ($employeeid or $advFiltersEnabled) {
  1589. $result .= wf_delimiter();
  1590. $inputs = '';
  1591. if ($employeeid) {
  1592. $curselected = (isset($_POST['displaytype'])) ? $_POST['displaytype'] : '';
  1593. $displayTypes = array(
  1594. 'all' => __('Show tasks for all users'),
  1595. 'onlyme' => __('Show only mine tasks')
  1596. );
  1597. //some other employee
  1598. $activeEmployeeTmp = ts_GetActiveEmployee();
  1599. if (!empty($activeEmployeeTmp)) {
  1600. foreach ($activeEmployeeTmp as $actId => $empName) {
  1601. $displayTypes['displayempid' . $actId] = $empName;
  1602. }
  1603. }
  1604. $inputs .= wf_Selector('displaytype', $displayTypes, '', $curselected, false, '', '', 'col-1-2-occupy');
  1605. }
  1606. if ($advFiltersEnabled) {
  1607. $inputs .= ts_AdvFiltersControls();
  1608. }
  1609. $formClasses = ($advFiltersEnabled ? 'glamour form-grid-6cols form-grid-6cols-label-right' : 'glamour form-grid-2cols');
  1610. $submitClasses = ($advFiltersEnabled ? 'ubButton' : 'inline-grid-button');
  1611. $submitOpts = 'style="width: 100%";';
  1612. $inputs .= wf_SubmitClassed(true, $submitClasses, '', __('Show'), '', $submitOpts);
  1613. $showTypeForm = wf_Form('', 'POST', $inputs, $formClasses);
  1614. if (!$branchCurseFlag) {
  1615. $result .= $showTypeForm;
  1616. }
  1617. }
  1618. }
  1619. return ($result);
  1620. }
  1621. /**
  1622. * Stores SMS for some employee for further sending with senddog run
  1623. *
  1624. * @param int $employeeid
  1625. * @param string $message
  1626. * @return array
  1627. * @throws Exception
  1628. */
  1629. function ts_SendSMS($employeeid, $message) {
  1630. $query = "SELECT `mobile`,`name` from `employee` WHERE `id`='" . $employeeid . "'";
  1631. $empData = simple_query($query);
  1632. $mobile = $empData['mobile'];
  1633. $result = array();
  1634. $sms = new UbillingSMS();
  1635. if (!empty($mobile)) {
  1636. if (ispos($mobile, '+')) {
  1637. $sms->sendSMS($mobile, $message, true, 'TASKMAN');
  1638. $result['number'] = $mobile;
  1639. $result['message'] = $message;
  1640. } else {
  1641. throw new Exception('BAD_MOBILE_FORMAT ' . $mobile);
  1642. }
  1643. }
  1644. return ($result);
  1645. }
  1646. /**
  1647. * Updates SMS data record in task record
  1648. *
  1649. * @param array $smsDataRaw
  1650. *
  1651. * @return void
  1652. */
  1653. function ts_TaskSMSDataUpdate($smsDataRaw) {
  1654. if (!empty($smsDataRaw)) {
  1655. $smsDataSave = serialize($smsDataRaw);
  1656. $smsDataSave = base64_encode($smsDataSave);
  1657. simple_update_field('taskman', 'smsdata', $smsDataSave, "WHERE `id`='" . ubRouting::get('edittask', 'int') . "'");
  1658. }
  1659. }
  1660. /**
  1661. * Marks some task as done
  1662. *
  1663. * @return void
  1664. */
  1665. function ts_TaskIsDone() {
  1666. $editid = vf($_POST['changetask']);
  1667. simple_update_field('taskman', 'enddate', $_POST['editenddate'], "WHERE `id`='" . $editid . "'");
  1668. simple_update_field('taskman', 'employeedone', $_POST['editemployeedone'], "WHERE `id`='" . $editid . "'");
  1669. simple_update_field('taskman', 'donenote', $_POST['editdonenote'], "WHERE `id`='" . $editid . "'");
  1670. simple_update_field('taskman', 'change_admin', $_POST['change_admin'], "WHERE `id`='" . $editid . "'");
  1671. simple_update_field('taskman', 'status', '1', "WHERE `id`='" . $editid . "'");
  1672. $logQuery = "INSERT INTO `taskmandone` (`id`,`taskid`,`date`) VALUES ";
  1673. $logQuery .= "(NULL,'" . $editid . "','" . curdatetime() . "');";
  1674. nr_query($logQuery);
  1675. $LogTaskArr = array('editenddate' => $_POST['editenddate'], 'editemployeedone' => $_POST['editemployeedone'], 'editdonenote' => $_POST['editdonenote']);
  1676. $queryLogTask = ("
  1677. INSERT INTO `taskmanlogs` (`id`, `taskid`, `date`, `admin`, `ip`, `event`, `logs`)
  1678. VALUES (NULL, '" . $editid . "', CURRENT_TIMESTAMP, '" . whoami() . "', '" . @$_SERVER['REMOTE_ADDR'] . "', 'done', '" . serialize($LogTaskArr) . "')
  1679. ");
  1680. nr_query($queryLogTask);
  1681. log_register('TASKMAN DONE [' . $editid . ']');
  1682. }
  1683. /**
  1684. * Marks some task as undone
  1685. *
  1686. * @return void
  1687. */
  1688. function ts_TaskIsUnDone() {
  1689. $undid = ubRouting::get('setundone', 'int');
  1690. simple_update_field('taskman', 'status', '0', "WHERE `id`='" . $undid . "'");
  1691. simple_update_field('taskman', 'enddate', 'NULL', "WHERE `id`='" . $undid . "'");
  1692. log_register('TASKMAN UNDONE [' . $undid . ']');
  1693. $queryLogTask = ("
  1694. INSERT INTO `taskmanlogs` (`id`, `taskid`, `date`, `admin`, `ip`, `event`, `logs`)
  1695. VALUES (NULL, '" . $undid . "', CURRENT_TIMESTAMP, '" . whoami() . "', '" . @$_SERVER['REMOTE_ADDR'] . "', 'setundone', '')
  1696. ");
  1697. nr_query($queryLogTask);
  1698. }
  1699. /**
  1700. * Stores Telegram message for some employee
  1701. *
  1702. * @param int $employeeid
  1703. * @param string $message
  1704. * @param array $taskdata
  1705. *
  1706. * @return array
  1707. */
  1708. function ts_SendTelegram($employeeid, $message, $taskdata = array()) {
  1709. $employeeid = vf($employeeid, 3);
  1710. $query = "SELECT `telegram`,`name` from `employee` WHERE `id`='" . $employeeid . "'";
  1711. $empData = simple_query($query);
  1712. $chatId = $empData['telegram'];
  1713. $telegram = new UbillingTelegram();
  1714. $result = array();
  1715. if (!empty($chatId)) {
  1716. $telegram->sendMessage($chatId, $message, false, 'TASKMAN');
  1717. $result['chatid'] = $chatId;
  1718. $result['message'] = $message;
  1719. //optional geo sending
  1720. if (!empty($taskdata)) {
  1721. if (isset($taskdata['geo'])) {
  1722. ts_SendTelegramVenue($chatId, @$taskdata['jobtype'], @$taskdata['address'], $taskdata['geo']);
  1723. }
  1724. }
  1725. }
  1726. return ($result);
  1727. }
  1728. /**
  1729. * Sends task location to some chatid
  1730. *
  1731. * @param string $chatId
  1732. * @param string $title
  1733. * @param string $address
  1734. * @param string $geo
  1735. *
  1736. * @return void
  1737. */
  1738. function ts_SendTelegramVenue($chatId, $title, $address, $geo) {
  1739. global $ubillingConfig;
  1740. if ($ubillingConfig->getAlterParam('TASKMAN_SEND_LOCATION')) {
  1741. $telegram = new UbillingTelegram();
  1742. $message = 'title:{' . $title . '}address:(' . $address . ')sendVenue:[' . $geo . ']';
  1743. $telegram->sendMessage($chatId, $message, false, 'TASKMANGEO');
  1744. }
  1745. }
  1746. /**
  1747. * Flushes SMS data for some task
  1748. *
  1749. * @param int $taskid
  1750. *
  1751. * @return void
  1752. */
  1753. function ts_FlushSMSData($taskid) {
  1754. $taskid = vf($taskid, 3);
  1755. $query = "UPDATE `taskman` SET `smsdata`=NULL WHERE `id`='" . $taskid . "';";
  1756. nr_query($query);
  1757. $queryLogTask = ("
  1758. INSERT INTO `taskmanlogs` (`id`, `taskid`, `date`, `admin`, `ip`, `event`, `logs`)
  1759. VALUES (NULL, '" . $taskid . "', CURRENT_TIMESTAMP, '" . whoami() . "', '" . @$_SERVER['REMOTE_ADDR'] . "', 'flushsms', '')
  1760. ");
  1761. nr_query($queryLogTask);
  1762. log_register('TASKMAN FLUSH SMS [' . $taskid . ']');
  1763. }
  1764. /**
  1765. * Creates new task in database
  1766. *
  1767. * @param string $startdate
  1768. * @param string $starttime
  1769. * @param string $address
  1770. * @param string $login
  1771. * @param string $phone
  1772. * @param int $jobtypeid
  1773. * @param int $employeeid
  1774. * @param string $jobnote
  1775. *
  1776. * @return void
  1777. */
  1778. function ts_CreateTask($startdate, $starttime, $address, $login, $phone, $jobtypeid, $employeeid, $jobnote) {
  1779. global $ubillingConfig;
  1780. $curdate = curdatetime();
  1781. $admin = whoami();
  1782. $address = str_replace('\'', '`', $address);
  1783. $address = mysql_real_escape_string($address);
  1784. $address = trim($address);
  1785. $login = mysql_real_escape_string($login);
  1786. $phone = mysql_real_escape_string($phone);
  1787. $startdate = mysql_real_escape_string($startdate);
  1788. $jobSendTime = date("H:i", strtotime($curdate));
  1789. $taskDataGeo = array();
  1790. if (!empty($starttime)) {
  1791. $starttimeRaw = $starttime;
  1792. $starttime = "'" . mysql_real_escape_string($starttime) . "'";
  1793. } else {
  1794. $starttimeRaw = '';
  1795. $starttime = 'NULL';
  1796. }
  1797. $jobtypeid = vf($jobtypeid, 3);
  1798. $employeeid = vf($employeeid, 3);
  1799. $jobnote = mysql_real_escape_string($jobnote);
  1800. $smsData = 'NULL';
  1801. //store messages for backround processing via senddog for SMS
  1802. if ($ubillingConfig->getAlterParam('SENDDOG_ENABLED')) {
  1803. $jobtype = ts_GetAllJobtypes();
  1804. //SMS sending
  1805. if (isset($_POST['newtasksendsms'])) {
  1806. $newSmsText = $address . ' ' . $phone . ' ' . @$jobtype[$jobtypeid] . ' ' . $jobnote . $starttimeRaw;
  1807. $smsDataRaw = ts_SendSMS($employeeid, $newSmsText);
  1808. if (!empty($smsDataRaw)) {
  1809. $smsData = serialize($smsDataRaw);
  1810. $smsData = "'" . base64_encode($smsData) . "'";
  1811. }
  1812. }
  1813. }
  1814. $query = "INSERT INTO `taskman` (`id` , `date` , `address` , `login` , `jobtype` , `jobnote` , `phone` , `employee` , `employeedone` ,`donenote` , `startdate` ,`starttime`, `enddate` , `admin` , `status`,`smsdata`)
  1815. VALUES (NULL , '" . $curdate . "', '" . $address . "', '" . $login . "', '" . $jobtypeid . "', '" . $jobnote . "', '" . $phone . "', '" . $employeeid . "',NULL, NULL , '" . $startdate . "'," . $starttime . ",NULL , '" . $admin . "', '0'," . $smsData . ");";
  1816. nr_query($query);
  1817. $taskid = simple_query("SELECT LAST_INSERT_ID() as id");
  1818. $taskid = $taskid['id'];
  1819. //store messages for backround processing via senddog for Telegramm
  1820. if ($ubillingConfig->getAlterParam('SENDDOG_ENABLED')) {
  1821. if (!empty($login)) {
  1822. $userData = zb_UserGetAllData($login);
  1823. }
  1824. //Telegram sending
  1825. if (isset($_POST['newtasksendtelegram'])) {
  1826. $tgEol = '\r\n';
  1827. $newTelegramText = __('ID') . ': ' . $taskid . $tgEol;
  1828. $newTelegramText .= __('Address') . ': ' . $address . $tgEol;
  1829. if (!empty($login)) {
  1830. $newTelegramText .= __('Real Name') . ': ' . @$userData[$login]['realname'] . $tgEol;
  1831. }
  1832. $newTelegramText .= __('Job type') . ': ' . @$jobtype[$jobtypeid] . $tgEol;
  1833. $newTelegramText .= __('Phone') . ': ' . $phone . $tgEol;
  1834. $newTelegramText .= __('Job note') . ': ' . $jobnote . $tgEol;
  1835. $newTelegramText .= __('Target date') . ': ' . $startdate . ' ' . $starttimeRaw . $tgEol;
  1836. $newTelegramText .= __('Create date') . ': ' . $jobSendTime . $tgEol;
  1837. if (!empty($login)) {
  1838. $userCableSeal = '';
  1839. if ($ubillingConfig->getAlterParam('CONDET_ENABLED')) {
  1840. $userCondet = new ConnectionDetails();
  1841. $userCableSeal = $userCondet->getByLogin($login);
  1842. if (!empty($userCableSeal)) {
  1843. $userCableSeal = __('Cable seal') . ': ' . $userCableSeal['seal'] . $tgEol; // kabelnyi tyulenchik
  1844. }
  1845. }
  1846. $newTelegramText .= __('Login') . ': ' . $login . $tgEol;
  1847. $newTelegramText .= __('Password') . ': ' . @$userData[$login]['Password'] . $tgEol;
  1848. $newTelegramText .= __('Contract') . ': ' . @$userData[$login]['contract'] . $tgEol;
  1849. $newTelegramText .= __('IP') . ': ' . @$userData[$login]['ip'] . $tgEol;
  1850. $newTelegramText .= __('MAC') . ': ' . @$userData[$login]['mac'] . $tgEol;
  1851. $newTelegramText .= __('Tariff') . ': ' . @$userData[$login]['Tariff'] . $tgEol;
  1852. //data preprocessing for geo sending
  1853. if (@isset($userData[$login]['geo'])) {
  1854. if (!empty($userData[$login]['geo'])) {
  1855. $taskDataGeo['jobtype'] = @$jobtype[$jobtypeid];
  1856. $taskDataGeo['address'] = $address;
  1857. $taskDataGeo['geo'] = $userData[$login]['geo'];
  1858. }
  1859. }
  1860. if ($ubillingConfig->getAlterParam('SWITCHPORT_IN_PROFILE')) {
  1861. $allAssigns = zb_SwitchesGetAssignsAll();
  1862. if (isset($allAssigns[$login])) {
  1863. $newTelegramText .= __('Switch') . ': ' . @$allAssigns[$login]['label'] . $tgEol;
  1864. }
  1865. }
  1866. if (!empty($userCableSeal)) {
  1867. $newTelegramText .= $userCableSeal;
  1868. }
  1869. if ($ubillingConfig->getAlterParam('TASKMAN_SEND_ONU_SIGNAL')) {
  1870. $newTelegramText .= zb_getPonSignalData($login, false, true) . $tgEol;
  1871. }
  1872. }
  1873. //some hack to append UKV users cable seals and maybe something else
  1874. if (wf_CheckPost(array('unifiedformtelegramappend'))) {
  1875. $newTelegramText .= $_POST['unifiedformtelegramappend'];
  1876. }
  1877. //appending task direct URL to task
  1878. $fullBillingUrl = $ubillingConfig->getAlterParam('FULL_BILLING_URL');
  1879. $appendTaskLinkFlag = $ubillingConfig->getAlterParam('TASKMAN_SEND_TASKURL');
  1880. if (!empty($fullBillingUrl) and $appendTaskLinkFlag) {
  1881. $newTelegramText .= '<a href="' . $fullBillingUrl . '/?module=taskman&edittask=' . $taskid . '">🔍 ' . __('View task') . '</a> parseMode:{html}';
  1882. }
  1883. //telegram messages sending
  1884. ts_SendTelegram($employeeid, $newTelegramText, $taskDataGeo);
  1885. }
  1886. }
  1887. //flushing darkvoid
  1888. $darkVoid = new DarkVoid();
  1889. $darkVoid->flushCache();
  1890. $queryLogTask = ("
  1891. INSERT INTO `taskmanlogs` (`id`, `taskid`, `date`, `admin`, `ip`, `event`, `logs`)
  1892. VALUES (NULL, '" . $taskid . "', CURRENT_TIMESTAMP, '" . whoami() . "', '" . @$_SERVER['REMOTE_ADDR'] . "', 'create', '" . serialize($address) . "')
  1893. ");
  1894. nr_query($queryLogTask);
  1895. log_register('TASKMAN CREATE [' . $taskid . '] `' . $address . '`');
  1896. }
  1897. /**
  1898. * Returns array of task data by its ID
  1899. *
  1900. * @param int $taskid
  1901. * @return array
  1902. */
  1903. function ts_GetTaskData($taskid) {
  1904. $taskid = vf($taskid, 3);
  1905. $query = "SELECT * from `taskman` WHERE `id`='" . $taskid . "'";
  1906. $result = simple_query($query);
  1907. return ($result);
  1908. }
  1909. /**
  1910. * Returns task editing form
  1911. *
  1912. * @global object $ubillingConfig
  1913. * @param int $taskid
  1914. * @return string
  1915. */
  1916. function ts_TaskModifyForm($taskid) {
  1917. global $ubillingConfig;
  1918. $altercfg = $ubillingConfig->getAlter();
  1919. $taskid = vf($taskid, 3);
  1920. $taskdata = ts_GetTaskData($taskid);
  1921. $result = '';
  1922. $allemployee = ts_GetAllEmployee();
  1923. $activeemployee = ts_GetActiveEmployee();
  1924. $alljobtypes = ts_GetAllJobtypes();
  1925. //construct sms sending inputs
  1926. if ($altercfg['SENDDOG_ENABLED']) {
  1927. $smsCheckBox = ($ubillingConfig->getAlterParam('TASKMAN_SMS_PROFILE_CHECK')) ? true : false;
  1928. $smsInputs = wf_CheckInput('changetasksendsms', __('Send SMS'), false, $smsCheckBox);
  1929. // SET checkbed TELEGRAM for creating task from Userprofile if TASKMAN_TELEGRAM_PROFILE_CHECK == 1
  1930. $telegramInputsCheck = (isset($altercfg['TASKMAN_TELEGRAM_PROFILE_CHECK']) && $altercfg['TASKMAN_TELEGRAM_PROFILE_CHECK']) ? TRUE : FALSE;
  1931. $telegramInputs = wf_CheckInput('changetasksendtelegram', __('Telegram'), false, $telegramInputsCheck);
  1932. } else {
  1933. $smsInputs = '';
  1934. $telegramInputs = '';
  1935. }
  1936. if (!empty($taskdata)) {
  1937. $inputs = wf_HiddenInput('modifytask', $taskid);
  1938. $inputs .= '<!--ugly hack to prevent datepicker autoopen --> <input type="text" name="shittyhackmod" style="width: 0; height: 0; top: -100px; position: absolute;"/>';
  1939. if (cfr('TASKMANDATE')) {
  1940. $inputs .= wf_DatePickerPreset('modifystartdate', $taskdata['startdate']);
  1941. } else {
  1942. $inputs .= wf_HiddenInput('modifystartdate', $taskdata['startdate']);
  1943. }
  1944. $inputs .= wf_TimePickerPreset('modifystarttime', $taskdata['starttime'], '', false);
  1945. $inputs .= wf_tag('label') . __('Target date') . wf_tag('sup') . '*' . wf_tag('sup', true) . wf_tag('label', true);
  1946. $inputs .= wf_delimiter();
  1947. $inputs .= wf_tag('br');
  1948. if ($altercfg['SEARCHADDR_AUTOCOMPLETE']) {
  1949. $alladdress = zb_AddressGetFulladdresslistCached();
  1950. //Commented because significantly reduces performance. Waiting for feedback.
  1951. //natsort($alladdress);
  1952. $inputs .= wf_AutocompleteTextInput('modifytaskaddress', $alladdress, __('Address') . '<sup>*</sup>', $taskdata['address'], true, '30');
  1953. } else {
  1954. $inputs .= wf_TextInput('modifytaskaddress', __('Address') . '<sup>*</sup>', $taskdata['address'], true, '30');
  1955. }
  1956. $inputs .= wf_tag('br');
  1957. //custom login text input
  1958. $inputs .= wf_TextInput('modifytasklogin', __('Login'), $taskdata['login'], true, 30);
  1959. $inputs .= wf_tag('br');
  1960. $inputs .= wf_TextInput('modifytaskphone', __('Phone') . '<sup>*</sup>', $taskdata['phone'], true, '30');
  1961. $inputs .= wf_tag('br');
  1962. $inputs .= wf_Selector('modifytaskjobtype', $alljobtypes, __('Job type'), $taskdata['jobtype'], true);
  1963. $inputs .= wf_tag('br');
  1964. $inputs .= wf_Selector('modifytaskemployee', $activeemployee, __('Who should do'), $taskdata['employee'], true);
  1965. $inputs .= wf_tag('br');
  1966. $inputs .= wf_tag('label') . __('Job note') . wf_tag('label', true) . wf_tag('br');
  1967. $inputs .= wf_TextArea('modifytaskjobnote', '', $taskdata['jobnote'], true, '35x5');
  1968. $inputs .= $smsInputs;
  1969. $inputs .= $telegramInputs;
  1970. $inputs .= wf_Submit(__('Save'));
  1971. $result = wf_Form("", 'POST', $inputs, 'glamour');
  1972. $result .= __('All fields marked with an asterisk are mandatory');
  1973. }
  1974. return ($result);
  1975. }
  1976. /**
  1977. * Updates task params in database
  1978. *
  1979. * @param int $taskid
  1980. * @param string $startdate
  1981. * @param string $starttime
  1982. * @param string $address
  1983. * @param string $login
  1984. * @param string $phone
  1985. * @param int $jobtypeid
  1986. * @param int $employeeid
  1987. * @param string $jobnote
  1988. *
  1989. * @return void
  1990. */
  1991. function ts_ModifyTask($taskid, $startdate, $starttime, $address, $login, $phone, $jobtypeid, $employeeid, $jobnote) {
  1992. global $ubillingConfig;
  1993. $taskid = vf($taskid, 3);
  1994. $startdate = mysql_real_escape_string($startdate);
  1995. $starttimeRaw = (!empty($starttime)) ? $starttime : '';
  1996. $starttime = (!empty($starttime)) ? "'" . date("H:i:s", strtotime(mysql_real_escape_string($starttime))) . "'" : 'NULL';
  1997. $address = str_replace('\'', '`', $address);
  1998. $address = mysql_real_escape_string($address);
  1999. $login = mysql_real_escape_string($login);
  2000. $phone = mysql_real_escape_string($phone);
  2001. $jobtypeid = vf($jobtypeid, 3);
  2002. $employeeid = vf($employeeid, 3);
  2003. $org_taskdata = ts_GetTaskData($taskid);
  2004. $jobtype = ts_GetAllJobtypes();
  2005. simple_update_field('taskman', 'startdate', $startdate, "WHERE `id`='" . $taskid . "'");
  2006. nr_query("UPDATE `taskman` SET `starttime` = " . $starttime . " WHERE `id`='" . $taskid . "'"); //That shit for preventing quotes. Dont touch this.
  2007. simple_update_field('taskman', 'address', $address, "WHERE `id`='" . $taskid . "'");
  2008. simple_update_field('taskman', 'login', $login, "WHERE `id`='" . $taskid . "'");
  2009. simple_update_field('taskman', 'phone', $phone, "WHERE `id`='" . $taskid . "'");
  2010. simple_update_field('taskman', 'jobtype', $jobtypeid, "WHERE `id`='" . $taskid . "'");
  2011. simple_update_field('taskman', 'employee', $employeeid, "WHERE `id`='" . $taskid . "'");
  2012. simple_update_field('taskman', 'jobnote', $jobnote, "WHERE `id`='" . $taskid . "'");
  2013. $smsData = 'NULL';
  2014. //SMS sending
  2015. if (isset($_POST['changetasksendsms'])) {
  2016. $newSmsText = $address . ' ' . $phone . ' ' . @$jobtype[$jobtypeid] . ' ' . $jobnote . $starttimeRaw;
  2017. $smsDataRaw = ts_SendSMS($employeeid, $newSmsText);
  2018. if (!empty($smsDataRaw)) {
  2019. $smsData = serialize($smsDataRaw);
  2020. $smsData = "'" . base64_encode($smsData) . "'";
  2021. }
  2022. }
  2023. //Telegram sending
  2024. if (isset($_POST['changetasksendtelegram'])) {
  2025. $tgEol='\r\n';
  2026. if (!empty($login)) {
  2027. $userData = zb_UserGetAllData($login);
  2028. }
  2029. $newTelegramText = __('ID') . ': ' . $taskid . $tgEol;
  2030. $newTelegramText .= __('Address') . ': ' . $address . $tgEol;
  2031. if (!empty($login)) {
  2032. $newTelegramText .= __('Real Name') . ': ' . @$userData[$login]['realname'] . $tgEol;
  2033. }
  2034. $newTelegramText .= __('Job type') . ': ' . @$jobtype[$jobtypeid] . $tgEol;
  2035. $newTelegramText .= __('Phone') . ': ' . $phone . $tgEol;
  2036. $newTelegramText .= __('Job note') . ': ' . $jobnote . $tgEol;
  2037. $newTelegramText .= __('Target date') . ': ' . $startdate . ' ' . $starttimeRaw . $tgEol;
  2038. if (!empty($login)) {
  2039. $userCableSeal = '';
  2040. if ($ubillingConfig->getAlterParam('CONDET_ENABLED')) {
  2041. $userCondet = new ConnectionDetails();
  2042. $userCableSeal = $userCondet->getByLogin($login);
  2043. if (!empty($userCableSeal)) {
  2044. $userCableSeal = __('Cable seal') . ': ' . $userCableSeal['seal'] . $tgEol;
  2045. }
  2046. }
  2047. $newTelegramText .= __('Login') . ': ' . $login . $tgEol;
  2048. $newTelegramText .= __('Password') . ': ' . @$userData[$login]['Password'] . $tgEol;
  2049. $newTelegramText .= __('Contract') . ': ' . @$userData[$login]['contract'] . $tgEol;
  2050. $newTelegramText .= __('IP') . ': ' . @$userData[$login]['ip'] . $tgEol;
  2051. $newTelegramText .= __('MAC') . ': ' . @$userData[$login]['mac'] . $tgEol;
  2052. $newTelegramText .= __('Tariff') . ': ' . @$userData[$login]['Tariff'] . $tgEol;
  2053. if ($ubillingConfig->getAlterParam('SWITCHPORT_IN_PROFILE')) {
  2054. $allAssigns = zb_SwitchesGetAssignsAll();
  2055. if (isset($allAssigns[$login])) {
  2056. $newTelegramText .= __('Switch') . ': ' . @$allAssigns[$login]['label'] . $tgEol;
  2057. }
  2058. }
  2059. if (!empty($userCableSeal)) {
  2060. $newTelegramText .= $userCableSeal;
  2061. }
  2062. if ($ubillingConfig->getAlterParam('TASKMAN_SEND_ONU_SIGNAL')) {
  2063. $newTelegramText .= zb_getPonSignalData($login, false, true) . $tgEol;
  2064. }
  2065. }
  2066. //appending task direct URL to task
  2067. $fullBillingUrl = $ubillingConfig->getAlterParam('FULL_BILLING_URL');
  2068. $appendTaskLinkFlag = $ubillingConfig->getAlterParam('TASKMAN_SEND_TASKURL');
  2069. if (!empty($fullBillingUrl) and $appendTaskLinkFlag) {
  2070. $newTelegramText .= '<a href="' . $fullBillingUrl . '/?module=taskman&edittask=' . $taskid . '">🔍 ' . __('View task') . '</a> parseMode:{html}';
  2071. }
  2072. ts_SendTelegram($employeeid, $newTelegramText);
  2073. }
  2074. // Unset parametr, that we dont diff
  2075. unset($org_taskdata['date'], $org_taskdata['employeedone'], $org_taskdata['donenote'], $org_taskdata['enddate'], $org_taskdata['admin'], $org_taskdata['status'], $org_taskdata['change_admin'], $org_taskdata['smsdata']);
  2076. $new_taskdata = array(
  2077. 'id' => $taskid,
  2078. 'address' => $address,
  2079. 'login' => $login,
  2080. 'jobtype' => $jobtypeid,
  2081. 'jobnote' => $jobnote,
  2082. 'phone' => $phone,
  2083. 'employee' => $employeeid,
  2084. 'startdate' => $startdate,
  2085. 'starttime' => date("H:i:s", strtotime($starttimeRaw))
  2086. );
  2087. $cahged_taskdata = (array_diff_assoc($org_taskdata, $new_taskdata));
  2088. $log_data = '';
  2089. $log_data_arr = array();
  2090. foreach ($cahged_taskdata as $par => $value) {
  2091. $log_data .= __($par) . ':`' . $value . '` => `' . $new_taskdata[$par] . '`';
  2092. $log_data_arr[$par]['old'] = $value;
  2093. $log_data_arr[$par]['new'] = $new_taskdata[$par];
  2094. }
  2095. $queryLogTask = ("
  2096. INSERT INTO `taskmanlogs` (`id`, `taskid`, `date`, `admin`, `ip`, `event`, `logs`)
  2097. VALUES (NULL, '" . $taskid . "', CURRENT_TIMESTAMP, '" . whoami() . "', '" . @$_SERVER['REMOTE_ADDR'] . "', 'modify', '" . serialize($log_data_arr) . "')
  2098. ");
  2099. nr_query($queryLogTask);
  2100. log_register('TASKMAN MODIFY [' . $taskid . '] `' . $address . '`' . ' CHANGED [' . $log_data . ']');
  2101. }
  2102. /**
  2103. * Returns all available admin_login=>employee name pairs
  2104. *
  2105. * @return string serialized array
  2106. */
  2107. function ts_GetAllEmployeeLogins() {
  2108. global $ubillingConfig;
  2109. $altCfg = $ubillingConfig->getAlter();
  2110. $namesFlag = (@$altCfg['ADMIN_NAMES']) ? true : false;
  2111. $result = array();
  2112. $query = "SELECT `admlogin`,`name` from `employee`";
  2113. $all = simple_queryall($query);
  2114. if (!empty($all)) {
  2115. foreach ($all as $io => $each) {
  2116. if (!empty($each['admlogin'])) {
  2117. if ($namesFlag) {
  2118. $result[$each['admlogin']] = $each['name'];
  2119. } else {
  2120. $result[$each['admlogin']] = $each['admlogin'];
  2121. }
  2122. }
  2123. }
  2124. }
  2125. $result = serialize($result);
  2126. return ($result);
  2127. }
  2128. /**
  2129. * Returns all available admin_login=>employee name pairs from cache if available
  2130. *
  2131. * @return string serialized array
  2132. */
  2133. function ts_GetAllEmployeeLoginsCached() {
  2134. $result = '';
  2135. $cache = new UbillingCache();
  2136. $cacheTime = 86400;
  2137. $result = $cache->getCallback('EMPLOYEE_LOGINS', function () {
  2138. return (ts_GetAllEmployeeLogins());
  2139. }, $cacheTime);
  2140. return ($result);
  2141. }
  2142. /**
  2143. * Returns all available admin_login=>employee name pairs from cache if available
  2144. *
  2145. * @return array
  2146. */
  2147. function ts_GetAllEmployeeLoginsAssocCached() {
  2148. $result = array();
  2149. $raw = ts_GetAllEmployeeLoginsCached();
  2150. if (!empty($raw)) {
  2151. $result = unserialize($raw);
  2152. }
  2153. return ($result);
  2154. }
  2155. /**
  2156. * Checks some task for duplicates by login/address fields
  2157. *
  2158. * @param array $taskData
  2159. * @param int $optionValue 1 - today duplicates, any other digit - days around
  2160. *
  2161. * @return void
  2162. */
  2163. function ts_CheckDailyDuplicates($taskData, $optionValue = 1) {
  2164. if (!empty($taskData)) {
  2165. if (!empty($taskData['startdate'])) {
  2166. $allTasksDuplicates = array();
  2167. $loginDuplicates = array();
  2168. $addressDuplicates = array();
  2169. $result = '';
  2170. $tasksDb = new NyanORM('taskman');
  2171. if (!empty($taskData['login'])) {
  2172. $tasksDb->where('id', '!=', $taskData['id']);
  2173. //just the same date
  2174. if ($optionValue == 1) {
  2175. $tasksDb->where('startdate', 'LIKE', $taskData['startdate'] . '%');
  2176. } else {
  2177. //configurable days count interval
  2178. $startDateTimestamp = strtotime($taskData['startdate']);
  2179. $daysOffset = round($optionValue * 86400); //int
  2180. $dayBegin = date("Y-m-d", ($startDateTimestamp - $daysOffset)); // -X days
  2181. $dayEnd = date("Y-m-d", ($startDateTimestamp + $daysOffset)); // +X days
  2182. $tasksDb->where('startdate', 'BETWEEN', $dayBegin . "' AND '" . $dayEnd);
  2183. }
  2184. $tasksDb->where('login', '=', $taskData['login']);
  2185. $loginDuplicates = $tasksDb->getAll('id');
  2186. }
  2187. if (!empty($taskData['address'])) {
  2188. $tasksDb->where('id', '!=', $taskData['id']);
  2189. //just the same date
  2190. if ($optionValue == 1) {
  2191. $tasksDb->where('startdate', 'LIKE', $taskData['startdate'] . '%');
  2192. } else {
  2193. //configurable days count interval
  2194. $startDateTimestamp = strtotime($taskData['startdate']);
  2195. $daysOffset = round($optionValue * 86400); //int
  2196. $dayBegin = date("Y-m-d", ($startDateTimestamp - $daysOffset)); // -X days
  2197. $dayEnd = date("Y-m-d", ($startDateTimestamp + $daysOffset)); // +X days
  2198. $tasksDb->where('startdate', 'BETWEEN', $dayBegin . "' AND '" . $dayEnd);
  2199. }
  2200. $tasksDb->where('address', '=', $taskData['address']);
  2201. $addressDuplicates = $tasksDb->getAll('id');
  2202. }
  2203. $allTasksDuplicates = $loginDuplicates + $addressDuplicates;
  2204. if (!empty($allTasksDuplicates)) {
  2205. $messages = new UbillingMessageHelper();
  2206. foreach ($allTasksDuplicates as $io => $each) {
  2207. $taskLink = ' ' . __('ID') . wf_Link('?module=taskman&edittask=' . $each['id'], '[' . $each['id'] . '] ');
  2208. $result .= $messages->getStyledMessage(__('Duplicate') . $taskLink . $each['startdate'] . ' ' . $each['address'], 'warning');
  2209. }
  2210. $windowLabel = __('Tasks with duplicate address created for same day');
  2211. if ($optionValue > 1) {
  2212. $windowLabel .= ' ' . __('or in') . ' +-' . $optionValue . ' ' . __('days');
  2213. }
  2214. show_window($windowLabel, $result);
  2215. }
  2216. }
  2217. }
  2218. }
  2219. /**
  2220. * Returns array of employee with some assigned tag only as id=>name
  2221. *
  2222. * @param array $allEmployeeData
  2223. * @param int $tagId
  2224. *
  2225. * @return array
  2226. */
  2227. function ts_EmployeeFilterTagId($allEmployeeData, $tagId) {
  2228. $result = array();
  2229. if (!empty($allEmployeeData)) {
  2230. foreach ($allEmployeeData as $io => $each) {
  2231. if ($each['tagid'] == $tagId) {
  2232. $result[$each['id']] = $each['name'];
  2233. }
  2234. }
  2235. }
  2236. return ($result);
  2237. }
  2238. /**
  2239. * Returns array of employee with some appointment substring only as id=>name
  2240. *
  2241. * @param array $allEmployeeData
  2242. * @param int $appointment
  2243. *
  2244. * @return array
  2245. */
  2246. function ts_EmployeeFilterAppointment($allEmployeeData, $appointment) {
  2247. $result = array();
  2248. if (!empty($allEmployeeData)) {
  2249. foreach ($allEmployeeData as $io => $each) {
  2250. if (ispos($each['appointment'], $appointment)) {
  2251. $result[$each['id']] = $each['name'];
  2252. }
  2253. }
  2254. }
  2255. return ($result);
  2256. }
  2257. /**
  2258. * Shows task editing/management form aka task profile
  2259. *
  2260. * @global object $ubillingConfig
  2261. * @param int $taskid
  2262. *
  2263. * @return void
  2264. */
  2265. function ts_TaskChangeForm($taskid) {
  2266. global $ubillingConfig;
  2267. $altCfg = $ubillingConfig->getAlter();
  2268. $taskid = vf($taskid, 3);
  2269. $taskdata = ts_GetTaskData($taskid);
  2270. $result = '';
  2271. $allemployee = ts_GetAllEmployee();
  2272. $activeemployee = ts_GetActiveEmployee();
  2273. @$employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached());
  2274. $alljobtypes = ts_GetAllJobtypes();
  2275. $messages = new UbillingMessageHelper();
  2276. $smsData = '';
  2277. $branchName = '';
  2278. if (!empty($taskdata)) {
  2279. //not done task
  2280. if (empty($taskdata['login'])) {
  2281. $login_detected = ts_DetectUserByAddress($taskdata['address']);
  2282. if ($login_detected) {
  2283. $addresslink = wf_Link("?module=userprofile&username=" . $login_detected, web_profile_icon() . ' ' . $taskdata['address'], false);
  2284. $loginType = ' (' . __('telepathically guessed') . ')';
  2285. $taskLogin = $login_detected;
  2286. } else {
  2287. $addresslink = $taskdata['address'];
  2288. $loginType = ' (' . __('No') . ' - ' . __('telepathically guessed') . ')';
  2289. $taskLogin = '';
  2290. }
  2291. } else {
  2292. $addresslink = wf_Link("?module=userprofile&username=" . $taskdata['login'], web_profile_icon() . ' ' . $taskdata['address'], false);
  2293. $taskLogin = $taskdata['login'];
  2294. $loginType = '';
  2295. }
  2296. //job generation form
  2297. if ($taskLogin) {
  2298. $jobgencheckbox = wf_CheckInput('generatejob', __('Generate job performed for this task'), true, true);
  2299. $jobgencheckbox .= wf_HiddenInput('generatelogin', $taskLogin);
  2300. $jobgencheckbox .= wf_HiddenInput('generatejobid', $taskdata['jobtype']);
  2301. $jobgencheckbox .= wf_delimiter();
  2302. } else {
  2303. $jobgencheckbox = '';
  2304. }
  2305. //modify form handlers
  2306. $modform = '';
  2307. if (cfr('TASKMANTRACK')) {
  2308. $modform .= wf_Link('?module=taskmantrack&trackid=' . $taskid, wf_img('skins/track_icon.png', __('Track this task'))) . ' ';
  2309. }
  2310. //warehouse mass-outcome helper
  2311. if (cfr('WAREHOUSEOUTRESERVE') or cfr('WAREHOUSEOUT')) {
  2312. if ($altCfg['WAREHOUSE_ENABLED']) {
  2313. if ($altCfg['TASKMAN_WAREHOUSE_HLPR']) {
  2314. if ($taskdata['status'] == 0 and $taskdata['employee'] != $altCfg['TASKMAN_ANYONE_EMPLOYEEID']) {
  2315. $massOutUrl = Warehouse::URL_ME . '&' . Warehouse::URL_RESERVE . '&massoutemployee=' . $taskdata['employee'] . '&taskidpreset=' . $taskid;
  2316. $modform .= wf_Link($massOutUrl, wf_img('skins/drain_icon.png', __('Mass outcome')), false, '', 'target="_BLANK"');
  2317. }
  2318. }
  2319. }
  2320. }
  2321. //task editing limitations
  2322. if (cfr('TASKMANEDITTASK')) {
  2323. $modform .= wf_modal(web_edit_icon(), __('Edit'), ts_TaskModifyForm($taskid), '', '450', '550') . ' ';
  2324. }
  2325. //modform end
  2326. //extracting sms data
  2327. if (!empty($taskdata['smsdata'])) {
  2328. $rawSmsData = $taskdata['smsdata'];
  2329. $rawSmsData = base64_decode($rawSmsData);
  2330. $rawSmsData = unserialize($rawSmsData);
  2331. $smsDataCells = wf_TableCell(__('Mobile'), '', 'row2');
  2332. $smsDataCells .= wf_TableCell($rawSmsData['number']);
  2333. $smsDataRows = wf_TableRow($smsDataCells, 'row3');
  2334. $smsDataCells = wf_TableCell(__('Message'), '', 'row2');
  2335. $smsDataCells .= wf_TableCell($rawSmsData['message']);
  2336. $smsDataRows .= wf_TableRow($smsDataCells, 'row3');
  2337. $smsDataTable = wf_TableBody($smsDataRows, '100%', '0', 'glamour');
  2338. $smsDataFlushControl = wf_delimiter() . wf_JSAlert('?module=taskman&edittask=' . $taskid . '&flushsmsdata=' . $taskid, web_delete_icon(), __('Are you serious'));
  2339. $smsData = wf_modal(wf_img('skins/icon_sms_micro.gif', __('SMS sent to employees')), __('SMS sent to employees'), $smsDataTable . $smsDataFlushControl, '', '400', '200');
  2340. } else {
  2341. //post sending form
  2342. if ($altCfg['SENDDOG_ENABLED']) {
  2343. $smsAddress = str_replace('\'', '`', $taskdata['address']);
  2344. $smsAddress = mysql_real_escape_string($smsAddress);
  2345. $smsPhone = mysql_real_escape_string($taskdata['phone']);
  2346. $smsJobTime = (!empty($taskdata['starttime'])) ? ' ' . date("H:i", strtotime($taskdata['starttime'])) : '';
  2347. $smsJobNote = mysql_real_escape_string($taskdata['jobnote']);
  2348. $smsEmployee = vf($taskdata['employee']);
  2349. $taskJobTypeId = $taskdata['jobtype'];
  2350. $taskJobTypeName = @$alljobtypes[$taskJobTypeId];
  2351. $newSmsText = $smsAddress . ' ' . $smsPhone . ' ' . $taskJobTypeName . ' ' . $smsJobNote . $smsJobTime;
  2352. $smsDataCells = wf_TableCell(__('Employee'), '', 'row2');
  2353. $smsDataCells .= wf_TableCell(@$allemployee[$taskdata['employee']]);
  2354. $smsDataRows = wf_TableRow($smsDataCells, 'row3');
  2355. $smsDataCells = wf_TableCell(__('Message'), '', 'row2');
  2356. $smsDataCells .= wf_TableCell(zb_TranslitString($newSmsText));
  2357. $smsDataRows .= wf_TableRow($smsDataCells, 'row3');
  2358. $smsDataTable = wf_TableBody($smsDataRows, '100%', '0', 'glamour');
  2359. $smsInputs = $smsDataTable;
  2360. $smsInputs .= wf_HiddenInput('postsendemployee', $smsEmployee);
  2361. $smsInputs .= wf_HiddenInput('postsendsmstext', $newSmsText);
  2362. $smsInputs .= wf_Submit(__('Send SMS'));
  2363. $smsForm = wf_Form('', 'POST', $smsInputs, '');
  2364. $smsData = wf_modal(wf_img_sized('skins/icon_mobile.gif', __('Send SMS'), '10'), __('Send SMS'), $smsForm, '', '400', '200');
  2365. }
  2366. }
  2367. $administratorName = (isset($employeeLogins[$taskdata['admin']])) ? $employeeLogins[$taskdata['admin']] : $taskdata['admin'];
  2368. $tablecells = wf_TableCell(__('ID'), '30%');
  2369. $tablecells .= wf_TableCell($taskdata['id']);
  2370. $tablerows = wf_TableRow($tablecells, 'row3');
  2371. $tablecells = wf_TableCell(__('Task creation date') . ' / ' . __('Administrator'));
  2372. $tablecells .= wf_TableCell($taskdata['date'] . ' / ' . $administratorName);
  2373. $tablerows .= wf_TableRow($tablecells, 'row3');
  2374. $tablecells = wf_TableCell(__('Target date'));
  2375. $tablecells .= wf_TableCell(wf_tag('strong') . $taskdata['startdate'] . ' ' . $taskdata['starttime'] . wf_tag('strong', true));
  2376. $tablerows .= wf_TableRow($tablecells, 'row3');
  2377. //here some build passport data
  2378. $bpData = '';
  2379. if ($altCfg['BUILD_EXTENDED']) {
  2380. if (!empty($taskLogin)) {
  2381. if (cfr('BUILDPASSPORT')) {
  2382. $allUserBuilds = zb_AddressGetBuildUsers();
  2383. if (isset($allUserBuilds[$taskLogin])) {
  2384. $taskUserBuildId = $allUserBuilds[$taskLogin];
  2385. $buildPassport = new BuildPassport();
  2386. $buildPassportData = $buildPassport->renderPassportData($taskUserBuildId);
  2387. if (!empty($buildPassportData)) {
  2388. $bpLink = $buildPassport::URL_PASSPORT . '&' . $buildPassport::ROUTE_BUILD . '=' . $taskUserBuildId;
  2389. $bpLink .= '&back=' . base64_encode('taskman&edittask=' . $taskid);
  2390. $buildPassportData = wf_CleanDiv() . $buildPassportData;
  2391. $buildPassportData .= wf_delimiter(0) . wf_Link($bpLink, wf_img('skins/icon_buildpassport.png') . ' ' . __('Go to build passport'), false, 'ubButton');
  2392. $bpData .= wf_modal(wf_img_sized('skins/icon_buildpassport.png', __('Build passport'), 12), __('Build passport'), $buildPassportData, '', 700);
  2393. }
  2394. }
  2395. }
  2396. }
  2397. }
  2398. $tablecells = wf_TableCell(__('Task address') . $bpData);
  2399. $tablecells .= wf_TableCell($addresslink);
  2400. $tablerows .= wf_TableRow($tablecells, 'row3');
  2401. // getting user's branch name
  2402. $branchConsider = (!empty($taskLogin)
  2403. and $ubillingConfig->getAlterParam('BRANCHES_ENABLED')
  2404. and $ubillingConfig->getAlterParam('TASKMAN_BRANCHES_CONSIDER_ON'));
  2405. if ($branchConsider) {
  2406. $branches = new UbillingBranches();
  2407. $branchName = $branches->userGetBranchName($taskLogin);
  2408. $branchName = (empty($branchName) ? '' : wf_Link($branches::URL_ME . '&userbranch=' . $taskLogin, $branchName));
  2409. $tablecells = wf_TableCell(__('Branch'));
  2410. $tablecells .= wf_TableCell($branchName);
  2411. $tablerows .= wf_TableRow($tablecells, 'row3');
  2412. }
  2413. $tablecells = wf_TableCell(__('Login'));
  2414. $tablecells .= wf_TableCell($taskLogin . $loginType);
  2415. $tablerows .= wf_TableRow($tablecells, 'row3');
  2416. if (!empty($taskLogin)) {
  2417. $allUserLogins = zb_UserGetAllDataCache();
  2418. if (isset($allUserLogins[$taskLogin])) {
  2419. $UserIpMAC = zb_UserGetAllData($taskLogin);
  2420. $tablecells = wf_TableCell(__('IP'));
  2421. $tablecells .= wf_TableCell(@$UserIpMAC[$taskLogin]['ip']);
  2422. $tablerows .= wf_TableRow($tablecells, 'row3');
  2423. $tablecells = wf_TableCell(__('MAC'));
  2424. $tablecells .= wf_TableCell(@$UserIpMAC[$taskLogin]['mac']);
  2425. $tablerows .= wf_TableRow($tablecells, 'row3');
  2426. if (@$altCfg['TASKMAN_SHOW_USERTAGS']) {
  2427. $userTags = __('No');
  2428. $userTagsRaw = zb_UserGetAllTags($taskLogin);
  2429. if (!empty($userTagsRaw)) {
  2430. $userTagsRaw = $userTagsRaw[$taskLogin];
  2431. $userTags = implode(', ', $userTagsRaw);
  2432. }
  2433. $tablecells = wf_TableCell(__('Tags'));
  2434. $tablecells .= wf_TableCell($userTags);
  2435. $tablerows .= wf_TableRow($tablecells, 'row3');
  2436. }
  2437. if (@$altCfg['SWITCHPORT_IN_PROFILE']) {
  2438. $allAssigns = zb_SwitchesGetAssignsAll();
  2439. if (isset($allAssigns[$taskLogin])) {
  2440. $tablecells = wf_TableCell(__('Switch'));
  2441. $tablecells .= wf_TableCell(@$allAssigns[$taskLogin]['label']);
  2442. $tablerows .= wf_TableRow($tablecells, 'row3');
  2443. }
  2444. }
  2445. if ($ubillingConfig->getAlterParam('TASKMAN_RENDER_ONU_SIGNAL')) {
  2446. $onuLinkFlag=(cfr('PON')) ? true : false;
  2447. $tablecells = wf_TableCell(__('ONU Signal'));
  2448. $tablecells .= wf_TableCell(zb_getPonSignalData($taskLogin, true, false, $onuLinkFlag));
  2449. $tablerows .= wf_TableRow($tablecells, 'row3');
  2450. }
  2451. }
  2452. }
  2453. $tablecells = wf_TableCell(__('Phone'));
  2454. $tablecells .= wf_TableCell($taskdata['phone']);
  2455. $tablerows .= wf_TableRow($tablecells, 'row3');
  2456. $tablecells = wf_TableCell(__('Job type'));
  2457. $tablecells .= wf_TableCell(@$alljobtypes[$taskdata['jobtype']]);
  2458. $tablerows .= wf_TableRow($tablecells, 'row3');
  2459. $tablecells = wf_TableCell(__('Who should do'));
  2460. $tablecells .= wf_TableCell(@$allemployee[$taskdata['employee']] . ' ' . $smsData);
  2461. $tablerows .= wf_TableRow($tablecells, 'row3');
  2462. $tablecells = wf_TableCell(__('Job note'));
  2463. $tablecells .= wf_TableCell(nl2br($taskdata['jobnote']));
  2464. $tablerows .= wf_TableRow($tablecells, 'row3');
  2465. if (@$altCfg['TASKRANKS_ENABLED']) {
  2466. $taskRanksReadOnly = (!cfr('TASKRANKS')) ? true : false;
  2467. $taskFails = new Stigma('TASKFAILS', $taskid);
  2468. if (!$taskRanksReadOnly) {
  2469. $taskFails->stigmaController('TASKMAN:Task checklist fails');
  2470. }
  2471. $taskRanks = new Stigma('TASKRANKS', $taskid);
  2472. if (!$taskRanksReadOnly) {
  2473. $taskRanks->stigmaController('TASKMAN:Score');
  2474. }
  2475. $taskRanksInterface = '';
  2476. $taskRanksInterface .= __('Task checklist fails') . wf_delimiter(0);
  2477. $taskRanksInterface .= $taskFails->render($taskid, 128, $taskRanksReadOnly) . wf_delimiter(0);
  2478. $taskRanksInterface .= __('User rating of task completion') . wf_delimiter(0);
  2479. $taskRanksInterface .= $taskRanks->render($taskid, 64, $taskRanksReadOnly);
  2480. $taskHaveFails = $taskFails->haveState($taskid);
  2481. $taskHaveRank = $taskRanks->haveState($taskid);
  2482. $rankTextLabels = '';
  2483. if ($taskHaveFails) {
  2484. $rankTextLabels .= ' ' . $taskFails->textRender($taskid, ' ', '10') . ' ';
  2485. }
  2486. if ($taskHaveRank) {
  2487. $rankTextLabels .= __('Score') . ': ' . $taskRanks->textRender($taskid, '', '10');
  2488. }
  2489. $ranksModalLabel = __('Edit');
  2490. if (!$taskRanksReadOnly) {
  2491. $taskRanksModal = wf_modalAuto($ranksModalLabel, __('Quality control'), $taskRanksInterface, '');
  2492. } else {
  2493. $taskRanksModal = '';
  2494. }
  2495. $tablecells = wf_TableCell(__('Quality control'));
  2496. $tablecells .= wf_TableCell($taskRanksModal . $rankTextLabels);
  2497. $tablerows .= wf_TableRow($tablecells, 'row3');
  2498. }
  2499. $result .= wf_TableBody($tablerows, '100%', '0', 'glamour');
  2500. $result .= wf_CleanDiv();
  2501. // show task preview
  2502. show_window(__('View task') . ' ' . $modform, $result);
  2503. // Task logs
  2504. if (cfr('TASKMANNWATCHLOG')) {
  2505. show_window(__('View log'), ts_renderLogsListAjax($taskid));
  2506. }
  2507. //Task duplicates check
  2508. if (@$altCfg['TASKMAN_DUPLICATE_CHECK']) {
  2509. ts_CheckDailyDuplicates($taskdata, $altCfg['TASKMAN_DUPLICATE_CHECK']);
  2510. }
  2511. //Salary accounting
  2512. if ($altCfg['SALARY_ENABLED']) {
  2513. if (cfr('SALARYTASKSVIEW')) {
  2514. $salary = new Salary($taskid);
  2515. show_window(__('Additional jobs done'), $salary->taskJobCreateForm($taskid));
  2516. }
  2517. }
  2518. //warehouse integration
  2519. if ($altCfg['WAREHOUSE_ENABLED']) {
  2520. if (cfr('WAREHOUSE') or cfr('WAREVIEW')) {
  2521. $warehouse = new Warehouse($taskid);
  2522. show_window(__('Additionally spent materials'), $warehouse->taskMaterialsReport($taskid));
  2523. }
  2524. }
  2525. //if task undone
  2526. if ($taskdata['status'] == 0) {
  2527. $empTagidFilter = @$altCfg['TASKMAN_EMPLOYEE_TAGID_FILTER'];
  2528. $empAppointFilter = @$altCfg['TASKMAN_EMPLOYEE_APPOINTMENT_FILTER'];
  2529. $empFilteredFlag = false;
  2530. if ($empTagidFilter) {
  2531. $allTagTypes = stg_get_alltagnames();
  2532. }
  2533. $doneEmployeeList = $activeemployee; //defaults
  2534. //tagid employee filter
  2535. if (ubRouting::checkGet('empfiltertagid')) {
  2536. $allEmployeeData = ts_GetAllEmployeeData();
  2537. $doneEmployeeList = ts_EmployeeFilterTagId($allEmployeeData, ubRouting::get('empfiltertagid'));
  2538. $empFilteredFlag = true;
  2539. }
  2540. //appointment employee filter
  2541. if (ubRouting::checkGet('empfilterappointment')) {
  2542. $allEmployeeData = ts_GetAllEmployeeData();
  2543. $doneEmployeeList = ts_EmployeeFilterAppointment($allEmployeeData, ubRouting::get('empfilterappointment'));
  2544. $empFilteredFlag = true;
  2545. }
  2546. $sup = wf_tag('sup') . '*' . wf_tag('sup', false);
  2547. $inputs = wf_HiddenInput('changetask', $taskid);
  2548. $inputs .= wf_HiddenInput('change_admin', whoami());
  2549. if ((cfr('TASKMANNODONDATE')) and (!cfr('ROOT'))) {
  2550. //manual done date selection forbidden
  2551. $inputs .= wf_HiddenInput('editenddate', curdate());
  2552. } else {
  2553. $inputs .= wf_DatePicker('editenddate') . wf_tag('label', false) . __('Finish date') . $sup . wf_tag('label', true) . wf_tag('br');
  2554. }
  2555. $inputs .= wf_tag('br');
  2556. //employee custom selector here
  2557. if (@$altCfg['TASKMAN_EMPDONESEL_SEARCHBL']) {
  2558. $inputs .= wf_SelectorSearchable('editemployeedone', $doneEmployeeList, __('Worker done'), $taskdata['employee'], true);
  2559. } else {
  2560. $inputs .= wf_Selector('editemployeedone', $doneEmployeeList, __('Worker done'), $taskdata['employee'], true);
  2561. }
  2562. //custom employee filters enabled?
  2563. if ($empTagidFilter or $empAppointFilter) {
  2564. $inputs .= wf_tag('br');
  2565. if ($empFilteredFlag) {
  2566. $empNoFlUrl = '?module=taskman&edittask=' . $taskid;
  2567. $inputs .= wf_Link($empNoFlUrl, wf_img('skins/icon_cleanup.png') . ' ' . __('Any'), false, 'ubButton');
  2568. }
  2569. if ($empTagidFilter) {
  2570. $empTagIdFlUrl = '?module=taskman&edittask=' . $taskid . '&empfiltertagid=' . $empTagidFilter;
  2571. $inputs .= wf_Link($empTagIdFlUrl, wf_img('skins/tagiconsmall.png') . ' ' . @$allTagTypes[$empTagidFilter], false, 'ubButton');
  2572. }
  2573. if ($empAppointFilter) {
  2574. $empAppFlUrl = '?module=taskman&edittask=' . $taskid . '&empfilterappointment=' . $empAppointFilter;
  2575. $inputs .= wf_Link($empAppFlUrl, wf_img('skins/shovel.png') . ' ' . $empAppointFilter, false, 'ubButton');
  2576. }
  2577. $inputs .= wf_tag('br');
  2578. }
  2579. $inputs .= wf_tag('br');
  2580. $inputs .= wf_tag('label', false) . __('Finish note') . wf_tag('label', true) . wf_tag('br');
  2581. $inputs .= wf_TextArea('editdonenote', '', '', true, '55x4');
  2582. $inputs .= wf_tag('br');
  2583. $inputs .= $jobgencheckbox;
  2584. $inputs .= wf_Submit(__('This task is done'));
  2585. $form = wf_Form("", 'POST', $inputs, 'glamour');
  2586. if (cfr('TASKMANDELETE')) {
  2587. show_window('', wf_JSAlertStyled('?module=taskman&deletetask=' . $taskid, web_delete_icon() . ' ' . __('Remove this task - it is an mistake'), $messages->getDeleteAlert(), 'ubButton'));
  2588. }
  2589. //show editing form
  2590. if (cfr('TASKMANDONE')) {
  2591. show_window(__('If task is done'), $form);
  2592. }
  2593. } else {
  2594. $donecells = wf_TableCell(__('Finish date'), '30%');
  2595. $donecells .= wf_TableCell($taskdata['enddate']);
  2596. $donerows = wf_TableRow($donecells, 'row3');
  2597. $donecells = wf_TableCell(__('Worker done'));
  2598. $donecells .= wf_TableCell((empty($allemployee[$taskdata['employeedone']]) ? '' : $allemployee[$taskdata['employeedone']]));
  2599. $donerows .= wf_TableRow($donecells, 'row3');
  2600. $donecells = wf_TableCell(__('Finish note'));
  2601. $donecells .= wf_TableCell($taskdata['donenote']);
  2602. $donerows .= wf_TableRow($donecells, 'row3');
  2603. $administratorChange = (isset($employeeLogins[$taskdata['change_admin']])) ? $employeeLogins[$taskdata['change_admin']] : $taskdata['change_admin'];
  2604. $donecells = wf_TableCell(__('Administrator'));
  2605. $donecells .= wf_TableCell($administratorChange);
  2606. $donerows .= wf_TableRow($donecells, 'row3');
  2607. $doneresult = wf_TableBody($donerows, '100%', '0', 'glamour');
  2608. if (cfr('TASKMANDELETE')) {
  2609. $doneresult .= wf_JSAlertStyled('?module=taskman&deletetask=' . $taskid, web_delete_icon() . ' ' . __('Remove this task - it is an mistake'), $messages->getDeleteAlert(), 'ubButton');
  2610. }
  2611. if (cfr('TASKMANDONE')) {
  2612. $doneresult .= '&nbsp;';
  2613. $doneresult .= wf_JSAlertStyled('?module=taskman&setundone=' . $taskid, wf_img('skins/icon_key.gif') . ' ' . __('No work was done'), $messages->getEditAlert(), 'ubButton');
  2614. }
  2615. show_window(__('Task is done'), $doneresult);
  2616. }
  2617. }
  2618. }
  2619. /**
  2620. * Deletes existing task from database
  2621. *
  2622. * @param int $taskid
  2623. *
  2624. * @return void
  2625. */
  2626. function ts_DeleteTask($taskid) {
  2627. $taskid = vf($taskid, 3);
  2628. // Before delete task - write task data to log
  2629. $task_data = ts_GetTaskData($taskid);
  2630. $queryLogTask = ("
  2631. INSERT INTO `taskmanlogs` (`id`, `taskid`, `date`, `admin`, `ip`, `event`, `logs`)
  2632. VALUES (NULL, '" . $taskid . "', CURRENT_TIMESTAMP, '" . whoami() . "', '" . @$_SERVER['REMOTE_ADDR'] . "', 'delete',
  2633. '" . serialize($task_data) . "')
  2634. ");
  2635. nr_query($queryLogTask);
  2636. $query = "DELETE from `taskman` WHERE `id`='" . $taskid . "'";
  2637. nr_query($query);
  2638. log_register('TASKMAN DELETE [' . $taskid . ']');
  2639. }
  2640. /**
  2641. * Find all log for task
  2642. *
  2643. * @param int $taskid
  2644. *
  2645. * @return void
  2646. */
  2647. function ts_GetLogTask($taskid) {
  2648. $result = '';
  2649. if (!empty($taskid)) {
  2650. $query = "SELECT * FROM `taskmanlogs` WHERE taskid = '" . $taskid . "' ORDER BY `id` ASC";
  2651. } else {
  2652. $renderYear = (ubRouting::checkGet('renderyear')) ? ubRouting::get('renderyear', 'int') : curyear();
  2653. if ($renderYear == '1488') {
  2654. //all time tasks
  2655. $renderYear = '%';
  2656. }
  2657. $query = "SELECT * FROM `taskmanlogs` WHERE `date` LIKE '" . $renderYear . "-%' ORDER BY `id` DESC";
  2658. }
  2659. $resultLog = simple_queryall($query);
  2660. if (!empty($resultLog)) {
  2661. $result = $resultLog;
  2662. }
  2663. return ($result);
  2664. }
  2665. /**
  2666. * Render panel for tas logs
  2667. *
  2668. * @param int $taskid
  2669. *
  2670. * @return void
  2671. */
  2672. function ts_renderLogsListAjax($taskid = '') {
  2673. $result = '';
  2674. // Task logs
  2675. if (cfr('TASKMANNWATCHLOG')) {
  2676. $resultLogAjax = '';
  2677. $columns = array('ID');
  2678. if (empty($taskid)) {
  2679. $opts = '"order": [[ 0, "desc" ]]';
  2680. $columns[] = 'Task ID';
  2681. } else {
  2682. $opts = '"order": [[ 0, "asc" ]]';
  2683. }
  2684. $columns[] = 'Date';
  2685. $columns[] = 'Login';
  2686. $columns[] = 'IP';
  2687. $columns[] = 'Events';
  2688. $columns[] = 'Logs';
  2689. $renderYear = (ubRouting::checkPost('renderyear')) ? ubRouting::post('renderyear', 'int') : '';
  2690. $module_link = (empty($taskid)) ? '?module=taskman&ajaxlog=true' : '?module=taskman&ajaxlog=true&edittask=' . $taskid;
  2691. if (!empty($renderYear)) {
  2692. $module_link .= '&renderyear=' . $renderYear;
  2693. }
  2694. $result = wf_JqDtLoader($columns, $module_link, false, 'Logs', 100, $opts);
  2695. if (empty($taskid)) {
  2696. //appending year selector form
  2697. $inputs = wf_YearSelectorPreset('renderyear', __('Year'), false, $renderYear, true) . ' ';
  2698. $inputs .= wf_Submit(__('Show'));
  2699. $result .= wf_delimiter(0);
  2700. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  2701. }
  2702. }
  2703. return ($result);
  2704. }
  2705. /**
  2706. * Find all log for task
  2707. *
  2708. * @param int $taskid
  2709. *
  2710. * @return void
  2711. */
  2712. function ts_renderLogsDataAjax($taskid = '') {
  2713. $taskid = vf($taskid, 3);
  2714. $result_log = ts_GetLogTask($taskid);
  2715. @$employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached());
  2716. $json = new wf_JqDtHelper();
  2717. if (!empty($result_log)) {
  2718. $allemployee = ts_GetAllEmployee();
  2719. $alljobtypes = ts_GetAllJobtypes();
  2720. $taskStates = new TaskStates(true);
  2721. foreach ($result_log as $each) {
  2722. $administratorChange = (isset($employeeLogins[$each['admin']])) ? $employeeLogins[$each['admin']] : $each['admin'];
  2723. $data[] = $each['id'];
  2724. if (empty($taskid)) {
  2725. $data[] = wf_link('?module=taskman&edittask=' . $each['taskid'], $each['taskid']);
  2726. }
  2727. $data[] = $each['date'];
  2728. $data[] = $administratorChange;
  2729. $data[] = $each['ip'];
  2730. if ($each['event'] == 'create') {
  2731. $data[] = __('Create task');
  2732. $data_event = @unserialize($each['logs']);
  2733. } elseif ($each['event'] == 'modify') {
  2734. $data[] = __('Edit task');
  2735. $data_event = '';
  2736. $logDataArr = @unserialize($each['logs']);
  2737. if (isset($logDataArr['address'])) {
  2738. $data_event .= wf_tag('b') . __('Task address') . ": " . wf_tag('b', true);
  2739. $data_event .= wf_tag('font', false, '', 'color="green"') . $logDataArr['address']['old'] . wf_tag('font', true);
  2740. $data_event .= " => ";
  2741. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['address']['new'] . wf_tag('font', true);
  2742. $data_event .= wf_tag('br');
  2743. }
  2744. if (isset($logDataArr['login'])) {
  2745. $data_event .= wf_tag('b') . __('Login') . ": " . wf_tag('b', true);
  2746. $data_event .= wf_tag('font', false, '', 'color="green"') . $logDataArr['login']['old'] . wf_tag('font', true);
  2747. $data_event .= " => ";
  2748. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['login']['new'] . wf_tag('font', true);
  2749. $data_event .= wf_tag('br');
  2750. }
  2751. if (isset($logDataArr['jobtype'])) {
  2752. $jobTypeIdOld = $logDataArr['jobtype']['old'];
  2753. $jobTypeIdNew = $logDataArr['jobtype']['new'];
  2754. $jobtypeOld = @$alljobtypes[$jobTypeIdOld];
  2755. $jobtypeNew = @$alljobtypes[$jobTypeIdNew];
  2756. $data_event .= wf_tag('b') . __('Job type') . ": " . wf_tag('b', true);
  2757. $data_event .= wf_tag('font', false, '', 'color="green"') . $jobtypeOld . wf_tag('font', true);
  2758. $data_event .= " => ";
  2759. $data_event .= wf_tag('font', false, '', 'color="red"') . $jobtypeNew . wf_tag('font', true);
  2760. $data_event .= wf_tag('br');
  2761. }
  2762. if (isset($logDataArr['jobnote'])) {
  2763. $data_event .= wf_tag('b') . __('Job note') . ": " . wf_tag('b', true);
  2764. $data_event .= wf_tag('font', false, '', 'color="green"') . $logDataArr['jobnote']['old'] . wf_tag('font', true);
  2765. $data_event .= " => ";
  2766. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['jobnote']['new'] . wf_tag('font', true);
  2767. $data_event .= wf_tag('br');
  2768. }
  2769. if (isset($logDataArr['phone'])) {
  2770. $data_event .= wf_tag('b') . __('phone') . ": " . wf_tag('b', true);
  2771. $data_event .= wf_tag('font', false, '', 'color="green"') . $logDataArr['phone']['old'] . wf_tag('font', true);
  2772. $data_event .= " => ";
  2773. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['phone']['new'] . wf_tag('font', true);
  2774. $data_event .= wf_tag('br');
  2775. }
  2776. if (isset($logDataArr['employee'])) {
  2777. $employeeIdOld = $logDataArr['employee']['old'];
  2778. $employeeIdNew = $logDataArr['employee']['new'];
  2779. $employeeOld = @$allemployee[$employeeIdOld];
  2780. $employeeNew = @$allemployee[$employeeIdNew];
  2781. $data_event .= wf_tag('b') . __('Worker') . ": " . wf_tag('b', true);
  2782. $data_event .= wf_tag('font', false, '', 'color="green"') . $employeeOld . wf_tag('font', true);
  2783. $data_event .= " => ";
  2784. $data_event .= wf_tag('font', false, '', 'color="red"') . $employeeNew . wf_tag('font', true);
  2785. $data_event .= wf_tag('br');
  2786. }
  2787. if (isset($logDataArr['startdate'])) {
  2788. $data_event .= wf_tag('b') . __('Target date') . ": " . wf_tag('b', true);
  2789. $data_event .= wf_tag('font', false, '', 'color="green"') . $logDataArr['startdate']['old'] . wf_tag('font', true);
  2790. $data_event .= " => ";
  2791. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['startdate']['new'] . wf_tag('font', true);
  2792. $data_event .= wf_tag('br');
  2793. }
  2794. if (isset($logDataArr['starttime'])) {
  2795. $data_event .= wf_tag('b') . __('Target date') . ": " . wf_tag('b', true);
  2796. $data_event .= wf_tag('font', false, '', 'color="green"') . $logDataArr['starttime']['old'] . wf_tag('font', true);
  2797. $data_event .= " => ";
  2798. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['starttime']['new'] . wf_tag('font', true);
  2799. $data_event .= wf_tag('br');
  2800. }
  2801. if (isset($logDataArr['taskstate'])) {
  2802. $data_event .= wf_tag('b') . __('Task state') . ": " . wf_tag('b', true);
  2803. $data_event .= wf_tag('font', false, '', 'color="green"') . $taskStates->getStateName($logDataArr['taskstate']['old']) . wf_tag('font', true);
  2804. $data_event .= " => ";
  2805. $data_event .= wf_tag('font', false, '', 'color="red"') . $taskStates->getStateName($logDataArr['taskstate']['new']) . wf_tag('font', true);
  2806. $data_event .= wf_tag('br');
  2807. }
  2808. if (isset($logDataArr['taskparam'])) {
  2809. $oldParam = (!empty($logDataArr['taskparam']['old'])) ? $logDataArr['taskparam']['old'] : 'none';
  2810. $newParam = (!empty($logDataArr['taskparam']['new'])) ? $logDataArr['taskparam']['new'] : 'none';
  2811. $paramName = (!empty($logDataArr['taskparam']['name'])) ? $logDataArr['taskparam']['name'] : 'Parameter';
  2812. $data_event .= wf_tag('b') . __($paramName) . ": " . wf_tag('b', true);
  2813. $data_event .= wf_tag('font', false, '', 'color="green"') . __($oldParam) . wf_tag('font', true);
  2814. $data_event .= " => ";
  2815. $data_event .= wf_tag('font', false, '', 'color="red"') . __($logDataArr['taskparam']['new']) . wf_tag('font', true);
  2816. $data_event .= wf_tag('br');
  2817. }
  2818. } elseif ($each['event'] == 'done') {
  2819. $data[] = __('Task is done');
  2820. $data_event = '';
  2821. $logDataArr = @unserialize($each['logs']);
  2822. $data_event .= wf_tag('b') . __('Finish date') . ": " . wf_tag('b', true);
  2823. $data_event .= wf_tag('font', false, '', 'color="green"') . $logDataArr['editenddate'] . wf_tag('font', true);
  2824. $data_event .= wf_tag('br');
  2825. $data_event .= wf_tag('b') . __('Worker done') . ": " . wf_tag('b', true);
  2826. $data_event .= wf_tag('font', false, '', 'color="green"') . @$allemployee[$logDataArr['editemployeedone']] . wf_tag('font', true);
  2827. $data_event .= wf_tag('br');
  2828. $data_event .= wf_tag('b') . __('Finish note') . ": " . wf_tag('b', true);
  2829. $data_event .= wf_tag('font', false, '', 'color="green"') . $logDataArr['editdonenote'] . wf_tag('font', true);
  2830. $data_event .= wf_tag('br');
  2831. } elseif ($each['event'] == 'setundone') {
  2832. $data[] = __('No work was done');
  2833. $data_event = wf_tag('font', false, '', 'color="red"') . wf_tag('b') . __('No work was done') . wf_tag('b', true) . wf_tag('font', true);
  2834. } elseif ($each['event'] == 'delete') {
  2835. $data[] = __('Task delete');
  2836. $data_event = '';
  2837. $logDataArr = @unserialize($each['logs']);
  2838. if ($logDataArr) {
  2839. $data_event .= wf_tag('b') . __('Create date') . ": " . wf_tag('b', true);
  2840. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['date'] . wf_tag('font', true);
  2841. $data_event .= wf_tag('br');
  2842. $data_event .= wf_tag('b') . __('Task address') . ": " . wf_tag('b', true);
  2843. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['address'] . wf_tag('font', true);
  2844. $data_event .= wf_tag('br');
  2845. $data_event .= wf_tag('b') . __('Login') . ": " . wf_tag('b', true);
  2846. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['login'] . wf_tag('font', true);
  2847. $data_event .= wf_tag('br');
  2848. $data_event .= wf_tag('b') . __('Job type') . ": " . wf_tag('b', true);
  2849. $data_event .= wf_tag('font', false, '', 'color="red"') . @$alljobtypes[$logDataArr['jobtype']] . wf_tag('font', true);
  2850. $data_event .= wf_tag('br');
  2851. $data_event .= wf_tag('b') . __('Job note') . ": " . wf_tag('b', true);
  2852. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['jobnote'] . wf_tag('font', true);
  2853. $data_event .= wf_tag('br');
  2854. $data_event .= wf_tag('b') . __('Phone') . ": " . wf_tag('b', true);
  2855. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['phone'] . wf_tag('font', true);
  2856. $data_event .= wf_tag('br');
  2857. $data_event .= wf_tag('b') . __('Worker') . ": " . wf_tag('b', true);
  2858. $data_event .= wf_tag('font', false, '', 'color="red"') . @$allemployee[$logDataArr['employee']] . wf_tag('font', true);
  2859. $data_event .= wf_tag('br');
  2860. $data_event .= wf_tag('b') . __('Worker done') . ": " . wf_tag('b', true);
  2861. $data_event .= wf_tag('font', false, '', 'color="red"') . @$allemployee[$logDataArr['employeedone']] . wf_tag('font', true);
  2862. $data_event .= wf_tag('br');
  2863. $data_event .= wf_tag('b') . __('Target date') . ": " . wf_tag('b', true);
  2864. $data_event .= wf_tag('font', false, '', 'color="red"') . $logDataArr['startdate'] . " " . $logDataArr['starttime'] . wf_tag('font', true);
  2865. $data_event .= wf_tag('br');
  2866. $data_event .= wf_tag('b') . __('Admin') . ": " . wf_tag('b', true);
  2867. $data_event .= wf_tag('font', false, '', 'color="red"') . @$employeeLogins[$logDataArr['admin']] . wf_tag('font', true);
  2868. $data_event .= wf_tag('br');
  2869. $data_event .= wf_tag('b') . __('Status') . ": " . wf_tag('b', true);
  2870. $data_event .= web_bool_led($logDataArr['status']);
  2871. $data_event .= wf_tag('br');
  2872. } else {
  2873. $data[] = __('Log data corrupted');
  2874. }
  2875. } else {
  2876. $data[] = __($each['event']);
  2877. $data_event = $each['logs'];
  2878. }
  2879. $data[] = $data_event;
  2880. $json->addRow($data);
  2881. unset($data);
  2882. }
  2883. }
  2884. $json->getJson();
  2885. }
  2886. /**
  2887. * Logs some parameter change for some task
  2888. *
  2889. * @param int $taskId existing task ID
  2890. * @param string $parameter parameter name which changed
  2891. * @param string $oldValue old parameter value
  2892. * @param string $newValue new parameter value
  2893. * @param bool $weblog log to weblogs table?
  2894. *
  2895. * @retrun void
  2896. */
  2897. function ts_logTaskChange($taskId, $parameter, $oldValue, $newValue, $weblog = false) {
  2898. $taskId = ubRouting::filters($taskId, 'int');
  2899. $parameter = ubRouting::filters($parameter, 'mres');
  2900. $oldValue = ubRouting::filters($oldValue, 'mres');
  2901. $newValue = ubRouting::filters($newValue, 'mres');
  2902. $log_data_arr = array();
  2903. $logData['taskparam']['name'] = $parameter;
  2904. $logData['taskparam']['old'] = $oldValue;
  2905. $logData['taskparam']['new'] = $newValue;
  2906. $storeLogData = serialize($logData);
  2907. $taskmanLogs = new NyanORM('taskmanlogs');
  2908. $taskmanLogs->data('taskid', $taskId);
  2909. $taskmanLogs->data('date', curdatetime());
  2910. $taskmanLogs->data('admin', whoami());
  2911. $taskmanLogs->data('ip', @$_SERVER['REMOTE_ADDR']);
  2912. $taskmanLogs->data('event', 'modify');
  2913. $taskmanLogs->data('logs', $storeLogData);
  2914. $taskmanLogs->create();
  2915. if ($weblog) {
  2916. log_register('TASKSTATE CHANGE TASK [' . $taskId . '] PARAM `' . $parameter . '` ON `' . $newValue . '`');
  2917. }
  2918. }
  2919. /**
  2920. * Returns task typical problems editing form
  2921. *
  2922. * @return string
  2923. */
  2924. function ts_TaskProblemsEditForm() {
  2925. $rawNotes = zb_StorageGet('PROBLEMS');
  2926. //extract old or create new typical problems array
  2927. if (!empty($rawNotes)) {
  2928. $rawNotes = base64_decode($rawNotes);
  2929. $rawNotes = unserialize($rawNotes);
  2930. } else {
  2931. $emptyArray = array();
  2932. $newNotes = serialize($emptyArray);
  2933. $newNotes = base64_encode($newNotes);
  2934. zb_StorageSet('PROBLEMS', $newNotes);
  2935. $rawNotes = $emptyArray;
  2936. }
  2937. //adding and deletion subroutines
  2938. if (wf_CheckPost(array('createtypicalnote'))) {
  2939. $toPush = strip_tags($_POST['createtypicalnote']);
  2940. array_push($rawNotes, $toPush);
  2941. $newNotes = serialize($rawNotes);
  2942. $newNotes = base64_encode($newNotes);
  2943. zb_StorageSet('PROBLEMS', $newNotes);
  2944. log_register('TASKMAN ADD TYPICALPROBLEM');
  2945. rcms_redirect("?module=tasksprobcfg");
  2946. }
  2947. if (wf_CheckPost(array('deletetypicalnote', 'typicalnote'))) {
  2948. $toUnset = $_POST['typicalnote'];
  2949. if (($delkey = array_search($toUnset, $rawNotes)) !== false) {
  2950. unset($rawNotes[$delkey]);
  2951. }
  2952. $newNotes = serialize($rawNotes);
  2953. $newNotes = base64_encode($newNotes);
  2954. zb_StorageSet('PROBLEMS', $newNotes);
  2955. log_register('TASKMAN DELETE TYPICALPROBLEM');
  2956. rcms_redirect("?module=tasksprobcfg");
  2957. }
  2958. $rows = '';
  2959. $result = wf_BackLink("?module=taskman", '', true);
  2960. if (!empty($rawNotes)) {
  2961. foreach ($rawNotes as $eachNote) {
  2962. $cells = wf_TableCell($eachNote);
  2963. $rows .= wf_TableRow($cells, 'row3');
  2964. }
  2965. }
  2966. $result .= wf_TableBody($rows, '100%', '0', '');
  2967. $result .= wf_delimiter();
  2968. $addinputs = wf_TextInput('createtypicalnote', __('Create'), '', true, '20');
  2969. $addinputs .= wf_Submit(__('Save'));
  2970. $addform = wf_Form("", "POST", $addinputs, 'glamour');
  2971. $result .= $addform;
  2972. $delinputs = ts_TaskTypicalNotesSelector(false);
  2973. $delinputs .= wf_HiddenInput('deletetypicalnote', 'true');
  2974. $delinputs .= wf_Submit(__('Delete'));
  2975. $delform = wf_Form("", "POST", $delinputs, 'glamour');
  2976. $result .= $delform;
  2977. return ($result);
  2978. }
  2979. /**
  2980. * Checks is current administrator cursed by some branch?
  2981. *
  2982. * @global object $ubillingConfig
  2983. *
  2984. * @return bool
  2985. */
  2986. function ts_isMeBranchCursed() {
  2987. global $ubillingConfig;
  2988. $result = false;
  2989. if ($ubillingConfig->getAlterParam('BRANCHES_ENABLED') or $ubillingConfig->getAlterParam('TASKMAN_GULAG')) {
  2990. if (cfr('ROOT')) {
  2991. $result = false;
  2992. } else {
  2993. if (cfr('BRANCHES') or cfr('TASKMANGULAG')) {
  2994. if (cfr('TSUNCURSED')) {
  2995. //gulag and branches curse excluding right
  2996. $result = false;
  2997. } else {
  2998. $result = true;
  2999. }
  3000. }
  3001. }
  3002. } else {
  3003. $result = false;
  3004. }
  3005. return ($result);
  3006. }
  3007. /**
  3008. * Returns tasks by date printing dialogue
  3009. *
  3010. * @return string
  3011. */
  3012. function ts_PrintDialogue() {
  3013. global $ubillingConfig;
  3014. $advFiltersEnabled = $ubillingConfig->getAlterParam('TASKMAN_ADV_FILTERS');
  3015. $submitOpts = '';
  3016. $tmpInputs = '';
  3017. $inputs = '';
  3018. $inputs .= wf_tag('span', false, 'col-1-2-occupy');
  3019. $inputs .= wf_tag('h3');
  3020. $inputs .= __('From') . wf_nbsp(2);
  3021. $inputs .= wf_tag('h3', true);
  3022. $inputs .= wf_DatePickerPreset('printdatefrom', curdate());
  3023. $inputs .= wf_nbsp(8);
  3024. $inputs .= wf_tag('h3');
  3025. $inputs .= __('To') . wf_nbsp(2);
  3026. $inputs .= wf_tag('h3', true);
  3027. $inputs .= wf_DatePickerPreset('printdateto', curdate());
  3028. $inputs .= wf_tag('span', true);
  3029. if ($advFiltersEnabled) {
  3030. $whoami = whoami();
  3031. $employeeid = ts_GetEmployeeByLogin($whoami);
  3032. if ($employeeid) {
  3033. $curselected = (isset($_POST['displaytype'])) ? $_POST['displaytype'] : '';
  3034. $displayTypes = array('all' => __('Show tasks for all users'), 'onlyme' => __('Show only mine tasks'));
  3035. $tmpInputs .= wf_Selector('displaytype', $displayTypes, '', $curselected, false, false, '', 'col-3-4-occupy');
  3036. }
  3037. $tmpInputs .= ts_AdvFiltersControls();
  3038. $tmpInputs .= wf_tag('span', false, 'col-1-2-occupy', '');
  3039. $tmpInputs .= wf_CheckInput('nopagebreaks', __('No page breaks for each employee'), false, false);
  3040. $tmpInputs .= wf_tag('span', true);
  3041. }
  3042. $inputs .= $tmpInputs;
  3043. $inputs .= wf_tag('span', false, '');
  3044. $inputs .= wf_CheckInput('tableview', __('Grid view'), false, true) . ' ';
  3045. $inputs .= wf_tag('span', true);
  3046. $inputs .= wf_SubmitClassed(true, 'ubButton', '', __('Print'), '', $submitOpts);
  3047. $result = wf_Form("", 'POST', $inputs, 'glamour form-grid-4cols form-grid-4cols-label-right ');
  3048. return ($result);
  3049. }
  3050. /**
  3051. * Renders printable tasks filtered by dates
  3052. *
  3053. * @param string $datefrom
  3054. * @param string $dateto
  3055. *
  3056. * @return void
  3057. */
  3058. function ts_PrintTasks($datefrom, $dateto) {
  3059. global $ubillingConfig;
  3060. $advFiltersEnabled = $ubillingConfig->getAlterParam('TASKMAN_ADV_FILTERS');
  3061. $branchConsider = ($ubillingConfig->getAlterParam('BRANCHES_ENABLED')
  3062. and $ubillingConfig->getAlterParam('TASKMAN_BRANCHES_CONSIDER_ON'));
  3063. $datefrom = mysql_real_escape_string($datefrom);
  3064. $dateto = mysql_real_escape_string($dateto);
  3065. $allemployee = ts_GetAllEmployee();
  3066. $alljobtypes = ts_GetAllJobtypes();
  3067. $advFilter = '';
  3068. $appendQueryJOIN = '';
  3069. $result = wf_tag('style');
  3070. $result .= '
  3071. table.gridtable {
  3072. font-family: verdana,arial,sans-serif;
  3073. font-size:9pt;
  3074. color:#333333;
  3075. border-width: 1px;
  3076. border-color: #666666;
  3077. border-collapse: collapse;
  3078. }
  3079. table.gridtable th {
  3080. border-width: 1px;
  3081. padding: 3px;
  3082. border-style: solid;
  3083. border-color: #666666;
  3084. background-color: #dedede;
  3085. }
  3086. table.gridtable td {
  3087. border-width: 1px;
  3088. padding: 3px;
  3089. border-style: solid;
  3090. border-color: #666666;
  3091. background-color: #ffffff;
  3092. }
  3093. ';
  3094. $result .= wf_tag('style', true);
  3095. if ($advFiltersEnabled) {
  3096. $advFilter = ts_AdvFiltersQuery();
  3097. $appendQueryJOIN = ($branchConsider) ? " LEFT JOIN `branchesusers` USING(`login`)
  3098. LEFT JOIN `branches` ON `branchesusers`.`branchid` = `branches`.`id` " : "";
  3099. }
  3100. $displaytype = (isset($_POST['displaytype'])) ? $_POST['displaytype'] : 'all';
  3101. if ($displaytype == 'onlyme') {
  3102. $whoami = whoami();
  3103. $curempid = ts_GetEmployeeByLogin($whoami);
  3104. $appendQuery = " AND `employee`='" . $curempid . "'";
  3105. } else {
  3106. $appendQuery = '';
  3107. }
  3108. $query = "SELECT * FROM `taskman`
  3109. LEFT JOIN `jobtypes` ON `taskman`.`jobtype` = `jobtypes`.`id`
  3110. " . $appendQueryJOIN . "
  3111. WHERE `startdate` BETWEEN '" . $datefrom . " 00:00:00' AND '" . $dateto . " 23:59:59' AND `status`='0'"
  3112. . " " . $advFilter . " " . $appendQuery;
  3113. $alltasks = simple_queryall($query);
  3114. if (!empty($alltasks)) {
  3115. foreach ($alltasks as $io => $each) {
  3116. $rows = '';
  3117. $cells = wf_TableCell(__('ID'));
  3118. $cells .= wf_TableCell($each['id']);
  3119. $rows .= wf_TableRow($cells);
  3120. $cells = wf_TableCell(__('Target date'));
  3121. $cells .= wf_TableCell($each['startdate'] . ' ' . @$each['starttime']);
  3122. $rows .= wf_TableRow($cells);
  3123. $cells = wf_TableCell(__('Task address'));
  3124. $cells .= wf_TableCell($each['address']);
  3125. $rows .= wf_TableRow($cells);
  3126. $cells = wf_TableCell(__('Phone'));
  3127. $cells .= wf_TableCell($each['phone']);
  3128. $rows .= wf_TableRow($cells);
  3129. $cells = wf_TableCell(__('Job type'));
  3130. //$cells.= wf_TableCell(@$alljobtypes[$each['jobtype']]);
  3131. $cells .= wf_TableCell($each['jobname']);
  3132. $rows .= wf_TableRow($cells);
  3133. $cells = wf_TableCell(__('Who should do'));
  3134. $cells .= wf_TableCell(@$allemployee[$each['employee']]);
  3135. $rows .= wf_TableRow($cells);
  3136. $cells = wf_TableCell(__('Job note'));
  3137. $cells .= wf_TableCell($each['jobnote']);
  3138. $rows .= wf_TableRow($cells);
  3139. $tasktable = wf_TableBody($rows, '100%', '0', 'gridtable');
  3140. $result .= wf_tag('div', false, '', 'style="width: 300px; height: 250px; float: left; border: dashed; border-width:1px; margin:5px; page-break-inside: avoid;"');
  3141. $result .= $tasktable;
  3142. $result .= wf_tag('div', true);
  3143. }
  3144. $result .= wf_tag('script', false, '', 'language="javascript"');
  3145. $result .= 'window.print();';
  3146. $result .= wf_tag('script', true);
  3147. } else {
  3148. //$_POST['showemptyqueryerror'] = 'true';
  3149. $messages = new UbillingMessageHelper();
  3150. $result = '<link rel="stylesheet" href="./skins/ubng/css/ubilling.css" type="text/css">';
  3151. $result .= $messages->getStyledMessage(__('Query returned empty result'), 'warning');
  3152. }
  3153. die($result);
  3154. }
  3155. /**
  3156. * Renders printable tasks filtered by dates
  3157. *
  3158. * @param string $datefrom
  3159. * @param string $dateto
  3160. *
  3161. * @return void
  3162. */
  3163. function ts_PrintTasksTable($datefrom, $dateto, $nopagebreaks = false) {
  3164. global $ubillingConfig;
  3165. $advFiltersEnabled = $ubillingConfig->getAlterParam('TASKMAN_ADV_FILTERS');
  3166. $branchConsider = ($ubillingConfig->getAlterParam('BRANCHES_ENABLED')
  3167. and $ubillingConfig->getAlterParam('TASKMAN_BRANCHES_CONSIDER_ON'));
  3168. $datefrom = mysql_real_escape_string($datefrom);
  3169. $dateto = mysql_real_escape_string($dateto);
  3170. $allemployee = ts_GetAllEmployee();
  3171. $alljobtypes = ts_GetAllJobtypes();
  3172. $advFilter = '';
  3173. $appendQueryJOIN = '';
  3174. $tmpArr = array();
  3175. $pageBreakStyle = ($nopagebreaks) ? '' : 'page-break-after: always;';
  3176. $result = wf_tag('style');
  3177. $result .= '
  3178. table.gridtable {
  3179. font-family: verdana,arial,sans-serif;
  3180. font-size:9pt;
  3181. color:#333333;
  3182. border-width: 1px;
  3183. border-color: #666666;
  3184. border-collapse: collapse;
  3185. ' . $pageBreakStyle . '
  3186. }
  3187. .row1 {
  3188. background-color: #000000;
  3189. color: #FFFFFF;
  3190. font-weight: bolder;
  3191. font-size: larger;
  3192. }
  3193. table.gridtable td {
  3194. border-width: 1px;
  3195. padding: 3px;
  3196. border-style: solid;
  3197. border-color: #666666;
  3198. }
  3199. ';
  3200. $result .= wf_tag('style', true);
  3201. if ($advFiltersEnabled) {
  3202. $advFilter = ts_AdvFiltersQuery();
  3203. $appendQueryJOIN = ($branchConsider) ? " LEFT JOIN `branchesusers` USING(`login`)
  3204. LEFT JOIN `branches` ON `branchesusers`.`branchid` = `branches`.`id` " : "";
  3205. }
  3206. $displaytype = (isset($_POST['displaytype'])) ? $_POST['displaytype'] : 'all';
  3207. if ($displaytype == 'onlyme') {
  3208. $whoami = whoami();
  3209. $curempid = ts_GetEmployeeByLogin($whoami);
  3210. $appendQuery = " AND `employee`='" . $curempid . "'";
  3211. } else {
  3212. $appendQuery = '';
  3213. }
  3214. $orderFilter = 'address';
  3215. $customOrderFilter = $ubillingConfig->getAlterParam('TASKMAN_PRINT_ORDER');
  3216. if ($customOrderFilter) {
  3217. $orderFilter = mysql_real_escape_string($customOrderFilter);
  3218. }
  3219. $query = "SELECT * FROM `taskman`
  3220. LEFT JOIN `jobtypes` ON `taskman`.`jobtype` = `jobtypes`.`id`
  3221. " . $appendQueryJOIN . "
  3222. WHERE `startdate` BETWEEN '" . $datefrom . " 00:00:00' AND '" . $dateto . " 23:59:59' AND `status`='0'"
  3223. . $advFilter . " " . $appendQuery . " " . "ORDER BY `taskman`.`" . $orderFilter . "`";
  3224. $alltasks = simple_queryall($query);
  3225. if (!empty($alltasks)) {
  3226. foreach ($alltasks as $io => $each) {
  3227. $tmpArr[$each['employee']][] = $each;
  3228. }
  3229. if (!empty($tmpArr)) {
  3230. foreach ($tmpArr as $eachEmployeeId => $eachEmployeeTasks) {
  3231. if (!empty($eachEmployeeId)) {
  3232. $result .= wf_tag('h2') . @$allemployee[$eachEmployeeId] . wf_tag('h2', true);
  3233. if (!empty($eachEmployeeTasks)) {
  3234. $cells = wf_TableCell(__('Target date'));
  3235. $cells .= wf_TableCell(__('Task address'));
  3236. $cells .= wf_TableCell(__('Phone'));
  3237. $cells .= wf_TableCell(__('Job type'));
  3238. $cells .= wf_TableCell(__('Job note'));
  3239. $cells .= wf_TableCell(__('Additional comments'));
  3240. $rows = wf_TableRow($cells, 'row1');
  3241. foreach ($eachEmployeeTasks as $io => $each) {
  3242. $cells = wf_TableCell($each['startdate'] . ' ' . wf_tag('b') . @$each['starttime'] . wf_tag('b', true));
  3243. $cells .= wf_TableCell($each['address']);
  3244. $cells .= wf_TableCell($each['phone']);
  3245. //$cells.= wf_TableCell(@$alljobtypes[$each['jobtype']]);
  3246. $cells .= wf_TableCell($each['jobname']);
  3247. $cells .= wf_TableCell(nl2br($each['jobnote']));
  3248. $cells .= wf_TableCell('');
  3249. $rows .= wf_TableRow($cells, 'row3');
  3250. }
  3251. $result .= wf_TableBody($rows, '100%', 0, 'gridtable');
  3252. }
  3253. }
  3254. }
  3255. }
  3256. $result .= wf_tag('script', false, '', 'language="javascript"');
  3257. $result .= 'window.print();';
  3258. $result .= wf_tag('script', true);
  3259. } else {
  3260. //$_POST['showemptyqueryerror'] = 'true';
  3261. $messages = new UbillingMessageHelper();
  3262. $result = '<link rel="stylesheet" href="./skins/ubng/css/ubilling.css" type="text/css">';
  3263. $result .= $messages->getStyledMessage(__('Query returned empty result'), 'warning');
  3264. }
  3265. die($result);
  3266. }
  3267. /**
  3268. * Gets employee by administrator login
  3269. *
  3270. * @param string $login logged in administrators login
  3271. *
  3272. * @return mixed
  3273. */
  3274. function ts_GetEmployeeByLogin($login) {
  3275. $login = mysql_real_escape_string($login);
  3276. $query = "SELECT `id` from `employee` WHERE `admlogin`='" . $login . "'";
  3277. $raw = simple_query($query);
  3278. if (!empty($raw)) {
  3279. $result = $raw['id'];
  3280. } else {
  3281. $result = false;
  3282. }
  3283. return ($result);
  3284. }
  3285. /**
  3286. * Returns count of undone tasks - used by DarkVoid
  3287. *
  3288. * @return int
  3289. */
  3290. function ts_GetUndoneCountersAll() {
  3291. $result = 0;
  3292. $curdate = curdate();
  3293. $curyear = curyear();
  3294. $query = "SELECT `id` from `taskman` WHERE `status` = '0' AND `startdate` <= '" . $curdate . "' AND `date` LIKE '" . $curyear . "-%';";
  3295. $allundone = simple_queryall($query);
  3296. if (!empty($allundone)) {
  3297. $result = sizeof($allundone);
  3298. }
  3299. return ($result);
  3300. }
  3301. /**
  3302. * Returns array of all tasks address as taskId=>address
  3303. *
  3304. * @return array
  3305. */
  3306. function ts_GetAllTasksAddress() {
  3307. $result = array();
  3308. $all = simple_queryall("SELECT `id`,`address` from `taskman`");
  3309. if (!empty($all)) {
  3310. foreach ($all as $io => $each) {
  3311. $result[$each['id']] = $each['address'];
  3312. }
  3313. }
  3314. return ($result);
  3315. }
  3316. /**
  3317. * Returns array of undone tasks - used by Warehouse and another weird things as id=>taskdata
  3318. *
  3319. * @param bool $allTime get undone tasks not only before current date
  3320. *
  3321. * @return array
  3322. */
  3323. function ts_GetUndoneTasksArray($allTime = false) {
  3324. $result = array();
  3325. if (!$allTime) {
  3326. $curdate = curdate();
  3327. $dateFilters = "AND `startdate` <= '" . $curdate . "'";
  3328. } else {
  3329. $dateFilters = '';
  3330. }
  3331. $orders = "ORDER BY `address`,`jobtype` ASC";
  3332. $query = "SELECT * from `taskman` WHERE `status` = '0' " . $dateFilters . " " . $orders;
  3333. $all = simple_queryall($query);
  3334. if (!empty($all)) {
  3335. foreach ($all as $io => $each) {
  3336. $result[$each['id']] = $each;
  3337. }
  3338. }
  3339. return ($result);
  3340. }
  3341. /**
  3342. * Returns count of undone tasks only for current admin login - used by DarkVoid
  3343. *
  3344. * @return int
  3345. */
  3346. function ts_GetUndoneCountersMy() {
  3347. $result = 0;
  3348. $curdate = curdate();
  3349. $curyear = curyear();
  3350. $mylogin = whoami();
  3351. $adminQuery = "SELECT `id` from `employee` WHERE `admlogin`='" . $mylogin . "'";
  3352. $adminId = simple_query($adminQuery);
  3353. if (!empty($adminId)) {
  3354. $adminId = $adminId['id'];
  3355. $query = "SELECT `id` from `taskman` WHERE `employee`='" . $adminId . "' AND `status` = '0' AND `startdate` <= '" . $curdate . "' AND `date` LIKE '" . $curyear . "-%';";
  3356. $allundone = simple_queryall($query);
  3357. if (!empty($allundone)) {
  3358. $result = sizeof($allundone);
  3359. }
  3360. }
  3361. return ($result);
  3362. }
  3363. /**
  3364. * Returns all of available tasks as id=>data
  3365. *
  3366. * @param int $year
  3367. *
  3368. * @return array
  3369. */
  3370. function ts_GetAllTasks($year = '') {
  3371. $result = array();
  3372. $year = vf($year, 3);
  3373. $query = "SELECT * from `taskman`";
  3374. if (!empty($year)) {
  3375. $query .= " WHERE `startdate` LIKE '" . $year . "-%'";
  3376. }
  3377. $all = simple_queryall($query);
  3378. if (!empty($all)) {
  3379. foreach ($all as $io => $each) {
  3380. $result[$each['id']] = $each;
  3381. }
  3382. }
  3383. return ($result);
  3384. }
  3385. /**
  3386. * Returns all tasks short data as taskid=>data
  3387. *
  3388. * @return array
  3389. */
  3390. function ts_GetAllTasksQuickData() {
  3391. $result = array();
  3392. $query = "SELECT `id`,`address`,`startdate`,`employee` from `taskman`";
  3393. $all = simple_queryall($query);
  3394. if (!empty($all)) {
  3395. foreach ($all as $io => $each) {
  3396. $result[$each['id']]['address'] = $each['address'];
  3397. $result[$each['id']]['startdate'] = $each['startdate'];
  3398. $result[$each['id']]['employee'] = $each['employee'];
  3399. }
  3400. }
  3401. return ($result);
  3402. }
  3403. function ts_AdvFiltersControls() {
  3404. global $ubillingConfig;
  3405. $branchConsider = ($ubillingConfig->getAlterParam('BRANCHES_ENABLED')
  3406. and $ubillingConfig->getAlterParam('TASKMAN_BRANCHES_CONSIDER_ON'));
  3407. $branchAdvFltON = $ubillingConfig->getAlterParam('TASKMAN_ADV_FILTERS_BRANCHES_ON');
  3408. $alljobtypes = ts_GetAllJobtypes();
  3409. $alljobtypes = array('0' => __('Any')) + $alljobtypes;
  3410. $selectedjobtype = (ubRouting::checkPost('filtertaskjobtypeexact') ? ubRouting::post('filtertaskjobtypeexact') : '');
  3411. $jobtypecontains = (ubRouting::checkPost('filtertaskjobtype') ? ubRouting::post('filtertaskjobtype') : '');
  3412. $addresscontains = (ubRouting::checkPost('filtertaskaddr') ? ubRouting::post('filtertaskaddr') : '');
  3413. $jobnotecontains = (ubRouting::checkPost('filtertaskjobnote') ? ubRouting::post('filtertaskjobnote') : '');
  3414. $phonecontains = (ubRouting::checkPost('filtertaskphone') ? ubRouting::post('filtertaskphone') : '');
  3415. $branchcontains = (ubRouting::checkPost('filtertaskbranch') ? ubRouting::post('filtertaskbranch') : '');
  3416. $inputs = '';
  3417. $inputs .= wf_tag('h3');
  3418. $inputs .= __('Job type');
  3419. $inputs .= wf_tag('h3', true);
  3420. $inputs .= wf_Selector('filtertaskjobtypeexact', $alljobtypes, '', $selectedjobtype);
  3421. $inputs .= wf_tag('h3');
  3422. $inputs .= __('Job type contains');
  3423. $inputs .= wf_tag('h3', true);
  3424. $inputs .= wf_TextInput('filtertaskjobtype', '', $jobtypecontains);
  3425. if ($branchConsider and $branchAdvFltON) {
  3426. $inputs .= wf_tag('h3');
  3427. $inputs .= __('Branch contains');
  3428. $inputs .= wf_tag('h3', true);
  3429. $inputs .= wf_TextInput('filtertaskbranch', '', $branchcontains);
  3430. }
  3431. $inputs .= wf_tag('h3');
  3432. $inputs .= __('Address contains');
  3433. $inputs .= wf_tag('h3', true);
  3434. $inputs .= wf_TextInput('filtertaskaddr', '', $addresscontains);
  3435. $inputs .= wf_tag('h3');
  3436. $inputs .= __('Job note contains');
  3437. $inputs .= wf_tag('h3', true);
  3438. $inputs .= wf_TextInput('filtertaskjobnote', '', $jobnotecontains);
  3439. $inputs .= wf_tag('h3');
  3440. $inputs .= __('Job phone contains');
  3441. $inputs .= wf_tag('h3', true);
  3442. $inputs .= wf_TextInput('filtertaskphone', '', $phonecontains);
  3443. return ($inputs);
  3444. }
  3445. function ts_AdvFiltersQuery() {
  3446. global $ubillingConfig;
  3447. $branchConsider = ($ubillingConfig->getAlterParam('BRANCHES_ENABLED')
  3448. and $ubillingConfig->getAlterParam('TASKMAN_BRANCHES_CONSIDER_ON'));
  3449. $branchAdvFltON = $ubillingConfig->getAlterParam('TASKMAN_ADV_FILTERS_BRANCHES_ON');
  3450. $appendQuery = '';
  3451. if (ubRouting::checkPost('filtertaskjobtypeexact')) {
  3452. $appendQuery .= " AND `jobtype` = " . ubRouting::post('filtertaskjobtypeexact');
  3453. } elseif (ubRouting::checkPost('filtertaskjobtype')) {
  3454. $appendQuery .= " AND `jobname` LIKE '%" . ubRouting::post('filtertaskjobtype') . "%'";
  3455. }
  3456. if (ubRouting::checkPost('filtertaskaddr')) {
  3457. $appendQuery .= " AND `address` LIKE '%" . ubRouting::post('filtertaskaddr') . "%'";
  3458. }
  3459. if (ubRouting::checkPost('filtertaskjobnote')) {
  3460. $appendQuery .= " AND `jobnote` LIKE '%" . ubRouting::post('filtertaskjobnote') . "%'";
  3461. }
  3462. if (ubRouting::checkPost('filtertaskphone')) {
  3463. $appendQuery .= " AND `phone` LIKE '%" . ubRouting::post('filtertaskphone') . "%'";
  3464. }
  3465. if ($branchConsider and $branchAdvFltON and ubRouting::checkPost('filtertaskbranch')) {
  3466. $appendQuery .= " AND `branches`.`name` LIKE '%" . ubRouting::post('filtertaskbranch') . "%'";
  3467. }
  3468. return ($appendQuery);
  3469. }
  3470. /**
  3471. * Returns all tasks array filtered by some date
  3472. *
  3473. * @param string $date
  3474. *
  3475. * @return array
  3476. */
  3477. function ts_getAllTasksByDate($date) {
  3478. $date = ubRouting::filters($date, 'mres');
  3479. $query = "SELECT * from `taskman` WHERE `startdate` LIKE '" . $date . "%'";
  3480. $result = simple_queryall($query);
  3481. return ($result);
  3482. }