Sindbad~EG File Manager
<?php
class VTController extends BaseController {
//VT get
public function getVT($id = null){
$categories = array('' => '--select--') + Category::VT();
$membership = CustomClass::GetMembership();
$pres_auth_id = 0;
try {
if($id != null )
$id = intval(urldecode(Helper::decrypt($id)));
} catch (Exception $e) {
return Redirect::to('dashboard');
}
if($id>0)
{
$vt = Abstracts::find($id);
if($vt != null)
{
if($vt->user_id != CustomClass::getUserId())
{
return Redirect::to('dashboard');
}
else if($vt->status_id ==CustomClass::$Submitted)
{
return Redirect::to('dashboard');
}
$pa_author = Authors::where('abs_id',$vt->abs_id)->where('role_id',CustomClass::$PresentingAuthor)->first();
if($pa_author !=null)
{
$pres_auth_id = $pa_author->user_id;
}
}
}
else
{
if($this->is_closed())
{
return Redirect::to('abstracts?type=VT');
}
else
{
//dump creat table after step new fp
$vt = new Abstracts();
$vt->user_id = CustomClass::getUserId();
$vt->abs_type = CustomClass::$VT;
$vt->save();
return Redirect::to('vt/'.urlencode(Helper::encrypt($vt->abs_id)));
}
// if($this->is_closed())
// {
// return Redirect::to('dashboard');
// }
}
return View::make('vt.vt')
->with('vt',$vt)
->with('pres_auth_id',$pres_auth_id)
->with('categories',$categories)
->with('membership',$membership);
}
public function is_closed()
{
$vts = Abstracts::where('abs_type','VT')->where('user_id',CustomClass::getUserId())->get();
if(!(CustomClass::$VT_Count > count($vts)))
{
return true;
}
else
{
return false;
}
}
//VT view
public function view($id){
$categories = array('' => '--select--') + Category::VT();
if($id != null )
$id = intval(urldecode(Helper::decrypt($id)));
$vt = null;
if($id>0)
{
$vt = Abstracts::find($id);
$arr = $this->get_COA_Count($vt->abs_id);
$user = App::make('UserController')->getUserDetails($vt->user_id);
$pa = Abstracts::usp_get_authors(null,CustomClass::$VT,CustomClass::$PresentingAuthor,$id,null,null);
if(isset($pa[0]))
{
$pa = $pa[0];
}
return View::make('vt.view')->with('vt',$vt)
->with('coas',$arr["coas"])
->with('pa',$pa)
->with('categories',$categories)
->with('user',$user);
}
}
//VT Search user for Presenting Author
public function getSearchMembersPA(){
try { $arr = [];
$data = "";
$msg = "";
$code = 0;
$search = Helper::trimAndTruncate(Input::get('search'),250);
//$vt_id = intval(Input::get('vt_id'));
$data = Abstracts::usp_get_authors($search,CustomClass::$VT,CustomClass::$PresentingAuthor,null,CustomClass::$UserType_VT_PA,null);
if(empty($data))
{
$data = "";
$code = 0;
$msg = "record not found";
}
else
{
$code = 1;
$msg = "";
}
} catch (Exception $e) {
Log::error('VTController - getSearchMembersPA'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
//VT Search user for COA
public function getSearchMembers(){
try {
$arr = [];
$data = "";
$msg = "";
$code = 0;
$search = Helper::trimAndTruncate(Input::get('search'),250);
$data = Abstracts::usp_get_authors($search,CustomClass::$VT,CustomClass::$CoAuthor,null,CustomClass::$UserType_VT_COA,null);
//$data = DB::select("call usp_SearchMembers ('".$search."')");
if(empty($data))
{
$data = "";
$code = 0;
$msg = "record not found";
}
else
{
$code = 1;
$msg = "";
}
} catch (Exception $e) {
Log::error('VTController - getSearchMembers'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
//VT Get Presenting Author
public function getPADetails(){
try {
$arr = [];
$data = "";
$msg = "";
$code = 0;
$pa_id = intval(Input::get('pa_id'));
$data = App::make('UserController')->getUserDetails($pa_id);
if(empty($data))
{
$data = "";
$code = 0;
}
else
{
$code = 1;
$msg = "";
}
} catch (Exception $e) {
Log::error('VTController - getSearchMembersPA'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
//VT Store
public function store()
{
try {
//for Response
$arr = [];
$code = 0;
$msg = "";
$data = "";
$vt_id = intval(Input::get('hdnId'));
$pa_id = intval(Input::get('hdnPAId'));
$is_next = intval(Input::get('hdnIsNext'));
$step = intval(Input::get("hdnStep"));
$is_edit = true;
//for first step only
$categories = array('' => '--select--') + Category::VT();
$membership = CustomClass::GetMembership();
$pres_auth_id = 0;
if($vt_id >0)
$vt = Abstracts::find($vt_id);
else
$vt = new Abstracts();
if($vt != null)
{
$pa_author = Authors::where('abs_id',$vt->abs_id)->where('role_id',CustomClass::$PresentingAuthor)->first();
if($pa_author !=null)
{
$pres_auth_id = $pa_author->user_id;
}
}
if($is_next == 1)
{
if($step ==1)
{
if($vt->status_id ==CustomClass::$Submitted)
{
$code = 0;
$msg = AppMessage::$VT_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";
$data = "";
}
else
{
$vt->abs_type = CustomClass::$VT;
$vt->category_id = Input::get('ddlSection');
$vt->original_category_id = Input::get('ddlSection');
$vt->user_id = CustomClass::getUserId();
$vt->save();
//check and save chief instructor in author table
$author = Authors::where('abs_id',$vt->abs_id)->where('role_id',CustomClass::$ChiefAuthor)->first();
if($author == null)
{
$author = new Authors();
$author->user_id = CustomClass::getUserId();
$author->abs_id = $vt->abs_id;
$author->role_id = CustomClass::$ChiefAuthor;
$author->consent_status_id = CustomClass::$Selected;
$author->save();
}
// $author = Authors::where('abs_id',$vt->abs_id)->where('role_id',CustomClass::$PresentingAuthor)->first();
// if($author == null)
// {
// $author = new Authors();
// $author->user_id = CustomClass::getUserId();
// $author->abs_id = $vt->abs_id;
// $author->role_id = CustomClass::$PresentingAuthor;
// $author->consent_status_id = CustomClass::$Selected;
// $author->save();
// }
$count = $this->get_VTPA_Count($pres_auth_id);
if($count >= CustomClass::$VT_Count)
{
$code = 0;
$msg = AppMessage::$VT_PA_Count;
$data = "";
}
else
{
$code = 1;
$data = View::make('vt.step2')->with('vt',$vt)->render();;
}
}
}
if($step ==2)
{
if($vt->status_id ==CustomClass::$Submitted)
{
$code = 0;
$msg = AppMessage::$VT_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";
$data = "";
}
else
{
$vt->title = Helper::trimAndTruncate(Input::get('txtTitle'),200);
$vt->synopsis = Helper::trimAndTruncate(Input::get('txtSynopsis'),3000);
$vt->save();
$arr = $this->get_COA_Count($vt_id);
$code = 1;
$data = View::make('vt.step3')->with('vt',$vt)
->with('coas',$arr["coas"])
->with('isMaxCount',$arr["isMaxCount"])->render();
}
}
if($step ==3)
{
if($vt->status_id ==CustomClass::$Submitted)
{
$code = 0;
$msg = AppMessage::$VT_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";
$data = "";
}
else
{
if($this->IsRatifiedMembers($vt))
{
$code = 1;
$data = View::make('vt.step4')->with('vt',$vt)->render();
}
else
{
$code = 0;
$msg = AppMessage::$VT_RATIFIED_MEMBER;
$data = "";
}
}
}
if($step == 4)
{
if($vt->status_id ==CustomClass::$Submitted)
{
$code = 0;
$msg = AppMessage::$VT_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";
$data = "";
}
else
{
$vt->is_in_india = Input::get('rbtnIndia');
$vt->is_already_published = Input::get('rbtnIsAlreadyPublished');
$vt->save();
$arr = $this->get_COA_Count($vt_id);
$pa = Abstracts::usp_get_authors(null,CustomClass::$VT,CustomClass::$PresentingAuthor,$vt_id,null,null);
if(isset($pa[0]))
{
$pa = $pa[0];
}
$code = 1;
$data = View::make('vt.step5')->with('vt',$vt)
->with('coas',$arr["coas"])
->with('pa',$pa)
->with('categories',$categories)
->with('membership',$membership)
->with('isMaxCount',$arr["isMaxCount"])->render();
}
}
if($step == 5)
{
if($vt->status_id ==CustomClass::$Submitted)
{
$code = 0;
$msg = AppMessage::$VT_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";
$data = "";
}
else
{
$count = $this->get_VTPA_Count($pres_auth_id);
if($count >= CustomClass::$VT_Count)
{
$code = 0;
$msg = AppMessage::$VT_PA_Count;
$data = "";
}
else
{
if(!($vt->abs_no>0))
{
$is_edit = false;
$vt->submitted_at = date('Y-m-d H:i:s');
$vt->status_id = CustomClass::$Submitted;
$vt->Annual = (Input::get("chkAnnual")==1?1:0);
$vt->MidYear = (Input::get("chkMidYear")==1?1:0);
$result = Abstracts::usp_generate_abs_no(CustomClass::$VT,$vt->abs_id);
$vt->abs_no = $result[0]->abs_no;
}
$vt->save();
//VT mail
$user = App::make('UserController')->getUserDetails($vt->user_id);
$pa = Abstracts::usp_get_authors(null,CustomClass::$VT,CustomClass::$PresentingAuthor,$vt->abs_id,null,null);
if(isset($pa[0]))
{
$pa = $pa[0];
}
$arr = $this->get_COA_Count($vt_id);
if($is_edit)
{
$this->vt_mail_data($user,$pa,$vt,$arr['coas'],$categories);
}
else
{
$this->vt_mail($user,$pa,$vt,$arr['coas'],$categories);
}
$code = 1;
$data = View::make('vt.success')->with('vt',$vt)->with('coas',$arr["coas"])->render();
}
}
}
}
else
{
if($step == 2)
{
$code = 1;
$data = View::make('vt.step1')
->with('vt',$vt)
->with('pres_auth_id',$pres_auth_id)
->with('categories',$categories)
->with('membership',$membership)->render();
}
if($step == 3)
{
$code = 1;
$data = View::make('vt.step2')
->with('vt',$vt)->render();
}
if($step == 4)
{
$arr = $this->get_COA_Count($vt_id);
$code = 1;
$data = View::make('vt.step3')->with('vt',$vt)
->with('coas',$arr["coas"])
->with('isMaxCount',$arr["isMaxCount"])->render();
}
if($step == 5)
{
$code = 1;
$data = View::make('vt.step4')->with('vt',$vt)->render();
}
}
} catch (Exception $e) {
Log::error('VTController - store :'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
//PA Store
public function storePA()
{
try {
//for Response
$arr = [];
$code = 0;
$msg = "";
$data = "";
$vt_id = intval(Input::get('vt_id'));
$pa_user_id = intval(Input::get('pa_user_id'));
$paauthor = Authors::where('abs_id',$vt_id)->where('role_id',CustomClass::$PresentingAuthor)->first();
if($paauthor == null)
{
//presenting author
$pa_author = new Authors();
$pa_author->user_id = $pa_user_id;
$pa_author->abs_id = $vt_id;
$pa_author->role_id = CustomClass::$PresentingAuthor;
$pa_author->consent_status_id = CustomClass::$Selected;
//$pa_author->save();
//$code = 1;
//use for validation
$count = $this->get_VTPA_Count($pa_user_id);
if($count >= CustomClass::$VT_Count)
{
$code = 0;
$msg = AppMessage::$VT_PA_Count;
}
else
{
$code = 1;
$pa_author->save();
}
}
else
{
$code = 1;
}
} catch (Exception $e) {
Log::error('VTController - storePA :'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
//COA Store
public function storeCOA()
{
try {
//for Response
$arr = [];
$code = 0;
$msg = "";
$data = "";
$vt_id = intval(Input::get('vt_id'));
$coa_user_id = intval(Input::get('coa_user_id'));
$coa = new Authors();
$coa->role_id = CustomClass::$CoAuthor;
$coa->abs_id = $vt_id;
$coa->user_id = $coa_user_id;
$coa->consent_status_id = CustomClass::$Selected;
$coa->is_present = 1;
$vt = Abstracts::find($vt_id);
//use for validation
$arr = $this->get_COA_Count($vt_id,$coa_user_id);
if($arr["isDuplicate"])
{
$code = 0;
$msg = AppMessage::$VT_COA_Duplicate;
}
else if($arr["isMaxCount"])
{
$code = 0;
$msg = AppMessage::$VT_COA_Count;
}
else
{
$code = 1;
$coa->save();
}
//use for get coi list
$arr = $this->get_COA_Count($vt_id);
//var_dump($arr);
$data = View::make('vt.step3')
->with('vt',$vt)
->with('coas',$arr["coas"])
->with('isMaxCount',$arr["isMaxCount"])->render();
} catch (Exception $e) {
Log::error('VTController - storeCOA :'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
//VT Get Max FPNo Plus one
public function GetMaxVTNoPlusOne()
{
$vtno = VT::max('vt_no');
return (intval($vtno) + 1);
}
//COA Remove
public function removePA()
{
try {
//for Response
$arr = [];
$code = 0;
$msg = "";
$data = "";
$vt_id = intval(Input::get('vt_id'));
$pa_id = intval(Input::get('pa_id'));
$pa = Authors::where('abs_id',$vt_id)->where('user_id',$pa_id)->where('role_id',CustomClass::$PresentingAuthor)->first();
$pa->delete();
$code = 1;
// $fp = Abstracts::find($fp_id);
// $arr = $this->get_FPCOA_Count($fp_id);
// $code = 1;
// $data = View::make('fp.step3')
// ->with('fp',$fp)
// ->with('coas',$arr["coas"])
// ->with('isMaxCount',$arr["isMaxCount"])->render();
} catch (Exception $e) {
Log::error('FPController - removeCOA :'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
//COA Remove
public function removeCOA()
{
try {
//for Response
$arr = [];
$code = 0;
$msg = "";
$data = "";
$vt_id = intval(Input::get('vt_id'));
$coa_id = intval(Input::get('coa_id'));
$coa = Authors::find($coa_id);
$coa->delete();
$vt = Abstracts::find($vt_id);
$arr = $this->get_COA_Count($vt_id);
$code = 1;
$data = View::make('vt.step3')
->with('vt',$vt)
->with('coas',$arr["coas"])
->with('isMaxCount',$arr["isMaxCount"])->render();
} catch (Exception $e) {
Log::error('VTController - removeCOA :'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
//Get PA Count for validation
public function get_VTPA_Count($pa_uid)
{
try {
$isMaxCount = false;
$users = null;
$users = Abstracts::usp_get_abstracts(null,null,null,null,null,null,null,$pa_uid,null,null,null,null);
$pa_count = 0;
foreach ($users["engaged"] as $key => $value) {
if($value->abs_type==CustomClass::$VT && $value->role_id==CustomClass::$PresentingAuthor && $value->status_id == CustomClass::$Submitted && $value->MidYear == 1)
{
$pa_count++;
}
}
} catch (Exception $e) {
Log::error('VTController - get_VTCOA_Count :'.$e->getMessage());
}
return $pa_count;
}
//Get COA and COA Count for validation
public function get_COA_Count($vt_id,$coa_uid = null)
{
$isMaxCount = false;
$isDuplicate = false;
$coas = Abstracts::usp_get_authors(null,CustomClass::$VT,CustomClass::$CoAuthor,$vt_id,null,null);
$coa_uids = [];
foreach ($coas as $key => $value) {
if($coa_uid == $value->user_id)
{
$isDuplicate =true;
}
array_push($coa_uids, $value->user_id);
}
if(count(array_unique($coa_uids)) >= CustomClass::$VT_COA_Count)
{
$isMaxCount = true;
}
return ["isMaxCount" => $isMaxCount,"isDuplicate" => $isDuplicate ,"coas" => $coas];
}
//RATIFIED MEMBER Check for vt
public function IsRatifiedMembers($vt)
{
$isretified = false;
$ca = App::make('UserController')->getUserDetails($vt->user_id);
if($ca->user_type_id==CustomClass::$Ratified_Member)
{
$isretified = true;
}
// $pa = App::make('UserController')->getUserDetails($vt->pres_auth_id);
// if(!empty($pa->membership_no))
// {
// $isretified = true;
// }
$pa = Abstracts::usp_get_authors(null,CustomClass::$VT,CustomClass::$PresentingAuthor,$vt->abs_id,null,null);
if(isset($pa[0]))
{
$pa = $pa[0];
if($pa->user_type_id==CustomClass::$Ratified_Member)
{
$isretified = true;
}
}
$arr = $this->get_COA_Count($vt->abs_id);
foreach ($arr['coas'] as $key => $value) {
if($value->user_type_id==CustomClass::$Ratified_Member)
{
$isretified = true;
}
}
return $isretified;
}
//VT Mail Send add cc COA
public function vt_mail($user,$pa,$vt,$coa,$categories)
{
if(empty($user->email))
{
return;
}
if(CustomClass::$IsEmailEnabled)
{
$isMailSend = Mail::send('emails.vt.chiefauthor', array('user' => $user,'vt' =>$vt,'coa' =>$coa,'pa'=>$pa,'categories'=>$categories), function($message) use ($coa,$vt,$user,$pa)
{
$message->subject(sprintf(Subject::$vt_ca,$vt->abs_no));
if(CustomClass::$IsEmailTest)
{
$message->to(CustomClass::$TestMailId);
}
else
{
$message->to($user->email);
if(isset($coa) && count($coa)>0)
{
foreach ($coa as $value) {
if(!empty($value->email))
$message->cc($value->email);
}
}
if(isset($pa) && !empty($pa))
{
if(!empty($pa->email))
$message->cc($pa->email);
}
$message->cc(CustomClass::$BackupId);
}
});
}
}
//VT Mail Send add cc COA data
public function vt_mail_data($user,$pa,$vt,$coa,$categories)
{
if(empty($user->email))
{
return;
}
if(CustomClass::$IsEmailEnabled)
{
$isMailSend = Mail::send('emails.vt.chiefauthor_data', array('user' => $user,'vt' =>$vt,'pa'=>$pa,'coas' =>$coa,'categories'=>$categories), function($message) use ($coa,$vt,$user,$pa)
{
$message->subject(sprintf(Subject::$vt_ca,$vt->abs_no));
if(CustomClass::$IsEmailTest)
{
$message->to(CustomClass::$TestMailId);
}
else
{
$message->to($user->email);
if(isset($coa) && count($coa)>0)
{
foreach ($coa as $value) {
if(!empty($value->email))
$message->cc($value->email);
}
}
if(isset($pa) && !empty($pa))
{
if(!empty($pa->email))
$message->cc($pa->email);
}
$message->cc(CustomClass::$BackupId);
}
});
}
}
/******************************* Consent Judge *****************************************/
public function ConsentJudge($id){
try {
$id = urldecode(Helper::decrypt($id));
$exp = explode(',', $id);
$name_in_grid_id = $exp[0];
$user_id = $exp[1];
$role_id = $exp[2];
$consent_status_id = $exp[3];
$msg = "";
$result = DB::select("call usp_consent_judge_vt($name_in_grid_id,$user_id,$role_id,$consent_status_id)");
if(isset($result))
{
$msg = $result[0]->msg;
}
else
{
$msg = AppMessage::$GENERAL_ERROR;
}
} catch (Exception $e) {
Log::error('VTController - ConsentJudge'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
return View::make("msg")->with('msg',$msg);
}
/******************************* Consent Judge *****************************************/
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists