private function get_recs() { global $_DB; $sql = ""; $where = "WHERE (organization_idref=" . $_SESSION["organization_id"] . ")"; if (!$GLOBALS["_PERMITS"]->can_pass(PERMITS::_SUPERUSER)) { //superuser gets all if (is_array($this->restrict)) { $where .= "AND (a10.project_id IN (" . implode(",", $this->restrict) . ")) "; } else { if ($this->restrict > 0) { //super-duper always gets all $sql = "INNER JOIN (\n\t\t\t\t\t SELECT c02.project_idref FROM " . $_DB->prefix . "c02_rate AS c02\n\t\t\t\t\t INNER JOIN " . $_DB->prefix . "c00_person AS c00 ON c00.person_id = c02.person_idref\n\t\t\t\t\t WHERE c00.person_id = " . $this->restrict . "\tGROUP BY c02.project_idref\n\t\t\t\t\t) AS c02 ON c02.project_idref = a10.project_id "; } } } $sql = "SELECT a10.* FROM " . $_DB->prefix . "a10_project AS a10 " . $sql . $where . " ORDER BY timestamp;"; $stmt = $_DB->query($sql); $today = COM_NOW(); $this->inactives = 0; while ($row = $stmt->fetchObject()) { $element = array($row->name, $row->description, false); if (!is_null($row->inactive_asof)) { if (new DateTime($row->inactive_asof) <= $today) { $element[2] = true; ++$this->inactives; } } $this->records[strval($row->project_id)] = $element; } $stmt->closeCursor(); reset($this->records); }
function field_input_audit() { global $_STATE; $errors = ""; foreach ($_STATE->fields as $name => $field) { if (($msg = $field->audit()) === true) { continue; } $errors .= "<br>" . $name . ": " . $msg; } if ($errors != "") { $_STATE->msgStatus = "Error:" . $errors; return false; } $diff = date_diff($_STATE->fields["Close Date"]->value, COM_NOW(), true); if ($diff->m > 2) { $_STATE->msgStatus = "The Close Date is suspect - proceeding anyway"; } if (!array_key_exists(strval($_POST["selAccounting"]), $_STATE->accounting)) { throw_the_bum_out(NULL, "Evicted(" . __LINE__ . "): invalid accounting id " . $_POST["selAccounting"]); //we're being spoofed } $_STATE->accounting_id = intval($_POST["selAccounting"]); //Should check to see if inactive is greater than any timelogs? foreach ($_STATE->fields as $name => $field) { $field->disabled = true; } return TRUE; }
private function get_recs() { global $_DB; $where = ""; if ($this->restrict[0] != 0) { $not = ""; if ($this->blacklist) { $not = " NOT"; } $where = "AND (a10.project_id " . $not . " IN (" . implode(",", $this->restrict) . "))"; } $sql = "SELECT a10.* FROM " . $_DB->prefix . "a10_project AS a10\n\t\t\tWHERE (organization_idref=" . $_SESSION["organization_id"] . ")\n\t\t\t" . $where . "\n\t\t\tORDER BY timestamp;"; $stmt = $_DB->query($sql); $today = COM_NOW(); $this->inactives = 0; while ($row = $stmt->fetchObject()) { $element = array($row->name, $row->description, ''); if (!is_null($row->inactive_asof)) { $inactive = new DateTime($row->inactive_asof); if ($inactive <= $today) { $element[self::INACTIVE] = $inactive->format('Y-m-d'); ++$this->inactives; } } $this->records[strval($row->project_id)] = $element; } $stmt->closeCursor(); reset($this->records); }
private function get_recs() { global $_DB; $where = ""; if ($this->restrict[0] != 0) { $not = ""; if ($this->blacklist) { $not = " NOT"; } $where = "AND (c00.person_id " . $not . " IN (" . implode(",", $this->restrict) . "))"; } $sql = "SELECT c00.*, c10.inactive_asof FROM " . $_DB->prefix . "c00_person AS c00\n\t\t\tINNER JOIN " . $_DB->prefix . "c10_person_organization AS c10\n\t\t\tON (c00.person_id = c10.person_idref)\n\t\t\tWHERE (c10.organization_idref=" . $_SESSION["organization_id"] . ")\n\t\t\tAND (c00.person_id > 0)\n\t\t\t" . $where . "\n\t\t\tORDER BY c00.lastname;"; $stmt = $_DB->query($sql); $today = COM_NOW(); $this->inactives = 0; while ($row = $stmt->fetchObject()) { $element = array($row->lastname, $row->firstname, ''); if (!is_null($row->inactive_asof)) { $inactive = new DateTime($row->inactive_asof); if ($inactive <= $today) { $element[self::INACTIVE] = $inactive->format('Y-m-d'); ++$this->inactives; } } $this->records[strval($row->person_id)] = $element; } $stmt->closeCursor(); reset($this->records); }
function __construct($page_cnt = 2, $drop = "") { $this->page_count = $page_cnt; $this->drops = $drop . " "; //want a min of 2 chars $this->page = COM_NOW(); $this->page->sub(new DateInterval('P1M')); }
private function get_recs() { global $_DB; $sql = ""; if (!$this->allow_user) { $sql = " AND c00.person_id <> " . $_SESSION["person_id"]; } $sql = "SELECT c00.*, c10.inactive_asof FROM " . $_DB->prefix . "c00_person AS c00\n\t\t\tINNER JOIN " . $_DB->prefix . "c10_person_organization AS c10\n\t\t\tON (c00.person_id = c10.person_idref)\n\t\t\tWHERE c10.organization_idref=" . $_SESSION["organization_id"] . "\n\t\t\tAND c00.person_id > 0" . $sql . " ORDER BY c00.lastname;"; $stmt = $_DB->query($sql); $today = COM_NOW(); $this->inactives = 0; while ($row = $stmt->fetchObject()) { $element = array($row->lastname, $row->firstname, false); if (!is_null($row->inactive_asof)) { if (new DateTime($row->inactive_asof) <= $today) { $element[2] = true; ++$this->inactives; } } $this->records[strval($row->person_id)] = $element; } $stmt->closeCursor(); reset($this->records); }
function audit($chkrecent = true) { if (isset($_POST[$this->pagename . "YYYY"])) { $this->YYYY = COM_input_edit($this->pagename . "YYYY", 4); } if (isset($_POST[$this->pagename . "MM"])) { $this->MM = COM_input_edit($this->pagename . "MM", 2); } if (isset($_POST[$this->pagename . "DD"])) { $this->DD = COM_input_edit($this->pagename . "DD", 2); } if ($this->YYYY . $this->MM . $this->DD == "") { if ($this->required) { return "entry required"; } $this->value = NULL; return true; } if ($this->YYYY == "" || $this->MM == "" || $this->DD == "") { return "incomplete date"; } if (!is_numeric($this->YYYY) || !is_numeric($this->MM) || !is_numeric($this->DD)) { return "dates must be all numeric"; } if ($chkrecent) { $now = COM_NOW(); if ($this->YYYY < $now->format('Y') - 1 || $this->YYYY > $now->format('Y') + 1) { return "date must be recent"; } } if ($this->MM < 1 || $this->MM > 12) { return "invalid month"; } $m = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); if ($this->YYYY % 4 == 0) { $m[2] = 29; } if ($this->DD < 1 || $this->DD > $m[intval($this->MM)]) { return "invalid day of month"; } $this->value = new DateTime($this->YYYY . "-" . $this->MM . "-" . $this->DD); return true; }
break; case 'd': //delete delete_log($state, $logdate, $ndx); break; } } } //Main State Gate: (the while (1==1) allows a loop back through the switch using a 'break 1') while (1 == 1) { switch ($_STATE->status) { case STATE::INIT: $_STATE->person_id = 0; $_STATE->inactive_date = COM_NOW(); $_STATE->project_id = 0; $_STATE->close_date = COM_NOW(); $_STATE->accounting_id = 0; $_STATE->accounting = ""; $_STATE->task_id = 0; $_STATE->subtask_id = 0; $_STATE->account_id = 0; $_STATE->activity_id = 0; $_STATE->columns = -1; $_STATE->max_column = 0; $_STATE->closedCols = 0; //in tabular form => cols prior to close date unset($_SESSION["_EXTENSION"]); require_once "person_select.php"; $persons = new PERSON_SELECT(true); //true: user can edit their own stuff if (!$_EDIT) {
function POST($chkrecent = 3) { //1=to,2=from,3=logical OR global $_STATE; if (!isset($_POST["radRange"])) { return false; } //can happen on a goback if ($this->uses & DATE_SELECT::FROM) { //From date //pagename,DBname,load from DB?,write to DB?,required?,maxlength,disabled,value $from = new DATE_FIELD("txtFrom", "", FALSE, FALSE, FALSE, 0, FALSE, $this->from); $chk = $chkrecent & DATE_SELECT::FROM; if (($msg = $from->audit($chk)) !== true) { $_STATE->msgStatus = "From Date error: " . $msg; return false; } } if ($this->uses & DATE_SELECT::TO) { //To date $to = new DATE_FIELD("txtTo", "", FALSE, FALSE, FALSE, 0, FALSE, $this->to); $chk = $chkrecent & DATE_SELECT::TO; if (($msg = $to->audit($chk)) !== true) { $_STATE->msgStatus = "To Date error: " . $msg; return false; } } $this->checked = $_POST["radRange"]; switch ($this->checked) { case "a": break; case "b": break; case "m": $from->value->modify("first day of this month"); $to->value = clone $from->value; $to->value->modify("last day of this month"); break; case "p": break; case "s": break; case "w": if ($from->format("w") != 0 && $from->format("N") != 1) { $from->value->modify("last monday"); } $to->value = clone $from->value; $to->value->add(new DateInterval('P6D')); //P=period, 6=number, D=days } if ($this->uses & 3 && $from->value > $to->value) { $_STATE->msgStatus = "Error: From Date must be less than To Date"; return false; } if ($this->uses & DATE_SELECT::TO) { $now = COM_NOW(); $diff = date_diff($to->value, $now, true); if ($diff->m > 2) { if ($_STATE->msgStatus != "") { $_STATE->msgStatus .= "<br>"; } $_STATE->msgStatus .= "These dates are suspect - proceeding anyway"; } } $this->from = clone $from->value; $this->to = clone $to->value; return true; }
function get_projects($person_id) { //projects connected to this person global $_STATE, $_DB, $_PERMITS; if ($_PERMITS->can_pass(PERMITS::_SUPERUSER)) { return array(0); } //superuser gets all $sql = "SELECT a10.project_id, a10.inactive_asof FROM " . $_DB->prefix . "a10_project AS a10\n\t\t\tINNER JOIN (\n\t\t\t\tSELECT c02.project_idref FROM " . $_DB->prefix . "c02_rate AS c02\n\t\t\t\t\tINNER JOIN " . $_DB->prefix . "c00_person AS c00 ON c00.person_id = c02.person_idref\n\t\t\t\t\tWHERE c00.person_id = " . $person_id . " GROUP BY c02.project_idref\n\t\t\t\t) AS rate ON rate.project_idref = a10.project_id\n\t\t\tWHERE (organization_idref=" . $_SESSION["organization_id"] . ")\n\t\t\tORDER BY timestamp;"; $stmt = $_DB->query($sql); $today = COM_NOW(); $projects = array(); while ($row = $stmt->fetchObject()) { // if (!$_PERMITS->can_pass("edit_logs")) { // if (!is_null($row->inactive_asof)) { // if (new DateTime($row->inactive_asof) <= $today) continue; // } // } $projects[] = $row->project_id; } $stmt->closeCursor(); return $projects; }
if ($state->records[$state->recID]["event_id"] != $_POST["event"] || $state->records[$state->recID]["account_id"] != $_POST["account"]) { throw_the_bum_out(NULL, "Evicted(" . __LINE__ . "): invalid record " . $recID, true); } if ($_POST["sessions"] == 0) { delete_log($state); } else { update_log($state); } } //Main State Gate: (the while (1==1) allows a loop back through the switch using a 'break 1') while (1 == 1) { switch ($_STATE->status) { case STATE::INIT: $_STATE->title_singular = EVENT_HEAD; $_STATE->close_date = COM_NOW(); $_STATE->inactive_date = COM_NOW(); $_STATE->project_id = 0; $_STATE->accounting_id = 0; $_STATE->accounting = ""; // $_STATE->task_id = 0; $_STATE->event_id = 0; $_STATE->account_id = 0; $_STATE->closedCols = 0; //in tabular form => cols prior to close require_once "project_select.php"; $projects = new PROJECT_SELECT($_SESSION["person_id"]); $_STATE->project_select = serialize(clone $projects); if ($projects->selected) { $_STATE->status = SELECTED_PROJECT; break 1; //re-switch to SELECTED_PROJECT
function audit_input() { global $_STATE; if (!is_numeric($_STATE->new_rate["rate"]) || $_STATE->new_rate["rate"] < 0) { $_STATE->msgStatus = "!**Invalid entry for rate amount**"; return false; } if ($_STATE->new_rate["rate"] > 200 && !isset($_STATE->replies["RT"])) { $_STATE->msgStatus = "?RTThis rate is suspiciously high, accept it?"; return false; } $_STATE->new_rate["rate"] = number_format($_STATE->new_rate["rate"], 2); //2 decimal places $today = COM_NOW(); if ($_STATE->new_rate["eff"] != 0) { if (!($eff = DateTime::createFromFormat('Y-m-d', $_STATE->new_rate["eff"]))) { $_STATE->msgStatus = "!**Invalid effective date**"; return false; } if ($today->diff($eff, true)->days > 365 && !isset($_STATE->replies["EF"])) { $_STATE->msgStatus = "?EFEffective date is more than a year away, accept it?"; return false; } } if ($_STATE->new_rate["exp"] != 0 && $_STATE->new_rate["exp"] != "" && $_STATE->new_rate["eff"] != 0) { if (!($exp = DateTime::createFromFormat('Y-m-d', $_STATE->new_rate["exp"]))) { $_STATE->msgStatus = "!**Invalid expiration date**"; return false; } if ($today->diff($exp, true)->days > 365 && !isset($_STATE->replies["EX"])) { $_STATE->msgStatus = "?EXExpiration date is more than a year away, accept it?"; return false; } if (isset($eff) && $exp <= $eff) { $_STATE->msgStatus = "!**New expiration date must follow effective date**"; return false; } } $_STATE->msgStatus = "-"; //tell server_call to reset page return true; }
function NOW() { return COM_NOW(); }