����JFIFXX�����    $.' ",#(7),01444'9=82<.342  2!!22222222222222222222222222222222222222222222222222����"��4�� ���,�PG"Z_�4�˷����kjز�Z�,F+��_z�,�© �����zh6�٨�ic�fu���#ډb���_�N�?��wQ���5-�~�I���8����TK<5o�Iv-�����k�_U_�����~b�M��d����Ӝ�U�Hh��?]��E�w��Q���k�{��_}qFW7HTՑ��Y��F�?_�'ϔ��_�Ջt��=||I ��6�έ"�����D���/[�k�9���Y�8ds|\���Ҿp6�Ҵ���]��.����6�z<�v��@]�i%��$j��~�g��J>��no����pM[me�i$[����s�o�ᘨ�˸ nɜG-�ĨU�ycP�3.DB�li�;��hj���x7Z^�N�h������N3u{�:j�x�힞��#M&��jL P@_���� P��&��o8������9�����@Sz6�t7#O�ߋ �s}Yf�T���lmr����Z)'N��k�۞p����w\�Tȯ?�8`�O��i{wﭹW�[�r�� ��Q4F�׊���3m&L�=��h3����z~��#�\�l :�F,j@�� ʱ�wQT����8�"kJO���6�֚l����}���R�>ډK���]��y����&����p�}b��;N�1�m�r$�|��7�>e�@B�TM*-iH��g�D�)� E�m�|�ؘbҗ�a��Ҿ����t4���o���G��*oCN�rP���Q��@z,|?W[0�����:�n,jWiE��W��$~/�hp\��?��{(�0���+�Y8rΟ�+����>S-S����VN;�}�s?.����� w�9��˟<���Mq4�Wv'��{)0�1mB��V����W[�����8�/<� �%���wT^�5���b��)iM� pg�N�&ݝ��VO~�q���u���9� ����!��J27����$O-���! �:�%H��� ـ����y�ΠM=t{!S�� oK8������t<����è:a������[�����ա�H���~��w��Qz`�po�^ ����Q��n� �,uu�C�$ ^���,������8�#��:�6��e�|~���!�3�3.�\0��q��o�4`.|� ����y�Q�`~;�d�ׯ,��O�Zw�������`73�v�܋�<���Ȏ�� ـ4k��5�K�a�u�=9Yd��$>x�A�&�� j0� ���vF��� Y�|�y��� ~�6�@c��1vOp�Ig����4��l�OD���L����� R���c���j�_�uX6��3?nk��Wy�f;^*B� ��@�~a�`��Eu������+���6�L��.ü>��}y���}_�O�6�͐�:�YrG�X��kG�����l^w���~㒶sy��Iu�!� W ��X��N�7BV��O��!X�2����wvG�R�f�T#�����t�/?���%8�^�W�aT��G�cL�M���I��(J����1~�8�?aT ���]����AS�E��(��*E}� 2��#I/�׍qz��^t�̔���b�Yz4x���t�){ OH��+(E��A&�N�������XT��o��"�XC��'���)}�J�z�p� ��~5�}�^����+�6����w��c��Q�|Lp�d�H��}�(�.|����k��c4^�"�����Z?ȕ ��a<�L�!039C� �Eu�C�F�Ew�ç ;�n?�*o���B�8�bʝ���'#Rqf���M}7����]����s2tcS{�\icTx;�\��7K���P���ʇ Z O-��~��c>"��?�������P��E��O�8��@�8��G��Q�g�a�Վ���󁶠�䧘��_%#r�>�1�z�a��eb��qcPѵ��n���#L��� =��׀t� L�7�`��V���A{�C:�g���e@�w1 Xp3�c3�ġ����p��M"'-�@n4���fG��B3�DJ�8[Jo�ߐ���gK)ƛ��$���� ���8�3�����+���� �����6�ʻ���� ���S�kI�*KZlT _`���?��K����QK�d����B`�s}�>���`��*�>��,*@J�d�oF*����弝��O}�k��s��]��y�ߘ��c1G�V���<=�7��7����6�q�PT��tXԀ�!9*4�4Tހ3XΛex�46���Y��D ����� �BdemDa����\�_l,��G�/���֌7���Y�](�xTt^%�GE�����4�}bT���ڹ�����;Y)���B�Q��u��>J/J �⮶.�XԄ��j�ݳ�+E��d ��r�5�_D�1 ��o�� �B�x�΢�#���<��W�����8���R6�@g�M�.��� dr�D��>(otU��@x=��~v���2� ӣ�d�oBd��3�eO�6�㣷�����ݜ6��6Y��Qz`��S��{���\P�~z m5{J/L��1������<�e�ͅPu�b�]�ϔ���'������f�b� Zpw��c`"��i���BD@:)ִ�:�]��hv�E�w���T�l��P���"Ju�}��وV J��G6��. J/�Qgl߭�e�����@�z�Zev2u�)]կ�����7x���s�M�-<ɯ�c��r�v�����@��$�ޮ}lk���a���'����>x��O\�ZFu>�����ck#��&:��`�$�ai�>2Δ����l���oF[h��lE�ܺ�Πk:)���`�� $[6�����9�����kOw�\|���8}������ބ:��񶐕��I�A1/�=�2[�,�!��.}gN#�u����b��� ~��݊��}34q����d�E��Lc��$��"�[q�U�硬g^��%B �z���r�pJ�ru%v\h1Y�ne`ǥ:g���pQM~�^�Xi� ��`S�:V29.�P���V�?B�k�� AEvw%�_�9C�Q����wKekPؠ�\�;Io d�{ ߞo�c1eP����\� `����E=���@K<�Y���eڼ�J���w����{av�F�'�M�@/J��+9p���|]�����Iw &`��8���&M�hg��[�{��Xj��%��Ӓ�$��(����ʹN���<>�I���RY���K2�NPlL�ɀ)��&e����B+ь����( � �JTx���_?EZ� }@ 6�U���뙢ط�z��dWI�n` D����噥�[��uV��"�G&Ú����2g�}&m��?ċ�"����Om#��������� ��{�ON��"S�X��Ne��ysQ���@Fn��Vg���dX�~nj�]J�<�K]:��FW��b�������62�=��5f����JKw��bf�X�55��~J �%^����:�-�QIE��P��v�nZum� z � ~ə ���� ���ة����;�f��\v���g�8�1��f24;�V���ǔ�)����9���1\��c��v�/'Ƞ�w�������$�4�R-��t���� e�6�/�ġ �̕Ecy�J���u�B���<�W�ַ~�w[B1L۲�-JS΂�{���΃������A��20�c#��@ 0!1@AP"#2Q`$3V�%45a6�FRUq��� ����^7ׅ,$n�������+��F�`��2X'��0vM��p�L=������5��8������u�p~���.�`r�����\���O��,ư�0oS ��_�M�����l���4�kv\JSd���x���SW�<��Ae�IX����������$I���w�:S���y���›R��9�Q[���,�5�;�@]�%���u�@ *ro�lbI �� ��+���%m:�͇ZV�����u�̉����θau<�fc�.����{�4Ա� �Q����*�Sm��8\ujqs]{kN���)qO�y�_*dJ�b�7���yQqI&9�ԌK!�M}�R�;������S�T���1���i[U�ɵz�]��U)V�S6���3$K{�ߊ<�(� E]Զ[ǼENg�����'�\?#)Dkf��J���o��v���'�%ƞ�&K�u�!��b�35LX�Ϸ��63$K�a�;�9>,R��W��3�3� d�JeTYE.Mϧ��-�o�j3+y��y^�c�������VO�9NV\nd�1 ��!͕_)a�v;����թ�M�lWR1��)El��P;��yوÏ�u 3�k�5Pr6<�⒲l�!˞*��u־�n�!�l:����UNW ��%��Chx8vL'��X�@��*��)���̮��ˍ��� ���D-M�+J�U�kvK����+�x8��cY������?�Ԡ��~3mo��|�u@[XeY�C�\Kp�x8�oC�C�&����N�~3-H���� ��MX�s�u<`���~"WL��$8ξ��3���a�)|:@�m�\���^�`�@ҷ)�5p+��6���p�%i)P M���ngc�����#0Aruz���RL+xSS?���ʮ}()#�t��mˇ!��0}}y����<�e� �-ή�Ԩ��X������ MF���ԙ~l L.3���}�V뽺�v�����멬��Nl�)�2����^�Iq��a��M��qG��T�����c3#������3U�Ǎ���}��לS�|qa��ڃ�+���-��2�f����/��bz��ڐ�� �ݼ[2�ç����k�X�2�* �Z�d���J�G����M*9W���s{��w���T��x��y,�in�O�v��]���n����P�$�JB@=4�OTI�n��e�22a\����q�d���%�$��(���:���: /*�K[PR�fr\nڙdN���F�n�$�4�[�� U�zƶ����� �mʋ���,�ao�u 3�z� �x��Kn����\[��VFmbE;�_U��&V�Gg�]L�۪&#n%�$ɯ�dG���D�TI=�%+AB�Ru#��b4�1�»x�cs�YzڙJG��f��Il��d�eF'T� iA��T���uC�$����Y��H?����[!G`}���ͪ� �纤Hv\������j�Ex�K���!���OiƸ�Yj�+u-<���'q����uN�*�r\��+�]���<�wOZ.fp�ێ��,-*)V?j-kÊ#�`�r��dV����(�ݽBk�����G�ƛk�QmUڗe��Z���f}|����8�8��a���i��3'J�����~G_�^���d�8w������ R�`(�~�.��u���l�s+g�bv���W���lGc}��u���afE~1�Ue������Z�0�8�=e�� f@/�jqEKQQ�J��oN��J���W5~M>$6�Lt�;$ʳ{���^��6�{����v6���ķܰg�V�cnn �~z�x�«�,2�u�?cE+Ș�H؎�%�Za�)���X>uW�Tz�Nyo����s���FQƤ��$��*�&�LLXL)�1�" L��eO��ɟ�9=���:t��Z���c��Ž���Y?�ӭV�wv�~,Y��r�ۗ�|�y��GaF�����C�����.�+� ���v1���fήJ�����]�S��T��B��n5sW}y�$��~z�'�c ��8 ��� ,! �p��VN�S��N�N�q��y8z˱�A��4��*��'������2n<�s���^ǧ˭P�Jޮɏ�U�G�L�J�*#��<�V��t7�8����TĜ>��i}K%,���)[��z�21z ?�N�i�n1?T�I�R#��m-�����������������1����lA�`��fT5+��ܐ�c�q՝��ʐ��,���3�f2U�եmab��#ŠdQ�y>\��)�SLY����w#��.���ʑ�f��� ,"+�w�~�N�'�c�O�3F�������N<���)j��&��,-� �љ���֊�_�zS���TǦ����w�>��?�������n��U仆�V���e�����0���$�C�d���rP �m�׈e�Xm�Vu� �L��.�bֹ��� �[Դaզ���*��\y�8�Է:�Ez\�0�Kq�C b��̘��cө���Q��=0Y��s�N��S.���3.���O�o:���#���v7�[#߫ ��5�܎�L���Er4���9n��COWlG�^��0k�%<���ZB���aB_���������'=��{i�v�l�$�uC���mƎҝ{�c㱼�y]���W�i ��ߧc��m�H� m�"�"�����;Y�ߝ�Z�Ǔ�����:S#��|}�y�,/k�Ld� TA�(�AI$+I3��;Y*���Z��}|��ӧO��d�v��..#:n��f>�>���ȶI�TX��� 8��y����"d�R�|�)0���=���n4��6ⲑ�+��r<�O�܂~zh�z����7ܓ�HH�Ga롏���nCo�>������a ���~]���R���̲c?�6(�q�;5%� |�uj�~z8R=X��I�V=�|{v�Gj\gc��q����z�؋%M�ߍ����1y��#��@f^���^�>N�����#x#۹��6�Y~�?�dfPO��{��P�4��V��u1E1J �*|���%���JN��`eWu�zk M6���q t[�� ��g�G���v��WIG��u_ft����5�j�"�Y�:T��ɐ���*�;� e5���4����q$C��2d�}���� _S�L#m�Yp��O�.�C�;��c����Hi#֩%+) �Ӎ��ƲV���SYź��g |���tj��3�8���r|���V��1#;.SQ�A[���S������#���`n�+���$��$I �P\[�@�s��(�ED�z���P��])8�G#��0B��[ى��X�II�q<��9�~[Z멜�Z�⊔IWU&A>�P~�#��dp<�?����7���c��'~���5 ��+$���lx@�M�dm��n<=e�dyX��?{�|Aef ,|n3�<~z�ƃ�uۧ�����P��Y,�ӥQ�*g�#먙R�\���;T��i,��[9Qi歉����c>]9�� ��"�c��P�� �Md?٥��If�ت�u��k��/����F��9�c*9��Ǎ:�ØF���z�n*�@|I�ށ9����N3{'��[�'ͬ�Ҳ4��#}��!�V� Fu��,�,mTIk���v C�7v���B�6k�T9��1�*l� '~��ƞF��lU��'�M ����][ΩũJ_�{�i�I�n��$���L�� j��O�dx�����kza۪��#�E��Cl����x˘�o�����V���ɞ�ljr��)�/,�߬h�L��#��^��L�ф�,íMƁe�̩�NB�L�����iL����q�}��(��q��6IçJ$�W�E$��:������=#����(�K�B����zђ <��K(�N�۫K�w��^O{!����)�H���>x�������lx�?>Պ�+�>�W���,Ly!_�D���Ō�l���Q�!�[ �S����J��1��Ɛ�Y}��b,+�Lo�x�ɓ)����=�y�oh�@�꥟/��I��ѭ=��P�y9��� �ۍYӘ�e+�p�Jnϱ?V\SO%�(�t� ���=?MR�[Ș�����d�/ ��n�l��B�7j� ��!�;ӥ�/�[-���A�>�dN�sLj ��,ɪv��=1c�.SQ�O3�U���ƀ�ܽ�E����������̻��9G�ϷD�7(�}��Ävӌ\�y�_0[w ���<΍>����a_��[0+�L��F.�޺��f�>oN�T����q;���y\��bՃ��y�jH�<|q-eɏ�_?_9+P���Hp$�����[ux�K w�Mw��N�ی'$Y2�=��q���KB��P��~������Yul:�[<����F1�2�O���5=d����]Y�sw:���Ϯ���E��j,_Q��X��z`H1,#II ��d�wr��P˂@�ZJV����y$�\y�{}��^~���[:N����ߌ�U�������O��d�����ؾe��${p>G��3c���Ė�lʌ�� ת��[��`ϱ�-W����dg�I��ig2��� ��}s ��ؤ(%#sS@���~���3�X�nRG�~\jc3�v��ӍL��M[JB�T��s3}��j�Nʖ��W����;7��ç?=X�F=-�=����q�ߚ���#���='�c��7���ڑW�I(O+=:uxq�������������e2�zi+�kuG�R��������0�&e�n���iT^J����~\jy���p'dtG��s����O��3����9* �b#Ɋ�� p������[Bws�T�>d4�ۧs���nv�n���U���_�~,�v����ƜJ1��s�� �QIz��)�(lv8M���U=�;����56��G���s#�K���MP�=��LvyGd��}�VwWBF�'�à �?MH�U�g2�� ����!�p�7Q��j��ڴ����=��j�u��� Jn�A s���uM������e��Ɔ�Ҕ�!)'��8Ϣ�ٔ��ޝ(��Vp���צ֖d=�IC�J�Ǡ{q������kԭ�߸���i��@K����u�|�p=..�*+����x�����z[Aqġ#s2a�Ɗ���RR�)*HRsi�~�a &f��M��P����-K�L@��Z��Xy�'x�{}��Zm+���:�)�) IJ�-i�u���� ���ܒH��'�L(7�y�GӜq���� j��� 6ߌg1�g�o���,kر���tY�?W,���p���e���f�OQS��!K�۟cҒA�|ս�j�>��=⬒��˧L[�� �߿2JaB~R��u�:��Q�] �0H~���]�7��Ƽ�I���(}��cq '�ήET���q�?f�ab���ӥvr� �)o��-Q��_'����ᴎo��K������;��V���o��%���~OK ����*��b�f:���-ťIR��`B�5!RB@���ï�� �u �̯e\�_U�_������� g�ES��3�������QT��a����x����U<~�c?�*�#]�MW,[8O�a�x��]�1bC|踤�P��lw5V%�)�{t�<��d��5���0i�XSU��m:��Z�┵�i�"��1�^B�-��P�hJ��&)O��*�D��c�W��vM��)����}���P��ܗ-q����\mmζZ-l@�}��a��E�6��F�@��&Sg@���ݚ�M����� ȹ 4����#p�\H����dYDo�H���"��\��..R�B�H�z_�/5˘����6��KhJR��P�mƶi�m���3�,#c�co��q�a)*Pt����R�m�k�7x�D�E�\Y�閣_X�<���~�)���c[[�BP����6�Yq���S��0����%_����;��Àv�~�| VS؇ ��'O0��F0��\���U�-�d@�����7�SJ*z��3n��y��P����O���������m�~�P�3|Y��ʉr#�C�<�G~�.,! ���bqx���h~0=��!ǫ�jy����l�O,�[B��~��|9��ٱ����Xly�#�i�B��g%�S��������tˋ���e���ې��\[d�t)��.+u�|1 ������#�~Oj����hS�%��i.�~X���I�H�m��0n���c�1uE�q��cF�RF�o���7� �O�ꮧ� ���ۛ{��ʛi5�rw?׌#Qn�TW��~?y$��m\�\o����%W� ?=>S�N@�� �Ʈ���R����N�)�r"C�:��:����� �����#��qb��Y�. �6[��2K����2u�Ǧ�HYR��Q�MV��� �G�$��Q+.>�����nNH��q�^��� ����q��mM��V��D�+�-�#*�U�̒ ���p욳��u:�������IB���m���PV@O���r[b= �� ��1U�E��_Nm�yKbN�O���U�}�the�`�|6֮P>�\2�P�V���I�D�i�P�O;�9�r�mAHG�W�S]��J*�_�G��+kP�2����Ka�Z���H�'K�x�W�MZ%�O�YD�Rc+o��?�q��Ghm��d�S�oh�\�D�|:W������UA�Qc yT�q������~^�H��/��#p�CZ���T�I�1�ӏT����4��"�ČZ�����}��`w�#�*,ʹ�� ��0�i��課�Om�*�da��^gJ݅{���l�e9uF#T�ֲ��̲�ٞC"�q���ߍ ոޑ�o#�XZTp����@ o�8��(jd��xw�]�,f���`~�|,s��^����f�1���t��|��m�򸄭/ctr��5s��7�9Q�4�H1꠲BB@l9@���C�����+�wp�xu�£Yc�9��?`@#�o�mH�s2��)�=��2�.�l����jg�9$�Y�S�%*L������R�Y������7Z���,*=�䷘$�������arm�o�ϰ���UW.|�r�uf����IGw�t����Zwo��~5 ��YյhO+=8fF�)�W�7�L9lM�̘·Y���֘YLf�큹�pRF���99.A �"wz��=E\Z���'a� 2��Ǚ�#;�'}�G���*��l��^"q��+2FQ� hj��kŦ��${���ޮ-�T�٭cf�|�3#~�RJ����t��$b�(R��(����r���dx� >U b�&9,>���%E\� Ά�e�$��'�q't��*�א���ެ�b��-|d���SB�O�O��$�R+�H�)�܎�K��1m`;�J�2�Y~9��O�g8=vqD`K[�F)k�[���1m޼c��n���]s�k�z$@��)!I �x՝"v��9=�ZA=`Ɠi �:�E��)`7��vI��}d�YI�_ �o�:ob���o ���3Q��&D&�2=�� �Ά��;>�h����y.*ⅥS������Ӭ�+q&����j|UƧ����}���J0��WW< ۋS�)jQR�j���Ư��rN)�Gű�4Ѷ(�S)Ǣ�8��i��W52���No˓� ۍ%�5brOn�L�;�n��\G����=�^U�dI���8$�&���h��'���+�(������cȁ߫k�l��S^���cƗjԌE�ꭔ��gF���Ȓ��@���}O���*;e�v�WV���YJ\�]X'5��ղ�k�F��b 6R�o՜m��i N�i����>J����?��lPm�U��}>_Z&�KK��q�r��I�D�Չ~�q�3fL�:S�e>���E���-G���{L�6p�e,8��������QI��h��a�Xa��U�A'���ʂ���s�+טIjP�-��y�8ۈZ?J$��W�P� ��R�s�]��|�l(�ԓ��sƊi��o(��S0��Y� 8�T97.�����WiL��c�~�dxc�E|�2!�X�K�Ƙਫ਼�$((�6�~|d9u+�qd�^3�89��Y�6L�.I�����?���iI�q���9�)O/뚅����O���X��X�V��ZF[�یgQ�L��K1���RҖr@v�#��X�l��F���Нy�S�8�7�kF!A��sM���^rkp�jP�DyS$N���q��nxҍ!U�f�!eh�i�2�m���`�Y�I�9r�6� �TF���C}/�y�^���Η���5d�'��9A-��J��>{�_l+�`��A���[�'��յ�ϛ#w:݅�%��X�}�&�PSt�Q�"�-��\縵�/����$Ɨh�Xb�*�y��BS����;W�ջ_mc�����vt?2}1�;qS�d�d~u:2k5�2�R�~�z+|HE!)�Ǟl��7`��0�<�,�2*���Hl-��x�^����'_TV�gZA�'j� ^�2Ϊ��N7t�����?w�� �x1��f��Iz�C-Ȗ��K�^q�;���-W�DvT�7��8�Z�������� hK�(P:��Q- �8�n�Z���܃e貾�<�1�YT<�,�����"�6{/ �?�͟��|1�:�#g��W�>$����d��J��d�B��=��jf[��%rE^��il:��B���x���Sּ�1հ��,�=��*�7 fcG��#q� �eh?��2�7�����,�!7x��6�n�LC�4x��},Geǝ�tC.��vS �F�43��zz\��;QYC,6����~;RYS/6���|2���5���v��T��i����������mlv��������&� �nRh^ejR�LG�f���? �ۉҬܦƩ��|��Ȱ����>3����!v��i�ʯ�>�v��オ�X3e���_1z�Kȗ\<������!�8���V��]��?b�k41�Re��T�q��mz��TiOʦ�Z��Xq���L������q"+���2ۨ��8}�&N7XU7Ap�d�X��~�׿��&4e�o�F��� �H����O���č�c�� 懴�6���͉��+)��v;j��ݷ�� �UV�� i��� j���Y9GdÒJ1��詞�����V?h��l����l�cGs�ځ�������y�Ac�����\V3�? �� ܙg�>qH�S,�E�W�[�㺨�uch�⍸�O�}���a��>�q�6�n6����N6�q������N ! 1AQaq�0@����"2BRb�#Pr���3C`��Scst���$4D���%Td�� ?���N����a��3��m���C���w��������xA�m�q�m���m������$����4n淿t'��C"w��zU=D�\R+w�p+Y�T�&�պ@��ƃ��3ޯ?�Aﶂ��aŘ���@-�����Q�=���9D��ռ�ѻ@��M�V��P��܅�G5�f�Y<�u=,EC)�<�Fy'�"�&�չ�X~f��l�KԆV��?�� �W�N����=(� �;���{�r����ٌ�Y���h{�١������jW����P���Tc�����X�K�r��}���w�R��%��?���E��m�� �Y�q|����\lEE4���r���}�lsI�Y������f�$�=�d�yO����p�����yBj8jU�o�/�S��?�U��*������ˍ�0������u�q�m [�?f����a�� )Q�>����6#������� ?����0UQ����,IX���(6ڵ[�DI�MNލ�c&���υ�j\��X�R|,4��� j������T�hA�e��^���d���b<����n�� �즇�=!���3�^�`j�h�ȓr��jẕ�c�,ٞX����-����a�ﶔ���#�$��]w�O��Ӫ�1y%��L�Y<�wg#�ǝ�̗`�x�xa�t�w��»1���o7o5��>�m뭛C���Uƃߜ}�C���y1Xνm�F8�jI���]����H���ۺиE@I�i;r�8ӭ����V�F�Շ| ��&?�3|x�B�MuS�Ge�=Ӕ�#BE5G�����Y!z��_e��q�р/W>|-�Ci߇�t�1ޯќd�R3�u��g�=0 5��[?�#͏��q�cf���H��{ ?u�=?�?ǯ���}Z��z���hmΔ�BFTW�����<�q�(v� ��!��z���iW]*�J�V�z��gX֧A�q�&��/w���u�gYӘa���; �i=����g:��?2�dž6�ى�k�4�>�Pxs����}������G�9��3 ���)gG�R<>r h�$��'nc�h�P��Bj��J�ҧH� -��N1���N��?��~��}-q!=��_2hc�M��l�vY%UE�@|�v����M2�.Y[|y�"Eï��K�ZF,�ɯ?,q�?v�M 80jx�"�;�9vk�����+ ֧�� �ȺU��?�%�vcV��mA�6��Qg^M����A}�3�nl� QRN�l8�kkn�'�����(��M�7m9و�q���%ޟ���*h$Zk"��$�9��: �?U8�Sl��,,|ɒ��xH(ѷ����Gn�/Q�4�P��G�%��Ա8�N��!� �&�7�;���eKM7�4��9R/%����l�c>�x;������>��C�:�����t��h?aKX�bhe�ᜋ^�$�Iհ �hr7%F$�E��Fd���t��5���+�(M6�t����Ü�UU|zW�=a�Ts�Tg������dqP�Q����b'�m���1{|Y����X�N��b �P~��F^F:����k6�"�j!�� �I�r�`��1&�-$�Bevk:y���#yw��I0��x��=D�4��tU���P�ZH��ڠ底taP��6����b>�xa����Q�#� WeF��ŮNj�p�J* mQ�N����*I�-*�ȩ�F�g�3 �5��V�ʊ�ɮ�a��5F���O@{���NX��?����H�]3��1�Ri_u��������ѕ�� ����0��� F��~��:60�p�͈�S��qX#a�5>���`�o&+�<2�D����: �������ڝ�$�nP���*)�N�|y�Ej�F�5ټ�e���ihy�Z �>���k�bH�a�v��h�-#���!�Po=@k̆IEN��@��}Ll?j�O������߭�ʞ���Q|A07x���wt!xf���I2?Z��<ץ�T���cU�j��]��陎Ltl �}5�ϓ��$�,��O�mˊ�;�@O��jE��j(�ا,��LX���LO���Ц�90�O �.����a��nA���7������j4 ��W��_ٓ���zW�jcB������y՗+EM�)d���N�g6�y1_x��p�$Lv:��9�"z��p���ʙ$��^��JԼ*�ϭ����o���=x�Lj�6�J��u82�A�H�3$�ٕ@�=Vv�]�'�qEz�;I˼��)��=��ɯ���x �/�W(V���p�����$ �m�������u�����񶤑Oqˎ�T����r��㠚x�sr�GC��byp�G��1ߠ�w e�8�$⿄����/�M{*}��W�]˷.�CK\�ުx���/$�WPw���r� |i���&�}�{�X� �>��$-��l���?-z���g����lΆ���(F���h�vS*���b���߲ڡn,|)mrH[���a�3�ר�[1��3o_�U�3�TC�$��(�=�)0�kgP���� ��u�^=��4 �WYCҸ:��vQ�ר�X�à��tk�m,�t*��^�,�}D*� �"(�I��9R����>`�`��[~Q]�#af��i6l��8���6�:,s�s�N6�j"�A4���IuQ��6E,�GnH��zS�HO�uk�5$�I�4��ؤ�Q9�@��C����wp�BGv[]�u�Ov���0I4���\��y�����Q�Ѹ��~>Z��8�T��a��q�ޣ;z��a���/��S��I:�ܫ_�|������>=Z����8:�S��U�I�J��"IY���8%b8���H��:�QO�6�;7�I�S��J��ҌAά3��>c���E+&jf$eC+�z�;��V����� �r���ʺ������my�e���aQ�f&��6�ND��.:��NT�vm�<- u���ǝ\MvZY�N�NT��-A�>jr!S��n�O 1�3�Ns�%�3D@���`������ܟ 1�^c<���� �a�ɽ�̲�Xë#�w�|y�cW�=�9I*H8�p�^(4���՗�k��arOcW�tO�\�ƍR��8����'�K���I�Q�����?5�>[�}��yU�ײ -h��=��% q�ThG�2�)���"ו3]�!kB��*p�FDl�A���,�eEi�H�f�Ps�����5�H:�Փ~�H�0Dت�D�I����h�F3�������c��2���E��9�H��5�zԑ�ʚ�i�X�=:m�xg�hd(�v����׊�9iS��O��d@0ڽ���:�p�5�h-��t�&���X�q�ӕ,��ie�|���7A�2���O%P��E��htj��Y1��w�Ѓ!����  ���� ࢽ��My�7�\�a�@�ţ�J �4�Ȼ�F�@o�̒?4�wx��)��]�P��~�����u�����5�����7X ��9��^ܩ�U;Iꭆ 5 �������eK2�7(�{|��Y׎ �V��\"���Z�1� Z�����}��(�Ǝ"�1S���_�vE30>���p;� ΝD��%x�W�?W?v����o�^V�i�d��r[��/&>�~`�9Wh��y�;���R��� ;;ɮT��?����r$�g1�K����A��C��c��K��l:�'��3 c�ﳯ*"t8�~l��)���m��+U,z��`(�>yJ�?����h>��]��v��ЍG*�{`��;y]��I�T� ;c��NU�fo¾h���/$���|NS���1�S�"�H��V���T���4��uhǜ�]�v;���5�͠x��'C\�SBpl���h}�N����� A�Bx���%��ޭ�l��/����T��w�ʽ]D�=����K���ž�r㻠l4�S�O?=�k �M:� ��c�C�a�#ha���)�ѐxc�s���gP�iG��{+���x���Q���I= �� z��ԫ+ �8"�k�ñ�j=|����c ��y��CF��/��*9ж�h{ �?4�o� ��k�m�Q�N�x��;�Y��4膚�a�w?�6�>e]�����Q�r�:����g�,i"�����ԩA�*M�<�G��b�if��l^M��5� �Ҩ�{����6J��ZJ�����P�*�����Y���ݛu�_4�9�I8�7���������,^ToR���m4�H��?�N�S�ѕw��/S��甍�@�9H�S�T��t�ƻ���ʒU��*{Xs�@����f�����֒Li�K{H�w^���������Ϥm�tq���s� ���ք��f:��o~s��g�r��ט� �S�ѱC�e]�x���a��) ���(b-$(�j>�7q�B?ӕ�F��hV25r[7 Y� }L�R��}����*sg+��x�r�2�U=�*'WS��ZDW]�WǞ�<��叓���{�$�9Ou4��y�90-�1�'*D`�c�^o?(�9��u���ݐ��'PI&� f�Jݮ�������:wS����jfP1F:X �H�9dԯ���˝[�_54 �}*;@�ܨ�� ð�yn�T���?�ןd�#���4rG�ͨ��H�1�|-#���Mr�S3��G�3�����)�.᧏3v�z֑��r����$G"�`j �1t��x0<Ɔ�Wh6�y�6��,œ�Ga��gA����y��b��)��h�D��ß�_�m��ü �gG;��e�v��ݝ�nQ� ��C����-�*��o���y�a��M��I�>�<���]obD��"�:���G�A��-\%LT�8���c�)��+y76���o�Q�#*{�(F�⽕�y����=���rW�\p���۩�c���A���^e6��K������ʐ�cVf5$�'->���ՉN"���F�"�UQ@�f��Gb~��#�&�M=��8�ט�JNu9��D��[̤�s�o�~������ G��9T�tW^g5y$b��Y'��س�Ǵ�=��U-2 #�MC�t(�i� �lj�@Q 5�̣i�*�O����s�x�K�f��}\��M{E�V�{�υ��Ƈ�����);�H����I��fe�Lȣr�2��>��W�I�Ȃ6������i��k�� �5�YOxȺ����>��Y�f5'��|��H+��98pj�n�.O�y�������jY��~��i�w'������l�;�s�2��Y��:'lg�ꥴ)o#'Sa�a�K��Z� �m��}�`169�n���"���x��I ��*+� }F<��cГ���F�P�������ֹ*�PqX�x۩��,� ��N�� �4<-����%����:��7����W���u�`����� $�?�I��&����o��o��`v�>��P��"��l���4��5'�Z�gE���8���?��[�X�7(��.Q�-��*���ތL@̲����v��.5���[��=�t\+�CNܛ��,g�SQnH����}*F�G16���&:�t��4ُ"A��̣��$�b �|����#rs��a�����T�� ]�<�j��BS�('$�ɻ� �wP;�/�n��?�ݜ��x�F��yUn�~mL*-�������Xf�wd^�a�}��f�,=t�׵i�.2/wpN�Ep8�OР���•��R�FJ� 55TZ��T �ɭ�<��]��/�0�r�@�f��V��V����Nz�G��^���7hZi����k��3�,kN�e|�vg�1{9]_i��X5y7� 8e]�U����'�-2,���e"����]ot�I��Y_��n�(JҼ��1�O ]bXc���Nu�No��pS���Q_���_�?i�~�x h5d'�(qw52] ��'ޤ�q��o1�R!���`ywy�A4u���h<קy���\[~�4�\ X�Wt/� 6�����n�F�a8��f���z �3$�t(���q��q�x��^�XWeN'p<-v�!�{�(>ӽDP7��ո0�y)�e$ٕv�Ih'Q�EA�m*�H��RI��=:��� ���4牢) �%_iN�ݧ�l]� �Nt���G��H�L��� ɱ�g<���1V�,�J~�ٹ�"K��Q�� 9�HS�9�?@��k����r�;we݁�]I�!{ �@�G�[�"��`���J:�n]�{�cA�E����V��ʆ���#��U9�6����j�#Y�m\��q�e4h�B�7��C�������d<�?J����1g:ٳ���=Y���D�p�ц� ׈ǔ��1�]26؜oS�'��9�V�FVu�P�h�9�xc�oq�X��p�o�5��Ա5$�9W�V(�[Ak�aY錎qf;�'�[�|���b�6�Ck��)��#a#a˙��8���=äh�4��2��C��4tm^ �n'c���]GQ$[Wҿ��i���vN�{Fu ��1�gx��1┷���N�m��{j-,��x�� Ūm�ЧS�[�s���Gna���䑴�� x�p 8<������97�Q���ϴ�v�aϚG��Rt�Һ׈�f^\r��WH�JU�7Z���y)�vg=����n��4�_)y��D'y�6�]�c�5̪�\� �PF�k����&�c;��cq�$~T�7j ���nç]�<�g ":�to�t}�159�<�/�8������m�b�K#g'I'.W�����6��I/��>v��\�MN��g���m�A�yQL�4u�Lj�j9��#44�t��l^�}L����n��R��!��t��±]��r��h6ٍ>�yҏ�N��fU�� ���� Fm@�8}�/u��jb9������he:A�y�ծw��GpΧh�5����l}�3p468��)U��d��c����;Us/�֔�YX�1�O2��uq�s��`hwg�r~�{ R��mhN��؎*q 42�*th��>�#���E����#��Hv�O����q�}�����6�e��\�,Wk�#���X��b>��p}�դ��3���T5��†��6��[��@�P�y*n��|'f�֧>�lư΂�̺����SU�'*�q�p�_S�����M�� '��c�6�����m�� ySʨ;M��r���Ƌ�m�Kxo,���Gm�P��A�G�:��i��w�9�}M(�^�V��$ǒ�ѽ�9���|���� �a����J�SQ�a���r�B;����}���ٻ֢�2�%U���c�#�g���N�a�ݕ�'�v�[�OY'��3L�3�;,p�]@�S��{ls��X�'���c�jw�k'a�.��}�}&�� �dP�*�bK=ɍ!����;3n�gΊU�ߴmt�'*{,=SzfD� A��ko~�G�aoq�_mi}#�m�������P�Xhύ����mxǍ�΂���巿zf��Q���c���|kc�����?���W��Y�$���_Lv����l߶��c���`?����l�j�ݲˏ!V��6����U�Ђ(A���4y)H���p�Z_�x��>���e��R��$�/�`^'3qˏ�-&Q�=?��CFVR �D�fV�9��{�8g�������n�h�(P"��6�[�D���< E�����~0<@�`�G�6����Hг�cc�� �c�K.5��D��d�B���`?�XQ��2��ٿyqo&+�1^� DW�0�ꊩ���G�#��Q�nL3��c���������/��x ��1�1[y�x�პCW��C�c�UĨ80�m�e�4.{�m��u���I=��f�����0QRls9���f���������9���~f�����Ǩ��a�"@�8���ȁ�Q����#c�ic������G��$���G���r/$W�(��W���V�"��m�7�[m�A�m����bo��D� j����۳� l���^�k�h׽����� ��#� iXn�v��eT�k�a�^Y�4�BN��ĕ��0 !01@Q"2AaPq3BR������?���@4�Q�����T3,���㺠�W�[=JK�Ϟ���2�r^7��vc�:�9 �E�ߴ�w�S#d���Ix��u��:��Hp��9E!�� V 2;73|F��9Y���*ʬ�F��D����u&���y؟��^EA��A��(ɩ���^��GV:ݜDy�`��Jr29ܾ�㝉��[���E;Fzx��YG��U�e�Y�C���� ����v-tx����I�sם�Ę�q��Eb�+P\ :>�i�C'�;�����k|z�رn�y]�#ǿb��Q��������w�����(�r|ӹs��[�D��2v-%��@;�8<a���[\o[ϧw��I!��*0�krs)�[�J9^��ʜ��p1)� "��/_>��o��<1����A�E�y^�C��`�x1'ܣn�p��s`l���fQ��):�l����b>�Me�jH^?�kl3(�z:���1ŠK&?Q�~�{�ٺ�h�y���/�[��V�|6��}�KbX����mn[-��7�5q�94�������dm���c^���h� X��5��<�eޘ>G���-�}�دB�ޟ� ��|�rt�M��V+�]�c?�-#ڛ��^ǂ}���Lkr���O��u�>�-D�ry� D?:ޞ�U��ǜ�7�V��?瓮�"�#���r��չģVR;�n���/_� ؉v�ݶe5d�b9��/O��009�G���5n�W����JpA�*�r9�>�1��.[t���s�F���nQ� V 77R�]�ɫ8����_0<՜�IF�u(v��4��F�k�3��E)��N:��yڮe��P�`�1}�$WS��J�SQ�N�j�ٺ��޵�#l���ј(�5=��5�lǏmoW�v-�1����v,W�mn��߀$x�<����v�j(����c]��@#��1������Ǔ���o'��u+����;G�#�޸��v-lη��/(`i⣍Pm^���ԯ̾9Z��F��������n��1��� ��]�[��)�'������:�֪�W��FC����� �B9،!?���]��V��A�Վ�M��b�w��G F>_DȬ0¤�#�QR�[V��kz���m�w�"��9ZG�7'[��=�Q����j8R?�zf�\a�=��O�U����*oB�A�|G���2�54 �p��.w7� �� ��&������ξxGHp� B%��$g�����t�Џ򤵍z���HN�u�Я�-�'4��0��;_��3 !01"@AQa2Pq#3BR������?��ʩca��en��^��8���<�u#��m*08r��y�N"�<�Ѳ0��@\�p��� �����Kv�D��J8�Fҽ� �f�Y��-m�ybX�NP����}�!*8t(�OqѢ��Q�wW�K��ZD��Δ^e��!� ��B�K��p~�����e*l}z#9ң�k���q#�Ft�o��S�R����-�w�!�S���Ӥß|M�l޶V��!eˈ�8Y���c�ЮM2��tk���� ������J�fS����Ö*i/2�����n]�k�\���|4yX�8��U�P.���Ы[���l��@"�t�<������5�lF���vU�����W��W��;�b�cД^6[#7@vU�xgZv��F�6��Q,K�v��� �+Ъ��n��Ǣ��Ft���8��0��c�@�!�Zq s�v�t�;#](B��-�nῃ~���3g������5�J�%���O������n�kB�ĺ�.r��+���#�N$?�q�/�s�6��p��a����a��J/��M�8��6�ܰ"�*������ɗud"\w���aT(����[��F��U՛����RT�b���n�*��6���O��SJ�.�ij<�v�MT��R\c��5l�sZB>F��<7�;EA��{��E���Ö��1U/�#��d1�a�n.1ě����0�ʾR�h��|�R��Ao�3�m3 ��%�� ���28Q� ��y��φ���H�To�7�lW>����#i`�q���c����a��� �m,B�-j����݋�'mR1Ήt�>��V��p���s�0IbI�C.���1R�ea�����]H�6����������4B>��o��](��$B���m�����a�!=��?�B� K�Ǿ+�Ծ"�n���K��*��+��[T#�{E�J�S����Q�����s�5�:�U�\wĐ�f�3����܆&�)����I���Ԇw��E T�lrTf6Q|R�h:��[K�� �z��c֧�G�C��%\��_�a�84��HcO�bi��ؖV��7H �)*ģK~Xhչ0��4?�0��� �E<���}3���#���u�?�� ��|g�S�6ꊤ�|�I#Hڛ� �ա��w�X��9��7���Ŀ%�SL��y6č��|�F�a 8���b��$�sק�h���b9RAu7�˨p�Č�_\*w��묦��F ����4D~�f����|(�"m���NK��i�S�>�$d7SlA��/�²����SL��|6N�}���S�˯���g��]6��; �#�.��<���q'Q�1|KQ$�����񛩶"�$r�b:���N8�w@��8$�� �AjfG|~�9F ���Y��ʺ��Bwؒ������M:I岎�G��`s�YV5����6��A �b:�W���G�q%l�����F��H���7�������Fsv7��k�� 403WebShell
403Webshell
Server IP : 54.89.25.11  /  Your IP : 216.73.216.121
Web Server : Apache/2.4.7 (Ubuntu)
System : Linux ip-172-31-88-18 3.13.0-74-generic #118-Ubuntu SMP Thu Dec 17 22:52:10 UTC 2015 x86_64
User : www-data ( 33)
PHP Version : 5.5.9-1ubuntu4.24
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/kalemon/module-old/Test/src/Test/Controller/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/kalemon/module-old/Test/src/Test/Controller//TestController.php
<?php

