<?php 
//****************MODIFY BY AMIT SINGH ************D&D************************23-11-2012*********************************
$table='crm_leadtodo';  include("ClassRole.php");
if($_REQUEST['todoid']=='')
$eventid= $s->GetFieldValue('crm_leadtodo',"lead_type='Visit' ORDER BY todoid DESC   LIMIT 1   ",'todoid')+1 ;
else
$eventid=$_REQUEST['todoid'];

//if($_REQUEST['SaveEvent'])
//{
//	$fstatus=true;
//	if($_REQUEST['leadtodo']=='')
//	{
//	$msgErr[]="Please Enter The Event name";
//	$fstatus=false;
//	}
//	if($_REQUEST['todostatus']=='0')
//	{
//	$msgErr[]="Please Select The Event Status";
//	$fstatus=false;
//	}
//	if($_REQUEST['lead_priority']=='0')
//	{
//	$msgErr[]="Please Select The Lead Priority";
//	$fstatus=false;
//	}
//	if($_REQUEST['hours']=='0')
//	{
//	$msgErr[]="Please Select The Start Time";
//	$fstatus=false;
//	}
//	if($_REQUEST['tododatetime']=='')
//	{
//	$msgErr[]="Please Enter The Start Date";
//	$fstatus=false;
//	}
//	if($_REQUEST['ehours']=='')
//	{
//	$msgErr[]="Please Enter The End Time";
//	$fstatus=false;
//	}
//	if($_REQUEST['tododue_date']=='')
//	{
//	$msgErr[]="Please Enter The End Date";
//	$fstatus=false;
//	}
//}



if($_REQUEST['SaveEvent'])
	{
	$a=explode(" ",$_REQUEST['eventstartat']);
	$startdate=ConvertSQLDate($a[0]);
	$b=explode(" ",$_REQUEST['eventendon']);
	$enddate=ConvertSQLDate($b[0]);
	$data['mst_leadid']=$_REQUEST['mst_leadid'];
	$data['eventstartat']=$startdate;
	$data['eventstarttime']=$a[1];
	$data['eventendon']=$enddate;
	$data['eventendtime']=$b[1];
	//$data['tododue_date']=ConvertSQLDate($_REQUEST['tododue_date']);
	$data['leadtodo']=$_REQUEST['leadtodo'];
	$data['lead_type']=$_REQUEST['lead_type'];
	$data['lead_priority']=$_REQUEST['lead_priority'];
	$data['description']=$_REQUEST['description'];
	$data['send_notification']=$_REQUEST['send_notification'];
	$data['notification_matter']=$_REQUEST['notification_matter'];
	//$data['tododatetime']=ConvertSQLDate($_REQUEST['tododatetime']);
	$data['todostatus']=$_REQUEST['todostatus'];
	$data['groupid']=trim(implode(',',$_REQUEST['groupid']));
	$data['leaduserid']=trim(implode(',',$_REQUEST['leaduserid']));
	$data['event_location']=$_REQUEST['event_location'];
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['todostart_time']=$_REQUEST['hours'].":".$_REQUEST['mins']." ".$_REQUEST['AMPM'];
	$data['todoend_time']=$_REQUEST['ehours'].":".$_REQUEST['emins']." ".$_REQUEST['eAMPM'];
	
	if($_REQUEST['action']=='Edit')
	{	
	$cond="todoid='".$_REQUEST['todoid']."'";
	$row= $s->RecordEdit($table, $data,$cond);
	}
	else
	{
	$row= $s->RecordInsert($table, $data);
	}
	prnMsg(_('Inserted Successfully'),'Success');
	$s->pageLocation("index.php?route=CRM/CrmLeadEvent&leadid=".$_REQUEST['leadid'].$rurl);
}	

if($_REQUEST['action']=='Edit' &&  isset($_REQUEST['todoid']))
{
	$getlead=DB_query( "select * from $table where mst_leadid='".$_REQUEST['leadid']."' and todoid='".$_REQUEST['todoid']."'",$db);
	while($row_lead=DB_fetch_array($getlead))
	{
	$mst_leadid=$row_lead['mst_leadid'];
	$tododue_date=$row_lead['tododue_date'];
	$leadtodo=$row_lead['leadtodo'];
	$lead_type=$row_lead['lead_type'];
	$description=$row_lead['description'];
	$tododatetime=$row_lead['tododatetime'];
	$todostatus=$row_lead['todostatus'];
	$tododue_date=$row_lead['tododue_date'];
	$groupid=$row_lead['groupid'];
	$leaduserid= $row_lead['leaduserid'];
	$event_location=$row_lead['event_location'];
	$send_notification=$row_lead['send_notification'];
	$notification_matter=$row_lead['notification_matter'];
	$lead_priority=$row_lead['lead_priority'];
	$todostart_time=explode(":",$row_lead['todostart_time']);
	$todoend_time=explode(":",$row_lead['todoend_time']);;
	$hours=$todostart_time[0];
	$mins=$todostart_time[1];
	$AMPM=$todostart_time[2];
	$ehours=$todoend_time[0];
	$emins=$todoend_time[1];
	$eAMPM=$todoend_time[2];
	}
}
?>
<script type="text/javascript" src="CRM/datetimepicker/jquery.js"></script>
<script type="text/javascript" src="CRM/datetimepicker/jquery-calendar.js"></script>

