<?php

/**

 * HTML Change Password Form

 *

 * PHP version 7.3

 *

 * @package        SMS

 * @version        Release 1.0.0

 * @create_by      Mohammad aljaouni

 * @create_date    17-08-2020

 * @edited_by

 * @last_edit_date

 * @todo           Nothing

 */

ob_start();

session_start();

$chain = "AWdrh78y892Djk*^523*%$#ghgHGHia&%$*)AsfdsLJnLaad";

include("validateLogin.php");

include("includeInformation.php");

include("header.php");

include("reader.php");

unset($_SESSION["excelData"]);

$queryAccount = "SELECT * ";

$queryAccount.= " FROM $userLogin";

$queryAccount.= " WHERE id=$_SESSION[userId]";

$resultAccount = mysqli_query($conn, $queryAccount);

$rowAccount = mysqli_fetch_array($resultAccount);

$msgUniqueMd5 = md5(time());

$_SESSION["msgUnique"] = $msgUniqueMd5;

?>

<link rel="stylesheet" type="text/css" href="../JScalendar/jquery-ui-timepicker-addon.css" />

<link rel="stylesheet" media="all" href="../JScalendar/jquery-ui.css" />

<?php if($_SESSION["language"]==1){

    ?>

    <script type="text/javascript" src="../JScalendar/jquery-ui.min.Ar.js"></script>

    <script type="text/javascript" src="../JScalendar/jquery-ui-timepicker-addon-Ar.js"></script>

    <?php

}else{

    ?>

    <script type="text/javascript" src="../JScalendar/jquery-ui.min.js"></script>

    <script type="text/javascript" src="../JScalendar/jquery-ui-timepicker-addon.js"></script>

    <?php

}

?>

<script language="javascript" type="text/javascript">

function checkIntergetType(val)

{

	var string = "1234567890";	

	for(var i=0;i<val.length;i++)

	{

		if(string.indexOf(val.charAt(i)) == -1)

		return false;

	}

	return true;

}



function validate()

{   

	if(document.formMsg.userSender.value == "")

  	{

		//أدخل إسم المرسل

  		alert('<?php echo $sendFromExcelLBL["insertSenderName"];?>');

  		document.formMsg.userSender.focus();

  		return false;

  	} 	

	var sender = document.formMsg.userSender.value;

    if(checkIntergetType(sender))

    {

	    if(sender.substring(0,2)=="00")

		sender=sender.substring(2);

		if(sender.substring(0,1)=="0")

	    sender=sender.substring(1);

		if (sender.length > 12)

		{

			alert("<?php echo $sendFromExcelLBL["senderNameLength"]?>");

			return false;

		}

	}

	else

	{

		if(unicode(document.formMsg.userSender.value)==1)

		{

			//اسم المرسل بالغة الانجليزية

			alert('<?php echo $sendFromExcelLBL["senderNameEnglish"]?>')

			return false;

		}

		if (sender.length > 11)

		{

			alert("<?php echo $sendFromExcelLBL["senderNameLength"]?>");

			return false;

		}

	}

	if(document.getElementById("ceil").value == -1){

		alert("<?php echo $sendFromExcelLBL["selectNumberCell"]?>");

	    return false;

	}

	for (i=0; i < formMsg.msg.value.length; i++)

	{

    	if (formMsg.msg.value.charAt(i) =="'")

        {

        	alert("<?php echo $sendFromExcelLBL["notAllowedNumber"]?>");

            return false;

		}



        if (formMsg.msg.value.charAt(i) =='"')

        {

        	alert("<?php echo $sendFromExcelLBL["notAllowedNumber"]?>");

            return false;

		}

	}

	if(document.getElementById("fileName").value == ""){

		if(document.getElementById("file2").value == ""){

			alert("<?php echo $sendFromExcelLBL["uploadFile"]?>");

		    return false;

		}

	}

	if(document.formMsg.msg.value == "")

	{

		//يجب عليك إدخال نص الرسالة

		alert('<?php echo $sendFromExcelLBL["insetTextMsg"];?>')

		document.formMsg.msg.focus();

		return false;

	}

	msgTemp = "";

	for(i=0; i<document.formMsg.msg.value.length; i++)

	{

		if(document.formMsg.msg.value.charCodeAt(i)=="1632")

			msgTemp += "0";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1633")

			msgTemp += "1";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1634")

			msgTemp += "2";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1635")

			msgTemp += "3";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1636")

			msgTemp += "4";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1637")

			msgTemp += "5";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1638")

			msgTemp += "6";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1639")

			msgTemp += "7";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1640")

			msgTemp += "8";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1641")

			msgTemp += "9";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1785")

			msgTemp += "9";

		else if(document.formMsg.msg.value.charCodeAt(i)=="1642")

			msgTemp += "%";			

		else

			msgTemp +=document.formMsg.msg.value.charAt(i);

	}

	document.formMsg.msg.value =msgTemp;

	for(i=0; i<document.formMsg.msg.value.length; i++)

	{

		if(document.formMsg.msg.value.charAt(i) =='ـ')

		{

			if(document.formMsg.confirmMsg.value == '0')

			{

				//الحرف التالي (شفت و ت) قد لا يصل بشكل صحيح على جميع أنواع الجوالات

				alert('<?php echo $sendFromExcelLBL["lettersNotSend"];?>');

				document.formMsg.confirmMsg.value = '1';

				document.formMsg.msg.focus();

				return false;

			}

		}

	}

	/*

	if(textFilter(document.formMsg.msg.value)==1)

	{

		document.formMsg.msg.focus();

		return false;

	}

	*/

	return true;

}

