function get_parent_taskIDs($taskID) { $q = prepare("SELECT taskID,taskName,parentTaskID \n FROM task \n WHERE taskID = %d \n AND (taskID != parentTaskID OR parentTaskID IS NULL)", $taskID); $db = new db_alloc(); $db->query($q); while ($db->next_record()) { $rtn[$db->f("taskName")] = $db->f("taskID"); $arr = get_parent_taskIDs($db->f("parentTaskID")); if (is_array($arr)) { $rtn = array_merge($rtn, $arr); } } return $rtn; }
function show_reminder_filter($template) { $current_user =& singleton("current_user"); global $TPL; if ($current_user->have_role("admin") || $current_user->have_role("manage")) { $TPL["reminderActiveOptions"] = page::select_options(array("1" => "Active", "0" => "Inactive"), $_REQUEST["filter_reminderActive"]); $db = new db_alloc(); $db->query("SELECT username,personID FROM person WHERE personActive = 1 ORDER BY username"); while ($db->next_record()) { $recipientOptions[$db->f("personID")] = $db->f("username"); } $TPL["recipientOptions"] = page::select_options($recipientOptions, $_REQUEST["filter_recipient"]); include_template($template); } }
function set_value_role($roleHandle) { $db = new db_alloc(); $db->query(prepare("SELECT * FROM role WHERE roleHandle = '%s' AND roleLevel = 'project'", $roleHandle)); $db->next_record(); $this->set_value("roleID", $db->f("roleID")); }
function find_by_partial_name($name = false, $projectID = false) { $stack1 = array(); $people = array(); $db = new db_alloc(); if ($projectID) { $db->query("SELECT clientID FROM project WHERE projectID = %d", $projectID); $row = $db->qr(); if ($row["clientID"]) { $extra = prepare("AND clientID = %d", $row["clientID"]); } } $q = prepare("SELECT clientContactID, clientContactName\n FROM clientContact\n WHERE 1=1\n AND clientContactName like '%s%%'" . $extra, $name); $db->query($q); while ($row = $db->row()) { $people[$db->f("clientContactID")] = $row; } foreach ($people as $personID => $row) { similar_text(strtolower($row["clientContactName"]), strtolower($name), $percent1); $stack1[$personID] = $percent1; } asort($stack1); end($stack1); $probable1_clientContactID = key($stack1); $person_percent1 = current($stack1); if ($probable1_clientContactID) { return $probable1_clientContactID; } }
public static function get_config_item_id($name = '') { $db = new db_alloc(); $db->query(prepare("SELECT configID FROM config WHERE name = '%s'", $name)); $db->next_record(); return $db->f('configID'); }
function show_items($template_name) { global $TPL; global $db; global $db2; $current_user =& singleton("current_user"); $today = date("Y") . "-" . date("m") . "-" . date("d"); $dbUsername = new db_alloc(); $db = new db_alloc(); $db2 = new db_alloc(); $db->query("select * from item order by itemName"); while ($db->next_record()) { $i++; $item = new item(); $item->read_db_record($db); $db2->query("select * from loan where itemID=" . $item->get_id() . " and dateReturned='0000-00-00'"); $db2->next_record(); $loan = new loan(); $loan->read_db_record($db2); $item->set_values(); // you need to have this repeated here for the a href bit below. if ($loan->get_value("dateReturned") == "0000-00-00") { if ($loan->have_perm(PERM_READ_WRITE)) { // if item is overdue if ($loan->get_value("dateToBeReturned") < $today) { $ret = "Return Now!"; } else { $ret = "Return"; } $TPL["itemAction"] = "<td><a href=\"" . $TPL["url_alloc_item"] . "itemID=" . $TPL["itemID"] . "&return=true\">{$ret}</a></td>"; } else { // if you don't have permission to borrow or return item. $TPL["itemAction"] = "<td> </td>"; } $TPL["status"] = "Due " . $loan->get_value("dateToBeReturned"); $dbUsername->query("select username from person where personID=" . $loan->get_value("personID")); $dbUsername->next_record(); $TPL["person"] = "from " . $dbUsername->f("username"); } else { // if the item is available $TPL["status"] = "Available"; $TPL["person"] = ""; $TPL["itemAction"] = "<td><a href=\"" . $TPL["url_alloc_item"] . "itemID=" . $TPL["itemID"] . "&borrow=true\">Borrow</a></td>"; $TPL["dueBack"] = ""; } $loan->set_values(); $item->set_values(); include_template($template_name); } }
function get_recipient_options() { $current_user =& singleton("current_user"); $recipients = $this->get_recipients(); $type = $this->get_value('reminderType'); $selected = array(); $db = new db_alloc(); $query = "SELECT * from reminderRecipient WHERE reminderID = %d"; $db->query($query, $this->get_id()); while ($db->next_record()) { if ($db->f('metaPersonID')) { $selected[] = $db->f('metaPersonID'); } else { $selected[] = $db->f('personID'); } } if (!$selected && $_GET["personID"]) { $selected[] = $_GET["personID"]; } if (!$this->get_id()) { $selected[] = $current_user->get_id(); } return array($recipients, $selected); }
<?php // UPDATE invoice.invoiceStatus from the invoiceItem.status field $db2 = new db_alloc(); $q = prepare("SELECT invoiceID FROM invoiceItem WHERE status = 'paid'"); $db = new db_alloc(); $db->query($q); while ($db->next_record()) { $q = prepare("UPDATE invoice SET invoiceStatus = 'finished' WHERE invoiceID = %d", $db->f("invoiceID")); $db2->query($q); } $q = prepare("SELECT invoiceID FROM invoiceItem WHERE status = 'allocated'"); $db = new db_alloc(); $db->query($q); while ($db->next_record()) { $q = prepare("UPDATE invoice SET invoiceStatus = 'allocate' WHERE invoiceID = %d", $db->f("invoiceID")); $db2->query($q); } $q = prepare("SELECT invoiceID FROM invoiceItem WHERE status = 'pending'"); $db = new db_alloc(); $db->query($q); while ($db->next_record()) { $q = prepare("UPDATE invoice SET invoiceStatus = 'edit' WHERE invoiceID = %d", $db->f("invoiceID")); $db2->query($q); }
function check_optional_has_line_items() { global $expenseForm; if (is_object($expenseForm) && $expenseForm->get_id()) { $db = new db_alloc(); $q = prepare("SELECT COUNT(*) as tally FROM transaction WHERE expenseFormID = %d", $expenseForm->get_id()); $db->query($q); $db->next_record(); return $db->f("tally"); } }
function create_transaction($amount, $tfID, $status) { $transaction = new transaction(); $invoice = $this->get_foreign_object("invoice"); $this->currency = $invoice->get_value("currencyTypeID"); $db = new db_alloc(); // If there already a transaction for this invoiceItem, use it instead of creating a new one $q = prepare("SELECT * FROM transaction WHERE invoiceItemID = %d ORDER BY transactionCreatedTime DESC LIMIT 1", $this->get_id()); $db->query($q); if ($db->row()) { $transaction->set_id($db->f("transactionID")); $transaction->select(); } // If there already a transaction for this timeSheet, use it instead of creating a new one if ($this->get_value("timeSheetID")) { $q = prepare("SELECT * \n FROM transaction \n WHERE timeSheetID = %d \n AND fromTfID = %d\n AND tfID = %d\n AND amount = %d\n AND (invoiceItemID = %d or invoiceItemID IS NULL)\n ORDER BY transactionCreatedTime DESC LIMIT 1\n ", $this->get_value("timeSheetID"), config::get_config_item("inTfID"), $tfID, page::money($this->currency, $amount, "%mi"), $this->get_id()); $db->query($q); if ($db->row()) { $transaction->set_id($db->f("transactionID")); $transaction->select(); } } $transaction->set_value("amount", $amount); $transaction->set_value("currencyTypeID", $this->currency); $transaction->set_value("fromTfID", config::get_config_item("inTfID")); $transaction->set_value("tfID", $tfID); $transaction->set_value("status", $status); $transaction->set_value("invoiceID", $this->get_value("invoiceID")); $transaction->set_value("invoiceItemID", $this->get_id()); $transaction->set_value("transactionDate", $this->get_value("iiDate")); $transaction->set_value("transactionType", "invoice"); $transaction->set_value("product", sprintf("%s", $this->get_value("iiMemo"))); $this->get_value("timeSheetID") && $transaction->set_value("timeSheetID", $this->get_value("timeSheetID")); $transaction->save(); }
if ($transactionDate == "Date" || !$transactionDate || strpos("_____", $transactionDate) !== FALSE || strpos("¯¯¯", $transactionDate) !== FALSE || stripos("total", $transactionDate) !== FALSE) { continue; } // If the employeeNum field is blank use the previous employeeNum #if (!$employeeNum) { # $employeeNum = $prev_employeeNum; #} #$prev_employeeNum = $employeeNum; // Find the TF for the wage $query = prepare("SELECT * FROM tf WHERE qpEmployeeNum=%d", $employeeNum); $db->query($query); if (!$db->next_record()) { $msg .= "<b>Warning: Could not find TF for employee number '{$employeeNum}' {$name}</b><br>"; continue; } $fromTfID = $db->f("tfID"); // Convert the date to yyyy-mm-dd if (!preg_match("|^([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})\$|i", $transactionDate, $matches)) { $msg .= "<b>Warning: Could not convert date '{$transactionDate}'</b><br>"; continue; } $transactionDate = sprintf("%04d-%02d-%02d", $matches[3], $matches[2], $matches[1]); // Strip $ and , from amount $amount = str_replace(array('$', ','), array(), $amount); if (!preg_match("/^[-]?[0-9]+(\\.[0-9]+)?\$/", $amount)) { $msg .= "<b>Warning: Could not convert amount '{$amount}'</b><br>"; continue; } // Negate the amount - Wages are a debit from TF's $amount = -$amount; // Check for an existing transaction for this wage - note we have to use a range or amount because it is floating point
function get_projectPerson_hourly_rate($personID, $projectID) { $db = new db_alloc(); $q = prepare("SELECT rate,rateUnitID FROM projectPerson WHERE personID = %d AND projectID = %d", $personID, $projectID); $db->query($q); $db->next_record(); $rate = $db->f("rate"); $unitID = $db->f("rateUnitID"); $t = new timeUnit(); $timeUnits = $t->get_assoc_array("timeUnitID", "timeUnitSeconds", $unitID); $rate && $timeUnits[$unitID] and $hourly_rate = $rate / ($timeUnits[$unitID] / 60 / 60); return $hourly_rate; }
function rebuild_cache($table) { $cache =& singleton("cache"); if (meta::$tables[$table]) { $m = new meta($table); $cache[$table] = $m->get_list(); } else { $db = new db_alloc(); $db->query("SELECT * FROM " . $table); while ($row = $db->row()) { $cache[$table][$db->f($table . "ID")] = $row; } } // Special processing for person and config tables if ($table == "person") { $people = $cache["person"]; foreach ($people as $id => $row) { if ($people[$id]["firstName"] && $people[$id]["surname"]) { $people[$id]["name"] = $people[$id]["firstName"] . " " . $people[$id]["surname"]; } else { $people[$id]["name"] = $people[$id]["username"]; } } uasort($people, "sort_by_name"); $cache["person"] = $people; } else { if ($table == "config") { // Special processing for config table $config = $cache["config"]; foreach ($config as $id => $row) { $rows_config[$row["name"]] = $row; } $cache["config"] = $rows_config; } } singleton("cache", $cache); }
$_POST["transactionType"] or alloc_error("Please select a Transaction Type"); $_POST["transactionStartDate"] or alloc_error("You must enter the Start date in the format yyyy-mm-dd"); $_POST["transactionFinishDate"] or alloc_error("You must enter the Finish date in the format yyyy-mm-dd"); if (!$TPL["message"]) { !$transactionRepeat->get_value("status") && $transactionRepeat->set_value("status", "pending"); $transactionRepeat->set_value("companyDetails", rtrim($transactionRepeat->get_value("companyDetails"))); $transactionRepeat->save(); alloc_redirect($TPL["url_alloc_transactionRepeat"] . "transactionRepeatID=" . $transactionRepeat->get_id()); } $transactionRepeat->set_values(); } $TPL["reimbursementRequired_checked"] = $transactionRepeat->get_value("reimbursementRequired") ? " checked" : ""; if ($transactionRepeat->get_value("transactionRepeatModifiedUser")) { $db->query("select username from person where personID=%d", $transactionRepeat->get_value("transactionRepeatModifiedUser")); $db->next_record(); $TPL["user"] = $db->f("username"); } if (have_entity_perm("tf", PERM_READ, $current_user, false)) { // Person can access all TF records $q = prepare("SELECT tfID AS value, tfName AS label \n FROM tf \n WHERE tfActive = 1 \n OR tf.tfID = %d \n OR tf.tfID = %d \n ORDER BY tfName", $transactionRepeat->get_value("tfID"), $transactionRepeat->get_value("fromTfID")); } else { if (have_entity_perm("tf", PERM_READ, $current_user, true)) { // Person can only read TF records that they own $q = prepare("SELECT tf.tfID AS value, tf.tfName AS label\n FROM tf, tfPerson \n WHERE tfPerson.personID=%d \n AND tf.tfID=tfPerson.tfID \n AND (tf.tfActive = 1 OR tf.tfID = %d OR tf.tfID = %d)\n ORDER BY tfName", $current_user->get_id(), $transactionRepeat->get_value("tfID"), $transactionRepeat->get_value("fromTfID")); } else { alloc_error("No permissions to generate TF list"); } } //special case for disabled TF. Include it in the list, but also add a warning message. $tf = new tf(); $tf->set_id($transactionRepeat->get_value("tfID"));
$amount = str_replace(array('$', ','), array(), $amount); if (!preg_match("/^-?[0-9]+(\\.[0-9]+)?\$/", $amount)) { $msg .= "<b>Warning: Could not convert amount '{$amount}'</b><br>"; continue; } // Ignore positive amounts if ($amount > 0) { $msg .= "<b>Warning: Ignored positive '{$amount}' for {$memo} on {$date}</b><br>"; continue; } // Find the TF ID for the expense $query = prepare("SELECT * FROM tf WHERE tfActive = 1 AND quickenAccount='%s'", $account); echo $query; $db->query($query); if ($db->next_record()) { $fromTfID = $db->f("tfID"); } else { $msg .= "<b>Warning: Could not find active TF for account '{$account}'</b><br>"; continue; } // Check for an existing transaction $query = prepare("SELECT * FROM transaction WHERE transactionType='expense' AND transactionDate='%s' AND product='%s' AND amount > %0.3f and amount < %0.3f", $date, $memo, $amount - 0.004, $amount + 0.004); $db->query($query); if ($db->next_record()) { $msg .= "Warning: Expense '{$memo}' on {$date} already exixsts.<br>"; continue; } // Create a transaction object and then save it $transaction = new transaction(); $transaction->set_value("companyDetails", $description); $transaction->set_value("product", $memo);
} } if ($_POST["field_quotes"] == "single") { $quotes = "'"; } if ($_POST["field_quotes"] == "double") { $quotes = "\""; } while ($db->next_record()) { $odd_even = $odd_even == "even" ? "odd" : "even"; $TPL["result_row"] .= sprintf($start_row_separator, $odd_even); foreach ($fields as $k => $field) { $field = end(explode(".", $field)); if (stripos("ModifiedUser", $field) !== FALSE || stripos("personID", $field) !== FALSE) { $person = new person(); $person->set_id($db->f($field)); $person->select(); $result = $person->get_name(array("format" => "nick")); } else { if (stripos("tfID", $field) !== FALSE) { $result = tf::get_name($db->f($field)); } else { $result = $db->f($field); } } $TPL["result_row"] .= $start_field_separator; $TPL["result_row"] .= $quotes . $result . $quotes; if (isset($fields[$k + 1]) || !$_POST["generate_file"]) { $TPL["result_row"] .= $end_field_separator; } }
} else { $loan->set_value("personID", $current_user->get_id()); } $loan->set_value("dateBorrowed", $today); $loan->set_value("dateReturned", "0000-00-00"); $loan->save(); alloc_redirect($TPL["url_alloc_loanAndReturn"]); } } if ($_POST["returnItem"]) { $dbTemp = new db_alloc(); $dbTemp->query("select * from loan where itemID=%d and dateReturned='0000-00-00'", $itemID); $db = new db_alloc(); $db->query("select * from loan where loan.itemID=%d and dateBorrowed>dateReturned", $itemID); $db->next_record(); $loan->set_id($db->f("loanID")); if ($loan->select()) { $loan->set_value("dateReturned", $today); $loan->set_value("itemID", $itemID); // check to see if admin/manager returning someone elses item, and sent email if ($loan->get_value("personID") != $current_user->get_id()) { if ($current_user->have_role("admin") || $current_user->have_role("manage")) { $person = new person(); $person->set_id($loan->get_value("personID")); $person->select(); $loan->save(); } } else { $loan->save(); } }
function email_move_status_to_finished($direction, $info) { if ($direction == "forwards") { //requires INVOICE_TIMESHEETS if (!$this->have_perm(PERM_TIME_INVOICE_TIMESHEETS)) { //no permission, go away alloc_error("You do not have permission to change this timesheet."); } //transactions $q = prepare("SELECT DISTINCT transaction.transactionDate, transaction.product, transaction.status\n FROM transaction\n JOIN tf ON tf.tfID = transaction.tfID OR tf.tfID = transaction.fromTfID\n RIGHT JOIN tfPerson ON tfPerson.personID = %d AND tfPerson.tfID = tf.tfID\n WHERE transaction.timeSheetID = %d\n ", $this->get_value('personID'), $this->get_id()); $db = new db_alloc(); $db->query($q); //the email itself $email = array(); $email["type"] = "timesheet_finished"; $email["to"] = $info["timeSheet_personID_email"]; $email["subject"] = commentTemplate::populate_string(config::get_config_item("emailSubject_timeSheetCompleted"), "timeSheet", $this->get_id()); $email["body"] = <<<EOD To: {$info["timeSheet_personID_name"]} Time Sheet: {$info["url"]} For Project: {$info["projectName"]} Your timesheet has been completed by {$info["current_user_name"]}. EOD; if ($db->num_rows() > 0) { $email["body"] .= "Transaction summary:\n"; $status_ops = array("pending" => "Pending", "approved" => "Approved", "rejected" => "Rejected"); while ($db->next_record()) { $email["body"] .= $db->f("transactionDate") . " for " . $db->f("product") . ": " . $status_ops[$db->f("status")] . "\n"; } } $msg[] = $this->shootEmail($email); $this->set_value("status", "finished"); return $msg; } }
function get_all_parties($projectID = false, $task_exists = false) { $current_user =& singleton("current_user"); if (!$projectID && is_object($this)) { $projectID = $this->get_id(); } if ($projectID) { $extra_interested_parties = config::get_config_item("defaultInterestedParties"); foreach ((array) $extra_interested_parties as $name => $email) { $interestedPartyOptions[$email]["name"] = $name; } // Get primary client contact from Project page $db = new db_alloc(); $q = prepare("SELECT projectClientName,projectClientEMail FROM project WHERE projectID = %d", $projectID); $db->query($q); $db->next_record(); $interestedPartyOptions[$db->f("projectClientEMail")]["name"] = $db->f("projectClientName"); $interestedPartyOptions[$db->f("projectClientEMail")]["external"] = "1"; // Get all other client contacts from the Client pages for this Project $q = prepare("SELECT clientID FROM project WHERE projectID = %d", $projectID); $db->query($q); $db->next_record(); $clientID = $db->f("clientID"); if ($clientID) { $client = new client($clientID); $interestedPartyOptions = array_merge((array) $interestedPartyOptions, (array) $client->get_all_parties()); } // Get all the project people for this tasks project $q = prepare("SELECT emailAddress, firstName, surname, person.personID, username\n FROM projectPerson \n LEFT JOIN person on projectPerson.personID = person.personID \n WHERE projectPerson.projectID = %d AND person.personActive = 1 ", $projectID); $db->query($q); while ($db->next_record()) { unset($name); $db->f("firstName") && $db->f("surname") and $name = $db->f("firstName") . " " . $db->f("surname"); $name or $name = $db->f("username"); $interestedPartyOptions[$db->f("emailAddress")]["name"] = $name; $interestedPartyOptions[$db->f("emailAddress")]["personID"] = $db->f("personID"); $interestedPartyOptions[$db->f("emailAddress")]["internal"] = true; } } if (is_object($current_user) && $current_user->get_id()) { $interestedPartyOptions[$current_user->get_value("emailAddress")]["name"] = $current_user->get_name(); $interestedPartyOptions[$current_user->get_value("emailAddress")]["personID"] = $current_user->get_id(); } // return an aggregation of the current task/proj/client parties + the existing interested parties $interestedPartyOptions = interestedParty::get_interested_parties("project", $projectID, $interestedPartyOptions, $task_exists); return (array) $interestedPartyOptions; }
function get_all_parties($clientID = false) { if (!$clientID && is_object($this)) { $clientID = $this->get_id(); } if ($clientID) { // Get all client contacts $db = new db_alloc(); $q = prepare("SELECT clientContactName, clientContactEmail, clientContactID \n FROM clientContact \n WHERE clientID = %d\n AND clientContactActive = 1\n ", $clientID); $db->query($q); while ($db->next_record()) { $interestedPartyOptions[$db->f("clientContactEmail")] = array("name" => $db->f("clientContactName"), "external" => "1", "clientContactID" => $db->f("clientContactID")); } } // return an aggregation of the current task/proj/client parties + the existing interested parties $interestedPartyOptions = interestedParty::get_interested_parties("client", $clientID, $interestedPartyOptions); return (array) $interestedPartyOptions; }
public static function get_interested_parties($entity, $entityID = false, $ops = array(), $dont_select = false) { $rtn = array(); if ($entityID) { $db = new db_alloc(); $q = prepare("SELECT *\n FROM interestedParty\n WHERE entity='%s'\n AND entityID = %d\n ", $entity, $entityID); $db->query($q); while ($db->row()) { $ops[$db->f("emailAddress")]["name"] = $db->f("fullName"); $ops[$db->f("emailAddress")]["role"] = "interested"; $ops[$db->f("emailAddress")]["selected"] = $db->f("interestedPartyActive") && !$dont_select ? true : false; $ops[$db->f("emailAddress")]["personID"] = $db->f("personID"); $ops[$db->f("emailAddress")]["clientContactID"] = $db->f("clientContactID"); $ops[$db->f("emailAddress")]["external"] = $db->f("external"); } } if (is_array($ops)) { foreach ($ops as $email => $info) { // if there is an @ symbol in email address if (stristr($email, "@")) { $info["email"] = $email; $info["identifier"] = interestedParty::get_encoded_interested_party_identifier($info); $rtn[$email] = $info; } } uasort($rtn, array("interestedParty", "sort_interested_parties")); } return $rtn; }
function get_name($tfID = false) { if ($tfID) { $db = new db_alloc(); $db->query(prepare("SELECT tfName FROM tf WHERE tfID=%d", $tfID)); $db->next_record(); return $db->f("tfName"); } }
function select_token_by_entity_and_action($entity, $entityID, $action) { $q = prepare("SELECT token.*, tokenAction.*\n FROM token \n LEFT JOIN tokenAction ON token.tokenActionID = tokenAction.tokenActionID \n WHERE tokenEntity = '%s' \n AND tokenEntityID = %d\n AND tokenAction.tokenActionMethod = '%s'\n ", $entity, $entityID, $action); $db = new db_alloc(); $db->query($q); if ($db->next_record()) { $this->set_id($db->f("tokenID")); $this->select(); return true; } }
<?php // Nuke additional index name_2 from config table $db = new db_alloc(); $db->query("show keys from config"); while ($db->next_record()) { if ($db->f("Key_name") == "name_2") { $db->query("drop index name_2 on config"); } }
function show_main_list() { global $timeSheet; $current_user =& singleton("current_user"); if (!$timeSheet->get_id()) { return; } $db = new db_alloc(); $q = prepare("SELECT COUNT(*) AS tally FROM timeSheetItem WHERE timeSheetID = %d AND timeSheetItemID != %d", $timeSheet->get_id(), $_POST["timeSheetItem_timeSheetItemID"]); $db->query($q); $db->next_record(); if ($db->f("tally")) { include_template("templates/timeSheetItemM.tpl"); } }
function get_history_label($SCRIPT_NAME, $qs) { // Save the history record LABEL with the most descriptive label // possible, using the class variable->display_field_name $db = new db_alloc(); $script_name_array = explode("/", $SCRIPT_NAME); $file = end($script_name_array); $CLASS_NAME = str_replace(".php", "", $file); // File name without .php extension $dir = $script_name_array[sizeof($script_name_array) - 2]; // Directory that file is in $qs = preg_replace("[^\\?]", "", $qs); // Nuke the leading question mark of the query string attached to end of url eg: ?tfID=23&anal=true // We can only get a descriptive history entry if there is a xxxID // on the url, that way we can get the specific records label. if ($qs) { $qs_array = explode("&", $qs); foreach ($qs_array as $query_pair) { // Break up url query string into key/value pairs. if (preg_match("/{$CLASS_NAME}/", $query_pair)) { // Look for a key like eg: transactionID so in that case it'd // use the class transaction. $key_and_value = explode("=", $query_pair); // Break key/value up into $KEY_FIELD and $ID $ID = $key_and_value[1]; $KEY_FIELD = $key_and_value[0]; if (class_exists($CLASS_NAME) && $ID) { $newClass = new $CLASS_NAME(); $display_field = $newClass->display_field_name; if (is_object($newClass->key_field) && $newClass->key_field->get_name() == $KEY_FIELD) { // The primary key for this db table is the same as // our KEY_FIELD var which was extracted from url. $query = prepare("SELECT * FROM %s WHERE %s = %d", $CLASS_NAME, $KEY_FIELD, $ID); $db->query($query); $db->next_record(); // return that particular classes _default_ display field // eg: for the table project, it would be projectName $rtn = $db->f($display_field); // But if our search for a descriptive text label failed // because the above search returned a number try again // to get a description from the next table // Get a new id and key field name and table name // Strip the trailing 'ID' from the , to get new class name $next_class_name = preg_replace("/ID\$/", "", $display_field); if (is_numeric($rtn) && class_exists($next_class_name)) { $next_class = new $next_class_name(); if ($display_field == $next_class->key_field->get_name()) { // If the display field was eg: tfID and that equals the key field of this table $next_class->set_id($rtn); $next_class->select(); $rtn = $next_class->get_value($next_class->display_field_name); } else { $rtn = $ID; } } $rtn = ": " . $rtn; return ucwords($CLASS_NAME) . $rtn; } } } } } return false; }
function have_perm($action = 0, $person = "", $assume_owner = false) { $current_user =& singleton("current_user"); global $permission_cache; if (defined("IS_GOD")) { return true; } if (!$person) { if ($current_user && is_object($current_user) && method_exists($current_user, "get_id") && $current_user->get_id()) { $person = $current_user; } } $entity_id = 0; if (is_object($person) && method_exists($person, "get_id") && $person->get_id()) { $person_id = $person->get_id(); $person_type = $person->classname; $person_id and $person_flag = $person_type . "_" . $person_id; } $record_cache_key = $this->data_table . ":" . $entity_id . ":" . $action . ":" . $person_flag . ":" . $assume_owner; $table_cache_key = $this->data_table . ":T:" . $action . ":" . $person_flag . ":" . $assume_owner; if (isset($permission_cache[$table_cache_key])) { return $permission_cache[$table_cache_key]; } else { if (isset($permission_cache[$record_cache_key])) { return $permission_cache[$record_cache_key]; } } $db = new db_alloc(); $query = prepare("SELECT * \n FROM permission \n WHERE (tableName = '%s')\n AND (actions & %d = %d)\n ORDER BY entityID DESC", $this->data_table, $action, $action); $db->query($query); while ($db->next_record()) { // Ignore this record if it specifies a role the user doesn't have if ($db->f("roleName") && is_object($person) && !$person->have_role($db->f("roleName"))) { continue; } // Ignore this record if it specifies that the user must be the record's owner and they are not if ($db->f("entityID") == -1 && !$assume_owner && !$this->is_owner($person)) { continue; } // Cache the result in variables to prevent duplicate database lookups $permission_cache[$record_cache_key] = true; if ($db->f("entityID") == 0) { $permission_cache[$table_cache_key] = true; } return true; } // No matching records - return false $permission_cache[$record_cache_key] = false; return false; }
function get_time_billed($taskID = "") { static $results; if (is_object($this) && !$taskID) { $taskID = $this->get_id(); } if ($results[$taskID]) { return $results[$taskID]; } if ($taskID) { $db = new db_alloc(); // Get tally from timeSheetItem table $db->query("SELECT sum(timeSheetItemDuration*timeUnitSeconds) as sum_of_time\n FROM timeSheetItem \n LEFT JOIN timeUnit ON timeSheetItemDurationUnitID = timeUnitID \n WHERE taskID = %d\n GROUP BY taskID", $taskID); while ($db->next_record()) { $results[$taskID] = $db->f("sum_of_time"); return $db->f("sum_of_time"); } return ""; } }
$info["username"] = config::get_config_item("allocEmailUsername"); $info["password"] = config::get_config_item("allocEmailPassword"); $info["protocol"] = config::get_config_item("allocEmailProtocol"); if (!$info["host"]) { alloc_error("Email mailbox host not defined, assuming email receive function is inactive."); } else { $mail = new email_receive($info, $lockfile); $mail->open_mailbox(config::get_config_item("allocEmailFolder")); $mail->check_mail(); $TPL["message_good"][] = "Connection succeeded!"; } } $db = new db_alloc(); $db->query("SELECT name,value,type FROM config"); while ($db->next_record()) { $fields_to_save[] = $db->f("name"); $types[$db->f("name")] = $db->f("type"); if ($db->f("type") == "text") { $TPL[$db->f("name")] = page::htmlentities($db->f("value")); } else { if ($db->f("type") == "array") { $TPL[$db->f("name")] = unserialize($db->f("value")); } } } #echo "<pre>".print_r($_POST,1)."</pre>"; if ($_POST["update_currencyless_transactions"] && $_POST["currency"]) { $db = new db_alloc(); $q = prepare("UPDATE transaction SET currencyTypeID = '%s' WHERE currencyTypeID IS NULL", $_POST["currency"]); $db->query($q); $q = prepare("UPDATE transactionRepeat SET currencyTypeID = '%s' WHERE currencyTypeID IS NULL", $_POST["currency"]);
<?php // UPDATE the newly created invoiceItem.iiDate field with the date from the invoice table (used to be invoiceDate, now it's invoiceDateFrom) $db = new db_alloc(); $db2 = new db_alloc(); $db->query("SELECT * FROM invoice"); while ($db->next_record()) { $db2->query(prepare("UPDATE invoiceItem SET iiDate = '%s' WHERE invoiceID = %d", $db->f("invoiceDateFrom"), $db->f("invoiceID"))); }