<?php require_once('../Connections/oprmConn.php');

$date = date("Y-m-d");



if(isset($_POST['announce_sub'])){
  $file_path = '';

	$sdate = date("Y-m-d",strtotime($_POST['sdate']));

	if($_FILES["file"]["name"] != ''){		

		$allowedExts = array("pdf", "jpeg", "jpg", "png","tiff", "rtf", "docs", "docx", "doc", "mov", "mp3", "mp4", "vob", "txt", "rtf", "csv", "xls", "xlsx", "csv", "PDF", "JPEG", "JPG", "PNG","TIFF", "RTF", "DOCS", "DOCX", "DOC", "MOV", "MP3", "MP4", "VOB", "TXT", "RTF", "CSV", "XLS", "XLSX", "CSV");

		$path1 = "../images/";

		$extension1 = explode(".", $_FILES["file"]["name"]);

		$extension = end($extension1);

		//echo $_FILES["file"]["name"];

		

		if (($_FILES["file"]["size"] < 10000000000) && in_array($extension, $allowedExts)) {



			if ($_FILES["file"]["error"] == 0) {

			$tkn = rand(0001,9999);

			$name = basename($_FILES["file"]["name"], ".".$extension);

			$filename = $name."_".$tkn.".".$extension;

			//$filename = $name.".".$extension;

			$fullpath = '/images/'.$filename;
      $file_path = dirname(__DIR__) . '/images/' . $filename;
      $file_path = str_replace('//', '/', $file_path);
			move_uploaded_file($_FILES["file"]["tmp_name"], "$path1/$filename");



}	

		}			

		}

mysql_select_db($database_oprmConn, $oprmConn);

//$announce_sub = REPLACE("$_POST[announce_sub]", "'", "/'");
   $announce_sub = mysql_real_escape_string(trim($_POST[announce_sub]));
   
   //$announce_msg = REPLACE("$_POST[announce_msg]", "'", "/'");
  $announce_msg = mysql_real_escape_string(trim($_POST[announce_msg]));
   

	$query_getannounce = "INSERT INTO weby_announcement (`subject`, `message`, `sent_date`, `file_name`, `status`, `created_by`, `created_date`) VALUES ('$announce_sub', '$announce_msg', '$sdate', '$fullpath', 'A', '$_SESSION[user_id]', '$date')";

	$getannounce = mysql_query($query_getannounce, $oprmConn) or die(mysql_error());


	



$anounsubject=$_POST['announce_sub'];

$anounmessage=$_POST['announce_msg'];

/*to get all resources email id's*/

mysql_select_db($database_oprmConn, $oprmConn);

$query_getanouncemail = "SELECT weby_profiles.*, weby_users.* FROM weby_profiles, weby_users WHERE weby_users.status = 'A' AND weby_profiles.status = 'A' AND weby_profiles.user_id = weby_users.user_id";

$getanouncemail = mysql_query($query_getanouncemail, $oprmConn) or die(mysql_error());

$row_getanouncemail = mysql_fetch_assoc($getanouncemail);

$totalRows_getanouncemail = mysql_num_rows($getanouncemail);
  

do{


  $user_email = $row_getanouncemail['email_address'];


    $headers = 'MIME-Version: 1.0' . "\r\n";



       $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";



       $headers .= "From: $SERVER_EMAIL" . "\r\n" ;



  $subject = "$anounsubject";



  $body = "$anounmessage";

  include_once '../../PHPMailer/PHPMailerAutoload.php';
  //mail_send($user_email, $subject, $body, $file_path);


mail($user_email, $subject, $body, $headers);





}while($row_getanouncemail = mysql_fetch_assoc($getanouncemail));


header("Location: announcement-list.php?msgcrtannonce");

}

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;



  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);



  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;    

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}



$maxRows_getTimeSheet = 10;

$pageNum_getTimeSheet = 0;

if (isset($_GET['pageNum_getTimeSheet'])) {

  $pageNum_getTimeSheet = $_GET['pageNum_getTimeSheet'];

}

$startRow_getTimeSheet = $pageNum_getTimeSheet * $maxRows_getTimeSheet;



mysql_select_db($database_oprmConn, $oprmConn);