function unicode(strText)

{

	str = "دجحخهعغفقثصضطكمنتالبيسشظزوةىلارؤءئإلإألأآلآ،؛؟ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيـًٌٍَُِّْ";

 	for (i=0; i<strText.length; i++)

		if (str.indexOf(strText.charAt(i)) != -1)

			return 1;

 	return 0;

}



function charPlus()

{

	strLen = 0;

	strText = document.formMsg.msg.value;

	for(i=0; i<strText.length; i++)

	{

		if(strText.charCodeAt(i)!=13)

			strLen++;

	}

	document.formMsg.numChars.value = strLen;

	numChar = strLen;	

	if (unicode(document.formMsg.msg.value))

	{

		document.formMsg.unicode1.value = 1;

		if(numChar <= 70)

			document.formMsg.numMsgs.value = 1;

		else

			document.formMsg.numMsgs.value = Math.ceil(numChar/67);

	}

	else

	{

		document.formMsg.unicode1.value = 0;

		if(numChar <= 160)

			document.formMsg.numMsgs.value = 1;

		else

			document.formMsg.numMsgs.value = Math.ceil(numChar/153);

	}

}

function goToUploade(){

	if(document.getElementById("file2").value == ""){

		alert("<?php echo $sendFromExcelLBL["uploadFile"]?>");

	    return false;

	}

	formMsg.action = "sendFromExcel.php";

	formMsg.submit();



}

function addVar(ceil){

	var ceil = ceil;

	document.getElementById("msg").value+="<<ceil"+ceil+">>";

	document.getElementById("varNum").value++;

	formMsg.msg.focus();



}