namespace Test\Controller;

use Checkondispatch\Custom\AbstractSecureController;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;
use Zend\Session\Container;
use Test\Form\TestForm;
use Test\Model\TestInputFilter;
use Secure\Model\Grade\GradeTable;
use Zend\Http\Client;

//use mPDF;
class TestController extends AbstractSecureController {

    use placementFunctionTrait;

    private $testPlugin;

    public function __construct() {
        $this->container = new Container('auth');
    }

    private function getConfig() {
        return $this->getServiceLocator()->get('Config');
    }

    /**
     * @desc Used to display automative-test for demo purposes.
     * @return ViewModel
     */
    function AutomativeTestAction() {
        $this->CommonClass()->setCustomLayout($this, 'backendLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $viewModel->setVariables([]);
        return $viewModel;
    }

    public function indexAction() {
		return $this->redirect()->toRoute('test', array('action' => 'quiz'));
        $_SESSION['ass'] = '';
        $_SESSION['url'] = '';
        $translator = $this->getServiceLocator()->get('translator');
        $config = $this->getServiceLocator()->get('config');
        $this->CommonClass()->setCustomLayout($this, 'backendLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
        $request = $this->getRequest();
        $requestData = $request->getPost()->toArray();
        $requestData['sortColumn'] = (isset($requestData['sortColumn']) && !empty($requestData['sortColumn'])) ? $requestData['sortColumn'] : "QUIZ_ID";
        $requestData['sortType'] = ( isset($requestData['sortType']) && !empty($requestData['sortType'])) ? $requestData['sortType'] : "DESC";
        $requestData['START'] = 0;
        $requestData['LENGTH'] = $config["RECORDS_PER_PAGE"];
        $requestData['apiStatus'] = $this->container->authDetail['TEST_ENABLE'];
        $requestData['USER_OID'] = $this->container->authDetail['USER_OID'];
        $requestData['ORG_ID'] = $this->container->authDetail['ORG_ID'];
        $requestData['UT_ID'] = $this->container->authDetail['UT_ID'];
        if ($request->isXmlHttpRequest()) {
            if (isset($_POST['searchfor']) && !empty($_POST['searchfor'])) {
                $requestData['searchKey'] = $_POST['searchfor'];
                $requestData['searchColumn'] = 'TITLE';
                $requestData['START'] = !empty($requestData['start']) ? $requestData['start'] : 0;
            } else { // code to display country listing while scrolling down by user
                $requestData['START'] = !empty($requestData['start']) ? $requestData['start'] : 0;
            }
            $quizList = $createQuizTable->getPlcTestList($requestData);
            $htmlViewPart = new ViewModel();
            $htmlViewPart->setTerminal(true)
                    ->setTemplate('test/test/listquiz.phtml')
                    ->setVariables(array('quizData' => $quizList, 'userId' => $requestData['USER_OID'], 'utId' => $requestData['UT_ID']));
            $htmlOutput = $this->getServiceLocator()->get('viewrenderer')->render($htmlViewPart);
            $jsonModel = new JsonModel();
            $jsonModel->setVariables(array(
                'responseData' => $htmlOutput
            ));
            return $jsonModel;
        }
        $quizList = $createQuizTable->getPlcTestList($requestData);
        $viewModel->setTemplate('test/test/test.phtml')->setVariables(array('quizData' => $quizList, 'userId' => $requestData['USER_OID'], 'utId' => $requestData['UT_ID'], 'userSessionDetails' => $this->container->authDetail));
        return $viewModel;
    }

    public function quizAction() {
        $_SESSION['ass'] = '';
        $translator = $this->getServiceLocator()->get('translator');
        $config = $this->getServiceLocator()->get('config');
        $this->CommonClass()->setCustomLayout($this, 'backendLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
        $request = $this->getRequest();
        $requestData = $request->getPost()->toArray(); //echo print_r($requestData); die;
        $requestData['sortColumn'] = (isset($requestData['sortColumn']) && !empty($requestData['sortColumn'])) ? $requestData['sortColumn'] : "QUIZ_ID";
        $requestData['sortType'] = ( isset($requestData['sortType']) && !empty($requestData['sortType'])) ? $requestData['sortType'] : "DESC";
        $requestData['START'] = 0;
        $requestData['LENGTH'] = $config["RECORDS_PER_PAGE"];
        $requestData['apiStatus'] = $this->container->authDetail['TEST_ENABLE'];
        $requestData['USER_OID'] = $this->container->authDetail['USER_OID'];
        $requestData['ORG_ID'] = $this->container->authDetail['ORG_ID'];
        $requestData['UT_ID'] = $this->container->authDetail['UT_ID'];
        $this->container->authDetail['EDIT_FROM'] = 'quiz';
        $requestData['Created_By'] = (!empty($this->params()->fromQuery('only'))) ? 'OnlyMy' : "All";
        $requestData['test_type'] = (!empty($this->params()->fromQuery('test_type'))) ? $this->params()->fromQuery('test_type') : ''; // for Only FT Test        
        $filtertext = $translator->translate("Filter");
        if ($requestData['Created_By'] == 'OnlyMy') {
            $filtertext = $translator->translate("Created By Me");
        }
        if ($requestData['test_type'] == 'GT') {
            $filtertext = $translator->translate("Formative Test");
        }
        if ($requestData['test_type'] == 'ST') {
            $filtertext = $translator->translate("Summative Test");
        }
        if ($requestData['test_type'] == 'FT') {
            $filtertext = $translator->translate("Final Test");
        }
        $quizfttestList = $quizList = [];
        if ($request->isXmlHttpRequest()) {
            if (isset($_POST['searchfor']) && !empty($_POST['searchfor'])) {
                $requestData['searchKey'] = $_POST['searchfor'];
                $requestData['searchColumn'] = 'TITLE';
                $requestData['START'] = !empty($requestData['start']) ? $requestData['start'] : 0;
            } else { // code to display country listing while scrolling down by user
                $requestData['START'] = !empty($requestData['start']) ? $requestData['start'] : 0;
            }
            if (empty($requestData['test_type'])) {
                $quizList = $createQuizTable->getAllTypeTestListing($requestData);
            } else {
                $quizList = $createQuizTable->getfinalTestList($requestData);                      //for ft test    
            }
            $htmlViewPart = new ViewModel();
            $htmlViewPart->setTerminal(true)
                    ->setTemplate('test/test/quiz-listgt.phtml')
                    ->setVariables(array('quizData' => $quizList, 'userId' => $requestData['USER_OID'], 'utId' => $requestData['UT_ID']));
            $htmlOutput = $this->getServiceLocator()->get('viewrenderer')->render($htmlViewPart);
            $jsonModel = new JsonModel();
            $jsonModel->setVariables(array(
                'responseData' => $htmlOutput
            ));
            return $jsonModel;
        }
        if (empty($requestData['test_type'])) {
            $quizList = $createQuizTable->getAllTypeTestListing($requestData);
        } else {
            $quizList = $createQuizTable->getfinalTestList($requestData);                  //for ft test                       
        }
        $viewModel->setTemplate('test/test/quiz.phtml')->setVariables(array('quizData' => $quizList, 'userId' => $requestData['USER_OID'], 'utId' => $requestData['UT_ID'], 'userSessionDetails' => $this->container->authDetail, 'filtertext' => $filtertext));
        return $viewModel;
    }

    /**
     * @desc Create and edit entries for entire test, even through courses.
     * @return JsonModel on Add/edit request else return ViewModel
     */
    public function generatePdfAction() {
        $baseDirPath = getcwd() . '/library/';
        require_once ($baseDirPath . 'mpdf/mpdf.php');
        $mpdf = new mPDF('c', 'A4');
        //$mpdf = new mPDF('', 'A4', '', '', 32, 25, 27, 25, 16, 13);
        $mpdf->SetDisplayMode('fullpage');
        $translator = $this->getServiceLocator()->get('translator');
        $config = $this->getServiceLocator()->get('config');
        $this->CommonClass()->setCustomLayout($this, 'backendLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
        $request = $this->getRequest();
        $requestData = $request->getPost()->toArray();
        $requestData['sortColumn'] = (isset($requestData['sortColumn']) && !empty($requestData['sortColumn'])) ? $requestData['sortColumn'] : "QUIZ_ID";
        $requestData['sortType'] = ( isset($requestData['sortType']) && !empty($requestData['sortType'])) ? $requestData['sortType'] : "DESC";
        $requestData['START'] = 0;
        $requestData['LENGTH'] = $config["RECORDS_PER_PAGE"];
        $requestData['apiStatus'] = $this->container->authDetail['TEST_ENABLE'];
        $requestData['USER_OID'] = $this->container->authDetail['USER_OID'];
        $requestData['ORG_ID'] = $this->container->authDetail['ORG_ID'];
        $requestData['UT_ID'] = $this->container->authDetail['UT_ID'];
        $quizList = $createQuizTable->getPlcTestList($requestData);
        $viewModel = new ViewModel();
        $viewModel->setTemplate('test/test/listquizpdf.phtml')->setVariables(array('mpdf' => $mpdf, 'quizData' => $quizList, 'userId' => $requestData['USER_OID'], 'utId' => $requestData['UT_ID'], 'userSessionDetails' => $this->container->authDetail));
        return $viewModel;
    }

    public function editAction() {
        $config = $this->getConfig();
        $this->CommonClass()->setCustomLayout($this, 'backendLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $translator = $this->getServiceLocator()->get('translator');
         $this->container->authDetail['EDIT_FROM_CU'] = 'quiz'; 
         $userId = $this->container->authDetail['USER_OID'];
        $utId = $this->container->authDetail['UT_ID'];
        $orgId = $this->container->authDetail['ORG_ID'];
        $ccoGradeList = [];
            
        //$ccoGradeList = $this->getGradesLocal('cco');        
        $localGradeList = $this->getGradesLocal();
        $request = $this->getRequest();
        $postData = $request->getPost()->toArray();
        $requestData = $request->getQuery()->toArray();
        $dbadapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
        $createQuizTable = new \Test\Model\CreateQuizTable($dbadapter);
        $curriculumTable = new \Curriculum\Model\CurriculumTable($dbadapter);
        $viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
        $configFunction = $viewHelperManager->get('repoconfig');
        $bank_uuid = $this->container->authDetail['BANK_UUID'];
        $userType = $this->container->authDetail['USER_TYPE'];
        $lastQusId = (!empty($this->params()->fromQuery('lastQusId'))) ? $this->params()->fromQuery('lastQusId') : '';
        $step = (!empty($this->params('step'))) ? $this->params('step') : 1;
        $testId = !empty($this->params('id')) ? $this->params('id') : '';
        /* Redirect with access test using another org Id */
        if (!empty($testId)) {
            $oId = $createQuizTable->getTestAuthentication($testId);
            if ($orgId != $oId) {
                $config = $this->serviceLocator->get('config');
                $route = $config['user_auth_redirect'][$userType]['route'];
                $action = $config['user_auth_redirect'][$userType]['action'];
                return $this->redirect()->toRoute($route, array('action' => $action));
            }
        }
        /* ---- */
        $lpId = isset($requestData['lpId']) ? $requestData['lpId'] : '';
        $test_type = isset($requestData['test_type']) ? $requestData['test_type'] : '';
        $edit_from = isset($requestData['edit_from']) ? $requestData['edit_from'] : '';
        $test_level = isset($requestData['test_level']) ? $requestData['test_level'] : '';
        $test_subject = isset($requestData['test_subject']) ? $requestData['test_subject'] : '';
        // for Automative Test, during creation of Final Test
        $test_create_mode = isset($requestData['test_create_mode']) ? $requestData['test_create_mode'] : '';
        /** Get Test-Name incase of SUMMATIVE-TEST (ST) */
        $postTestName = isset($postData['TEST_NAME']) ? $postData['TEST_NAME'] : null;
        $postData['TEST_NAME'] = isset($requestData['TEST_NAME']) && $test_type == 'ST' ? $requestData['TEST_NAME'] : $postTestName;
        if (!empty($edit_from)) {
            $str = "&edit_from=" . $edit_from;
        } else {
            $str = "";
        }
        $result = [];
        $start = isset($postData['start']) ? $postData['start'] : "1";
        $search = isset($postData['searchfor']) ? $postData['searchfor'] : "";
        $banktext = isset($postData['banktext']) ? $postData['banktext'] : "";
        $qnsType = isset($postData['qnsType']) ? $postData['qnsType'] : "";
        $cognitiveId = isset($postData['cognitiveId']) ? $postData['cognitiveId'] : "";
        $topicArr = [0];
        $topicApiArr = [0];
        $gradeArr = [0];
        $subjectArr = [0];
        /** Used to prepare quiz-LP's topics as an array to get these topic associated question only(In 2nd tab of quiz). */
        $quiz_lp_topics = [];
        $quiz_lp_api_topics = [];
        $quiz_lp_topics_array = [];
        $quiz_lp_api_topics_array = [];
        if (!empty($testId) && $test_type == 'ST') {
            $joins[] = ['t_cm_lessonplan_topic', 't_cm_lessonplan_topic.LESSONPLAN_ID = t_mgr_test_lessonplan.LESSONPLAN_ID', ['TOPIC_ID']];
            $joins[1] = ['t_cm_mgr_curriculum_outline', 't_cm_mgr_curriculum_outline.CAT_ID = t_cm_lessonplan_topic.TOPIC_ID', ['CAT_ID', 'ADM_REF_ID', 'CAT_NAME']];
            $quiz_lp_topics_data = $createQuizTable->fetchData('t_mgr_test_lessonplan', ['t_mgr_test_lessonplan.QUIZ_ID' => $testId], ['LESSONPLAN_ID'], null, true, null, null, null, null, null, null, $joins);
            if (count($quiz_lp_topics_data)) {
                foreach ($quiz_lp_topics_data as $topicData) {
                    $quiz_lp_topics[] = $topicData['CAT_ID'];
                    $quiz_lp_topics_array[$topicData['CAT_ID']] = $topicData['CAT_NAME'];
                    if (!empty($topicData["ADM_REF_ID"])) {
                        $quiz_lp_api_topics_array[$topicData["ADM_REF_ID"]] = $topicData["CAT_NAME"];
                    }
                }
            }
            /** Only unique topic-id array for local and API. */
            $quiz_lp_topics = array_unique($quiz_lp_topics);
            $quiz_lp_api_topics = array_unique($quiz_lp_api_topics);
            /** Unique Key-value pair of topic-id and topic name respectively for local and API.. */
            $quiz_lp_topics_array = array_unique($quiz_lp_topics_array);
            $quiz_lp_api_topics_array = array_unique($quiz_lp_api_topics_array);
        }
        if (!$test_subject) {
            /** for ADMIN */
            if ($utId == 5) {
                $subjects = [0];
                $grades = $curriculumTable->fetchData('t_cm_mgr_grade', array('ORG_ID' => $this->container->authDetail['ORG_ID']), array('GRADE_ID'));
                if (!empty($grades)) {
                    foreach ($grades as $grade) {
                        $gradeArr[] = $grade["GRADE_ID"];
                    }
                }
                $subjects = $createQuizTable->fetchData('t_cm_mgr_subject', ['GRADE_ID' => $gradeArr], ['SUBJECT_ID']);
                if (!empty($subjects)) {
                    foreach ($subjects as $subject) {
                        $subjectArr[] = $subject["SUBJECT_ID"];
                    }
                }
                $topics = $createQuizTable->fetchData('t_cm_mgr_curriculum_outline', ['SUBJECT_ID' => $subjectArr], ['CAT_ID', 'ADM_REF_ID']);
                if (!empty($topics)) {
                    foreach ($topics as $topic) {
                        $topicArr[] = $topic["CAT_ID"];
                        if (!empty($topic["ADM_REF_ID"]))
                            $topicApiArr[] = $topic["ADM_REF_ID"];
                    }
                }
                /** for TEACHER */
            } else if ($utId == 2) {
                $subjects = [0];
                $subjects = $curriculumTable->getAssignSubjectById($userId);
                $topics = $createQuizTable->fetchData('t_cm_mgr_curriculum_outline', ['SUBJECT_ID' => $subjects], ['CAT_ID', 'ADM_REF_ID']);
                if (!empty($topics)) {
                    foreach ($topics as $topic) {
                        $topicArr[] = $topic["CAT_ID"];
                        if (!empty($topic["ADM_REF_ID"]))
                            $topicApiArr[] = $topic["ADM_REF_ID"];
                    }
                }
            }
        }
        /** being empty for now */
        $topicApiArr = [];
        $topicId = !empty($postData['topicId']) ? $postData['topicId'] : (count($quiz_lp_topics) && $test_type == 'ST') ? $quiz_lp_topics : $topicArr;
        $topicIdApi = !empty($postData['topicId']) ? $postData['topicId'] : (count($quiz_lp_api_topics) && $test_type == 'ST') ? $quiz_lp_api_topics : $topicApiArr;
        $difficultyLevel = isset($postData['difficultyLevel']) ? $postData['difficultyLevel'] : "";
        $listFrom = isset($postData['listFrom']) ? $postData['listFrom'] : "LOCAL";
        $limit = 10;
        $this->layout()->setVariable('quiz_type', $test_type,'userSessionDetails' , $this->container->authDetail);
        if ($request->isXmlHttpRequest()) {
            
            /** Get topics when request comes from AJAX (as string to array converted here) to get appropriate data for both tab types. */
            $postData['topicId'] = isset($postData['topicId']) && !empty($postData['topicId']) && gettype($postData['topicId'] == 'string') ? explode(',', $postData['topicId']) : (isset($postData['topicId']) ? $postData['topicId'] : [0]);
            $topicId = (isset($postData['isAdvanceSearch']) && $postData['isAdvanceSearch']) ? (!empty($postData['topicId']) ? $postData['topicId'] : [0]) : (((count($quiz_lp_topics) && $test_type == 'ST')) ? $quiz_lp_topics : (count($topicArr) ? $topicArr : [0]));
            $topicIdApi = (isset($postData['isApiAdvanceSearch']) && $postData['isApiAdvanceSearch']) ? (!empty($postData['topicId']) ? $postData['topicId'] : [0]) : (((count($quiz_lp_api_topics) && $test_type == 'ST')) ? $quiz_lp_api_topics : (count($topicApiArr) ? $topicApiArr : [0]));
            $viewModel = new JsonModel();
            if (!isset($testId) || empty($testId)) {
                $dbadapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
                $grade = new GradeTable($dbadapter);
                $CONT_ORDER = $grade->getContentCountByLpId($postData['lpId']);
                /** One time add case for title only. */
                if (!empty($postData['TEST_NAME'])) {
                    if ($postData['TEST_TYPE'] == 'GT') {
                        $contentData = [
                            'LESSONPLAN_ID' => $postData['lpId'],
                            'CONT_TITLE' => $postData['TEST_NAME'],
                            'CONTTYPE_ID' => $postData['CONTTYPE_ID'],
                            'CONT_ORDER' => $CONT_ORDER,
                            'STATUS' => 'A',
                            'CREATED_ON' => date('Y-m-d H:i:s'),
                            'CREATED_BY' => $userId,
                        ];
                        $contId = $createQuizTable->insertData('t_cm_cnf_content', $contentData);
                    } else {
                        $contId = 0;
                    }
                    $testData = [
                        'CONT_ID' => $contId,
                        'SUBJECT_ID' => !empty($postData['TEST_SUBJECT']) ? $postData['TEST_SUBJECT'] : null,
                        'TITLE' => $postData['TEST_NAME'],
                        'PLC_LEVEL_ID' => $postData['TEST_LEVEL'],
                        'QUIZ_TYPE' => $postData['TEST_TYPE'],
                        'QUIZ_MODE' => ( isset($postData['TEST_TYPE_CREATION']) && $postData['TEST_TYPE_CREATION'] == 'AT') ? 'A' : 'M',
                        'STATUS' => 'A',
                        'CREATED_ON' => date('Y-m-d H:i:s'),
                        'CREATED_BY' => $userId,
                        'TEST_ID' => '',
                    ];
                    $testData['TEST_ID'] = 0;
                    $quizId = $createQuizTable->insertData('t_master_test', $testData);
                    if ($postData['TEST_TYPE'] == 'GT') {
                        $redPath = $this->getRequest()->getBasePath() . '/test/edit/' . $quizId . '/2?lpId=' . $lpId . $str;
                    } else if ($postData['TEST_TYPE'] == 'FT' && $postData['TEST_TYPE_CREATION'] == 'AT') {
                        $redPath = $this->getRequest()->getBasePath() . '/test/edit/' . $quizId . '/2?test_type=' . $postData['TEST_TYPE'] . '&test_create_mode=AT' . $str;
                    } else {
                        $redPath = $this->getRequest()->getBasePath() . '/test/edit/' . $quizId . '/2?test_type=' . $postData['TEST_TYPE'] . $str;
                    }
                    $result = ['result' => true, 'redirectUrl' => $redPath];
                } else {
                    $result = array("result" => false, "message" => array("TEST_NAME" => array("isEmpty" => $translator->translate("Value is required and can't be empty"))));
                }
            } else {
                /** Edit case */
                if (!empty($testId) && ( $step == 1 || !isset($step)) && !empty($postData['TEST_NAME'])) {
                    $testData = [
                        'TITLE' => $postData['TEST_NAME'],
                        'UPDATED_ON' => date('Y-m-d H:i:s'),
                        'UPDATED_BY' => $userId,
                    ];
                    if (isset($postData['TEST_TYPE_CREATION'])) {
                        $testData = [
                            'QUIZ_MODE' => ($postData['TEST_TYPE_CREATION'] == 'AT') ? "A" : 'M',
                        ];
                    }
                    $contData = $createQuizTable->fetchData('t_master_test', ['QUIZ_ID' => $testId], ['TEST_ID', 'QUIZ_TYPE'], null, false);
                    $quzId = (!empty($contData['TEST_ID'])) ? $contData['TEST_ID'] : null;
                    $quzType = (!empty($contData['QUIZ_TYPE'])) ? $contData['QUIZ_TYPE'] : null;
                    $isUpdatedTest = $createQuizTable->updateData('t_master_test', $testData, ['QUIZ_ID' => $testId]);
                    $isUpdatedTest = 1;
                    if ($isUpdatedTest && ($quzType == 'PT' || $quzType == 'FT' || $quzType == 'ST')) {
                        if ($quzType == 'FT' && $postData['TEST_TYPE_CREATION'] == 'AT') {
                            $redPath = $this->getRequest()->getBasePath() . '/test/edit/' . $testId . '/2?test_type=' . $quzType . '&test_create_mode=AT' . $str;
                        } else {
                            $redPath = $this->getRequest()->getBasePath() . '/test/edit/' . $testId . '/2?test_type=' . $quzType . $str;
                        }
                        $result = ['result' => true, 'redirectUrl' => $redPath];
                    } else {
                        $contData = $createQuizTable->fetchData('t_master_test', ['QUIZ_ID' => $testId], ['CONT_ID'], null, false);
                        if ($isUpdatedTest) {
                            $contentData = [
                                'CONT_TITLE' => $postData['TEST_NAME'],
                                'UPDATED_ON' => date('Y-m-d H:i:s'),
                                'UPDATED_BY' => $userId
                            ];
                            $condition = ['CONT_ID' => $contData->CONT_ID];
                            $isUpdatedContent = $createQuizTable->updateData('t_cm_cnf_content', $contentData, $condition);
                            if ($isUpdatedContent) {
                                if (!empty($edit_from)) {
                                    $str = "&edit_from=" . $edit_from;
                                } else {
                                    $str = "";
                                }
                                $redPath = $this->getRequest()->getBasePath() . '/test/edit/' . $testId . '/2?lpId=' . $lpId . $str;
                                $result = ['result' => true, 'redirectUrl' => $redPath];
                            }
                        }
                    }
                } else {
                    $result = array("result" => false, "message" => array("TEST_NAME" => array("isEmpty" => "Value is required and can't be empty")));
                }
            }
            /** STEP - 2 via AJAX Request(s). */
            if ($step == 2) {
                /** Get all Mixed question(s) (both LOCAL & API) within a specific test. */
                $allQsnOfQuiz = $createQuizTable->getAllQsnByQuiz($testId);
                /** If request comes from API Tab. */
                if ($listFrom == 'API') {
                    /** Searching Criteria for API requests. */
                    $apiSearchArr = array(
                        'search' => $search,
                        'qnsType' => $qnsType,
                        'cognitiveId' => $cognitiveId,
                        'topicId' => $topicIdApi,
                        'difficultyLevel' => $difficultyLevel,
                        'bankUuid' => $bank_uuid,
                    );
                    if ($banktext) {
                        $bank_detail = [];
                        $apiSearchArr['bankUuid'] = $bank_detail[0]['BANK_UUID'];
                    }
                    $questionCount = (!count($quiz_lp_api_topics) && $test_type == 'ST') ? [] : [];
                    $questionsListing = (!count($quiz_lp_api_topics) && $test_type == 'ST') ? [] : [];
                    /** To get and displayed API`s Question(s) as checked. */
                    $apiQues = $createQuizTable->getAllApiQsnByTestId($testId);
                    $apiQuesIds = [];
                    $apiquesMarks = [];
                    $testData = [];
                    if (count($apiQues)) {
                        $quesIds = '';
                        $apiquesMarks = [];
                        foreach ($apiQues as $val) {
                            $quesIds .= $val['QUS_ID'] . ',';
                            $apiquesMarks[] = $val['QUS_MARK'];
                        }
                        $apiQuesIds['questionIds'] = substr($quesIds, 0, -1);
                    }
                    $apiQuesIds['pageType'] = 'searchFilter';
                    if (!empty($apiQuesIds['questionIds'])) {
                        $testData['QUIZ_QUESTIONS'] = [];
                    }
                    /** Only to get All API question-ID`s for select all criteria feature. */
                    $questionsList = (!count($quiz_lp_api_topics) && $test_type == 'ST') ? [] : [];
                    if (count($questionsList)) {
                        foreach ($questionsList as $val) {
                            $total_api_ques_ids[] = $val['QUS_ID'] . '-API';
                        }
                    }
                } else {
                    /** If request comes from API Tab. */
                    /** Searching Criteria for LOCAL requests. */
                    $localSearchArr = array(
                        'search' => $search,
                        'banktext' => $banktext,
                        'qnsType' => $qnsType,
                        'cognitiveId' => $cognitiveId,
                        'topicId' => $topicId,
                        'difficultyLevel' => $difficultyLevel,
                        'bankUuid' => $bank_uuid,
                        'userId' => $userId
                    );
                    /** Total initial count for Questions from LOCAL. */
                    $questionCountDB = (!count($quiz_lp_topics) && $test_type == 'ST') ? [] : $createQuizTable->getAllQuestionsCount($localSearchArr, true);
                    /** Extended Searching Criteria for LOCAL requests. */
                    $localSearchArr['page'] = $start;
                    $localSearchArr['records'] = $limit;
                    /** Total initial List for Questions from LOCAL. */
                    $questionsListingDB = (!count($quiz_lp_topics) && $test_type == 'ST') ? [] : $createQuizTable->getAllQuestion($localSearchArr, $configFunction);
                    /** Only to get All Local question-ID`s for select all criteria feature with AJAX request. */
                    $questionsListDB = (!count($quiz_lp_topics) && $test_type == 'ST') ? [] : $createQuizTable->getAllQuestion($localSearchArr, $configFunction, true);
                    if (count($questionsListDB)) {
                        foreach ($questionsListDB as $val) {
                            $total_local_ques_ids[] = $val['QUS_ID'] . '-LOCAL';
                        }
                    }
                    /** Get all question(s) in a test from LOCAL only. */
                    $allLocalQuesOfTest = $createQuizTable->getAllLocalQsnByTestId($testId);
                }
                $htmlViewPart = new ViewModel();
                $htmlViewPart->setTerminal(true)
                        ->setTemplate('test/test/search-filter-data.phtml')
                        ->setVariables([
                            'step' => $step,
                            'testId' => $testId,
                            'title' => !empty($title) ? $title : '',
                            'quizMode' => !empty($quizMode) ? $quizMode : '',
                            'questionsListing' => !empty($questionsListing) ? $questionsListing : [],
                            'questionsListingDB' => !empty($questionsListingDB) ? $questionsListingDB : [],
                            'start' => $start,
                            'testData' => !empty($testData) ? $testData : [],
                            'testDataDB' => !empty($testDataDB) ? $testDataDB : [],
                            'totalFilterQuestionsData' => !empty($questionsListing) ? count($questionsListing) : 0,
                            'questionCount' => !empty($questionCount['total_questions']['total_items']) ? $questionCount['total_questions']['total_items'] : 0,
                            'questionCountDB' => !empty($questionCountDB) ? $questionCountDB : 0,
                            'listFrom' => !empty($postData['listFrom']) ? $postData['listFrom'] : 'LOCAL',
                            'allQsnOfQuiz' => $allQsnOfQuiz,
                            'allLocalQuesOfTest' => !empty($allLocalQuesOfTest) ? $allLocalQuesOfTest : [],
                            'test_type' => $test_type,
                            'getApiGrades' => $ccoGradeList,
                            'totalApiQuesIds' => !empty($total_api_ques_ids) ? $total_api_ques_ids : [],
                            'totalLocalQuesIds' => !empty($total_local_ques_ids) ? $total_local_ques_ids : [],
                            'edit_from' => $edit_from,
                            'EDIT_FROM' => 'quiz'
                ]);
                $htmlOutput = $this->getServiceLocator()->get('viewrenderer')->render($htmlViewPart);
                $jsonModel = new JsonModel();
                $jsonModel->setVariables(array(
                    'responseData' => $htmlOutput
                ));
                return $jsonModel;
            }
            $viewModel->setVariables(['data' => $result]);
            return $viewModel;
        }
        if (( $step == 1 || !isset($step))) {
            $title = '';
            $quizMode = '';
            if (!empty($testId)) {
                $dataTitle = $createQuizTable->fetchData('t_master_test', ['QUIZ_ID' => $testId], ['TITLE', 'QUIZ_MODE', 'QUIZ_TYPE'], null, false);
                $title = $dataTitle->TITLE;
                $quizMode = $dataTitle->QUIZ_MODE;
                $quizTypeFromDB = $dataTitle->QUIZ_TYPE;
            }
            $viewModel->setVariables([
                'step' => $step,
                'testId' => $testId,
                'title' => $title,
                'lpId' => $lpId,
                'quizMode' => $quizMode,
                'quizTypeFromDB' => !empty($quizTypeFromDB) ? $quizTypeFromDB : '',
                'test_level' => $test_level,
                'test_subject' => $test_subject,
                "test_type" => $test_type,
                'getApiGrades' => $ccoGradeList,
                'edit_from' => $edit_from,
                'userSessionDetails' => $this->container->authDetail
            ]);
        }
        /** STEP - 2 on initial Request(s). */
        if ($step == 2) {
            if (!empty($test_create_mode) && $test_create_mode == 'AT') {
                $qusCount = 0;
                $QusMark = 0;
                $qusIdsStr = '';
                if ($testId) {
                    $allQuesForTest = $createQuizTable->getAllQuesByQuizId($testId);
                    $qusCount = count($allQuesForTest);
                    if (!empty($allQuesForTest)) {
                        foreach ($allQuesForTest as $questionArr) {
                            if ($questionArr['QUS_MARK']) { // if ques marks given
                                $QusMark += $questionArr['QUS_MARK'];
                            } else { // if not then show default marks
                                $QusMark += $createQuizTable->getDefaulQuesMarkByQuesId($questionArr['QUS_ID']);
                            }
                            if (empty($questionArr['QUS_REF_ID'])) { // means LOCAL ques
                                $questionArr['QUS_ID'] . '-LOCAL';
                                $qusIdsStr .= $questionArr['QUS_ID'] . '-LOCAL,';
                            } else { // means API ques
                                $qusIdsStr .= $questionArr['QUS_ID'] . '-API,';
                            }
                        }
                    }
                }
                // cognitive from LOCAL                
                $localCognitive = $createQuizTable->fetchData('t_adm_cnf_cognitive');
                foreach ($localCognitive as $localCog) {
                    $localDomains[$localCog['COGNITIVE_ID']] = $localCog['COGNITIVE_NAME'];
                }
                // question type from LOCAL
                $quesType = $createQuizTable->fetchData('t_master_question_type', array('STATUS' => 'A'), array('*'));
                $questionTypeArray = [];
                foreach ($quesType as $ques_type) {
                    $questionTypeArray[$ques_type['QUESTYPE_ID']] = $ques_type['QUES_TYPE'];
                }
                $viewModel->setVariables([
                    'step' => $step,
                    'testId' => $testId,
                    'lpId' => $lpId,
                    'test_type' => $test_type,
                    'getApiGrades' => $ccoGradeList,
                    'getLocalGrades' => $localGradeList,
                    'test_create_mode' => $test_create_mode,
                    'questionTypeArray' => $questionTypeArray,
                    'apiCognitive' => $localDomains,
                    'edit_from' => $edit_from,
                      'userSessionDetails' => $this->container->authDetail,
                    'qusCount' => $qusCount,
                    'QusMark' => $QusMark,
                    'qusIdsStr' => substr($qusIdsStr, 0, -1),
                ]);
            } else {
                /** Get Commonly used test-specific details, and get all question(s) within a quiz. */
                $testDetail = $createQuizTable->fetchData('t_master_test', ['QUIZ_ID' => $testId], ['TEST_ID'], null, false);
                $allQsnOfQuiz = $createQuizTable->getAllQsnByQuiz($testId);
                /** Searching Criteria for Local & API requests. */
                $localSearchArr = array('bankUuid' => $bank_uuid, 'page' => $start, 'records' => $limit, 'userId' => $userId, 'topicId' => $topicId);
                $localSearchPageArr = array('bankUuid' => $bank_uuid, 'userId' => $userId, 'topicId' => $topicId);
                $apiSearchArr = array('bankUuid' => $bank_uuid, 'topicId' => $topicIdApi);
                /** Get Question listing, test-detail, question counting via Local. */
                $questionsListingDB = (!count($quiz_lp_topics) && $test_type == 'ST') ? [] : $createQuizTable->getAllQuestion($localSearchArr, $configFunction);
                $testDataDB = $createQuizTable->getAllTest($testId);
                $questionCountDB = (!count($quiz_lp_topics) && $test_type == 'ST') ? [] : $createQuizTable->getAllQuestionsCount($localSearchPageArr, true);
                $allLocalQuesOfTest = $createQuizTable->getAllLocalQsnByTestId($testId);
                /** Get API Question`s listing to rendered & count on the API Tab. */
                $questionsListing = (!count($quiz_lp_api_topics) && $test_type == 'ST') ? [] : [];
                $questionCount = (!count($quiz_lp_api_topics) && $test_type == 'ST') ? [] : [];
                /** Get all API question-id's to get checked via local question-id's by Local */
                $apiQues = $createQuizTable->getAllApiQsnByTestId($testId);
                $apiQuesIds = [];
                $apiquesMarks = [];
                $testData = [];
                if (count($apiQues)) {
                    $quesIds = '';
                    $apiquesMarks = [];
                    foreach ($apiQues as $val) {
                        $quesIds .= $val['QUS_ID'] . ',';
                        $apiquesMarks[] = $val['QUS_MARK'];
                    }
                    $apiQuesIds['questionIds'] = substr($quesIds, 0, -1);
                }
                $apiQuesIds['pageType'] = 'searchFilter';
                /** In-case of stored API Question-id's and displayed with checked check-boxes. */
                if (!empty($apiQuesIds['questionIds'])) {
                    $testData['QUIZ_QUESTIONS'] = []; // a test might contain max 100 ques from API
                }
                /** Used to get all API question-id's at once. */
                $total_api_ques_ids = [];
                $getAllApiQuestion = (!count($quiz_lp_api_topics) && $test_type == 'ST') ? [] : [];
                if (!empty($getAllApiQuestion)) {
                    foreach ($getAllApiQuestion as $val) {
                        $total_api_ques_ids[] = $val['QUS_ID'] . '-API';
                    }
                }
                /** Used to get all Local question-id's at once. */
                $total_local_ques_ids = [];
                $getAllLocalQuestion = (!count($quiz_lp_topics) && $test_type == 'ST') ? [] : $createQuizTable->getAllQuestion($localSearchArr, $configFunction, true);
                if (!empty($getAllLocalQuestion)) {
                    foreach ($getAllLocalQuestion as $val) {
                        $total_local_ques_ids[] = $val['QUS_ID'] . '-LOCAL';
                    }
                }
                $viewModel->setVariables([
                    'step' => $step,
                    'testId' => $testId,
                    'title' => !empty($title) ? $title : '',
                    'questionsListing' => $questionsListing,
                    'questionsListingDB' => $questionsListingDB,
                    'allLocalQuesOfTest' => $allLocalQuesOfTest,
                    'start' => $start,
                    'testData' => $testData,
                    'testDataDB' => $testDataDB,
                    'questionCount' => !empty($questionCount['total_questions']['total_items']) ? $questionCount['total_questions']['total_items'] : 0,
                    'questionCountDB' => !empty($questionCountDB) ? $questionCountDB : 0,
                    'lastQusId' => $lastQusId,
                    'lpId' => $lpId,
                    'allQsnOfQuiz' => $allQsnOfQuiz,
                    'test_type' => $test_type,
                    'test_type' => $test_type,
                    'edit_from' => $edit_from,
                     'userSessionDetails' => $this->container->authDetail,
                    'getApiGrades' => $ccoGradeList,
                    'totalApiQuesIds' => $total_api_ques_ids,
                    'totalLocalQuesIds' => $total_local_ques_ids,
                    'quizLpTopics' => (count($quiz_lp_topics_array) && $test_type == 'ST') ? $quiz_lp_topics_array : [],
                    'quizLpApiTopics' => (count($quiz_lp_api_topics_array) && $test_type == 'ST') ? $quiz_lp_api_topics_array : [],
                    'test_create_mode' => $test_create_mode,
                ]);
            }
        }
        if ($step == 3) {
            $returnArr = array();
            $viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
            $configFunction = $viewHelperManager->get('repoconfig');
            $testDetail = $createQuizTable->fetchData('t_master_test', ['QUIZ_ID' => $testId], ['TEST_ID'], null, false);
            $testData = [];
            $apiQues = $createQuizTable->getAllApiQsnByTestId($testId);
            $apiQuesIds = [];
            $apiquesMarks = [];
            $questionsListingAPI = [];
            if (count($apiQues)) {
                $quesIds = '';
                $apiquesMarks = [];
                foreach ($apiQues as $val) {
                    $quesIds .= $val['QUS_ID'] . ',';
                    $apiquesMarks[] = $val['QUS_MARK'];
                    $apiquesOrder[] = $createQuizTable->getApiQuestionOrderByQusId($val['QUS_ID'], $testId);
                }
                $apiQuesIds['questionIds'] = substr($quesIds, 0, -1);
            }
            $apiQuesIds['pageType'] = 'review';
            $apiQuesIds['sortColumn'] = 't_mgr_test_question.QUS_ORDER';
            $apiQuesIds["sortType"] = 'ASC';
            $apiQuesIds['noLimit'] = true;
            if (!empty($apiQuesIds['questionIds'])) {
                $quesListingAPI = array(); // a test might contain max 100 ques from API 
                for ($q = 0; $q < count($quesListingAPI); $q++) {
                    $question = $quesListingAPI[$q];
                    $question['QUS_MARK'] = $apiquesMarks[$q];
                    $question['QUS_ORDER'] = $apiquesOrder[$q];
                    $questionsListingAPI[] = $question;
                }
            }
            unset($apiQuesIds['noLimit']);
            $allLocalQuesOfTest = $createQuizTable->getAllLocalQsnByTestId($testId);
            $dataCond = ['page' => $start, 'records' => $limit, 'quiz_id' => $testId];
            $testDataDB = $createQuizTable->getAllTestList($dataCond);
            if (!empty($testDataDB)) {
                foreach ($testDataDB as $key => $val) {
                    $returnArr[$key] = $val;
                    if ($val['QUIZ_QUESTION_IDS']) {
                        $array["QUS_IDS"] = $val['QUIZ_QUESTION_IDS'];
                        $array["QUZ_ID"] = $testId;
                        $array["sortColumn"] = 't_mgr_test_question.QUS_ORDER';
                        $array["sortType"] = 'ASC';
                        $array["QUS_REF_ID"] = 'Y';
                        $array["noLimit"] = true;
                        $Qsndata = $createQuizTable->getAllQuestion($array, $configFunction);
                        $qsnArr = array();
                        if (!empty($Qsndata)) {
                            foreach ($Qsndata as $key2 => $val2) {
                                $qsnArr[$key2] = $val2;
                            }
                            $returnArr[$key]['QUIZ_QUESTIONS'] = $qsnArr;
                        }
                    }
                }
                $returnArr['TOTAL_RECORDS'] = $createQuizTable->getAllTestCount(['quiz_id' => $testId]);
                unset($array["noLimit"]);
            }
            $questionsListingDB = (!empty($returnArr[0]['QUIZ_QUESTIONS'])) ? $returnArr[0]['QUIZ_QUESTIONS'] : [];
            $start = 0;
            if (count($questionsListingDB) == 0 && count($questionsListingAPI) == 0) {
                if ($lpId) {
                    return $this->redirect()->toRoute('test', array('controller' => 'test', 'action' => 'edit', 'id' => $testId, 'step' => '2'), ['query' => ['lpId' => $lpId, 'edit_from' => $edit_from]]);
                } else {
                    return $this->redirect()->toRoute('test', array('controller' => 'test', 'action' => 'edit', 'id' => $testId, 'step' => '2'), ['query' => ['test_type' => $test_type, 'edit_from' => $edit_from]]);
                }
            }
            $allQsnOfQuiz = $createQuizTable->getAllQsnByQuiz($testId);
            $viewModel->setVariables([
                'step' => $step,
                'testId' => $testId,
                'questionsListing' => $questionsListingAPI,
                'questionsListingDB' => $questionsListingDB,
                'start' => $start,
                'testData' => $testData,
                'testDataDB' => $testDataDB,
                'lpId' => $lpId,
                'allQsnOfQuiz' => $allQsnOfQuiz,
                'allLocalQuesOfTest' => $allLocalQuesOfTest,
                'questionCountDB' => 0,
                'test_type' => $test_type,
                'userSessionDetails' => $this->container->authDetail,
                'EDIT_FROM' => 'quiz',
                'test_create_mode' => $test_create_mode,
            ]);
        }
        if ($step == 4) {
            /**
             * This block being check that, this test contains any essay type question or not
             */
            // check with local question
            $allLocalQsnTypeOfQuiz = $createQuizTable->getAllLocalQsnTypeByTestId($testId);
            $isEssayTypeQuesExists = false;
            if (!empty($allLocalQsnTypeOfQuiz)) {
                foreach ($allLocalQsnTypeOfQuiz as $qus) {
                    if ($qus['QUS_TYPE'] == 1)
                        $isEssayTypeQuesExists = true;
                }
            }
            // check with api question, only if local questions does not have any single essay type ques
            if (!$isEssayTypeQuesExists) {
                $apiQues = $createQuizTable->getAllApiQsnByTestId($testId);
                $apiQuesIds = [];
                $quesListingAPI = [];
                if (count($apiQues)) {
                    $quesIds = '';
                    $apiquesMarks = [];
                    foreach ($apiQues as $val) {
                        $quesIds .= $val['QUS_ID'] . ',';
                    }
                    $apiQuesIds['questionIds'] = substr($quesIds, 0, -1);
                }
                if (!empty($apiQuesIds['questionIds'])) {
                    $quesListingAPI = []; // a test might contain max 100 ques from API
                }
                if (!empty($quesListingAPI)) {
                    foreach ($quesListingAPI as $qus) {
                        if ($qus['QUS_TYPE'] == 1)
                            $isEssayTypeQuesExists = true;
                    }
                }
            }
            /**
             * End Block
             */
            $dataCond = ['quiz_id' => $testId];
            $testDataDB = $createQuizTable->getAllTestList($dataCond);
            $questionCount = (!empty($selectedQue['QUIZ_QUESTIONS'])) ? count($selectedQue['QUIZ_QUESTIONS']) : 0;
            /* prepare data for displayed into form */
            $startDate = explode(' ', $testDataDB[0]['ASSIGN_DATE']);
            $endDate = explode(' ', $testDataDB[0]['END_DATE']);
            $testDataDB[0]['ASSIGN_DATE'] = isset($startDate[0]) ? $startDate[0] : '';
            $testDataDB[0]['START_TIME'] = isset($startDate[1]) ? $startDate[1] : '';
            $testDataDB[0]['END_DATE'] = isset($endDate[0]) ? $endDate[0] : '';
            $testDataDB[0]['END_TIME'] = isset($endDate[1]) ? $endDate[1] : '';
            $testDataDB[0]['CORRECTNESS'] = ($testDataDB[0]['CORRECTNESS'] == 0) ? 1 : $testDataDB[0]['CORRECTNESS'];
            $testDataDB[0]['PARTICIPATION'] = isset($testDataDB[0]['CORRECTNESS']) ? (1 - $testDataDB[0]['CORRECTNESS']) : null;
            /* end of prepared data */
            $qusCount = $testDataDB[0]['Total_Que'];
            $form = new \Test\Form\TestForm($translator);
            $form->setdata($testDataDB[0]);
            $viewModel->setVariables([
                'step' => $step,
                'testId' => $testId,
                'testData' => $testDataDB[0],
                'form' => $form,
                'qusCount' => $qusCount,
                'lpId' => $lpId,
                'test_type' => $test_type,
                'isEssayTypeQuesExists' => $isEssayTypeQuesExists,
                 'userSessionDetails' => $this->container->authDetail,
                'EDIT_FROM' => 'quiz',
                'test_type' => $test_type,
                'test_create_mode' => $test_create_mode,
            ]);
        }
        return $viewModel;
    }

    /**
     * @desc used for save test published data into DB and via API as well.
     * @return {array} with success/failure message
     */
    public function publishTestAction() {
        $config = $this->getConfig();
        $this->CommonClass()->setCustomLayout($this, 'backendLayout');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $translator = $this->getServiceLocator()->get('translator');
        $request = $this->getRequest();
        $data = $request->getPost()->toArray();
        $requestData = $request->getQuery()->toArray();
        $edit_from = !empty($data['edit_from']) ? $data['edit_from'] : null;
        $test_type = !empty($data['test_type']) ? $data['test_type'] : null;
        $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
        $CreateQuizForm = new TestForm($translator);
        $CreateQuizInputFilter = new TestInputFilter($data);
        $result = ['result' => false, 'message' => ''];
        if ($request->isXmlHttpRequest()) {
            $CreateQuizForm->setInputFilter($CreateQuizInputFilter->getInputFilter());
            if (!empty($data['Time_Limit'])) {
                $data['TIME_LIMIT_DURATION'] = empty($data['Time_Limit']) ? '00:00:00' : $data['TIME_LIMIT_DURATION'];
            }
            if (!empty($data['Allow_Multiple_Attempts'])) {
                $data['ALLOWED_ATTEMPT_NO'] = empty($data['Allowed_Attempt']) ? 0 : $data['ALLOWED_ATTEMPT_NO'];
            } else {
                $data['ALLOWED_ATTEMPT_NO'] = 1;
            }
            $this->setValidationFalse($data, $CreateQuizInputFilter);
            $CreateQuizForm->setData($request->getPost());
            if ($CreateQuizForm->isValid()) {
                if ((empty($data['TIME_LIMIT_DURATION']) || $data['TIME_LIMIT_DURATION'] == '00:00:00') && (!empty($data['Time_Limit']))) {
                    $result = ['result' => false, 'message' => ['TIME_LIMIT_DURATION' => ['isEmpty' => "Value is required and can't be empty"]]];
                    if (!$viewModel instanceof JsonModel && $request->isXmlHttpRequest()) {
                        $viewModel = new JsonModel();
                    }
                    $viewModel->setVariables(['data' => $result]);
                    return $viewModel;
                }
                if ($data['TEST_TYPE'] != 'PT') {
                    $data['ASSIGN_DATE'] = $data['ASSIGN_DATE'] . ' ' . $data['START_TIME'];
                    $data['END_DATE'] = $data['END_DATE'] . ' ' . $data['END_TIME'];
                } else {
                    $data['ASSIGN_DATE'] = $data['END_DATE'] = '';
                    $data['ALLOWED_ATTEMPT_NO'] = null;
                }
                if ($data['QUIZ_ID']) {
                    $createdBy = $this->container->authDetail['USER_OID'];
                    $quizDuration = $data['TIME_LIMIT_DURATION'];
                    /*                     * *************** (DO NOT REMOVED THIS CODE) code commented for to stop creation of test on Assessment Platform * */
//                    $updateDataApi = [
//                        'title' => $data['TITLE'],
//                        'instruction' => $data['INSTRUCTION'],
//                        'test_duration' => ($quizDuration == '00:00:00') ? "null" : $quizDuration,
//                        'quiz_score_keep' => $data['QUIZ_SCORE_KEEP'],
//                        'allowed_attempt' => !empty($data['ALLOWED_ATTEMPT_NO']) ? $data['ALLOWED_ATTEMPT_NO'] : 'null',
//                        'appearance' => 'SOQ',
//                        'start_date' => $data['ASSIGN_DATE'],
//                        'end_date' => $data['END_DATE'],
//                        'is_scratchpad' => $data['IS_SCRATCHPAD'],
//                        'grade_release' => $data['GRADE_RELEASE'],
//                        'correctness' => $data['CORRECTNESS'],
//                        'response_time' => !empty($data['RESPONSE_TIME']) ? $data['RESPONSE_TIME'] : 'null',
//                        'question_response_type' => $data['Quiz_Response'],
//                        'status' => 'A',
//                        'publish' => 'Y',
//                        'test_img' => "null",
//                        'updated_by' => $createdBy,
//                        'updated_on' => date('Y-m-d H:i:s'),
//                    ];
                    /*                     * *************** (DO NOT REMOVED THIS CODE) code commented for to stop creation of test on Assessment Platform * */
                    $updateDataDB = [
                        'TITLE' => $data['TITLE'],
                        'INSTRUCTION' => $data['INSTRUCTION'],
                        'TIME_LIMIT_DURATION' => ($quizDuration == '00:00:00') ? null : $quizDuration,
                        'QUIZ_SCORE_KEEP' => $data['QUIZ_SCORE_KEEP'],
                        'ALLOWED_ATTEMPT_NO' => $data['ALLOWED_ATTEMPT_NO'],
                        'APPEARANCE' => 'SOQ',
                        'ASSIGN_DATE' => $data['ASSIGN_DATE'],
                        'END_DATE' => $data['END_DATE'],
                        'IS_SCRATCHPAD' => $data['IS_SCRATCHPAD'],
                        'GRADE_RELEASE' => $data['GRADE_RELEASE'],
                        'CORRECTNESS' => $data['CORRECTNESS'],
                        'RESPONSE_TIME' => $data['RESPONSE_TIME'],
                        'Quiz_Response' => $data['Quiz_Response'],
                        'STATUS' => 'A',
                        'CUT_SCORE' => !empty($data['CUT_SCORE']) ? $data['CUT_SCORE'] : null,
                        'PUBLISH' => 'Y',
                        'UPDATED_BY' => $createdBy,
                        'UPDATED_ON' => date('Y-m-d H:i:s')
                    ];
                    // to do if image name found
                    if ($config['AWS_ENABLE']) {
                        if (!empty($data['TEST_IMG'])) {
                            $updateDataDB['TEST_IMG'] = $data['TEST_IMG'];
                            $this->uploadS3File($data['TEST_IMG'], 'TEST/');
                        }
                    }
                    //if(!empty($data['TEST_IMG'])){
                    /*                     * *************** (DO NOT REMOVED THIS CODE) code commented for to stop creation of test on Assessment Platform * */
//                        $updateDataApi['test_img'] = $data['TEST_IMG'];
                    /*                     * *************** (DO NOT REMOVED THIS CODE) code commented for to stop creation of test on Assessment Platform * */
                    // $updateDataDB['TEST_IMG'] = $data['TEST_FILE_PATH'];
                    // }
                    /** to get EXTERNAL TEST_ID from local DB */
                    /*                     * *************** (DO NOT REMOVED THIS CODE) code commented for to stop creation of test on Assessment Platform * */
                    //$testData = $createQuizTable->fetchData('t_master_test', ['QUIZ_ID' => $data['QUIZ_ID']], ['TEST_ID'], null, false);
                    //$externalTestId = $testData['TEST_ID'];
                    /** To Update data via API */
                    //$apiResponse = $this->getTestPlugin()->publishTest($updateDataApi, $externalTestId);
                    /*                     * *************** (DO NOT REMOVED THIS CODE) code commented for to stop creation of test on Assessment Platform * */
                    /** To Update data in Db if API updated data successfully */
                    //if ($apiResponse['status'] == 200) {
                    //$updateDataDB['TOTAL_QUES'] = $apiResponse['detail']['TOTAL_QUES'];
                    //$updateDataDB['TOTAL_MARKS'] = $apiResponse['detail']['TOTAL_MARKS'];
                    $createQuizTable->updateData('t_master_test', $updateDataDB, array('QUIZ_ID' => $data['QUIZ_ID']));
                    //}
                }
                $lpId = $data['lpId'];
                $subjectId = '';
                $redUrl = '';
                if ($lpId && empty($edit_from)) {
                    $redUrl = $this->returnBasePath() . "/grade/lesson-plan";
                    $subjectData = $createQuizTable->fetchData('t_cm_lessonplan_master', ['LESSONPLAN_ID' => $lpId], ['SUBJECT_ID'], null, false);
                    $subjectId = !empty($subjectData) ? $subjectData['SUBJECT_ID'] : "";
                } else if ($edit_from == 'quiz') {
                    $redUrl = $this->returnBasePath() . "/test/quiz";
                } else if ($test_type == 'ST' || $test_type == 'FT') {
                    $subjectData = $createQuizTable->fetchData('t_master_test', ['QUIZ_ID' => $data['QUIZ_ID']], ['SUBJECT_ID'], null, false);
                    $subjectId = !empty($subjectData) ? $subjectData['SUBJECT_ID'] : "";
                    $redUrl = $this->returnBasePath() . "/grade/lesson-plan/" . $subjectId;
                } else {
                    $redUrl = $this->returnBasePath() . '/test/quiz';
                }                
                $result = ['result' => true, 'redirectUrl' => $redUrl, 'lpId' => $lpId, 'subjectId' => $subjectId];
            } else {
                $result = ['result' => false, 'message' => $CreateQuizForm->getMessages()];
            }
            if (!$viewModel instanceof JsonModel && $request->isXmlHttpRequest()) {
                $viewModel = new JsonModel();
            }
            $viewModel->setVariables(['data' => $result]);
            return $viewModel;
        }
    }

    /**
     * @desc used of this function for set validation false if dependent check box is un-check
     * @param array $data
     * @param obj $CreateQuizInputFilter
     */
    private function setValidationFalse($data, $CreateQuizInputFilter) {
        if (!empty($data['Allow_Multiple_Attempts'])) {
            $CreateQuizInputFilter->getInputFilter()->get('QUIZ_SCORE_KEEP')->setRequired(true);
        }
        if (!empty($data['Allowed_Attempt'])) {
            $CreateQuizInputFilter->getInputFilter()->get('ALLOWED_ATTEMPT_NO')->setRequired(true);
        }
        if (!empty($data['Time_Limit'])) {
            $CreateQuizInputFilter->getInputFilter()->get('TIME_LIMIT_DURATION')->setRequired(false);
        }
        if (isset($data['TEST_TYPE']) && $data['TEST_TYPE'] == 'PT') {
            $CreateQuizInputFilter->getInputFilter()->get('CUT_SCORE')->setRequired(false);
            $CreateQuizInputFilter->getInputFilter()->get('ASSIGN_DATE')->setRequired(false);
            $CreateQuizInputFilter->getInputFilter()->get('START_TIME')->setRequired(false);
            $CreateQuizInputFilter->getInputFilter()->get('END_DATE')->setRequired(false);
            $CreateQuizInputFilter->getInputFilter()->get('END_TIME')->setRequired(false);
            $CreateQuizInputFilter->getInputFilter()->get('ALLOWED_ATTEMPT_NO')->setRequired(false);
            $CreateQuizInputFilter->getInputFilter()->get('QUIZ_SCORE_KEEP')->setRequired(true);
        }
    }

    function openPopupAction() {
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $requestData = $this->getRequest()->getQuery()->toArray();
        $deltype = '';
        if (!empty($requestData['deleteAction']) && $requestData['deleteAction'] == 'delete_content') {
            $deltype = 'file';
        }
        $viewModel = $this->CommonClass()->openPopUp($viewModel, $requestData);
        $translator = $this->getServiceLocator()->get('translator');
        $dbadapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
        $file = $requestData['file'];
        switch ($file) {
            case "popup/add-test":
                $viewModel->setVariables([]);
                break;
            case 'popup/popup_delete_confirmation':
                $viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
                $questionHelper = $viewHelperManager->get('QuestionPreviewHelper');
                $testId = !empty($requestData['id']) ? $requestData['id'] : '';
                $level_id = !empty($requestData['PLC_LEVEL_ID']) ? $requestData['PLC_LEVEL_ID'] : '';
                $resultstatus = true;
                $openstatus = true;
                if ($level_id) {
                    $openstatus = $questionHelper->getNextTestAndLevelId($level_id);
                    $resultstatus = $questionHelper->isAttempted($testId, $level_id);
                } else {
                    $resultstatus = $questionHelper->isAttempted($testId);
                }
                $viewModel->setVariables(['result' => $resultstatus, 'deltype' => $deltype, 'openStatus' => $openstatus]);
                break;
            case 'popup/popup_test_type':
                //$countryList = $this->getCountries();
                $userId = $this->container->authDetail['USER_OID'];
                $orgId = $this->container->authDetail['ORG_ID'];
                $utId = $this->container->authDetail['UT_ID'];
                $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
                $gradeList = [];
                if ($utId == 2) {
                    $gradeList = $createQuizTable->getGradesByUserId($userId);
                } else {
                    $gradeList = $createQuizTable->getGradesForAdmin($orgId);
                }
                $form = new \Test\Form\TestTypeForm($gradeList, $translator);
                $viewModel->setVariables(array(
                    'form' => $form
                ));
                break;
        }
        return $viewModel;
    }

    /**
     * @desc used of this function for delete whole quiz from local DB & from API
     * @return json message
     */
    public function deleteDataAction() {
        $request = $this->getRequest();
        if ($request->isXmlHttpRequest()) {
            $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
            $viewModel->setTerminal(true);
            $requestData = $request->getQuery()->toArray();
            $ID = $requestData['ID'];
            $deleteAction = $requestData['deleteAction'];
            $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
            $testDetail = $createQuizTable->fetchData('t_master_test', ['QUIZ_ID' => $ID], ['TEST_ID', 'TEST_IMG'], null, false);
            $externalTestId = $testDetail['TEST_ID'];
            $isDeleted = 0;
            if ($deleteAction == 'delete_quiz') {
                /** API Delete Code here */
                //$isApiTestDeleted = $this->getTestPlugin()->deleteTestById($ID);
                /** if success then run following code to delete from local DB */
                //if ($isApiTestDeleted['status'] == 200) {
                $createQuizTable->deleteQuizRecord($ID);
                $isDeleted = 1;
                //}
            }
            if ($deleteAction == 'delete_quiz_gt') {
                $conditions = array('QUIZ_ID' => $ID);
                $Data = $createQuizTable->fetchData('t_master_test', $conditions, array('CONT_ID'), '', false);
                $createQuizTable->deleteQuizRecord($ID);
                $createQuizTable->deleteContent($Data['CONT_ID']);
                $isDeleted = 1;
                //}
            }
            /** use to delete uploaded test file from S3 and update in local DB and in Assessment via API */
            if ($deleteAction == 'delete_content') {
                /* if(!empty($testDetail['TEST_IMG'])){
                  $break = explode('/', $testDetail['TEST_IMG']);
                  $requestData['filename'] = $break[count($break) - 1];
                  } */
                //$requestData['delete_type'] = 'test';
                /** API to Delete file, Code here */
                //$isApiTestFileDeleted = $this->getTestPlugin()->deleteFileById($externalTestId, $requestData);
                /** if success then run following code to update on local DB */
                //if ($isApiTestFileDeleted['status'] == 200) {
                $createQuizTable->updateData('t_master_test', ['TEST_IMG' => null], ['QUIZ_ID' => $ID]);
                $isDeleted = 1;
                //}
            }
            $jsonModel = new JsonModel();
            $jsonModel->setVariables(array(
                'result' => $isDeleted
            ));
            return $jsonModel;
        }
    }

    /**
     * @desc used of this action for save data to t_mgr_test_question table
     */
    public function addQsnToTest2Action() {
        $request = $this->getRequest();
        $postData = $request->getPost()->toArray();
        $htmlViewPart = new ViewModel();
        $htmlViewPart->setTerminal(true);
        $QUZ_ID = $this->params('id');
        if (!empty($postData['allQuestions'])) {
            $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
            $allQuestions = substr($postData['allQuestions'], 0, -1);
            $allQuestionsArr = explode(",", $allQuestions);
            foreach ($allQuestionsArr as $quesId) {
                if (strpos($quesId, 'API') !== false) {
                    $ques_ids[] = str_replace('-API', '', $quesId);
                } else {
                    $ques_ids[] = str_replace('-LOCAL', '', $quesId);
                }
            }
            $data = $createQuizTable->addQsnToTest2(["quz_id" => $QUZ_ID, "qus_ids" => $ques_ids, 'qus_ids_with_source' => $allQuestionsArr]);
        }
        $array['result'] = 1;
        echo json_encode($array);
        die;
    }

    /**
     * @desc used of this action for save API/LOCAL question(s) to t_mgr_test_question table.
     */
    public function addQsnToTestAction() {
        $request = $this->getRequest();
        $postData = $request->getPost()->toArray();
        $htmlViewPart = new ViewModel();
        $htmlViewPart->setTerminal(true);
        $QUZ_ID = $this->params('id');
        $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
        /** Single/Multiple Question(s) ADD case only. */
        if (!empty($postData['allQuestions'])) {
            $allQuestions = substr($postData['allQuestions'], 0, -1);
            $allQuestionsArr = explode(",", $allQuestions);
            $quesFromApis = [];
            $quesFromLocaldb = [];
            $quizStoredData = [];
            /** Get all Stored Question(s) in DB to match current Question(s) */
            if (!empty($QUZ_ID)) {
                $quizStoredDataArray = $createQuizTable->fetchData('t_mgr_test_question', ["QUZ_ID" => $QUZ_ID], ['QUS_ID']);
                foreach ($quizStoredDataArray as $quizData) {
                    $quizStoredData[] = $quizData['QUS_ID'];
                }
            }
            foreach ($allQuestionsArr as $quesId) {
                /** Single ADD & DELETION of API question. */
                if (strpos($quesId, 'API') !== false) {
                    $current_api_ques_id = str_replace('-API', '', $quesId);
                    /** Skip API current Question into array after DELETE from DB. */
                    if ($postData['action'] == 'DELETE') {
                        $createQuizTable->deleteData('t_mgr_test_question', ["QUZ_ID" => $QUZ_ID, "QUS_ID" => $current_api_ques_id]);
                        continue;
                    }
                    /** Skip API current Question into array if this one already stored in DB. */
                    if (count($quizStoredData) && in_array($current_api_ques_id, $quizStoredData)) {
                        continue;
                    }
                    $quesFromApis[] = $current_api_ques_id;
                } else {
                    /** Single ADD & DELETION of API question. */
                    $current_local_ques_id = str_replace('-LOCAL', '', $quesId);
                    /** Skip LOCAL current Question into array after DELETE from DB. */
                    if ($postData['action'] == 'DELETE') {
                        $createQuizTable->deleteData('t_mgr_test_question', ["QUZ_ID" => $QUZ_ID, "QUS_ID" => $current_local_ques_id]);
                        continue;
                    }
                    /** Skip LOCAL current Question into array if this one already stored in DB. */
                    if (count($quizStoredData) && in_array($current_local_ques_id, $quizStoredData)) {
                        continue;
                    }
                    $quesFromLocaldb[] = $current_local_ques_id;
                }
            }
            /** Multiple ADD and Delete from LOCAL Tab. */
            if (!empty($quesFromLocaldb)) {
                if ($postData['action'] == 'ADD') {
                    $createQuizTable->addQsnToTest(["quz_id" => $QUZ_ID, "qus_ids" => $quesFromLocaldb], false);
                } else {
                    $createQuizTable->deleteData('t_mgr_test_question', ["QUZ_ID" => $QUZ_ID, "QUS_ID" => $quesFromLocaldb]);
                }
            }
            /** Multiple ADD and Delete from API Tab. */
            if (!empty($quesFromApis)) {
                if ($postData['action'] == 'ADD') {
                    $createQuizTable->addQsnToTest(["quz_id" => $QUZ_ID, "qus_ids" => $quesFromApis], true);
                } else {
                    $createQuizTable->deleteData('t_mgr_test_question', ["QUZ_ID" => $QUZ_ID, "QUS_ID" => $quesFromApis]);
                }
            }
        }
        /** Get displayed Question count after ADD/Delete. */
        if (!empty($QUZ_ID)) {
            $countData = $createQuizTable->countData('t_mgr_test_question', ["QUZ_ID" => $QUZ_ID]);
        }
        $array['result'] = 1;
        $array['data_count'] = $countData;
        echo json_encode($array);
        die;
    }

    /**
     * @desc used of this function for save pull qustion
     */
    public function savePullAction() {
        $PullQusForm = new \Test\Form\PullQusForm();
        $PullQusInputFilter = new \Test\Model\PullQusInputFilter();
        $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
        $result = ['result' => false, 'message' => ''];
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $request = $this->getRequest();
        $requestData = $this->getRequest()->getQuery()->toArray();
        $lpId = isset($requestData['lpId']) ? $requestData['lpId'] : '';
        $edit_from = isset($requestData['edit_from']) ? $requestData['edit_from'] : '';
        $test_create_mode = isset($requestData['test_create_mode']) ? $requestData['test_create_mode'] : '';
        $errorMessage = "Value is required and can't be empty";
        if ($request->isXmlHttpRequest()) {
            $data = $request->getPost()->toArray();
            $viewModel->setTerminal(true);
            $conditions = array('QUIZ_ID' => $data['QUZ_ID'][0]);
            $populateData = $createQuizTable->fetchData('t_master_test', $conditions, array('*'), '', false);
            $externalTestId = !empty($populateData['TEST_ID']) ? $populateData['TEST_ID'] : '';
            $orderCount = 1;
            $noOfQus = 0;
            $dataUpdate = [];
            $qusIdArr = [];
            $qusMarkArr = [];
            $qusOrder = [];
            foreach ($data['QUS_ID'] as $QUSIDK => $QUSIDV) {
                // first update marks in local db
                $updateData = ['QUS_MARK' => $data['QUS_MARK'][$QUSIDK], 'QUS_ORDER' => $orderCount];
                $createQuizTable->updateMark($updateData, $data['QUZ_ID'], $QUSIDV);
                $noOfQus = $noOfQus + $data['QUS_MARK'][$QUSIDK];
                /*                 * *************** (DO NOT REMOVED THIS CODE) code commented for to stop creation of test on Assessment Platform * */
                // then update marks on api
                //$quesRefId = $createQuizTable->fetchData('t_mgr_test_question', ['QUS_ID' => $QUSIDV, 'QUZ_ID' => $data['QUZ_ID']], ['QUS_REF_ID'], null, false);
                //if ($quesRefId->QUS_REF_ID) {
                //    $dataUpdate = array();
                //    $dataUpdate['qus_ids'] = $quesRefId->QUS_REF_ID;
                //    $dataUpdate['qus_marks'] = $data['QUS_MARK'][$QUSIDK];
                //    $dataUpdate['qus_orders'] = $orderCount;
                //    $dataUpdate['TEST_ID'] = $externalTestId;
                //    $response = $this->getTestPlugin()->addQsnToTest($dataUpdate, "PUT");
                //}
                /*                 * *************** (DO NOT REMOVED THIS CODE) code commented for to stop creation of test on Assessment Platform * */
                $orderCount++;
            }
            if (!empty($edit_from)) {
                $str = "&edit_from=" . $edit_from;
            } else {
                $str = "";
            }
            if (!empty($test_create_mode)) {
                $str1 = "&test_create_mode=" . $test_create_mode;
            } else {
                $str1 = "";
            }
            if ($lpId) {
                $result['redirectUrl'] = $this->getRequest()->getBasePath() . '/test/edit/' . $data['QUZ_ID'][0] . '/4?lpId=' . $lpId . $str;
            } else {
                $result['redirectUrl'] = $this->getRequest()->getBasePath() . '/test/edit/' . $data['QUZ_ID'][0] . '/4?edit_from=' . $edit_from . $str1;
                if ($requestData['test_type']) {
                    $result['redirectUrl'] .= "&test_type=" . $requestData['test_type'];
                }
            }
        }
        $jsonModel = new JsonModel();
        $jsonModel->setVariables($result);
        return $jsonModel;
    }

    /**
     * @Desc To upload temp
     * @return Json encoded file data
     */
    public function uploadTempAction() {
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $viewModel->setTerminal(true);
        $request = $this->getRequest();
        $fileArray = $request->getFiles()->toArray();
        $path = $fileArray['file']['name'];
        $ext = pathinfo($path, PATHINFO_EXTENSION);
        $time = time();
        $fileName = $time . '.' . $ext;
        $fileArray['file']['name'] = $fileName;
        $movefile = move_uploaded_file($fileArray['file']['tmp_name'], getcwd() . "/public/upload/" . $fileName);
        $filedetails['path'] = $this->returnBasePath() . "/upload/" . $fileName;
        $filedetails['BACKING_FILE'] = $fileName;
        $filedetails['FILE_ARRAY'] = json_encode($fileArray);
        echo json_encode($filedetails);
        die;
    }

    /**
     * @Desc To upload temp image image directly to S3 Server via API.
     * @return Json encoded file data
     */
    public function uploadSummernoteImageAction() {
        $config = $this->getServiceLocator()->get('config');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $viewModel->setTerminal(true);
        $request = $this->getRequest();
        $fileArray = $request->getFiles()->toArray();
        $postRequest = $request->getPost()->toArray();
        $path = $fileArray['file']['name'];
        $ext = pathinfo($path, PATHINFO_EXTENSION);
        $fileName = time() . '.' . $ext;
        $fileArray['file']['name'] = $fileName;
        $type = strtolower(end(explode('.', $fileName)));
        $formid = $this->params('id');
        $formname = $config['QUES_TYPE_URL'][$formid];
        $movefile = move_uploaded_file($fileArray['file']['tmp_name'], getcwd() . "/public/upload/" . $fileName);
        $filedata = 'data:image/' . $type . ';base64,' . base64_encode(file_get_contents($this->returnBasePath() . "/upload/" . $fileName));
        $requestParameters = ['questype' => 50, 'filename' => $fileName, 'filedata' => $filedata];
        $filedetails = $this->httpRequestToApi($config['ASSESSMENT_API_URL'] . $config['test-api']['fileupload'], $requestParameters, $fileArray, $formname);
        $filedetails = json_decode($filedetails, true);
        echo json_encode($filedetails);
        die;
    }

    /**
     * @desc Save Cropped Image	
     */
    public function saveCropedImgAction() {
        if (!empty($_POST['FILE_ARRAY']) && !empty($_POST['formName']) && !empty($_POST['fileName'])) {
            $targ_w = (empty($_POST['targ_w'])) ? 750 : $_POST['targ_w'];
            $targ_h = (empty($_POST['targ_h'])) ? 421 : $_POST['targ_h'];
            $jpeg_quality = 95;
            $targetDir = "public/upload/";
            $src = $targetDir . $_POST['fileName'];
            $name = $_POST['fileName']; //"file_" . time();
            $fileName = $name;  //. "." . end(explode('.', $_POST['fileName']));
            $thumb = $targetDir . $name;
            $type = strtolower(end(explode('.', $_POST['fileName'])));
            if ($type == 'jpeg' || $type == 'jpg') {
                $img_r = imagecreatefromjpeg($src);
                $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
                imagecopyresampled($dst_r, $img_r, 0, 0, $_POST['x'], $_POST['y'], $targ_w, $targ_h, $_POST['w'], $_POST['h']);
                imagejpeg($dst_r, $thumb, $jpeg_quality);
            } else if ($type == 'gif') {
                $img_r = imagecreatefromgif($src);
                $dst_r = imagecreatetruecolor($targ_w, $targ_h);
                imagecopyresampled($dst_r, $img_r, 0, 0, $_POST['x'], $_POST['y'], $targ_w, $targ_h, $_POST['w'], $_POST['h']);
                imagegif($dst_r, $thumb, $jpeg_quality);
            } else if ($type == 'png') {
                $img_r = imagecreatefrompng($src);
                $dst_r = imagecreatetruecolor($targ_w, $targ_h);
                /* Added to prevent black bg for png images */
                imagealphablending($dst_r, false);
                imagesavealpha($dst_r, true);
                $transparent = imagecolorallocatealpha($dst_r, 255, 255, 255, 127);
                imagefilledrectangle($dst_r, 0, 0, $targ_w, $targ_h, $transparent);
                /* ---- */
                @imagecopyresampled($dst_r, $img_r, 0, 0, $_POST['x'], $_POST['y'], $targ_w, $targ_h, $_POST['w'], $_POST['h']);
                imagepng($dst_r, $thumb);
            }
            $dataPath = $this->returnBasePath() . "/upload/" . $fileName;
            $filePath = getcwd() . '/public/upload/' . $fileName;
            chmod($filePath, 0777);
            $ret = ['BACKING_FILE' => $fileName, 'status' => true, 'fullPath' => $dataPath];
            echo json_encode($ret);
            /* --For Api image upload-- */
            /* $fileArray = json_decode($_POST['FILE_ARRAY'], true);
              $config = $this->getServiceLocator()->get('config');
              $formname = $_POST['formName'];
              $filedata = 'data:image/' . $type . ';base64,' . base64_encode(file_get_contents($this->returnBasePath() . "/upload/" .$_POST['fileName']));
              $requestParameters = ['questype' => 50, 'filename' => $fileName, 'filedata' => $filedata];
              $filedetails  = $this->httpRequestToApi($config['ASSESSMENT_API_URL'].$config['test-api']['fileupload'], $requestParameters, $fileArray, $formname);
              $filedetails = json_decode($filedetails, true);
              $filedetails['BACKING_FILE'] = $fileName;
              $filedetails['status'] = true;
              $filedetails['dataPath'] = $dataPath;
              unlink($src);
              echo json_encode($filedetails); */
            die;
        }
    }

    /**
     * @desc  Used to upload file on S3, using Assessment 'fileupload' API.
     * @param array $file
     * @param string $formname
     * @dev Rizban Ahmad
     * @author  Piron Corporation
     * @return array
     */
    public function httpRequestToApi($url, $requestData, $file, $formname) {
        ini_set('max_execution_time', 0);
        ini_set('memory_limit', '20480M');
        $client = new Client(null, ['timeout' => 1200]);
        $config = $this->getServiceLocator()->get('config');
        $postData = $requestData;
        $client->setUri($url);
        $client->setMethod('POST');
        $client->setParameterPOST($postData);
        foreach ($file as $k => $f) {
            if (!empty($f['name'])) {
                $ext = pathinfo($f['name'], PATHINFO_EXTENSION);
                if (in_array($ext, array('jpg', 'png', 'gif', 'jpeg', 'svg', 'mp4', 'mp3'))) {
                    $content_tmpname = $f['tmp_name'];
                    $content_filename = $f['name'];
                    $contentfileData = file_get_contents($content_tmpname);
                    $client->setFileUpload($content_filename, $formname, $contentfileData);
                }
            }
        }
        $response = $client->send();
        $body = $response->getBody();
        $response = $this->getResponse();
        $response->setContent($body);
        return $response->getBody();
    }

    /**
     * @desc used of this function for delete pulled question while creating new Test via API.
     * @vars {integer} $quizQusId | used for getting QUIZ_QUS_ID required for delete a test's question.
     * @return {json} message.
     */
    public function deletePullQuesAction() {
        $request = $this->getRequest();
        $translator = $this->getServiceLocator()->get('translator');
        if ($request->isXmlHttpRequest()) {
            $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
            $viewModel->setTerminal(true);
            $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
            $postData = $request->getPost()->toArray();
            $quizId = $postData['quizId'];
            $qusId = $postData['qusId'];
            $quizQusId = $postData['quizQusId'];
            //echo $quizId.'<pre />'.$qusId.'<pre />'.$quizQusId.'<pre />'; die('macrocc');
            // first check that this question exists in local db or API
            $QUS_REF_IDS = $createQuizTable->fetchData('t_mgr_test_question', array('QUS_ID' => $qusId, 'QUZ_ID' => $quizId), array('QUZ_QUS_ID', 'QUS_REF_ID'));
            // echo '<pre />'; print_r($QUS_REF_IDS); die('macro');
            if (!empty($QUS_REF_IDS)) {
                foreach ($QUS_REF_IDS as $ids) {
                    if (!empty($ids['QUS_REF_ID'])) {
                        /** Delete linked question with Test via API. */
                        $deleteResponse = []; //$quizQusId
                        /** Delete question from Local Db * */
                        $isDeleted = $createQuizTable->deleteRecord($quizId, $qusId, $ids['QUZ_QUS_ID']);
                    } else {
                        /** Delete question from Local Db * */
                        $isDeleted = $createQuizTable->deleteRecord($quizId, $qusId, $ids['QUZ_QUS_ID']);
                    }
                }
            }
            $jsonModel = new JsonModel();
            $jsonModel->setVariables(array(
                'result' => $translator->translate('Record deleted succesfully.')
            ));
            return $jsonModel;
        }
    }

    /**
     * @desc Use of this action for get grades and levels
     */
    public function getLevelRequestAction() {
        $html = '';
        $translator = $this->getServiceLocator()->get('translator');
        $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
        $request = $this->getRequest();
        $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
        $postData = $this->getRequest()->getPost()->toArray();
        if ($request->isPost() && $request->isXmlHttpRequest()) {
            $viewModel->setTerminal(true);
            $grade_id = $postData['id'];
            $request_type = $postData['request_type'];
            if ($request_type === 'getLevels') {
                $data['grade'] = (!empty($grade_id)) ? trim($grade_id) : null;
                $orgId = $this->container->authDetail['ORG_ID'];
                $getAdmin = $createQuizTable->fetchData('t_usr_user', ['ORG_ID' => $orgId, 'UT_ID' => 5], ['USER_OID']);
                //print_r($getAdmin);
                foreach ($getAdmin as $admin) {
                    $userId[] = $admin['USER_OID'];
                }
                $getDataArray = $createQuizTable->getLevelByGradeId($data['grade'], $userId);
                //print_r($getDataArray); 
                $lastPLcId = $createQuizTable->getLastTestPlcID($data['grade']);
                $lastPlcDetail = $createQuizTable->getLastTestPlcID($data['grade']);
                $lastPLPosition = 0;
                if ($lastPLcId) {
                    foreach ($getDataArray as $val2) {
                        if ($val2['PLC_LEVEL_ID'] == $lastPLcId) {
                            $lastPLPosition = $val2['PLC_POSITION'];
                        }
                    }
                }
                //print_r($lastPLcId); die($lastPLPosition);
                $html = '<option value="">' . $translator->translate('Select Level') . '</option>';
                $count = 0;
                $check = 1;
                foreach ($getDataArray as $key => $val) {
                    if ($check) {
                        if (!empty($lastPLcId) && $lastPLcId && $lastPLPosition) {
                            if ($val['PLC_POSITION'] > $lastPLPosition) {
                                $PLC_LEVEL_ID = $val['PLC_LEVEL_ID'];
                                $check = 0;
                            } else {
                                $PLC_LEVEL_ID = $val['PLC_LEVEL_ID'];
                            }
                        } else {
                            $PLC_LEVEL_ID = $val['PLC_LEVEL_ID'];
                            $check = 0;
                        }
                    } else {
                        $PLC_LEVEL_ID = '-1';
                    }
                    /*
                      $data = $this->isExistLevelAction($val['PLC_LEVEL_ID']);
                      if ($data == 0) {
                      $count++;
                      }
                      if ($data == 0 && $count == 1) {
                      // send correct id
                      // echo "enable" . "\n";
                      $PLC_LEVEL_ID = $val['PLC_LEVEL_ID'];
                      } else if ($data > 1) {
                      //send blank ID
                      //echo "enable" . "\n";
                      $PLC_LEVEL_ID = $val['PLC_LEVEL_ID'];
                      } else {
                      //echo "disable" . "\n";
                      if($data == 0){
                      $PLC_LEVEL_ID = $val['PLC_LEVEL_ID'];
                      }else{
                      $PLC_LEVEL_ID ='-1';
                      }
                      } */
                    $html .= '<option value="' . $PLC_LEVEL_ID . '">' . $val['LEVEL'] . '</option>';
                }
            }
        }
        echo $html;
        die;
    }

    public function isExistLevelAction($levelId) {
        $translator = $this->getServiceLocator()->get('translator');
        $request = $this->getRequest();
        $postData = $request->getPost();
        $levelId = (!empty($levelId)) ? $levelId : 0;
        $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
        return $data = $createQuizTable->isExistPlLevel($levelId);
//        if($data > 0){
//            $result = ['success'=>'false', 'message'=>$translator->translate('Test is already created.')];
//        }else{
//            $result = ['success'=>'success'];
//        }
//        $jsonModel = new JsonModel();
//        $jsonModel->setVariables($result);
//        return $jsonModel;
    }

    /**
     * @desc Use of this function for get all grades by school from Local.
     * @return array
     */
    public function getGradesLocal($cco = null) {
        $teacherid = $this->container->authDetail['USER_OID'];
        $questionTable = $this->initTable('Assessment\Model\QuestionTable');
        $curriculumTable = $this->initTable('Curriculum\Model\CurriculumTable');
        $translator = $this->getServiceLocator()->get('translator');
        $orgId = $this->container->authDetail['ORG_ID'];
        $utid = $this->container->authDetail['UT_ID'];
        if (empty($cco)) {
            if ($utid == 2) {
                $subjects = $curriculumTable->getAssignSubjectById($teacherid);
                if (empty($subjects)) {
                    $subjects = [0];
                }
                $join[] = ['t_cm_mgr_grade', 't_cm_mgr_grade.GRADE_ID = t_cm_mgr_subject.GRADE_ID'];
                $getAllgrades = $questionTable->fetchData('t_cm_mgr_subject', ['t_cm_mgr_subject.SUBJECT_ID' => $subjects], ['*'], '', true, '', '', '', '', '', '', $join);
            } else {
                $getAllgrades = $questionTable->fetchData('t_cm_mgr_grade', ['ORG_ID' => $orgId], ['*']);
            }
            $result = ['' => $translator->translate('Select Grade')];
            if (count($getAllgrades)) {
                if (empty($cco)) {
                    foreach ($getAllgrades as $grade_data) {
                        $result[$grade_data['GRADE_ID']] = $grade_data['GRADE_NAME'];
                    }
                }
            }
        } else {
            $result = ['' => $translator->translate('Select Grade')];
            $config = $this->serviceLocator->get('config');
            $this->dropDownApiUrl = $config['CCO_URL'];
            $selected_id = 1;
            //standard id start 
            //$dataArray = $this->apiCall()->getCcoGradeList($this->container->authDetail['PROJECT_UUID']);
            $dataArray = array();
            if (empty($this->container->authDetail['PROJECT_UUID'])) {
                $dataArray = array();
            }
            $standardid = (!empty($dataArray[0]["STANDARD_ID"])) ? $dataArray[0]["STANDARD_ID"] : "";
            //standard id end 
            //$response = $this->HttpClientRequest()->clientRequest($this->dropDownApiUrl . '/api/standard?standardId=' . $standardid . '&flag=1', '', 'GET');
            // $html = '<option value="">' . $translator->translate('Grade') . '</option>';
            /* if ($response->isSuccess()) {
              $grades = json_decode($response->getBody(), true);
              if(count($grades['detail'])){
              foreach ($grades['detail'] as $data) {
              $result[$data['GRADE_ID']] = $data['GRADE_Name'];
              //   $html .= '<option value="' . $data['GRADE_ID'] . '">' . $data['GRADE_Name'] . '</option>';
              }
              }
              } */
        }
        return $result;
    }

    public function getAutomativeTestFilterDataAction() {
        $request = $this->getRequest();
        if ($request->isXmlHttpRequest()) {
            $questionMark = $questionCount = 0;
            $total_local_ques_ids = '';
            $apiQuesLimit = $localQuesLimit = 1000;
            $localTopicIds = $question_types = $api_cognitive_dropdowns = $difficulty_levels = $ques_ids_with_api = $ques_ids_without_api = [];
            $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
            $viewModel->setTerminal(true);
            $createQuizTable = $this->initTable('Test\Model\CreateQuizTable');
            $postData = $request->getPost()->toArray();
            $userId = $this->container->authDetail['USER_OID'];
            $utId = $this->container->authDetail['UT_ID'];
            $topicArr = [0];
            $gradeArr = [0];
            $subjectArr = [0];
            if ($utId == 5) { // for admin
                $grades = [];
                $grades = $createQuizTable->fetchData('t_cm_mgr_grade', array('ORG_ID' => $this->container->authDetail['ORG_ID']), array('GRADE_ID'));
                foreach ($grades as $grade) {
                    $gradeArr[] = $grade["GRADE_ID"];
                }
                $subjects = $createQuizTable->fetchData('t_cm_mgr_subject', ['GRADE_ID' => $gradeArr], ['SUBJECT_ID']);
                foreach ($subjects as $subject) {
                    $subjectArr[] = $subject["SUBJECT_ID"];
                }
                $topics = $createQuizTable->fetchData('t_cm_mgr_curriculum_outline', ['SUBJECT_ID' => $subjectArr], ['CAT_ID', 'ADM_REF_ID']);
                if (!empty($topics)) {
                    foreach ($topics as $topic) {
                        $topicArr[] = $topic["CAT_ID"];
                    }
                }
            } else if ($utId == 2) {
                $subjects = $createQuizTable->getAssignSubjectById($userId);
                if (count($subjects) == 0) {
                    $subjects = [0];
                }
                $topics = $questionTable->fetchData('t_cm_mgr_curriculum_outline', ['SUBJECT_ID' => $subjects], ['CAT_ID', 'ADM_REF_ID']);
                if (!empty($topics)) {
                    foreach ($topics as $topic) {
                        $topicArr[] = $topic["CAT_ID"];
                    }
                }
            }
            $questionCountWithAPi = $questionCountWithoutApi = $questionMarkWithAPi = $questionMarkWithoutApi = 0;
            if (!empty($postData['topic'])) {
                $topicArray = explode(',', rtrim($postData['topic'], ','));
                foreach ($topicArray as $topicId) {
                    if (strpos($topicId, 'LOCAL') !== false) {
                        $localTopicIds[] = str_replace('-LOCAL', '', $topicId);
                    }
                }
            } else {
                if (!empty($postData['question_type']) || !empty($postData['difficulty_level']) || !empty($postData['api_cognitive_dropdown']) || !empty($postData['question_number'])) {
                    $localTopicIds = $topicArr;
                }
            }
            /** Searching Criteria for LOCAL requests. */
            if (!empty($localTopicIds)) {
                if (!empty($postData['question_type'])) {
                    $question_types = explode(',', rtrim($postData['question_type'], ','));
                }
                if (!empty($postData['difficulty_level'])) {
                    $difficulty_levels = explode(',', rtrim($postData['difficulty_level'], ','));
                }
                if (!empty($postData['api_cognitive_dropdown'])) {
                    $api_cognitive_dropdowns = explode(',', rtrim($postData['api_cognitive_dropdown'], ','));
                }
                /**
                 * if user ask for limited number of question for different question types like essay type 5, fill in blank type 4 etc
                 */
                if (!empty($postData['question_number'])) {
                    $question_numbers = explode(',', rtrim($postData['question_number'], ','));
                    for ($i = 0; $i < count($question_types); $i++) {
                        $localSearchArr = array(
                            'topicId' => $localTopicIds,
                            'qnsType' => $question_types[$i],
                            'cognitiveId' => $api_cognitive_dropdowns,
                            'difficultyLevel' => $difficulty_levels,
                            'localQuesLimit' => $question_numbers[$i],
                        );
                        /** Total count for Questions from LOCAL. */
                        $questionsListDB = $createQuizTable->getAllQuestion($localSearchArr, '', true, true);
                        $questionCountWithoutApi += count($questionsListDB);
                        foreach ($questionsListDB as $val) {
                            $ques_ids_without_api[] = $val['QUS_ID'] . '-LOCAL';
                            $questionMarkWithoutApi += $val['QUES_MARK'];
                        }
                    }
                } else {
                    /**
                     * if user did not ask for limited number of question for different question types
                     */
                    $localSearchArr = array(
                        'topicId' => $localTopicIds,
                        'qnsType' => $question_types,
                        'cognitiveId' => $api_cognitive_dropdowns,
                        'difficultyLevel' => $difficulty_levels,
                        'localQuesLimit' => $localQuesLimit,
                    );
                    /** Total count for Questions from LOCAL. */
                    $questionsListDB = $createQuizTable->getAllQuestion($localSearchArr, '', true);
                    $questionCountWithoutApi = count($questionsListDB);
                    foreach ($questionsListDB as $val) {
                        $ques_ids_without_api[] = $val['QUS_ID'] . '-LOCAL';
                        $questionMarkWithoutApi += $val['QUES_MARK'];
                    }
                }
            }
            $questionCount = $questionCountWithAPi + $questionCountWithoutApi;
            $questionMark = $questionMarkWithAPi + $questionMarkWithoutApi;
            $total_local_ques_ids = array_merge($ques_ids_without_api, $ques_ids_with_api);
            $jsonModel = new JsonModel();
            $jsonModel->setVariables(array(
                'questionCount' => $questionCount,
                'questionMark' => $questionMark,
                'total_ques_ids' => $total_local_ques_ids
            ));
            return $jsonModel;
        }
    }

}

?>

Youez - 2016 - github.com/yon3zu
LinuXploit