/** Add My Booth */
 public function actionBoothschedule()
 {
     if (Yii::$app->request->post()) {
         $boothschedule = new BoothSchedules();
         $value = \Yii::$app->request->post();
         if (isset($value['booth_id']) && isset($value['attendee_id'])) {
             $userid = User::findOne(['id' => $value['attendee_id']]);
             if ($userid) {
                 $contact = AmgenContactList::findOne($userid->attendee_id);
                 $checkboothexits = $boothschedule->findOne(['booth_id' => $value['booth_id'], 'attendee_id' => $userid->attendee_id]);
                 if ($checkboothexits) {
                     echo "Booth is already added for this attendee";
                 } else {
                     $boothschedule->booth_id = $value['booth_id'];
                     $boothschedule->attendee_id = $userid->attendee_id;
                     $boothschedule->function_id = $contact->function_Id;
                     $boothschedule->cost_center_id = "";
                     $boothschedule->status_id = 1;
                     if ($boothschedule->save(FALSE)) {
                         echo "Booth Schedule is Added";
                     }
                 }
             } else {
                 echo "Contact List not exist";
             }
         } else {
             echo "Please fill required ";
         }
     }
 }
 /**
  * Get details of workforce contacts
  */
 public function actionGetcontactdata()
 {
     $model1 = new AmgenContactList();
     $model2 = new CongressSchedules();
     $model1->workforce_id = $_POST['AmgenContactList']['workforce_id'];
     $wf_id = $model1->workforce_id;
     $exists = $model1::find()->where(['Name' => $wf_id])->exists();
     if ($exists) {
         $userid = \backend\models\AmgenContactList::find()->where(['Name' => $wf_id])->one();
         $userid = $userid['id'];
         $model2->attendee_id = $userid;
         $model2->congress_id = $_POST['CongressSchedules']['congress_id'];
         $congid = $_POST['CongressSchedules']['congress_id'];
         $sql = "select congress_id,attendee_id from congress_schedules where congress_id='{$congid}' and attendee_id='{$userid}'";
         $res = Yii::$app->db->createCommand($sql)->execute();
         if ($res == 0) {
             $model2->save(FALSE);
             echo "TRUE";
         } else {
             echo "FALSE";
         }
     } else {
         echo "Exists";
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function searchAmgenWorkforce($params)
 {
     $query = AmgenContactList::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         return $dataProvider;
     }
     $query->join('left join', 'workforce_contacts wc', self::tableName() . ".workforce_id = wc.id");
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'function_Id' => $this->function_Id, 'group_Id' => $this->group_Id, 'Phone' => $this->Phone, 'Created_on' => $this->Created_on]);
     $query->andFilterWhere(['like', 'last_name', $this->Name]);
     $query->orFilterWhere(['like', 'first_name', $this->Name]);
     $query->orderBy('last_name asc');
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAttendee()
 {
     return $this->hasOne(AmgenContactList::className(), ['id' => 'attendee_id']);
 }
/* @var $this yii\web\View */
/* @var $model backend\models\CongressDetails */
/* @var $form yii\widgets\ActiveForm */
$request = Yii::$app->request;
$id = $request->get('id');
$model1 = new \backend\models\AmgenContactList();
$model2 = new \backend\models\CongressSchedules();
$model2->congress_id = $id;
$model3 = new \backend\models\CongressAttachments();
$controller = Yii::$app->controller->id;
$action = Yii::$app->controller->action->id;
$workforce = new \backend\models\AmgenContactList();
$columns = [];
$columns[] = 'Name as value';
$columns[] = 'id as key';
$data = AmgenContactList::find()->select($columns)->where('workforce_id != :workforce_id', [':workforce_id' => 'NULL'])->asArray()->all();
if (isset($_SERVER['HTTP_REFERER'])) {
    $back = $_SERVER['HTTP_REFERER'];
} else {
    $back = Url::home();
}
?>


<div class="m15 m-0-40">
    <div class="f30">Congress</div>
    <div class="bdr">
        <button type="button" class="btn_booths float_left active" style="margin-left:0">Congress Details</button>
        <?php 
