200 lines
9.5 KiB
PHP
200 lines
9.5 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'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
|
|
];
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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' => ['form' => 'Web Form', 'external' => 'External Webpage', 'nativeform' => 'Native Form (coming soon)'] ],
|
|
'form_id' => ['title' => 'Form', 'type' => 'select', 'values' => $forms_dd ],
|
|
'link_type' => ['title' => 'Menu Type (valid of forms only)', 'type' => 'select', 'required' => true, 'values' => ['form' => 'Web Form', 'list' => 'Submitted Data'] ],
|
|
'external_url' => ['title' => 'External Url', 'type' => 'text'],
|
|
'visiblity_check' => ['title' => 'Enable Schedule', 'type' => 'yesno', 'required' => true],
|
|
'validity_start' => ['title' => 'Schedule Start Date', 'type' => 'date', 'required' => true],
|
|
'validity_end' => ['title' => 'Schedule End Date', 'type' => 'date', 'required' => true],
|
|
|
|
'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']);
|
|
return $data;
|
|
}
|
|
protected function _beforeform($type, $values) {
|
|
if($type == 'edit') {
|
|
$values->groups = explode('#', $values->groups);
|
|
$values->roles = explode('#', $values->roles);
|
|
}
|
|
return $values;
|
|
}
|
|
|
|
public function consolelist(Request $request) {
|
|
$actions = $this->getlambda('get', 'form', 'formaction', 'list');
|
|
//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;
|
|
}
|
|
|
|
}
|