$(document).ready(function(){

	$('#calendar').datetimepicker();

	

	$("#process").click(function(){

		if (!validate())

		{

			return false;

		}

		var userSender = $('#userSender').val();

		var msg = $('#msg').val();

		if (userSender !="" && msg !="")

		{

			$("#reportResult").html('');							 

			senderName = $('#userSender').val();

			var values = new Array();

			if($("input:checkbox[name='categoryId[]']").length) {	

				$.each($("input:checkbox[name='categoryId[]']:checked"), function(){

					values.push($(this).val());

				});	

			}

			var catSelected = values;

			var numbersCat = "";

			if($("#numbersCatId").length)

				numbersCat = $('#numbersCatId').val();

			var numbersRank = "";	

			if($("#numbersRankId").length)

				var numbersRank = $('#numbersRankId').val();

			var calendarlater = $('#calendar').val();

			var typeSend = $('input:radio[name=sendNow]:checked').val();

			var delNum = 'off';

			if($("#deleteNum").is(':checked'))

				delNum='on';



			$.post("reportSendFromExcel.php", { 

				numFiled: $("#numFiled").val(),

				varNum: $("#varNum").val(),

				ceil: $("#ceil").val(),

				msg: $("#msg").val(),

				numbers: $("#numbers").val(),

				userSender: senderName,							

				category: ""+catSelected,

				numberscat: numbersCat,

				numbersrank: numbersRank,

				calendarlater: calendarlater,

				typeSend: typeSend,

				deleteNum: delNum  

			},

			function(data){

				$("#reportResult").html(data);	

				$('#reportSendModal').modal('show');

			});

		}

		else

		{

			//يجب ادخال اسم المرسل و نص الرسالة المرسلة

			alert("<?php echo $sendFromExcelLBL["enterSenderAndMsg"];?>");

			return false;

		} 

	});

	

	$("#saveMsg").click( function(){

		strLen = 0;

		numMsgseN = 0;

		

		if($('#titleId').val() == '')

		{

			//ادخل عنوان الرسالة

			alert("<?php echo $sendFromExcelLBL["enterMsgTitle"];?>");

			$('#titleId').focus();

			return false;

		}

		strText = document.formMsg.msg.value;

		if(strText == "")

		{

			//يجب عليك إدخال نص الرسالة

			alert('<?php echo $sendFromExcelLBL["insetTextMsg"];?>');

			$('#saveMsgModal').modal('hide');

			document.formMsg.msg.focus();

			return false;

		}

		msgTemp = "";

		for(i=0; i<document.formMsg.msg.value.length; i++)

		{

			if(document.formMsg.msg.value.charCodeAt(i)=="1632")

				msgTemp += "0";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1633")

				msgTemp += "1";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1634")

				msgTemp += "2";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1635")

				msgTemp += "3";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1636")

				msgTemp += "4";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1637")

				msgTemp += "5";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1638")

				msgTemp += "6";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1639")

				msgTemp += "7";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1640")

				msgTemp += "8";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1641")

				msgTemp += "9";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1785")

				msgTemp += "9";

			else if(document.formMsg.msg.value.charCodeAt(i)=="1642")

				msgTemp += "%";			

			else



				msgTemp +=document.formMsg.msg.value.charAt(i);

		}

		document.formMsg.msg.value = msgTemp;

		for(i=0; i<document.formMsg.msg.value.length; i++)

		{

			if(document.formMsg.msg.value.charAt(i) =='ـ')

			{

				if(document.formMsg.confirmMsg.value == '0')

				{

					//الحرف التالي (شفت و ت) قد لا يصل بشكل صحيح على جميع أنواع الجوالات

					alert('<?php echo $sendFromExcelLBL["lettersNotSend"];?>');

					document.formMsg.confirmMsg.value = '1';

					$('#saveMsgModal').modal('hide');

					document.formMsg.msg.focus();

					return false;

				}

			}

		}

		/*

		if(textFilter(document.formMsg.msg.value)==1)

		{

			$('#saveMsgModal').modal('hide');

			document.formMsg.msg.focus();

			return false;

		}

		*/

		strText = document.formMsg.msg.value;

		for(i=0; i<strText.length; i++)

		{

			if(strText.charCodeAt(i)!=13)

				strLen++;

		}

		numCharN = strLen;

		if (unicode(document.formMsg.msg.value))

		{

			numMsgseN = 1;

			if(numCharN <= 70)

				numMsgseN = 1;

			else

				numMsgseN = Math.ceil(numCharN/67);

		}

		else

		{

			numMsgseN = 0;

			if(numCharN <= 160)

				numMsgseN = 1;

			else

				numMsgseN = Math.ceil(numCharN/153);

		}

		var titleIdMsg = $('#titleId').val();

		$.post("saveMsgs.php",{msg:$("#msg").val(),numChars:numCharN,numMsgs:numMsgseN,title:titleIdMsg},function (res){

			if(res == 1)

			{

				//تمت عملية تخزين الرسالة في صندوق الرسائل بنجاح

				alert("<?php echo $sendFromExcelLBL["msgBoxSaveDone"];?>");

				$('#saveMsgModal').modal('hide');

			}

			if(res == 2)

			{

				//لم تتم عملية الاضافة بنجاح ... اعد المحاولة مرة اخرى

				alert("<?php echo $sendFromExcelLBL["msgBoxSaveFail"];?>");

				$('#saveMsgModal').modal('hide');

			}

			if(res == 0)

			{

				//لم تتم عملية الاضافة بنجاح ... البيانات مفقودة

				alert("<?php echo $sendFromExcelLBL["addFailNoData"];?>");

				$('#saveMsgModal').modal('hide');

			}

		});

	});

	

	$("#msgReadyId").change(function(){	

		$("#msg").text('');

		$("#msg").text($(this).children(':selected').attr('msg')); 

		charPlus();

	});

});

function clock()

{

	$.post("timeDateServer.php",function(res){																																																											

		$("#TimeOnTheServer").text(res);

	})

	setTimeout('clock()',1000); 

}

clock();



function fetchDateCategory(id)

{

	$.post("categoryNumberFetch.php",{id:id,rand:Math.random() } ,function(res){

		$("#reportResultNumber").html(res);

	});

	$('#catgoriesNumbersModal').modal('show');



}

</script>

<!--  saveMsgModal -->

<div class="modal fade modal-fullscreen " style="z-index:10000;padding-<?php echo $align;?>:0px" id="saveMsgModal" tabindex="-1" role="dialog" aria-labelledby="searchModalTitle" aria-hidden="true">

  <div class="modal-dialog modal-dialog-centered" role="document">

     <div class="modal-content text-right">

        <div class="modal-header modal-header-primary">

           <h5 class="modal-title" id="searchModalTitle"><?php echo $sendFromExcelLBL["saveMsg"];?></h5>

           <button type="button" class="close slidedown" data-dismiss="modal" aria-label="Close">

           <span aria-hidden="true">&times;</span>

           </button>

        </div>

        <div class="modal-body" style="text-align: <?php echo $align;?>;">

            <div class="form-group" style="margin-bottom: 0px;">

            	<label for="titleId" class="col-form-label myModalLabel"> <?php echo $sendFromExcelLBL["msgTitle"];?>:</label>

            	<input type="text" class="form-control" name="title" id="titleId">

            </div>

        </div>

        <div class="modal-footer">

           <button type="button" class="btn bg-danger btn-flat text-white m-1" data-dismiss="modal"><?php echo $button["close"];?></button>

           <input type="button" value='<?php echo $button["save"];?>' name="saveMsg" id="saveMsg" class="btn bg-primary btn-flat text-white m-1">

        </div>

     </div>

  </div>

</div>

<!--  saveMsgModal -->



