It would take a year to explain it if you're me, so I'll just say this:
It is used to parse through an existing resultset (an object array) and produce an HTML dropdown of particular customers out of the entire resultset of all customers, however, you need to be able to pick out whether or not you've select A particular JOB out of EACH customer, along with other fields, so the only thing I could figure out what to do is to take that information and stuff it into an associative object array (so that you don't have to re-query the information several hundred times PER customer which could be in the hundreds itself, so you'd be querying several hundred THOUSAND times!) - so I loop through the existing resultset ONE time to produce a SESSION variable consisting of an object array associated by customer ID (as key) and an object (as value) consisting of the required properties to ensure whether or not that customer has ONE job you picked per customer.
That's about as good as I can explain it. Bottom line: I have this session variable that I must be able to immediately retrieve. I set it like this in the function:
$_SESSION["${projectAcronym}_customerSOWObjectArray"] = $customerSOWObjectArray;
And then you leave the function and then you IMMEDIATELY have to get that session variable.
if (!function_exists('generate_admin_customer_position_dropdown')) {
/**
* Generate customer position (statement of work) dropdown per customer for the admin student details page
*
* @access protected
* @param object $result resultset
* @param int $customer_id customer id
* @param boolean $willShowDropdownHeader (default false)
* @param mixed $dropdownHeader (optional)
* @param mixed $noScriptSubmitName (optional) Will default to "view" if no unique name is given
* @return mixed HTML
* @see str_print_repeat
* @uses $_SESSION["${projectAcronym}_customerSOWObjectArray"] - Object associative array with key being customer ID and value of Object properies reflecting student ID,
* qualification match and the "isAllowed" rule: 1) student id in statementofwork_accept_reject_student? 2) student id in customer_student_reviewed_assoc?
* 3) student id in statementofwork_student_qualification_match? 4) valid qualification match in statementofwork_student_qualification_match mapped to student id?
*/
function &generate_admin_customer_position_dropdown($result, $customer_id, $willShowDropdownHeader = false, $dropdownHeader = '', $noScriptSubmitName = '') {
global $projectAcronym, $adminURLPath, $adminPositionDetailsSubmitButtonName;
// YOU MAY ONLY USE THIS FUNCTION FROM WITHIN THE ADMIN PAGES (RESTRICTED)
if (preg_match('/' . str_replace('/', '\\/', preg_quote($adminURLPath)) . '/', $_SERVER['PHP_SELF'])) {
$customerSOWObjectArray = array();
$viewSubmitButtonName = ($noScriptSubmitName) ? $noScriptSubmitName : ($adminPositionDetailsSubmitButtonName ? $adminPositionDetailsSubmitButtonName : 'view');
// NEW 2/25/2006: IMPORTANT TO SAVE THIS SO YOU KNOW WHAT THE PREFIX WILL BE REGARDLESS OF WHICH "button" YOU PRESS
$_SESSION["${projectAcronym}_viewSubmitButtonName"] = $viewSubmitButtonName;
$html = "\n<select name=\"statement_of_work_id[$customer_id]\" onChange=\"showURLPopup('" . $adminURLPath . "/position_details.php?id=', this)\">";
if ($willShowDropdownHeader && $dropdownHeader)
$html .= "\n<option value=\"\">" . str_replace('<', '<', $dropdownHeader) . "</option>\n<option value=\"\">" . str_print_repeat('-', strlen($dropdownHeader)) . '</option>';
for ($i = 0; $i < @sizeof($result); $i++) {
if (!$_SESSION["${projectAcronym}_customerSOWObjectArray"]) {
// GENERATE THE LOCAL OBJECT ARRAY $customerSOWObjectArray ACCORDING TO RULES MENTIONED ABOVE
// YOU MUST ONLY SELECT FROM customer_student_reviewed_assoc SINCE THAT INDICATES CUSTOMER REVIEWABLE STUDENT IRREGARDLESS OF STATEMENT OF WORK
$customerSOWObjectArray[$result[$i]->id]->student_id = $result[$i]->csr_student_id;
if (!$customerSOWObjectArray[$result[$i]->id]->qualification_match) {
$customerSOWObjectArray[$result[$i]->id]->qualification_match = ($_POST['qualification_match'][$_POST['statement_of_work_id'][$result[$i]->id]]) ?
$_POST['qualification_match'][$_POST['statement_of_work_id'][$result[$i]->id]] :
$result[$i]->qualification_match;
} // YOU MUST CHECK TO SEE IF THERE ALREADY IS AN EXISTING qualification_match SINCE THERE CAN ONLY BE ONE, IF NONE FOUND THEN ATTEMPT TO WRITE
if (!$customerSOWObjectArray[$result[$i]->id]->isAllowed) {
$customerSOWObjectArray[$result[$i]->id]->isAllowed = (
(int)$_POST['allowed_customer'][$customer_id] === 1 || (
(int)$result[$i]->sowars_student_id > 0 && $result[$i]->sowars_student_id == $_REQUEST['id'] && $result[$i]->sowars_student_id == $result[$i]->csr_student_id &&
$result[$i]->csr_student_id = $result[$i]->q_student_id && (int)$result[$i]->qualification_match > 0
)
);
} // SAME RULE AS qualification_match
}
//--END OF BLOCK TO INSTANTIATE THE LOCAL OBJECT ARRAY $customerSOWObjectArray------------------------------------------------------------------------------------------------------------------
if ((int)$customer_id > 0 && (int)$result[$i]->id === (int)$customer_id) {
$html .= "\n<option value=\"" . $result[$i]->statement_of_work_id . '"';
if ((int)$result[$i]->statement_of_work_id > 0 && ((int)$_POST['statement_of_work_id'][$customer_id] == $result[$i]->statement_of_work_id ||
((int)$result[$i]->sowars_statement_of_work_id > 0 && $result[$i]->sowars_statement_of_work_id ==
$result[$i]->statement_of_work_id &&
(int)$result[$i]->sowars_student_id > 0 && $result[$i]->sowars_student_id == $_REQUEST['id']
)
)
) {
$html .= ' selected';
}
$html .= '>' . $result[$i]->position_title;
if ($result[$i]->position_expires) $html .= 'Expires: ' . date('n/j/Y', strtotime($result[$i]->position_expires)); // PRINT EXPIRY DATE IF EXISTS
$html .= ' (Positions available: ' . $result[$i]->availability_amount . ')</option>';
}
}
$html .= "\n</select>\n<noscript>\n" .
" <input type=\"submit\" name=\"${viewSubmitButtonName}_$customer_id\" value=\"View Position Description\">\n" .
" <input type=\"hidden\" name=\"customer_id\" value=\"$customer_id\">\n" .
"</noscript>\n";
$_SESSION["${projectAcronym}_customerSOWObjectArray"] = $customerSOWObjectArray; // STUFF ASSOC. OBJECT ARRAY INTO SESSION TO USE LATER
return $html;
}
}
}
Phil