<?php
/**
 * Created by PhpStorm.
 * User: IOAN
 * Date: 9/29/2015
 * Time: 9:18 AM
 */

$member_id = isset($_SESSION['member_id']) ? intval($_SESSION['member_id']) : 0;

if($member_id > 0) {

    $breadcrumbs [] = array(
        'link' => 'account/my_account.html',
        'title' => 'My Account'
    );


    $breadcrumbs [] = array(
        'link'  => '',
        'title' => "Jobs/Resume Dashboard"
    );

    // Get the number of jobs
    $jobs = array(
        "total" => 0,
        "new" => 0,
        "active" => 0,
        "inactive" => 0,
        "expired" => 0
    );

    // Jobs configs
    $NeedActivation = 'yes';
    $DaysToLive = 180;
    $Expiration = 'yes';
    $q = "SELECT * FROM job_config";
    $r = @mysql_query($q);
    if($r && mysql_num_rows($r) > 0) {
        $row = mysql_fetch_assoc($r);

        $NeedActivation = $row["NeedActivation"];
        $DaysToLive = $row["DaysToLive"];
        $Expiration = $row["Expiration"];
    }

    $q = "SELECT * FROM job_jobs WHERE member_id='$member_id';";
    $r = @mysql_query($q);
    if($r && mysql_num_rows($r) > 0) {
        $current_time = time();
        while($row = mysql_fetch_assoc($r)) {
            $jobs['total'] += 1;
            if($row['active'] == "new") {
                $jobs['new'] += 1;
            }
            elseif($row['active'] == "yes") {
                $jobs['active'] += 1;
            }
            elseif($row['active'] == "no") {

                $jobs['inactive'] += 1;
            }
        }

        if(strtotime($row['added_on'] . ' ' . $row['added_on_time']) + $DaysToLive * 3600 * 24 < $current_time ) {
            $jobs['expired'] += 1;
        }
    }

    ?>
    <div class="box">
        <div class="box-header with-border">
            <b>Posted Jobs</b>
        </div>
        <div class="box-body">
            <div class="list-group no-margin">
                <div class="list-group-item list-group-item-info">
                    <span class="badge"><?=$jobs['total'];?></span>
                    <b>Total jobs</b>
                </div>
                <div class="list-group-item list-group-item-warning">
                    <span class="badge"><?=$jobs['new'];?></span>
                    <b>Pending approval</b>
                </div>
                <div class="list-group-item list-group-item-success">
                    <span class="badge"><?=$jobs['active'];?></span>
                    <b>Approved</b>
                </div>
                <div class="list-group-item list-group-item-danger">
                    <span class="badge"><?=$jobs['inactive'];?></span>
                    <b>Rejected</b>
                </div>
                <div class="list-group-item list-group-item-danger">
                    <span class="badge"><?=$jobs['expired'];?></span>
                    <b>Expired</b>
                </div>
            </div>
        </div>
        <div class="box-footer text-left">
            <a href="account/jobs/job.html" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> Add New Job</a>
            <a href="account/jobs/my-jobs.html" class="btn btn-info btn-sm"><i class="fa fa-list"></i> View Jobs</a>
        </div>
    </div>
    <?php


    // Get the resume details
    $resume = array(
        "exists" => 0,
        "active" => 0,
        "expired" => 0,
        "clicks" => 0
    );

    // Resume configs
    $NeedActivation = 'yes';
    $DaysToLive = 180;
    $Expiration = 'yes';
    $q = "SELECT * FROM job_config";
    $r = @mysql_query($q);
    if($r && mysql_num_rows($r) > 0) {
        $row = mysql_fetch_assoc($r);

        $NeedActivation = $row["NeedActivationCV"];
        $DaysToLive = $row["DaysToLiveCV"];
        $Expiration = $row["ExpirationCV"];
    }

    $q = "SELECT * FROM job_cvs WHERE member_id='$member_id';";
    $r = @mysql_query($q);
    if($r && mysql_num_rows($r) == 1) {
        $current_time = time();
        $row = mysql_fetch_assoc($r);

        $resume['exists'] = 1;

        if($row['active'] == "yes") {
            $resume['active'] = 1;
        }

        $resume['clicks'] = intval($row['clicks']);


        if(strtotime($row['added_on'] . ' ' . $row['added_on_time']) + $DaysToLive * 3600 * 24 < $current_time ) {
            $resume['expired'] = 1;
        }
    }

    ?>
    <div class="box">
        <div class="box-header with-border">
            <b>Your Resume</b>
        </div>
        <div class="box-body">
            <?php
            if($resume['exists'] == 1) {
                if($resume['active'] == 1) {
                    ?>
                    <div class="alert alert-success no-margin">
                        <p><i class="fa fa-info-circle fa-lg"></i> Your resume is approved.</p>
                    </div>
                    <?php
                }
                else {
                    ?>
                    <div class="alert alert-warning no-margin">
                        <p><i class="fa fa-hourglass-half fa-lg"></i> Your resume is pending approval.</p>
                    </div>
                    <?php
                }

                if($resume['expired'] == 1) {
                    ?>
                    <div class="alert alert-danger no-margin">
                        <p><i class="fa fa-info-circle fa-lg"></i> Your resume is expired.</p>
                    </div>
                    <?php
                }
                ?>

                <?php
            }
            else {
                ?>
                <div class="alert alert-danger no-margin">
                    <p class="text-white"><i class="fa fa-info-circle fa-lg"></i> You have not posted your resume yet.</p>
                </div>
                <?php
            }
            ?>
        </div>
        <div class="box-footer text-left">
            <?php
            $resume_action = '<i class="fa fa-plus"></i> Create Your Resume';
            if($resume['exists'] == 1) {
                $resume_action = '<i class="fa fa-pencil"></i> Edit Your Resume';
            }
            ?>
            <a href="account/resume/my-resume.html" class="btn btn-primary btn-sm"><?=$resume_action;?></a>
        </div>
    </div>
    <?php

}