<?php
/**
 * Created by PhpStorm.
 * User: IOAN
 * Date: 10/6/2015
 * Time: 1:19 PM
 */
$optres['js'][] = $path . "assets/js/moment.min.js";

$optres['css'][] = $path . "assets/css/bootstrap-dialog.min.css";
$optres['js'][] = $path . "assets/js/bootstrap-dialog.min.js";

$optres['css'][] = $path . "assets/css/bootstrap-datetimepicker.min.css";
$optres['js'][] = $path . "assets/js/bootstrap-datetimepicker.min.js";


$optres['js'][] = $path . "assets/plugins/tinymce/js/tinymce/tinymce.min.js";
$optres['css'][] = $module_css_path . "amodules/jobsresumes/css/my_resume.css";
$optres['js'][] = $path . "amodules/jobsresumes/js/my_resume.js";

$new_date = time();

$cv = array(
    "job_cv_id" => 0,
    "job_cat_id" => "",
    "catdom_id" => $domain_id,
    "JobLocation" => "",
    "FirstName" => "",
    "LastName" => "",
    "Genre" => "m",
    "Age" => "",
    "dob"   => null,
    "CountryOfOrigin" => "CYPRUS",
    "MaritalStatus" => "Single",
    "Children" => "",
    "ResCountry" => "CYPRUS",
    "ResTown" => "",
    "ResAddress" => "",
    "ResPhone" => "",
    "Mobile" => "",
    "Email" => "",
    "Qualifications" => "",
    "ProfessionalExperience" => "",
    "Education" => "",
    "Interests" => "",
    "SpecialSkills" => "",
    "Languages" => "",
    "Training" => "",
    "Affiliations" => "",
    "ReferencesOther" => "",

    "added_on" => date("Y-m-d"),
    "added_on_time" => date("H:i:s"),
    "created_at" => date("Y-m-d H:i:s", $new_date),
    "updated" => 0,
    "updated_at" => date("Y-m-d H:i:s", $new_date),

    "member_id" => $_SESSION['member_id'],

    "active" => "new",
    "resume_status" => "1",
    "clicks" => 0,
    "jversion" => 1
);

$html_fields = array(
    "Qualifications" => "",
    "ProfessionalExperience" => "",
    "Education" => "",
    "Interests" => "",
    "SpecialSkills" => "",
    "Languages" => "",
    "Training" => "",
    "Affiliations" => "",
    "ReferencesOther" => ""
);

$member_id = intval($_SESSION['member_id']);

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



    $tmp = array_map('stripslashes', $row);
    if(intval($tmp['jversion']) == 0) {
        foreach ($tmp as $fld => $val) {
            if (in_array($fld, $html_fields)) {
                $tmp[$fld] = nl2br($val);
            }
        }
    }
    $cv = array_merge($cv, $tmp);

    if(isset($_REQUEST['rdebug'])) {
        echo '<pre>$row = ', var_export($row, true), '</pre>';
        echo '<pre>$tmp = ', var_export($tmp, true), '</pre>';
    }

    unset($tmp);
}


if(isset($_REQUEST['rdebug'])) {
    echo $q;
    echo '<pre>', var_export($_SESSION, true), '</pre>';
    echo '<pre>', var_export($cv, true), '</pre>';
}

$job_cv_id = intval($cv['job_cv_id']);


if($job_cv_id == 0) {
    ?>
    <div class="alert alert-danger">
        <p class="text-white"><i class="fa fa-info-circle fa-lg"></i> You have not yet filled in your resume details. </p>
    </div>
    <?php
}

if(isset($_SESSION['flashm']) && trim($_SESSION['flashm']) != "") {
    ?>
    <div class="alert alert-info">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
        <p><i class="fa fa-info-circle"></i> <?=$_SESSION['flashm'];?></p>
    </div>
    <?php
    unset($_SESSION['flashm']);
}
?>
<?php
// Breadcrumbs
$breadcrumbs [] = array(
    'link' => 'account/my_account.html',
    'title' => 'My Account'
);