<!-- Start Dashboard page -->

    <!-- start main-content -->

    <div class="main-content">

        <!-- Start Page-content -->

        <div class="page-content">

        <!-- Page-Title -->

        <div class="page-title-box">

            <div class="container-fluid">

                <div class="row align-items-center">

                    <?php echo breadcrumbs(basename($_SERVER['PHP_SELF']));?>

                </div>

            </div>

        </div>

        <?php

		

		$color = "seagreen";

		$result = $resultReport = balanceSMS($userAccount, $passAccount, 1);

		//@list($elem1, $elme2) = explode("/", $result);

		$querySiteAccount = "UPDATE $userLogin SET";

		$querySiteAccount.= " account='$result'";

		$querySiteAccount.= " WHERE id='".$_SESSION["userId"]."'";

		$result2 = mysqli_query($conn, $querySiteAccount);

		$balance = sprintf($sendMsgLBL["balanceHeader"], $result);

		$accountUser = $result;

		if($result <= 0)

			$color = "red";

		

		$resultRyal = balanceSMS($userAccount, $passAccount);

		$balanceRyal = sprintf($sendMsgLBL["balanceHeader2"], $resultRyal);

		?>

        <!-- end page title end breadcrumb -->

        <div class="page-content-wrapper">

            <div class="container-fluid">

                <div class="row justify-content-center align-items-center">

                    <div class="col-sm-12 col-lg-6 ">

                        <div class="card">

                            <div class="card-body table-responsive">

                            <?php

								if(!empty($_GET['sendErrorMsg'])) {

									if($_GET['sendErrorMsg'] == 1)

										echo result(222);

								}

								if(!empty($_GET["res"]))

									echo result($_GET["res"]);

								?>

                                <span class="text-center balanceTitle" style="color:<?php echo $color;?>"><center class="mb-3"><b><?php echo $balanceRyal;?> = <?php echo $balance;?></b></center></span>

								<form name=formMsg   method=post enctype="multipart/form-data" action="sendFromExcel2.php">

                                <?php

								if (empty($_FILES['file2']['size'])) {

								?>

								<table border="0" width="100%" cellpadding="3" cellspacing="2" style="margin:0px; border-collapse:collapse">

                                   <!-- START (Server Time) --->

                                   <tbody>

                                      <!-- END (Server Time) --->

                                      <!-- START (Sender Managment) --->            

                                      <tr>

                                         <td class="myModalLabel"><?php echo $sendFromExcelLBL["sender"];?>: </td>

                                         <td>

                                            <?php

                                            	$userActiveArr = array();

                                                $userActive = getSenderAvailability($userAccount);

												if(!empty($userActive)){

													$userActiveArr = explode(",", $userActive);

													$userActiveArr = array_filter($userActiveArr);

												}

                                                ?>

                                                <select name="userSender" id="userSender" class="form-control" style="padding:0px">

                                                    <?php

                                                    foreach ($userActiveArr as $value) {

                                                        ?>

                                                        <option value="<?php echo $value; ?>"><?php echo $value; ?></option>

                                                        <?php

                                                    }

                                                    ?>

                                                </select>

                                         </td>

                                      </tr>

                                      <!-- END (Sender Managment) --->

                                      <!-- START (Numbers Managment) --->

                                       <?php

										?>

                                      <tr>

                                         <td class="myModalLabel" valign="top"><?php echo $sendFromExcelLBL["uploadFile2"];?>: </td>

                                        <td>

                                            <input type="file" name="file2" id="file2" /> <input type="submit" value="<?php echo $sendFromExcelLBL["upload"];?>" name="upload" onclick="return goToUploade()" style="width: 75px;padding: 0 4px;height: 29px;line-height: inherit;" class="btn btn-success waves-effect waves-light">

                                        </td>

                                      </tr>

                                    <tr>

                                    	<td colspan="2" ><b style="font-size: 14px; color: red"><?php echo $sendFromExcelLBL["numbersNote"]?>:</b></td>

                                    </tr>

                                    <tr>

                                    	<td colspan="2" style="padding: 0 15px;"><a href="sampleFromExcel.xls"><b style="font-size: 14px; color: red"><?php echo $sendFromExcelLBL["sampleXls"]?></b></a></td>

                                    </tr>

                                    <tr>

                                    	<td colspan="2" style="padding: 0 15px;"><a href="sampleFromExcel.xlsx"><b style="font-size: 14px; color: red"><?php echo $sendFromExcelLBL["sampleXlsx"]?></b></a></td>

                                    </tr>

                                    <tr>

                                    	<td colspan="2" style="padding: 0 15px;" ><a href="sampleFromExcel.csv"><b style="font-size: 14px; color: red"><?php echo $sendFromExcelLBL["sampleCsv"]?></b></a></td>

                                    </tr>

                                    <tr>

                                    	<td colspan="2" style="padding: 0 15px;"><a href="sampleFromExcel.txt"><b style="font-size: 14px; color: red" download><?php echo $sendFromExcelLBL["sampleTxt"]?></b></a></td>

                                    </tr>

                                    <tr>

                                        <td class="myModalLabel" valign="top" nowrap="nowrap"><?php echo $sendFromExcelLBL["numbers"]?> : </td> 

                                        <td style="text-align:<?php $align?>;"  colspan=3>

                                            <select name="ceil" id="ceil"  class="form-control" style="padding:0px">

                                                <option value="0"><?php echo $sendFromExcelLBL["selectCell"]?></option>

                                            </select>

                                        </td>

                                    </tr>

                                      <!-- END (Numbers Managment) --->

                                      <!-- START (Message Managment) --->    

                                     

                                      <tr style="<?php echo (!empty($_POST["sendNow"]) && $_POST["sendNow"]==2)?"" :"display:none";?>" id="timingTR">

                                         <td nowrap="nowrap">&nbsp;</td>

                                         <td nowrap="nowrap"><input type="text" name="calendar" class="form-control" id="calendar" value="<?php echo (!empty($_POST["calendar"]))? $_POST["calendar"]:"";?>" placeholder="<?php echo $sendFromExcelLBL["time"];?>" />

                                         </td>

                                      </tr>

                                      <?php

										$msg = '';

										$setCounter = false;

										if (!empty($_POST['readyMsgId']))

										{

											$queryfetchMsg = "SELECT msg FROM temp_msg WHERE id=$_POST[readyMsgId]";

											$resultfetchMsg = mysqli_query($conn, $queryfetchMsg);

											$numfetchMsg = mysqli_num_rows($resultfetchMsg);

											if(!empty($numfetchMsg))

											{

												$rowfetchMsg = mysqli_fetch_array($resultfetchMsg);

												$msg = $rowfetchMsg['msg'];

												$setCounter = true;

											}

										} 

										?>

                                      <tr>

                                         <td class="myModalLabel" valign="top"><?php echo $sendFromExcelLBL["message"];?>: </td>

                                         <td>

                                            <table border="0" width="100%" cellpadding="2" cellspacing="0" style="margin:0px; border-collapse:collapse">

                                               <tbody>

                                                  <tr>

                                                     <td style="width:500px"><textarea class="form-control" onkeydown="javascript:charPlus()" onkeyup="javascript:charPlus()" name="msg" id="msg" rows=4><?php echo (!empty($_POST["msg"]))? $_POST["msg"]:"";?><?php if(!empty($reMsg)){?><?php echo $reMsg?><?php }else{?><?php echo $msg?><?php }?></textarea></td>

                                                  </tr>

                                                  <tr>

                                                     <td valign="bottom" align="<?php echo $align;?>" class="charsCount" >

                                                     <span style="font-weight:bold; padding-top:10px"><?php echo $sendFromExcelLBL["charCount"];?> : </span>&nbsp; 

                                                     <input class="form-control" readonly value="0" name="numChars" style="width:60px;background-color: #eee;">&nbsp; 

                                                     <span style="font-weight:bold; padding-top:10px"><?php echo $sendFromExcelLBL["msgCount"];?> : </span> &nbsp; 

                                                     <input class="form-control" readonly value="0" name="numMsgs" style="width:60px;background-color: #eee;">

                                                     </td>

                                                  </tr>

                                               </tbody>

                                            </table>

                                         </td>

                                      </tr>

                                      <!-- END (Message Managment) --->

                                      <tr>

                                         <td></td>

                                         <td valign="top" style="white-space: nowrap;"><input type="checkbox" id="deleteNum" name="deleteNum" checked="checked" dir="<?php echo $dir;?>"> <b><?php echo $sendFromExcelLBL["delNum"];?></b></td>

                                      </tr>

                                      <tr>

                                         <td align="left" colspan="2">

                                         <?php

											$style = 'disabled=disabled';

											if(!empty($_SESSION["excelData"]))

												$style = '';

											?>

                                            <hr>

                                            <input class="btn btn-success waves-effect waves-light" type="button" value="<?php echo $sendFromExcelLBL["send"];?>"  <?php echo $style;?> name="send" id="process">

                                            <input class="btn btn-info  waves-effect waves-light" type="reset" value="<?php echo $sendFromExcelLBL["clear"];?>">

                                         </td>

                                      </tr>

                                   </tbody>

                                </table>

                                <input type="hidden" value="0"  name="unicode1">

                                <input type="hidden" value="<?php echo $_SESSION['userId'];?>" name="userId2">

                                <input type="hidden" name="userSenderSMS" value="<?php echo $rowAccount['sender'];?>">

                                <input type="hidden" name="selectArchives" value="1" >

                                <input type="hidden" name="confirmMsg" value="0">

                                <?php 

								} else {

									$fileName = $_FILES['file2']['tmp_name'];

									if(strrchr(@$_FILES['file2']['name'],".") == ".csv" || strrchr(@$_FILES['file2']['name'],".") == ".txt")

									{

										$handle = fopen($_FILES['file2']['tmp_name'], "r");

										$row = 0;

										$dataText = "";

										$d1 = "";

										$d2 = "";

										while (!feof($handle))

										{

											$data[$row] = fgets($handle,100000);

											$data[$row]=str_replace("\r","",$data[$row]);

											$data[$row]=str_replace("\n","",$data[$row]);

											if(strpos($data[$row],','))

												list($d1,$d2) = explode(",",$data[$row]);

											elseif(strpos($data[$row],';'))	

												list($d1,$d2) = explode(";",$data[$row]);

											 else

												list($d2) = explode(" ",$data[$row]);	

											if(!empty($dataText) || !empty($d2))

											{

												$dataText .= $d2.",";	

												if(strpos($data[$row],','))

													$data2= explode(",",$data[$row]);

												elseif(strpos($data[$row],';'))	

													$data2= explode(";",$data[$row]);

												else

													$data2 = explode(" ",$data[$row]);	

												$num = count($data2);

													$data2 = array_filter($data2);	

												$col= 0;

												while($col < $num)

												{

													if(!empty($data2[$col]) && $data2[$col] != " ")

													{

														if(strrchr(@$_FILES['file2']['name'],".") == ".txt")

															$data2[$col]= iconv("UTF-8", "windows-1256", $data2[$col]);

														$excelData[$row][$col] = $data2[$col];

													}

													$col++;

												}

											}

											$row++;

										}

									   fclose($handle);

									}

									elseif (strrchr(@$_FILES['file2']['name'],".") == ".xls")

									{

										$data = new Spreadsheet_Excel_Reader();

										$data->setOutputEncoding('CP1256');

										$data->read($_FILES['file2']['tmp_name']);

										$dataText = "";

										$d1 = "";

										$d2 = "";

										for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)

										{	

											for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)

											{

												@list($d1,$d2) = explode(",",$data->sheets[0]['cells'][$i][$j]);

												$dataText.= $d2.",";

												//aljaouni start edit 05/24/2018

												if(!empty($data->sheets[0]['cells'][$i][$j]))

												$excelData[$i-1][$j-1]=$data->sheets[0]['cells'][$i][$j];

												//aljaouni end edit 05/24/2018

												

											}

										}

									}

									elseif (strrchr(@$_FILES['file2']['name'],".") == ".xlsx") {

										if($xlsx = new SimpleXLSX($_FILES['file2']['tmp_name'])) {

											foreach($xlsx->rows() as $r => $row) {

												foreach($row as $c => $cell) {

													$cell = iconv("UTF-8", "windows-1256", $cell);

													$excelData[$r][$c] = $cell;

												}

											}

										}

									}

									

									if(!empty($excelData) && is_array($excelData)) {

										$excelData = array_values($excelData);

										$_SESSION["excelData"] = $excelData;

										$numFiled = count($excelData[0]);

										$numRow  = count($excelData);

									} else {

										$_SESSION["excelData"]=$excelData = array();

										$numFiled=$numRow= 0;

									}

								?>

                                <table border="0" width="100%" cellpadding="3" cellspacing="2" style="margin:0px; border-collapse:collapse">

                                   <!-- START (Server Time) --->

                                   <tbody>

                                      <!-- END (Server Time) --->

                                      <!-- START (Sender Managment) --->            

                                      <tr>

                                         <td class="myModalLabel"><?php echo $sendFromExcelLBL["sender"];?>: </td>

                                         <td>

                                            <?php

                                            	$userActiveArr = array();

                                                $userActive = getSenderAvailability($userAccount);

												if(!empty($userActive)){

													$userActiveArr = explode(",", $userActive);

													$userActiveArr = array_filter($userActiveArr);

												}

                                                ?>

                                                <select name="userSender" id="userSender" class="form-control" style="padding:0px">

                                                    <?php

                                                    foreach ($userActiveArr as $value) {

                                                        ?>

                                                        <option value="<?php echo $value; ?>"><?php echo $value; ?></option>

                                                        <?php

                                                    }

                                                    ?>

                                                </select>

                                         </td>

                                      </tr>

                                      <!-- END (Sender Managment) --->

                                      <!-- START (Numbers Managment) --->

                                       <?php

										?>

                                      <tr>

                                         <td class="myModalLabel" valign="top"><?php echo $sendFromExcelLBL["uploadFile2"];?>: </td>

                                        <td>

                                            <input type="file" name="file2" id="file2" /> <input type="submit" value="<?php echo $sendFromExcelLBL["upload"];?>" name="upload" onclick="return goToUploade()" style="width: 75px;padding: 0 4px;height: 29px;line-height: inherit;" class="btn btn-success waves-effect waves-light">

                                            <input type="hidden" name="fileName" id="fileName" value="<?php echo $fileName;?>" style="height:24px">	

                                        </td>

                                      </tr>

                                    <tr>

                                    	<td colspan="2" ><b style="font-size: 14px; color: red"><?php echo $sendFromExcelLBL["numbersNote"]?>:</b></td>

                                    </tr>

                                    <tr>

                                    	<td colspan="2" style="padding: 0 15px;"><a href="sampleFromExcel.xls"><b style="font-size: 14px; color: red"><?php echo $sendFromExcelLBL["sampleXls"]?></b></a></td>

                                    </tr>

                                    <tr>

                                    	<td colspan="2" style="padding: 0 15px;"><a href="sampleFromExcel.xlsx"><b style="font-size: 14px; color: red"><?php echo $sendFromExcelLBL["sampleXlsx"]?></b></a></td>

                                    </tr>

                                    <tr>

                                    	<td colspan="2" style="padding: 0 15px;" ><a href="sampleFromExcel.csv"><b style="font-size: 14px; color: red"><?php echo $sendFromExcelLBL["sampleCsv"]?></b></a></td>

                                    </tr>

                                    <tr>

                                    	<td colspan="2" style="padding: 0 15px;"><a href="sampleFromExcel.txt"><b style="font-size: 14px; color: red" download><?php echo $sendFromExcelLBL["sampleTxt"]?></b></a></td>

                                    </tr>

                                     <tr>

                                        <td colspan="2" class="myModalLabel" style="color:red;text-align:center"><?php echo $sendFromExcelLBL["infoFound"]?> <?php echo $numRow?> <?php echo $sendFromExcelLBL["lineAnd"]?>  <?php echo $numFiled?>  <?php echo $sendFromExcelLBL["cloumn"]?></td>

                                    </tr>

                                    <tr>

                                        <td colspan="2">

                                            <table width="50%"  align="center">

                                            <?php

                                            $viewCounter = 0;

                                            for($row =0; $row < count($excelData); $row++) {

                                                ++$viewCounter;

                                                if($viewCounter == 6)

                                                    break;

                                                if($row == 0) {

                                                    ?>

                                                <tr>

                                                    <?php for($col =0; $col < count($excelData[$row]); $col++){ ?>

                                                        <td align="center"><input type="button"  class="btn btn-success waves-effect waves-light" style="width: 120px;padding: 0 4px;height: 25px;line-height: inherit;" onclick="addVar(<?php echo $col?>)"  value=" <?php echo $sendFromExcelLBL["addCell"]?>   <?php echo $col;?>"/></td>

                                                    <?php } ?>

                                                </tr>

                                                <?php } ?>

                                                <tr>

                                                    <?php

                                                    for($col =0; $col < count($excelData[$row]); $col++) {

                                                        //aljaouni

                                                        ?>

                                                        <td align="center"><?php if(!empty($excelData[$row][$col])) { echo $excelData[$row][$col]; }?></td>

                                                        <?php

                                                    }

                                                    ?>

                                                </tr>

                                            <?php } ?>

                                            </table>

                                        </td>

                                    </tr>

                                    <tr>

                                        <td class="myModalLabel" valign="top" nowrap="nowrap"><?php echo $sendFromExcelLBL["numbers"]?> : </td> 

                                        <td style="text-align:<?php $align?>;"  colspan=3>

                                            <select name="ceil" id="ceil"  class="form-control" style="padding:0px">

                                                <option value="-1" <?php if($_POST["ceil"] == 'ceil'){?> selected  <?php } ?>><?php echo $sendFromExcelLBL["selectCell"]?></option>

                                                <?php for ($i = 0;$i < $numFiled ;$i++) {?>

                        						<option value="<?php echo $i?>" <?php if($_POST["ceil"] == "<?php echo $i?>"){?> SELECTED  <?php } ?>><?php echo $sendFromExcelLBL["cell"]?> <?php echo $i?></option>

                                                <?php } ?>

                                            </select>

                                        </td>

                                    </tr>

                                      <!-- END (Numbers Managment) --->

                                      <!-- START (Message Managment) --->    

                                      <tr style="<?php echo (!empty($_POST["sendNow"]) && $_POST["sendNow"]==2)?"" :"display:none";?>" id="timingTR">

                                         <td nowrap="nowrap">&nbsp;</td>

                                         <td nowrap="nowrap"><input type="text" name="calendar" class="form-control" id="calendar" value="<?php echo (!empty($_POST["calendar"]))? $_POST["calendar"]:"";?>" placeholder="<?php echo $sendFromExcelLBL["time"];?>" />

                                         </td>

                                      </tr>

                                      <?php

										$msg = '';

										$setCounter = false;

										if (!empty($_POST['readyMsgId'])) {

											$queryfetchMsg = "SELECT msg FROM temp_msg WHERE id=$_POST[readyMsgId]";

											$resultfetchMsg = mysqli_query($conn, $queryfetchMsg);

											$numfetchMsg = mysqli_num_rows($resultfetchMsg);

											if(!empty($numfetchMsg)) {

												$rowfetchMsg = mysqli_fetch_array($resultfetchMsg);

												$msg = $rowfetchMsg['msg'];

												$setCounter = true;

											}

										} 

										?>

                                      <tr>

                                         <td class="myModalLabel" valign="top"><?php echo $sendFromExcelLBL["message"];?>: </td>

                                         <td>

                                            <table border="0" width="100%" cellpadding="2" cellspacing="0" style="margin:0px; border-collapse:collapse">

                                               <tbody>

                                                  <tr>

                                                     <td style="width:500px"><textarea class="form-control" onkeydown="javascript:charPlus()" onkeyup="javascript:charPlus()" name="msg" id="msg" rows=4><?php echo (!empty($_POST["msg"]))? $_POST["msg"]:"";?><?php if(!empty($reMsg)){?><?php echo $reMsg?><?php }else{?><?php echo $msg?><?php }?></textarea></td>

                                                  </tr>

                                                  <tr>

                                                     <td valign="bottom" align="<?php echo $align;?>" class="charsCount" >

                                                     <span style="font-weight:bold; padding-top:10px"><?php echo $sendFromExcelLBL["charCount"];?> : </span>&nbsp; 

                                                     <input class="form-control" readonly value="0" name="numChars" style="width:60px;background-color: #eee;">&nbsp; 

                                                     <span style="font-weight:bold; padding-top:10px"><?php echo $sendFromExcelLBL["msgCount"];?> : </span> &nbsp; 

                                                     <input class="form-control" readonly value="0" name="numMsgs" style="width:60px;background-color: #eee;">

                                                     </td>

                                                  </tr>

                                               </tbody>

                                            </table>

                                         </td>

                                      </tr>

                                      <!-- END (Message Managment) --->

                                      <tr>

                                         <td></td>

                                         <td valign="top" style="white-space: nowrap;"><input type="checkbox" id="deleteNum" name="deleteNum" checked="checked" dir="<?php echo $dir;?>">&nbsp;<b><?php echo $sendFromExcelLBL["delNum"];?></b></td>

                                      </tr>

                                      <tr>

                                         <td align="left" colspan="2">

                                            <hr>

                                            <input class="btn btn-success waves-effect waves-light" type="button" value="<?php echo $sendFromExcelLBL["send"];?>" name="send" id="process">

                                            <input class="btn btn-info  waves-effect waves-light" type="reset" value="<?php echo $sendFromExcelLBL["clear"];?>">

                                         </td>

                                      </tr>

                                   </tbody>

                                </table>

                                <input type="hidden" value="0"  name="unicode1">

                                <input type="hidden" value="<?php echo $_SESSION['userId'];?>" name="userId2">

                                <input type="hidden" name="userSenderSMS" value="<?php echo $rowAccount['sender'];?>">

                                <input type="hidden" name="selectArchives" value="1" >

                                <input type="hidden" name="confirmMsg" value="0">

                                <?php

								}

								?>

                                <!--  reportSendModal -->

                                <div class="modal fade modal-fullscreen " style="z-index:10000;padding-<?php echo $align;?>:0px" id="reportSendModal" tabindex="-1" role="dialog" aria-labelledby="searchModalTitle" aria-hidden="true">

                                  <div class="modal-dialog modal-dialog-centered" role="document">

                                     <div class="modal-content text-right">

                                        <div class="modal-header modal-header-primary">

                                           <h5 class="modal-title" id="searchModalTitle"><?php echo $sendFromExcelLBL["reportSendMsg"];?></h5>

                                           <button type="button" class="close slidedown" data-dismiss="modal" aria-label="Close">

                                           <span aria-hidden="true">&times;</span>

                                           </button>

                                        </div>

                                        <div class="modal-body" style="text-align: <?php echo $align;?>;">

                                            <span id="reportResult"></span>

                                        </div>

                                        

                                     </div>

                                  </div>

                                </div>

                                <!--  reportSendModal -->

                                <?php

								if(!empty($numFiled)) {

								?>

								<input type="hidden" name="numFiled"  id="numFiled"  value="<?php echo $numFiled?>">

								<?php

								} else {

								?>

								<input type="hidden" name="numFiled"  id="numFiled"  value="">

								<?php

								}

								?>

								<input type="hidden" name="varNum" id="varNum" value=0>

                                </form>

                            </div>

                        </div>

                    </div>

                </div>

                <!-- end row -->

            </div>

            <!-- end container-fluid -->

        </div>

        <!-- end page-content-wrapper -->

    </div>

        <!-- End Page-content -->

</div>

    <!-- end main content -->

<!-- End Dashboard page -->

<script type="text/javascript">

function openSubCatsTR(trId)

{

	if($('#subCatgoriesTRStatus'+trId).val() == '0')

	{

		$('#subCatgoriesTR'+trId).show('fast');

		$('#subCatgoriesTRStatus'+trId).val(1);

		$('#aCategoryId'+trId).css('color', '#900');

	}

	else

	{

		$('#subCatgoriesTR'+trId).hide('fast');

		$('#subCatgoriesTRStatus'+trId).val(0);

		$('#aCategoryId'+trId).css('color', '#000');

	}

}

function checkSubCats(mainCatId)

{

	if($('#mainCategory'+mainCatId).is(':checked'))

	{

		$("#subCatgoriesTR"+mainCatId+" [id^=subCategory"+mainCatId+"-]").prop('checked', 'checked');

	}

	else

	{

		$("#subCatgoriesTR"+mainCatId+" [id^=subCategory"+mainCatId+"-]").prop('checked', '');

	}

} 

</script>

<?php if($setCounter):?>

<script language="javascript">

charPlus();

</script>

<?php endif;?>

<?php

include("footer.php");

ob_end_flush();

?>
