<?php

include('includes/session1.php');

error_reporting(0);

include('includes/dbconnection.php');
require_once 'includes/session_term_helper.php';
$stResult = resolveCurrentSessionTerm($con);
$currentSessionName = $stResult['session_name'];
$currentTermName    = $stResult['term_name'];

include('includes/flash.php');



if (strlen($_SESSION['sid'] == 0)) {

  header('location:logoutteacher.php');

} else {

  if (isset($_POST['submit'])) {

    $eid = $_SESSION['sid'];

    $email = $_POST['email'];

    $mobile = $_POST['mobile'];

    $name = $_POST['firstname'];

    $lastname = $_POST['lastname'];

    $username = $_POST['username'];

    $sql = "update tblusers set name=:name,username=:username,mobile=:mobile,email=:email,lastname=:lastname where id=:eid";

    $query = $dbh->prepare($sql);

    $query->bindParam(':name', $name, PDO::PARAM_STR);

    $query->bindParam(':lastname', $lastname, PDO::PARAM_STR);

    $query->bindParam(':username', $username, PDO::PARAM_STR);

    $query->bindParam(':email', $email, PDO::PARAM_STR);

    $query->bindParam(':mobile', $mobile, PDO::PARAM_STR);

    $query->bindParam(':eid', $eid, PDO::PARAM_STR);

    $query->execute();

    flash_alert('updated successfuly');

    header("Location: profile_teacher.php?tab_id=$tabSessionID"); exit;

  }

?>



  <?php @include("includes/head.php"); ?>



  <body class="hold-transition sidebar-mini layout-fixed">

    <div class="wrapper">

      <!-- Navbar -->

      <?php @include("includes/headert.php"); ?>

      <!-- /.navbar -->

      <!-- Side bar and Menu -->

      <?php @include("includes/sidebart.php"); ?>

      <!-- /.sidebar and menu -->



      <!-- Content Wrapper. Contains page content -->

      <div class="content-wrapper">

             <section class="content-header premium-header">

    <div class="container-fluid">

        <div class="header-glass-card">

            <div class="row align-items-center">

                <div class="col-md-8">

                    <div class="title-section">

                        <div class="icon-box bg-primary-gradient shadow-sm">

                            <i class="fas fa-user-tie"></i>

                        </div>

                        <div>

                            <h1 class="premium-title text-primary">

                            Teacher Information Management

                                <span class="premium-subtitle text-secondary">Manage Profile</span>

                            </h1>
                            <div class="mt-1">
                              <?php if ($currentSessionName): ?>
                                <span class="badge badge-primary mr-1">
                                  <i class="fas fa-calendar-alt"></i>
                                  <?= htmlspecialchars($currentSessionName) ?>
                                </span>
                              <?php endif; ?>
                              <?php if ($currentTermName): ?>
                                <span class="badge badge-success">
                                  <i class="fas fa-bookmark"></i>
                                  <?= htmlspecialchars($currentTermName) ?>
                                </span>
                              <?php else: ?>
                                <span class="badge badge-warning">
                                  <i class="fas fa-exclamation-triangle"></i> No active term
                                </span>
                              <?php endif; ?>
                            </div>

                        </div>

                    </div>

                </div>

                <div class="col-md-4">

                    <nav aria-label="breadcrumb">

                        <ol class="breadcrumb premium-breadcrumb">

                            <li class="breadcrumb-item"><a href="teacher_dashboard.php" class="text-primary">Home</a></li>

                            <li class="breadcrumb-item active" aria-current="page">Upadte Profile</li>

                        </ol>

                    </nav>

                </div>

            </div>

        </div>

    </div>

</section> 

        <div class="col-lg-12">

          <div class="card card-primary mb-4">

            <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">

              <h5 class="m-0 font-weight-bold"> <i class="fas fa-user-edit"></i> Update Profile</h5>

            </div>

            <div class="card-body">

              <form method="post">

                <?php

                $eid = $_SESSION['sid'];

                $sql = "SELECT * from tblusers   where id=:eid ";

                $query = $dbh->prepare($sql);

                $query->bindParam(':eid', $eid, PDO::PARAM_STR);

                $query->execute();

                $results = $query->fetchAll(PDO::FETCH_OBJ);



                $cnt = 1;

                if ($query->rowCount() > 0) {

                  foreach ($results as $row) {

                ?>

                    <div class="container rounded bg-white mt-5">

                      <div class="row">

                        <div class="col-md-4 border-right">

                          <div class="d-flex flex-column align-items-center text-center p-3 py-5">

                            <?php

                            if ($row->userimage == "avatar15.jpg") { ?>

                              <img class="rounded-circle mt-5" src="staff_images/avatar15.jpg" width="90">

                            <?php

                            } else { ?>

                              <img class="rounded-circle mt-5" src="staff_images/<?php echo $row->userimage; ?>" width="90">

                            <?php

                            } ?><span class="font-weight-bold"><?php echo $row->name; ?> <?php echo $row->lastname; ?></span><span class="text-black-50"><?php echo $row->email; ?></span><span><?php echo $row->mobilenumber; ?></span>

                            <div class="mt-3">

                              <a href="update_userimage_t.php?id=<?php echo $eid; ?>">Edit Image</a>

                            </div>

                          </div>

                        </div>

                        <div class="col-md-8">

                          <div class="p-3 py-5">

                            <div class="d-flex justify-content-between align-items-center mb-3">

                              <div class="d-flex flex-row align-items-center back"><i class="fa fa-long-arrow-left mr-1 mb-1"></i>

                              </div>

                              <h6 class="text-right">Edit Profile</h6>

                            </div>

                            <div class="row mt-2">

                              <div class="form-group col-md-6"><input type="text" class="form-control" name="firstname" value="<?php echo $row->name; ?>" required='true'></div>

                              <div class="form-group col-md-6"><input type="text" class="form-control" value="<?php echo $row->lastname; ?> " name="lastname" required></div>

                            </div>

                            <div class="row mt-3">

                              <div class="form-group col-md-6"><input type="text" class="form-control" name="email" value="<?php echo $row->email; ?>" required></div>

                              <div class="form-group col-md-6"><input type="text" class="form-control" value="<?php echo $row->mobile; ?>" name="mobile" required></div>

                            </div>

                            <div class="row mt-3">

                              <div class="col-md-6">

                                <label class="form-group">User Name</label>

                                <input type="text" class="form-control" name="username" value="<?php echo $row->username; ?>" required>

                              </div>

                              <div class="col-md-6">

                                <label class="form-group">Permission</label>

                                <input type="text" class="form-control" name="permission" value="<?php echo $row->permission; ?>" readonly="true">

                              </div>

                            </div>



                            <div class="mt-5 text-center"><button class="btn btn-primary profile-button" type="submit" name="submit"><i class="fas fa-sync"></i> Update Profile</button></div>

                          </div>

                        </div>

                      </div>

                    </div>

                <?php

                  }

                } ?>

              </form>

            </div>

          </div>

        </div>



        <!-- /.content-header -->

      </div>

      <!-- /.content-wrapper -->

      <?php @include("includes/foot.php"); ?>

      <?php @include("includes/footer.php"); ?>

  </body>



  </html>

<?php

} ?>