function notify_emails($dbid, $req_id) { if ("{$req_id}" == "") { return ""; } $query = "SELECT email, fullname FROM usr, request_interested "; $query .= "WHERE request_interested.user_no = usr.user_no "; $query .= " AND request_interested.request_id = {$req_id} "; $query .= " AND usr.active "; $query .= "UNION "; $query .= "SELECT email, fullname FROM usr, request_allocated "; $query .= "WHERE request_allocated.allocated_to_id = usr.user_no "; $query .= " AND request_allocated.request_id = {$req_id} "; $query .= " AND usr.active "; $peopleq = awm_pgexec($dbid, $query, "notify-eml"); $to = ""; if ($peopleq) { $rows = pg_NumRows($peopleq); for ($i = 0; $i < $rows; $i++) { $interested = pg_Fetch_Object($peopleq, $i); if ($i > 0) { $to .= ", "; } $to .= "{$interested->fullname} <{$interested->email}>"; } } return $to; }
function get_system_list($access = "", $current = 0, $maxwidth = 50) { global $dbconn; global $session, $roles; $system_id_list = ""; function int_val(&$item) { $item = strval(intval($item)); } if (is_array($current)) { array_walk($current, 'int_val'); } else { $current = intval("{$current}"); } $query = "SELECT work_system.system_id, system_desc "; $query .= "FROM work_system WHERE active "; if ($access != "" && !is_member_of('Admin', 'Support')) { $query .= " AND EXISTS (SELECT system_usr.system_id FROM system_usr WHERE system_usr.system_id=work_system.system_id"; $query .= " AND user_no={$session->user_no} "; $query .= " AND role~*'[{$access}]') "; } if (is_array($current)) { $query .= " OR work_system.system_id IN (" . implode(",", $current) . ") "; } else { if ($current != "") { $query .= " OR work_system.system_id={$current}"; } } $query .= " ORDER BY LOWER(system_desc);"; $rid = awm_pgexec($dbconn, $query); if (!$rid) { return; } if (pg_NumRows($rid) > 0) { // Build table of systems found $rows = pg_NumRows($rid); for ($i = 0; $i < $rows; $i++) { $system_id = pg_Fetch_Object($rid, $i); $system_id_list .= "<option value=\"" . urlencode($system_id->system_id) . "\""; if (is_array($current) && in_array($system_id->system_id, $current, true) || "{$system_id->system_id}" == "{$current}") { $system_id_list .= " SELECTED"; } $system_id->system_desc = substr($system_id->system_desc, 0, $maxwidth); $system_id_list .= ">{$system_id->system_desc}</option>\n"; } } return $system_id_list; }
function get_user_list($roles = "", $org = "", $current) { global $dbconn; global $session; $user_list = ""; $query = "SELECT DISTINCT usr.user_no, usr.fullname, organisation.abbreviation "; $query .= "FROM usr , organisation"; $query .= " WHERE usr.active "; $query .= " AND usr.org_code = organisation.org_code "; if ($roles != "") { $role_array = split(',', $roles); $in_roles = ""; foreach ($role_array as $v) { $in_roles .= $in_roles == "" ? "" : ","; $in_roles .= "'{$v}'"; } $query .= "AND EXISTS (SELECT role_member.user_no FROM role_member JOIN roles USING(role_no) "; $query .= "WHERE role_member.user_no = usr.user_no "; $query .= "AND roles.role_name IN ({$in_roles}) )"; } if ("{$org}" != "") { $query .= " AND usr.org_code='{$org}' "; } $query .= " ORDER BY usr.fullname; "; $rid = awm_pgexec($dbconn, $query, "userlist", false, 7); if (!$rid) { echo "<p>{$query}"; } else { if (pg_NumRows($rid) > 0) { // Build table of users found $rows = pg_NumRows($rid); for ($i = 0; $i < $rows; $i++) { $user = pg_Fetch_Object($rid, $i); $user_list .= "<OPTION VALUE=\"{$user->user_no}\""; if (is_array($current) && in_array($user->user_no, $current, true) || "{$user->user_no}" == "{$current}") { $user_list .= " selected=\"SELECTED\""; } $user->fullname = substr($user->fullname, 0, 25) . " ({$user->abbreviation})"; $user_list .= ">{$user->fullname}"; } } } return $user_list; }
function send_footers() { global $settings, $c, $session, $theme, $dbconn, $total_query_time, $debuglevel; global $REQUEST_URI, $HTTP_USER_AGENT, $HTTP_REFERER, $PHP_SELF; $theme->EndContentArea(); if ($theme->panel_right) { $theme->RightPanel(); } $theme->EndPanels(); if ($theme->panel_bottom) { $theme->PageFooter(); } echo <<<CLOSEHTML <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div> <script language="JavaScript" src="js/overlib.js"></script> </body> </html> CLOSEHTML; if (is_object($settings) && $settings->is_modified()) { if (!is_numeric($settings->get('counter'))) { $settings->set('counter', 0); } else { $settings->set('counter', $settings->get('counter') + 1); } $config_data_string = qpg($settings->to_save()); $query = "UPDATE session SET session_config={$config_data_string} "; $query .= "WHERE session_id={$session->session_id} "; $query .= "AND session_config != {$config_data_string}; "; if ($session->user_no > 0) { $query .= "UPDATE usr SET config_data={$config_data_string} WHERE user_no={$session->user_no} "; $query .= "AND config_data != {$config_data_string}; "; } $result = awm_pgexec($dbconn, $query); } error_reporting(7); if ($debuglevel > 0) { $total_query_time = sprintf("%3.06lf", $total_query_time); error_log($c->sysabbr . " total_query_ TQ: {$total_query_time} URI: {$REQUEST_URI}", 0); $total_time = sprintf("%3.06lf", duration($c->started, microtime())); error_log($c->sysabbr . " process_time TT: {$total_time} Agent: {$HTTP_USER_AGENT} Referrer: {$HTTP_REFERER} ", 0); error_log("=============================================== Endof {$PHP_SELF}"); } }
function get_code_list($table, $field, $current = "", $misc = "", $tag = "option", $varname = "") { global $dbconn; $query = "SELECT * FROM lookup_code WHERE source_table = '{$table}' AND source_field = '{$field}' ORDER BY source_table, source_field, lookup_seq, lookup_code"; $rid = awm_pgexec($dbconn, $query, "codelist", false); $rows = pg_NumRows($rid); $lookup_code_list = ""; if ($tag != "option") { $prestuff = "input type="; $selected = " checked"; } else { $prestuff = ""; $selected = " selected"; } for ($i = 0; $i < $rows; $i++) { $lookup_code = pg_Fetch_Object($rid, $i); $lookup_code_list .= "<{$prestuff}{$tag} value=\"{$lookup_code->lookup_code}\""; if ("{$varname}" != "") { $lookup_code_list .= " name={$varname}"; } if ("{$lookup_code->lookup_code}" == "{$current}") { $lookup_code_list .= $selected; } $lookup_code_list .= ">"; $lookup_code_list .= "{$lookup_code->lookup_desc}"; if ("{$misc}" != "" && "{$lookup_code->lookup_misc}" != "") { $lookup_code_list .= " - {$lookup_code->lookup_misc}"; } if ("{$tag}" == "option") { $lookup_code_list .= "</{$tag}>"; } else { $lookup_code_list .= " \n"; } } return $lookup_code_list; }
$query .= " AND request_timesheet.work_on::date <= '{$to_date}'::date "; } if ("{$uncharged}" != "") { $numcols++; // No charged on column if ("{$charge}" != "") { $query .= " AND request_timesheet.ok_to_charge=TRUE "; } $query .= " AND request_timesheet.work_charged IS NULL "; } $query .= " ORDER BY {$tlsort} {$tlseq} "; if (!isset($maxresults) || intval($maxresults) == 0) { $maxresults = 1000; } $query .= " LIMIT {$maxresults} "; $result = awm_pgexec($dbconn, $query, 'timelist', FALSE, 7); if ($result) { // Build up the column header cell, with %s gaps for the sort, sequence and sequence image $header_cell = "<th class=cols><a class=cols href=\"{$PHP_SELF}?f={$form}&tlsort=%s&tlseq=%s"; if (isset($org_code) && $org_code > 0) { $header_cell .= "&org_code={$org_code}"; } if (isset($system_id) && $system_id > 0) { $header_cell .= "&system_id={$system_id}"; } if (isset($search_for)) { $header_cell .= "&search_for={$search_for}"; } if (isset($inactive)) { $header_cell .= "&inactive={$inactive}"; }
<?php if (!is_member_of('Admin', 'Support')) { $session_id = $session->session_id; } if ("{$search_for} " != "") { $query = "SELECT *, (session_end - session_start)::interval AS duration FROM usr, session "; $query .= "WHERE usr.user_no = session.user_no "; if ("{$search_for}" != "") { $query .= " AND session_start <= '{$search_for}' "; } if ("{$user_no}" != "") { $query .= " AND session.user_no = '{$user_no}' "; } $query .= " ORDER BY session.session_start DESC"; $query .= " LIMIT 30 "; $result = awm_pgexec($dbconn, $query); if (!$result) { $error_loc = "sessionlist-form.php"; $error_qry = "{$query}"; include "error.php"; } else { echo "<p>" . pg_NumRows($result) . " sessions found</p>"; echo "<table border=\"0\" align=center><tr>\n"; echo "<th class=cols>Session #</th><th class=cols>Name</th>"; echo "<th class=cols align=left>Start</th>"; echo "<th class=cols align=left>Duration</th>"; echo "</tr>"; // Build table of sessions found for ($i = 0; $i < pg_NumRows($result); $i++) { $thissession = pg_Fetch_Object($result, $i); if ($i % 2 == 0) {
echo "<th class=cols>Type</th>"; echo "<th class=cols>Ranking</th>"; echo "</tr>"; for ($i = 0; $i < pg_NumRows($result); $i++) { $thisrequest = pg_Fetch_Object($result, $i); printf("<tr class=row%1d>", $i % 2); echo "<td class=sml><a href=\"request.php?request_id={$thisrequest->request_id}\">{$thisrequest->request_id}</a></td>"; echo "<td class=sml>{$thisrequest->brief}</td>"; echo "<td class=sml>{$thisrequest->importance}</td>"; echo "<td class=sml>{$thisrequest->urgency}</td>"; echo "<td class=sml>{$thisrequest->by_date}</td>"; echo "<td class=sml>" . str_replace(' ', ' ', $thisrequest->status) . "</td>"; echo "<td class=sml>"; // Display request quote info. $quotes_query = "SELECT quote_id, quoted_on::DATE AS quoted_date, quote_type, quote_amount, quote_units, " . "approved_on::DATE AS approved_date, quote_brief, quoted_by, username " . "FROM request_quote " . "LEFT OUTER JOIN usr ON usr.user_no = request_quote.approved_by_id " . "WHERE request_quote.request_id = {$thisrequest->request_id}"; $quotes_result = awm_pgexec($dbconn, $quotes_query, "requestrank", false, 7); for ($ii = 0; $ii < pg_NumRows($quotes_result); $ii++) { $quote_result = pg_Fetch_Object($quotes_result, $ii); echo "<INPUT TYPE=checkbox NAME=q_{$quote_result->quote_id} CHECKED " . "title='Quoted by {$quote_result->quoted_by} on {$quote_result->quoted_date}: {$quote_result->quote_amount}" . " {$quote_result->quote_units}'>"; if ($quote_result->approved_date != "") { echo " <INPUT TYPE=checkbox NAME=a_{$quote_result->quote_id} CHECKED " . "title='Approved by {$quote_result->username} on {$quote_result->approved_date}'>"; } echo "<BR>"; } echo "</td>"; echo "<td class=sml>" . str_replace(' ', ' ', $thisrequest->type) . "</td>"; echo "<td class=sml>{$thisrequest->ranking}</td>"; echo "</tr>\n"; } echo "</table>"; /* if ( intval("$user_no") > 0 )
if ("{$search_for}" != "") { $query .= " AND (org_code ~* '{$search_for}' "; $query .= " OR org_name ~* '{$search_for}' ) "; } if ("{$system_id}{$org_code}" != "") { $query .= " AND org_system.org_code = organisation.org_code "; } if ("{$system_id}" != "") { $query .= " AND org_system.system_id=" . intval($system_id); } if ("{$org_code}" != "") { $query .= " AND org_system.org_code =" . intval($org_code); } $query .= " ORDER BY LOWER(organisation.org_name) "; $query .= " LIMIT 500 "; $result = awm_pgexec($dbconn, $query, "orglist-form", false, 7); if (!$result) { $error_loc = "orglist-form.php"; $error_qry = "{$query}"; include "error.php"; } else { echo "<p><small>" . pg_NumRows($result) . " organisations found</small></p>"; echo "<table border=\"0\" align=center width=100%><tr>\n"; echo "<th class=cols align=left>Abbrev.</th>\n"; echo "<th class=cols align=left>Full Name</th>"; if (is_member_of('Admin', 'Support')) { echo "<th class=cols>Debtor #</th>"; } echo "<th class=cols align=center>Actions</th></tr>"; // Build table of organisations found for ($i = 0; $i < pg_NumRows($result); $i++) {
return; } $query = "SELECT s.system_id, lower(s.system_desc) AS lcname, s.system_desc, "; $query .= "to_char( max(r.request_on), 'D Mon YYYY') AS last_request_date, "; $query .= "count(r.request_id) AS active_sys_requests "; $query .= "FROM work_system s "; $query .= "JOIN system_usr su ON s.system_id = su.system_id "; $query .= "JOIN request r ON r.system_id = su.system_id "; $query .= "WHERE su.user_no = {$session->user_no} AND s.active AND r.active "; $query .= "AND su.role IN ( 'A', 'S', 'C', 'E', 'O', 'V' ) "; $query .= "AND (r.last_activity > (current_timestamp - '30 days'::interval) "; $query .= " OR r.last_status NOT IN ( 'F', 'C' ) ) "; $query .= "GROUP BY lower(s.system_desc), s.system_id, s.system_desc "; $query .= "HAVING COUNT(r.request_id) > 0 "; $query .= "ORDER BY lower(s.system_desc) "; $result = awm_pgexec($dbconn, $query, "indexsupport", false, 5); if ($result && pg_NumRows($result)) { echo "<table border=\"0\" align=center width=100%><tr>\n"; echo "<th class=cols align=left>Organisation Name</th>"; echo "<th class=cols align=center>Requests</th>"; echo "<th class=cols align=center>Last Request</th>"; echo "<th class=cols align=center>Show:</th></tr>"; // Build table of organisations found for ($i = 0; $i < pg_NumRows($result); $i++) { $this_system = pg_Fetch_Object($result, $i); printf("<tr class=row%1d>", $i % 2); echo "<td class=sml> <a href=\"requestlist.php?system_id={$this_system->system_id}\">{$this_system->system_desc}"; if ("{$this_system->system_desc}" == "") { echo "-- no description --"; } echo "</a> </td>\n";
$sql .= " OR username ~* {$search_for} "; $sql .= " OR email ~* {$search_for} )"; } if (is_member_of('Manage') && !is_member_of('Admin', 'Support')) { $sql .= " AND usr.org_code='{$session->org_code}' "; } else { if (isset($org_code) && $org_code > 0) { $sql .= " AND usr.org_code={$org_code}"; } } if (isset($system_id) && $system_id > 0) { $sql .= " AND system_usr.system_id={$system_id}"; } $sql .= " ORDER BY LOWER(fullname);"; $qry = new PgQuery($sql); $result = awm_pgexec($dbconn, $sql, 'usrsearch'); if ($qry->Exec("UsrSearch")) { // Build table of usrs found echo "<p> " . $qry->rows . " users found</p>"; echo "<table border=\"0\" cellpadding=2 cellspacing=1 align=center width=100%>\n<tr>\n"; echo "<th class=cols>User ID</th><th class=cols>Full Name</th>\n"; if (!isset($org_code) || $org_code == 0) { echo "<th class=cols>Organisation</th>\n"; } echo "<th class=cols>Email</th>\n"; if (isset($system_id) && $system_id > 0) { echo "<th class=cols>User Role</th>\n"; } echo "<th class=cols>Accessed</th>\n"; echo "<th class=cols>Actions</th>\n"; echo "</tr>\n";
$rid = awm_pgexec($dbconn, $query, "req-roles1"); if (!$rid) { $error_loc = "get-request-roles.php"; $error_qry = "{$query}"; include "error.php"; } if ($rid && pg_NumRows($rid) > 0) { $allocated_to = TRUE; } /* Is the person client or support manager for this (or any?) system? */ $query = "SELECT * FROM system_usr WHERE system_usr.user_no={$session->user_no}"; $query .= " AND system_usr.role ~ '[CS]' "; if ($is_request) { $query .= " AND system_usr.system_id = '{$request->system_id}' "; } $rid = awm_pgexec($dbconn, $query, "req-roles2"); if (!$rid) { $error_loc = "get-request-roles.php"; $error_qry = "{$query}"; include "error.php"; } if ($rid && pg_NumRows($rid) > 0) { $sysman_role = pg_fetch_object($rid, 0); if (eregi('S', $sysman_role->role)) { $sysmgr = TRUE; } else { $cltmgr = TRUE; } } // Also set $sysmgr if the person is Admin... if (is_member_of('Admin')) {
$query .= ", importance.lookup_desc AS importance_desc"; $query .= ", system_desc, request_sla_code(sla_response_time,sla_response_type) "; $query .= " FROM request LEFT OUTER JOIN usr ON (request.requester_id = usr.user_no)"; $query .= " LEFT OUTER JOIN organisation USING( org_code )"; $query .= " LEFT OUTER JOIN lookup_code AS status ON status.source_table='request' AND status.source_field='status_code' AND status.lookup_code = request.last_status"; $query .= " LEFT OUTER JOIN lookup_code AS request_type ON request_type.source_table='request' AND request_type.source_field='request_type' AND request.request_type = request_type.lookup_code"; $query .= " LEFT OUTER JOIN lookup_code AS urgency ON urgency.source_table='request' AND urgency.source_field='urgency' AND int4(urgency.lookup_code)=request.urgency"; $query .= " LEFT OUTER JOIN lookup_code AS sla_response ON sla_response.source_table='request' AND sla_response.source_field='sla_response' AND sla_response.lookup_code=request_sla_code(sla_response_time,sla_response_type)"; $query .= " LEFT OUTER JOIN lookup_code AS importance ON importance.source_table='request' AND importance.source_field='importance' AND int4(importance.lookup_code)=request.importance"; $query .= " LEFT OUTER JOIN work_system USING( system_id )"; $query .= " WHERE request.request_id = '{$request_id}'"; if (!$session->AllowedTo('see_other_orgs')) { $query .= " AND organisation.org_code = '{$session->org_code}' "; } /* now actually query the database... */ $rid = awm_pgexec($dbconn, $query, "getrequest", false, 7); if (!$rid) { $error_loc = "request-form.php"; $error_qry = "{$query}"; include "error.php"; } $rows = pg_NumRows($rid); if (!$rows) { echo "<p>No records for request: {$request_id}</p>"; if (is_member_of('Admin', 'Support')) { echo "<p>There is probably a bug in the following query:</p>"; echo "<p>{$query}</p>"; } exit; /* Make sure that code below does not get executed when we redirect. */ }
$where .= " AND rt.work_on >= '{$from_date}' "; } if ("{$to_date}" != "") { $where .= " AND rt.work_on <= '{$to_date}' "; } if (isset($where)) { $query .= " WHERE " . substr($where, 4); } // Build ORDER BY clause foreach ($columns as $column) { $by[] = $select_columns[$column]; } $query .= " ORDER BY " . implode(",", $by) . "\n"; // echo "<pre>$query"; // Execute query $result = awm_pgexec($dbconn, $query, "plan", false, 7); // Create xml doc to put query data into. $doc = domxml_new_doc("1.0"); $xtable = $doc->add_root("table"); $xtable->set_attribute("style", "empty-cells: show; border-collapse: collapse; border: 1px solid {$colors['row1']} ;"); $xtable->set_attribute("border", "1"); // Create column headers for selected fields. $xthead = $xtable->new_child("thead", ""); $xthr = $xthead->new_child("tr", ""); $clone_tr = $doc->create_element("tr"); foreach ($columns as $column) { $xth = $xthr->new_child("th", $column); $xth->set_attribute("class", "cols"); $clone_td = $doc->create_element("td"); $clone_td = $clone_tr->append_child($clone_td); $clone_td->set_attribute("class", "sml");
} if ($can_edit) { echo "<p><br> <br> <br>"; } } else { $words = split("[^a-zA-Z0-9]+", strtolower($nodename), 4); $query = ""; while (list($k, $v) = each($words)) { if ($query != "") { $query .= "UNION "; } $query .= "SELECT * FROM infonode WHERE LOWER(nodename) ~ '{$v}' "; } $query .= "LIMIT 100;"; echo "<p>I can't find an exact match for \"{$nodename}\" but perhaps one of these is the answer you need:"; $rid = awm_pgexec($dbconn, $query, "wu-form"); if ($rid && pg_NumRows($rid) > 0) { echo "<ul>"; for ($i = 0; $i < pg_NumRows($rid); $i++) { $node = pg_Fetch_Object($rid, $i); echo "<li><a href=\"/wu.php?node_id={$node->node_id}&last={$last}\">{$node->nodename}</a></li>\n"; } echo "</ul></p>"; if ($can_edit) { echo "<p><br> <br><p>Alternatively, if none of these fits the bill, enter your new editorial directly in the space below:"; } } } if ($can_edit) { if (isset($my_wu)) { $submitlabel = "Update Editorial";
} else { $query .= "WHERE active "; } if ("{$search_for}" != "") { $query .= "AND (system_code ~* '{$search_for}' "; $query .= " OR system_desc ~* '{$search_for}' ) "; } if (isset($org_code) && $org_code > 0) { $query .= "AND work_system.system_id=org_system.system_id "; $query .= "AND org_system.org_code='{$org_code}' "; } else { $query .= "AND NOT organisation_specific "; } $query .= " ORDER BY lower(work_system.system_desc) "; $query .= " LIMIT {$maxresults} "; $result = awm_pgexec($dbconn, $query, "syslist", false, 7); if (!$result) { $error_loc = "syslist-form.php"; $error_qry = "{$query}"; include "error.php"; } else { if ($result && pg_NumRows($result) > 0) { echo "\n<small>"; echo pg_NumRows($result) . " systems found"; if (pg_NumRows($result) == $maxresults) { echo " (limit reached)"; } if (isset($saved_query) && $saved_query != "") { echo " for <b>{$saved_query}</b>"; } echo "</small>";
<?php if ($logged_on) { $user_no = $session->user_no; } else { $user_no = 0; } $query = "SELECT help_hit({$user_no}, '" . tidy($topic) . "');"; awm_pgexec($dbconn, $query, "help", true, 5); $query = "SELECT * FROM help WHERE topic = '" . tidy($topic) . "' "; if (isset($seq) && $action == "edit") { $query .= "AND seq = " . intval($seq) . " "; } $query .= "ORDER BY topic, seq;"; $rid = awm_pgexec($dbconn, $query, "help"); if (!$rid) { echo "<h1>Help about {$topic}</h1>"; echo "<h2 style=\"font-family: comic sans ms, verdana, fantasy; font-size: 200px; line-height: 80px; padding-top: 70px; font-weight: 700; text-align: center\">HELP!!!</h2>\n"; } else { $rows = pg_NumRows($rid); if (0 == $rows || $action == "add" || $action == "edit" && $rows == 1) { // No rows! Maybe they want to add it? if ("edit" == "{$action}") { $submitlabel = "Update Help"; $help = pg_Fetch_Object($rid, 0); } else { if ("add" == "{$action}") { $submitlabel = "Add New Help"; echo "<h1>Help about {$topic}</h1>"; if ($rows > 0) { echo "<p>Existing help on this topic includes:</p>";
printf("<tr class=\"row%1d\" valign=\"top\">\n", $i % 2); echo "<td>{$thisnote->nice_date}</td>\n"; echo "<td>{$thisnote->fullname}</td>\n"; echo "<td colspan=\"5\">" . html_format($thisnote->note_detail) . "</td>\n"; echo "</tr>\n"; } } if ($show_work) { $subquery = "SELECT *, to_char( work_on, 'DD/MM/YYYY') AS nice_date "; $subquery .= "FROM request_timesheet, usr "; $subquery .= "WHERE request_id = {$thisrequest->request_id} "; $subquery .= "AND usr.user_no = request_timesheet.work_by_id "; $subquery .= "ORDER BY request_id, work_on "; $total = 0.0; $qty_total = 0.0; $subres = awm_pgexec($dbconn, $subquery, "requestlist"); for ($j = 0; $subres && $j < pg_NumRows($subres); $j++) { $thiswork = pg_Fetch_Object($subres, $j); printf("<tr class=row%1d valign=top>\n", $i % 2); echo "<td>{$thiswork->nice_date}</td>\n"; echo "<td>{$thiswork->fullname}</td>\n"; echo "<td colspan=\"2\">{$thiswork->work_description}</td>\n"; printf("<td align=\"right\">%9.2f </td>\n", $thiswork->work_quantity); printf("<td align=\"right\">%9.2f </td>\n", $thiswork->work_rate); $value = $thiswork->work_quantity * $thiswork->work_rate; $total += $value; $qty_total += $thiswork->work_quantity; printf("<td align=\"right\">%9.2f </td>\n", $value); echo "</tr>\n"; } if ($j > 0) {
<table border="0" cellspacing="0" cellpadding="1"> <?php $query = "SELECT lookup_code, lookup_desc FROM lookup_code "; $query .= " WHERE source_table='codes' AND source_field='menus' "; $query .= " ORDER BY lookup_seq;"; $result = awm_pgexec($dbconn, $query, "lookhead"); if ($result && pg_NumRows($result) > 0) { echo "<tr><td>\n"; for ($i = 0; $i < pg_NumRows($result); $i++) { $codes = pg_Fetch_Object($result, $i); list($s_table, $s_field) = explode("|", "{$codes->lookup_code}"); if ($agent == "moz4" && $i > 0) { echo " | "; } printf("<a class=submit href=\"lookups.php?table={$s_table}&field={$s_field}\">%s{$codes->lookup_desc}%s</a>\n", "{$table}{$field}" == "{$s_table}{$s_field}" ? "<b>*" : "", "{$table}{$field}" == "{$s_table}{$s_field}" ? "*</b>" : ""); } echo "</td></tr>\n"; } ?> </table>
echo ">{$select_option->abbreviation}</option>\n"; } echo "</select>\n"; echo "</th>\n"; echo '<th class=cols>Dbtr. No.'; echo '<input type="Image" src="$theme->images/down.gif" title="Sort" border="0" name="sort[organisation.org_code]" >'; echo "</th>\n"; echo '<th class=cols>WR No.<input TYPE="Image" src="/' . $theme->images . '/down.gif" alt="Sort" BORDER="0" name="sort[request_timesheet.request_id]" ></th>' . "\n"; echo "<th class=cols>WR Status"; echo '<select class=sml name="filter[request.last_status]">' . "\n"; echo "<option class=sml value=''>All</option>\n"; $select_query = "SELECT lookup_code, lookup_desc FROM lookup_code"; $select_query .= " WHERE lookup_code.source_table = 'request' "; $select_query .= " AND lookup_code.source_field = 'status_code' "; $select_query .= " ORDER BY lookup_code.lookup_desc"; $select_result = awm_pgexec($dbconn, $select_query); for ($i = 0; $i < pg_NumRows($select_result); $i++) { $select_option = pg_Fetch_Object($select_result, $i); echo "<option class=sml value=\"'{$select_option->lookup_code}'\""; if ("'" . $select_option->lookup_code . "'" == $filter["request.last_status"]) { echo ' selected'; } echo ">{$select_option->lookup_desc}</option>\n"; } echo "</select>\n"; echo "</th>\n"; echo "<th class=cols>Status On</th>\n"; echo "<th class=cols>WR Brief</th>\n"; echo '<th class=cols>'; echo '<table cellpadding=2 cellspacing=0 border=0>'; echo '<tr>';
} $query = substr($query, 2); $query = "UPDATE wu SET {$query} WHERE node_id = {$node_id} AND wu_by = {$session->user_no}; "; } else { $fields = ""; $values = ""; if (!isset($node_id) || $node_id == 0) { $query = "SELECT nextval('infonode_node_id_seq');"; $rid = awm_pgexec($dbconn, $query, "wu-action", false); if ($rid) { $node_id = pg_Result($rid, 0, 0); $query = "INSERT INTO infonode (node_id, nodename, created_by) "; $query .= "VALUES( {$node_id}, '" . tidy($nodename) . "', {$session->user_no} );"; $rid = awm_pgexec($dbconn, $query, "wu-action", false); } } $new['node_id'] = $node_id; $new['wu_by'] = $session->user_no; reset($new); foreach ($new as $key => $value) { $fields .= ", {$key}"; $values .= ", '" . tidy($value) . "' "; } $fields = substr($fields, 2); $values = substr($values, 2); $query = "INSERT INTO wu ({$fields}) VALUES({$values}); "; } $rid = awm_pgexec($dbconn, $query, "wu-action", false); $rid = awm_pgexec($dbconn, "COMMIT", "wu-action", true); $because .= "<H2>Writeup Details Changed</H2>"; $seq = intval($new['seq']);
} else { if ("{$invoiced}" == "uninvoiced") { $lw_query .= " AND (rt.charged_details IS null OR rt.charged_details = '')"; } } if ("{$from_date}" != "") { $lw_query .= " AND rt.work_on >= '{$from_date}' "; } if ("{$to_date}" != "") { $lw_query .= " AND rt.work_on <= '{$to_date}' "; } $lw_query .= " LEFT OUTER JOIN request r ON r.request_id = rr.to_request_id "; $lw_query .= " LEFT OUTER JOIN lookup_code lc ON lc.source_table = 'request' AND lc.source_field = 'status_code' AND lc.lookup_code = r.last_status"; $lw_query .= " WHERE rr.request_id = " . $row["id"]; $lw_query .= " GROUP BY rr.to_request_id, rr.link_type, rt.work_units, lc.lookup_desc, rt.charged_details"; $lw_result = awm_pgexec($dbconn, $lw_query, "billing.linkedwork", false, 7); $numrows_lw_result = pg_numrows($lw_result); $prev_id = $row["id"]; } $max_res = max($numrows_w_result, $numrows_lw_result); // echo " id: " . $row["id"] ." " . $max_res . " " . $row["inv no"] . " " . $numrows_w_result . " " . $numrows_lw_result . " " ; // If looking for invoiced only, and there are no invoice numbers for work done, or any quote, then skip it. if ($max_res == 0 && "{$invoiced}" == "invoiced" && $row["inv no"] == "") { continue; } // looking for un-invoiced stuff. if ("{$invoiced}" == "uninvoiced") { // If there is a 'Q' type quote with an invoice no, and no un-invoiced work then skip it. if ($row["quote type"] == "Q" && $row["inv no"] != "" && $numrows_w_result == 0) { continue; }
} else { if (isset($from_date)) { $query .= " AND request_timesheet.work_on::date >= '{$from_date}'::date"; } if (isset($to_date)) { $query .= " AND request_timesheet.work_on::date <= '{$to_date}'::date"; } } } $query .= " ORDER BY {$tlsort} {$tlseq} "; if (!isset($maxresults) || intval($maxresults) == 0) { $maxresults = 1000; } $query .= " LIMIT 1000 "; $qry = new PgQuery($query); $result = awm_pgexec($dbconn, $query, 'simpletimelist', false, 7); if ($qry->Exec('simpletimelist')) { // Build up the column header cell, with %s gaps for the sort, sequence and sequence image $header_cell = "<th class=cols><a class=cols href=\"{$PHP_SELF}?f={$form}&tlsort=%s&tlseq=%s"; if (isset($user_no)) { $header_cell .= "&user_no={$user_no}"; } if (isset($from_date)) { $header_cell .= "&from_date={$from_date}"; } if (isset($to_date)) { $header_cell .= "&to_date={$to_date}"; } if (isset($date_restriction)) { $header_cell .= "&date_restriction={$date_restriction}"; }
$invoice = $chg_inv[$k]; $query .= "UPDATE request_timesheet SET"; if ($amount != 0 || eregi("^w((/o)|(rite))", $invoice)) { $query .= " work_charged='{$v}',"; $query .= " charged_by_id={$session->user_no},"; $query .= " charged_details='{$invoice}', "; $query .= " charged_amount={$amount}, "; $because .= "<tr>\n<td align=center>{$k}</td>\n"; $because .= "<td>{$v}</td>\n"; $because .= "<td align=center>{$invoice}</td>\n"; $because .= "<td align=right>" . sprintf("%.2f", $amount) . " </td>\n"; $because .= "</tr>\n"; } $query .= " ok_to_charge={$charge_ok} "; $query .= " WHERE timesheet_id={$k};\n"; } $because .= "</TABLE>\n"; $rid = awm_pgexec($dbconn, $query); $msg = "<HEAD>\n<TITLE>Timesheets Charged</TITLE>\n</HEAD>\n"; $msg .= "<BODY BGCOLOR=#E7FFE7>\n"; $msg .= "<H2>Timesheets Charged by {$session->fullname}</H2>{$because}\n</BODY>\n</HTML>"; $msg = "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\"><HTML>{$msg}"; $headers = "Content-Type: text/html; charset=us-ascii"; if (strpos("{$session->email}", "@")) { $headers .= "\nFrom: {$session->email}"; } mail("*****@*****.**", "Timesheets Charged", $msg, $headers); } ?>