<link rel="stylesheet" type="text/css" href="CRM/datetimepicker/jquery-calendar.css" />
<link rel="stylesheet" type="text/css"  href="CRM/datetimepicker/styles.css" />
	<script type="text/javascript">

		//<![CDATA[

			$(document).ready(function (){ 

				$("#calendar1, #calendar2").calendar();
				

				$("#calendar1_alert").click(function(){alert(popUpCal.parseDate($('#calendar1').val()))});
				

			});

		//]]>

		</script>
		<script type="text/javascript" language="javascript">
function selectDate()
{



	
	$date1=document.getElementById("calendar1").value;
	alert($date1);
	//var testing=document.getElementById("validTill").value;
//	var collection = document.getElementById("quotationDate").value;
//    
//     
//       
//       var collection1 =   collection.split("/");
//             
//       var DobDate   = collection1[0];
//       var DobMonth = collection1[1];       
//       var DobYear   = collection1[2];
//   
//       var testing1 =   testing.split("/");
//              
//       var SysDate   = testing1[0];
//       var SysMonth = testing1[1];
//       var SysYear   = testing1[2];
       
       
    // alert("DobYear="+DobYear+"SysYear ="+SysYear +"DobMonth="+DobMonth+"SysMonth="+SysMonth+"DobDate="+DobDate+"SysDate="+SysDate);
       
       
	   
	  
	 
	 //  if(DobYear > SysYear)
//       {
//         alert("Till Date  cannot be less than Quotations Date ");
//		 document.getElementById("validTill").value='';
//		 document.getElementById("validTill").focus();
//         return false;      
//       }
//       else if((DobYear == SysYear) && (DobMonth > SysMonth))
//       {
//         alert("Till Date  cannot be less than Quotations Date ");
//		 document.getElementById("validTill").value='';
//		 document.getElementById("validTill").focus();
//         return false; 
//       }
//       
//        else if((DobYear == SysYear) && (DobMonth == SysMonth) && (DobDate > SysDate))
//       {
//         alert("Till Date  cannot be less than Quotations Date ");
//		 document.getElementById("validTill").value='';
//		 document.getElementById("validTill").focus();
//         return false;
//       }
//	   
//      
//         return true;

}
</script>

