<?php 

/***************************************************************************
 *   copyright            : (C) 2019 PCRepairTracker.com
 *   email                : info@pcrepairtracker.com
 *   This program is a copyrighted work.
 *   Please see the license.txt file for details
 *
 ***************************************************************************/

require("validate2.php");

?>
  <script type="text/javascript">
    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox({
        loadingImage : 'jq/loading.gif',
        closeImage : 'jq/closelabel.png'
      })
    })
  </script>


<?php


require("deps.php");
require_once("common.php");

$startpagetimewo = microtime(true);

if (isset($_REQUEST['pcwo'])) {
$pcwo = $_REQUEST['pcwo'];
} else {
$pcwo = "";
}

if (isset($_REQUEST['scrollto'])) {
$scrollto = $_REQUEST['scrollto'];
} else {
$scrollto = "top";
}

if ($gomodal == 1) {
$therel = "rel=facebox";
} else {
$therel = "";
}

$rs_findpc = "SELECT * FROM pc_wo WHERE woid = '$pcwo'";
$rs_result = mysqli_query($rs_connect, $rs_findpc);

while($rs_result_q = mysqli_fetch_object($rs_result)) {
$pcid = "$rs_result_q->pcid";
$probdesc = "$rs_result_q->probdesc";
$dropoff = "$rs_result_q->dropdate";
$pickup = "$rs_result_q->pickupdate";
$pcstatus = "$rs_result_q->pcstatus";
$called = "$rs_result_q->called";
$custassetsindb2 = "$rs_result_q->custassets";
$pcwa = "$rs_result_q->workarea";
$pcpriorityindb = "$rs_result_q->pcpriority";
$cibyuser = "$rs_result_q->cibyuser";
$theprobsindb2 = "$rs_result_q->commonproblems";
$wostoreid = "$rs_result_q->storeid";
$assigneduser = "$rs_result_q->assigneduser";
$skeddate = "$rs_result_q->skeddate";
$sked = "$rs_result_q->sked";
$slid = "$rs_result_q->slid";
$wochecks = "$rs_result_q->wochecks";
$servicepromiseid = "$rs_result_q->servicepromiseid";
$promisedtime = "$rs_result_q->promisedtime";


$storeinfoarray = getstoreinfo($wostoreid);

if ($custassetsindb2 != "") {
$custassetsindb3 = unserialize($custassetsindb2);
} else {
$custassetsindb3 = array();
}

if(is_array($custassetsindb3)) {
$custassetsindb = $custassetsindb3;
} else {
$custassetsindb = array();
}

if ($theprobsindb2 != "") {
$theprobsindb3 = unserialize($theprobsindb2);
} else {
$theprobsindb3 = array();
}

if (is_array($theprobsindb3)) {
$theprobsindb = $theprobsindb3;
} else {
$theprobsindb = array();
}


$rs_findowner = "SELECT * FROM pc_owner WHERE pcid = '$pcid'";
$rs_result2 = mysqli_query($rs_connect, $rs_findowner);
while($rs_result_q2 = mysqli_fetch_object($rs_result2)) {
$pcname = "$rs_result_q2->pcname";
$pccompany = "$rs_result_q2->pccompany";
$pcphone = "$rs_result_q2->pcphone";
$pcmake = "$rs_result_q2->pcmake";
$pcemail = "$rs_result_q2->pcemail";
$pcaddress = "$rs_result_q2->pcaddress";
$pccellphone = "$rs_result_q2->pccellphone";
$pcworkphone = "$rs_result_q2->pcworkphone";
$pcaddress2 = "$rs_result_q2->pcaddress2";
$pccity = "$rs_result_q2->pccity";
$pcstate = "$rs_result_q2->pcstate";
$pczip = "$rs_result_q2->pczip";
$pcextra = "$rs_result_q2->pcextra";
$pcgroupid = "$rs_result_q2->pcgroupid";
$custsourceid = "$rs_result_q2->custsourceid";
$prefcontact = "$rs_result_q2->prefcontact";
$pcnotes = nl2br($rs_result_q2->pcnotes);
$mainassettypeidindb = "$rs_result_q2->mainassettypeid";
$scid = "$rs_result_q2->scid";
$scpriceid = "$rs_result_q2->scpriceid";
$pcownertags = "$rs_result_q2->tags";

$custompcinfoindb = serializedarraytest($pcextra);


$pcname2 = urlencode($pcname);
$pccompany2 = urlencode($pccompany);
$pcaddress12 = urlencode($pcaddress);
$pcaddress22 = urlencode($pcaddress2);
$pccity2 = urlencode($pccity);
$pcstate2 = urlencode($pcstate);
$pczip2 = urlencode($pczip);
$pcemail2 = urlencode($pcemail);
$pcmake2 = urlencode($pcmake);
$pchomephone2 = urlencode($pcphone);
$pccellphone2 = urlencode($pccellphone);
$pcworkphone2 = urlencode($pcworkphone);



if($prefcontact == "home") {
$pcphone2 = urlencode($pcphone);
} else if ($prefcontact == "mobile") {
$pcphone2 = urlencode($pccellphone);
} else if ($prefcontact == "work") {
$pcphone2 = urlencode($pcworkphone);
} else {
if($pcphone != "") {
$pcphone2 = urlencode($pcphone);
} else if ($pccellphone != "") {
$pcphone2 = urlencode($pccellphone);
} else {
$pcphone2 = urlencode($pcworkphone);
}
}

$rs_qce = "SELECT actionid FROM userlog WHERE reftype = 'woid' AND refid = '$pcwo'";
$rs_resultce1 = mysqli_query($rs_connect, $rs_qce);
$actionids = array();
while($rs_result_qce1 = mysqli_fetch_object($rs_resultce1)) {
$actionids[] = "$rs_result_qce1->actionid";
}


if($pcgroupid != "0") {
$rs_findgname = "SELECT * FROM pc_group WHERE pcgroupid = '$pcgroupid'";
$rs_findgname2 = @mysqli_query($rs_connect, $rs_findgname);
$rs_findgname3 = mysqli_fetch_object($rs_findgname2);
$pcgroupname = "$rs_findgname3->pcgroupname";
$grpcompany = "$rs_findgname3->grpcompany";
$grpphone = "$rs_findgname3->grpphone";
$grpcellphone = "$rs_findgname3->grpcellphone";
$grpworkphone = "$rs_findgname3->grpworkphone";
$grpaddress = "$rs_findgname3->grpaddress1";
$grpaddress2 = "$rs_findgname3->grpaddress2";
$grpcity = "$rs_findgname3->grpcity";
$grpstate = "$rs_findgname3->grpstate";
$grpzip = "$rs_findgname3->grpzip";
$grpemail = "$rs_findgname3->grpemail";
$grpnotes = nl2br("$rs_findgname3->grpnotes");

$ue_pcgroupname = urlencode($pcgroupname);
$ue_grpcompany = urlencode($grpcompany);
$ue_grpphone = urlencode($grpphone);
$ue_grpcellphone = urlencode($grpcellphone);
$ue_grpworkphone = urlencode($grpworkphone );
$ue_grpaddress = urlencode($grpaddress); 
$ue_grpaddress2 = urlencode($grpaddress2);
$ue_grpcity = urlencode($grpcity); 
$ue_grpstate = urlencode($grpstate); 
$ue_grpzip = urlencode($grpzip); 
$ue_grpemail = urlencode($grpemail); 

$boxfill = "<table style=\"width:100%;\"><tr>";

$boxfill .= "<td style=\"text-align:left;margin:0px;padding:0px\">";
$boxfill .= "";
######
$boxfill .= "<table border=0 cellspacing=0 cellpadding=2><tr><td style=\"background:#222222;\" class=radiusall><i class=\"fa fa-phone fa-lg fa-fw\" style=\"color:#ffffff;\"></i></td><td>";
if($grpphone != "") {
$boxfill .= "&nbsp;<i class=\"fa fa-home fa-lg fa-fw\"></i> <strong>$grpphone</strong><br>";
}
if($grpcellphone != "") {
$boxfill .= "&nbsp;<i class=\"fa fa-mobile fa-lg fa-fw\"></i> <strong>$grpcellphone</strong><br>";
}
if($grpworkphone != "") {
$boxfill .= "&nbsp;<i class=\"fa fa-briefcase fa-lg fa-fw\"></i> <strong>$grpworkphone</strong>";
}
$boxfill .= "</td></tr></table><br>";
if($grpaddress != "") {
$grpaddressbr = nl2br($grpaddress);
$boxfill .= "<table cellpadding=2 cellspacing=0 border=0><tr><td style=\"background:#222222;\" class=radiusall><i class=\"fa fa-map-marker fa-lg fa-fw\" style=\"color:#ffffff;\"></i></td><td><strong>$grpaddressbr</strong><br>";
if($grpaddress2 != "") {
$boxfill .= "<strong>$grpaddress2</strong><br>";
}
if(($grpcity != "") && ($grpstate != "") && ($grpzip != "")) {
$boxfill .= "<strong>$grpcity, $grpstate $grpzip</strong>";
}
$boxfill .= "</td></tr></table>";
}
if($grpemail != "") {
$boxfill .= pcrtlang("Email").": $grpemail<br>";
}
if($grpnotes != "") {
$boxfill .= "<br><strong>".pcrtlang("Notes").":</strong><br>$grpnotes<br><br>";
}


$boxfill .= "<br><a href=\"group.php?func=viewgroup&pcgroupid=$pcgroupid\" class=\"groupbarlink radiusall\" style=\"text-align:center\"><i class=\"fa fa-group fa-lg\"></i> ".pcrtlang("View Group")."</a>";

######

$boxfill .= "</td></tr></table>";
}

if("$pccompany" == "") {
$titlefill = "<span class=\"colormewhite sizemelarger textoutline\">$pcname &bull; $pcmake</span><span class=\"colormewhite sizemelarger textoutline\" style=\"float:right;\"><i class=\"fa fa-tag fa-lg\"></i> $pcid</span>";
} else {
$titlefill = "<span class=\"colormewhite sizemelarger textoutline\">$pcname &bull; $pccompany &bull; $pcmake</span><span  class=\"colormewhite sizemelarger textoutline\"  style=\"float:right;\"><i class=\"fa fa-tag fa-lg\"></i> $pcid</span>";
}


$boxstyles = getboxstyle("$pcstatus");

echo "<div id=toparea></div>";

start_color_boxnobottomround("$pcstatus","$titlefill");


$rs_find_items = "SELECT * FROM repaircart WHERE pcwo = '$pcwo' ORDER BY addtime ASC";
$rs_find_result = mysqli_query($rs_connect, $rs_find_items);
$rs_chargewhatcount = mysqli_num_rows($rs_find_result);

echo "<div class=\"nvbar\" style=\"margin:-10px\">";

echo "<div class=\"nvdropdown\">";
echo "<button class=\"nvdropbtn\"><i class=\"fa fa-user fa-lg\"></i> ".pcrtlang("Owner/Device");
echo " <i class=\"fa fa-caret-down\"></i>";
echo "</button>";
echo "<div class=\"nvdropdown-content\">";

echo "<a href=pc.php?func=editowner&pcid=$pcid&woid=$pcwo $therel><img src=images/customeredit.png class=menuicon> ".pcrtlang("Edit Owner/Device Info")."</a>";
if ($ipofpc == "admin") {
echo "<a href=admin.php?func=admindeletepc&pcid=$pcid onClick=\"return confirm('".pcrtlang("Are you sure you wish to permanently delete this Customer/Device and all associated Work Orders!!!?")."');\"><img src=images/trash.png class=menuicon> ".pcrtlang("Delete this Customer/Device")." </a>";
}
if ($pcgroupid != "0") {
echo "<a href=group.php?func=removefromgroup&pcid=$pcid&woid=$pcwo onClick=\"return confirm('".pcrtlang("Are you sure you wish to remove this PC/Customer from this Group?")."');\"><img src=images/groupremove.png class=menuicon> ".pcrtlang("Remove From Group")."</a>";
echo "<a href=group.php?func=viewgroup&pcgroupid=$pcgroupid><img src=images/groups.png class=menuicon> ".pcrtlang("View Group")."</a>";
} else {
echo "<a href=group.php?func=addtogroup&pcid=$pcid&woid=$pcwo&pcname=$pcname2><img src=images/groupadd.png class=menuicon> ".pcrtlang("Add to Group")."</a>";
echo "<a href=group.php?func=addtogroupnew&pcid=$pcid&woid=$pcwo&groupname=$pcname2&grpcompany=$pccompany2&pccompany=$pccompany2&pcaddress1=$pcaddress12&pcaddress2=$pcaddress22&pccity=$pccity2&pcstate=$pcstate2&pczip=$pczip2&pcemail=$pcemail2&pchomephone=$pchomephone2&pccellphone=$pccellphone2&pcworkphone=$pcworkphone2><img src=images/groupadd.png class=menuicon> ".pcrtlang("Add to New Group")."</a>";
}
echo "<a href=attachment.php?func=add&pcid=$pcid&attachtowhat=pcid&pcwo=$pcwo $therel><img src=images/attachment.png class=menuicon> ".pcrtlang("Add Attachment to Device")."</a>";
echo "<a href=servicereminder.php?func=addsr&pcid=$pcid&pcwo=$pcwo $therel><img src=images/reminder.png class=menuicon> ".pcrtlang("Add Service Reminder")."</a>";
echo "<a href=rwo.php?func=addrwo&pcid=$pcid&woid=$pcwo $therel><img src=images/return.png class=menuicon $therel> ".pcrtlang("Add Recurring Work Order")."</a>";
echo "</div>";
echo "</div>";


echo "<div class=\"nvdropdown\">";
echo "<button class=\"nvdropbtn\"><i class=\"fa fa-clipboard fa-lg\"></i> ".pcrtlang("Work Order")." ";
echo "<i class=\"fa fa-caret-down\"></i>";
echo "</button>";
echo "<div class=\"nvdropdown-content\">";
echo "<a href=\"pc.php?func=editproblem&woid=$pcwo&custname=$pcname2\" $therel><img src=images/woedit.png class=menuicon> ".pcrtlang("Edit Work Order")."</a>";
echo "<a href=\"pc.php?func=movewo&woid=$pcwo&pcid=$pcid&custname=$pcname\"><img src=images/womove.png class=menuicon> ".pcrtlang("Move Work Order")."</a>";
if ($ipofpc == "admin") {
echo "<a href=admin.php?func=admindeletewo&pcwoid=$pcwo onClick=\"return confirm('".pcrtlang("Are you sure you wish to permanently delete this Work Order!!!?")."');\"><img src=images/trash.png class=menuicon> ".pcrtlang("Delete this Work Order")."</a>";
}
echo "<a href=pc.php?func=showpc&pcid=$pcid><img src=images/wohistory.png class=menuicon> ".pcrtlang("View Work Order History")."</a>";
echo "<a href=pc.php?func=workorderaction&woid=$pcwo><img src=images/woaction.png class=menuicon> ".pcrtlang("View Work Order Action Log")."</a>";
echo "<a href=attachment.php?func=add&woid=$pcwo&attachtowhat=woid&pcwo=$pcwo $therel><img src=images/attachment.png class=menuicon> ".pcrtlang("Add Attachment to Work Order")."</a>";
echo "<a href=\"sticky.php?func=addsticky&stickyname=$pcname2&stickycompany=$pccompany2&stickyaddy1=$pcaddress12&stickyaddy2=$pcaddress22&stickycity=$pccity2&stickystate=$pcstate2&stickyzip=$pczip2&stickyemail=$pcemail2&stickyphone=$pcphone2&stickyrefid=$pcwo&stickyreftype=woid&stickynote=$probdesc\" $therel><img src=images/sticky.png class=menuicon> ".pcrtlang("Create a Sticky Note")."</a>";

echo "<form action=pc.php?func=checkout method=post>
<input type=hidden name=woid value=$pcwo>";
if($rs_chargewhatcount == "0") {
echo "<a href=pc.php?func=checkout&woid=$pcwo><img src=images/logout.png class=menuicon> ".pcrtlang("Close Work Order")."</a>";
} else {
echo "<a href=pc.php?func=checkout&woid=$pcwo onClick=\"return confirm('".pcrtlang("This Work Order has charges or invoices specified. Are you sure you want to checkout WITHOUT FINALIZING A SALE?")."');\"><img src=images/logout.png class=menuicon> ".pcrtlang("Close Work Order")."</a>";
}
echo "</form>";

echo "</div>";
echo "</div>";


echo "<div class=\"nvdropdown\">";
echo "<button class=\"nvdropbtn\"><i class=\"fa fa-print fa-lg\"></i> ".pcrtlang("Print")." ";
echo "<i class=\"fa fa-caret-down\"></i>";
echo "</button>";
echo "<div class=\"nvdropdown-content\">";
echo "<a href=\"pc.php?func=printclaimticket&woid=$pcwo\"><i class=\"fa fa-ticket fa-lg fa-fw\"></i> ".pcrtlang("Claim Ticket")."</a>";
echo "<a href=\"pc.php?func=printthankyou&woid=$pcwo&pcname=$pcname2\"><i class=\"fa fa-star fa-lg fa-fw\"></i> ".pcrtlang("Thank You Letter")."</a>";
$probdesc_ss = addslashes($probdesc);
echo "<a href=\"pc.php?func=printit&woid=$pcwo\" onClick=\"return confirm('".pcrtlang("Did you repair the following").":\\n $probdesc_ss \\n \\n ".pcrtlang("REMOVE ANY CDS OR FLASH DRIVES FROM THE DEVICE! DO IT NOW!!! DO NOT WAIT!!!!!!")."');\"><i class=\"fa fa-file fa-lg fa-fw\"></i> ".pcrtlang("Repair Report")."</a>";
echo "<a href=\"printpricecard.php?func=printpricecard&woid=$pcwo\"><i class=\"fa fa-money fa-lg fa-fw\"></i> ".pcrtlang("Price Tent")."</a>";
echo "<a href=\"pc.php?func=printcheckoutreceipt&woid=$pcwo\"><i class=\"fa fa-sign-out fa-lg fa-fw\"></i> ".pcrtlang("Checkout Receipt")."</a>";
echo "<a href=\"pc.php?func=benchsheet&woid=$pcwo\"><i class=\"fa fa-plug fa-lg fa-fw\"></i> ".pcrtlang("Bench Sheet")."</a>";
echo "<li><i class=\"fa fa-tags fa-lg\"></i> ".pcrtlang("Labels")."</li>";
$backurl = urlencode("index.php?pcwo=$pcwo");
echo "<a href=\"repairlabel.php?pcid=$pcid&name=$pcname2&company=$pccompany2&woid=$pcwo&pcmake=$pcmake2&pcphone=$pcphone2&dymojsapi=html&backurl=$backurl\"><i class=\"fa fa-tag fa-lg fa-fw\"></i> ".pcrtlang("Asset Label")."</a>";
echo "<a href=\"addresslabel.php?pcname=$pcname2&pccompany=$pccompany2&pcaddress1=$pcaddress12&pcaddress2=$pcaddress2&pccity=$pccity2&pcstate=$pcstate2&pczip=$pczip2&dymojsapi=html&backurl=$backurl\"><i class=\"fa fa-envelope fa-lg fa-fw\"></i> ".pcrtlang("Address Label")."</a>";

echo "</div>";
echo "</div>";


echo "<div class=\"nvdropdown\">";
echo "<button class=\"nvdropbtn\"><i class=\"fa fa-envelope fa-lg\"></i> ".pcrtlang("Email")." ";
echo "<i class=\"fa fa-caret-down\"></i>";
echo "</button>";
echo "<div class=\"nvdropdown-content\">";
echo "<a href=\"pc.php?func=emailclaimticket&woid=$pcwo&email=$pcemail2\" $therel><i class=\"fa fa-ticket fa-lg fa-fw\"></i> ";
echo pcrtlang("Claim Ticket");
if (in_array(12, $actionids)) {
echo "<span class=colormegreen> <i class=\"fa fa-check-circle fa-lg\"></i></span>";
}
echo "</a>";
echo "<a href=\"pc.php?func=emailthankyou&woid=$pcwo&email=$pcemail2&pcname=$pcname2\"><i class=\"fa fa-star fa-lg fa-fw\"></i> ";
echo pcrtlang("Thank You Letter");
if (in_array(25, $actionids)) {
echo "<span class=colormegreen> <i class=\"fa fa-check-circle fa-lg\"></i></span>";
}
echo "</a>";
echo "<a href=\"pc.php?func=emailit&woid=$pcwo&email=$pcemail2\" $therel onClick=\"return confirm('".pcrtlang("Did you repair the following:")." $probdesc.  ".pcrtlang("CHECK THE OPTICAL DRIVE FOR BENCH CDS! DO IT NOW!!! DO NOT WAIT!!!!!!")."');\"><i class=\"fa fa-file fa-lg fa-fw\"></i> ";
echo pcrtlang("Repair Report");
if (in_array(6, $actionids)) {
echo "<span class=colormegreen> <i class=\"fa fa-check-circle fa-lg\"></i></span>";
}
echo "</a>";
echo "</div>";
echo "</div>";


$rs_findstatii = "SELECT * FROM boxstyles WHERE selectablestatus = '1' ORDER BY displayedorder ASC";
$rs_result_st = mysqli_query($rs_connect, $rs_findstatii);
while($rs_result_stq = mysqli_fetch_object($rs_result_st)) {
$thestatii[] = "$rs_result_stq->statusid";
}
$thestaticstatii = $thestatii;
if ($rs_chargewhatcount == 0) {
$thestatiisub = array(4,6,7);
$thestatii = array_diff($thestatii, $thestatiisub);
}

if(count($thestaticstatii) <= 200) {
echo "<div class=\"nvdropdown\">";
$lighter = adjustBrightness("$boxstyles[selectorcolor]", 75);
echo "<button class=\"nvdropbtn\"><i class=\"fa fa-window-maximize fa-lg\"  style=\"color:$lighter;\"></i> ".pcrtlang("Status").": $boxstyles[boxtitle] ";
echo "<i class=\"fa fa-caret-down\"></i>";
echo "</button>";
echo "<div class=\"nvdropdown-content\">";

$countthestatus = 0;
echo "<table style=\"border-collapse:collapse;padding:0;\"><tr><td style=\"vertical-align:top;padding:0px;\">";
reset($thestatii);
foreach($thestatii as $k => $v) {
$rs_gets2 = "SELECT * FROM boxstyles WHERE statusid = '$v'";
$rs_results2 = mysqli_query($rs_connect, $rs_gets2);
$rs_result_qs2 = mysqli_fetch_object($rs_results2);
$selectorcolor2 = "$rs_result_qs2->selectorcolor";
$boxtitle2 = "$rs_result_qs2->boxtitle";
if($pcstatus != $v) {
$countthestatus++;
echo "<a href=\"pc.php?func=stat_change&woid=$pcwo&statnum=$v\"><i class=\"fa fa-window-maximize fa-lg\"  style=\"color:#$selectorcolor2;\"></i> $boxtitle2</a>";
}

if(($countthestatus % 15) == 0) {
echo "</td><td style=\"vertical-align:top;padding:0px;\">";
}

}

echo "</td></tr></table>";
echo "</div>";
echo "</div>";
}


if($pcgroupid != "0") {
echo "<a href=\"group.php?func=viewgroup&pcgroupid=$pcgroupid\" style=\"float:right;\" class=boldme><i class=\"fa fa-group fa-lg\"></i> $pcgroupname</a>";
}


echo "</div><br>";








echo "<table style=\"border-collapse:collapse;margin:0px;padding:0px;width:100%;\"><tr width=100%><td style=\"padding:10px 20px 0px 0px;width:50%;vertical-align:top;\">";


$boxstyles = getboxstyle("$pcstatus");
echo "<table style=\"border-collapse:collapse;margin:0px;padding:0px;\"><tr><td valign=top>";

if (($pcphone != "") || ($pcworkphone != "") || ($pccellphone != "")) {

echo "<table style=\"border-collapse:collapse;margin:0px;padding:0px;width:100%;\"><tr><td bgcolor=#$boxstyles[selectorcolor] style=\"border-radius:3px;\"><i class=\"fa fa-phone fa-lg\" style=\"color:#ffffff;padding:20px 3px;\"></i></td><td>";

echo "<table style=\"border-collapse:collapse;margin:0px;padding:0px;width:100%;\">";

if($pcphone != "") {
echo "<tr><td style=\"text-align:right\">";
if($prefcontact == "home") {
echo "<span style=\"color: #$boxstyles[selectorcolor];\"><i class=\"fa fa-home fa-lg fa-fw\"></i></span>";
} else {
echo "<i class=\"fa fa-home fa-lg fa-fw\"></i>";
}
echo "</td><td><strong>$pcphone</strong></td></tr>";
}

if($pccellphone != "") {
echo "<tr><td style=\"text-align:right\">";
if($prefcontact == "mobile") {
echo "<span style=\"color: #$boxstyles[selectorcolor];\"><i class=\"fa fa-mobile fa-lg fa-fw\"></i></span>";
} else {
echo "<i class=\"fa fa-mobile fa-lg fa-fw\"></i>";
}

echo "</td><td><strong>$pccellphone</strong>";

echo "</td></tr>";
}

if($pcworkphone != "") {
echo "</td><td style=\"text-align:right\">";
if($prefcontact == "work") {
echo "<span style=\"color: #$boxstyles[selectorcolor];\"><i class=\"fa fa-suitcase fa-lg fa-fw\"></i></span>";
} else {
echo "<i class=\"fa fa-suitcase fa-lg fa-fw\"></i>";
}

echo "</td><td><strong>$pcworkphone</strong>";
echo "</td></tr>";
}
echo "</table>";
echo "</td></tr></table>";
}

echo "</td><td>&nbsp;&nbsp;</td><td valign=top>";

if($pcaddress != "") {
$pcaddressbr = nl2br($pcaddress);
echo "<table cellpadding=2 cellspacing=0 border=0><tr><td bgcolor=#$boxstyles[selectorcolor] style=\"border-radius:3px;\"><i class=\"fa fa-map-marker fa-lg\"  style=\"padding:20px 5px; color:#ffffff;\"></i></td><td style=\"padding:5px;\"><strong>$pcaddressbr</strong><br>";
if($pcaddress2 != "") {
echo "<strong>$pcaddress2</strong><br>";
}

$addystring = urlencode("$pcaddress $pccity $pcstate $pczip");
echo "<strong>$pccity, $pcstate $pczip</strong>";
echo "<br><a href=pc.php?func=callmap&woid=$pcwo&pcid=$pcid class=\"linkbuttonsmall linkbuttongray radiusleft\"><i class=\"fa fa-map fa-lg\"></i> ".pcrtlang("map")."</a>";
echo "<a href=pc.php?func=addmiles&woid=$pcwo&addystring=$addystring class=\"linkbuttonsmall linkbuttongray radiusright\"><i class=\"fa fa-car fa-lg\"></i> ".pcrtlang("add mileage")."</a>";
echo "</td></tr></table>";
}

echo "</td></tr></table>";


if($pcemail != "") {
echo "<br>";
if($prefcontact == "email") {
echo "<a href=mailto:$pcemail class=\"linkbuttonsmall linkbuttongray radiusall\"><span style=\"color: #$boxstyles[selectorcolor];\"><i class=\"fa fa-envelope\"></i></span> $pcemail</a>";
} else {
echo "<a href=mailto:$pcemail class=\"linkbuttonsmall linkbuttongray radiusall\"><i class=\"fa fa-envelope\"></i> $pcemail</a>";
}
echo "<br>";
}


if($custsourceid != "0") {
$rs_cssq = "SELECT * FROM custsource WHERE custsourceid='$custsourceid'";
$rs_result1cs = mysqli_query($rs_connect, $rs_cssq);
while($rs_result_qcs1 = mysqli_fetch_object($rs_result1cs)) {
$thesource = "$rs_result_qcs1->thesource";
$sourceicon = "$rs_result_qcs1->sourceicon";
echo "<br><img src=images/custsources/$sourceicon align=absmiddle> ".pcrtlang("Customer Source").": <strong>$thesource</strong><br>";
}
}



echo "<br><table class=standard><tr><th><i class=\"fa fa-comment-o fa-lg fa-fw\"></i> ".pcrtlang("Notes")."</th></tr>";
echo "<tr><td>".parseforlinks($pcnotes)."</td></tr></table><br>";

###################

echo "<br><table class=standard><tr><th><i class=\"fa fa-tags fa-lg fa-fw\"></i> ".pcrtlang("Tags")."</th></tr><tr><td>";


displaytags($pcid,$pcgroupid,32);


echo "<a href=\"javascript:void(0);\" class=\"linkbuttonsmall linkbuttongray radiusall floatright\" id=tagchange>
<i class=\"fa fa-chevron-down\"></i></a>";

echo "<div id=tagselectorbox style=\"display:none;\"><br>";

echo "<form method=post action=\"pc.php?func=tagsave\"><input type=hidden name=woid value=\"$pcwo\"><input type=hidden name=pcid value=\"$pcid\">";

echo "<div class=\"checkbox\">";

$pcownertagsarray = explode_list($pcownertags);

echo "<table><tr><td style=\"vertical-align:top\">";

$rs_sq = "SELECT * FROM custtags WHERE tagenabled = '1' ORDER BY theorder DESC";
$rs_result1 = mysqli_query($rs_connect, $rs_sq);

$totaltags = mysqli_num_rows($rs_result1);
$halftags = ceil($totaltags / 2) + 1;
$tagcounter = 0;

while($rs_result_q1 = mysqli_fetch_object($rs_result1)) {
$tagid = "$rs_result_q1->tagid";
$thetag = "$rs_result_q1->thetag";
$tagicon = "$rs_result_q1->tagicon";
$tagenabled = "$rs_result_q1->tagenabled";
$theorder = "$rs_result_q1->theorder";
$primero = mb_substr("$thetag", 0, 1);
$tagcounter++;

if($tagcounter == $halftags) {
echo "</td><td style=\"vertical-align:top\">";
}

if("$primero" == "-") {
$thetag = mb_substr("$thetag", 1);
echo "<span class=\"linkbuttontiny linkbuttongraylabel radiusall\">$thetag</span><br>";
} else {
$tagcheck = "";
if(in_array($tagid, $pcownertagsarray)) {
$tagcheck = "checked";
}
echo "<input type=checkbox $tagcheck id=\"$tagid\" value=\"$tagid\" name=\"tags[]\">
<label for=\"$tagid\"><img src=images/tags/$tagicon width=16> $thetag</input></label><br>";
}
}

echo "<br><input class=button type=submit value=\"".pcrtlang("Save Tags")."\"></form>";

echo "</td></tr></table>";

echo "</div></div>";

?>
<script type='text/javascript'>
$('#tagchange').click(function(){
  $('#tagselectorbox').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});
</script>
<?php


echo "</td></tr></table><br>";

###############

echo "<table class=standard><tr><th>";

echo "<i class=\"fa fa-key fa-lg fa-fw\"></i> ".pcrtlang("Credentials")."</th>";
echo "<th style=\"text-align:right;\">";

echo "&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0);\" class=\"linkbuttontiny linkbuttongray radiusall\" id=pass1change>
<i class=\"fa fa-lock\"></i></a> ";

echo "&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0);\" class=\"linkbuttontiny linkbuttongray radiusall\" id=pass2change>
<i class=\"fa fa-thumb-tack\"></i></a> ";

echo "&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0);\" class=\"linkbuttontiny linkbuttongray radiusall\" id=pass3change>
<i class=\"fa fa-th\"></i></a>";

echo "&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0);\" class=\"linkbuttontiny linkbuttongray radiusall\" id=pass5change>
<i class=\"fa fa-question-circle\"></i></a>";


echo "</th>";
echo "</tr><tr><td colspan=2>";

echo "<div id=pass1box style=\"display:none;border:2px #cccccc solid;padding:5px;border-radius:3px;\">";
echo "<form action=pc.php?func=newpass method=post><input type=hidden name=woid value=$pcwo><input type=hidden name=pcid value=$pcid><input type=hidden name=credtype value=1><input type=hidden name=returnto value=wo>";

$rs_cd = "SELECT * FROM creddesc ORDER BY creddescorder DESC";
$rs_resultcd1 = mysqli_query($rs_connect, $rs_cd);
$creddescoptions = "<option value=\"\">".pcrtlang("pick one or write your own below")."</option>";
while($rs_result_cdq1 = mysqli_fetch_object($rs_resultcd1)) {
$credtitle = "$rs_result_cdq1->credtitle";
$creddescoptions .= "<option value=\"$credtitle\">$credtitle</option>";
}

echo "<select name=creddesc onchange='document.getElementById(\"creddesc1box\").value=this.options[this.selectedIndex].value '>";
echo "$creddescoptions";
echo "</select><br><br>";
echo "<input type=text class=textbox id=creddesc1box name=creddesc style=\"width:250px\" placeholder=\"".pcrtlang("Description")."\"><br><br>";

echo "<input type=text class=textbox name=username placeholder=\"".pcrtlang("Enter Username")."\"><br><br>";
echo "<input type=text class=textbox name=password placeholder=\"".pcrtlang("Enter Password")."\">";
echo "<button type=submit class=sbutton><i class=\"fa fa-save\"></i></button>";


echo "</form></div>";

echo "<div id=pass2box style=\"display:none;border:2px #cccccc solid;padding:5px;border-radius:3px;\">";
echo "<form action=pc.php?func=newpass method=post><input type=hidden name=woid value=$pcwo><input type=hidden name=pcid value=$pcid><input type=hidden name=credtype value=2><input type=hidden name=returnto value=wo>";
echo "<select name=creddesc onchange='document.getElementById(\"creddesc2box\").value=this.options[this.selectedIndex].value '>";
echo "$creddescoptions";
echo "</select><br><br>";
echo "<input type=text class=textbox id=creddesc2box name=creddesc placeholder=\"".pcrtlang("Description")."\"><br><br>";
echo "<input type=text class=textbox name=password placeholder=\"".pcrtlang("Enter Pin")."\"> ";
echo "<button type=submit class=sbutton><i class=\"fa fa-save\"></i></button>";
echo "</form></div>";


echo "<div id=pass3box style=\"display:none;border:2px #cccccc solid;padding:5px;border-radius:3px;\">";
echo "<div id=patternmain></div>";
echo "<form action=pc.php?func=newpass method=post><input type=hidden name=woid value=$pcwo><input type=hidden name=pcid value=$pcid><input type=hidden name=credtype value=3><input type=hidden name=returnto value=wo>";
echo "<select name=creddesc1 onchange='document.getElementById(\"creddesc3box\").value=this.options[this.selectedIndex].value '>";
echo "$creddescoptions";
echo "</select><br><br>";
echo "<input type=text class=textbox id=creddesc3box name=creddesc style=\"width:250px\" placeholder=\"".pcrtlang("Description")."\">";
echo "<input type=hidden class=textbox name=newpattern id=patterntextbox> ";
echo "<button type=submit class=sbutton><i class=\"fa fa-save\"></i></button>";
echo "</form>";
echo "</div>";


echo "<div id=pass5box style=\"display:none;border:2px #cccccc solid;padding:5px;border-radius:3px;\">";
echo "<form action=pc.php?func=newpass method=post><input type=hidden name=woid value=$pcwo><input type=hidden name=pcid value=$pcid><input type=hidden name=credtype value=5><input type=hidden name=returnto value=wo>";

echo "<select name=creddesc onchange='document.getElementById(\"creddesc5box\").value=this.options[this.selectedIndex].value '>";
echo "$creddescoptions";
echo "</select><br><br>";
echo "<input type=text class=textbox id=creddesc5box name=creddesc style=\"width:350px\" placeholder=\"".pcrtlang("Description")."\"><br><br>";

echo "<input type=text class=textbox name=username style=\"width:350px\" placeholder=\"".pcrtlang("Enter Security Question")."\"><br><br>";
echo "<input type=text class=textbox name=password style=\"width:320px\" placeholder=\"".pcrtlang("Enter Answer")."\">";
echo " <button type=submit class=sbutton> <i class=\"fa fa-save\"></i> </button>";


echo "</form></div>";


?>
<link href="jq/patternLock.css"  rel="stylesheet" type="text/css">
<script src="jq/patternLock.js"></script>
<script type='text/javascript'>
var lock = new PatternLock("#patternmain", {
   onDraw:function(pattern){
	$('#patterntextbox').val(pattern);	
    }
});
</script>



<script type='text/javascript'>
$('#pass1change').click(function(){
  $('#pass1box').toggle('1000');
  $('#pass2box').hide('1000');
  $('#pass3box').hide('1000');
  $('#pass5box').hide('1000');
});

$('#pass2change').click(function(){
  $('#pass2box').toggle('1000');
  $('#pass1box').hide('1000');
  $('#pass3box').hide('1000');
  $('#pass5box').hide('1000');
});

$('#pass3change').click(function(){
  $('#pass3box').toggle('1000');
  $('#pass1box').hide('1000');
  $('#pass2box').hide('1000');
  $('#pass5box').hide('1000');
});

$('#pass5change').click(function(){
  $('#pass5box').toggle('1000');
  $('#pass1box').hide('1000');
  $('#pass2box').hide('1000');
  $('#pass3box').hide('1000');
});


</script>
<?php


require("patterns.php");

if(perm_check("34")) {
if($pcgroupid != 0) {
$credgroupsql = " OR groupid = '$pcgroupid' ";
} else {
$credgroupsql = "";
}
} else {
$credgroupsql = "";
}

$rs_findcreds = "SELECT * FROM creds WHERE pcid = '$pcid' $credgroupsql ORDER BY groupid,creddate DESC";
$rs_result_creds = mysqli_query($rs_connect, $rs_findcreds);
while($rs_result_qcreds = mysqli_fetch_object($rs_result_creds)) {
$credid = "$rs_result_qcreds->credid";
$creddesc = "$rs_result_qcreds->creddesc";
$creduser = "$rs_result_qcreds->creduser";
$credpass = "$rs_result_qcreds->credpass";
$patterndata = "$rs_result_qcreds->patterndata";
$credtype = "$rs_result_qcreds->credtype";
$creddate2 = "$rs_result_qcreds->creddate";
$credgroupid = "$rs_result_qcreds->groupid";

if($credgroupid == 0) {
$badgestyle = "passbadge";
} else {
$badgestyle = "passbadge2";
}


$creddate = pcrtdate("$pcrt_mediumdate", "$creddate2");

if($credtype == 1) {
echo "<table class=\"$badgestyle\"><tr><td><i class=\"fa fa-lock fa-2x\"></i></td>";
echo "<td><strong>$creddesc</strong> &bull; <span class=sizemesmaller>$creddate</span>";
echo "<span class=floatright>";

if (($pcgroupid != 0) && ($credgroupid == 0)) {
echo "<a href=\"pc.php?func=movecred&woid=$pcwo&groupid=$pcgroupid&credid=$credid&moveto=group&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\">
<i class=\"fa fa-group fa-lg\"></i></a>";
} elseif ($pcgroupid != 0) {
echo "<a href=\"pc.php?func=movecred&woid=$pcwo&groupid=$pcgroupid&credid=$credid&moveto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\">
<i class=\"fa fa-clipboard fa-lg\"></i></a>";
}


echo "<a href=\"pc.php?func=editcred&woid=$pcwo&credid=$credid&credtype=$credtype&returnto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusleft\" $therel>
<i class=\"fa fa-edit fa-lg\"></i></a>";
echo "<a href=\"pc.php?func=deletecred&woid=$pcwo&credid=$credid&returnto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\"
onClick=\"return confirm('".pcrtlang("Are you sure you want to delete this credential?")."')\"><i class=\"fa fa-trash fa-lg\"></i></a>";
echo "</span>";

echo "<br><i class=\"fa fa-user\"></i> $creduser
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i class=\"fa fa-key\"></i> $credpass";
echo "</td></tr></table>";
}

if($credtype == 2) {
echo "<table class=\"$badgestyle\"><tr><td><i class=\"fa fa-thumb-tack fa-2x\"></i></td>";
echo "<td><strong>$creddesc</strong> &bull; <span class=sizemesmaller>$creddate</span>";
echo "<span class=floatright>";

if (($pcgroupid != 0) && ($credgroupid == 0)) {
echo "<a href=\"pc.php?func=movecred&woid=$pcwo&groupid=$pcgroupid&credid=$credid&moveto=group&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\">
<i class=\"fa fa-group fa-lg\"></i></a>";
} elseif ($pcgroupid != 0) {
echo "<a href=\"pc.php?func=movecred&woid=$pcwo&groupid=$pcgroupid&credid=$credid&moveto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\">
<i class=\"fa fa-clipboard fa-lg\"></i></a>";
}


echo "<a href=\"pc.php?func=editcred&woid=$pcwo&credid=$credid&credtype=$credtype&returnto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\" $therel>
<i class=\"fa fa-edit fa-lg\"></i></a>";
echo "<a href=\"pc.php?func=deletecred&woid=$pcwo&credid=$credid&returnto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\"
onClick=\"return confirm('".pcrtlang("Are you sure you want to delete this PIN?")."')\"><i class=\"fa fa-trash fa-lg\"></i></a>";
echo "</span>";
echo "<br><i class=\"fa fa-thumb-tack\"></i> $credpass";
echo "</td></tr></table>";
}

if($credtype == 3) {
echo "<table class=\"$badgestyle\"><tr><td><i class=\"fa fa-th fa-2x\"></i></td>";
echo "<td><strong>$creddesc</strong> &bull; <span class=sizemesmaller>$creddate</span>";
echo "<span class=floatright>";

if (($pcgroupid != 0) && ($credgroupid == 0)) {
echo "<a href=\"pc.php?func=movecred&woid=$pcwo&groupid=$pcgroupid&credid=$credid&moveto=group&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\">
<i class=\"fa fa-group fa-lg\"></i></a>";
} elseif ($pcgroupid != 0) {
echo "<a href=\"pc.php?func=movecred&woid=$pcwo&groupid=$pcgroupid&credid=$credid&moveto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\">
<i class=\"fa fa-clipboard fa-lg\"></i></a>";
}


echo "<a href=\"pc.php?func=deletecred&woid=$pcwo&credid=$credid&returnto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\"
onClick=\"return confirm('".pcrtlang("Are you sure you want to delete this pattern?")."')\"><i class=\"fa fa-trash fa-lg\"></i></a></span><br>";
echo draw3x3("$patterndata","small");
echo "</td></tr></table>";
}

if($credtype == 5) {
echo "<table class=\"$badgestyle\"><tr><td><i class=\"fa fa-question-circle fa-2x\"></i></td>";
echo "<td><strong>$creddesc</strong> &bull; <span class=sizemesmaller>$creddate</span>";
echo "<span class=floatright>";

if (($pcgroupid != 0) && ($credgroupid == 0)) {
echo "<a href=\"pc.php?func=movecred&woid=$pcwo&groupid=$pcgroupid&credid=$credid&moveto=group&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\">
<i class=\"fa fa-group fa-lg\"></i></a>";
} elseif ($pcgroupid != 0) {
echo "<a href=\"pc.php?func=movecred&woid=$pcwo&groupid=$pcgroupid&credid=$credid&moveto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\">
<i class=\"fa fa-clipboard fa-lg\"></i></a>";
}

echo "<a href=\"pc.php?func=editcred&woid=$pcwo&credid=$credid&credtype=$credtype&returnto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\" $therel>
<i class=\"fa fa-edit fa-lg\"></i></a>";
echo "<a href=\"pc.php?func=deletecred&woid=$pcwo&credid=$credid&returnto=wo&pcid=$pcid\" class=\"linkbuttonsmall linkbuttongray radiusall\"
onClick=\"return confirm('".pcrtlang("Are you sure you want to delete this security question?")."')\"><i class=\"fa fa-trash fa-lg\"></i></a>";
echo "</span>";

echo "<br><i class=\"fa fa-question\"></i> $creduser<br><i class=\"fa fa-commenting-o\"></i> $credpass";
echo "</td></tr></table>";
}



}


echo "</td></tr></table><br>";




####
$rs_srsql = "SELECT * FROM servicereminders WHERE srpcid = '$pcid' ORDER BY srdate ASC";
$rs_result1srsql = mysqli_query($rs_connect, $rs_srsql);
$total_sr = mysqli_num_rows($rs_result1srsql);

if ($total_sr > 0) {
echo "<table class=standard><tr><th colspan=4>";
echo "<i class=\"fa fa-bell-o fa-lg fa-fw\"></i> ".pcrtlang("Service Reminders")."</th></tr>";
while($rs_result_srsql1 = mysqli_fetch_object($rs_result1srsql)) {
$srid = "$rs_result_srsql1->srid";
$srdate = "$rs_result_srsql1->srdate";
$srsent = "$rs_result_srsql1->srsent";
$srnote = nl2br("$rs_result_srsql1->srnote");
$srcanned = "$rs_result_srsql1->srcanned";

if ($srcanned != "") {
$srcanned2 = unserialize($srcanned);
if(is_array($srcanned2)) {
$srcanned3 = $srcanned2;
} else {
$srcanned3 = array();
}
} else {
$srcanned3 = array();
}

$srcanned4 = "";

foreach($srcanned3 as $srkey => $srval) {
$rs_srsqlc = "SELECT * FROM serviceremindercanned WHERE srid = '$srval'";
$rs_result1srsqlc = mysqli_query($rs_connect, $rs_srsqlc);
while($rs_result_srsql1c = mysqli_fetch_object($rs_result1srsqlc)) {
$srtitle = "$rs_result_srsql1c->srtitle";
$srtext = nl2br("$rs_result_srsql1c->srtext");
$srcanned4 .= "<strong>$srtitle</strong><br>$srtext<br><br>";
}
}


$srboxfill = "<strong>".pcrtlang("Service Reminder Message").":</strong><br><br>$srnote<br><br>";
$srboxfill .= "<strong>".pcrtlang("Service Reminder Standard Messages").":</strong><br><br>$srcanned4";

echo "<tr><td style=\"text-align:right\"><img src=images/reminder.png style=\"height:16px;\"></td><td>";
echo "<span class=\"sizemesmaller boldme\">$srdate</span></td>";
if ($srsent == 0) {
echo "<td style=\"vertical-align:middle;\"><span class=\"sizemesmaller boldme\">".pcrtlang("Status").": </span><span class=\"colormered sizemesmaller\">".pcrtlang("Unsent")."</span></td>";
} elseif($srsent == 1) {
echo "<td style=\"vertical-align:middle;\"><span class=\"sizemesmaller boldme\">".pcrtlang("Status").": </span><span class=\"colormeblue sizemesmaller\">".pcrtlang("Sent")."</span></td>";
} else {
echo "<td style=\"vertical-align:middle;\"><span class=\"sizemesmaller boldme\">".pcrtlang("Status").": </span><span class=\"colormeblue sizemesmaller\">".pcrtlang("Recurring")."</span></td>";
}

echo "<td style=\"vertical-align:middle;text-align:right\">&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"infotext linkbuttonsmall linkbuttongray radiusleft\"><i class=\"fa fa-eye fa-lg\"></i> ".pcrtlang("view")."<span>$srboxfill</span></a>";
echo "<a href=\"servicereminder.php?func=editsr&woid=$pcwo&pcid=$pcid&srid=$srid\" class=\"linkbuttonsmall linkbuttongray\" $therel><i class=\"fa fa-edit fa-lg\"></i> ".pcrtlang("edit")."</a>";
echo "<a href=\"servicereminder.php?func=deletesr&woid=$pcwo&srid=$srid\" class=\"linkbuttonsmall linkbuttongray radiusright\" onClick=\"return confirm('".pcrtlang("Are you sure you want to delete this service reminder")."')\"><i class=\"fa fa-trash fa-lg\"></i> ".pcrtlang("delete")."</a></td></tr>";
}
echo "</table>";
}

#####################

$rs_rwosql = "SELECT * FROM rwo WHERE pcid = '$pcid' ORDER BY rwodate ASC";
$rs_result1rwosql = mysqli_query($rs_connect, $rs_rwosql);
$total_rwo = mysqli_num_rows($rs_result1rwosql);

if ($total_rwo > 0) {
echo "<br><table class=standard><tr><th colspan=4>";
echo "<i class=\"fa fa-retweet fa-lg fa-fw\"></i> ".pcrtlang("Recurring Work Orders")."</th></tr>";
while($rs_result_rwosql1 = mysqli_fetch_object($rs_result1rwosql)) {
$rwoid = "$rs_result_rwosql1->rwoid";
$rwodate = "$rs_result_rwosql1->rwodate";
$rwointerval = "$rs_result_rwosql1->rwointerval";
$rwotask = nl2br("$rs_result_rwosql1->rwotask");
$tasksummary = "$rs_result_rwosql1->tasksummary";

echo "<td>$tasksummary<br><span class=sizemesmaller>".pcrtlang("Next Recurrence").": $rwodate</span></td><td style=\"text-align:right\">";

echo "<a href=\"rwo.php?func=editrwo&woid=$pcwo&pcid=$pcid&rwoid=$rwoid\" class=\"linkbuttonsmall linkbuttongray\" $therel>
<i class=\"fa fa-edit fa-lg\"></i> ".pcrtlang("edit")."</a>";
echo "<a href=\"rwo.php?func=deleterwo&woid=$pcwo&rwoid=$rwoid\" class=\"linkbuttonsmall linkbuttongray radiusright\"
onClick=\"return confirm('".pcrtlang("Are you sure you want to delete this recurring work order")."')\">
<i class=\"fa fa-trash fa-lg\"></i> ".pcrtlang("delete")."</a></td></tr>";

}

echo "</table>";

}

##

function validate_zipfile2($v_filename) {
   return preg_match('/^[a-z0-9_ -\.]+\.(zipfile|zip)$/i', $v_filename) ? '1' : '0';
}


$rs_asql = "SELECT * FROM attachments WHERE pcid = '$pcid' ORDER BY attach_date ASC";
$rs_result1asql = mysqli_query($rs_connect, $rs_asql);
$total_attachments = mysqli_num_rows($rs_result1asql);

if ($total_attachments > 0) {
echo "<br><table class=standard><tr><th colspan=3>";
echo "<i class=\"fa fa-paperclip fa-lg fa-fw\"></i> ".pcrtlang("Asset Attachments")."</th></tr>";
while($rs_result_asql1 = mysqli_fetch_object($rs_result1asql)) {
$attach_id = "$rs_result_asql1->attach_id";
$attach_title = "$rs_result_asql1->attach_title";
$attach_size = "$rs_result_asql1->attach_size";
$attach_filename = "$rs_result_asql1->attach_filename";
$attach_date = "$rs_result_asql1->attach_date";
$fileextpc = strtolower(substr(strrchr($attach_filename, "."), 1));

$fileicon = getfileicon($fileextpc);

if($attach_size == 0) {
$thebytes = "";
} else {
$thebytes = formatBytes($attach_size);
}

if(filter_var($attach_filename, FILTER_VALIDATE_URL)) {
	$fileextpc = 'url';
	$attach_link = $attach_filename.' target=_blank';
} else {
	$attach_link = "attachment.php?func=get&attach_id=$attach_id";
}

echo "<tr><td style=\"vertical-align:top\">";
echo "<a href=$attach_link title=\"$attach_date\" class=\"linkbuttonsmall linkbuttongray radiusall displayblock\">$fileicon $attach_title<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $thebytes</a></td>";
echo "<td>&nbsp;&nbsp;&nbsp;<a href=\"attachment.php?func=editattach&woid=$pcwo&attach_id=$attach_id\" class=\"linkbuttonsmall linkbuttongray radiusleft\" $therel><i class=\"fa fa-edit fa-lg\"></i> ".pcrtlang("edit")."</a>";
echo "<a href=\"attachment.php?func=deleteattach&woid=$pcwo&attach_id=$attach_id&attachfilename=$attach_filename\" onClick=\"return confirm('".pcrtlang("Are you sure you wish to permanently delete this Attachment!!!?")."');\" class=\"linkbuttonsmall linkbuttongray\"><i class=\"fa fa-trash fa-lg\"></i> ".pcrtlang("delete")."</a>";
echo "<a href=\"attachment.php?func=moveattach&woid=$pcwo&attach_id=$attach_id&pcid=$pcid&moveto=wo\" class=\"linkbuttonsmall linkbuttongray radiusright\"><i class=\"fa fa-arrow-right fa-lg\"></i> ".pcrtlang("move to wo")."</a>";

if (validate_zipfile2($attach_filename) == '1') {

$attach_filename_ue = urlencode($attach_filename);

if (preg_match("/d7/i", "$attach_title")) {
echo "<br><br>&nbsp;&nbsp;&nbsp;<span class=\"linkbuttonsmall linkbuttongraylabel radiusleft\">".pcrtlang("d7 import").": </span><a href=\"pc.php?func=editowner&woid=$pcwo&pcid=$pcid&attach_filename=$attach_filename\" class=\"linkbuttonsmall linkbuttongray\" $therel>".pcrtlang("machine specs")."</a>";
echo "<a href=\"pc.php?func=addd7note&woid=$pcwo&pcid=$pcid&attach_filename=$attach_filename_ue\" class=\"linkbuttonsmall linkbuttongray radiusright\">".pcrtlang("notes")."</a>";
}

if (preg_match("/uvk/i", "$attach_title")) {
echo "<div id=wouvklinks></div>";
?>
<script type="text/javascript">
  $.get('uvk.php?func=wouvklinks&woid=<?php echo "$pcwo"; ?>&filename=<?php echo "$attach_filename_ue"; ?>&pcid=<?php echo "$pcid"; ?>', function(data) {
    $('#wouvklinks').html(data);
  });
</script>
<?php
}


}

echo "</td></tr>";
}
echo "</table>";
}



echo "</td>";
echo "<td style=\"padding:10px 0px 0px 20px; width:50%;vertical-align:top;\">";
$probdesc2 = nl2br($probdesc);

echo "<table class=standard><tr><th><i class=\"fa fa-wrench fa-lg fa-fw\"></i> ".pcrtlang("Problem/Task")."</td></th>";

echo "<tr><td>";


echo "$probdesc2<br>";

foreach($theprobsindb as $key => $val) {
echo "<strong>&bull;</strong> $val<br>";
}

echo "</td></tr></table><br>";



$rs_asql2 = "SELECT * FROM attachments WHERE woid = '$pcwo'";
$rs_result1asql2 = mysqli_query($rs_connect, $rs_asql2);
$total_attachments2 = mysqli_num_rows($rs_result1asql2);

if ($total_attachments2 > 0) {
echo "<table class=standard><tr><th colspan=3>";
echo "<i class=\"fa fa-paperclip fa-lg fa-fw\"></i> ".pcrtlang("Work Order Attachments")."</td></th>";
while($rs_result_asql12 = mysqli_fetch_object($rs_result1asql2)) {
$attach_id2 = "$rs_result_asql12->attach_id";
$attach_title2 = "$rs_result_asql12->attach_title";
$attach_size2 = "$rs_result_asql12->attach_size";
$attach_filename2 = "$rs_result_asql12->attach_filename";
$fileextpc2 = strtolower(substr(strrchr($attach_filename2, "."), 1));

if($attach_size2 == 0) {
$thebytes2 = "";
} else {
$thebytes2 = formatBytes($attach_size2);
}

$fileicon2 = getfileicon($fileextpc2);


if(filter_var($attach_filename2, FILTER_VALIDATE_URL)) {
	$fileextpc2 = 'url';
	$attach_link2 = $attach_filename2.' target=_blank';
} else {
	$attach_link2 = "attachment.php?func=get&attach_id=$attach_id2";
}

echo "<tr><td>";
echo "<a href=$attach_link2 class=\"linkbuttonsmall linkbuttongray radiusall displayblock\">$fileicon2 $attach_title2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $thebytes2</a></td>";
echo "<td>&nbsp;&nbsp;&nbsp;<a href=\"attachment.php?func=editattach&woid=$pcwo&attach_id=$attach_id2\" class=\"linkbuttonsmall linkbuttongray radiusleft\" $therel><i class=\"fa fa-edit fa-lg\"></i> ".pcrtlang("edit")."</a>";
echo "<a href=\"attachment.php?func=deleteattach&woid=$pcwo&attach_id=$attach_id2&attachfilename=$attach_filename2\" class=\"linkbuttonsmall linkbuttongray\" onClick=\"return confirm('".pcrtlang("Are you sure you wish to permanently delete this Attachment!!!?")."');\"><i class=\"fa fa-trash fa-lg\"></i> ".pcrtlang("delete")."</a>";
echo "<a href=\"attachment.php?func=moveattach&woid=$pcwo&attach_id=$attach_id2&pcid=$pcid&moveto=asset\" class=\"linkbuttonsmall linkbuttongray radiusright\"><i class=\"fa fa-arrow-left fa-lg\"></i> ".pcrtlang("move to asset")."</a>";
echo "</td></tr>";
}
echo "</table><br>";
}



echo "<table class=standard><tr><th colspan=2><i class=\"fa fa-info fa-lg fa-fw\"></i> ".pcrtlang("Other Work Order Info")."</th></tr>";

$pickdate = pcrtdate("$pcrt_mediumdate", "$pickup")." ".pcrtdate("$pcrt_time", "$pickup");

$dropdate = pcrtdate("$pcrt_mediumdate", "$dropoff")." ".pcrtdate("$pcrt_time", "$dropoff"); 


echo "<tr><td style=\"width:33%;\">".pcrtlang("Work Order ID").":</td><td><strong>$pcwo</strong></td></tr>";

echo "<tr><td style=\"width:33%;\">".pcrtlang("Opened On").": </td><td><strong>$dropdate</strong></td></tr>";

if ($cibyuser != "") {
echo "<tr><td>".pcrtlang("Opened By").": </td><td><strong>$cibyuser</strong></td></tr>";
}

if(($sked == 1) && ($pcstatus != 5)) {
echo "<tr><td><strong>".pcrtlang("Scheduled").":</strong></td><td>";
skedwhen("$skeddate");
echo "</td></tr>";
}



if($servicepromiseid != 0) {
echo "<tr><td><strong>".pcrtlang("Promised").":</strong></td><td style=\"vertical-align:middle;\">";
$promisedtimedisplay = pcrtdate("$pcrt_mediumdate", "$promisedtime")." ".pcrtdate("$pcrt_time", "$promisedtime");
if($pickup == "0000-00-00 00:00:00") {
echo servicepromiseicon("$promisedtime","label")."<br>";
}
echo "$promisedtimedisplay";
echo "</td></tr>";
}


if ($scid != "0") {

$rs_scn = "SELECT * FROM servicecontracts WHERE scid = '$scid'";
$rs_resultscn = mysqli_query($rs_connect, $rs_scn);
$rs_result_scn = mysqli_fetch_object($rs_resultscn);
$scname = "$rs_result_scn->scname";
$chkrinvoice = "$rs_result_scn->rinvoice";

echo "<tr><td>".pcrtlang("Service Contract").": </td><td><a href=\"msp.php?func=viewservicecontract&scid=$scid\" class=\"linkbuttonmedium linkbuttonblack radiusall\">";
echo "<i class=\"fa fa-file-text\"></i> $scname #$scid</a>";


if($scpriceid != 0) {
$rs_ql = "SELECT * FROM scprices WHERE scpriceid = '$scpriceid'";
$rs_result1 = mysqli_query($rs_connect, $rs_ql);
$rs_result_q1 = mysqli_fetch_object($rs_result1);
$scpriceid = "$rs_result_q1->scpriceid";
$labordesc = "$rs_result_q1->labordesc";
echo "<br><br>$labordesc";
}

if($chkrinvoice != 0) {
if(overduerinvoice($chkrinvoice) == 1) {
echo "<br><br><span class=\"colormered\"><i class=\"fa fa-warning faa-flash animated fa-lg\"></i> Service Contract has Overdue Invoices!</span>";
}
}

echo "</td></tr>";
}



if ($assigneduser != "") {
echo "<tr><td>".pcrtlang("Assigned To").": </td><td><strong>$assigneduser</strong>";
echo "&nbsp;&nbsp;&nbsp;<span class=\"linkbuttonsmall linkbuttongraylabel radiusleft\">".pcrtlang("Renotify?")."</span><a href=pc.php?func=worenotify&woid=$pcwo&notifyuseremail=yes class=\"linkbuttonsmall linkbuttongray\">".pcrtlang("email")."</a><a href=pc.php?func=worenotify&woid=$pcwo&notifyusersms=yes class=\"linkbuttonsmall linkbuttongray\">".pcrtlang("sms")."</a><a href=pc.php?func=worenotify&woid=$pcwo&notifyuseremail=yes&notifyusersms=yes class=\"linkbuttonsmall linkbuttongray radiusright\">".pcrtlang("both")."</a>";
echo "</td></tr>";
}

if ($activestorecount > "1") {
echo "<tr><td>".pcrtlang("Store").": </td><td><strong>$storeinfoarray[storesname]</strong></td></tr>";
}


if ($pickup != "0000-00-00 00:00:00") {
echo "<tr><td>".pcrtlang("Closed On").": </td><td><strong>$pickdate</strong>";
if ((time() - strtotime($pickup)) < 1209600) { 
echo " <a href=pc.php?func=reopenwo&woid=$pcwo class=\"linkbuttonsmall linkbuttongray radiusall floatright\" style=\"padding:3px;\"><i class=\"fa fa-undo\"></i> ".pcrtlang("re-open")."</a>";
}
echo "</td></tr>";
}


if (in_array(23, $actionids)) {

$totalcustchecks = count(array_keys($actionids, 23));


$checkcustlooklast = "SELECT thedatetime FROM userlog WHERE actionid = '23' AND refid = '$pcwo' ORDER BY thedatetime DESC LIMIT 1";
$checkcustlookqlast = mysqli_query($rs_connect, $checkcustlooklast);
$custlookfetch = mysqli_fetch_object($checkcustlookqlast);
$lasttime = "$custlookfetch->thedatetime";

$lasttimef = pcrtdate("$pcrt_mediumdate", "$lasttime")." ".pcrtdate("$pcrt_time", "$lasttime");

$thetimes = ($totalcustchecks > 1 ? "times" : "time");

echo "<tr><td><strong>".pcrtlang("Customer Status Check").": </strong></td><td>
<span class=\"colormered boldme\"><i class=\"fa fa-eye fa-lg\"></i> $totalcustchecks $thetimes</span><br>".pcrtlang("Last Check").": $lasttimef</td></tr>";

}



echo "<tr><td>".pcrtlang("Priority").": </td><td>";

if (($pcpriorityindb == "") || (!array_key_exists($pcpriorityindb, $pcpriority))) {
$pcpriorityindb = "Not Set";
}


if ($pcpriorityindb != "Not Set") {
$icon = $pcpriority[$pcpriorityindb];
} else {
$icon = "";
}

if($icon != "") {
echo "<img src=images/$icon class=menuicon>&nbsp;&nbsp;&nbsp;";
} else {
echo "<i class=\"fa fa-hourglass fa-2x vam fa-fw\"></i>&nbsp;&nbsp;&nbsp;";
}
echo pcrtlang("$pcpriorityindb");

echo "&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0);\" class=\"linkbuttonsmall linkbuttongray radiusall floatright\" id=prioritychange>
<i class=\"fa fa-chevron-down\"></i></a>";


echo "<div id=priorityselectorbox style=\"display:none;\"><br>";
foreach($pcpriority as $key => $val) {
if("$pcpriorityindb" != "$key") {
$key2 = urlencode($key);
echo " <a href=pc.php?func=setpriority&woid=$pcwo&setpriority=$key2 class=menulinksm style=\"display:block;\">";
if($val != "") {
echo "<img src=images/$val class=menuicon>";
}
echo " ".pcrtlang("$key")."</a>";
}
}

if ($pcpriorityindb != "Not Set") {
echo "<a href=\"pc.php?func=setpriority&woid=$pcwo&setpriority=\" class=menulinksm style=\"display:block;\"><img src=images/del.png class=menuicon style=\"width:20px;\"> ".pcrtlang("Unset Priority")."</a>";
}
echo "</div>";


?>
<script type='text/javascript'>
$('#prioritychange').click(function(){
  $('#priorityselectorbox').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});
</script>
<?php



echo "</td></tr>";


echo "<tr><td>".pcrtlang("Call/Contact Status for Pickup/Collection").": </td><td>";

if ($called == 1) {
$calledtext = pcrtlang("Not Called");
$calledicon = "<i class=\"fa fa-phone-square fa-2x fa-fw colormered\"></i>";
} elseif ($called == 2){
$calledtext = pcrtlang("Called");
$calledicon = "<i class=\"fa fa-phone-square fa-2x fa-fw colormegreen\"></i>";
} elseif  ($called == 3){
$calledtext = pcrtlang("Called - No Answer");
$calledicon = "<i class=\"fa fa-phone-square fa-2x fa-fw colormeyellow\"></i>";
} elseif  ($called == 7){
$calledtext = pcrtlang("Called - Left Voice Message");
$calledicon = "<i class=\"fa fa-phone-square fa-2x fa-fw colormegreen\"></i>";
} elseif  ($called == 5){
$calledtext = pcrtlang("Sent SMS");
$calledicon = "<i class=\"fa fa-mobile fa-2x fa-fw colormegreen vam\"></i>";
} elseif  ($called == 6){
$calledtext = pcrtlang("Sent Email");
$calledicon = "<i class=\"fa fa-envelope fa-2x fa-fw colormegreen\"></i>";
} else {
$calledtext = pcrtlang("Called - Waiting for Call Back");
$calledicon = "<i class=\"fa fa-phone-square fa-2x fa-fw colormeblue\"></i>";
}


echo "$calledicon <strong>$calledtext</strong>";

echo "&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0);\" class=\"linkbuttonsmall linkbuttongray radiusall floatright\" id=callstatuschange><i class=\"fa fa-chevron-down\"></i></a>";

echo "<div id=callstatusselectorbox style=\"display:none;\"><br>";
echo "<a href=pc.php?func=precalled&woid=$pcwo&status=1 class=menulinksm $therel><i class=\"fa fa-phone-square fa-2x fa-fw colormered vam\"></i> ".pcrtlang("Not Called")."</a>";
echo "<a href=pc.php?func=precalled&woid=$pcwo&status=2 class=menulinksm $therel><i class=\"fa fa-phone-square fa-2x fa-fw colormegreen vam\"></i> ".pcrtlang("Called")."</a>";
echo "<a href=pc.php?func=precalled&woid=$pcwo&status=7 class=menulinksm $therel><i class=\"fa fa-phone-square fa-2x fa-fw colormegreen vam\"></i> ".pcrtlang("Left Voice Message")."</a>";
echo "<a href=pc.php?func=precalled&woid=$pcwo&status=5 class=menulinksm $therel><i class=\"fa fa-mobile fa-2x fa-fw colormegreen vam\"></i> ".pcrtlang("Sent SMS")."</a>";
echo "<a href=pc.php?func=precalled&woid=$pcwo&status=6 class=menulinksm $therel><i class=\"fa fa-envelope fa-2x fa-fw colormegreen vam\"></i> ".pcrtlang("Sent Email")."</a>";
echo "<a href=pc.php?func=precalled&woid=$pcwo&status=3 class=menulinksm $therel><i class=\"fa fa-phone-square fa-2x fa-fw colormeyellow vam\"></i> ".pcrtlang("No Answer")."</a>";
echo "<a href=pc.php?func=precalled&woid=$pcwo&status=4 class=menulinksm $therel><i class=\"fa fa-phone-square fa-2x fa-fw colormeblue vam\"></i> ".pcrtlang("Awaiting Call Back")."</a>";
echo "</div>";

?>
<script type='text/javascript'>
$('#callstatuschange').click(function(){
  $('#callstatusselectorbox').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});
</script>
<?php


echo "</td></tr>";


if($slid != 0) {
$rs_sls = "SELECT * FROM storagelocations WHERE slid = '$slid'";
$rs_result1s = mysqli_query($rs_connect, $rs_sls);
if(mysqli_num_rows($rs_result1s) != 0) {
$rs_result_q1s = mysqli_fetch_object($rs_result1s);
$slnames = "$rs_result_q1s->slname";
} else {
$slnames = pcrtlang("Not Set");
}
} else {
$slnames = pcrtlang("Not Set");
}



echo "<tr><td>".pcrtlang("Storage Location").":</td><td><i class=\"fa fa-archive fa-2x fa-fw vam\"></i>&nbsp;&nbsp;&nbsp;$slnames";
echo "<a href=\"javascript:void(0);\" class=\"linkbuttonsmall linkbuttongray radiusall floatright\" id=storagechange>
<i class=\"fa fa-chevron-down\"></i></a>";

echo "<div id=storageselectorbox style=\"display:none;\"><br>";

$rs_sl = "SELECT * FROM storagelocations ORDER BY theorder DESC";
$rs_result1 = mysqli_query($rs_connect, $rs_sl);
while($rs_result_q1 = mysqli_fetch_object($rs_result1)) {
$slidtoset = "$rs_result_q1->slid";
$slname = "$rs_result_q1->slname";
$theorder = "$rs_result_q1->theorder";
if($slid != $slidtoset) {
echo "<a href=pc.php?func=setsl&woid=$pcwo&slid=$slidtoset  class=\"linkbuttonsmall linkbuttongray radiusall floatright\" style=\"margin:3px;\">$slname</a>";
}
}
if($slid != "0") {
echo "<a href=pc.php?func=setsl&woid=$pcwo&slid=0  class=\"linkbuttonsmall linkbuttonred radiusall floatright\" style=\"margin:3px;\">".pcrtlang("Unset")."</a>";
}

echo "</div>";


?>
<script type='text/javascript'>
$('#storagechange').click(function(){
  $('#storageselectorbox').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});
</script>
<?php

echo "</td></tr>";

#################################################################

$rs_findstatii = "SELECT * FROM boxstyles ORDER BY displayedorder ASC";
$rs_result_st = mysqli_query($rs_connect, $rs_findstatii);
while($rs_result_stq = mysqli_fetch_object($rs_result_st)) {
$statusoptions[$rs_result_stq->statusid] = serializedarraytest("$rs_result_stq->statusoptions");
}

if (is_array($statusoptions[$pcstatus])) {
if (in_array("workbench", $statusoptions[$pcstatus])) {

echo "<tr><td>".pcrtlang("Workarea").":</td><td>";

$storeworkareas = array();

$rs_ql = "SELECT * FROM benches WHERE storeid = '$wostoreid'";
$rs_result1 = mysqli_query($rs_connect, $rs_ql);

if(mysqli_num_rows($rs_result1) != 0) {

while($rs_result_q1 = mysqli_fetch_object($rs_result1)) {
$benchid = "$rs_result_q1->benchid";
$benchname = "$rs_result_q1->benchname";
$benchcolor = "$rs_result_q1->benchcolor";
$storeworkareas[$benchname] = $benchcolor;
}


if ($pcwa != "") {
$wacolor = "$storeworkareas[$pcwa]";
$watitle = "$pcwa";
} else {
$wacolor = "ffffff";
$watitle = pcrtlang("Unassigned");
}

echo "<a href=\"javascript:void(0);\" class=\"statusbarlink radiusall\" id=workareachange style=\"background:#$wacolor;\">$watitle
<i class=\"fa fa-chevron-down fa-lg\"></i></a>";

echo "<div id=workareaselectorbox style=\"display:none;\">";


if ($pcwa != "") {
echo "<a href=\"pc.php?func=changewa&woid=$pcwo&workarea=\" class=\"statusbarlink\" style=\"background:#ffffff\">".pcrtlang("Not Assigned")."</a>";
}
foreach($storeworkareas as $key => $val) {
if ($key == "$pcwa") {
echo "<a href=\"pc.php?func=changewa&woid=$pcwo&workarea=$key\" class=\"statusbarlink\" style=\"background:#$storeworkareas[$key];\">$key</a>";
} else {
echo "<a href=\"pc.php?func=changewa&woid=$pcwo&workarea=$key\" class=\"statusbarlink\" style=\"background:#$storeworkareas[$key];\">$key</a>";
}
}


echo "</div>";


?>
<script type='text/javascript'>
$('#workareachange').click(function(){
  $('#workareaselectorbox').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});
</script>
<?php

}
}
echo "</td></tr>";
}



#######################

echo "</table>";


echo "</td></tr></table><br>";

#################################here maybe...

echo "<div id=statusarea></div>";


if(count($thestaticstatii) > 100) {
echo "<table style=\"width:100%;\"><tr><td style=\"width:45%;vertical-align:top;padding:0px;\">";

reset($thestatii);
echo "<span class=\"linkbuttonmedium linkbuttongraylabel radiusleft\"><i class=\"fa fa-cog fa-lg\"></i> ".pcrtlang("Status").":&nbsp;&nbsp;</span>";

echo "<a href=\"javascript:void(0);\" class=statusbarlink id=statuschange style=\"background:#$boxstyles[selectorcolor];display:inline\">$boxstyles[boxtitle] <i class=\"fa fa-chevron-down fa-lg\"></i></a>";

echo "<div id=statusselectorbox style=\"display:none;\">";

reset($thestatii);
foreach($thestatii as $k => $v) {
$rs_gets2 = "SELECT * FROM boxstyles WHERE statusid = '$v'";
$rs_results2 = mysqli_query($rs_connect, $rs_gets2);
$rs_result_qs2 = mysqli_fetch_object($rs_results2);
$selectorcolor2 = "$rs_result_qs2->selectorcolor";
$boxtitle2 = "$rs_result_qs2->boxtitle";

if($pcstatus == $v) {
echo "<a href=\"pc.php?func=stat_change&woid=$pcwo&statnum=$v\" class=statusbarlink style=\"background:#$selectorcolor2;\">$boxtitle2</a>";
} else {
echo "<a href=\"pc.php?func=stat_change&woid=$pcwo&statnum=$v\" class=statusbarlink style=\"background:#$selectorcolor2;\">$boxtitle2</a>";
}

}


echo "</div>";

?>
<script type='text/javascript'>
$('#statuschange').click(function(){
  $('#statusselectorbox').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});
</script>
<?php

########




echo "</td><td style=\"width:35%;vertical-align:top;padding:0px;\">";

#

$rs_findstatii = "SELECT * FROM boxstyles ORDER BY displayedorder ASC";
$rs_result_st = mysqli_query($rs_connect, $rs_findstatii);
while($rs_result_stq = mysqli_fetch_object($rs_result_st)) {
$statusoptions[$rs_result_stq->statusid] = serializedarraytest("$rs_result_stq->statusoptions");
}

if (is_array($statusoptions[$pcstatus])) {
if (in_array("workbench", $statusoptions[$pcstatus])) {


$storeworkareas = array();

$rs_ql = "SELECT * FROM benches WHERE storeid = '$wostoreid'";
$rs_result1 = mysqli_query($rs_connect, $rs_ql);

if(mysqli_num_rows($rs_result1) != 0) {

while($rs_result_q1 = mysqli_fetch_object($rs_result1)) {
$benchid = "$rs_result_q1->benchid";
$benchname = "$rs_result_q1->benchname";
$benchcolor = "$rs_result_q1->benchcolor";
$storeworkareas[$benchname] = $benchcolor;
}


echo "<span class=\"linkbuttonmedium linkbuttongraylabel radiusleft\"><i class=\"fa fa-plug fa-lg\"></i> ".pcrtlang("Workarea").":&nbsp;&nbsp;</span>";

if ($pcwa != "") {
$wacolor = "$storeworkareas[$pcwa]";
$watitle = "$pcwa";
} else {
$wacolor = "ffffff";
$watitle = pcrtlang("Unassigned");
}

echo "<a href=\"javascript:void(0);\" class=statusbarlink id=workareachange style=\"background:#$wacolor;display:inline-block\">$watitle 
<i class=\"fa fa-chevron-down fa-lg\"></i></a>";

echo "<div id=workareaselectorbox style=\"display:none;\">";


if ($pcwa != "") {
echo "<a href=\"pc.php?func=changewa&woid=$pcwo&workarea=\" class=statusbarlink style=\"background:#ffffff\">".pcrtlang("Not Assigned")."</a>";
} 
foreach($storeworkareas as $key => $val) {
if ($key == "$pcwa") {
echo "<a href=\"pc.php?func=changewa&woid=$pcwo&workarea=$key\" class=statusbarlink style=\"background:#$storeworkareas[$key];\">$key</a>";
} else {
echo "<a href=\"pc.php?func=changewa&woid=$pcwo&workarea=$key\" class=statusbarlink style=\"background:#$storeworkareas[$key];\">$key</a>";
}
}


echo "</div>";


?>
<script type='text/javascript'>
$('#workareachange').click(function(){
  $('#workareaselectorbox').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});
</script>
<?php


}
}
}




echo "</td><td style=\"width:20%;vertical-align:top;padding:0px;text-align:right;\"><form action=pc.php?func=checkout method=post>
<input type=hidden name=woid value=$pcwo>";
if($rs_chargewhatcount == "0") {

echo "<button class=ibutton type=button onclick=\"this.disabled=true; this.form.submit();\">".pcrtlang("Close Work Order")."</button>";
} else {
echo "<button class=ibutton type=button onclick=\"javascript: if(confirm('".pcrtlang("This Work Order has charges or invoices specified. Are you sure you 
want to checkout WITHOUT FINALIZING A SALE?")."')) this.form.submit();\">".pcrtlang("Close Work Order")."</button>";
}
echo "</td></tr></table></form>";


#end old status switcher
}

echo "<div id=assetinfoarea></div>";

stop_color_box();
#######################
$mainassettype = getassettypename($mainassettypeidindb);
$mainassettypeshowscans = getassettypeshowscans($mainassettypeidindb);

start_color_boxnoround("$pcstatus","$mainassettype: $pcmake");



echo "<table style=\"width:100%\"><tr><td style=\"width:50%;vertical-align:top\">";


$rs_allfindassets = "SELECT * FROM mainassetinfofields";
$rs_result2all = mysqli_query($rs_connect, $rs_allfindassets);
while ($rs_result_q2all = mysqli_fetch_object($rs_result2all)) {
$mainassetfieldid = "$rs_result_q2all->mainassetfieldid";
$mainassetfieldname = "$rs_result_q2all->mainassetfieldname";
$allassetinfofields[$mainassetfieldid] = "$mainassetfieldname";
}

$custompcinfoindb = array_filter($custompcinfoindb);

$a = 1;
$countitems = (count($custompcinfoindb) / 2);

foreach($custompcinfoindb as $key => $val) {
if(array_key_exists("$key", $allassetinfofields)) {
echo "<p class=\"assetlist\"><i class=\"fa fa-cogs fa-lg\"></i> <strong>$allassetinfofields[$key] </strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$val</p>";
}

if(($a >= $countitems) && ($a < ($countitems + 1))) {
echo "</td><td style=\"width:50%;vertical-align:top\">";
}

$a++;
}



echo "</td></tr></table><table width=100%><tr><td>";
if (!empty($custassetsindb)) {
echo "<span class=boldme style=\"padding-right:10px\">".pcrtlang("Accessory Assets").":</span> ";

foreach($custassetsindb as $key => $val) {

if (!array_key_exists("$val", $custassets)) {
echo "<img src=images/admin.png align=absmiddle class=assetimage style=\"border: 1px #$boxstyles[selectorcolor] solid;\"><span class=\"linkbuttongraylabel linkbuttonsmall radiusleft\" style=\"background: #$boxstyles[selectorcolor];\"> ".pcrtlang("$val")." </span>&nbsp;&nbsp;&nbsp;";
} else {
echo "<img src=images/assets/$custassets[$val] align=absmiddle class=assetimage style=\"border: 1px #$boxstyles[selectorcolor] solid;\"><span class=\"linkbuttonsmall radiusright linkbuttongraylabel\" style=\"background: #$boxstyles[selectorcolor];\"> ".pcrtlang("$val")." </span>&nbsp;&nbsp;&nbsp;";
}
}
}
echo "</span></td></tr></table>";

$rs_assetphotos = "SELECT * FROM assetphotos WHERE pcid = '$pcid'";
$rs_result_aset = mysqli_query($rs_connect, $rs_assetphotos);

$assetcount = 0;

$totalassetphotos = mysqli_num_rows($rs_result_aset);

if ($totalassetphotos != "0") {

echo "<div class=\"flexassets-container\">";

while($rs_result_aset2 = mysqli_fetch_object($rs_result_aset)) {
$photofilename = "$rs_result_aset2->photofilename";
$assetphotoid = "$rs_result_aset2->assetphotoid";
$highlight = "$rs_result_aset2->highlight";

echo "<div class=\"flexassets-item\">";

if ($highlight == "0") {
$highlightstyle = "";
} else {
$highlightstyle = "style=\"background:yellow\"";
}


echo "<a href=\"pc.php?func=getpcimage&photoid=$assetphotoid\" class=\"assetpreview\"><img src=\"pc.php?func=getpcimage&photoid=$assetphotoid\" $highlightstyle class=\"assetimage\" height=75></a>";

echo "<br><a href=pc.php?func=removephoto&woid=$pcwo&pcid=$pcid&photoid=$assetphotoid&photofilename=$photofilename class=linkbutton onClick=\"return confirm('".pcrtlang("Are you sure you wish to delete this photo?")."')\"><i class=\"fa fa-trash fa-lg\"></i></a>";
if ($highlight == "0") {
echo "<a href=pc.php?func=highlightphoto&woid=$pcwo&pcid=$pcid&photoid=$assetphotoid class=linkbutton><i class=\"fa fa-lightbulb-o fa-lg\"></i></a>";
} else {
echo "<a href=pc.php?func=remhighlightphoto&woid=$pcwo&pcid=$pcid&photoid=$assetphotoid class=linkbutton><i class=\"fa fa-times fa-lg\"></i> <i class=\"fa fa-lightbulb-o fa-lg\"></i></a>";
}

echo "</div>";

}


echo "</div>";
}

echo "<script type=\"text/javascript\" src=\"tooltip2.js\"></script>\n";

echo "<a href=pc.php?func=takepicture&pcid=$pcid&woid=$pcwo class=\"linkbuttonmedium linkbuttonblack radiusleft\"><i class=\"fa fa-camera fa-lg\"></i> ".pcrtlang("Take Asset Photos")."</a><a href=pc.php?func=addassetphoto&pcid=$pcid&woid=$pcwo $therel class=\"linkbuttonblack linkbuttonmedium radiusright\"><i class=\"fa fa-upload fa-lg\"></i> ".pcrtlang("Upload Asset Photos")."</a><a name=items id=items></a>";

stop_color_box();
#######################################################################

$rs_findsinv_t = "SELECT * FROM invoices WHERE woid = '$pcwo' AND invstatus != '3'";
$rs_findsinv2_t = @mysqli_query($rs_connect, $rs_findsinv_t);
$rs_invoicecount = mysqli_num_rows($rs_findsinv2_t);

#$totalpagetimewo = microtime(true) - $startpagetimewo;
#echo "<div style=\"text-align:right\"><span class=text12eng>$totalpagetimewo</span></div>";

$invoicelist = array();
echo "<div id=repaircartarea></div>";
echo "<br>";
start_moneybox();

if (($rs_chargewhatcount != 0) || ($rs_invoicecount != 0)) {

echo "<table style=\"width:100%;box-sizing:border-box;\"><tr><td style=\"width:45%; vertical-align:top; \">";
echo "<span class=\"colormemoney sizemelarge boldme\">&nbsp;".pcrtlang("Repair Cart")."&nbsp;</span><br><br>";

echo "<table class=\"moneylist lastalignright3\">";

echo "<tr><th colspan=4>".pcrtlang("Cart Items")."</th></tr>";
echo "<tr><td class=subhead>".pcrtlang("Description")."</td><td class=subhead>".pcrtlang("Qty")."</td><td class=subhead>".pcrtlang("Unit")."</td><td class=\"subhead\" style=\"text-align:right;\">".pcrtlang("Total")."</td></tr>";

while($rs_find_result_q = mysqli_fetch_object($rs_find_result)) {
$rs_stock_id = "$rs_find_result_q->cart_stock_id";
$cart_item_id = "$rs_find_result_q->cart_item_id";
$rs_cart_price = "$rs_find_result_q->cart_price";
$rs_labor_desc = "$rs_find_result_q->labor_desc";
$rs_labor_pdesc = "$rs_find_result_q->printdesc";
$rs_cart_type = "$rs_find_result_q->cart_type";
$rs_taxex = "$rs_find_result_q->taxex";
$rs_cart_addtime = "$rs_find_result_q->addtime";
$rs_itemserial = "$rs_find_result_q->itemserial";
$price_alt = "$rs_find_result_q->price_alt";
$origprice = mf("$rs_find_result_q->origprice");
$ourprice = "$rs_find_result_q->ourprice";
$unit_price = "$rs_find_result_q->unit_price";
$quantity = "$rs_find_result_q->quantity";
$discountname = "$rs_find_result_q->discountname";


$rs_labor_desc2 = urlencode($rs_labor_desc);
$rs_labor_pdesc2 = urlencode($rs_labor_pdesc);
$rs_cart_unit_price2 = urlencode($unit_price);
$rs_itemserial2 = urlencode($rs_itemserial);

if($ourprice == 0 ) {
$ourprice_ue = 0;
} else {
$ourprice_ue = urlencode($ourprice / $quantity);
}



if ($rs_stock_id == '0') {
echo "<tr><td style=\"width:60%\">";

echo "<a href=\"javascript:void(0);\" class=barlinkmoney style=\"display:inline;border-radius:3px;padding:2px;text-align:center;\" id=cartitemlink$cart_item_id><i class=\"fa fa-chevron-down\"></i></a> ";


echo "<span class=boldme>$rs_labor_desc</span>";

if ($rs_itemserial != "") {
echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"sizemesmaller boldme\">".pcrtlang("Serial/Code").":</span> <span class=sizemesmaller>$rs_itemserial</span>";
}



echo "<div id=cartitem$cart_item_id style=\"display:none;\"><br>";

echo "<a href=repcart.php?func=remove_cart_item&pcwo=$pcwo&cart_item_id=$cart_item_id class=\"linkbuttontiny linkbuttonmoney radiusleft\"><img src=images/del.png class=iconsmall> ".pcrtlang("remove")."</a>";

echo "<a href=repcart.php?func=edit&woid=$pcwo&cart_item_id=$cart_item_id&rs_cart_price=$rs_cart_unit_price2&rs_taxex=$rs_taxex&rs_cart_type=$rs_cart_type&itemdesc=$rs_labor_desc2&itempdesc=$rs_labor_pdesc2&price_alt=$price_alt&serial=$rs_itemserial2&cost=$ourprice_ue&qty=$quantity $therel class=\"linkbuttontiny linkbuttonmoney\"><img src=../store/images/invedit.png class=iconsmall> ".pcrtlang("edit")."</a>";

if ($price_alt != 1) {
echo "<a href=repcart.php?func=add_discount&woid=$pcwo&cart_item_id=$cart_item_id&rs_cart_price=$unit_price&rs_taxex=$rs_taxex&rs_cart_type=$rs_cart_type&itemdesc=$rs_labor_desc2&qty=$quantity $therel class=\"linkbuttontiny linkbuttonmoney radiusright\"><img src=../store/images/discount.png class=iconsmall> ".pcrtlang("add discount")."</a>";
} else {
echo "<a href=\"repcart.php?func=removediscount&cart_item_id=$cart_item_id&woid=$pcwo\" class=\"linkbuttontiny linkbuttonmoney radiusright\"><img src=../store/images/remdiscount.png class=iconsmall> ".pcrtlang("remove discount")."</a><br><span class=\"sizemesmaller colormered\">".pcrtlang("Discount").": $discountname - ".pcrtlang("was")." $money$origprice</span>";
}


###
$rs_find_tax = "SELECT * FROM taxes WHERE taxenabled = '1' ORDER BY taxname ASC";
$rs_result_tax = mysqli_query($rs_connect, $rs_find_tax);
echo "<form method=post action=repcart.php?func=setitemtax><input type=hidden name=cart_item_id value=$cart_item_id><select name=settaxid class=selects  onchange='this.form.submit()'>";

while($rs_result_tq = mysqli_fetch_object($rs_result_tax)) {
$rs_taxname = "$rs_result_tq->taxname";
$rs_taxid = "$rs_result_tq->taxid";

if ($rs_taxid == $rs_taxex) {
echo "<option selected value=$rs_taxid>$rs_taxname</option>";
} else {
echo "<option value=$rs_taxid>$rs_taxname</option>";
}
}
echo "</select><input type=hidden name=cartitemtype value=$rs_cart_type><input type=hidden name=woid value=$pcwo>
<button type=submit class=ibutton style=\"padding:1px 5px;\"><i class=\"fa fa-arrow-circle-left\"></i> ".pcrtlang("Tax")."</button></form>";

echo "</div></td>";


echo "<td>".qf("$quantity")." </td><td> $money".mf("$unit_price")."</td><td>";

echo "<span class=\"boldme nowrap\">";

if ($price_alt == 1) {
echo "<img src=../store/images/discount.png border=0 align=absmiddle width=14> ";
}

echo "$money".mf("$rs_cart_price")."</span>";

?>
<script type='text/javascript'>
$('#cartitemlink<?php echo "$cart_item_id"; ?>').click(function(){
  $('#cartitem<?php echo "$cart_item_id"; ?>').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});
</script>
<?php


echo "</td></tr>";

###



} else {
$rs_find_item_detail = "SELECT * FROM stock WHERE stock_id = '$rs_stock_id'";
$rs_find_result_detail = mysqli_query($rs_connect, $rs_find_item_detail);

echo "<tr><td style=\"width:60%\">";

while($rs_find_result_detail_q = mysqli_fetch_object($rs_find_result_detail)) {
$rs_stocktitle = "$rs_find_result_detail_q->stock_title";

$rs_stocktitle2 = urlencode($rs_stocktitle);


echo "<a href=\"javascript:void(0);\" class=barlinkmoney style=\"display:inline;border-radius:3px;padding:2px;text-align:center;\" id=cartitemlink$cart_item_id><i class=\"fa fa-chevron-down\"></i></a> ";

echo "<span class=boldme>$rs_stocktitle</span>";

if ($rs_itemserial != "") {
echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"sizemesmaller boldme\">".pcrtlang("Serial/Code").":</span> <span class=sizemesmaller>$rs_itemserial</span>";
}

if (($rs_itemserial == "") && ($quantity == 1)) {
if (count(available_serials($rs_stock_id)) > 0) {
echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"sizemesmaller boldme\"><i class=\"fa fa-info-circle faa-flash animated\"></i> ".pcrtlang("Serials Available")."</span>";
echo " <a href=repcart.php?func=addserialafter&pcwo=$pcwo&cart_item_id=$cart_item_id&stockid=$rs_stock_id class=\"linkbuttontiny linkbuttonmoney radiusall\" style=\"padding:2px;\">
<i class=\"fa fa-plus\"></i></a>";
}
}

echo "<div id=cartitem$cart_item_id style=\"display:none;\">";

echo "<a href=repcart.php?func=remove_cart_item&pcwo=$pcwo&cart_item_id=$cart_item_id class=\"linkbuttontiny linkbuttonmoney radiusleft\"><img src=images/del.png class=iconsmall> ".pcrtlang("remove")."</a>";

if($rs_itemserial == "") {
$rs_cart_unit_price_ue = urlencode("$unit_price");
$rs_quantity_ue = urlencode("$quantity");

if($ourprice == 0 ) {
$ourprice_ue = 0;
} else {
$ourprice_ue = urlencode($ourprice / $quantity);
}

echo "<a href=repcart.php?func=editinvitem&cart_item_id=$cart_item_id&rs_cart_price=$rs_cart_unit_price_ue&rs_taxex=$rs_taxex&price_alt=$price_alt&cost=$ourprice_ue&qty=$rs_quantity_ue&woid=$pcwo&stock_id=$rs_stock_id $therel class=\"linkbuttontiny linkbuttonmoney\"><img src=\"../store/images/invedit.png\" class=iconsmall> ".pcrtlang("edit")."</a><br>";
}

if ($price_alt != 1) {
echo "<a href=repcart.php?func=add_discount&woid=$pcwo&cart_item_id=$cart_item_id&rs_cart_price=$unit_price&rs_taxex=$rs_taxex&rs_cart_type=$rs_cart_type&itemdesc=$rs_stocktitle2&qty=$quantity $therel class=\"linkbuttontiny linkbuttonmoney radiusright\"><img src=../store/images/discount.png class=iconsmall> ".pcrtlang("add discount")."</a>";
} else {
echo "<a href=\"repcart.php?func=removediscount&cart_item_id=$cart_item_id&woid=$pcwo\" class=\"linkbuttontiny linkbuttonmoney radiusright\"><img src=../store/images/remdiscount.png border=0 align=absmiddle width=16> ".pcrtlang("remove discount")."</a><br><span class=\"sizemesmaller colormered\">".pcrtlang("Discount").": $discountname</span>";
}


###
$rs_find_tax = "SELECT * FROM taxes WHERE taxenabled = '1' ORDER BY taxname ASC";
$rs_result_tax = mysqli_query($rs_connect, $rs_find_tax);
echo "<form method=post action=repcart.php?func=setitemtax><input type=hidden name=cart_item_id value=$cart_item_id><select name=settaxid class=selects  onchange='this.form.submit()'>";

while($rs_result_tq = mysqli_fetch_object($rs_result_tax)) {
$rs_taxname = "$rs_result_tq->taxname";
$rs_taxid = "$rs_result_tq->taxid";

if ($rs_taxid == $rs_taxex) {
echo "<option selected value=$rs_taxid>$rs_taxname</option>";
} else {
echo "<option value=$rs_taxid>$rs_taxname</option>";
}
}
echo "</select><input type=hidden name=cartitemtype value=$rs_cart_type><input type=hidden name=woid value=$pcwo><button type=submit class=ibutton style=\"padding:1px 5px;\"><i class=\"fa fa-arrow-circle-left\"></i> ".pcrtlang("Tax")."</button></form>";
###

echo "</div>";

$rs_find_stock = "SELECT * FROM stockcounts WHERE storeid = '$defaultuserstore' AND stockid = '$rs_stock_id'";
$rs_result_stock = mysqli_query($rs_connect, $rs_find_stock);
$rs_result_stockq = mysqli_fetch_object($rs_result_stock);
$stockqty = "$rs_result_stockq->quantity";

$rs_cart_addtime_menosuno = $rs_cart_addtime + 86400;
$rs_cart_addtime_ahora = time();


if(($stockqty < 1) && ($rs_cart_addtime_menosuno > $rs_cart_addtime_ahora)) {
echo "<br><span class=\"sizemesmaller colormered\"><i class=\"fa fa-exclamation-triangle fa-lg faa-flash animated\"></i> ".pcrtlang("Inventory has non-sufficient quantity")." ($stockqty)</span><br>
<a href=../store/stock.php?func=show_stock_detail&stockid=$rs_stock_id class=\"linkbuttontiny linkbuttonred radiusall\">".pcrtlang("check qty")."</a>";
}



echo "</td>";
echo "<td>".qf("$quantity")." </td><td> $money".mf("$unit_price")."</td><td>";

echo "<span class=\"boldme floatright\">";
if ($price_alt == 1) {
echo "<img src=../store/images/discount.png border=0 align=absmiddle width=14> ";
}
echo "$money".mf("$rs_cart_price")."</span>";



?>
<script type='text/javascript'>
$('#cartitemlink<?php echo "$cart_item_id"; ?>').click(function(){
  $('#cartitem<?php echo "$cart_item_id"; ?>').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});
</script>
<?php

}

echo "</td></tr>";
}
}

echo "</table>";

$rs_findsinv = "SELECT * FROM invoices WHERE invstatus != '3' AND preinvoice != '1' AND (woid = '$pcwo' OR woid LIKE '%"."\_"."$pcwo"."\_"."%')";
$rs_findsinv2 = @mysqli_query($rs_connect, $rs_findsinv);
$invcount = mysqli_num_rows($rs_findsinv2);


$rs_findtsum = "SELECT (SUM(cart_price) + SUM(itemtax)) as checkcarttsum FROM repaircart WHERE pcwo = '$pcwo'";
$rs_findtsum2 = @mysqli_query($rs_connect, $rs_findtsum);
$rs_findtsum3 = mysqli_fetch_object($rs_findtsum2);
$checkcarttsum2 = "$rs_findtsum3->checkcarttsum";

if(is_numeric($checkcarttsum2)) {
$checkcarttsum = mf($checkcarttsum2, 2, '.', '');

if ($rs_chargewhatcount != 0) {
echo "<div class=\"moneybox\">";
echo "<table style=\"width:100%\"><tr><td>";

echo "<form action=repcart.php?func=loadsavecartout&pcwo=$pcwo method=post>";

if ($pcgroupid == 0) {
echo "<input type=hidden name=cfirstname value=\"$pcname\">";
echo "<input type=hidden name=ccompany value=\"$pccompany\">";
echo "<input type=hidden name=caddress value=\"$pcaddress\">";
echo "<input type=hidden name=caddress2 value=\"$pcaddress2\">";
echo "<input type=hidden name=ccity value=\"$pccity\">";
echo "<input type=hidden name=cstate value=\"$pcstate\">";
echo "<input type=hidden name=czip value=\"$pczip\">";

if ($pcphone != "") {
echo "<input type=hidden name=cphone value=\"$pcphone\">";
} elseif ($pccellphone != "") {
echo "<input type=hidden name=cphone value=\"$pccellphone\">";
} else {
echo "<input type=hidden name=cphone value=\"$pcworkphone\">";
}

echo "<input type=hidden name=cemail value=\"$pcemail\">";

} else {

echo "<input type=hidden name=cfirstname value=\"$pcgroupname\">";
echo "<input type=hidden name=ccompany value=\"$grpcompany\">";

if ($grpaddress == "") {
echo "<input type=hidden name=caddress value=\"$pcaddress\">";
} else {
echo "<input type=hidden name=caddress value=\"$grpaddress\">";
}
if ($grpaddress2 == "") {
echo "<input type=hidden name=caddress2 value=\"$pcaddress2\">";
} else {
echo "<input type=hidden name=caddress2 value=\"$grpaddress2\">";
}
if ($grpcity == "") {
echo "<input type=hidden name=ccity value=\"$pccity\">";
} else {
echo "<input type=hidden name=ccity value=\"$grpcity\">";
}
if ($grpstate == "") {
echo "<input type=hidden name=cstate value=\"$pcstate\">";
} else {
echo "<input type=hidden name=cstate value=\"$grpstate\">";
}
if ($grpzip == "") {
echo "<input type=hidden name=czip value=\"$pczip\">";
} else {
echo "<input type=hidden name=czip value=\"$grpzip\">";
}

if ($grpphone != "") {
echo "<input type=hidden name=cphone value=\"$grpphone\">";
} elseif ($grpcellphone != "") {
echo "<input type=hidden name=cphone value=\"$grpcellphone\">";
} else {
echo "<input type=hidden name=cphone value=\"$grpworkphone\">";
}
echo "<input type=hidden name=cemail value=\"$grpemail\">";
}
echo "<input type=hidden name=cwoid value=\"$pcwo\">";

echo "<input type=hidden name=cpcgroupid value=\"$pcgroupid\">";

if($invcount > "0") {
echo "<button type=button class=button onclick=\"javascript: if(confirm('".pcrtlang("This Work Order has invoices specified. Are you sure your want to continue checking out THE CART, AND NOT THE INVOICE?")."')) this.form.submit();\"><i class=\"fa fa-shopping-cart fa-lg\"></i> ".pcrtlang("CHECKOUT")."</button></form>";
} else {
echo "<button type=button class=button onclick=\"this.disabled=true; this.form.submit();\"><i class=\"fa fa-shopping-cart fa-lg\"></i> ".pcrtlang("CHECKOUT")."</button></form>";
}



echo "</td><th style=\"text-align:right;\">";
echo "<span class=\"sizemelarge boldme colormemoney floatright\">".pcrtlang("Repair Cart Total").": $money$checkcarttsum</span>";
echo "</th></tr></table></div>";
}
}


$rs_find_cart_items = "SELECT * FROM receipts WHERE (woid LIKE '%_$pcwo"."_%' OR woid = '$pcwo') AND (invoice_id = '' OR invoice_id = '0')";
$rs_resultrec = mysqli_query($rs_connect, $rs_find_cart_items);

if(mysqli_num_rows($rs_resultrec) > 0) {

echo "<br><span class=text16bu-ongreen>&nbsp;".pcrtlang("Receipts")."&nbsp;</span><br>";

while($rs_result_q = mysqli_fetch_object($rs_resultrec)) {
$rs_receipt_id = "$rs_result_q->receipt_id";
$rs_pay_type = "$rs_result_q->pay_type";
$rs_name = "$rs_result_q->person_name";
$rs_company = "$rs_result_q->company";
$rs_pay_type = "$rs_result_q->pay_type";
$rs_checkno = "$rs_result_q->check_number";
$rs_gt = "$rs_result_q->grandtotal";
$rs_date = "$rs_result_q->date_sold";

echo " <a href=../store/receipt.php?func=show_receipt&receipt=$rs_receipt_id class=\"linkbuttonmedium linkbuttonmoney radiusall\"><img src=../store/images/receipts.png style=\"width:24px;\" align=absmiddle> ".pcrtlang("Receipt").": #$rs_receipt_id</a><br>";

}
}



echo "</td>";

$rs_findsum = "SELECT SUM(cart_price) as checkcartsum FROM repaircart WHERE pcwo = '$pcwo'";
$rs_findsum2 = @mysqli_query($rs_connect, $rs_findsum);  
$rs_findsum3 = mysqli_fetch_object($rs_findsum2);
$checkcartsum = "$rs_findsum3->checkcartsum";

$rs_findcont = "SELECT * FROM repaircart WHERE pcwo = '$pcwo'";
$rs_findcont2 = @mysqli_query($rs_connect, $rs_findsum);
$checkcartcontents = mysqli_num_rows($rs_findcont2);

echo "<td style=\"width:5%; vertical-align:top;\">";
echo "<td style=\"width:50%; vertical-align:top;\">";

echo "<span class=\"colormemoney sizemelarge boldme\">&nbsp;".pcrtlang("Invoicing")."&nbsp;</span><br>";

if (($invcount < 1) && ($checkcartcontents > 0)) {
if($pcgroupid == 0) {
echo "<br><a href=repinvoice.php?func=createinvoice&woid=$pcwo&pcname=$pcname2&pccompany=$pccompany2&pcphone=$pcphone2&pcemail=$pcemail2&pcaddress=$pcaddress12&pcaddress2=$pcaddress22&pccity=$pccity2&pcstate=$pcstate2&pczip=$pczip2&preinvoice=0 $therel class=linkbutton><img src=images/invoice.png border=0 align=absmiddle> ".pcrtlang("Create Invoice (Final) or Quote")."</a>";
} else {
echo "<br><a href=repinvoice.php?func=createinvoice&woid=$pcwo&pcname=$ue_pcgroupname&pccompany=$ue_grpcompany&pcphone=$ue_grpphone&pcemail=$ue_grpemail&pcaddress=$ue_grpaddress&pcaddress2=$ue_grpaddress2&pccity=$ue_grpcity&pcstate=$ue_grpstate&pczip=$ue_grpzip&preinvoice=0 $therel class=linkbutton><img src=images/invoice.png border=0 align=absmiddle> ".pcrtlang("Create Invoice (Final) or Quote")."</a>";
}
}

$rs_findsinv_2 = "SELECT * FROM invoices WHERE woid = '$pcwo' AND invstatus != '3' AND preinvoice != '0'";
$rs_findsinv2_2 = @mysqli_query($rs_connect, $rs_findsinv_2);
$invcount_2 = mysqli_num_rows($rs_findsinv2_2);
if ($checkcartcontents > 0) {
if($pcgroupid == 0) {
echo "<br><a href=repinvoice.php?func=createinvoice&woid=$pcwo&pcname=$pcname2&pccompany=$pccompany2&pcphone=$pcphone2&pcemail=$pcemail2&pcaddress=$pcaddress12&pcaddress2=$pcaddress22&pccity=$pccity2&pcstate=$pcstate2&pczip=$pczip2&preinvoice=1 $therel class=linkbutton><img src=images/invoice.png border=0 align=absmiddle> ".pcrtlang("Create Invoice (Prepaid)")."</a><br>";
} else {
echo "<br><a href=repinvoice.php?func=createinvoice&woid=$pcwo&pcname=$ue_pcgroupname&pccompany=$ue_grpcompany&pcphone=$ue_grpphone&pcemail=$ue_grpemail&pcaddress=$ue_grpaddress&pcaddress2=$ue_grpaddress2&pccity=$ue_grpcity&pcstate=$ue_grpstate&pczip=$ue_grpzip&preinvoice=1 $therel class=linkbutton><img src=images/invoice.png border=0 align=absmiddle> ".pcrtlang("Create Invoice (Prepaid)")."</a><br>";
}

}


##
if($pcgroupid != 0) {
$otherinvoicearray = array();
$rs_findotherpcs = "SELECT * FROM pc_owner WHERE pcgroupid = '$pcgroupid'";
$rs_findotherpcs_2 = @mysqli_query($rs_connect, $rs_findotherpcs);
while($rs_find_otherpcs_q = mysqli_fetch_object($rs_findotherpcs_2)) {
$otherpcid = "$rs_find_otherpcs_q->pcid";

$rs_findotherwo = "SELECT * FROM pc_wo WHERE pcid = '$otherpcid' AND woid != '$pcwo'";
$rs_findotherwo_2 = @mysqli_query($rs_connect, $rs_findotherwo);
while($rs_find_otherwo_q = mysqli_fetch_object($rs_findotherwo_2)) {
$otherwoid = "$rs_find_otherwo_q->woid";

$rs_findotherinv = "SELECT * FROM invoices WHERE preinvoice != '1' AND invstatus = '1' AND (woid = '$otherwoid' OR woid LIKE '%_"."$otherwoid"."_%')";
$rs_findotherinv_2 = @mysqli_query($rs_connect, $rs_findotherinv);
while($rs_find_otherinv_q = mysqli_fetch_object($rs_findotherinv_2)) {
$otherinv = "$rs_find_otherinv_q->invoice_id";
$thisinvwoid = "$rs_find_otherinv_q->woid";
$woidsinthisinvoice = explode_list($thisinvwoid);
if (!in_array($pcwo, $woidsinthisinvoice)) {
$itemtoadd = explode_list($otherinv);
$otherinvoicearray = array_merge($itemtoadd, $otherinvoicearray);
}
}
}
}

$otherinvoicearray = array_unique($otherinvoicearray);

if (($invcount < 1) && ($checkcartcontents > 0)) {
if(count($otherinvoicearray) > 0 ) {
foreach($otherinvoicearray as $key => $otherinvoiceid) {
echo "<a href=repinvoice.php?func=addtoexistinginvoice&woid=$pcwo&invoice_id=$otherinvoiceid class=linkbutton><img src=images/invoice.png border=0 align=absmiddle> ".pcrtlang("Add to Invoice")." #$otherinvoiceid</a>";
echo " <strong>&bull;</strong> <a href=../store/invoice.php?func=printinv&invoice_id=$otherinvoiceid target=_new class=linkbutton>".pcrtlang("view")."</a><br>";
}
}
}
}
##


$depositinvoicearray = array();

if (($invcount + $invcount_2) == 1) {
echo "<br>";
}

while($rs_find_invoices_q = mysqli_fetch_object($rs_findsinv2)) {
$invoice_id = "$rs_find_invoices_q->invoice_id";
$invname = "$rs_find_invoices_q->invname";
$invcompany = "$rs_find_invoices_q->invcompany";
$invstatus = "$rs_find_invoices_q->invstatus";
$invemail = "$rs_find_invoices_q->invemail";
$invaddy1 = "$rs_find_invoices_q->invaddy1";
$invaddy2 = "$rs_find_invoices_q->invaddy2";
$invcity = "$rs_find_invoices_q->invcity";
$invstate = "$rs_find_invoices_q->invstate";
$invzip = "$rs_find_invoices_q->invzip";
$invphone = "$rs_find_invoices_q->invphone";
$invemail = "$rs_find_invoices_q->invemail";
$invwoid = "$rs_find_invoices_q->woid";
$invrec = "$rs_find_invoices_q->receipt_id";
$invdate = "$rs_find_invoices_q->invdate";
$invdate2 = pcrtdate("$pcrt_shortdate", "$invdate");
$invbyuser = "$rs_find_invoices_q->byuser";
$findinvtotal = "SELECT SUM(cart_price) AS invsubtotal, SUM(itemtax) AS invtax FROM invoice_items WHERE invoice_id = '$invoice_id'";
$findinvq = @mysqli_query($rs_connect, $findinvtotal);
$findinva = mysqli_fetch_object($findinvq);
$invtax = "$findinva->invtax";
$invsubtotal = "$findinva->invsubtotal";
$invtotal2 = $invtax + $invsubtotal;
$invtotal = number_format($invtotal2, 2, '.', '');

$invoicelist[] = $invoice_id;


$chkinvoicesql = "SELECT * FROM userlog WHERE reftype = 'invoiceid' AND refid = '$invoice_id' AND actionid = '15'";
$chkinvoice = mysqli_num_rows(mysqli_query($rs_connect, $chkinvoicesql));


echo "<br><div class=\"invoicebox colorbox\">";

$custname = urlencode("$invname");
$custcompany = urlencode("$invcompany");
$custaddy1 = urlencode("$invaddy1");
$custaddy2 = urlencode("$invaddy2");
$custcity = urlencode("$invcity");
$custstate = urlencode("$invstate");
$custzip = urlencode("$invzip");
$custphone = urlencode("$invphone");
$custemail = urlencode("$invemail");

$iorq = invoiceorquote($invoice_id);
if ($iorq == "quote") {
$ilabel = pcrtlang("Quote")." #$invoice_id";
} else {
$ilabel = pcrtlang("Invoice")." #$invoice_id ".pcrtlang("(Final)");
} 


$finddeposits = "SELECT SUM(amount) AS deposittotal FROM deposits WHERE invoiceid = '$invoice_id'";
$finddepositsq = @mysqli_query($rs_connect, $finddeposits);
$finddepositsa = mysqli_fetch_object($finddepositsq);
$deposittotal = "$finddepositsa->deposittotal";
$depositbalance = tnv($invtotal) - tnv($deposittotal);


echo "<span class=\"sizemelarge boldme\"><img src=images/invoice.png border=0 align=absmiddle width=24> $ilabel</span>";
echo "<span class=\"sizemelarge boldme\" style=\"float:right;\">$money$invtotal</span><br>";
if(($deposittotal > 0) && ($invstatus == 1)) {
echo "<span class=\"sizemesmaller boldme\" style=\"float:right;\">".pcrtlang("Deposit Total:")." $money".mf($deposittotal)."</span><br>";
echo "<span class=\"sizemesmaller boldme\" style=\"float:right;\">".pcrtlang("Invoice Balance:")." $money".mf($depositbalance)."</span>";
}

if ($invstatus == 1) {

$depositinvoicearray[] = $invoice_id;

echo "$invdate2 | ";
if ($iorq != "quote") {
echo pcrtlang("Status: Open");
}
if ($invbyuser != "") {
echo " | ".pcrtlang("Created By").": $invbyuser";
}

$invoicewoids = explode_list($invwoid);


if(count($invoicewoids) > 1) {

echo "<br>".pcrtlang("Other Work Orders on this Invoice").":";
foreach($invoicewoids as $key => $thiswoids) {
if($thiswoids != $pcwo) {
echo "<a href=\"index.php?pcwo=$thiswoids\" class=\"linkbuttontiny linkbuttoninv radiusall\">#$thiswoids</a> ";
}
}

}

$returnurli2 = urlencode("../repair/index.php?pcwo=$pcwo");

echo "</span><br><br>";
echo "<a href=../store/invoice.php?func=printinv&invoice_id=$invoice_id&returnurl=$returnurli2 class=invtoolbarlinksmall><i class=\"fa fa-print fa-lg\"></i> ".pcrtlang("Print")."</a>";
echo "<a href=../store/invoice.php?func=emailinv2&invoice_id=$invoice_id&emailaddy=$invemail&returnurl=$returnurli2 class=invtoolbarlinksmall><i class=\"fa fa-envelope fa-lg\"></i> ".pcrtlang("Email")." ";
if ($chkinvoice >= 1) {
echo "<span class=colormegreen> <i class=\"fa fa-check-circle\"></i> </span>";
}

echo "</a>";

echo "<a href=../store/invoice.php?func=editinvoice&invoice_id=$invoice_id&returnurl=$returnurli2 $therel class=invtoolbarlinksmall><i class=\"fa fa-edit fa-lg\"></i> ".pcrtlang("Edit")."</a>";
if ($iorq != "quote") {
echo "<a href=repinvoice.php?func=checkout&invoice_id=$invoice_id&woid=$pcwo&custname=$custname&custcompany=$custcompany&custaddy1=$custaddy1&custaddy2=$custaddy2&custcity=$custcity&custstate=$custstate&custzip=$custzip&custphone=$custphone&custemail=$custemail class=invtoolbarlinksmall><i class=\"fa fa-sign-out fa-lg\"></i> ".pcrtlang("Checkout")."</a>";
echo "<a href=../store/invoice.php?func=changeinvoicestatus&invstatus=3&invoice_id=$invoice_id&returnurl=$returnurli2  class=invtoolbarlinksmall onClick=\"return confirm('".pcrtlang("Are you sure you wish to void this invoice?")."');\"><i class=\"fa fa-times-circle fa-lg\"></i> ".pcrtlang("Void")."</a>";
echo "<a href=../store/invoice.php?func=changeinvoicestatus&invstatus=2&invoice_id=$invoice_id&returnurl=$returnurli2 class=invtoolbarlinksmall onClick=\"return confirm('".pcrtlang("Are you sure you wish to close this invoice? Usually you want to checkout an invoice so that the invoice gets marked as paid.")."');\"><i class=\"fa fa-check-circle fa-lg\"></i> ".pcrtlang("Close")."</a>";

### add deposit

if ($depositbalance > 0) {
if ($pcgroupid == 0) {
echo "<a href=\"../store/deposits.php?woid=$pcwo&invoiceid=$invoice_id&cfirstname=$pcname2&ccompany=$pccompany2&caddress=$pcaddress12&caddress2=$pcaddress22&ccity=$pccity2&cstate=$pcstate2&czip=$pczip2&cphone=$pcphone2&cemail=$pcemail2&depamount=$depositbalance\" class=invtoolbarlinksmall><i class=\"fa fa-money fa-lg\"></i> ".pcrtlang("Add Deposit")."</a>";
} else {
echo "<a href=\"../store/deposits.php?woid=$pcwo&invoiceid=$invoice_id&cfirstname=$ue_pcgroupname&ccompany=$ue_grpcompany&caddress=$ue_grpaddress&caddress2=$ue_grpaddress2&ccity=$ue_grpcity&cstate=$ue_grpstate&czip=$ue_grpzip&cphone=$ue_grpphone&cemail=$ue_grpemail&depamount=$depositbalance\" class=invtoolbarlinksmall><i class=\"fa fa-money fa-lg\"></i> ".pcrtlang("Add Deposit")."</a>";
}
}

###


} else {
echo "<a href=../store/invoice.php?func=deletequote&invoice_id=$invoice_id&returnurl=$returnurli2 class=invtoolbarlinksmall onClick=\"return confirm('".pcrtlang("Are you sure you wish to delete this quote?")."');\"><i class=\"fa fa-times-circle fa-lg\"></i> ".pcrtlang("Delete Quote")."</a>";
echo "<a href=repinvoice.php?func=checkout&invoice_id=$invoice_id&woid=$pcwo&custname=$custname&custcompany=$custcompany&custaddy1=$custaddy1&custaddy2=$custaddy2&custcity=$custcity&custstate=$custstate&custzip=$custzip&custphone=$custphone&custemail=$custemail&checkout=no class=invtoolbarlinksmall><i class=\"fa fa-edit fa-lg\"></i> ".pcrtlang("Edit Items")."</a>";

}

} else {

echo "$invname | $invdate2 | $money$invtotal<br>";
if ($iorq != "quote") {
echo pcrtlang("Status: Closed/Paid");
}
if ($invbyuser != "") {
echo " | ".pcrtlang("Created By").": $invbyuser";
}
echo "<br>";

$invoicewoids = explode_list("$invwoid");

if(count($invoicewoids) > 1) {

echo pcrtlang("Other Work Orders on this Invoice").":";
foreach($invoicewoids as $key => $thiswoids) {
echo "<strong>#</strong><a href=\"index.php?pcwo=$thiswoids\">$thiswoids</a> ";
}
echo "<br><br>";
}


$returnurli2 = urlencode("../repair/index.php?pcwo=$pcwo");

echo "<a href=../store/invoice.php?func=printinv&invoice_id=$invoice_id&returnurl=$returnurli2 class=invtoolbarlinksmall><i class=\"fa fa-print fa-lg\"></i> ".pcrtlang("Print")."</a>";
echo "<a href=../store/invoice.php?func=emailinv2&invoice_id=$invoice_id&emailaddy=$invemail&returnurl=$returnurli2 class=invtoolbarlinksmall><i class=\"fa fa-envelope fa-lg\"></i> ".pcrtlang("Email")." ";
if ($chkinvoice >= 1) {
echo "<span class=colormegreen> <i class=\"fa fa-check-circle\"></i></span>";
}
echo "</a>";

if ($iorq != "quote") {
echo "<a href=../store/invoice.php?func=changeinvoicestatus&invstatus=3&invoice_id=$invoice_id&returnurl=$returnurli2 class=invtoolbarlinksmall onClick=\"return confirm('".pcrtlang("Are you sure you wish to void this invoice?")."');\"><i class=\"fa fa-check-circle fa-lg\"></i> ".pcrtlang("Void")."</a>";
}

if (($invrec != '0') && ($iorq != "quote")) {
echo "<a href=../store/receipt.php?func=show_receipt&receipt=$invrec class=invtoolbarlinksmall><i class=\"fa fa-file-text fa-lg\"></i> ".pcrtlang("View Receipt")." #$invrec</a>";
}

}


}



echo "</div>";

#######################################################

while($rs_find_invoices_q_2 = mysqli_fetch_object($rs_findsinv2_2)) {
$invoice_id_2 = "$rs_find_invoices_q_2->invoice_id";
$invname_2 = "$rs_find_invoices_q_2->invname";
$invcompany_2 = "$rs_find_invoices_q_2->invcompany";
$invstatus_2 = "$rs_find_invoices_q_2->invstatus";
$invemail_2 = "$rs_find_invoices_q_2->invemail";
$invaddy1_2 = "$rs_find_invoices_q_2->invaddy1";
$invaddy2_2 = "$rs_find_invoices_q_2->invaddy2";
$invcity_2 = "$rs_find_invoices_q_2->invcity";
$invstate_2 = "$rs_find_invoices_q_2->invstate";
$invzip_2 = "$rs_find_invoices_q_2->invzip";
$invphone_2 = "$rs_find_invoices_q_2->invphone";
$invemail_2 = "$rs_find_invoices_q_2->invemail";
$invwoid_2 = "$rs_find_invoices_q_2->woid";
$invrec_2 = "$rs_find_invoices_q_2->receipt_id";
$invdate_2 = "$rs_find_invoices_q_2->invdate";
$invdate2_2 = pcrtdate("$pcrt_mediumdate", "$invdate_2");
$invbyuser_2 = "$rs_find_invoices_q_2->byuser";
$findinvtotal_2 = "SELECT SUM(cart_price) AS invsubtotal, SUM(itemtax) AS invtax FROM invoice_items WHERE invoice_id = '$invoice_id_2'";
$findinvq_2 = @mysqli_query($rs_connect, $findinvtotal_2);
$findinva_2 = mysqli_fetch_object($findinvq_2);
$invtax_2 = "$findinva_2->invtax";
$invsubtotal_2 = "$findinva_2->invsubtotal";
$invtotal2_2 = $invtax_2 + $invsubtotal_2;
$invtotal_2 = number_format($invtotal2_2, 2, '.', '');

$invoicelist[] = $invoice_id_2;


$chkinvoicesql2 = "SELECT * FROM userlog WHERE reftype = 'invoiceid' AND refid = '$invoice_id_2' AND actionid = '15'";
$chkinvoice2 = mysqli_num_rows(mysqli_query($rs_connect, $chkinvoicesql2));



echo "<br>";

echo "<div class=\"invoiceprebox colorbox\">";

$custname_2 = urlencode("$invname_2");
$custcompany_2 = urlencode("$invcompany_2");
$custaddy1_2 = urlencode("$invaddy1_2");
$custaddy2_2 = urlencode("$invaddy2_2");
$custcity_2 = urlencode("$invcity_2");
$custstate_2 = urlencode("$invstate_2");
$custzip_2 = urlencode("$invzip_2");
$custphone_2 = urlencode("$invphone_2");
$custemail_2 = urlencode("$invemail_2");

$iorq_2 = invoiceorquote($invoice_id_2);
if ($iorq_2 == "quote") {
$ilabel_2 = pcrtlang("Quote")." #$invoice_id_2";
} else {
$ilabel_2 = pcrtlang("Invoice")." #$invoice_id_2 ".pcrtlang("(Prepaid)");
} 


$finddeposits_2 = "SELECT SUM(amount) AS deposittotal FROM deposits WHERE invoiceid = '$invoice_id_2'";
$finddepositsq_2 = @mysqli_query($rs_connect, $finddeposits_2);
$finddepositsa_2 = mysqli_fetch_object($finddepositsq_2);
$deposittotal_2 = "$finddepositsa_2->deposittotal";
$depositbalance_2 = tnv($invtotal_2) - tnv($deposittotal_2);


echo "<span class=\"sizemelarge boldme\"><img src=images/invoice.png border=0 align=absmiddle width=24> $ilabel_2</span>";
echo "<span class=\"sizemelarge boldme\" style=\"float:right;\">$money$invtotal_2</span><br>";
if(($deposittotal_2 > 0) && ($invstatus_2 == 1)) {
echo "<span class=\"sizemesmaller boldme\" style=\"float:right;\">".pcrtlang("Deposit Total:")." $money".mf($deposittotal_2)."</span><br>";
echo "<span class=\"sizemesmaller boldme\" style=\"float:right;\">".pcrtlang("Invoice Balance:")." $money".mf($depositbalance_2)."</span>";
}


if ($invstatus_2 == 1) {

$depositinvoicearray[] = $invoice_id_2;

echo "$invdate2_2 | ";
if ("$iorq_2" != "quote") {
echo pcrtlang("Status: Open");
}
if ($invbyuser_2 != "") {
echo " | ".pcrtlang("Created By").": $invbyuser_2";
}

$returnurli2 = urlencode("../repair/index.php?pcwo=$pcwo");

echo "<br><br>";
echo "<a href=../store/invoice.php?func=printinv&invoice_id=$invoice_id_2&returnurl=$returnurli2 class=invtoolbarlinksmall><i class=\"fa fa-print fa-lg\"></i> ".pcrtlang("Print")."</a>";
echo "<a href=../store/invoice.php?func=emailinv2&invoice_id=$invoice_id_2&emailaddy=$invemail_2&returnurl=$returnurli2 class=invtoolbarlinksmall><i class=\"fa fa-envelope fa-lg\"></i> ".pcrtlang("Email")." ";
if ($chkinvoice2 >= 1) {
echo "<span class=colormegreen> <i class=\"fa fa-check-circle\"></i> </span>";
}
echo "</a>";
echo "<a href=../store/invoice.php?func=editinvoice&invoice_id=$invoice_id_2&returnurl=$returnurli2 class=invtoolbarlinksmall $therel><i class=\"fa fa-edit fa-lg\"></i> ".pcrtlang("Edit")."</a>";
if ($iorq_2 != "quote") {
echo "<a href=repinvoice.php?func=checkout&invoice_id=$invoice_id_2&woid=$pcwo&custname=$custname_2&custcompany=$custcompany_2&custaddy1=$custaddy1_2&custaddy2=$custaddy2_2&custcity=$custcity_2&custstate=$custstate_2&custzip=$custzip_2&custphone=$custphone_2&custemail=$custemail_2&prepaid=yes class=invtoolbarlinksmall><i class=\"fa fa-sign-out fa-lg\"></i> ".pcrtlang("Checkout")."</a>";
echo "<a href=../store/invoice.php?func=changeinvoicestatus&invstatus=3&invoice_id=$invoice_id_2&returnurl=$returnurli2 class=invtoolbarlinksmall  onClick=\"return confirm('".pcrtlang("Are you sure you wish to void this invoice?")."');\"><i class=\"fa fa-times-circle fa-lg\"></i> ".pcrtlang("Void")."</a>";
echo "<a href=../store/invoice.php?func=changeinvoicestatus&invstatus=2&invoice_id=$invoice_id_2&returnurl=$returnurli2 class=invtoolbarlinksmall  onClick=\"return confirm('".pcrtlang("Are you sure you wish to close this invoice? Usually you want to checkout an invoice so that the invoice gets marked as paid.")."');\"><i class=\"fa fa-check-circle fa-lg\"></i> ".pcrtlang("Close")."</a>";

if ($depositbalance_2 > 0) {
if ($pcgroupid == 0) {
echo "<a href=\"../store/deposits.php?woid=$pcwo&invoiceid=$invoice_id_2&cfirstname=$pcname2&ccompany=$pccompany2&caddress=$pcaddress12&caddress2=$pcaddress22&ccity=$pccity2&cstate=$pcstate2&czip=$pczip2&cphone=$pcphone2&cemail=$pcemail2&depamount=$depositbalance_2\" class=invtoolbarlinksmall><i class=\"fa fa-money fa-lg\"></i> ".pcrtlang("Add Deposit")."</a>";
} else {
echo "<a href=\"../store/deposits.php?woid=$pcwo&invoiceid=$invoice_id_2&cfirstname=$ue_pcgroupname&ccompany=$ue_grpcompany&caddress=$ue_grpaddress&caddress2=$ue_grpaddress2&ccity=$ue_grpcity&cstate=$ue_grpstate&czip=$ue_grpzip&cphone=$ue_grpphone&cemail=$ue_grpemail&depamount=$depositbalance_2\" class=invtoolbarlinksmall><i class=\"fa fa-money fa-lg\"></i> ".pcrtlang("Add Deposit")."</a>";
}
}


} else {
echo "<a href=../store/invoice.php?func=deletequote&invoice_id=$invoice_id_2&returnurl=$returnurli2 class=invtoolbarlinksmall onClick=\"return confirm('".pcrtlang("Are you sure you wish to delete this quote?")."');\"><i class=\"fa fa-times-circle fa-lg\"></i> ".pcrtlang("Delete Quote")."</a>";
echo "<a href=repinvoice.php?func=checkout&invoice_id=$invoice_id_2&woid=$pcwo&custname=$custname_2&custcompany=$custcompany_2&custaddy1=$custaddy1_2&custaddy2=$custaddy2_2&custcity=$custcity_2&custstate=$custstate_2&custzip=$custzip_2&custphone=$custphone_2&custemail=$custemail_2&checkout=no class=invtoolbarlinksmall><i class=\"fa fa-edit fa-lg\"></i> ".pcrtlang("Edit Items")."</a>";
}



} else {

echo "$invname_2 | $invdate2_2 | $money$invtotal_2<br>";
if ($iorq_2 != "quote") {
echo pcrtlang("Status: Closed/Paid");
}
if ($invbyuser_2 != "") {
echo " | ".pcrtlang("Created By").": $invbyuser_2";
}

$returnurli2 = urlencode("../repair/index.php?pcwo=$pcwo");

echo "<br>";
echo "<a href=../store/invoice.php?func=printinv&invoice_id=$invoice_id_2&returnurl=$returnurli2 class=invtoolbarlinksmall><i class=\"fa fa-print fa-lg\"></i> ".pcrtlang("Print")."</a>";
echo "<a href=../store/invoice.php?func=emailinv2&invoice_id=$invoice_id_2&emailaddy=$invemail_2&returnurl=$returnurli2 class=invtoolbarlinksmall><i class=\"fa fa-envelope fa-lg\"></i> ".pcrtlang("Email")." ";
if ($chkinvoice2 >= 1) {
echo "<span class=colormegreen> <i class=\"fa fa-check-circle\"></i> </span>";
}
echo "</a>";

if ($iorq_2 != "quote") {
echo "<a href=../store/invoice.php?func=changeinvoicestatus&invstatus=3&invoice_id=$invoice_id_2&returnurl=$returnurli2 class=invtoolbarlinksmall onClick=\"return confirm('".pcrtlang("Are you sure you wish to void this invoice?")."');\"><i class=\"fa fa-times-circle fa-lg\"></i> ".pcrtlang("Void")."</a></span>";
}

if (($invrec_2 != '0') && ($iorq_2 != "quote")) {
echo "<a href=../store/receipt.php?func=show_receipt&receipt=$invrec_2 class=invtoolbarlinksmall><i class=\"fa fa-file-text fa-lg\"></i> ".pcrtlang("View Receipt")." #$invrec_2</a>";
}

}

echo "</div>";

}


echo "<br>";

#######################################################

}

echo "</td></tr></table>";



############Deposits
$addywoids = "";
if(isset($invoicewoids)) {
if(count($invoicewoids) != 0) {
reset($invoicewoids);
foreach($invoicewoids as $key => $thiswoid) {
$addywoids .= " OR woid = '$thiswoid'";
}
}
}


if(count($invoicelist) > 0) {
foreach($invoicelist as $key => $thisinvid) {
$addywoids .= " OR invoiceid = '$thisinvid'";
}
}



$finddeposits = "SELECT * FROM deposits WHERE woid = '$pcwo'$addywoids";

$finddepositsq = @mysqli_query($rs_connect, $finddeposits);

if(mysqli_num_rows($finddepositsq) > 0) {

echo "<br><table class=moneylist>";
echo "<tr><th colspan=7>".pcrtlang("Deposits")."</th></tr>";
while ($finddepositsa = mysqli_fetch_object($finddepositsq)) {
$depositid = "$finddepositsa->depositid";
$depamount2 = "$finddepositsa->amount";
$depamount = mf($depamount2);
$depfirstname = "$finddepositsa->pfirstname";
$depplugin = "$finddepositsa->paymentplugin";
$dstatus = "$finddepositsa->dstatus";
$dwoid = "$finddepositsa->woid";
$dinvoiceid = "$finddepositsa->invoiceid";

echo "<tr><td><strong>".pcrtlang("Deposit")." #$depositid </strong></td><td><strong> $money$depamount </strong></td><td><strong> $depplugin </strong></td><td><strong> ";
echo "$depfirstname </strong></td><td><strong> ";
echo pcrtlang("Status").": ".pcrtlang("$dstatus")."</strong>";
echo "</td><td><strong>";

if(($dwoid != 0) && ($dinvoiceid == 0)) {
echo pcrtlang("Attached to Work Order");
} elseif ($dinvoiceid != 0) {
echo pcrtlang("Attached to Invoice").": $dinvoiceid";
} else {

}

echo "</strong></td><td style=\"width:15%\">";

if($dstatus == "open") {
#if(!empty($depositinvoicearray) || ($dinvoiceid != 0)) {
echo "<a href=\"javascript:void(0);\" class=\"linkbuttonmoney linkbuttonmedium\" style=\"display:inline;border-radius:3px;padding:2px;text-align:center;float:right;\" id=depitemlink$depositid><i class=\"fa fa-chevron-right fa-lg\"></i></a> ";

echo "<div id=depitem$depositid style=\"display:none;\"><br><br>";

if($dinvoiceid != 0) {
echo "<a href=\"pc.php?func=switchdeposit&towhat=woid&woid=$pcwo&depositid=$depositid\" class=moneytoolbarlinksmall style=\"display:block\">".pcrtlang("Work Order")." #$pcwo</a>";
}


if(!empty($depositinvoicearray)) {
reset($depositinvoicearray);
foreach($depositinvoicearray as $key => $thisinv) {
if($dinvoiceid != $thisinv) {

$rs_findsumdi = "SELECT SUM(amount) as invdsum FROM deposits WHERE invoiceid = '$thisinv'";
$rs_findsum2di = @mysqli_query($rs_connect, $rs_findsumdi);
$rs_findsum3di = mysqli_fetch_object($rs_findsum2di);
$invdsum = "$rs_findsum3di->invdsum";

$rs_findsumi = "SELECT SUM(cart_price) AS invsubtotal, SUM(itemtax) AS invtax FROM invoice_items WHERE invoice_id = '$thisinv'";
$rs_findsum2i = @mysqli_query($rs_connect, $rs_findsumi);
$rs_findsum3i = mysqli_fetch_object($rs_findsum2i);
$invdsumd = "$rs_findsum3i->invsubtotal";
$invdsumtax = "$rs_findsum3i->invtax";
$invdtotal = mf($invdsumd + $invdsumtax);

if(($invdsum + $depamount) <= $invdtotal) {
echo "<a href=\"pc.php?func=switchdeposit&towhat=invoice&invoiceid=$thisinv&depositid=$depositid&woid=$pcwo\" 
class=moneytoolbarlinksmall style=\"display:block\">".pcrtlang("Attach to Invoice")." #$thisinv</a>";
} else {
$invbal = mf($invdtotal - $invdsum);
if($invbal > 0) {
echo "<a href=\"repcart.php?func=splitdeposit&towhat=invoice&invoiceid=$thisinv&depositid=$depositid&woid=$pcwo&invbal=$invbal\"
class=moneytoolbarlinksmall style=\"display:block\">".pcrtlang("Split and Attach")." ".pcrtlang("Invoice")." #$thisinv</a>";
}
echo "<span class=moneytoolbarlinksmalldisabled  style=\"display:block\">".pcrtlang("Attach to Invoice")."#$thisinv</span>";
}

}
}
}

if(($dwoid != 0) && ($dinvoiceid == 0)) {
echo "<a href=\"pc.php?func=removedepositfromwo&depositid=$depositid&woid=$pcwo\" class=moneytoolbarlinksmall style=\"display:block\">".pcrtlang("Remove from WO")."</a>";
}

echo "<a href=\"../store/deposits.php?func=deposit_receipt&depositid=$depositid&depemail=$pcemail&woid=$pcwo\" class=moneytoolbarlinksmall style=\"display:block\">".pcrtlang("Print")."</a>";

echo "</div>";


?>
<script type='text/javascript'>
$('#depitemlink<?php echo "$depositid"; ?>').click(function(){
  $('#depitem<?php echo "$depositid"; ?>').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});
</script>
<?php

#}
}

echo "</td></tr>";
}
echo "</table><br>";

}

########################### end Deposits

echo "<div id=addrepaircartarea></div>";

echo "<a href=\"javascript:void(0);\" class=moneybarlink style=\"display:block;border-radius:3px;\" id=repaircartadd>".pcrtlang("Add Labor, Items, or Deposits to Repair Cart")."
<i class=\"fa fa-chevron-down\" style=\"float:right\"></i></a>";

echo "<div id=repaircartbox style=\"display:none;\">";
echo "<div id=repaircartbox2></div>";


echo "<br><table class=moneylist><tr><th colspan=2><strong>".pcrtlang("Add Deposit")."</strong></th></tr><tr><td>";
if ($pcgroupid == 0) {
echo "<a href=\"../store/deposits.php?woid=$pcwo&cfirstname=$pcname2&ccompany=$pccompany2&caddress=$pcaddress12&caddress2=$pcaddress22&ccity=$pccity2&cstate=$pcstate2&czip=$pczip2&cphone=$pcphone2&cemail=$pcemail2\" class=\"linkbuttonmoney linkbuttonmedium radiusall\"><img src=images/deposits.png class=iconmedium> ".pcrtlang("Add a Deposit to this Work Order")."</a>";
} else {
echo "<a href=\"../store/deposits.php?woid=$pcwo&cfirstname=$ue_pcgroupname&ccompany=$ue_grpcompany&caddress=$ue_grpaddress&caddress2=$ue_grpaddress2&ccity=$ue_grpcity&cstate=$ue_grpstate&czip=$ue_grpzip&cphone=$ue_grpphone&cemail=$ue_grpemail\" class=\"linkbuttonmoney linkbuttonmedium radiusall\"><img src=images/deposits.png align=absmiddle border=0> ".pcrtlang("Add a Deposit to this Work Order")."</a>";
}

echo "</td><td>";

$finduadeposits = "SELECT * FROM deposits WHERE woid = '0' AND invoiceid = '0' AND dstatus = 'open'";
$finduadepositsq = @mysqli_query($rs_connect, $finduadeposits);

if(mysqli_num_rows($finduadepositsq) > 0) {

echo "<span class=boldme>".pcrtlang("Add Un-Attached Deposit to Work Order").": </span>";

echo "<form method=post action=\"pc.php?func=adddeposittowo\"><input type=hidden name=woid value=\"$pcwo\"><select name=depositid>";

while ($finduadepositsa = mysqli_fetch_object($finduadepositsq)) {
$depositid = "$finduadepositsa->depositid";
$depositfname = "$finduadepositsa->pfirstname";
$depositlname = "$finduadepositsa->plastname";
$depositamount = "$finduadepositsa->amount";

echo "<option value=\"$depositid\">#$depositid $depositfname $depositlname - $money".mf("$depositamount")."</option>";

}
echo "</select><button type=submit class=\"button\"><i class=\"fa fa-plus fa-lg\"></i></button></form>";
}



echo "</td></tr></table>";

echo "</div>";

?>
<script type="text/javascript">
  $.get('addlabor.php?pcwo=<?php echo "$pcwo"; ?>', function(data) {
    $('#repaircartbox2').html(data);
  });
</script>

<script type='text/javascript'>

$('#repaircartadd').click(function(){
  $('#repaircartbox').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");
});



</script>
<?php




stop_box();







$rs_find_so = "SELECT * FROM specialorders WHERE spowoid = '$pcwo'";
$rs_result_so = mysqli_query($rs_connect, $rs_find_so);


#$totalpagetimewo = microtime(true) - $startpagetimewo;
#echo "<div style=\"text-align:right\"><span class=text12eng>$totalpagetimewo</span></div>";

if(mysqli_num_rows($rs_result_so) > 0) {

echo "<br>";

start_moneybox();

echo "<span class=\"sizemelarge colormemoney boldme\">&nbsp;".pcrtlang("Special Order Parts")."&nbsp;</span><br><br>";

echo "<table style=\"padding-left:10px;padding-right:10px;\" class=moneylist>";
echo "<tr><th>".pcrtlang("Part Name")."</th><th>".pcrtlang("Qty")."</th><th>".pcrtlang("Price")."</th>";
echo "<th style=\"padding-left:10px;padding-right:10px;text-align:right;\">".pcrtlang("Supplier")."</th>";
echo "<th style=\"padding-left:10px;padding-right:10px;\">".pcrtlang("Supplier PN")."</th>";
echo "<th>".pcrtlang("Url")."</th><th>".pcrtlang("Tracking No.")."</th>";
echo "<th>".pcrtlang("Date")."</td><th>".pcrtlang("Status")."</th>";
echo "<th>&nbsp;</th></tr>";

$statii = array(
0 => pcrtlang("Awaiting Customer Approval"),
8 => pcrtlang("Order Part"),
1 => pcrtlang("On Order"),
2 => pcrtlang("Received"),
3 => pcrtlang("Installed"),
4 => pcrtlang("Wrong Part"),
5 => pcrtlang("Bad/Damaged Part"),
6 => pcrtlang("Abandoned Part"),
7 => pcrtlang("Unable to Locate Part"),
9 => pcrtlang("Shipped")
);

while($rs_result_item_q = mysqli_fetch_object($rs_result_so)) {
$spoid = "$rs_result_item_q->spoid";
$spopartname = "$rs_result_item_q->spopartname";
$spoprice = "$rs_result_item_q->spoprice";
$spocost = "$rs_result_item_q->spocost";
$spowoid = "$rs_result_item_q->spowoid";
$sposupplierid = "$rs_result_item_q->sposupplierid";
$sposuppliername = "$rs_result_item_q->sposuppliername";
$spopartnumber = "$rs_result_item_q->spopartnumber";
$spoparturl = "$rs_result_item_q->spoparturl";
$spotracking = "$rs_result_item_q->spotracking";
$spostatus = "$rs_result_item_q->spostatus";
$spodate2 = "$rs_result_item_q->spodate";
$sponotes = "$rs_result_item_q->sponotes";
$spoquantity = "$rs_result_item_q->quantity";
$spounit_price = "$rs_result_item_q->unit_price";

$spodate = pcrtdate("$pcrt_shortdate", "$spodate2");

echo "<tr><td>$spopartname</td><td align=right>".qf("$spoquantity")."</td><td align=right>$money".mf("$spounit_price")."<br>$money".mf("$spoprice")."</td>";

if($sposupplierid != 0) {
$rs_find_suppliers = "SELECT * FROM suppliers WHERE supplierid = $sposupplierid";
$rs_result_supp = mysqli_query($rs_connect, $rs_find_suppliers);
$rs_result_suppq = mysqli_fetch_object($rs_result_supp);
$suppliername2 = "$rs_result_suppq->suppliername";
} else {
$suppliername2 = "$sposuppliername";
}


if(perm_check("23") && ($sposupplierid != 0)) {
echo "<td><a href=\"../store/suppliers.php?func=viewsupplier&supplierid=$sposupplierid\" class=\"moneytoolbarlinksmall radiusall\">$suppliername2</a></td>";
} else {
echo "<td><span class=\"sizemesmaller\">$suppliername2</span></td>";
}

echo "<td><span class=\"sizemesmaller\">$spopartnumber</span></td>";
echo "<td>";
if($spoparturl != "") {
$parturl2 = addhttp("$spoparturl");
echo "<a href=\"$parturl2\" target=\"_blank\" class=\"moneytoolbarlinksmall radiusall\"><i class=\"fa fa-external-link fa-lg\"></i></a>";
}
echo "</td>";

echo "<td>";

if($spotracking != "") {
echo "<a href=\"http://google.com/#q=$spotracking\" target=\"_blank\" class=\"moneytoolbarlinksmall radiusall\">$spotracking</a></span>";
}

echo "</td>";

echo "<td><span class=\"sizemesmaller\">$spodate</span></td>";

echo "<td><span class=\"sizemesmaller boldme\">$statii[$spostatus]</span><br><span class=\"sizemesmaller\">$sponotes</span></td>";


echo "<td>";

echo "<a href=\"pc.php?func=deletespo&spoid=$spoid&spowoid=$pcwo\" class=\"moneytoolbarlinksmall radiusleft\" style=\"white-space: nowrap\" onClick=\"return confirm('".pcrtlang("Are you sure you wish to permanently delete this special order!!!?")."');\"><i class=\"fa fa-trash-o fa-lg\"></i> ".pcrtlang("delete")."</a>";
echo "<a href=\"pc.php?func=editspo&spoid=$spoid&spowoid=$pcwo\" class=\"moneytoolbarlinksmall\"  style=\"white-space: nowrap\"><i class=\"fa fa-edit fa-lg\"></i> ".pcrtlang("edit")."</a>";
echo "<a href=\"repcart.php?func=spoaddcart&spoid=$spoid&spowoid=$pcwo\" class=\"moneytoolbarlinksmall radiusright\"  style=\"white-space: nowrap\"><i class=\"fa fa-shopping-cart fa-lg\"></i> ".pcrtlang("add to cart")."</a>";

echo "</td>";

echo "</tr>";


}

echo "</table>";

stop_box();

}

echo "<br>";


#$totalpagetimewo = microtime(true) - $startpagetimewo;
#echo "<div style=\"text-align:right\"><span class=text12eng>$totalpagetimewo</span></div>";

$rs_find_tl = "SELECT * FROM travellog WHERE tlwo = '$pcwo'";
$rs_result_tl = mysqli_query($rs_connect, $rs_find_tl);

if(mysqli_num_rows($rs_result_tl) > 0) {

start_moneybox();

echo "<span class=\"colormemoney sizemelarge boldme\">&nbsp;".pcrtlang("Mileage Log")."&nbsp;</span><br><br>";

echo "<form action=repcart.php?func=addmiles method=post><table style=\"padding-left:10px;padding-right:10px;\" class=moneylist>";
echo "<tr><th><strong>".pcrtlang("Technician")."</strong></th><th><strong>".pcrtlang("Distance")."</strong></th>";
echo "<th style=\"padding-left:10px;padding-right:10px;\"><strong>".pcrtlang("Date")."</strong></th><th> </th>";
echo "</tr>";

$totaldist = 0;

while($rs_result_item_q = mysqli_fetch_object($rs_result_tl)) {
$tlid = "$rs_result_item_q->tlid";
$tlwo = "$rs_result_item_q->tlwo";
$tldate2 = "$rs_result_item_q->tldate";
$tlmiles = "$rs_result_item_q->tlmiles";
$traveluser = "$rs_result_item_q->traveluser";

$totaldist = $totaldist + $tlmiles;

$tldate = pcrtdate("$pcrt_shortdate", "$tldate2")." ".pcrtdate("$pcrt_time", "$tldate2");

echo "<tr><td>$traveluser</td><td>$tlmiles";

if("$pcrt_units" == "METRIC") {
echo pcrtlang("km");
} else {
echo " ".pcrtlang("miles");
}

echo "</td><td>$tldate</td><td><a href=pc.php?func=deletetl&tlid=$tlid&woid=$pcwo class=\"moneytoolbarlinksmall radiusall\"><i class=\"fa fa-trash-o fa-lg\"></i> ".pcrtlang("remove")."</a></td></tr>";

}

echo "<tr><td><strong>".pcrtlang("Total")."</strong></td><td><input type=text class=textbox size=4 name=miles value=\"$totaldist\"></td>";
echo "<td><strong>$money</strong><input type=text class=textbox size=4 name=permile> <input type=hidden name=pcwo value=$pcwo>";

if("$pcrt_units" == "METRIC") {
echo pcrtlang("per km");
} else {
echo " ".pcrtlang("per mile");
}


echo "&nbsp;&nbsp;<button class=button onclick=\"this.disabled=true; this.form.submit();\"><i class=\"fa fa-cart-plus fa-lg\"></i> ".pcrtlang("Add to Cart")."</button></td><td></td></tr>";

echo "</table></form>";

stop_box();

}



echo "<a name=timers id=timers></a>";


if (function_exists('date_default_timezone_set')) {
date_default_timezone_set("$pcrt_timezone");
}


?>

<script type='text/javascript'>

   function pad(val)
        {
            var valString = val + "";
            if(valString.length < 2)
            {
                return "0" + valString;
            }
            else
            {
                return valString;
            }
        }


</script>

<?php


echo "<br>";


#$totalpagetimewo = microtime(true) - $startpagetimewo;
#echo "<div style=\"text-align:right\"><span class=text12eng>$totalpagetimewo</span></div>";

echo "<div id=timersarea></div>";

start_box();

echo "<table style=\"width:100%\"><tr><td><form action=pc.php?func=timerstart&woid=$pcwo method=post>";
echo "<input name=timername size=20 class=textbox placeholder=\"".pcrtlang("Enter Task Description")."\"> <button type=submit class=\"linkbuttonmedium linkbuttongreen radiusall\"><i class=\"fa fa-clock-o fa-lg\"></i> ".pcrtlang("Start New Timer")."</button></form>";
echo "</td>";

echo "<td rowspan=2 style=\"text-align:right\">";

echo "<a href=pc.php?func=timerstartmanual&woid=$pcwo class=\"linkbuttonmedium linkbuttongreen radiusleft\">".pcrtlang("Manual Timer")."</a>";

if($pcgroupid != 0) {
echo "<a href=\"group.php?func=viewgroup&pcgroupid=$pcgroupid&groupview=blockcontract\" class=\"linkbuttonmedium linkbuttongray radiusright\">".pcrtlang("Block of Time Contracts")."</a>";
}


echo "</td></tr></table>";

function time_elapsed($secs){

    $bit = array(
        'y' => $secs / 31556926 % 12,
        'w' => $secs / 604800 % 52,
        'd' => $secs / 86400 % 7,
        'h' => $secs / 3600 % 24,
        'm' => $secs / 60 % 60,
 #       's' => $secs % 60
        );

    foreach($bit as $k => $v)
        if($v > 0)$ret[] = $v . $k;

if(!isset($ret)) {
$ret[] = "0m";
}

    return join(' ', $ret);
    }


$totalelapsed = 0;

$rs_findtimers = "SELECT * FROM timers WHERE woid = '$pcwo' ORDER BY timerstart ASC";
$rs_result_t = mysqli_query($rs_connect, $rs_findtimers);
while($rs_result_qt = mysqli_fetch_object($rs_result_t)) {
$timername = "$rs_result_qt->timerdesc";
$timerstart = "$rs_result_qt->timerstart";
$timerstop = "$rs_result_qt->timerstop";
$timertotal = "$rs_result_qt->timertotal";
$timerid = "$rs_result_qt->timerid";
$billedout = "$rs_result_qt->billedout";
$timerbyuser = "$rs_result_qt->byuser";
$blockcontractid = "$rs_result_qt->blockcontractid";

$timerstart_2822 = date('r', strtotime("$timerstart"));


$timerstartdate2 = pcrtdate("$pcrt_shortdate", "$timerstart");
$timerstarttime2 = pcrtdate("$pcrt_time", "$timerstart");
$timerstoptime2 = pcrtdate("$pcrt_time", "$timerstop");


$startepoch = strtotime($timerstart);
$stopepoch = time();
$startseconds = $stopepoch - $startepoch;

if($timerstop == "0000-00-00 00:00:00") {
echo "<div class=timeritemactive><table style=\"width:100%\" class=pad5><tr><td colspan=2><span class=\"sizemelarge boldme\">$timername</span></td><td colspan=2 style=\"text-align:right;\">";

echo "<span class=\"colormegreen sizemelarge boldme\">".pcrtlang("Time Elapsed").": <i class=\"fa fa-spinner fa-lg fa-spin\"></i></span>";

?>

<label id="<?php echo "$timerid"; ?>hours" class="colormegreen sizemelarge boldme">0</label><span class="colormegreen sizemelarge boldme">:</span><label id="<?php echo "$timerid"; ?>minutes" class="colormegreen sizemelarge boldme">00</label><span class="colormegreen sizemelarge boldme">:</span><label id="<?php echo "$timerid"; ?>seconds" class="colormegreen sizemelarge boldme">00</label>
    <script type="text/javascript">
        var hoursLabel<?php echo "$timerid"; ?> = document.getElementById("<?php echo "$timerid"; ?>hours");
        var minutesLabel<?php echo "$timerid"; ?> = document.getElementById("<?php echo "$timerid"; ?>minutes");
        var secondsLabel<?php echo "$timerid"; ?> = document.getElementById("<?php echo "$timerid"; ?>seconds");
        var totalSeconds<?php echo "$timerid"; ?> = <?php echo "$startseconds"; ?>;
        setInterval(setTime<?php echo "$timerid"; ?>, 1000);

   function setTime<?php echo "$timerid"; ?>()
        {
            ++totalSeconds<?php echo "$timerid"; ?>;
            secondsLabel<?php echo "$timerid"; ?>.innerHTML = pad(totalSeconds<?php echo "$timerid"; ?>%60);
            minutesLabel<?php echo "$timerid"; ?>.innerHTML = pad(parseInt(totalSeconds<?php echo "$timerid"; ?>/60) %60);
            hoursLabel<?php echo "$timerid"; ?>.innerHTML = parseInt(totalSeconds<?php echo "$timerid"; ?>/3600);
        }

    </script>

<?php


echo "</td></tr>
<tr><td style=\"width:100px\"><span class=\"boldme\"><i class=\"fa fa-calendar fa-lg\"></i> $timerstartdate2</span></td>
<td style=\"width:100px\"><span class=\"colormegreen boldme\"><i class=\"fa fa-clock-o fa-lg\"></i> $timerstarttime2</span></td>
<td style=\"width:100px\"><span class=\"colormegreen boldme\"><i class=\"fa fa-user fa-lg\"></i> $timerbyuser</span> ";



echo "</td>
<td style=\"text-align:right\"><a href=pc.php?func=timereditprog&woid=$pcwo&timerid=$timerid class=\"linkbuttonmedium linkbuttongray radiusleft\"><i class=\"fa fa-edit\"></i> ".pcrtlang("Edit")."</a>";
echo "<a href=pc.php?func=timerstop&woid=$pcwo&timerid=$timerid&blockcontractid=$blockcontractid class=\"linkbuttonmedium linkbuttonred radiusright\"><i class=\"fa fa-stop\"></i> ".pcrtlang("Stop")."</a></td>
</tr></table></div>";

} else {

$startstamp = strtotime("$timerstart");
$stopstamp = strtotime("$timerstop");

$elapsedtime = $stopstamp - $startstamp;

$totalelapsed = $totalelapsed + $elapsedtime;


$elapsedhuman = time_elapsed($elapsedtime);

echo "<div class=timeritem><table style=\"width:100%\" class=pad5><tr><td colspan=2 style=\"vertical-align:top;\"><span class=\"sizemelarge boldme\">$timername</span></td>
<td style=\"text-align:right;vertical-align:top;padding: 10px 0px 0px 0px;\">";
echo "</td><td colspan=1 style=\"text-align:right;\">";

echo "<span class=\"sizemelarge boldme\"><i class=\"fa fa-user fa-lg\"></i> $timerbyuser</span></td><td style=\"text-align:right;width:150px;\">";

echo "<span class=\"colormeblue sizemelarge boldme\">$elapsedhuman</span>";





$timername = urlencode("$timername");

echo "</td></tr>
<tr><td style=\"width:100px\"><span class=\"boldme\"><i class=\"fa fa-calendar fa-lg\"></i> $timerstartdate2</span></td>
<td style=\"width:100px\"><span class=\"colormegreen boldme\"><i class=\"fa fa-clock-o fa-lg\"></i> $timerstarttime2</span></td>
<td style=\"width:100px\"><span class=\"colormered boldme\"><i class=\"fa fa-stop fa-lg\"></i> $timerstoptime2</span></td>
<td style=\"text-align:right\" colspan=3><a href=pc.php?func=timerdelete&woid=$pcwo&timerid=$timerid&blockcontractid=$blockcontractid class=\"linkbuttonmedium linkbuttonred radiusleft\"><i class=\"fa fa-times fa-lg\"></i> ".pcrtlang("Delete")."</a>";
echo "<a href=pc.php?func=timeredit&woid=$pcwo&timerid=$timerid&blockcontractid=$blockcontractid class=\"linkbuttonmedium linkbuttongray\"><i class=\"fa fa-edit fa-lg\"></i> ".pcrtlang("Edit")."</a>";

if($billedout == 0) {
$timername_hsc = urlencode("$timername");
echo "<a href=\"pc.php?func=timerbillfirst&woid=$pcwo&pcgroupid=$pcgroupid&timerid=$timerid&billtime=$elapsedtime&timerdesc=$timername_hsc\" class=\"linkbuttonmedium linkbuttongray\"><i class=\"fa fa-money fa-lg\"></i> ".pcrtlang("Bill Hours")."</a>";

} else {

if($blockcontractid != 0) {
echo "<a href=\"group.php?func=viewgroup&pcgroupid=$pcgroupid&groupview=blockcontract\" class=\"linkbuttonmedium linkbuttongray\">Billed to Contract</a>";
}

}


echo "<a href=pc.php?func=timerstart&woid=$pcwo&timername=$timername class=\"linkbuttonmedium linkbuttongreen radiusright\"><i class=\"fa fa-clock-o fa-lg\"></i> ".pcrtlang("Resume")."</a>
</td></tr></table></div>";

}

}


$elapsedhumantotal = time_elapsed($totalelapsed);

#echo $elapsedhumantotal;

echo "<a name=pcnotes0 id=pcnotes0></a>";

stop_box();


#$totalpagetimewo = microtime(true) - $startpagetimewo;
#echo "<div style=\"text-align:right\"><span class=text12eng>$totalpagetimewo</span></div>";

echo "<br>";

echo "<div id=notesarea></div>";

start_box();

echo "<table style=\"width:100%\"><tr><td><span class=\"sizemelarge boldme\">&nbsp;".pcrtlang("Notes for Customer").": </span><span class=\"sizemelarge\">($pcname)</span></td><td>";


######

echo "<a href=\"javascript:void(0);\" id=addcnote class=\"linkbutton floatright\"><i class=\"fa fa-plus fa-lg\"></i> ".pcrtlang("Add Customer Note")."</a></td></tr></table>";

?>
<script type='text/javascript'>
$('#addcnote').click(function() {
  $('#custnote').slideToggle(500, function() {
	$( "#custnoteta" ).focus();
  });
});
</script>
<?php

echo "<div id=custnote style=\"display:none;\">";

?>
<script type='text/javascript' src='jq/jquery.autogrow-textarea.js'></script>
<?php

echo "<form id=custnoteform action=pc.php?func=addnote2 method=post>";
echo "<table style=\"width:100%\"><tr><td>";
echo "<div class=\"wonote right\">";
echo "<textarea id=custnoteta name=thenote required=required rows=1 class=textboxw style=\"width:98%\"></textarea>";

?>

<script type='text/javascript'>
  $(function() {
    $('textarea').autogrow();
  });
</script>

<?php

echo "</div>";

echo "</td>";
echo "<td style=\"width:125px;text-align:center;vertical-align:top;\">";
echo "<input type=hidden name=woid value=$pcwo><input type=hidden name=ajaxcall value=yes><input type=hidden name=notetype value=0>";
echo "<input type=hidden name=touch value=\"\">";
echo "<button type=submit class=sbutton><i class=\"fa fa-save fa-lg\"></i> ".pcrtlang("Save")."</button></td></tr></table></form>";
echo "</div>";

?>
<script type='text/javascript'>
$(document).ready(function(){
$('#custnoteform').submit(function(e) { // catch the form's submit event
        e.preventDefault();
        $.ajax({ // create an AJAX call...
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
            $('#custnotearea').html(response); // update the DIV
	$('#custnoteform').each (function(){
	  this.reset();
	});
  	$('#custnote').slideToggle(1000, function() {
	});
    }
    });
});
});
</script>
<?php



###

echo "<div id=custnotearea>";

require("ajaxcalls.php");
loadwonotes("$pcwo","0");


echo "</div>";




stop_box();
echo "<a name=pcnotes1 id=pcnotes1></a>";
echo "<br>";
start_box();
#######tech notes

echo "<table style=\"width:100%\"><tr><td><span class=\"sizemelarge boldme\">&nbsp;".pcrtlang("Private Notes/Billing Instructions").": </span>
<span class=\"sizemelarge\">($pcname)</span></td><td>";
echo "<a href=\"javascript:void(0);\" id=addtnote class=linkbutton style=\"float:right\"><i class=\"fa fa-plus fa-lg\"></i> ".pcrtlang("Add Private Note")."</a></td>
</tr></table>\n";


?>
<script type='text/javascript'>
$('#addtnote').click(function() {
  $('#technote').slideToggle(500, function() {
        $( "#technoteta" ).focus();
  });
});
</script>
<?php

echo "<div id=technote style=\"display:none;\">";

?>
<script type='text/javascript' src='jq/jquery.autogrow-textarea.js'></script>
<?php

echo "<form id=technoteform action=pc.php?func=addnote2 method=post>";
echo "<table style=\"width:100%\"><tr><td>";
echo "<div class=\"wonote right\">";
echo "<textarea id=technoteta name=thenote required=required rows=1 class=textboxw style=\"width:98%\"></textarea>";

?>

<script type='text/javascript'>
  $(function() {
    $('textarea').autogrow();
  });
</script>

<?php

echo "</div>";

echo "</td>";
echo "<td style=\"width:125px;text-align:center;vertical-align:top;\">";
echo "<input type=hidden name=woid value=$pcwo><input type=hidden name=ajaxcall value=yes><input type=hidden name=notetype value=1>";
echo "<input type=hidden name=touch value=\"\">";
echo "<button type=submit class=sbutton><i class=\"fa fa-save fa-lg\"></i> ".pcrtlang("Save")."</button></td></tr></table></form>";
echo "</div>";
?>
<script type='text/javascript'>
$(document).ready(function(){
$('#technoteform').submit(function(e) { // catch the form's submit event
        e.preventDefault();
        $.ajax({ // create an AJAX call...
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
            $('#technotearea').html(response); // update the DIV
        $('#technoteform').each (function(){
          this.reset();
        });
        $('#technote').slideToggle(1000, function() {
        });
    }
    });
});
});
</script>
<?php


echo "<div id=technotearea>";
loadwonotes("$pcwo","1");
echo "</div>";
stop_box();
echo "<br>";

echo "<a name=messages id=messages></a>";
echo "<div id=messagesarea></div>";
start_box();
####### messages

$emails = array();
if(isset($grpemail)) {
if (filter_var($grpemail, FILTER_VALIDATE_EMAIL)) {
$emails[] = "$grpemail";
}
}
if (filter_var($pcemail, FILTER_VALIDATE_EMAIL)) {
if (!in_array($pcemail, $emails)) {
$emails[] = "$pcemail";
}
}

$emailsimploded = implode_list_email($emails);



$phnumbers = array();
$smsphonenumberoptions = "";

if($pcphone != "") {
$pcphonestripped = preg_replace("/[^0-9,.]/", "", "$pcphone" );
$phnumbers[] = "$pcphonestripped";
$smsphonenumberoptions .= "<option value=\"$mysmsprefix".filtersmsnumber("$pcphone")."\">".pcrtlang("Home").": $pcphone</option>";
}

if($pccellphone != "") {
$pccellphonestripped = preg_replace("/[^0-9,.]/", "", "$pccellphone");
if (!in_array($pccellphonestripped, $phnumbers)) {
$phnumbers[] = "$pccellphonestripped";
}
$smsphonenumberoptions .= "<option selected value=\"$mysmsprefix".filtersmsnumber("$pccellphone")."\">".pcrtlang("Mobile").": $pccellphone</option>";
}

if($pcworkphone != "") {
$pcworkphonestripped = preg_replace("/[^0-9,.]/", "", "$pcworkphone");
if (!in_array($pcworkphonestripped, $phnumbers)) {
$phnumbers[] = "$pcworkphonestripped";
}
$smsphonenumberoptions .= "<option value=\"$mysmsprefix".filtersmsnumber("$pcworkphone")."\">".pcrtlang("Work").": $pcworkphone</option>";
}

if($pcgroupid != 0) {

if($grpphone != "") {
$grpphonestripped = preg_replace("/[^0-9,.]/", "", "$grpphone");
if (!in_array($grpphonestripped, $phnumbers)) {
$phnumbers[] = "$grpphonestripped";
}
$smsphonenumberoptions .= "<option value=\"$mysmsprefix".filtersmsnumber("$grpphone")."\">".pcrtlang("Home from Group").": $grpphone</option>";
}

if($grpcellphone != "") {
$grpcellphonestripped = preg_replace("/[^0-9,.]/", "", "$grpcellphone");
if (!in_array($grpcellphonestripped, $phnumbers)) {
$phnumbers[] = "$grpcellphonestripped";
}
$smsphonenumberoptions .= "<option value=\"$mysmsprefix".filtersmsnumber("$grpcellphone")."\">".pcrtlang("Mobile from Group").": $grpcellphone</option>";
}

if($grpworkphone != "") {
$grpworkphonestripped = preg_replace("/[^0-9,.]/", "", "$grpworkphone");
if (!in_array($grpworkphonestripped, $phnumbers)) {
$phnumbers[] = "$grpworkphonestripped";
}
$smsphonenumberoptions .= "<option value=\"$mysmsprefix".filtersmsnumber("$grpworkphone")."\">".pcrtlang("Work from Group").": $grpworkphone</option>";
}

}


$phnumbers_il = implode_list($phnumbers);


echo "<table style=\"width:100%\"><tr><td><span class=\"sizemelarge boldme\">&nbsp;".pcrtlang("Messages").": </span>
<span class=\"sizemelarge\">($pcname)</span></td><td>";
echo "<a href=\"javascript:void(0);\" id=addmessage class=linkbutton style=\"float:right\"><i class=\"fa fa-paper-plane fa-lg\"></i> ".pcrtlang("Send Message")."</a></td>
</tr></table>\n";


?>
<script type='text/javascript'>
$('#addmessage').click(function() {
  $('#messagesdiv').slideToggle(500, function() {
        $( "#messagea" ).focus();
  });
});
</script>
<?php

echo "<div id=messagesdiv style=\"display:none;\">";

echo "<table class=standard><tr>";

echo "<tr><th>".pcrtlang("Send SMS")." ($mysmsgateway)</th><th>".pcrtlang("Call Log/Send Message")."</th></tr>";

echo "<td style=\"width:50%;vertical-align:top\">";

##############

start_box();

if ($mysmsgateway != "none") {

echo "<form action=sms.php?func=smssend2 method=post id=smsform>";

echo "<input type=hidden name=woid value=$pcwo>";

if($smsphonenumberoptions != "") {
echo "<select name=smsnumber>$smsphonenumberoptions</select><br>";
} else {
echo "<input type=text name=smsnumber class=textbox placeholder=\"Enter Mobile Number\"><br>";
}

$storeinfoarray = getstoreinfo($defaultuserstore);

echo "<select name=myoptions onchange='document.getElementById(\"smsmessage\").value=this.options[this.selectedIndex].value' style=\"width:300px;\">";
$rs_ql = "SELECT * FROM smstext ORDER BY theorder DESC";
$rs_result1 = mysqli_query($rs_connect, $rs_ql);
echo "<option value=\"\">".pcrtlang("choose a message or write your own below")."</option>";
while($rs_result_q1 = mysqli_fetch_object($rs_result1)) {
$smstextid = "$rs_result_q1->smstextid";
$smstext = "$rs_result_q1->smstext";
$theorder = "$rs_result_q1->theorder";
if (strlen($smstext) > 80) {
$smstextshort = substr("$smstext", 0, 80)."...";
} else {
$smstextshort = $smstext;
}
echo "<option value=\"$smstext\">$smstextshort</option>";
}
echo "</select>";


echo "<input type=hidden name=woid value=$pcwo><textarea style=\"width:90%;height:175px;\" rows=4 name=smsmessage id=smsmessage class=textbox name=smsbox></textarea>";
echo "<input type=hidden name=phonenumbers value=$phnumbers_il>";
echo "<input type=hidden name=emails value=$emailsimploded>";
echo "<input type=hidden name=pickup value=\"$pickup\">";
echo "<input type=hidden name=dropoff value=\"$dropoff\">";

echo "<br><span class=colormegreen>".pcrtlang("Characters Remaining").": <span id=\"charsLeft\"></span></span>";

###
if ($mysmsgateway == "twilio") {
$rs_assetphotos = "SELECT * FROM assetphotos WHERE pcid = '$pcid'";
$rs_result_aset = mysqli_query($rs_connect, $rs_assetphotos);
$totalsmspics = mysqli_num_rows($rs_result_aset);
if($totalsmspics > 0) {
echo "<br><br>";
echo "<select size=2 name=assetphotoid class=\"attach-menu\">";
echo "<option selected value=0 style=\"background-image:url(images/del.png)\">".pcrtlang("No Photo")."</option>";
while($rs_result_aset2 = mysqli_fetch_object($rs_result_aset)) {
$photofilename = "$rs_result_aset2->photofilename";
$assetphotoid = "$rs_result_aset2->assetphotoid";
$highlight = "$rs_result_aset2->highlight";

echo "<option value=$assetphotoid style=\"background-image:url(pc.php?func=getpcimage&photoid=$assetphotoid)\">$photofilename</option>";
}
echo "</select>";
}
}
###

echo "<br><input type=submit value=\"".pcrtlang("Send SMS")."\" class=ibutton>";

?>
<script src="jq/jquery.limit-1.2.js" type="text/javascript"></script>
<?php

if ($mysmsgateway == "smsglobal") {
?>
<script type="text/javascript">
$('#smsmessage').limit('600','#charsLeft');
</script>
<?php

} elseif ($mysmsgateway == "twilio") {
?>
<script type="text/javascript">
$('#smsmessage').limit('1600','#charsLeft');
</script>
<?php


} else {

?>
<script type="text/javascript">
$('#smsmessage').limit('150','#charsLeft');
</script>
<?php

}

echo "</form>";

} else {
echo "<i class=\"fa fa-warning fa-lg colormered\"></i> ".pcrtlang("No SMS Gateway Service Configured")."...";
}

stop_box();




##############

echo "</td><td style=\"vertical-align:top;\">";
start_box();
echo "<form action=pc.php?func=addmessage method=post id=calllogform><input type=hidden name=woid value=$pcwo>";
echo "<input type=hidden name=phonenumbers value=$phnumbers_il>";
echo "<input type=hidden name=emails value=$emailsimploded>";
echo "<input type=hidden name=pickup value=\"$pickup\">";
echo "<input type=hidden name=dropoff value=\"$dropoff\">";
echo "<textarea name=themessage required=required class=textboxw style=\"width:95%;height:90px;\" placeholder=\"".pcrtlang("Enter Call Notes")."\"></textarea>";
echo "<div class=startbox><input type=radio name=type value=1 checked> ".pcrtlang("Call Log Note")."</div>";
echo "<div class=startbox><input type=radio name=type value=2> ".pcrtlang("Portal Message")."</div>";
echo "<div class=startbox><input type=radio name=type value=3> ".pcrtlang("Send Email")."<br>";
echo pcrtlang("From").": <select name=fromemail>";
$storeinfoarray = getstoreinfo($defaultuserstore);
if("$storeinfoarray[storeemail]" != "") {
echo "<option value=\"$storeinfoarray[storeemail]\">".pcrtlang("Store").": $storeinfoarray[storeemail]</option>";
}
$techemail = getuseremail("$ipofpc");
if("$techemail" != "") {
echo "<option value=\"$techemail\">".pcrtlang("Tech").": $techemail</option>";
}
echo "</select><br>";

echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".pcrtlang("To").": <select name=toemail>";
if("$pcemail" != "") {
echo "<option value=\"$pcemail\">$pcemail</option>";
}
if(isset($grpemail)) {
if("$grpemail" != "") {
echo "<option value=\"$grpemail\">$grpemail</option>";
}
}

echo "</select>";
echo "</div>";


echo "<br><button type=submit class=sbutton><i class=\"fa fa-save fa-lg\"></i> ".pcrtlang("Save/Send")."</button>";

echo "</form>";
stop_box();
echo "</td></tr></table><br>";
echo "</div>";




?>
<script type='text/javascript'>
$(document).ready(function(){
$('#smsform').submit(function(e) { // catch the form's submit event
        e.preventDefault();
        $.ajax({ // create an AJAX call...
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
            $('#messagearea').html(response); // update the DIV
	$('#smsform').each (function(){
	  this.reset();
	});
  	$('#messagesdiv').slideToggle(1000, function() {
	});
    }
    });
});
});

