[insert_php] remove_filter( ‘the_content’, ‘wpautop’ ); [/insert_php]
[insert_php] remove_filter( ‘the_excerpt’, ‘wpautop’ ); [/insert_php]
[insert_php] remove_filter(‘the_content’, ‘wptexturize’); [/insert_php]
[insert_php] include(ABSPATH. ‘/wp-content/custom-php/templates/header.php’); [/insert_php]
[insert_php] if(!$_SESSION[‘login_user’]) { /*header(“Location: /log-in/”, true);*/ echo ““; } [/insert_php]
var _sandbox = ((window.location+"").match("sandbox") != null);
function pageLoad(){
gatherProjects("Projects");
gatherProjects("Quotes");
document.querySelector("#form_searchProjects").addEventListener("submit", function(event) { event.preventDefault(); }, false);
document.querySelector("#form_searchQuotes" ).addEventListener("submit", function(event) { event.preventDefault(); }, false);
if( getUrlParam('quotes', false) ) // Quote Tab
{ document.getElementById("tab-2").checked = "true"; }
if( getUrlParam('projects', false) ) // Quote Tab
{ document.getElementById("tab-1").checked = "true"; }
// else // Project Tab
// { document.getElementById("tab-1").checked = "true"; }
}
//
//
//
//
//
//
//
//
//Populate:
// Input: timeSheet To be displayed
function populate(data, action='sheet'){ //which timesheet to peruse.
console.log(action);
document.getElementById(action+'Body').innerHTML='';
document.getElementById(action+'Nums').innerHTML='';
var clientLinkIndex;
if(action=='Projects') clientLinkIndex = 10;
if(action=='Quotes') clientLinkIndex = 11;
//
// ======From Here to next SIGNPOST handles Search/Sort & pagination links.
//
var timeSheet=data[0];
if(timeSheet==[]){ // If there are no unaccepted times for this employee do the following -> to be handled once jquery is installed.
console.log("No pay Items.");
return(false);
}
var pageNum=document.getElementById(action+"page").value;
var lastDate =0;
//
var myMax =Math.max(10,(pageNum+5));
var i = 1;
if (pageNum>4){
i=pageNum-4;
}
myMax= Math.ceil(Math.max(Math.min(myMax, (data[1])),1)); //choose the smaller of A) current page+5, B) Total number of pages - determines the largest number shown on the index line
var pageNumbers=document.getElementById(action+"Nums");
document.getElementById(action+"lastPage").setAttribute('onClick','toPage('+Math.ceil((data[1]))+',"'+ action +'");');
var tempNum= pageNum;
tempNum++;
document.getElementById(action+'expenseNext').setAttribute('onClick','toPage('+Math.min(Math.ceil((data[1])), tempNum)+',"'+ action +'");');
document.getElementById(action+'expensePrev').setAttribute('onClick','toPage('+Math.max(1,(pageNum-1))+',"'+ action +'");');
//
//Creating the list of clickable numbers at the bottom of the page
//
for(i; i<=myMax;i++){
var addPage = document.createElement('a');
if(i!=pageNum){
addPage.setAttribute('onClick','toPage('+i+',"'+action+'");');
addPage.className='clickAble';
}
else{addPage.style.color='lightblue';} // indicate the current page.
addPage.innerHTML=" "+i+" ";
pageNumbers.appendChild(addPage);
}
//
//======END SIGNPOST ================================================
//
i=0;
var table = document.getElementById(action+'Body'); //selecting the timesheet table
table.innerHTML='';
if(action == "Quotes") table.classList.add( "colourise_quoteStatus" );
var mySize = document.getElementById(action+"Head").rows[0].cells.length;
//Possibly limit SQL returns from PHP page
//remove all table rows present:
//add fresh table rows
for(i; i Date.now() )
{ tableRow.classList.add("status_late"); statusText = "Quote Late"; }
// If the date due is within 7 days
else if ( Date.parse(timeSheet[i][_CELL_QUOTE_DUE]) < (new Date()).setDate( ( new Date() ).getDate() + 7) )
{ tableRow.classList.add("status_almostDue"); statusText = "Almost Due"; }
else
{ tableRow.classList.add("status_quoteOpen"); statusText = "Quote Open"; }
// status_responseLate
}
else {
if( timeSheet[i][_CELL_QUOTE_RESPONSE_DUE] == "" ||
timeSheet[i][_CELL_QUOTE_RESPONSE_DUE] == null ||
timeSheet[i][_CELL_QUOTE_RESPONSE_DUE] == "null" ||
Date.parse( timeSheet[i][_CELL_QUOTE_RESPONSE_DUE] ) < Date.now()
) { tableRow.classList.add("status_responseLate"); statusText = "Response from Client is Late"; }
else
{ tableRow.classList.add("status_sentToClient"); statusText = "Sent to Client"; }
}
} else {
if( timeSheet[i][_CELL_WINCODE] == "3" || timeSheet[i][_CELL_WINCODE] == 3 ) { tableRow.classList.add("status_rfqWithdrawn"); statusText = "RFQ Withdrawn"; }
else if( timeSheet[i][_CELL_WINCODE] == "4" || timeSheet[i][_CELL_WINCODE] == 4 ) { tableRow.classList.add("status_closedNoJob"); statusText = "Not Quoted"; }
// else if( timeSheet[i][_CELL_WINCODE] == "0" || timeSheet[i][_CELL_WINCODE] == 0 ) { tableRow.classList.add("status_closedNoJob"); statusText = "Quote Lost"; }
else {
if( timeSheet[i][_CELL_SUM_CLOSED] == 1 && timeSheet[i][_CELL_SUM_PROJECTS] == 1 ) { tableRow.classList.add( "status_closedNoJob" ); statusText = "Closed with No Job"; }
else if( timeSheet[i][_CELL_SUM_CLOSED] == 1 && timeSheet[i][_CELL_SUM_PROJECTS] == 2 ) { tableRow.classList.add( "status_jobOpen" ); statusText = "Job In Progress"; }
else if( timeSheet[i][_CELL_SUM_CLOSED] == 2 && timeSheet[i][_CELL_SUM_PROJECTS] == 2 ) { tableRow.classList.add( "status_jobClosed" ); statusText = "Job Closed"; }
else { tableRow.classList.add( "status_unknown" ); statusText = "Unknown"; }
}
}
} else if (action == "Projects") { statusText="STATUS"; }
else { statusText="STATUS"; }
var j=0;
for(j; j"+timeSheet[i][j]+"";
// tableCell.innerHTML = ""+timeSheet[i][j]+"";
} else if(j == 2) {
if( _sandbox) tableCell.innerHTML=""+(timeSheet[i][j] == null || timeSheet[i][j]=="null"? "" : timeSheet[i][j])+"";
else tableCell.innerHTML=""+(timeSheet[i][j] == null || timeSheet[i][j]=="null"? "" : timeSheet[i][j])+"";
// tableCell.innerHTML=timeSheet[i][j];
} else if(j == 3) {
tableCell.innerHTML=""+timeSheet[i][j]+"";
} else if(j == 5 && action=="Projects" ){
tableCell.innerHTML=(timeSheet[i][j] == 0 ? "Open" : "Closed" );
} else if( j == 8 && action=="Quotes") {
tableCell.innerHTML="$ "+( timeSheet[i][j] == "null" || timeSheet[i][j] == null ? 0.0.toFixed(2) : timeSheet[i][j] ); tableCell.style.textAlign = "right";
} else if( j == _CELL_QUOTE_CHANCE && action=="Quotes") {
tableCell.innerHTML=timeSheet[i][j];
switch( timeSheet[i][j].toUpperCase() )
{
case 'VL': tableCell.setAttribute( "data-tooltip", "Very Likely" ); break;
case 'L': tableCell.setAttribute( "data-tooltip", "Likely" ); break;
case 'P': tableCell.setAttribute( "data-tooltip", "Possible" ); break;
case 'UL': tableCell.setAttribute( "data-tooltip", "Unlikely" ); break;
case 'UVL': tableCell.setAttribute( "data-tooltip", "Very Unlikely" ); break;
case 'R': tableCell.setAttribute( "data-tooltip", "Risky" ); break;
case '': tableCell.removeAttribute( "data-tooltip" ); break;
default: tableCell.setAttribute( "data-tooltip", "Unknown" ); break;
}
} else if( j == _CELL_SUM_CLOSED && action=="Quotes") { tableCell.appendChild( document.createTextNode( statusText ) );
} else if( j == _CELL_PROJECT_PROGRESS && action=="Projects") {
// var L = document.createElement( "div" );
// L.style.width = "25%"; L.style.height = "100%";
// L.style.display = "block";
// L.style.margin = "0"; L.style.padding = "0";
// L.style.position = "absolute";
// L.style.top = "0"; L.style.right = "0";
// L.style.background = "RGB( "+(255 - timeSheet[i][j] * 1.0)+", 255, "+(255 - timeSheet[i][j] * 1.0)+" )";
// tableCell.appendChild( L );
var L = document.createElement( "span" );
L.appendChild( document.createTextNode( ( timeSheet[i][j] * 1.0 ).toFixed(2) +" %" ) );
tableCell.appendChild( L );
} else if((j == 6 || j == 7 || j == 8) && action=="Projects") {
tableCell.innerHTML=(isNaN(timeSheet[i][j]) ? "-" : ((timeSheet[i][j] * 100.0).toFixed(2)) + "%" );
if(j==6)
{
var pct = timeSheet[i][j];
if(isNaN(pct)) { tableCell.parentElement.classList.add("pct-nan"); }
else if (pct >= 1.00) { setRowPctClass( tableCell.parentElement, "pct-100" ); }
else if (pct >= 0.75) { setRowPctClass( tableCell.parentElement, "pct-75" ); }
else if (pct >= 0.50) { setRowPctClass( tableCell.parentElement, "pct-50" ); }
else if (pct >= 0.25) { setRowPctClass( tableCell.parentElement, "pct-25" ); }
else if (pct >= 0.00) { setRowPctClass( tableCell.parentElement, "pct-0" ); }
else { setRowPctClass( tableCell.parentElement, "pct-neg" ); }
}
} else if (j >= 10 ) {
/* Link to CTR Page */
var link = document.createElement( "a" );
link.href = "./project/ctr/?job="+timeSheet[i][_CELL_ID];
link.classList.add( "btn" );
link.classList.add( "btn-toCTR" );
link.setAttribute( "data-tooltip", "Core Management Page" );
tableCell.appendChild( link );
tableCell.style.verticalAlign = "middle";
/* Link to S-curve Graph */
link = document.createElement( "a" );
link.href = "./project/ctr-graph/?projectId="+timeSheet[i][_CELL_ID];
link.classList.add( "btn" );
link.classList.add( "btn-toGraph" );
link.setAttribute( "data-tooltip", "CTR Graph" );
tableCell.appendChild( link );
/* At a glance */
link = document.createElement( "button" );
link.classList.add( "btn" );
link.classList.add( "btn-inspect" );
link.setAttribute( "data-tooltip", "Project at a Glance" );
link.addEventListener( "click", drawInspectProject.bind( null, timeSheet[i][_CELL_ID] ) );
tableCell.appendChild( link );
tableCell.style.verticalAlign = "middle";
} else if (j >= clientLinkIndex) { continue;
} else { tableCell.innerHTML=timeSheet[i][j]; }
}
}
}
//
//END POPULATE()
//
function setRowPctClass(row, cls)
{
row.classList.remove( "project_internal" );
row.classList.remove( "project_inprogress" );
row.classList.remove( "project_underway" );
row.classList.remove( "project_submitted" );
row.classList.remove( "project_rfqWithdrawn" );
row.classList.remove( "project_finished" );
row.classList.remove( "project_bidLost" );
row.classList.remove( "pct-nan" );
row.classList.remove( "pct-100" );
row.classList.remove( "pct-75" );
row.classList.remove( "pct-50" );
row.classList.remove( "pct-25" );
row.classList.remove( "pct-0" );
row.classList.remove( "pct-neg" );
row.classList.add(cls);
}
//
//Function: toPage( INT )
//input: INT - page index for display (starting at 1)
//action: triggers JQUERY to pop the next page up.
//
function toPage(nextPage, table){
//add some type check - drop action if not int.
if(nextPage<1){
nextPage=1;
}
document.getElementById(table+'page').value=nextPage;
search(table, nextPage);
}
//
//END TOPAGE()
//
//
//Function: Sort(column);
//Action: handles formatting of the display prior to sending flag to JQUERY file.
//input: column - The column header's ID- used to sort by.
//Possible input: searched - currently applied search values.
//Calls: payrollSelection(sort, searched(?));
//
function sort(column, action){
//lookup table for value to search against -- somewhere about.
//check header value
//update header Value (add ↑ or ↓ or remove) - unicode: should be fine on browsers.
//
var searched = document.getElementById(action+'searchTerm'); //Un-cleaned last search value -- put in a check for empty fields.
var filtered = document.getElementById(action+'filterOn'); //Setting of filter used on last search.
var currSort = document.getElementById(action+'sortBy'); // sortBy holds the object ID of the column, makes it easier to reset later.
var currDir =document.getElementById(action+'sortDirection');// current sort direction
var origHead = document.getElementById(action+'baseField'); //the original text of the active field.
var myHeader= document.getElementById(column);
if(currSort.value==""){
currSort.value=column;
origHead.value =myHeader.innerHTML;
}
var nextHead=""; //The Text value to be used on the header for display
if(column ==currSort.value){
//
// bit of space to indicate the above is logically separate
//
switch(currDir.value){ //currDir to hold finite state: 0- no ordering, 1 - ascending, 2- descending.
case '1':
nextHead=origHead.value+" ↓";
currDir.value=2;
break;
case '2':
nextHead= origHead.value;
currDir.value=0;
break;
default:
nextHead=myHeader.innerHTML+" ↑";
currDir.value=1;
break;
}
//
//
}
else{
document.getElementById(currSort.value).innerHTML=origHead.value; //reset the old field's state
origHead.value=myHeader.innerHTML; //store the original value of this header
currSort.value=column; //note this header as the one in use.
currDir.value=1;
nextHead=myHeader.innerHTML+" ↑";
}
myHeader.innerHTML=nextHead; //update active header
gatherProjects(action, origHead.value, currDir.value);
}
// END SORT
//
//
//
//Function: search()
//Action: reads settings of search bar & filter, and requests new search on those terms
//input: None on call. Reads values from page. Done this way (on button) rather than with dynamic search-on-keystroke because the internet connection for the client is unreliable.
//Calls: payrollSelection()
//
function search(action, page=1){
console.log(action);
document.getElementById(action+'page').value=page;
var form;
switch( action )
{
case 'Quotes': form = document.getElementById( "form_searchQuotes" ); break;
case 'Projects': form = document.getElementById( "form_searchProjects" ); break;
default: console.log( "Incorrect Action" ); return;
}
document.getElementById(action+'searchTerm').value = form.querySelector( "[name=searchTerm]" ).value.trim();
advanceSearch = {
searchOn: ( form.querySelector( "[name=searchColumn]" ) == null ? null : form.querySelector( "[name=searchColumn]" ).value ),
showInternal: ( form.querySelector( "[name=showInternal]" ) == null ? null : form.querySelector( "[name=showInternal]" ).value ),
hideClosed: ( form.querySelector( "[name=hideClosed]" ) == null ? null : form.querySelector( "[name=hideClosed]" ).value ),
hidePaid: ( form.querySelector( "[name=hidePaid]" ) == null ? null : form.querySelector( "[name=hidePaid]" ).value ),
hideSubmitted: ( form.querySelector( "[name=hideSubmitted]" ) == null ? null : form.querySelector( "[name=hideSubmitted]" ).value ),
hideOverdue: ( form.querySelector( "[name=hideOverdue]" ) == null ? null : form.querySelector( "[name=hideOverdue]" ).value ),
hideInvoiced: ( form.querySelector( "[name=hideInvoiced]" ) == null ? null : form.querySelector( "[name=hideInvoiced]" ).value )
};
console.log( advanceSearch );
if(document.getElementById(action+'searchTerm').value!=""){
gatherProjects(action, document.getElementById(action+'baseField').value, document.getElementById(action+'sortDirection').value, advanceSearch );
}
else{
document.getElementById(action+'filterOn').value='';
gatherProjects(action, document.getElementById(action+'baseField').value, document.getElementById(action+'sortDirection').value, advanceSearch );
}
}
//END SEARCH
//
//
//
//Searchclear: clears search settings.
function searchClear(action){
document.getElementById(action+'searchTerm').value="";
document.getElementById(action+'searchMe').value="";
document.getElementById(action+'searchFilter').selectedIndex=0;
document.getElementById(action+'page').value=1;
document.getElementById(action+'filterOn').value=0;
document.getElementById(action+'searchClear').disabled=true;
document.getElementById(action+'searchClear').style.display='none';
gatherProjects(action,document.getElementById(action+'baseField').value, document.getElementById(action+'sortDirection').value);
}
//
function getVariationList(project)
{
ajaxGetProjectVariationList(project);
document.getElementById("lbl_baseVariation").innerHTML = project;
var table = document.getElementById("tbl_variationList");
var row;
while(row = table.rows[0]) { table.deleteRow(0); }
}
function hideVariationList() { document.getElementById("alert_listVariations").style.display = "none"; }
function populateVariationList(response)
{
document.getElementById("alert_listVariations").style.display = "";
// console.log(JSON.parse(response));
var table = document.getElementById("tbl_variationList");
var variations = JSON.parse(response);
// if( _sandbox) { if( variations.length == 1 ) { window.location = "/sandbox/sbox_open-quote/?job="+variations[0].job; return; } }
// else { if( variations.length == 1 ) { window.location = "./project/?job="+variations[0].job; return; } }
if( variations.length == 1 )
{
if( variations[1][0] == 'j' || variations[1][0] == 'J') { window.location = "./project/?job="+variations[1].job; return; }
}
for(var i = 0, variation; variation = variations[i]; i++)
{
var row = table.insertRow(-1);
row.style.display = "block";
row.style.width = "100%";
var cell = row.insertCell(0);
cell.innerHTML = ""+variation.job+"";
cell.style.color = "blue";
cell.style.width = "20%";
cell = row.insertCell(1);
cell.innerHTML = variation.variationReason;
cell.style.borderLeft = "1px dashed grey";
cell.style.textAlign = "left"
cell.style.paddingLeft = "0.5em"
cell.style.width = "340px";
cell = row.insertCell(2);
cell.innerHTML = (variation.status == 0 ? "Open" : "Closed" );
cell.style.width = "10%";
}
}
function selectAll( x, select=true )
{ Array.from( x.parentElement.getElementsByTagName( "input" ) ).forEach( L => L.checked = select ); }
//
[insert_php] echo createHeader(“Projects”); [/insert_php]