/**
  *  Display a list of files available
  *  to the user
  */
 public function actionIndex()
 {
     $user = \Yii::$app->user->identity;
     $requestform = new RequestForm();
     // get the list of files
     $tfiles = File::find()->orderBy('filename')->all();
     //Bucket to store files we find
     $files = [];
     // Iterate through the list of files!!
     foreach ($tfiles as $f) {
         $include_file = TRUE;
         $groups = FileFileGroup::find()->where(['file_id' => $f->id])->all();
         foreach ($groups as $group) {
             // Get users for the file groups
             $usersgroup = UserFileGroup::find()->where(['file_group_id' => $group->group_id])->all();
             foreach ($usersgroup as $ug) {
                 if ($ug->user_id == $user->id) {
                     // exclude this file
                     $include_file == FALSE;
                 }
             }
         }
         if ($include_file == TRUE) {
             array_push($files, $f);
         }
     }
     // WHat do we do if they belong to everything???
     if (sizeof($files) == 0) {
         $this->redirect(['site/index']);
     }
     // See if user has access to any of these files
     //var_dump($files);
     //exit;
     $selected_file = [];
     // To lazy to create  a ActiveForm object to hold these values
     if (Yii::$app->request->post()) {
         $post = Yii::$app->request->post();
         $requestform->load(Yii::$app->request->post());
         if ($requestform->validate()) {
             // Create the request entry
             $request = new Request();
             $request->create_datetime = date("Y-m-d H:i:s");
             $request->reason = $requestform->request;
             $request->user_id = $user->id;
             $request->save();
             if ($requestform->file !== NULL && sizeof($requestform->file) > 0) {
                 foreach ($requestform->file as $f) {
                     $rf = new RequestFile();
                     $rf->file_id = $f;
                     $rf->request_id = $request->id;
                     $rf->save();
                 }
                 // Send the email to the administrators
                 $admins = User::find()->where(['role_id' => 1])->all();
                 $body = "A new file access request has been submitted.\n";
                 $body .= "Please visit on the following link:\n";
                 $body .= 'http://gmod.wsu.edu/portal/request/verify?id=' . $request->id . '';
                 foreach ($admins as $admin) {
                     Yii::$app->mailer->compose()->setTo($admin->email)->setFrom([$admin->email => $admin->username])->setSubject("File Access Request for GMOD Portal")->setTextBody($body)->send();
                 }
                 $this->redirect(['requestconfirm']);
             }
         }
     }
     return $this->render('index', ['model' => $requestform, 'user' => $user, 'files' => $files, 'selected_file' => $selected_file]);
 }