$(document).ready(function(){
$('#calllogform').submit(function(e) { // catch the form's submit event
        e.preventDefault();
        $.ajax({ // create an AJAX call...
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
            $('#messagearea').html(response); // update the DIV
        $('#calllogform').each (function(){
          this.reset();
        });
        $('#messagesdiv').slideToggle(1000, function() {
        });
    }
    });
});
});

$(document).ready(function () {
        setInterval(function() {
                $.get('sms.php?func=smsload&phonenumbers=<?php echo "$phnumbers_il"; ?>&emails=<?php echo "$emailsimploded"; ?>&woid=<?php echo "$pcwo"; ?>&pickup=<?php echo "$pickup"; ?>&dropoff=<?php echo "$dropoff"; ?>', function(data) {
                $('#messagearea').html(data);
                });
        }, 60000);
});


</script>
<?php


echo "<div id=messagearea>";
displaymessages("$phnumbers_il","$emailsimploded","$pcwo","$pickup","$dropoff");
echo "</div>";

echo "<br><a href=messages.php?func=browsemessages&woid=$pcwo&phonenumbers=$phnumbers_il&emails=$emailsimploded class=\"linkbuttonsmall linkbuttongray radiusall\">
<i class=\"fa fa-comments fa-lg\"></i> ".pcrtlang("Browse all Messages")."</a>";

echo "<a name=wochecks id=wochecks></a>";
stop_box();
echo "<br>";





$rs_sq = "SELECT * FROM mainassettypes WHERE mainassettypeid = '$mainassettypeidindb'";
$rs_result1 = mysqli_query($rs_connect, $rs_sq);
$rs_result_q1 = mysqli_fetch_object($rs_result1);
$mainassetchecksindb = serializedarraytest("$rs_result_q1->mainassetchecks");


if(count($mainassetchecksindb) > 0) {


echo "<div id=checksarea>";

loadchecks($pcwo);

echo "</div>";

?>

<script type="text/javascript">
$(document).ready(function(){
$('#checksarea').on('click', 'a', function(e) {
  		e.preventDefault(); // stop the browser from following the link
  		var url = $(this).attr('href');
              	$('div#checksarea').load(url); // load the html response into a DOM element
	});
});
</script>
<?php




echo "<br>";

}

#$totalpagetimewo = microtime(true) - $startpagetimewo;
#echo "<div style=\"text-align:right\"><span class=text12eng>$totalpagetimewo</span></div>";

echo "<div id=scansarea></div>";
echo "<a name=addscan id=addscan></a>";

if ($mainassettypeshowscans == 1) {

echo "<div id=scansadd></div>";


?>
<script type="text/javascript">
  $.get('addscans.php?pcwo=<?php echo "$pcwo"; ?>', function(data) {
    $('#scansadd').html(data);
  });
</script>
<?php


#$totalpagetimewo = microtime(true) - $startpagetimewo;
#echo "<div style=\"text-align:right\"><span class=text12eng>$totalpagetimewo</span></div>";


echo "<div id=showscans></div>";

?>
<script type="text/javascript">
  $.get('showscans.php?pcwo=<?php echo "$pcwo"; ?>', function(data) {
    $('#showscans').html(data);
  });
</script>


<script type="text/javascript">
$('#scansadd').on('submit', 'form', function (e) {
        e.preventDefault();
	$(this).find("button").text('<?php echo pcrtlang("Wait..."); ?>').attr("disabled",true);
        $.ajax({ // create an AJAX call...
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
		$.get('addscans.php?pcwo=<?php echo "$pcwo"; ?>', function(data) {
    		$('#scansadd').html(data);
		});
               	$.get('showscans.php?pcwo=<?php echo "$pcwo"; ?>', function(data) {
               	$('#showscans').html(data);
               	});
    	}
    });
});

</script>


<script type="text/javascript">
$('#showscans').on('click', '.removescan', function (e) {
        	e.preventDefault();
                var url = $(this).attr('href');
		$.get(url, function () {	
                $.get('showscans.php?pcwo=<?php echo "$pcwo"; ?>', function(data) {
                $('#showscans').html(data);
                });
		$.get('addscans.php?pcwo=<?php echo "$pcwo"; ?>', function(data) {
    		$('#scansadd').html(data);
		});
		});
    });

</script>


<?php

#################################################
#End if scan
}
######



echo "<br>";


#$totalpagetimewo = microtime(true) - $startpagetimewo;
#echo "<div style=\"text-align:right\"><span class=text12eng>$totalpagetimewo</span></div>";


##################################################







} 

}


$pcphoned2 = urldecode($pcphone2);
if ("$floatbar" == "1") {
if("$pccompany" == "") {
floater("$pcstatus","<a href=\"#\" onclick=\"loadworkorder($pcwo);return false;\"><i class=\"fa fa-refresh fa-lg\" style=\"color:white;\"></i></a>&nbsp;&nbsp;$pcname &bull; $pcmake &bull; $pcphoned2");
} else {
floater("$pcstatus","<a href=\"#\" onclick=\"loadworkorder($pcwo);return false;\"><i class=\"fa fa-refresh fa-lg\" style=\"color:white;\"></i></a>&nbsp;&nbsp;$pcname &bull; $pccompany &bull; $pcmake &bull; $pcphoned2");
}
stopfloater();
}


?>





</td></tr></table>

<script type='text/javascript'>
scrollToElement($('#<?php echo "$scrollto"; ?>'));
</script>

<div id=bottomnavbarfixed>

<button id=topbutton class="linkbuttonsmall radiusall buttonopaque" style="background:none;color:white;"><i class="fa fa-user fa-2x"></i></button>
<button id=assetinfobutton class="linkbuttonsmall radiusall buttonopaque" style="background:none;color:#03a9f4;"><i class="fa fa-desktop fa-2x"></i></button>
<?php
if (($rs_chargewhatcount != 0) || ($rs_invoicecount != 0)) {
echo "<button id=repaircartbutton class=\"linkbuttonsmall radiusall buttonopaque\" style=\"background:none;color:#cddc39;\"><i class=\"fa fa-shopping-cart fa-2x\"></i></button>";
}
?>
<button id=addrepaircartbutton class="linkbuttonsmall radiusall buttonopaque" style="background:none;color:#cddc39;"><i class="fa fa-money fa-2x"></i></button>
<button id=timersbutton class="linkbuttonsmall radiusall buttonopaque" style="background:none;color:yellow;"><i class="fa fa-clock-o fa-2x"></i></button>
<button id=notesbutton class="linkbuttonsmall radiusall buttonopaque" style="background:none;color:#e040fb;"><i class="fa fa-pencil-square fa-2x"></i></button>
<button id=messagesbutton class="linkbuttonsmall radiusall buttonopaque" style="background:none;color:#81d4fa;"><i class="fa fa-comment fa-2x"></i></button>
<?php
if(count($mainassetchecksindb) > 0) {
echo "<button id=checksbutton class=\"linkbuttonsmall radiusall buttonopaque\" style=\"background:none;color:#ff1744;\"><i class=\"fa fa-check-circle fa-2x\"></i></button>";
}
if ($mainassettypeshowscans == 1) {
echo "<button id=scansbutton class=\"linkbuttonsmall radiusall buttonopaque\" style=\"background:none;color:#ff9800;\"><i class=\"fa fa-bug fa-2x\"></i></button>";
}
?>


