Sindbad~EG File Manager
<?php
class CPController extends BaseController {
//IF id is null then create empty fp and redeirect to edit fp page
//if id is not null then fp can edit
public function getCP($id = null){
$step = Input::get('step');
$categories = array('' => '--select--') + Category::FP();
$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)
{
$abs = Abstracts::find($id);
if($abs != null)
{
if($abs->user_id != CustomClass::getUserId())
{
return Redirect::to('dashboard');
}
else if($abs->status_id ==CustomClass::$Submitted)
{
return Redirect::to('dashboard');
}
$pa_author = Authors::where('abs_id',$abs->abs_id)->where('role_id',CustomClass::$PresentingAuthor)->first();
if($pa_author !=null)
{
$pres_auth_id = $pa_author->user_id;
}
}
else
{
return Redirect::to('dashboard');
}
}
else
{
if($this->is_closed())
{
return Redirect::to('abstracts?type=CP');
}
else
{
//dump creat table after step new fp
$abs = new Abstracts();
$abs->user_id = CustomClass::getUserId();
$abs->abs_type = CustomClass::$CP;
$abs->save();
return Redirect::to('cp/'.urlencode(Helper::encrypt($abs->abs_id)));
}
}
return View::make('cp.cp')
->with('abs',$abs)
->with('pres_auth_id',$pres_auth_id)
->with('categories',$categories)
->with('membership',$membership)
->with('step',$step);
}
//if FP count =< count 4 then close
public function is_closed()
{
$abs = Abstracts::where('abs_type','CP')->where('user_id',CustomClass::getUserId())->get();
if(!(CustomClass::$CP_Count > count($abs)))
{
return true;
}
else
{
return false;
}
}
//FP view
public function view($id){
$categories = array('' => '--select--') + Category::lists('name','Category_id');
if($id != null )
$id = intval(urldecode(Helper::decrypt($id)));
$abs = null;
if($id>0)
{
$abs = Abstracts::find($id);
$pa = Abstracts::usp_get_authors(null,CustomClass::$CP,CustomClass::$PresentingAuthor,$id,null,null);
if(isset($pa[0]))
{
$pa = $pa[0];
}
//$pa = App::make('UserController')->getUserDetails($fp->pres_auth_id);
$user = App::make('UserController')->getUserDetails($abs->user_id);
return View::make('cp.view')->with('abs',$abs)
->with('pa',$pa)
->with('categories',$categories)
->with('user',$user);
}
}
//FP Store
public function store()
{
try {
//for Response
$arr = [];
$code = 0;
$msg = "";
$data = "";
$abs_id = intval(Input::get('hdnId'));
$pa_id = intval(Input::get('hdnPAId'));
$is_next = intval(Input::get('hdnIsNext'));
$step = intval(Input::get("hdnStep"));
//for first step only
$categories = array('' => '--select--') + Category::FP();
$membership = CustomClass::GetMembership();
$is_edit = true;
$pres_auth_id = 0;
$abs_upload = [];
if($abs_id >0)
{
$abs = Abstracts::find($abs_id);
}
else
$abs = new Abstracts();
if($abs != null)
{
$pa_author = Authors::where('abs_id',$abs->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($abs->status_id ==CustomClass::$Submitted)
{
$code = 0;
$msg = AppMessage::$CP_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";
$data = "";
}
else
{
$abs->abs_type = CustomClass::$CP;
$abs->category_id = Input::get('ddlSection');
$abs->original_category_id = Input::get('ddlSection');
$abs->user_id = CustomClass::getUserId();
$abs->save();
//check and save chief instructor in author table
$author = Authors::where('abs_id',$abs->abs_id)->where('role_id',CustomClass::$ChiefAuthor)->first();
if($author == null)
{
$author = new Authors();
$author->user_id = CustomClass::getUserId();
$author->abs_id = $abs->abs_id;
$author->role_id = CustomClass::$ChiefAuthor;
$author->consent_status_id = CustomClass::$Selected;
$author->save();
}
//chief Author same PresentingAuthor
$author = Authors::where('abs_id',$abs->abs_id)->where('role_id',CustomClass::$PresentingAuthor)->first();
if($author == null)
{
$author = new Authors();
$author->user_id = CustomClass::getUserId();
$author->abs_id = $abs->abs_id;
$author->role_id = CustomClass::$PresentingAuthor;
$author->consent_status_id = CustomClass::$Selected;
$author->save();
}
$count = $this->get_CPPA_Count($pres_auth_id);
if($count >= CustomClass::$CP_Count)
{
$code = 0;
$msg = AppMessage::$FT_PA_Count;
$data = "";
}
else
{
$code = 1;
$data = View::make('cp.step2')->with('abs',$abs)->render();
}
}
}
if($step ==2)
{
if($abs->status_id ==CustomClass::$Submitted)
{
$code = 0;
$msg = AppMessage::$CP_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";
$data = "";
}
else
{
$abs->user_id = CustomClass::getUserId();
$abs->submitted_on = date('Y-m-d H:i:s');
$abs->title = Helper::trimAndTruncate(Input::get('txtTitle'),200);
$abs->synopsis = Helper::trimAndTruncate(Input::get('txtSynopsis'),1200);
$abs->save();
$pa = Abstracts::usp_get_authors(null,CustomClass::$CP,CustomClass::$PresentingAuthor,$abs_id,null,null);
if(isset($pa[0]))
{
$pa = $pa[0];
}
$code = 1;
$data = View::make('cp.step5')->with('abs',$abs)
->with('pa',$pa)
->with('categories',$categories)
->with('membership',$membership)
->render();
}
}
if($step ==3)
{
if($abs->status_id ==CustomClass::$Submitted)
{
$code = 0;
$msg = AppMessage::$CP_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";
$data = "";
}
else
{
// if($this->IsRatifiedMembers($arc))
// {
$code = 1;
$data = View::make('cp.step5')->with('abs',$abs)
->with('categories',$categories)
->with('membership',$membership)->render();
// }
// else
// {
// $code = 0;
// $msg = AppMessage::$ARC_RATIFIED_MEMBER;
// $data = "";
// }
}
}
if($step == 5)
{
if($abs->status_id ==CustomClass::$Submitted)
{
$code = 0;
$msg = AppMessage::$CP_ALREADY_SUBMIT ." <a href=". url('/dashboard'). " >Please, check the status in Dashboard</a>";
$data = "";
}
else
{
if(!($abs->abs_no >0))
{
$is_edit = false;
$abs->submitted_at = date('Y-m-d H:i:s');
$abs->status_id = CustomClass::$Submitted;
$abs->MidYear = 1; //default value is 1 for mid-year
$result = Abstracts::usp_generate_abs_no(CustomClass::$CP,$abs->abs_id);
$abs->abs_no = $result[0]->abs_no;
}
$abs->save();
//FT mail
$user = App::make('UserController')->getUserDetails($abs->user_id);
$pa = Abstracts::usp_get_authors(null,CustomClass::$CP,CustomClass::$PresentingAuthor,$abs->abs_id,null,null);
if(isset($pa[0]))
{
$pa = $pa[0];
}
if($is_edit)
{
$this->cp_mail_data($user,$abs,$categories);
}
else
{
$this->cp_mail($user,$abs,$categories);
}
$code = 1;
$data = View::make('cp.success')->with('abs',$abs)->render();
}
}
}
else
{
if($step == 2)
{
$code = 1;
$data = View::make('cp.step1')
->with('abs',$abs)
->with('pres_auth_id',$pres_auth_id)
->with('categories',$categories)
->with('membership',$membership)->render();
}
if($step == 5)
{
$code = 1;
$data = View::make('cp.step2')->with('abs',$abs)
->render();
}
}
} catch (Exception $e) {
Log::error('CPController - store :'.$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_CPPA_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::$CP && $value->role_id==CustomClass::$PresentingAuthor && $value->status_id == CustomClass::$Submitted)
{
$pa_count++;
}
}
} catch (Exception $e) {
Log::error('CPController - get_CPPA_Count :'.$e->getMessage());
}
return $pa_count;
}
//RATIFIED MEMBER Check for fp
public function IsRatifiedMembers($abs)
{
$isretified = false;
$ca = App::make('UserController')->getUserDetails($abs->user_id);
if($ca->user_type_id==CustomClass::$Ratified_Member)
{
$isretified = true;
}
// $pa = App::make('UserController')->getUserDetails($fp->pres_auth_id);
// if(!empty($pa->membership_no))
// {
// $isretified = true;
// }
$pa = Abstracts::usp_get_authors(null,CustomClass::$CP,CustomClass::$PresentingAuthor,$abs->abs_id,null,null);
if(isset($pa[0]))
{
$pa = $pa[0];
if($pa->user_type_id==CustomClass::$Ratified_Member)
{
$isretified = true;
}
}
return $isretified;
}
//FP Mail Send add cc COA
public function cp_mail($user,$abs,$categories)
{
if(empty($user->email))
{
return;
}
if(CustomClass::$IsEmailEnabled)
{
$isMailSend = Mail::send('emails.cp.chiefauthor', array('user' => $user,'abs' =>$abs,'categories'=>$categories), function($message) use ($abs,$user)
{
$message->subject(sprintf(Subject::$cp_ca,$abs->abs_no));
if(CustomClass::$IsEmailTest)
{
$message->to(CustomClass::$TestMailId);
}
else
{
$message->to($user->email);
$message->cc(CustomClass::$BackupId);
}
});
}
}
//FP Mail Send add cc COA
public function cp_mail_data($user,$appletree,$categories)
{
if(empty($user->email))
{
return;
}
if(CustomClass::$IsEmailEnabled)
{
$isMailSend = Mail::send('emails.cp.chiefauthor', array('user' => $user,'abs' =>$abs,'categories' => $categories ), function($message) use ($abs,$user)
{
$message->subject(sprintf(Subject::$cp_ca,$abs->abs_no));
if(CustomClass::$IsEmailTest)
{
$message->to(CustomClass::$TestMailId);
}
else
{
$message->to($user->email);
$message->cc(CustomClass::$BackupId);
}
});
}
}
//CP 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('CPController - getPADetails'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
//CP Search user for Presenting Author
public function getSearchMembersPA(){
try { $arr = [];
$data = "";
$msg = "";
$code = 0;
$search = Helper::trimAndTruncate(Input::get('search'),250);
$data = Abstracts::usp_get_authors($search,CustomClass::$CP,CustomClass::$PresentingAuthor,null,CustomClass::$UserType_CP_PA,null);
if(empty($data))
{
$data = "";
$code = 0;
$msg = "record not found";
}
else
{
$code = 1;
$msg = "";
}
} catch (Exception $e) {
Log::error('CPController - getSearchMembersPA'.$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 = "";
$abs_id = intval(Input::get('abs_id'));
$pa_user_id = intval(Input::get('pa_user_id'));
$paauthor = Authors::where('abs_id',$abs_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 = $abs_id;
$pa_author->role_id = CustomClass::$PresentingAuthor;
$pa_author->consent_status_id = CustomClass::$Selected;
//use for validation
$count = $this->get_CPPA_Count($pa_user_id);
if($count >= CustomClass::$CP_Count)
{
$code = 0;
$msg = AppMessage::$CP_PA_Count;
}
else
{
$code = 1;
$pa_author->save();
}
}
else
{
$code = 1;
}
} catch (Exception $e) {
Log::error('CPController - storePA :'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
//COA Remove
public function removePA()
{
try {
//for Response
$arr = [];
$code = 0;
$msg = "";
$data = "";
$abs_id = intval(Input::get('abs_id'));
$pa_id = intval(Input::get('pa_id'));
$pa = Authors::where('abs_id',$abs_id)->where('user_id',$pa_id)->where('role_id',CustomClass::$PresentingAuthor)->first();
$pa->delete();
$code = 1;
} catch (Exception $e) {
Log::error('CPController - removePA :'.$e->getMessage());
$msg =AppMessage::$GENERAL_ERROR;
}
$arr = ['data' => $data, 'code' => $code, 'msg' => $msg];
return Response::json($arr);
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists