|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Client\helpdesk; |
|
4
|
|
|
|
|
5
|
|
|
// controllers |
|
6
|
|
|
use App\Http\Controllers\Agent\helpdesk\TicketWorkflowController; |
|
7
|
|
|
use App\Http\Controllers\Controller; |
|
8
|
|
|
// requests |
|
9
|
|
|
use App\Http\Requests\helpdesk\ClientRequest; |
|
10
|
|
|
use App\Model\helpdesk\Agent\Department; |
|
11
|
|
|
// models |
|
12
|
|
|
use App\Model\helpdesk\Form\Fields; |
|
13
|
|
|
use App\Model\helpdesk\Manage\Help_topic; |
|
14
|
|
|
use App\Model\helpdesk\Settings\CommonSettings; |
|
15
|
|
|
use App\Model\helpdesk\Settings\System; |
|
16
|
|
|
use App\Model\helpdesk\Settings\Ticket; |
|
17
|
|
|
use App\Model\helpdesk\Ticket\Ticket_attachments; |
|
18
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Priority; |
|
19
|
|
|
use App\Model\helpdesk\Ticket\Ticket_source; |
|
20
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Thread; |
|
21
|
|
|
use App\Model\helpdesk\Ticket\Tickets; |
|
22
|
|
|
use App\Model\helpdesk\Utility\CountryCode; |
|
23
|
|
|
use App\User; |
|
24
|
|
|
use Exception; |
|
25
|
|
|
// classes |
|
26
|
|
|
use Form; |
|
27
|
|
|
use GeoIP; |
|
28
|
|
|
use Illuminate\Http\Request; |
|
29
|
|
|
use Input; |
|
30
|
|
|
use Lang; |
|
31
|
|
|
use Redirect; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* FormController. |
|
35
|
|
|
* |
|
36
|
|
|
* @author Ladybird <[email protected]> |
|
37
|
|
|
*/ |
|
38
|
|
|
class FormController extends Controller { |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Create a new controller instance. |
|
42
|
|
|
* Constructor to check. |
|
43
|
|
|
* |
|
44
|
|
|
* @return void |
|
|
|
|
|
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(TicketWorkflowController $TicketWorkflowController) { |
|
47
|
|
|
$this->middleware('board'); |
|
48
|
|
|
// creating a TicketController instance |
|
49
|
|
|
$this->TicketWorkflowController = $TicketWorkflowController; |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* getform. |
|
54
|
|
|
* |
|
55
|
|
|
* @param type Help_topic $topic |
|
56
|
|
|
* |
|
57
|
|
|
* @return type |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getForm(Help_topic $topic, CountryCode $code) { |
|
60
|
|
|
if (\Config::get('database.install') == '%0%') { |
|
61
|
|
|
return \Redirect::route('licence'); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); |
|
64
|
|
|
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first(); |
|
65
|
|
|
if (!\Auth::check() && ($settings->status == 1 || $settings->status == '1')) { |
|
66
|
|
|
return redirect('auth/login')->with(['login_require' => 'Please login to your account for submitting a ticket', 'referer' => 'form']); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
$location = GeoIP::getLocation(); |
|
69
|
|
|
$phonecode = $code->where('iso', '=', $location->iso_code)->first(); |
|
|
|
|
|
|
70
|
|
|
if (System::first()->status == 1) { |
|
71
|
|
|
$topics = $topic->get(); |
|
|
|
|
|
|
72
|
|
|
$codes = $code->get(); |
|
|
|
|
|
|
73
|
|
|
if ($phonecode->phonecode) { |
|
74
|
|
|
$phonecode = $phonecode->phonecode; |
|
75
|
|
|
} else { |
|
76
|
|
|
$phonecode = ''; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return view('themes.default1.client.helpdesk.form', compact('topics', 'codes', 'email_mandatory'))->with('phonecode', $phonecode); |
|
|
|
|
|
|
80
|
|
|
} else { |
|
81
|
|
|
return \Redirect::route('home'); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* This Function to post the form for the ticket. |
|
87
|
|
|
* |
|
88
|
|
|
* @param type Form_name $name |
|
89
|
|
|
* @param type Form_details $details |
|
90
|
|
|
* |
|
91
|
|
|
* @return type string |
|
92
|
|
|
*/ |
|
93
|
|
|
public function postForm($id, Help_topic $topic) { |
|
94
|
|
|
if ($id != 0) { |
|
95
|
|
|
$helptopic = $topic->where('id', '=', $id)->first(); |
|
|
|
|
|
|
96
|
|
|
$custom_form = $helptopic->custom_form; |
|
97
|
|
|
$values = Fields::where('forms_id', '=', $custom_form)->get(); |
|
98
|
|
|
if (!$values) { |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
if ($values) { |
|
102
|
|
|
foreach ($values as $form_data) { |
|
103
|
|
|
if ($form_data->type == 'select') { |
|
104
|
|
|
$form_fields = explode(',', $form_data->value); |
|
105
|
|
|
$var = ''; |
|
106
|
|
|
foreach ($form_fields as $form_field) { |
|
107
|
|
|
$var .= '<option value="' . $form_field . '">' . $form_field . '</option>'; |
|
108
|
|
|
} |
|
109
|
|
|
echo '<br/><label>' . ucfirst($form_data->label) . '</label><select class="form-control" name="' . $form_data->name . '">' . $var . '</select>'; |
|
110
|
|
View Code Duplication |
} elseif ($form_data->type == 'radio') { |
|
|
|
|
|
|
111
|
|
|
$type2 = $form_data->value; |
|
112
|
|
|
$vals = explode(',', $type2); |
|
113
|
|
|
echo '<br/><label>' . ucfirst($form_data->label) . '</label><br/>'; |
|
114
|
|
|
foreach ($vals as $val) { |
|
115
|
|
|
echo '<input type="' . $form_data->type . '" name="' . $form_data->name . '"> ' . $form_data->value . ' '; |
|
116
|
|
|
} |
|
117
|
|
|
echo '<br/>'; |
|
118
|
|
|
} elseif ($form_data->type == 'textarea') { |
|
119
|
|
|
$type3 = $form_data->value; |
|
|
|
|
|
|
120
|
|
|
echo '<br/><label>' . $form_data->label . '</label></br><textarea id="unique-textarea" name="' . $form_data->name . '" class="form-control" style="height:15%;"></textarea>'; |
|
121
|
|
View Code Duplication |
} elseif ($form_data->type == 'checkbox') { |
|
|
|
|
|
|
122
|
|
|
$type4 = $form_data->value; |
|
123
|
|
|
$checks = explode(',', $type4); |
|
124
|
|
|
echo '<br/><label>' . ucfirst($form_data->label) . '</label><br/>'; |
|
125
|
|
|
foreach ($checks as $check) { |
|
126
|
|
|
echo '<input type="' . $form_data->type . '" name="' . $form_data->name . '">  ' . $check; |
|
127
|
|
|
} |
|
128
|
|
|
} else { |
|
129
|
|
|
echo '<br/><label>' . ucfirst($form_data->label) . '</label><input type="' . $form_data->type . '" class="form-control" name="' . $form_data->name . '" />'; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
echo '<br/><br/>'; |
|
133
|
|
|
} |
|
134
|
|
|
} else { |
|
135
|
|
|
return; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Posted form. |
|
141
|
|
|
* |
|
142
|
|
|
* @param type Request $request |
|
143
|
|
|
* @param type User $user |
|
144
|
|
|
*/ |
|
145
|
|
|
public function postedForm(User $user, ClientRequest $request, Ticket $ticket_settings, Ticket_source $ticket_source, Ticket_attachments $ta, CountryCode $code) { |
|
|
|
|
|
|
146
|
|
|
try { |
|
147
|
|
|
$form_extras = $request->except('Name', 'Phone', 'Email', 'Subject', 'Details', 'helptopic', '_wysihtml5_mode', '_token', 'mobile', 'Code', 'priority', 'attachment'); |
|
148
|
|
|
$name = $request->input('Name'); |
|
149
|
|
|
$phone = $request->input('Phone'); |
|
150
|
|
|
if ($request->input('Email')) { |
|
151
|
|
|
if ($request->input('Email')) { |
|
152
|
|
|
$email = $request->input('Email'); |
|
153
|
|
|
} else { |
|
154
|
|
|
$email = null; |
|
155
|
|
|
} |
|
156
|
|
|
} else { |
|
157
|
|
|
$email = null; |
|
158
|
|
|
} |
|
159
|
|
|
$subject = $request->input('Subject'); |
|
160
|
|
|
$details = $request->input('Details'); |
|
161
|
|
|
$phonecode = $request->input('Code'); |
|
162
|
|
|
if ($request->input('mobile')) { |
|
163
|
|
|
$mobile_number = $request->input('mobile'); |
|
164
|
|
|
} else { |
|
165
|
|
|
$mobile_number = null; |
|
166
|
|
|
} |
|
167
|
|
|
$status = $ticket_settings->first()->status; |
|
|
|
|
|
|
168
|
|
|
$helptopic = $request->input('helptopic'); |
|
169
|
|
|
$helpTopicObj = Help_topic::where('id', '=', $helptopic); |
|
170
|
|
|
if ($helpTopicObj->exists() && ($helpTopicObj->value('status') == 1)) { |
|
171
|
|
|
$department = $helpTopicObj->value('department'); |
|
172
|
|
|
} else { |
|
173
|
|
|
$defaultHelpTopicID = Ticket::where('id', '=', '1')->first()->help_topic; |
|
174
|
|
|
$department = Help_topic::where('id', '=', $defaultHelpTopicID)->value('department'); |
|
175
|
|
|
} |
|
176
|
|
|
$sla = $ticket_settings->first()->sla; |
|
|
|
|
|
|
177
|
|
|
|
|
178
|
|
|
// $priority = $ticket_settings->first()->priority; |
|
|
|
|
|
|
179
|
|
|
$default_priority = Ticket_Priority::where('is_default', '=', 1)->first(); |
|
180
|
|
|
$user_priority = CommonSettings::where('option_name', '=', 'user_priority')->first(); |
|
|
|
|
|
|
181
|
|
|
if (!($request->input('priority'))) { |
|
182
|
|
|
$priority = $default_priority->priority_id; |
|
183
|
|
|
if ($helpTopicObj->exists() && ($helpTopicObj->value('status') == 1)) { |
|
184
|
|
|
$priority = $helpTopicObj->value('priority'); |
|
185
|
|
|
} |
|
186
|
|
|
} else { |
|
187
|
|
|
$priority = $request->input('priority'); |
|
188
|
|
|
} |
|
189
|
|
|
$source = $ticket_source->where('name', '=', 'web')->first()->id; |
|
|
|
|
|
|
190
|
|
|
$attachments = $request->file('attachment'); |
|
191
|
|
|
$collaborator = null; |
|
192
|
|
|
$assignto = null; |
|
193
|
|
|
if ($helpTopicObj->exists() && ($helpTopicObj->value('status') == 1)) { |
|
194
|
|
|
$assignto = $helpTopicObj->value('auto_assign'); |
|
195
|
|
|
} |
|
196
|
|
|
$auto_response = 0; |
|
197
|
|
|
$team_assign = null; |
|
198
|
|
|
if ($phone != null || $mobile_number != null) { |
|
|
|
|
|
|
199
|
|
|
$location = GeoIP::getLocation(); |
|
200
|
|
|
$geoipcode = $code->where('iso', '=', $location->iso_code)->first(); |
|
|
|
|
|
|
201
|
|
|
if ($phonecode == null) { |
|
202
|
|
|
$data = [ |
|
203
|
|
|
'fails' => Lang::get('lang.country-code-required-error'), |
|
204
|
|
|
'phonecode' => $geoipcode->phonecode, |
|
205
|
|
|
'country_code_error' => 1, |
|
206
|
|
|
]; |
|
207
|
|
|
|
|
208
|
|
|
return Redirect::back()->with($data)->withInput($request->except('password')); |
|
209
|
|
|
} else { |
|
210
|
|
|
$code = CountryCode::select('phonecode')->where('phonecode', '=', $phonecode)->get(); |
|
211
|
|
|
if (!count($code)) { |
|
212
|
|
|
$data = [ |
|
213
|
|
|
'fails' => Lang::get('lang.incorrect-country-code-error'), |
|
214
|
|
|
'phonecode' => $geoipcode->phonecode, |
|
215
|
|
|
'country_code_error' => 1, |
|
216
|
|
|
]; |
|
217
|
|
|
|
|
218
|
|
|
return Redirect::back()->with($data)->withInput($request->except('password')); |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
\Event::fire(new \App\Events\ClientTicketFormPost($form_extras, $email, $source)); |
|
|
|
|
|
|
223
|
|
|
$result = $this->TicketWorkflowController->workflow($email, $name, $subject, $details, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $department, $assignto, $team_assign, $status, $form_extras, $auto_response); |
|
224
|
|
|
// dd($result); |
|
|
|
|
|
|
225
|
|
|
if ($result[1] == 1) { |
|
226
|
|
|
$ticketId = Tickets::where('ticket_number', '=', $result[0])->first(); |
|
227
|
|
|
$thread = Ticket_Thread::where('ticket_id', '=', $ticketId->id)->first(); |
|
228
|
|
|
if ($attachments != null) { |
|
229
|
|
|
foreach ($attachments as $attachment) { |
|
|
|
|
|
|
230
|
|
|
if ($attachment != null) { |
|
231
|
|
|
$name = $attachment->getClientOriginalName(); |
|
232
|
|
|
$type = $attachment->getClientOriginalExtension(); |
|
233
|
|
|
$size = $attachment->getSize(); |
|
234
|
|
|
$data = file_get_contents($attachment->getRealPath()); |
|
235
|
|
|
$attachPath = $attachment->getRealPath(); |
|
|
|
|
|
|
236
|
|
|
$ta->create(['thread_id' => $thread->id, 'name' => $name, 'size' => $size, 'type' => $type, 'file' => $data, 'poster' => 'ATTACHMENT']); |
|
237
|
|
|
} |
|
238
|
|
|
} |
|
239
|
|
|
} |
|
240
|
|
|
// dd($result); |
|
|
|
|
|
|
241
|
|
|
return Redirect::back()->with('success', Lang::get('lang.Ticket-has-been-created-successfully-your-ticket-number-is') . ' ' . $result[0] . '. ' . Lang::get('lang.Please-save-this-for-future-reference')); |
|
242
|
|
|
} else { |
|
243
|
|
|
return Redirect::back()->withInput($request->except('password'))->with('fails', Lang::get('lang.failed-to-create-user-tcket-as-mobile-has-been-taken')); |
|
244
|
|
|
} |
|
245
|
|
|
} catch (\Exception $ex) { |
|
246
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
247
|
|
|
} |
|
248
|
|
|
// dd($result); |
|
|
|
|
|
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* reply. |
|
253
|
|
|
* |
|
254
|
|
|
* @param type $value |
|
|
|
|
|
|
255
|
|
|
* |
|
256
|
|
|
* @return type view |
|
257
|
|
|
*/ |
|
258
|
|
|
public function post_ticket_reply($id, Request $request) { |
|
259
|
|
|
try { |
|
260
|
|
|
if ($comment != null) { |
|
|
|
|
|
|
261
|
|
|
$tickets = Tickets::where('id', '=', $id)->first(); |
|
262
|
|
|
$thread = Ticket_Thread::where('ticket_id', '=', $tickets->id)->first(); |
|
263
|
|
|
|
|
264
|
|
|
$subject = $thread->title . '[#' . $tickets->ticket_number . ']'; |
|
265
|
|
|
$body = $request->input('comment'); |
|
266
|
|
|
|
|
267
|
|
|
$user_cred = User::where('id', '=', $tickets->user_id)->first(); |
|
268
|
|
|
|
|
269
|
|
|
$fromaddress = $user_cred->email; |
|
270
|
|
|
$fromname = $user_cred->user_name; |
|
271
|
|
|
$phone = ''; |
|
272
|
|
|
$phonecode = ''; |
|
273
|
|
|
$mobile_number = ''; |
|
274
|
|
|
|
|
275
|
|
|
$helptopic = $tickets->help_topic_id; |
|
276
|
|
|
$sla = $tickets->sla; |
|
277
|
|
|
$priority = $tickets->priority_id; |
|
278
|
|
|
$source = $tickets->source; |
|
279
|
|
|
$collaborator = ''; |
|
280
|
|
|
$dept = $tickets->dept_id; |
|
281
|
|
|
$assign = $tickets->assigned_to; |
|
282
|
|
|
$form_data = null; |
|
283
|
|
|
$team_assign = null; |
|
284
|
|
|
$ticket_status = null; |
|
285
|
|
|
$auto_response = 0; |
|
286
|
|
|
|
|
287
|
|
|
$this->TicketWorkflowController->workflow($fromaddress, $fromname, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response); |
|
288
|
|
|
|
|
289
|
|
|
return \Redirect::back()->with('success1', Lang::get('lang.successfully_replied')); |
|
290
|
|
|
} else { |
|
291
|
|
|
return \Redirect::back()->with('fails1', Lang::get('lang.please_fill_some_data')); |
|
292
|
|
|
} |
|
293
|
|
|
} catch (Exception $e) { |
|
294
|
|
|
return \Redirect::back()->with('fails1', $e->getMessage()); |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
public function getCustomForm(Request $request) { |
|
299
|
|
|
$html = ''; |
|
300
|
|
|
$helptopic_id = $request->input('helptopic'); |
|
301
|
|
|
$helptopics = new Help_topic(); |
|
302
|
|
|
$helptopic = $helptopics->find($helptopic_id); |
|
|
|
|
|
|
303
|
|
|
if (!$helptopic) { |
|
304
|
|
|
throw new Exception('We can not find your request'); |
|
305
|
|
|
} |
|
306
|
|
|
$custom_form = $helptopic->custom_form; |
|
307
|
|
|
if ($custom_form) { |
|
308
|
|
|
$fields = new Fields(); |
|
309
|
|
|
$forms = new \App\Model\helpdesk\Form\Forms(); |
|
310
|
|
|
$form_controller = new \App\Http\Controllers\Admin\helpdesk\FormController($fields, $forms); |
|
311
|
|
|
$html = $form_controller->renderForm($custom_form); |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
return $html; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
} |
|
318
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.