<?php 
  require_once ("../var/res.php");
  ##### ADD  ASSIGN ####
  $conctid = $_REQUEST['conctid'];
  $regid = $_REQUEST['regid'];
  $assignto_ids = $_REQUEST['assignto_ids'];
  $assgnSts = $_REQUEST['assgnSts'];
  $tskcom = $_REQUEST['tskcom'];

  $dt = date('Y-m-d');
  $dtrm = date('Y-m-d H:s:i');
  $sts = 1;
  
  $queCheck = $db->prepare('SELECT *FROM tbl_assign_reqs WHERE conasgn="'.$conctid.'" AND regst_asgn="'.$regid.'" ORDER BY assreq_id DESC LIMIT 1');
  $queCheck->execute();
  if($queCheck->rowCount()==0){
    foreach($assignto_ids as $val)
    {
        if ($val<>0)
        {

        $stmt = $db->prepare("INSERT INTO tbl_assign_reqs (asgn_appoint,conasgn,regst_asgn, dueasgn, asgntrm, status_assign, us_hd_sdr)
        VALUES (:asgn_appoint,:conasgn,:regst_asgn, :dueasgn, :asgntrm, :status_assign, :us_hd_sdr)");
        //if-else statement in executing our prepared statement
        $stmt->execute(array(':asgn_appoint' => $val ,':conasgn' => $conctid ,':regst_asgn' => $regid , ':dueasgn' => $dt , 
        ':asgntrm' => $dtrm ,':status_assign' => $sts, ':us_hd_sdr' => $userid));
        $msg = 1;
        }
    }

    ######## UPDATE DATE NOTE ####
    $updNotes = $db->prepare("UPDATE `tbl_con_infos` SET info_sts=6,assignotes='".$tskcom."' WHERE `con_info_id`=$conctid");
    $updNotes->execute();
    ######## END UPDATE DATE NOTE ####

    ######## UPDATE INFO ####
    $updinfo = $db->prepare("UPDATE `tbl_info_register` SET stts_reg=6 WHERE `regst_id`=$regid");
    $updinfo->execute();
    ######## END INFO ####

 }

?>