<link href="css/add_event.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/general.css" type="text/css" media="screen" />
<?php  include('crm_top_menu.php'); ?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<form action="" method="post">
    <input name="mst_leadid" type="hidden" value="<?php  echo $_REQUEST['leadid']?>">
    <div id="container">
      <ul class="menu">
        <li id="news" class="active">Calendar</li>
        <li id="tutorials">All Events & Todos</li>
      </ul>
      <span class="clear"></span>
      <div class="content news"><br />
        <br />
        <h3 style="padding-bottom:8px;">Add Event</h3>
		
		<div align="right">
        <a href="<?php echo "index.php?route=CRM/CrmLeadEvent&leadid=".$_REQUEST['leadid'].$rurl?>">Add New Event     </a></div>
        <!--form 1 -->
        <table width="100%" border="0" cellspacing="0" cellpadding="3">
          <tr class="row1">
            <td colspan="6" style="font-size:14px; font-weight:400;padding-top:5px; padding-bottom:5px; padding-left:10px; background-color:#666666; color:#FFFFFF;"> Event Information:-</td>
          </tr>
          <?php
	if(count($msgErr)>0)
	{?>
		<tr>
	<td colspan="6">
		<?php 
		for($i=0;$i<count($msgErr);$i++)
		{
		echo "<div class='error'>".$msgErr[$i]."</div>";	
		}?>
		</td>
		</tr>
		<?php
	}
	
	?>
          <tr class="row1">
            <td class="tabledata1">Event No.</th>
            <td width="20%"><input type="text" style="width:150px; height:25px; background-color:#f1f1f1; height:25px;"  value="E00<?php  echo $eventid;?>"/></td>
            <td class="tabledata1">Event Type</th>
            <td width="16%"><select   name="lead_type" style="width:120px; padding-top:4px; padding-bottom:4px;">
                <option id="0">--</option>
                <option id="Visit" <?php  echo ($lead_type=='Visit'?'selected':'')?>>Visit</option>
              </select>
            </td>
            <td class="tabledata1">Event Name <label><font color="#FF0000">*</font></label>   </th>
            <td width="20%"><input type="text" name="leadtodo" value="<?php echo $leadtodo?>" style="width:150px; height:25px; background-color:#f1f1f1; height:25px;"></td>
          </tr>
          <tr class="row1">
            <td class="tabledata1">Location<label><font color="#FF0000">*</font></label></th>
            <td><input type="text" name="event_location" value="<?php echo $event_location?>" style="width:150px; height:25px; background-color:#f1f1f1; height:25px;">
            </td>
            <td class="tabledata1">Priority</th>
            <td><select style="width:120px; padding-top:4px; padding-bottom:4px;" name="lead_priority">
                <option value="0">--Select--</option>
                <option value="High" <?php  echo ($lead_priority=='High'?'selected':'')?>>High</option>
                <option value="Low" <?php  echo ($lead_priority=='Low'?'selected':'')?>>Low</option>
                <option value="Medium" <?php  echo ($lead_priority=='Medium'?'selected':'')?>>Medium</option>
              </select>
            </td>
            <td class="tabledata1">Event Status <label><font color="#FF0000">*</font></label></th>
            <td><select name="todostatus"  style="width:150px; padding-top:4px; padding-bottom:4px;">
            	<option value="0">--Select--</option>
                <option value="Pending" <?php echo $todostatus=='Pending'?'selected':''?> >Pending</option>
                <option value="Confirm"   <?php echo $todostatus=='Confirm'?'selected':''?> >Confirm</option>
              </select>
            </td>
          </tr>
          <tr class="row1">
            <td class="tabledata1" colspan="1">Event Description</th>
            <td colspan="5"><textarea name="description"   style="width:670px;" ><?php echo $description?> </textarea>
            </td>
          </tr>
        </table>
        <div style="width:auto; margin:0px;">
          <table width="100%" border="0" cellspacing="0" cellpadding="3">
            <tr class="row1">
              <td colspan="6" style="font-size:14px; font-weight:400;padding-top:5px; padding-bottom:5px; padding-left:10px; background-color:#666666; color:#FFFFFF;">Group & User Assignment:-</td>
            </tr>
            <tr class="row1">
              <td width="12%" class="tabledata1">Group
                <label><font color="#FF0000">*</font></label></th>
              <td width="8%"><?php echo $ClassRole->Role($groupid);?></td>
              <td width="14%" class="tabledata1">User
              <label><font color="#FF0000">*</font></label></td>
              <td width="15%"><div id='hid-Roleid'>
<?php  
$user=explode(',',$leaduserid);
 $sql_state=DB_query("SELECT id , realname FROM  www_users where rolepid ='".$groupid."' ",$db);
while($row=DB_fetch_array($sql_state))
{
	
	$p='';
 	 if (in_array($row['id'],  $user))
	 $p='checked';

?>
 <input name="leaduserid[]" type="checkbox" value="<?php  echo $row['id'];?>"  <?php echo $p;?>   /><?php  echo $row['realname'];?><br />
 <?php 
 }
if(!$leaduserid)
{
 echo "<select name='leaduserid[]' style='width:150px;'  >";
echo "<option value='000'>---</option>";
 echo "</select>";
}
?>	
	</div></td>
              <td width="28%" class="tabledata1">Send Notification</th>
              <td width="23%">&nbsp;&nbsp;&nbsp;
              <input name="send_notification" type="checkbox" value="1" <?php echo ($send_notification=='Y'?'checked':'');?>  /></td>
            </tr>
            <tr class="row1">
              <td class="tabledata1" colspan="1">Notification Text Matter</th>
              <td colspan="5"><textarea style="width:670px;" name="notification_matter"><?php echo trim($notification_matter) ?> </textarea>
              </td>
            </tr>
          </table>
        </div>
        <div style="clear:both;"></div>
        <br />
        <hr />
        <br />
        <table width="100%" border="0" cellspacing="0" cellpadding="3">
          <tr class="row1">
            <td style="width:50%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr class="row1">
                  <td class="tabledata1" colspan="3" style="padding-top:5px; padding-bottom:5px;"><strong>Event Scheduling :---</strong></td>
                </tr>
                <tr class="row1">
                  <td class="tabledata1" colspan="3" style="padding-top:5px; padding-bottom:5px;">Event Start at<label><font color="#FF0000">*</font></label></td>
                </tr>
                <tr class="row1">
                  <td colspan="3" class="tabledata1" style="padding-top:5px; padding-bottom:5px;"><table width="50%" border="0">
                      <tr class="row1">
                       <td colspan="3" style="padding-top:5px; padding-bottom:5px;">
                  	<input type="text" name="eventstartat" id="calendar1" style="width:129px;"  value="" onchange="selectDate()" >
                  </td>
                      </tr>
                    </table></td>
                </tr>
              </table></td>
            <td width="20px;">&nbsp;</td>
            <td width="50%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td colspan="3" style="padding-top:5px; padding-bottom:5px;">&nbsp;</td>
                </tr>
                <tr class="row1">
                  <td class="tabledata1" colspan="3" style="padding-top:5px; padding-bottom:5px;">Event End on<label><font color="#FF0000">*</font></label></td>
                </tr>
                <tr class="row1">
                  <td colspan="3" class="tabledata1" style="padding-top:5px; padding-bottom:5px;"><table width="50%" border="0">
                      <tr class="row1">
                        <td colspan="3" class="tabledata1" style="padding-top:5px; padding-bottom:5px;">
