Test Setup Failed
Push — development ( c5582b...48e5db )
by Ashutosh
10:10
created

ProductController::adminDownload()   A

Complexity

Conditions 5
Paths 22

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 23
rs 9.3554
c 0
b 0
f 0
cc 5
nc 22
nop 3
1
<?php
2
3
namespace App\Http\Controllers\Product;
4
5
use App\Http\Controllers\Controller;
6
// use Illuminate\Http\Request;
7
    use App\Model\Order\Order;
8
    use App\Model\Payment\Currency;
9
    use App\Model\Payment\Period;
10
    use App\Model\Payment\Plan;
11
    use App\Model\Payment\Tax;
12
    use App\Model\Payment\TaxClass;
13
    use App\Model\Payment\TaxProductRelation;
14
    use App\Model\Product\Price;
15
    use App\Model\Product\Product;
16
    use App\Model\Product\ProductGroup;
17
    use App\Model\Product\ProductUpload;
18
    use App\Model\Product\Subscription;
19
    use App\Model\Product\Type;
20
    use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
21
    use Illuminate\Http\Request;
22
    use Illuminate\Support\Facades\Input;
23
    use Spatie\Activitylog\Models\Activity;
24
25
    // use Input;
26
27
    class ProductController extends BaseProductController
28
    {
29
        public $product;
30
        public $price;
31
        public $type;
32
        public $subscription;
33
        public $currency;
34
        public $group;
35
        public $plan;
36
        public $tax;
37
        public $tax_relation;
38
        public $tax_class;
39
        public $product_upload;
40
41
        public function __construct()
42
        {
43
            $this->middleware('auth');
44
            $this->middleware('admin', ['except' => ['adminDownload', 'userDownload']]);
45
46
            $product = new Product();
47
            $this->product = $product;
48
49
            $price = new Price();
50
            $this->price = $price;
51
52
            $type = new Type();
53
            $this->type = $type;
54
55
            $subscription = new Subscription();
56
            $this->subscription = $subscription;
57
58
            $currency = new Currency();
59
            $this->currency = $currency;
60
61
            $group = new ProductGroup();
62
            $this->group = $group;
63
64
            $plan = new Plan();
65
            $this->plan = $plan;
66
67
            $tax = new Tax();
68
            $this->tax = $tax;
69
70
            $period = new Period();
71
            $this->period = $period;
72
73
            $tax_relation = new TaxProductRelation();
74
            $this->tax_relation = $tax_relation;
75
76
            $tax_class = new TaxClass();
77
            $this->tax_class = $tax_class;
78
79
            $product_upload = new ProductUpload();
80
            $this->product_upload = $product_upload;
81
        }
82
83
        /**
84
         * Display a listing of the resource.
85
         *
86
         * @return \Response
87
         */
88
        public function index()
89
        {
90
            try {
91
                return view('themes.default1.product.product.index');
92
            } catch (\Exception $e) {
93
                Bugsnag::notifyException($e);
94
95
                return redirect('/')->with('fails', $e->getMessage());
96
            }
97
        }
98
99
        /**
100
         * Display a listing of the resource.
101
         *
102
         * @return \Response
103
         */
104
        public function getProducts()
105
        {
106
            try {
107
                $new_product = Product::select('id', 'name', 'type', 'group')->get();
108
109
                return\ DataTables::of($new_product)
110
            // return \Datatable::collection($this->product->select('id', 'name', 'type', 'group')->where('id', '!=', 1)->get())
111
                            ->addColumn('checkbox', function ($model) {
112
                                return "<input type='checkbox' class='product_checkbox' value=".$model->id.' name=select[] id=check>';
113
                            })
114
                            ->addColumn('name', function ($model) {
115
                                return ucfirst($model->name);
116
                            })
117
                            ->addColumn('type', function ($model) {
118
                                //dd($model->type());
119
                                if ($this->type->where('id', $model->type)->first()) {
120
                                    return $this->type->where('id', $model->type)->first()->name;
121
                                } else {
122
                                    return 'Not available';
123
                                }
124
                            })
125
                            ->addColumn('group', function ($model) {
126
                                //dd($model->type());
127
                                if ($this->group->where('id', $model->group)->first()) {
128
                                    return $this->group->where('id', $model->group)->first()->name;
129
                                } else {
130
                                    return 'Not available';
131
                                }
132
                            })
133
                            ->addColumn('price', function ($model) {
134
                                if ($this->price->where('product_id', $model->id)->first()) {
135
                                    return $this->price->where('product_id', $model->id)->first()->price;
136
                                } else {
137
                                    return 'Not available';
138
                                }
139
                            })
140
                            ->addColumn('currency', function ($model) {
141
                                if ($this->price->where('product_id', $model->id)->first()) {
142
                                    return $this->price->where('product_id', $model->id)->first()->currency;
143
                                } else {
144
                                    return 'Not available';
145
                                }
146
                            })
147
                            ->addColumn('Action', function ($model) {
148
                                $url = '';
149
                                if ($model->type == 2) {
150
                                    $url = '<a href='.url('product/download/'.$model->id)." class='btn btn-sm btn-primary btn-xs'><i class='fa fa-download' style='color:white;'> </i>&nbsp;&nbsp;Download</a>";
151
                                }
152
153
                                return '<p><a href='.url('products/'.$model->id.'/edit')." class='btn btn-sm btn-primary btn-xs'><i class='fa fa-edit' style='color:white;'> </i>&nbsp;&nbsp;Edit</a>&nbsp;$url</p>";
154
                            })
155
156
                            ->rawColumns(['checkbox', 'name', 'type', 'group', 'price', 'currency', 'Action'])
157
                            ->make(true);
158
            } catch (\Exception $e) {
159
                Bugsnag::notifyException($e);
160
161
                return redirect()->back()->with('fails', $e->getMessage());
162
            }
163
        }
164
165
        public function getUpload($id)
166
        {
167
            $new_upload = ProductUpload::where('product_id', '=', $id)->select('id', 'product_id', 'title', 'description', 'version', 'file')->get();
168
169
            return \DataTables::of($new_upload)
170
        ->addColumn('checkbox', function ($model) {
171
            return "<input type='checkbox' class='upload_checkbox' value=".$model->id.' name=select[] id=checks>';
172
        })
173
174
        ->addColumn('product_id', function ($model) {
175
            return ucfirst($this->product->where('id', $model->product_id)->first()->name);
176
        })
177
178
        ->addColumn('title', function ($model) {
179
            return ucfirst($model->title);
180
        })
181
        ->addColumn('description', function ($model) {
182
            return ucfirst($model->description);
183
        })
184
        ->addColumn('version', function ($model) {
185
            return $model->version;
186
        })
187
188
        ->addColumn('file', function ($model) {
189
            return $model->file;
190
        })
191
        ->addColumn('action', function ($model) {
192
            return '<a href='.('#edit-upload-option/'.$model->id).'  class=" btn btn-sm btn-primary " data-title="'.$model->title.'" data-description="'.$model->description.'" data-version="'.$model->version.'" data-id="'.$model->id.'" onclick="openEditPopup(this)" >Edit</a>';
193
        })
194
        ->rawcolumns(['checkbox', 'product_id', 'title', 'description', 'version', 'file', 'action'])
195
        ->make(true);
196
        }
197
198
        // Save file Info in Modal popup
199
        public function save(Request $request)
200
        {
201
            try {
202
                $product_id = Product::where('name', '=', $request->input('product'))->select('id')->first();
203
204
                $this->product_upload->product_id = $product_id->id;
205
                $this->product_upload->title = $request->input('title');
206
                $this->product_upload->description = $request->input('description');
207
                $this->product_upload->version = $request->input('version');
208
209
                // dd($request->hasFi le('file'));
210
                if ($request->file) {
211
                    $file = $request->file('file')->getClientOriginalName();
212
213
                    $destination = storage_path().'/products';
214
                    $request->file('file')->move($destination, $file);
215
                    $this->product_upload->file = $file;
216
                }
217
                $this->product_upload->save();
218
219
                return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
220
            } catch (\Exception $e) {
221
                Bugsnag::notifyException($e);
222
223
                return redirect()->with('fails', $e->getMessage());
224
            }
225
        }
226
227
        //Update the File Info
228
        public function uploadUpdate($id, Request $request)
229
        {
230
            $file_upload = ProductUpload::find($id);
231
232
            $file_upload->title = $request->input('title');
233
            $file_upload->description = $request->input('description');
234
            $file_upload->version = $request->input('version');
235
            if ($request->file) {
236
                $file = $request->file('file')->getClientOriginalName();
237
238
                $destination = storage_path().'/products';
239
                $request->file('file')->move($destination, $file);
240
                $file_upload->file = $file;
241
            }
242
            $file_upload->save();
243
244
            return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
245
        }
246
247
        /**
248
         * Show the form for creating a new resource.
249
         *
250
         * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Product\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
251
         */
252
        public function create()
253
        {
254
            try {
255
                /*
256
                 * server url
257
                 */
258
                $url = $this->GetMyUrl();
259
                $i = $this->product->orderBy('created_at', 'desc')->first()->id + 1;
260
                $cartUrl = $url.'/pricing?id='.$i;
261
                $type = $this->type->pluck('name', 'id')->toArray();
262
                $subscription = $this->plan->pluck('name', 'id')->toArray();
263
                $currency = $this->currency->pluck('name', 'code')->toArray();
264
                $group = $this->group->pluck('name', 'id')->toArray();
265
                $products = $this->product->pluck('name', 'id')->toArray();
266
                $periods = $this->period->pluck('name', 'days')->toArray();
267
                $taxes = $this->tax_class->pluck('name', 'id')->toArray();
268
                // dd($taxes);
269
                return view('themes.default1.product.product.create', compact('subscription', 'type', 'periods', 'currency', 'group', 'cartUrl', 'products', 'taxes'));
270
            } catch (\Exception $e) {
271
                Bugsnag::notifyException($e);
272
273
                return redirect()->back()->with('fails', $e->getMessage());
274
            }
275
        }
276
277
        /**
278
         * Store a newly created resource in storage.
279
         *
280
         * @return Response
281
         */
282
        public function store(Request $request)
283
        {
284
            $input = $request->all();
285
            // dd($input);
286
            $v = \Validator::make($input, [
287
                        'name'    => 'required|unique:products,name',
288
                        'type'    => 'required',
289
                        'group'   => 'required',
290
                        // 'image'   => 'sometimes | mimes:jpeg,jpg,png,gif | max:1000',
291
                        // 'version' => 'required',
292
            ]);
293
            // $v->sometimes(['file', 'image', 'version'], 'required', function ($input) {
294
            //     return $input->type == 2 && $input->github_owner == '' && $input->github_repository == '';
295
            // });
296
297
            // $v->sometimes(['github_owner', 'github_repository'], 'required', function ($input) {
298
            //     return $input->type == 2 && $input->file == '' && $input->image == '';
299
            // });
300
            // $v->sometimes(['currency', 'price'], 'required', function ($input) {
301
            //     return $input->subscription != 1;
302
            // });
303
            if ($v->fails()) {
304
                //     $currency = $input['currency'];
305
306
                return redirect()->back()
307
                        ->withErrors($v)
308
                        ->withInput()
309
                        ->with('currency');
310
            }
311
312
            try {
313
                if ($request->hasFile('image')) {
314
                    $image = $request->file('image')->getClientOriginalName();
315
                    $imagedestinationPath = 'dist/product/images';
316
                    $request->file('image')->move($imagedestinationPath, $image);
317
                    $this->product->image = $image;
318
                }
319
320
                $product = $this->product;
321
                $product->fill($request->except('image', 'file'))->save();
322
                // Product::where('id',$product->id)->update(['name'=>$request->names]);
323
324
                $product_id = $product->id;
325
                $subscription = $request->input('subscription');
326
327
                $price = $request->input('price');
328
                // $price=
329
330
                $sales_price = $request->input('sales_price');
331
                $currencies = $request->input('currency');
332
                // if (count($currencies) > 0) {
333
                //     foreach ($currencies as $key => $currency) {
334
                //         $this->price->create(['product_id' => $product_id, 'currency' => $currency, 'subscription' => $subscription, 'price' => $price[$key], 'sales_price' => $sales_price[$key]]);
335
                //     }
336
                // }
337
338
                $taxes = $request->input('tax');
339
                // dd($taxes);
340
341
                if ($taxes) {
342
                    foreach ($taxes as $key=>$value) {
343
                        $newtax = new TaxProductRelation();
344
                        $newtax->product_id = $product_id;
345
                        $newtax->tax_class_id = $value;
346
                        $newtax->save();
347
                    }
348
                }
349
350
                return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
351
            } catch (\Exception $e) {
352
                Bugsnag::notifyException($e);
353
354
                return redirect()->with('fails', $e->getMessage());
355
            }
356
        }
357
358
359
        /**
360
         * Show the form for editing the specified resource.
361
         *
362
         * @param int $id
363
         *
364
         * @return Response
365
         */
366
        public function edit($id)
367
        {
368
            try {
369
                $type = $this->type->pluck('name', 'id')->toArray();
370
371
                $subscription = $this->plan->pluck('name', 'id')->toArray();
372
                $currency = $this->currency->pluck('name', 'code')->toArray();
373
                $group = $this->group->pluck('name', 'id')->toArray();
374
                $products = $this->product->pluck('name', 'id')->toArray();
375
                $periods = $this->period->pluck('name', 'days')->toArray();
376
                $url = $this->GetMyUrl();
377
                $cartUrl = $url.'/cart?id='.$id;
378
                $product = $this->product->where('id', $id)->first();
379
                $price = $this->price->where('product_id', $product->id);
380
                foreach ($currency as $key => $value) {
381
                    if ($this->price->where('product_id', $product->id)->where('currency', $key)->first()) {
382
                        $regular[$key] = $this->price->where('product_id', $product->id)->where('currency', $key)->first()->price;
383
                        $sales[$key] = $this->price->where('product_id', $product->id)->where('currency', $key)->first()->sales_price;
384
                    } else {
385
                        $regular[$key] = '';
386
                        $sales[$key] = '';
387
                    }
388
                }
389
390
                $taxes = $this->tax_class->pluck('name', 'id')->toArray();
391
                // dd($taxes);
392
                $saved_taxes = $this->tax_relation->where('product_id', $id)->get();
393
                $savedTaxes = $this->tax_relation->where('product_id', $id)->pluck('tax_class_id')->toArray();
394
395
                return view('themes.default1.product.product.edit', compact('product', 'periods', 'type', 'subscription', 'currency', 'group', 'price', 'cartUrl', 'products', 'regular', 'sales', 'taxes', 'saved_taxes', 'savedTaxes'));
396
            } catch (\Exception $e) {
397
                Bugsnag::notifyException($e);
398
399
                return redirect()->back()->with('fails', $e->getMessage());
400
            }
401
        }
402
403
        /**
404
         * Update the specified resource in storage.
405
         *
406
         * @param int $id
407
         *
408
         * @return Response
409
         */
410
        public function update($id, Request $request)
411
        {
412
            $input = $request->all();
413
            $v = \Validator::make($input, [
414
                        'name'    => 'required',
415
                        'type'    => 'required',
416
                        'group'   => 'required',
417
                        'image'   => 'sometimes | mimes:jpeg,jpg,png,gif | max:1000',
418
    //                    'subscription' => 'required',
419
    //                    'currency.*' => 'required',
420
    //                    'price.*' => 'required',
421
            ]);
422
 
423
            if ($v->fails()) {
424
                return redirect()->back()->with('errors', $v->errors());
425
            }
426
427
            try {
428
                $product = $this->product->where('id', $id)->first();
429
                if ($request->hasFile('image')) {
430
                    $image = $request->file('image')->getClientOriginalName();
431
                    $imagedestinationPath = 'dist/product/images';
432
                    $request->file('image')->move($imagedestinationPath, $image);
433
                    $product->image = $image;
434
                }
435
                if ($request->hasFile('file')) {
436
                    $file = $request->file('file')->getClientOriginalName();
437
                    $filedestinationPath = storage_path().'/products';
438
                    $request->file('file')->move($filedestinationPath, $file);
439
                    $product->file = $file;
440
                }
441
                $product->fill($request->except('image', 'file'))->save();
442
                $this->updateVersionFromGithub($product->id);
443
444
                $product_id = $product->id;
445
                $subscription = $request->input('subscription');
446
                $cost = $request->input('price');
447
                $sales_price = $request->input('sales_price');
448
                $currencies = $request->input('currency');
449
450
                $prices = $this->price->where('product_id', $product->id)->get();
451
452
                if (count($currencies) > 0) {
453
                    foreach ($prices as $price) {
454
                        $price->delete();
455
                    }
456
457
                    foreach ($currencies as $key => $currency) {
458
                        $this->price->create(['product_id' => $product_id, 'currency' => $currency, 'price' => $cost[$key], 'sales_price' => $sales_price[$key]]);
459
                    }
460
                }
461
                //add tax class to tax_product_relation table
462
                $taxes = $request->input('tax');
463
                // dd($taxes);
464
                if ($taxes) {
465
                    $this->tax_relation->where('product_id', $product_id)->delete();
466
                    foreach ($taxes as $tax) {
467
                        $newTax = new TaxProductRelation();
468
                        $newTax->product_id = $product_id;
469
                        $newTax->tax_class_id = $tax;
470
                        $newTax->save();
471
                    }
472
                }
473
474
                return redirect()->back()->with('success', \Lang::get('message.updated-successfully'));
475
            } catch (\Exception $e) {
476
                Bugsnag::notifyException($e);
477
478
                return redirect()->back()->with('fails', $e->getMessage());
479
            }
480
        }
481
482
        /**
483
         * Remove the specified resource from storage.
484
         *
485
         * @param int $id
486
         *
487
         * @return Response
488
         */
489
        public function destroy(Request $request)
490
        {
491
            try {
492
                $ids = $request->input('select');
493
                if (!empty($ids)) {
494
                    foreach ($ids as $id) {
495
                        if ($id != 1) {
496
                            $product = $this->product->where('id', $id)->first();
497
                            if ($product) {
498
                                $product->delete();
499
                            } else {
500
                                echo "<div class='alert alert-danger alert-dismissable'>
501
                    <i class='fa fa-ban'></i>
502
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> './* @scrutinizer ignore-type */\Lang::get('message.failed').'
503
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
504
                        './* @scrutinizer ignore-type */\Lang::get('message.no-record').'
505
                </div>';
506
                                //echo \Lang::get('message.no-record') . '  [id=>' . $id . ']';
507
                            }
508
                            echo "<div class='alert alert-success alert-dismissable'>
509
                    <i class='fa fa-ban'></i>
510
                    <b>".\Lang::get('message.alert').'!</b> './* @scrutinizer ignore-type */ \Lang::get('message.success').'
0 ignored issues
show
Bug introduced by
Are you sure Lang::get('message.alert') of type null|string|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

510
                    <b>"./** @scrutinizer ignore-type */ \Lang::get('message.alert').'!</b> './* @scrutinizer ignore-type */ \Lang::get('message.success').'
Loading history...
511
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
512
                        './* @scrutinizer ignore-type */\Lang::get('message.deleted-successfully').'
513
                </div>';
514
                        } else {
515
                            echo "<div class='alert alert-danger alert-dismissable'>
516
                    <i class='fa fa-ban'></i>
517
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '.
518
                    /* @scrutinizer ignore-type */\Lang::get('message.failed').'
519
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
520
                        './* @scrutinizer ignore-type */ \Lang::get('message.can-not-delete-default').'
521
                </div>';
522
                        }
523
                    }
524
                } else {
525
                    echo "<div class='alert alert-danger alert-dismissable'>
526
                    <i class='fa fa-ban'></i>
527
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.failed').'
0 ignored issues
show
Bug introduced by
Are you sure Lang::get('message.failed') of type null|string|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

527
                    <b>".\Lang::get('message.alert').'!</b> './** @scrutinizer ignore-type */ \Lang::get('message.failed').'
Loading history...
528
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
529
                        '.\/* @scrutinizer ignore-type */Lang::get('message.select-a-row').'
0 ignored issues
show
Bug introduced by
Are you sure Lang::get('message.select-a-row') of type null|string|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

529
                        './** @scrutinizer ignore-type */ \/* @scrutinizer ignore-type */Lang::get('message.select-a-row').'
Loading history...
530
                </div>';
531
                    //echo \Lang::get('message.select-a-row');
532
                }
533
                $lastActivity = Activity::all()->last();
534
            } catch (\Exception $e) {
535
                echo "<div class='alert alert-danger alert-dismissable'>
536
                    <i class='fa fa-ban'></i>
537
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.failed').'
538
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
539
                        '.$e->getMessage().'
540
                </div>';
541
            }
542
        }
543
544
        /**
545
         * Remove the specified resource from storage.
546
         *
547
         * @param int $id
548
         *
549
         * @return Response
550
         */
551
        public function fileDestroy(Request $request)
552
        {
553
            try {
554
                $ids = $request->input('select');
555
                if (!empty($ids)) {
556
                    foreach ($ids as $id) {
557
                        if ($id != 1) {
558
                            $product = $this->product_upload->where('id', $id)->first();
559
                            if ($product) {
560
                                $product->delete();
561
                            } else {
562
                                echo "<div class='alert alert-danger alert-dismissable'>
563
                    <i class='fa fa-ban'></i>
564
                    <b>"./** @scrutinizer ignore-type */ \Lang::get('message.alert').'!</b> '.
565
                    /* @scrutinizer ignore-type */\Lang::get('message.failed').'
566
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
567
                        './* @scrutinizer ignore-type */ \Lang::get('message.no-record').'
568
                </div>';
569
                                //echo \Lang::get('message.no-record') . '  [id=>' . $id . ']';
570
                            }
571
                            echo "<div class='alert alert-success alert-dismissable'>
572
                    <i class='fa fa-ban'></i>
573
                    <b>".\Lang::get('message.alert').'!</b> './* @scrutinizer ignore-type */ \Lang::get('message.success').'
0 ignored issues
show
Bug introduced by
Are you sure Lang::get('message.alert') of type null|string|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

573
                    <b>"./** @scrutinizer ignore-type */ \Lang::get('message.alert').'!</b> './* @scrutinizer ignore-type */ \Lang::get('message.success').'
Loading history...
574
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
575
                        './* @scrutinizer ignore-type */\Lang::get('message.deleted-successfully').'
576
                </div>';
577
                        } else {
578
                            echo "<div class='alert alert-danger alert-dismissable'>
579
                    <i class='fa fa-ban'></i>
580
                    <b>".\Lang::get('message.alert').'!</b> './* @scrutinizer ignore-type */\Lang::get('message.failed').'
581
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
582
                        './* @scrutinizer ignore-type */\Lang::get('message.can-not-delete-default').'
583
                </div>';
584
                        }
585
                    }
586
                } else {
587
                    echo "<div class='alert alert-danger alert-dismissable'>
588
                    <i class='fa fa-ban'></i>
589
                    <b>".\Lang::get('message.alert').'!</b> './* @scrutinizer ignore-type */\Lang::get('message.failed').'
590
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
591
                        './* @scrutinizer ignore-type */\Lang::get('message.select-a-row').'
592
                </div>';
593
                    //echo \Lang::get('message.select-a-row');
594
                }
595
            } catch (\Exception $e) {
596
                echo "<div class='alert alert-danger alert-dismissable'>
597
                    <i class='fa fa-ban'></i>
598
                    <b>".\Lang::get('message.alert').'!</b> './* @scrutinizer ignore-type */ \Lang::get('message.failed').'
599
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
600
                        '.$e->getMessage().'
601
                </div>';
602
            }
603
        }
604
605
       
606
607
        /*
608
        *  Download Files from Filesystem/Github
609
        */
610
        public function downloadProduct($uploadid, $id, $invoice_id, $version_id = '')
611
        {
612
            try {
613
                $product = $this->product->findOrFail($uploadid);
614
                $type = $product->type;
615
                $owner = $product->github_owner;
616
                $repository = $product->github_repository;
617
                $file = $this->product_upload->where('product_id', '=', $uploadid)->where('id', $version_id)->select('file')->first();
618
                $order = Order::where('invoice_id', '=', $invoice_id)->first();
619
                $order_id = $order->id;
620
                if ($type == 2) {
621
                    $relese = $this->getRelease($owner,$repository);
622
                    return $relese;
623
                }
624
            } catch (\Exception $e) {
625
                Bugsnag::notifyException($e);
626
                return redirect()->back()->with('fails', $e->getMessage());
627
            }
628
        }
629
630
       
631
      
632
        public function adminDownload($id, $invoice = '', $api = false)
633
        {
634
            try {
635
                $role = \Auth::user()->role;
636
                $release = $this->getLinkToDownload($role,$invoice,$id);
637
             
638
                if (is_array($release) && array_key_exists('type', $release)) {
639
                    header('Location: '.$release['release']);
640
                    exit;
641
                } else {
642
                    header('Content-type: Zip');
643
                    header('Content-Description: File Transfer');
644
                    header('Content-Disposition: attachment; filename=Faveo.zip');
645
                    header('Content-Length: '.filesize($release));
646
                    flush();
647
                    readfile("$release");
648
                }
649
            } catch (\Exception $e) {
650
                if ($api) {
651
                    return response()->json(['error'=>$e->getMessage()]);
652
                }
653
                Bugsnag::notifyException($e);
654
                return redirect()->back()->with('fails', $e->getMessage());
655
            }
656
        }
657
658
    
659
660
        public function getProductField($productid)
661
        {
662
            try {
663
                $field = '';
664
                $product = $this->product->find($productid);
665
                if ($product) {
666
                    if ($product->require_domain == 1) {
667
                        $field .= "<div class='col-md-4 form-group'>
668
                            <label class='required'>"./* @scrutinizer ignore-type */ \Lang::get('message.domain')."</label>
669
                            <input type='text' name='domain' class='form-control' id='domain' placeholder='http://example.com'>
670
                    </div>";
671
                    }
672
                }
673
674
                return $field;
675
            } catch (\Exception $ex) {
676
                Bugsnag::notifyException($ex);
677
678
                return $ex->getMessage();
679
            }
680
        }
681
682
       
683
684
685
        public function getSubscriptionCheckScript()
686
        {
687
            $response = "<script>
688
        function getPrice(val) {
689
            var user = document.getElementsByName('user')[0].value;
690
            var plan = '';
691
            if ($('#plan').length > 0) {
692
                var plan = document.getElementsByName('plan')[0].value;
693
            }
694
            //var plan = document.getElementsByName('plan')[0].value;
695
            //alert(user);
696
697
            $.ajax({
698
                type: 'POST',
699
                url: ".url('get-price').",
700
                data: {'product': val, 'user': user,'plan':plan},
701
                //data: 'product=' + val+'user='+user,
702
                success: function (data) {
703
                    var price = data['price'];
704
                    var field = data['field'];
705
                    $('#price').val(price);
706
                    $('#fields').append(field);
707
                }
708
            });
709
        }
710
711
    </script>";
712
        }
713
    }
714