$query_getTimeSheet = "SELECT weby_timesheets.timesheet_id, weby_timesheets.user_id, weby_timesheets.total_hrs, weby_timesheets.hr_rate, weby_timesheets.total_amount, weby_profiles.full_name, weby_projects.project_name, weby_timesheets.created_date, weby_timesheetstatus.status_label FROM weby_timesheets, weby_profiles, weby_projects, weby_timesheetstatus WHERE weby_timesheets.created_by = weby_profiles.user_id  AND weby_projects.projetc_id = weby_timesheets.project_id AND weby_timesheetstatus.status = 'A'  AND weby_timesheetstatus.status_key = weby_timesheets.status AND weby_timesheetstatus.status_label!= 'Deleted' order by weby_timesheets.updated_date desc";

$query_limit_getTimeSheet = sprintf("%s LIMIT %d, %d", $query_getTimeSheet, $startRow_getTimeSheet, $maxRows_getTimeSheet);

$getTimeSheet = mysql_query($query_limit_getTimeSheet, $oprmConn) or die(mysql_error());

$row_getTimeSheet = mysql_fetch_assoc($getTimeSheet);



if (isset($_GET['totalRows_getTimeSheet'])) {

  $totalRows_getTimeSheet = $_GET['totalRows_getTimeSheet'];

} else {

  $all_getTimeSheet = mysql_query($query_getTimeSheet);

  $totalRows_getTimeSheet = mysql_num_rows($all_getTimeSheet);

}

$totalPages_getTimeSheet = ceil($totalRows_getTimeSheet/$maxRows_getTimeSheet)-1;



$maxRows_getRes = 2;

$pageNum_getRes = 0;

if (isset($_GET['pageNum_getRes'])) {

  $pageNum_getRes = $_GET['pageNum_getRes'];

}

$startRow_getRes = $pageNum_getRes * $maxRows_getRes;



mysql_select_db($database_oprmConn, $oprmConn);

$query_getRes = "SELECT weby_users.user_id, weby_users.email_address, weby_users.caeated_date, weby_profiles.profile_id, weby_profiles.full_name, weby_profiles.job_title, weby_profiles.skill_set, weby_profiles.profile_pic FROM weby_users, weby_profiles WHERE weby_users.status = 'P' AND weby_profiles.user_id = weby_users.user_id";

$query_limit_getRes = sprintf("%s LIMIT %d, %d", $query_getRes, $startRow_getRes, $maxRows_getRes);

$getRes = mysql_query($query_limit_getRes, $oprmConn) or die(mysql_error());

$row_getRes = mysql_fetch_assoc($getRes);



if (isset($_GET['totalRows_getRes'])) {

  $totalRows_getRes = $_GET['totalRows_getRes'];

} else {

  $all_getRes = mysql_query($query_getRes);

  $totalRows_getRes = mysql_num_rows($all_getRes);

}

$totalPages_getRes = ceil($totalRows_getRes/$maxRows_getRes)-1;



$maxRows_getRes1 = 2;

$pageNum_getRes1 = 0;

if (isset($_GET['pageNum_getRes1'])) {

  $pageNum_getRes1 = $_GET['pageNum_getRes1'];

}

$startRow_getRes1 = $pageNum_getRes1 * $maxRows_getRes1;



mysql_select_db($database_oprmConn, $oprmConn);

$query_getRes1 = "SELECT weby_users.user_id, weby_users.email_address, weby_users.caeated_date, weby_profiles.profile_id, weby_profiles.full_name, weby_profiles.job_title, weby_profiles.skill_set, weby_profiles.profile_pic FROM weby_users, weby_profiles WHERE weby_profiles.status = 'A' AND weby_users.status = 'A' AND weby_users.user_role <> 1 AND weby_profiles.user_id = weby_users.user_id order by weby_profiles.profile_id desc";

$query_limit_getRes1 = sprintf("%s LIMIT %d, %d", $query_getRes1, $startRow_getRes1, $maxRows_getRes1);

$getRes1 = mysql_query($query_limit_getRes1, $oprmConn) or die(mysql_error());

$row_getRes1 = mysql_fetch_assoc($getRes1);



if (isset($_GET['totalRows_getRes1'])) {

  $totalRows_getRes1 = $_GET['totalRows_getRes1'];

} else {

  $all_getRes1 = mysql_query($query_getRes1);

  $totalRows_getRes1 = mysql_num_rows($all_getRes1);

}

$totalPages_getRes1 = ceil($totalRows_getRes1/$maxRows_getRes1)-1;

 ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>SS WEB TECHNOLOGIES - Tool-Admin-DashBoard</title>

