Exemplo n.º 1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $siteID = $request->route('sites');
     $site = \App\Models\Site::find($siteID);
     // normal and admin users accessing other site info
     if (\Auth::user()->super == "No") {
         if (\Auth::user()->site_id != $siteID) {
             if ($request->ajax()) {
                 return response('Unauthorized', 401);
             } else {
                 return redirect()->guest('noAccess');
             }
         }
     }
     // if super user is trying to access a site belonging to another company
     if (\Auth::user()->super == "Yes") {
         if (\Auth::user()->site->company_id != $site->company_id) {
             if ($request->ajax()) {
                 return response('Unauthorized', 401);
             } else {
                 return redirect()->guest('noAccess');
             }
         }
     }
     return $next($request);
 }
Exemplo n.º 2
0
 /**
  *
  * @param boolean $active        	
  * @return Ambigous <\yii\db\ActiveRecord, multitype:, NULL>|boolean
  */
 public function check($active = true)
 {
     $args = ['domain' => Yii::$app->getRequest()->serverName];
     if ($active) {
         $args['status'] = 'active';
     }
     if ($site = Site::find()->where($args)->one()) {
         $this->_checkAccess($site);
         return $site;
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params        	
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Site::find()->where(['user_id' => Yii::$app->user->id]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'domain', $this->domain]);
     return $dataProvider;
 }
 /**
  * Finds the Site model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param string $site        	
  * @return Site the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($site)
 {
     if (($model = Site::find()->where(['domain' => $site, 'user_id' => Yii::$app->user->id])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 5
0
 public function getJson(Site $site, $id)
 {
     return $site->find($id);
 }
Exemplo n.º 6
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(UpdateJobSiteRequest $request, $id)
 {
     //
     $site = \App\Models\Site::find($id);
     $site->fill($request->all());
     $site->save();
     return redirect('sites/' . $site->id)->with('update-success', 'Job Site has been updated.');
 }
Exemplo n.º 7
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(UpdateToolRequest $request, $id)
 {
     //
     $tool = \App\Models\Tool::find($id);
     $tool->fill($request->all());
     $type = \Request::get("type");
     // if company tool has been transferred
     $iPreviousSiteID = $tool->user->site_id;
     if ($tool->user->site_id != $request->get("site_id")) {
         $iNewSiteID = \App\Models\Site::find($request->get("site_id"))->users()->where("admin", "=", "Yes")->first()->site_id;
         $tool->user_id = \App\Models\Site::find($request->get("site_id"))->users()->where("admin", "=", "Yes")->first()->id;
         // send notification
         $notification = new \App\Models\Notification();
         $notification->message = '<a href="' . url("tools/" . $tool->id) . '">' . $tool->name . '</a>' . " has been transferred to this job site.";
         $notification->user_id = $tool->user_id;
         $notification->save();
         //send email
         Mail::send('emails.transfers', ['tool' => $tool], function ($m) {
             $m->from('*****@*****.**', 'Tag and Track');
             $m->to('*****@*****.**', 'Leanne')->subject('Company Tool has been transferred');
         });
         // transfers table
         $transfer = new \App\Models\Transfer();
         $transfer->previous_site_id = $iPreviousSiteID;
         $transfer->current_site_id = $iNewSiteID;
         $transfer->tool_id = $tool->id;
         $transfer->save();
     }
     // reset notifications flags, when retag date changes
     if ($tool->retag_date != $request->get("retag_date")) {
         $tool->five_notice = 0;
         $tool->three_notice = 0;
         $tool->one_notice = 0;
     }
     $tool->save();
     if ($request->has('tech_name')) {
         $name = $request->get('tech_name');
         $company = $request->get('tech_company');
         $phone = $request->get('contact_number');
         $technician = \App\Models\Technician::where("tech_name", '=', $name)->where("tech_company", '=', $company)->where("contact_number", '=', $phone)->first();
         // if technician doesn't exist
         if ($technician == false) {
             $technician = Technician::create($request->all());
         }
         $tool->technician_id = $technician->id;
         $tool->save();
     }
     if ($type == "Company") {
         return redirect('tools?type=Company')->with('message-update', 'Update successful.');
     } else {
         return redirect('tools?type=Personal')->with('message-update', 'Update successful.');
     }
 }