<input type="text" name="eventendon" id="calendar2"  value="" style="width:129px;"/>
						</td>
                      </tr>
                    </table></td>
                </tr>
              </table></td>
          </tr>
        </table>
        <!--Close form 1 -->
        <!--Fotoer mentu -->
        <div>
          <div id="container1">
            <ul class="menu">
              <li id="news1">Reminder</li>
              <li id="tutorials1">Repeat</li>
              <li id="links1">Invite Users &  Email</li>
            </ul>
            <span class="clear"></span>
            <div class="content news1">
              <h1>&nbsp;</h1>
              Send Reminder&nbsp;&nbsp;
              <input name="yes" type="radio" value="" />
              &nbsp;Yes&nbsp;&nbsp;
              <input name="yes" type="radio" value="" />
              &nbsp;No </div>
            <div class="content tutorials1">
              <h1>&nbsp;</h1>
              Enable Repeat&nbsp;&nbsp;
              <input name="yes" type="radio" value="" />
              &nbsp;Yes&nbsp;&nbsp;
              <input name="yes" type="radio" value="" />
              &nbsp;No </div>
            <div class="content links1">
              <h1>Heading 1</h1>
              dslkfajf </div>
            <div class="cl"></div>
          </div>
          <div class="cl"></div>
        </div>
        <div class="cl"></div>
        <input type="submit"  name='SaveEvent' value="Save" style="font-size:14px;" class="bottonsview" />
      </div>
      <div class="content tutorials"> <br />
        
          <h1>Events</h1>
        
		<br />
        <table width="100%" border="0" cellspacing="0" cellpadding="3">
          <tr  bgcolor="#CCCCCC" height="25px;" style="font-weight:bold;"  >
            <td class="tabledata">Status </td>
            <td class="tabledata">Type</td>
            <td class="tabledata">Subject</td>
            <td class="tabledata">Start Date</td>
            <td class="tabledata">End Date</td> 
	    <td class="tabledata">Status</td>
            <td class="tabledata">Group</td>
            <td class="tabledata">Action</td>
          </tr>
          <?php $i=1;
      $getlead=DB_query( "select * from $table A,crm_leads B where B.leadid='".$_REQUEST['leadid']."' and A.mst_leadid=B.leadid  and A.lead_type!='Task'",$db);
	 while($row_lead=DB_fetch_array($getlead))
	 {
	 ?>
          <tr bgcolor="#dfdfdf">
            <td><?php  echo $row_lead['todostatus'];// ConvertSQLDate($row_lead['created_date'])?>
            </td>
            <td><?php  echo $row_lead['lead_type'];?></td>
            <td><?php  echo $row_lead['lead_subject']?></td>
            <td><?php  echo ConvertSQLDate($row_lead['tododatetime']);
			echo 	'&nbsp;&nbsp;'.$row_lead['todostart_time'];		?></td>
            <td><?php  echo ConvertSQLDate($row_lead['tododue_date']);
			echo 	'&nbsp;&nbsp;'.$row_lead['todoend_time'];
		?></td>
		 <td><?php  echo $row_lead['todostatus']?></td>
            <td><?php  echo $s->GetFieldValue('securityroles',"secroleid='".$row_lead['groupid']."'" ,'role_name');
	?></td>
            <td><a href="index.php?route=CRM/CrmLeadEvent&action=Edit&leadid=<?php echo $row_lead['leadid'].$rurl;?>&todoid=<?php echo $row_lead['todoid']?>"> <img src="images/icon_edit.gif" width="10px"  height="10" /></a> </td>
          </tr>
          <?php $i++; } ?>
        </table>
      </div>
      <div style="clear:both;"></div>
      <br />
    </form>    </div>
   <div style="clear:both;"></div>
    <div class="cl"></div>
  </div>

<!--	<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
-->
<script type="text/javascript" src="js/tabs.js"></script>
<div class="cl"></div>