$breadcrumbs [] = array(
    'link'  => '',
    'title' => $job_cv_id > 0 ? "Edit My Resume" : "Create Resume"
);

    if($job_cv_id > 0) {

        switch ($cv['active']) {
            case "yes":
                $status = 'Approved';
                $status_tip = 'Approved Listing';
                $status_class = 'fa fa-lg fa-check text-success';
                $text_class = "text-success";
                break;
            case "new":
                $status = 'Pending';
                $status_tip = 'Pending approval by Administrator';
                $status_class = 'fa fa-lg fa-hourglass-half text-warning';
                $text_class = "text-warning";
                break;
            case "no":
                $status = 'Rejected';
                $status_tip = 'Rejected by Administrator';
                $status_class = 'fa fa-lg fa-ban text-danger';
                $text_class = "text-danger";
                break;

        }

        if (intval($cv['updated']) == 1) {
            $status = 'Pending';
            $status_tip = 'Pending approval by Administrator';
            $status_class = 'fa fa-lg fa-hourglass-half text-warning';
            $text_class = "text-warning";
        }


        $resume_status = intval($cv['resume_status']);
        $resume_status_status = $resume_status == 1 ? "Active" : "Inactive";
        $resume_status_text = $resume_status == 1 ? "Inactivate" : "Activate";
        $resume_status_label = $resume_status == 1 ? "label-success" : "label-danger";
        $resume_status_text = 'Your Resume is <span class="resume-stat label ' . $resume_status_label . '">' . $resume_status_status . '</span>. <span class="status-action hidden">Click to <a href="#" class="resume-status btn btn-xs btn-default" data-resume_status="' . $resume_status . '" data-rid="' . $job_cv_id . '">' . $resume_status_text . '</a></span>';

        ?>
        <div class="box box-primary box-solid">
            <fieldset class="box-body form-horizontal">
                <legend>Approval Status</legend>
                <div class="alert">
                    <p><span class="text-bold <?= $text_class; ?>" data-toggle="tooltip" title="<?= $status_tip; ?>"
                             data-placement="bottom" data-container="body"><i
                                class="<?= $status_class; ?>"></i> <?= $status_tip; ?></span></p>
                </div>

                <legend>Activation Status</legend>

                <div class="alert resume-footer">
                    <p><?= $resume_status_text; ?></p>
                </div>

            </fieldset>
        </div>
        <?php

    }

?>