</div>



<script>

$("#messagesbutton").click(function() {
    $('html, body').animate({
        scrollTop: $("#messagesarea").offset().top-50
    }, 250);
  $('#messagesdiv').slideToggle(500, function() {
        $( "#messagea" ).focus();
  });
});


$("#topbutton").click(function() {
    $('html, body').animate({
        scrollTop: $("#toparea").offset().top-70
    }, 250);
});

$("#statusbutton").click(function() {
    $('html, body').animate({
        scrollTop: $("#statusarea").offset().top-70
    }, 250);
});

$("#assetinfobutton").click(function() {
    $('html, body').animate({
        scrollTop: $("#assetinfoarea").offset().top-70
    }, 250);
});

$("#addrepaircartbutton").click(function() {
    $('html, body').animate({
        scrollTop: $("#addrepaircartarea").offset().top-70
    }, 250);

  $('#repaircartbox').toggle('1000');
  $("i",this).toggleClass("fa-chevron-up fa-chevron-down");

});


$("#repaircartbutton").click(function() {
    $('html, body').animate({
        scrollTop: $("#repaircartarea").offset().top-70
    }, 250);
});

$("#timersbutton").click(function() {
    $('html, body').animate({
        scrollTop: $("#timersarea").offset().top-70
    }, 250);
});

$("#notesbutton").click(function() {
    $('html, body').animate({
        scrollTop: $("#notesarea").offset().top-70
    }, 250);
});

$("#checksbutton").click(function() {
    $('html, body').animate({
        scrollTop: $("#checksarea").offset().top-70
    }, 250);
});

$("#scansbutton").click(function() {
    $('html, body').animate({
        scrollTop: $("#scansarea").offset().top-70
    }, 250);
});




</script>


