269 lines
13 KiB
PHP
269 lines
13 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use App\Http\Requests\FormAdditional;
|
|
use DB;
|
|
use Auth;
|
|
|
|
class FormactionController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'form';
|
|
$this->_module = 'formaction';
|
|
$this->_viewname = 'formaction';
|
|
$this->_title = 'Quick Actions';
|
|
$this->_base_url = '/formaction';
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete'] ],
|
|
'name' => ['title' => 'Name', 'type' => 'text'],
|
|
'target_type' => ['title' => 'Target', 'type' => 'text'],
|
|
//'link_type' => ['title' => 'Link Type', 'type' => 'text'],
|
|
'roles' => ['title' => 'Roles', 'type' => 'text'],
|
|
'sort_order' => ['title' => 'Sort Order', 'type' => 'number'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
|
|
];
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all');
|
|
if (isset($response->statusCode) && $response->statusCode == 401) {
|
|
return redirect('/unauthorised');
|
|
}
|
|
$roleMap = $this->getRoleNameMap();
|
|
$items = $response->data->items ?? [];
|
|
foreach ($items as &$item) {
|
|
$item->roles = $this->formatAssignedRoles($item->roles ?? '', $roleMap);
|
|
}
|
|
unset($item);
|
|
$fields = $this->get_list_fields();
|
|
return $this->view('list')->with([
|
|
'title' => $this->_title,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $items,
|
|
'buttons' => $this->get_list_buttons()
|
|
]);
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$groups = $this->getlambda('get', 'ums', 'group', 'dropdown');
|
|
$groups_dd = [];
|
|
foreach($groups->data->items as $group){
|
|
$groups_dd[$group->id] = $group->name;
|
|
}
|
|
$roles = $this->getlambda('get', 'ums', 'roles', 'dropdown');
|
|
$roles_dd = [];
|
|
foreach($roles->data->items as $role){
|
|
$roles_dd[$role->id] = $role->name;
|
|
}
|
|
$forms = $this->getlambda('get', 'form', 'formentity', 'dropdown');
|
|
$forms_dd = [];
|
|
foreach($forms->data->items as $form){
|
|
$forms_dd[$form->id] = $form->title;
|
|
}
|
|
|
|
$forms = $this->getlambda('get', 'form', 'survey', 'dropdown');
|
|
foreach($forms->data->items as $form){
|
|
$forms_dd[$form->id] = $form->title . ' (Survey)';
|
|
}
|
|
|
|
$quizs = $this->getlambda('get', 'form', 'quiz', 'dropdown');
|
|
foreach($quizs->data->items as $form){
|
|
$forms_dd[$form->id] = $form->name . ' (Quiz)';
|
|
}
|
|
|
|
$target_types = ['form' => 'Web Form', 'survey' => 'Surveys', 'quiz' => 'Quizs', 'doctorlist' => 'Doctor List', 'external' => 'External Webpage', 'internal_action' => 'Internal Action', 'external_with_token' => 'External Webpage with Token', ];
|
|
|
|
$permissions = json_decode(auth()->user()->permissions);
|
|
if(in_array('rcpa_reports', $permissions)) {
|
|
$target_types['rcpa_reports'] = 'RCPA Report';
|
|
$forms_dd['apptmwise'] = 'TM Wise Report';
|
|
$forms_dd['appmonthwise'] = 'Month Wise Report';
|
|
}
|
|
|
|
return [
|
|
'name' => ['title' => 'Title', 'type' => 'text', 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
'groups' => ['title' => 'Groups', 'type' => 'multiselect', 'required' => true, 'values' => $groups_dd ],
|
|
'roles' => ['title' => 'Roles', 'type' => 'multiselect', 'required' => true, 'values' => $roles_dd ],
|
|
|
|
'target_type' => ['title' => 'Target Type', 'type' => 'select', 'required' => true, 'values' => $target_types ],
|
|
'form_id' => ['title' => 'Form', 'type' => 'select', 'values' => $forms_dd ],
|
|
'link_type' => ['title' => 'Menu Type (valid of forms only)', 'type' => 'select', 'required' => true, 'values' => ['formic' => 'Serverless Form', 'form' => 'Web Form', 'list' => 'Submitted Data'] ],
|
|
'external_url' => ['title' => 'External Url / Internal Action', 'type' => 'text'],
|
|
'visiblity_check' => ['title' => 'Enable Schedule', 'type' => 'yesno', 'required' => true],
|
|
'geolocation' => ['title' => 'Enable Geolocation', 'type' => 'yesno', 'required' => true],
|
|
|
|
'validity_start' => ['title' => 'Schedule Start Date', 'type' => 'datetime', 'required' => true],
|
|
'validity_end' => ['title' => 'Schedule End Date', 'type' => 'datetime', 'required' => true],
|
|
'sort_order' => ['title' => 'Sort Order', 'type' => 'number', 'required' => false],
|
|
'icon' => ['title' => 'Action Icon', 'type' => 'image', 'required' => true],
|
|
];
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
if( $request->file('icon') ) {
|
|
$data['icon'] = $this->_uploadMedia($request, 'icon', 'formaction');
|
|
}
|
|
$data['groups'] = implode('#', $data['groups']);
|
|
$data['roles'] = implode('#', $data['roles']);
|
|
$data['sort_order'] = isset($data['sort_order']) && $data['sort_order'] !== '' ? (int) $data['sort_order'] : 0;
|
|
//echo '<pre>'; print_r($data); exit;
|
|
return $data;
|
|
}
|
|
protected function _beforeform($type, $values) {
|
|
if($type == 'edit') {
|
|
$values->groups = explode('#', $values->groups);
|
|
$values->roles = explode('#', $values->roles);
|
|
$values->geolocation = isset($values->geolocation) ? $values->geolocation : 'no';
|
|
$values->sort_order = isset($values->sort_order) ? $values->sort_order : 0;
|
|
} else {
|
|
if (!is_object($values)) {
|
|
$values = (object) [];
|
|
}
|
|
if (!isset($values->sort_order)) {
|
|
$values->sort_order = 0;
|
|
}
|
|
}
|
|
return $values;
|
|
}
|
|
|
|
public function consolelist(Request $request) {
|
|
$actions = $this->getlambda('get', 'form', 'formaction', 'list');
|
|
//echo '<pre>'; print_r($actions); exit;
|
|
// For all actions, replace external form links with the localhost link
|
|
// if (isset($actions->data->actions) && is_array($actions->data->actions)) {
|
|
// foreach ($actions->data->actions as &$action) {
|
|
// if (isset($action->url) && is_string($action->url)) {
|
|
// $action->url = str_replace([
|
|
// "https://stage.buildrapport.co/form/",
|
|
// "https://form.buildrapport.co/index.php?finfo="
|
|
// ], "http://127.0.0.1:8005/index.php?finfo=", $action->url);
|
|
// }
|
|
// }
|
|
// unset($action); // break reference
|
|
// }
|
|
//echo '<pre>'; print_r($actions); exit;
|
|
return view('form.list-console')->with(['actions' => $actions->data->actions]);
|
|
}
|
|
|
|
public function consoleshow(Request $request) {
|
|
$form_id = $request->input('id', 0);
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/getformdefination', ['form_id' => $form_id, 'user_id' => Auth::user()->user_id, 'partition' => 'rapport-'.Auth::user()->domain ]);
|
|
//echo '<pre>'; print_r($finfo); exit;
|
|
$formdata = new \stdClass();
|
|
$formdata->link_type = 'form';
|
|
$formdata->title = $finfo->data->formdata->title;
|
|
$id = 0;
|
|
$additional_info = $this->get_additional_info($form_id);
|
|
if (\View::exists('form.'.$form_id.'-console')) {
|
|
$additional_info = $this->get_additional_info($form_id);
|
|
return view('form.'.$form_id.'-console')->with(['questions' => $finfo->data->questions, 'form' => $formdata, 'id' => $id, 'console' => true, 'additional' => $additional_info, 'form_id' => $form_id ]);
|
|
} else {
|
|
return view('form.common-console')->with(['questions' => $finfo->data->questions, 'form' => $formdata, 'id' => $id, 'form_id' => $form_id, 'console' => true ]);
|
|
}
|
|
}
|
|
|
|
public function postconsoleshow(Request $request) {
|
|
$post = $request->except('_token');
|
|
$entity_id = $post['id'];
|
|
unset($post['id']);
|
|
if(array_key_exists('record_date', $post)) {
|
|
$post['record_date'] = strtotime($post['record_date']);
|
|
}
|
|
if(array_key_exists('submission_id', $post) && $post['submission_id'] != '' ) {
|
|
$post['id'] = $post['submission_id'];
|
|
}
|
|
unset($post['submission_id']);
|
|
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $post, 'entity_id' => $entity_id, 'user_id' => $post['user_id'], 'partition' => 'rapport-'.Auth::user()->domain ]);
|
|
return redirect('/formaction/consoleshow?id='.$entity_id)->withSuccess('Form Submitted!');
|
|
|
|
}
|
|
|
|
protected function get_additional_info($form_id) {
|
|
switch($form_id) {
|
|
case '63c2ff17-a69c-4b47-af33-1d9909c608b6':
|
|
case 'eaef2abf-f16b-414c-b6a5-df3fd2282b2e':
|
|
$hierarchy = LambdaRequest::signedrequest('get', 'ums', 'hierarchy/hierarchy_below_me');
|
|
//echo '<pre>'; print_r($hierarchy); exit;
|
|
$team = [];
|
|
foreach($hierarchy->data->hierarchies as $hie) {
|
|
if(isset($hie->owner_info->id)) {
|
|
$team[$hie->owner_info->id] = ['name' => $hie->owner_info->name, 'code' => $hie->owner_info->employee_code ];
|
|
|
|
}
|
|
}
|
|
return ['team' => $team];
|
|
break;
|
|
|
|
default:
|
|
return [];
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function postgetformfielddata(Request $request) {
|
|
$post = $request->except('_token');
|
|
$history = LambdaRequest::postrequest('form', 'formentity/getformhistory', ['form_id' => $post['form_id'], 'user_id' => $post['user_id'], 'partition' => $post['partition'] ]);
|
|
$submission = [];
|
|
//print_r($history); exit;
|
|
foreach($history->data->submissions as $sub) {
|
|
if(date("M Y", strtotime($sub->record_date)) == date("M Y", strtotime($post['record_date'])) ) {
|
|
$submission = (array)$sub->formdata;
|
|
$submission['submission_id'] = $sub->id;
|
|
}
|
|
}
|
|
|
|
return response()->json(['submission' => $submission, 'submissions' => $history->data->submissions, 'record_date' => strtotime($post['record_date']) ]);
|
|
}
|
|
|
|
public function history(Request $request) {
|
|
$form_id = $request->input('id', 0);
|
|
echo $user_id = Auth::user()->user_id;
|
|
$history = LambdaRequest::postrequest('form', 'formentity/getformhistory', ['form_id' => $form_id, 'user_id' => $user_id, 'partition' => 'rapport-'.Auth::user()->domain ]);
|
|
//echo '<pre>'; print_r($history); exit;
|
|
//echo '<pre>'; print_r(['form_id' => $form_id, 'user_id' => $user_id, 'partition' => 'rapport-'.Auth::user()->domain ]); exit;
|
|
// $hierarchy = LambdaRequest::signedrequest('get', 'ums', 'hierarchy/hierarchy_below_me');
|
|
// $submissions = [];
|
|
// foreach($hierarchy->data->hierarchies as $hie) {
|
|
// if(isset($hie->owner_info->id)) {
|
|
|
|
// $submissions = array_merge($submissions, $history->data->submissions);
|
|
// //print_r($history);
|
|
// }
|
|
// }
|
|
return view('form.history-console')->with(['questions' => $history->data->questions, 'submissions' => $history->data->submissions, 'formname' => $history->data->formname, 'form_id' => $form_id ]);
|
|
//echo '<pre>'; print_r($history); print_r($formdata); exit;
|
|
}
|
|
|
|
public function consoleallhistory(Request $request) {
|
|
$form_id = $request->input('id', 0);
|
|
$hierarchy = LambdaRequest::signedrequest('get', 'ums', 'hierarchy/hierarchy_below_me');
|
|
$submissions = [];
|
|
foreach($hierarchy->data->hierarchies as $hie) {
|
|
if(isset($hie->owner_info->id)) {
|
|
$history = LambdaRequest::postrequest('form', 'formentity/getformhistory', ['form_id' => $form_id, 'user_id' => $hie->owner_info->id, 'partition' => 'rapport-'.Auth::user()->domain ]);
|
|
foreach($history->data->submissions as &$sub) {
|
|
$sub->user = $hie->owner_info->name;
|
|
}
|
|
$submissions = array_merge($submissions, $history->data->submissions);
|
|
//print_r($history);
|
|
}
|
|
}
|
|
//echo '<pre>'; print_r($submissions); exit;
|
|
return view('form.allhistory-console')->with(['questions' => $history->data->questions, 'submissions' => $submissions, 'formname' => $history->data->formname, 'form_id' => $form_id ]);
|
|
//echo '<pre>'; print_r($history); print_r($formdata); exit;
|
|
}
|
|
|
|
}
|