<link rel="stylesheet" href="../css/style.css" type="text/css">

<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">

  <script src="//code.jquery.com/jquery-1.10.2.js"></script>

  <script src="//code.jquery.com/ui/1.9.1/jquery-ui.js"></script>

    <!-- IE Fix for HTML5 Tags -->

    <!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 

	<![endif]-->

     <style>

.act_announcement { background: #373938;

  color: #fff;}

  textarea{

	  height:125px;

  }

</style>

<script>

$(function() {

   $( "#sdate" ).datepicker();

});



</script>

</head>



<body>





<!-- Wrapper Starts -->



<div class="wrapper">



    <?php  require_once('../includes/header.php'); ?>

    

<?php  require_once('../includes/tools-menu.php'); ?>

  <!-- Content Goes here -->

    <article class="inside_wrapper clear_fix">

    

    	<!-- Main Content Goes here -->

      <section class="main_content">

    		  <!--<h1>Current Timesheets</h1>

            

             

               <!--<div class="welcome_box">

                <div class="timesheet_type"><div class="welcome_txt arrow">Welcome Admin

            	<ul> <li><a href="index.php">Dashboard</a></li>

                <li><a href="timesheet-all.php">Time sheet</a></li>

                <li><a href="project-list.php">Projects</a></li>

            	<li><a href="resources-list.php">Resources</a></li>

            	<li><a href="profile.php">Profile</a></li>

                <li><a href="leave-list.php">Leave Manager</a></li>

                 <li><a href="reports.php">Records</a></li>

            	<li><a href="logout.php">Logout</a></li>

            	</ul>	

                </div>

                </div>	

             </div> --> 

             

    		<!-- Timesheets Goes here -->

      	   	<?php /*?> <div class="timesheet_table">

             	<div class="column_title">

                	<span class="item_wide">Timesheet #</span><span class="item_wide">Date Submitted</span><span class="item_wide">Resource</span><span class="item_wide">Project</span><span class="item_small">Status</span><span class="item_small">Hours</span><span class="item_small">Action</span><!--<span class="item_small">Rate(£)</span><span class="item_small">Total</span>-->

                </div>

                <?php if($totalRows_getTimeSheet>0) { do { ?>

                 <div class="row <?php if($n==0) { echo "yellow"; $n=1; } else $n=0; ?>">

                    <span class="item_wide"><?php echo $row_getTimeSheet['timesheet_id']; ?></span><span class="item_wide"><?php echo date('d/M/Y',strtotime($row_getTimeSheet['created_date'])); ?></span><span class="item_wide" title="<?php echo $row_getTimeSheet['full_name']; ?>"><?php echo $rest = substr($row_getTimeSheet['full_name'], 0, 10); ?>...</span><span class="item_wide" title="<?php echo $row_getTimeSheet['project_name']; ?>"><?php echo  $rest = substr($row_getTimeSheet['project_name'], 0, 10); ?></span><span class="item_small"><?php echo $row_getTimeSheet['status_label']; ?></span><span class="item_small"><?php echo $row_getTimeSheet['total_hrs']; ?></span><span class="item_small"><a href="timesheet-view.php?timesheetid=<?php echo $row_getTimeSheet['timesheet_id']; ?>"><b>View</b></a></span><!--<span class="item_small"><?php echo $row_getTimeSheet['hr_rate']; ?></span><span class="item_small"><?php echo $row_getTimeSheet['total_amount']; ?></span>   -->                  </div>

               <?php } while ($row_getTimeSheet = mysql_fetch_assoc($getTimeSheet)); } else echo "<div>No records found</div>";?>

                  

               <h4><a href="timesheet-all.php" >View all timesheets >></a></h4>

        </div><?php */?>

        

        <!-- dislpay the expiring passport details -->

        

       <div class="admin_container"> 

       <h1>Announcement</h1>

             	<form name="create_client_form" enctype="multipart/form-data" action="" method="POST" id="create_announcement" onsubmit="return validateForm()">

                    <div class="field_item">

						<label for="project_name">Subject:</label>

                		<input type="text" name="announce_sub" id="announce_sub" class="announce_sub">

                    </div>

					<div class="field_item">

						<label for="project_date">Date:</label>

                		<input type="text" name="sdate" id="sdate" class="announce_date">

                    </div>

					<div class="field_item">

						<label for="project_file">File:</label>

                		<input type="file" name="file" id="file" class="announce_file">

                    </div>

                     <div class="field_item">

						<label for="client_name">Message:</label>

                        <textarea name="announce_msg" id="announce_msg" class="announce_msg"></textarea>

                    </div>

                  <div class="action_items">

                    	<input name="submit" type="submit" class="save_btn" onclick="MM_validateForm('client_name','','R','client_contact_name','','R','clint_mail','','R','clint_phone','','R','clint_address','','R');return document.MM_returnValue" value="Send">

                        <input type="reset" value="Cancel" class="reset_btn"  onClick="window.location= 'announcement-list'">

                    </div>

                    <div class="clear-fix">&nbsp;</div>

                    <input type="hidden" name="MM_insert" value="create_pro_form">

           	   </form>

        </div>

     

        <!-- /end / -->

        </section>

    

    	<!-- Sidebar Goes here -->

        <aside class="sidebar"> 

       	  <?php /*?><div class="featured">

            	<h2 class="white_txt">PENDING RESOURCES</h2>

                <?php if($totalRows_getRes>0) { do { ?>

                <div class="profile_box">

                    <a href="resources-view.php?user_id=<?php echo $row_getRes['user_id']; ?>"><img src="/RM/images/<?php if(!empty($row_getRes['profile_pic'])) echo $row_getRes['profile_pic']; else echo "black-img.jpg";?>" width="68" /></a>

                    <p class="profile_title"><a href="resources-view.php?user_id=<?php echo $row_getRes['user_id']; ?>"><?php echo $row_getRes['full_name']; ?></a><span class="desig"><br />

                    <?php echo $row_getRes['job_title']; ?></span></p>

                <p class="profile_desc"><?php echo $row_getRes['skill_set']; ?></p>

                  <div class="clear-fix">&nbsp;</div>

            </div>

          <?php } while ($row_getRes = mysql_fetch_assoc($getRes)); } else { echo "<div>No Pending Resources</div>";}?></div><?php */?>

       	  <h2>ACTIVE RESOURCES</h2>

         <form action="resources-list.php" method="post" id="act_resource_search">

         <input name="search" type="text" size="30" /> 

         <input name="submit" type="submit" value="Search" />

         </form>

         

         

                <?php if($totalRows_getRes1>0) { do { ?>

                  <div class="profile_box">

                    <a href="resources-view.php?user_id=<?php echo $row_getRes1['user_id']; ?>"><img src="/RM/images/<?php if(!empty($row_getRes1['profile_pic'])) echo $row_getRes1['profile_pic']; else echo "black-img.jpg";?>" width="68" /></a>

                    <p class="profile_title"><a href="resources-view.php?user_id=<?php echo $row_getRes1['user_id']; ?>"><?php echo $row_getRes1['full_name']; ?></a><span class="desig"><br />

                    <?php echo $row_getRes1['job_title']; ?></span></p>

                  <p class="profile_desc"><?php echo $row_getRes1['skill_set']; ?></p>

                    <div class="clear-fix">&nbsp;</div>

                        </div>

                  <?php } while ($row_getRes1 = mysql_fetch_assoc($getRes1)); } else { echo "<div>No Active Resources</div>";} ?>

                  

                  <!-- <div class="profile_box"> <a href="resources-view.php?user_id=1234"><img src="/RM/images/black-img.jpg" /></a>

                    <p class="profile_title"><a href="resources-view.php?user_id=1234">David Masciana</a><span class="desig"><br />

				  IT Business Analyst</span></p>

                    <p class="profile_desc">Cisco IP knowledge is preferred to Cisco CCNA/Juniper JNCIA and similar level 		

                    ....</p>

                <div class="clear-fix">&nbsp;</div>

          </div> -->

          

          <h4><a href="resources-list.php">View all >></a></h4>

   	  </aside>

    

    	 

    

     	<div class="clear-fix">&nbsp;</div> 

        

  </article>

    

     	<div class="clear-fix">&nbsp;</div>

    <!-- Footer Goes here -->

     <?php  require_once('../includes/footer.php'); ?>

    

    

</div>

</body>

</html>

<?php

mysql_free_result($getTimeSheet);



mysql_free_result($getRes);



mysql_free_result($getRes1);



mysql_free_result($getPassEx);

?>