<form action="account/resume/my-resume.html" method="post" enctype="multipart/form-data" id="resume-form" class="form-horizontal" role="form">
    <div class="box box-default box-solid">
        <div class="box-header with-border">
            <?php echo '<b>'. ($job_cv_id > 0 ? 'Edit' : 'Create')  . ' My Resume</b>'; ?>
        </div>
        <fieldset class="box-body">

            <?php
            if($job_cv_id == 0) {
                ?>
                <legend>Info</legend>
                <div class="alert alert-info">
                    <p><i class="fa fa-info-circle"></i> <b>Attention!</b> Your Resume Listing will not be displayed until the Administrator of the site will approve and activate it.</p>
                </div>
                <?php
            }
            ?>

            <legend>Looking For A Job In</legend>
            <div class="form-group">
                <label class="control-label col-sm-3">Job Category <span class="req">*</span> </label>
                <div class="col-sm-7">
                    <?php
                    $queryjob_cat = "SELECT * FROM  job_cat WHERE active='yes' ORDER BY order_seq ASC";
                    $resultjob_cat = mysql_query($queryjob_cat);
                    $NumberOfFieldsjob_cat=mysql_num_rows($resultjob_cat);
                    if ($NumberOfFieldsjob_cat > 0) {
                        ?>
                        <select name="job_cat_id" class="form-control input-sm mw300" id="job_cat_id">
                            <option value="" selected>CHOOSE CATEGORY</option>
                            <?php
                            while ($linejob_cat = mysql_fetch_assoc($resultjob_cat)) {
                                $selected = '';
                                if ($linejob_cat["job_cat_id"]==$cv["job_cat_id"]) {
                                    $selected = 'selected="selected"';
                                }
                                ?>
                                <option value="<?php echo $linejob_cat["job_cat_id"];?>" <?=$selected;?>><?php echo $linejob_cat["title_en"];?></option>
                                <?php
                            }
                            ?>
                        </select>
                    <?php
                    }
                    else {
                        ?>
                        <p class="form-control-static">No Categories exist yet</p>
                        <?php
                    }
                    ?>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-sm-3">Job Location <span class="req">*</span></label>
                <div class="col-sm-7">
                    <div class="checkbox">
                        <?php
                        $querydistricts = "SELECT * FROM districts WHERE active='yes' ORDER BY order_seq ASC";
                        $resultdistricts = mysql_query($querydistricts);
                        if (mysql_num_rows($resultdistricts) <> 0) {
                            while ($linedistricts = mysql_fetch_assoc($resultdistricts)) {
                                $checked = '';
                                if (strstr($cv["JobLocation"], $linedistricts["title_en"])) {
                                    $checked = 'checked="checked"';
                                }
                                ?>
                                <label class="checkbox">
                                    <input type="checkbox" name="JobLocation[]" value="<?php echo $linedistricts["title_en"]; ?>" <?=$checked?>><?php echo $linedistricts["title_en"];?>
                                </label>
                                <?php
                            }
                            ?>
                            <?php
                        }
                        else {
                            ?>
                            <p class="form-control-static">No districts added yet.</p>
                            <?php
                        }
                        ?>
                    </div>
                </div>
            </div>

            <legend>Personal Details</legend>

            <div class="form-group">
                <label class="control-label col-sm-3">First Name <span class="req">*</span> </label>
                <div class="col-sm-7">
                    <input name="FirstName" type="text" id="FirstName" value="<?php echo $cv["FirstName"];?>" maxlength="80" required="required" class="form-control input-sm mw300">
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-sm-3">Last Name <span class="req">*</span> </label>
                <div class="col-sm-7">
                    <input name="LastName" type="text" class="form-control input-sm mw300" id="LastName" value="<?php echo $cv["LastName"];?>" required="required" maxlength="80">
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-sm-3">Gender <span class="req">*</span> </label>
                <div class="col-sm-7">
                    <div class="radio">
                        <label class="radio">
                            <input name="Genre" type="radio" value="m" <?php echo ($cv["Genre"]=="m") ? 'checked="checked"' : '';?>> Male
                        </label>
                        <label class="radio">
                            <input name="Genre" type="radio" value="f" <?php echo ($cv["Genre"]=="f") ? 'checked="checked"' : '';?>> Female
                        </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">Date Of Birth <span class="req">*</span></label>
                <div class="col-sm-7">
                    <div class="input-group date col-sm-5 mw300" id="dob-picker">
                        <input name="dob" type="text" readonly class="form-control input-sm" id="dob" value="<?=$cv["dob"];?>" required="required">
                        <span class="input-group-addon">
                            <i class="fa fa-calendar"></i>
                        </span>
                    </div>

                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">Country of origin <span class="req">*</span></label>
                <div class="col-sm-7">
                    <?php
                    $querycountries = "SELECT * FROM countries ORDER BY name ASC;";
                    $resultcountries = mysql_query($querycountries);
                    if (mysql_num_rows($resultcountries) <> 0) {
                        ?>
                        <select class="form-control input-sm mw300" name="CountryOfOrigin" id="CountryOfOrigin" required="required">
                            <option value="" selected="selected">Select</option>
                            <?php
                            while ($linecountries = mysql_fetch_assoc($resultcountries)) {
                                $selected = '';
                                if($linecountries['name'] == $cv['CountryOfOrigin']) $selected = 'selected="selected"';
                                ?>
                                <option value="<?php echo $linecountries["name"];?>" <?=$selected?>><?php echo $linecountries["name"];?></option>
                                <?php
                            }
                            ?>
                        </select>
                        <?php
                    } else {
                        ?>
                        <p class="form-control-static">No Countries added yet.</p>
                        <?php
                    }
                    ?>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">Marital status</label>
                <div class="col-sm-7">
                    <div class="radio">
                        <label class="radio"><input name="MaritalStatus" type="radio" value="Single" <?php echo ($cv["MaritalStatus"]=="Single") ? 'checked="checked"': '';?>> Single</label>
                        <label class="radio"><input name="MaritalStatus" type="radio" value="Married" <?php echo ($cv["MaritalStatus"]=="Married") ? 'checked="checked"': '';?>> Married</label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">Children</label>
                <div class="col-sm-7">
                    <input name="Children" type="number" class="form-control input-sm mw100" id="ResTown3" value="<?php echo $cv["Children"];?>" maxlength="2">
                </div>
            </div>

            <legend>Residence:</legend>

            <div class="form-group">
                <label class="control-label col-sm-3">Country <span class="req">*</span></label>
                <div class="col-sm-7">
                    <?php
                    $querycountries = "SELECT * FROM  countries ORDER BY name ASC;";
                    $resultcountries = @mysql_query($querycountries);
                    if (mysql_num_rows($resultcountries) > 0) {
                        ?>
                        <select class="form-control input-sm mw300" name="ResCountry" id="ResCountry" required="required">
                            <option value="" selected="selected">Select</option>
                            <?php
                            while ($linecountries = mysql_fetch_assoc($resultcountries)) {
                                $selected = '';
                                if($linecountries['name'] == $cv['ResCountry']) $selected = 'selected="selected"';
                                ?>
                                <option value="<?php echo $linecountries["name"];?>" <?=$selected;?>><?php echo $linecountries["name"];?></option>
                                <?php
                            }
                            ?>
                        </select>
                        <?php
                    }
                    else {
                        ?>
                        <p class="form-control-static">No Countries added yet.</p>
                        <?php
                    }
                    ?>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">Town <span class="req">*</span></label>
                <div class="col-sm-7">
                    <input name="ResTown" type="text" class="form-control input-sm mw300" id="ResTown" value="<?php echo $cv["ResTown"];?>" required="required">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">Address <span class="req">*</span></label>
                <div class="col-sm-7">
                    <textarea name="ResAddress" cols="30" rows="2"  style="width: 100%;"  wrap="soft" class="form-control input-sm" id="ResAddress" required="required"><?php echo $cv["ResAddress"];?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">Phone</label>
                <div class="col-sm-7">
                    <input name="ResPhone" type="text" class="form-control input-sm mw300" id="ResPhone" value="<?php echo $cv["ResPhone"];?>" maxlength="25">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">Mobile</label>
                <div class="col-sm-7">
                    <input name="Mobile" type="text" class="form-control input-sm mw300" id="Mobile" value="<?php echo $cv["Mobile"];?>" maxlength="25">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">E-mail <span class="req">*</span></label>
                <div class="col-sm-7">
                    <input name="Email" type="email" class="form-control input-sm mw300" id="Email" value="<?php echo $cv["Email"];?>" required="required" maxlength="100">
                </div>
            </div>

            <legend>Resume Details</legend>
            <div class="form-group">
                <label class="control-label col-sm-10">Qualifications</label>
                <div class="col-sm-10">
                    <textarea name="Qualifications" rows="3"  style="width: 100%;resize: vertical;"  wrap="soft" data-access="readonly" class="wysihtml5 form-control input-sm" id="Qualifications"><?php echo $cv["Qualifications"];?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-10">Professional experience</label>
                <div class="col-sm-10">
                    <textarea name="ProfessionalExperience" cols="50" rows="3"  style="width: 100%;"  wrap="soft" data-access="readonly" class="wysihtml5 form-control input-sm" id="ProfessionalExperience"><?php echo $cv["ProfessionalExperience"];?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-10">Education</label>
                <div class="col-sm-10">
                    <textarea name="Education" cols="50" rows="3"  style="width: 100%;"  wrap="soft" data-access="readonly" class="wysihtml5 form-control input-sm" id="Education"><?php echo $cv["Education"];?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-10">Interests</label>
                <div class="col-sm-10">
                    <textarea name="Interests" cols="50" rows="3"  style="width: 100%;"  wrap="soft" data-access="readonly" class="wysihtml5 form-control input-sm" id="Interests"><?php echo $cv["Interests"];?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-10">Special skills</label>
                <div class="col-sm-10">
                    <textarea name="SpecialSkills" cols="50" rows="3"  style="width: 100%;"  wrap="soft" data-access="readonly" class="wysihtml5 form-control input-sm" id="SpecialSkills"><?php echo $cv["SpecialSkills"];?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-10">Languages</label>
                <div class="col-sm-10">
                    <textarea name="Languages" cols="50" rows="3"  style="width: 100%;"  wrap="soft" data-access="readonly" class="wysihtml5 form-control input-sm" id="Languages"><?php echo $cv["Languages"];?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-10">Training</label>
                <div class="col-sm-10">
                    <textarea name="Training" cols="50" rows="3"  style="width: 100%;"  wrap="soft" data-access="readonly" class="wysihtml5 form-control input-sm" id="Training"><?php echo $cv["Training"];?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-10">Affiliations</label>
                <div class="col-sm-10">
                    <textarea name="Affiliations" cols="50" rows="3"  style="width: 100%;"  wrap="soft" data-access="readonly" class="wysihtml5 form-control input-sm" id="Affiliations"><?php echo $cv["Affiliations"];?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-10">References</label>
                <div class="col-sm-10">
                    <textarea name="ReferencesOther" cols="50" rows="3"  style="width: 100%;"  wrap="soft" data-access="readonly" class="wysihtml5 form-control input-sm" id="ReferencesOther"><?php echo $cv["ReferencesOther"];?></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-3">Operation</label>
                <div class="col-sm-7">
                    <input type="hidden" name="jobs_step" value="jobs_add_cv">
                    <input name="module_page" type="hidden" id="module_page" value="my_jobs">
                    <input name="job_cv_id" type="hidden" id="job_cv_id" value="<?php echo $job_cv_id;?>">
                    <?php
                    if ($job_cv_id>0) {
                        ?>
                            <div class="radio">
                                <label class="radio"><input type="radio" name="chcAction" id="radio-edit" value="Edit" checked> Edit</label>
                                <label class="radio"><input type="radio" name="chcAction" id="radio-delete" value="Delete"> Delete</label>
                            </div>

                        <?php
                    }
                    else {
                        ?>
                        <p class="form-control-static">Create my resume</p>
                        <input type="hidden" name="chcAction" id="chcAction" value="Add">
                        <?php
                    }
                    ?>                                
                </div>
            </div>
        </fieldset>
        <div class="box-footer text-center">
            <button type="submit" name="Submit" id="form-submit" class="btn btn-success btn-sm">Save</button>
        </div>
    </div>
    <input type="hidden" name="jversion" value="1"/>
    <input type="hidden" name="module_page" value="jobsresumes"/>
</form>
