<?php 
// Include main file
include_once('../libs/main.php');
// Check admin Login
include_once('checkLogin.php');
// Logical section of page
$cconsultationObj =  new cconsultation();


if(isset($_REQUEST['act']) && $_REQUEST['act']=='edit' && isset($_REQUEST['cconsultation_id'])){
    $cconsultationDetail = $cconsultationObj->fromId($_REQUEST['cconsultation_id']);
}
$clinicObj = new clinic();
$clinicDetails = $clinicObj->fromId($_REQUEST['clinic_id']);

if(isset($_POST['submit'])){

	$data=array(
      'cconsultation_speciality_id'=>trim(implode(",", $_POST['cconsultation_speciality_id'])),
      'cconsultation_clinic_id'=>trim($_REQUEST['clinic_id']),
      'cconsultation_name'=>trim($_POST['cconsultation_name']),
      'cconsultation_price'=>trim($_POST['cconsultation_price']),
      'cconsultation_duration'=>trim($_POST['cconsultation_duration']),
      'cconsultation_desc'=>trim($_POST['cconsultation_desc']),
    );
    if(isset($_POST['cconsultation_status'])){
        $data['cconsultation_status'] 			= '1';
    }else{
        $data['cconsultation_status'] 			= '0';
    } 
    if (isset($_POST['cconsultation_id'])){
        $id=$_POST['cconsultation_id'];
        $rs=$cconsultationObj->updateRecords($data,$id);
        $successMsg = base64_encode(RECORD_UPDATE);
        if ($rs){
            header('Location:clinic_consultationlist.php?clinic_id='.$_REQUEST['clinic_id'].'&successMsg='.$successMsg);
                exit;
        }
	}else{
        $data['cconsultation_domain_id']=$clinicDetails->clinic_domain;
        $data['cconsultation_created_at']=date("Y-m-d H:i:s");
        $rs = $cconsultationObj->addRecords($data);
        if($rs){
            $successMsg = base64_encode(RECORD_ADD);			
            header('Location:clinic_consultationlist.php?clinic_id='.$_REQUEST['clinic_id'].'&successMsg='.$successMsg);
            exit;
        }
	}
}

$specialityObj = new speciality();
$where = "speciality_id IN (".$clinicDetails->clinic_primary_speciality.")";
$arg = array('where'=>$where);
$allspecialities  =$specialityObj->getAllRecords($arg);
// Include Template 
include_once('../libs/routs.php')

?>