echo Html::a('  <button class="btn_booths float_left " type="button">Congress Schedule</button>', ['sda/index', 'id' => $id], ['class' => 'profile-link']);
?>
 /**
  * Finds the AmgenContactList model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AmgenContactList the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AmgenContactList::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
    }
}
if (count($modelsAttendees) == 0) {
    $modelsAttendees = [new \backend\models\MeetingSchedules()];
}
if (count($modelsOlAttendees) == 0) {
    $modelsOlAttendees = [new \backend\models\MeetingSchedules()];
}
//$model1 = new \backend\models\SdaSchedules();
$model1 = new \backend\models\MeetingSchedules();
$request = Yii::$app->request;
$id = $request->get('id');
$controller = Yii::$app->controller->id;
$action = Yii::$app->controller->action->id;
$congid = $model->congress_id;
$data = AmgenContactList::find()->select(['Name as value'])->asArray()->all();
$olattendees = OlAttendees::find()->select(['name as value'])->asArray()->all();
?>




<div class="meeting-details-form">
    <div class="btn-group" role="group" aria-label="First group" style="width:33%;margin-left: 34px;">

        <?php 
echo Html::a('  <button class="btn_booths float_left active " type="button">Congress Schedule</button>', ['sda/index', 'id' => $congid], ['class' => 'profile-link']);
?>

    </div>
    <?php 
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAmgenContactLists()
 {
     return $this->hasMany(AmgenContactList::className(), ['workforce_id' => 'id']);
 }
 /**
  * Import booth data using spreadsheet
  * @return mixed
  */
 public function actionExcel()
 {
     $model = new Booths();
     if ($model->load(Yii::$app->request->post())) {
         $congid = $_POST['Booths']['id'];
         $model->fileName = UploadedFile::getInstance($model, 'fileName');
         $time = time();
         $model->fileName->saveAs('csv/' . $time . '.' . $model->fileName->extension);
         $model->fileName = 'csv/' . $time . '.' . $model->fileName->extension;
         $handle = fopen($model->fileName, "r");
         $row = 1;
         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
             $row++;
             if ($row == 2) {
                 //Ignoring row 2
             } else {
                 //Parsing Time
                 $time = $data[2];
                 $exp = explode('-', $time);
                 $starttime = $exp[0];
                 $endtime = $exp[1];
                 //Getting User ID
                 $userData = AmgenContactList::find()->where(['Name' => $data[6]])->one();
                 $userid = $userData['id'];
                 $title = $data[7];
                 $departmentData = Functions::find()->where(['Name' => $data[8]])->one();
                 $department_id = $departmentData['ID'];
                 $group = CostCenter::find()->where(['Group_name' => $data[9]])->one();
                 $group_id = $group['id'];
                 //Getting Status  ID
                 $statusInfo = Status::find()->where(['status' => $data[10]])->one();
                 $status_id = $statusInfo['id'];
                 $sql = "INSERT into booths(congress_id,booth_name,from_time,to_time,date,location) values('{$congid}','{$data['1']}','{$starttime}','{$endtime}','{$data['3']}','{$data['4']}')";
                 $query = Yii::$app->db->createCommand($sql)->execute();
                 $booth_id = Yii::$app->db->getLastInsertID();
                 $sql_booth_schedule = "INSERT into booth_schedules(booth_id,attendee_id,title,function_id,cost_center_id,status_id) values('{$booth_id}','{$userid}','{$title}','{$department_id}','{$group_id}','{$status_id}')";
                 Yii::$app->db->createCommand($sql_booth_schedule)->execute();
             }
         }
         fclose($handle);
         print "Import done";
     }
     return $this->render('excel', ['model' => $model]);
 }
 /**
  * Uploads ol engagement data in CSV format
  * @return mixed
  */
 public function actionOlupload()
 {
     $model = new Olform();
     $congress = Yii::$app->getRequest()->getQueryParam('congress');
     if ($model->load(Yii::$app->request->post())) {
         $row = 1;
         $model->csvfile = UploadedFile::getInstance($model, 'csvfile');
         $time = time();
         $model->csvfile->saveAs('csv/' . $time . '.' . $model->csvfile->extension);
         $model->csvfile = 'csv/' . $time . '.' . $model->csvfile->extension;
         $requiredHeaders = array('Title', 'Meeting Type', 'Date', 'Start Time', 'End Time', 'Location', 'Amgen attendees', 'OL attendees', 'Commercial/Medical/Joint', 'Joint Meeting Approval Received', 'Restricted State Rules', 'Consultant', 'Catering', 'Notes');
         $f = fopen($model->csvfile, 'r');
         $firstLine = fgets($f);
         //get first line of csv file
         fclose($f);
         $foundHeaders = array_map('trim', str_getcsv(trim($firstLine), ',', '"'));
         //parse to array
         $handle = fopen($model->csvfile, "r");
         if ($foundHeaders == $requiredHeaders) {
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 $approval = 0;
                 $rsr = 0;
                 $consultant = 0;
                 $row++;
                 $eventtype = \backend\models\MeetingTypes::find()->where(['type' => $data[1]])->one();
                 $eventtype = isset($eventtype['id']) ? $eventtype['id'] : '4';
                 $profile = OlProfiles::find()->where(['name' => $data[8]])->one();
                 $profiletype = isset($profile['id']) ? $profile['id'] : '1';
                 if ($data[9] == "Yes") {
                     $approval = 1;
                 }
                 if ($data[10] == "Yes") {
                     $rsr = 1;
                 }
                 if ($data[11] == "Yes") {
                     $consultant = 1;
                 }
                 if ($row == 2) {
                     //ignoring
                 } else {
                     //Save the row
                     $meetingdetails = new \backend\models\MeetingDetails();
                     $meetingdetails->congress_id = $congress;
                     $meetingdetails->title = $data[0];
                     $meetingdetails->date = date("Y-m-d H:i:s", strtotime($data[2]));
                     $meetingdetails->start_time = $data[3];
                     $meetingdetails->stop_time = $data[4];
                     $meetingdetails->location = $data[5];
                     $meetingdetails->event_type = $eventtype;
                     if ($eventtype == "3") {
                         $meetingdetails->ol_profile_id = $profiletype;
                         $meetingdetails->rsr = $rsr;
                         $meetingdetails->meeting_approval = $approval;
                         $meetingdetails->ol_consultant = $consultant;
                         $meetingdetails->ol_catering = $data[12];
                         $meetingdetails->notes = $data[13];
                     }
                     try {
                         $meetingdetails->save();
                         $amgenatten = explode(',', $data[6]);
                         $olattendee = explode(',', $data[7]);
                         if (count($amgenatten) > 0) {
                             foreach ($amgenatten as $value) {
                                 $value = trim($value);
                                 $amgenattendee = explode(' ', $value);
                                 if (!empty($amgenattendee[0]) && !empty($amgenattendee[1])) {
                                     $attendeeexits = \backend\models\AmgenContactList::find()->where(['first_name' => $amgenattendee[0], 'last_name' => $amgenattendee[1]])->one();
                                     if ($attendeeexits) {
                                         $olengagement = new OlEngagement();
                                         $olengagement->congress_id = $congress;
                                         $olengagement->meeting_id = $meetingdetails->id;
                                         $olengagement->title = $data[0];
                                         $olengagement->ol_date = date("Y-m-d H:i:s", strtotime($data[2]));
                                         $olengagement->ol_start_time = $data[3];
                                         $olengagement->ol_end_time = $data[4];
                                         $olengagement->location = $data[5];
                                         $olengagement->attendee_id = $attendeeexits->id;
                                         $olengagement->ol_attendee_id = '';
                                         $olengagement->ol_profile_id = $profiletype;
                                         $olengagement->meeting_approval = $approval;
                                         $olengagement->rsr = $rsr;
                                         $olengagement->ol_consultant = $consultant;
                                         $olengagement->ol_catering = $data[12];
                                         $olengagement->notes = $data[13];
                                         $olengagement->save(TRUE);
                                         try {
                                             $olengagement->save(FALSE);
                                         } catch (\Exception $exc) {
                                             echo $exc->getTraceAsString();
                                         }
                                         $meetingschedule = new \backend\models\MeetingSchedules();
                                         $meetingschedule->congress_id = $congress;
                                         $meetingschedule->meeting_id = $meetingdetails->id;
                                         $meetingschedule->attendee_id = $attendeeexits->id;
                                         $meetingschedule->ol_attendee_id = "";
                                         $meetingschedule->save(FALSE);
                                     }
                                 }
                             }
                         }
                         if (count($olattendee) > 0) {
                             foreach ($olattendee as $value) {
                                 $value = trim($value);
                                 $oladata = explode(' ', $value);
                                 if (!empty($oladata[0]) && !empty($oladata[1])) {
                                     $olattendeeexits = \backend\models\OlAttendees::find()->where(['first_name' => $oladata[0], 'last_name' => $oladata[1]])->one();
                                     if ($olattendeeexits) {
                                         $olengagement = new OlEngagement();
                                         $olengagement->congress_id = $congress;
                                         $olengagement->meeting_id = $meetingdetails->id;
                                         $olengagement->title = $data[0];
                                         $olengagement->ol_date = date("Y-m-d H:i:s", strtotime($data[2]));
                                         $olengagement->ol_start_time = $data[3];
                                         $olengagement->ol_end_time = $data[4];
                                         $olengagement->location = $data[5];
                                         $olengagement->attendee_id = '';
                                         $olengagement->ol_attendee_id = $olattendeeexits->id;
                                         $olengagement->ol_profile_id = $profiletype;
                                         $olengagement->meeting_approval = $approval;
                                         $olengagement->rsr = $rsr;
                                         $olengagement->ol_consultant = $consultant;
                                         $olengagement->ol_catering = $data[12];
                                         $olengagement->notes = $data[13];
                                         $olengagement->save(TRUE);
                                         try {
                                             $olengagement->save(FALSE);
                                         } catch (Exception $exc) {
                                             echo $exc->getTraceAsString();
                                         }
                                         $meetingschedule = new \backend\models\MeetingSchedules();
                                         $meetingschedule->congress_id = $congress;
                                         $meetingschedule->meeting_id = $meetingdetails->id;
                                         $meetingschedule->attendee_id = '';
                                         $meetingschedule->ol_attendee_id = $olattendeeexits->id;
                                         $meetingschedule->save(FALSE);
                                     }
                                 }
                             }
                         }
                     } catch (Exception $exc) {
                         echo $exc->getTraceAsString();
                     }
                 }
             }
             Yii::$app->getSession()->setFlash('success', 'All OL  is Uploaded Successfully');
         } else {
             Yii::$app->getSession()->setFlash('error', 'CSV is in Incorrect format');
         }
         fclose($handle);
         $this->redirect(['meeting/index', 'id' => $congress]);
     } else {
         return $this->render('csvupload', ['model' => $model]);
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAmgenContactLists()
 {
     return $this->hasMany(AmgenContactList::className(), ['function_Id' => 'ID']);
 }
 /**
  * Import SDA in CSV format
  * @return mixed
  */
 public function actionExcel()
 {
     $model = new Sda();
     if ($model->load(Yii::$app->request->post())) {
         $row = 1;
         $congid = $_POST['Sda']['id'];
         $model->fileName = UploadedFile::getInstance($model, 'fileName');
         $time = time();
         $model->fileName->saveAs('csv/' . $time . '.' . $model->fileName->extension);
         $model->fileName = 'csv/' . $time . '.' . $model->fileName->extension;
         $requiredHeaders = array('Title', 'Abstract #', 'Priority', 'Abstract', 'Assigned to', 'Date', 'Product', 'Session Start Time', 'Session End Time', 'Presentation Start Time', 'Presentation End Time', 'Presenter', 'SDA type', 'Location', 'Category', 'Session id', 'Session #', 'Authors', 'Company', 'Team', 'Link to Poster', 'Poster Board Number', 'Presentation Number');
         $f = fopen($model->fileName, 'r');
         $firstLine = fgets($f);
         //get first line of csv file
         fclose($f);
         $foundHeaders = array_map('trim', str_getcsv(trim($firstLine), ',', '"'));
         //parse to array
         $result = array_diff_assoc($foundHeaders, $requiredHeaders);
         $csverrormessage = implode(",", $result);
         if ($foundHeaders !== $requiredHeaders) {
             \Yii::$app->getSession()->setFlash('error', 'CSV is in incorrect for ' . $csverrormessage . ' Column');
         } else {
             $handle = fopen($model->fileName, "r");
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 $row++;
                 // Getting Product id
                 $product = \backend\models\Products::find()->where(['name' => $data[6]])->one();
                 $product = isset($product['id']) ? $product['id'] : '';
                 // Getting Priority  ID
                 $priority_name = SdaPriority::find()->where(['priority_name' => $data[2]])->one();
                 $priority_name = isset($priority_name['id']) ? $priority_name['id'] : '3';
                 // Getting Sda Type  ID
                 $sdatype = SdaTypes::find()->where(['sda_name' => $data[12]])->one();
                 $sdatype = isset($sdatype['id']) ? $sdatype['id'] : '9';
                 $cmp = CompanyDetails::find()->where(['name' => $data[18]])->one();
                 $cmp = isset($cmp['id']) ? $cmp['id'] : '2';
                 if ($row == 2) {
                     //ignoring
                 } else {
                     $title = Yii::$app->db->quoteValue($data[0]);
                     $abstracthash = Yii::$app->db->quoteValue($data[1]);
                     $abstract = Yii::$app->db->quoteValue($data[3]);
                     $amgenatten = explode(',', $data[4]);
                     $date = Yii::$app->db->quoteValue(date("Y-m-d H:i:s", strtotime($data[5])));
                     $prod = Yii::$app->db->quoteValue($product);
                     if (!empty($data[7])) {
                         $sessiostart = Yii::$app->db->quoteValue(date("H:i:s", strtotime($data[7])));
                     } else {
                         $sessiostart = "null";
                     }
                     if (!empty($data[8])) {
                         $sessionend = Yii::$app->db->quoteValue(date("H:i:s", strtotime($data[8])));
                     } else {
                         $sessionend = "null";
                     }
                     if (!empty($data[9])) {
                         $presentationstart = Yii::$app->db->quoteValue(date("H:i:s", strtotime($data[9])));
                     } else {
                         $presentationstart = "null";
                     }
                     if (!empty($data[10])) {
                         $presentationend = Yii::$app->db->quoteValue(date("H:i:s", strtotime($data[10])));
                     } else {
                         $presentationend = "null";
                     }
                     $presenter = Yii::$app->db->quoteValue($data[11]);
                     $location = Yii::$app->db->quoteValue($data[13]);
                     $category = Yii::$app->db->quoteValue($data[14]);
                     $session = Yii::$app->db->quoteValue($data[15]);
                     $sessionhash = Yii::$app->db->quoteValue($data[16]);
                     $authors = Yii::$app->db->quoteValue($data[17]);
                     $team = Yii::$app->db->quoteValue($data[19]);
                     $linktoposter = Yii::$app->db->quoteValue($data[20]);
                     $posterboard = Yii::$app->db->quoteValue($data[21]);
                     $presentationno = Yii::$app->db->quoteValue($data[22]);
                     if ($title) {
                         $sql = "insert into sda(\n                                          congress_id,\n                                          title,\n                                          abstract_id,\n                                          priority,\n                                          abstract,\n                                          date,\n                                          session_start_time,\n                                          session_end_time,\n                                          presentation_start_time,\n                                          presentation_end_time,\n                                          presenter,\n                                          sda_type_id,\n                                          product,\n                                          location,\n                                          category,\n                                          session_id,\n                                          session,\n                                          authors,\n                                          company_id,\n                                          team,\n                                          link_to_poster,\n                                          poster_board_no,\n                                          presentation_no\n                                         )" . " values (" . "'{$congid}'," . "{$title}," . "{$abstracthash}," . "'{$priority_name}'," . "{$abstract}," . "{$date}," . "{$sessiostart}," . "{$sessionend}," . "{$presentationstart}," . "{$presentationend}," . "{$presenter}," . "'{$sdatype}'," . "'{$product}'," . "{$location}," . "{$category}," . "{$session}," . "{$sessionhash}," . "{$authors}," . "'{$cmp}'," . "{$team}," . "{$linktoposter}," . "{$posterboard}," . "{$presentationno})";
                         //save the data
                         Yii::$app->db->createCommand($sql)->execute();
                         $sdaId = Yii::$app->db->getLastInsertID();
                         if (count($amgenatten) > 0) {
                             foreach ($amgenatten as $value) {
                                 $value = trim($value);
                                 $amgenattendee = explode(' ', $value);
                                 if (!empty($amgenattendee[0]) && !empty($amgenattendee[1])) {
                                     $attendeeexits = \backend\models\AmgenContactList::find()->where(['first_name' => $amgenattendee[0], 'last_name' => $amgenattendee[1]])->one();
                                     if ($attendeeexits) {
                                         $modelSdaSchedule = new \backend\models\SdaSchedules();
                                         $modelSdaSchedule->sda_id = $sdaId;
                                         $modelSdaSchedule->congress_id = $congid;
                                         $modelSdaSchedule->attendee_id = $attendeeexits->id;
                                         $modelSdaSchedule->assigned = 0;
                                         $modelSdaSchedule->save(false);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             fclose($handle);
             Yii::$app->getSession()->setFlash('success', 'All SDA is Uploaded Successfully');
         }
     }
     return $this->render('excel', ['model' => $model]);
 }
/* @var $form yii\widgets\ActiveForm */
$request = Yii::$app->request;
$id = (int) $request->get('id');
//Cast to int for security
$model1 = new \backend\models\AmgenContactList();
$model2 = new \backend\models\CongressSchedules();
$model2->congress_id = $id;
$model3 = new \backend\models\CongressAttachments();
$controller = Yii::$app->controller->id;
$action = Yii::$app->controller->action->id;
$workforce = new \backend\models\AmgenContactList();
$mindate = date('m-d-Y');
$columns = [];
$columns[] = 'Name as value';
$columns[] = 'id as key';
$data = AmgenContactList::find()->select($columns)->asArray()->all();
if (isset($_SERVER['HTTP_REFERER'])) {
    $back = $_SERVER['HTTP_REFERER'];
} else {
    //
    $back = Url::home();
}
?>
<div class="m15 m-0-40">
    <div class="f30">Congress</div>
    <div class="bdr">
        <?php 
if ($action == "update") {
    ?>
            <?php 
    echo Html::a('  <button class="btn_booths float_left active" type="button">Congress Details</button>', ['congress/view', 'id' => $id], []);