Пример #1
0
function parse_operator_comparison($str, $figure)
{
    $operator_regex = "/\\s*([><=!]*)\\s*([\\d\\.]+)\\s*/";
    // 5
    if (is_numeric($str)) {
        $operator = '=';
        $number = $str;
        return operator_comparison($operator, $figure, $number);
        // <5 OR =10
    } else {
        if (stristr($str, "OR")) {
            $criterias = explode("OR", $str);
            foreach ($criterias as $criteria) {
                if (parse_operator_comparison($criteria, $figure)) {
                    return true;
                }
            }
            // >5 AND <10
        } else {
            if (stristr($str, "AND")) {
                $criterias = explode("AND", $str);
                foreach ($criterias as $criteria) {
                    preg_match($operator_regex, $criteria, $matches);
                    $operator = $matches[1];
                    $number = $matches[2];
                    if (operator_comparison($operator, $figure, $number)) {
                        $alive = true;
                    } else {
                        $dead = true;
                    }
                }
                return $alive && !$dead;
                // >5
            } else {
                if (preg_match($operator_regex, $str, $matches)) {
                    $operator = $matches[1];
                    $number = $matches[2];
                    return operator_comparison($operator, $figure, $number);
                }
            }
        }
    }
}
Пример #2
0
 public static function get_list($_FORM)
 {
     /*
      * This is the definitive method of getting a list of timeSheets that need a sophisticated level of filtering
      *
      */
     global $TPL;
     $current_user =& singleton("current_user");
     $_FORM["showShortProjectLink"] and $_FORM["showProjectLink"] = true;
     $filter = timeSheet::get_list_filter($_FORM);
     // Used in timeSheetListS.tpl
     $extra["showFinances"] = $_FORM["showFinances"];
     $debug = $_FORM["debug"];
     $debug and print "<pre>_FORM: " . print_r($_FORM, 1) . "</pre>";
     $debug and print "<pre>filter: " . print_r($filter, 1) . "</pre>";
     $_FORM["return"] or $_FORM["return"] = "html";
     if (is_array($filter) && count($filter)) {
         $filter = " WHERE " . implode(" AND ", $filter);
     }
     $q = "SELECT timeSheet.*, person.personID, projectName, projectShortName\n            FROM timeSheet \n       LEFT JOIN person ON timeSheet.personID = person.personID\n       LEFT JOIN project ON timeSheet.projectID = project.projectID\n       LEFT JOIN timeSheetItem ON timeSheet.timeSheetID = timeSheetItem.timeSheetID \n                 " . $filter . "\n        GROUP BY timeSheet.timeSheetID\n        ORDER BY dateFrom,projectName,timeSheet.status,surname";
     $debug and print "Query: " . $q;
     $db = new db_alloc();
     $db->query($q);
     $status_array = timeSheet::get_timeSheet_statii();
     $people_array =& get_cached_table("person");
     while ($row = $db->next_record()) {
         $t = new timeSheet();
         if (!$t->read_db_record($db)) {
             continue;
         }
         $t->load_pay_info();
         if ($_FORM["timeSheetItemHours"] && !parse_operator_comparison($_FORM["timeSheetItemHours"], $t->pay_info["total_duration_hours"])) {
             continue;
         }
         $row["currencyTypeID"] = $t->get_value("currencyTypeID");
         $row["amount"] = $t->pay_info["total_dollars"];
         $amount_tallies[] = array("amount" => $row["amount"], "currency" => $row["currencyTypeID"]);
         $extra["amountTotal"] += exchangeRate::convert($row["currencyTypeID"], $row["amount"]);
         $extra["totalHours"] += $t->pay_info["total_duration_hours"];
         $row["totalHours"] += $t->pay_info["total_duration_hours"];
         $row["duration"] = $t->pay_info["summary_unit_totals"];
         if ($t->get_value("status") == "edit" && imp($current_user->prefs["timeSheetHoursWarn"]) && $t->pay_info["total_duration_hours"] >= $current_user->prefs["timeSheetHoursWarn"]) {
             $row["hoursWarn"] = page::help("This time sheet has gone over " . $current_user->prefs["timeSheetHoursWarn"] . " hours.", page::warn());
         }
         if ($t->get_value("status") == "edit" && imp($current_user->prefs["timeSheetDaysWarn"]) && (mktime() - format_date("U", $t->get_value("dateFrom"))) / 60 / 60 / 24 >= $current_user->prefs["timeSheetDaysWarn"]) {
             $row["daysWarn"] = page::help("This time sheet is over " . $current_user->prefs["timeSheetDaysWarn"] . " days old.", page::warn());
         }
         $row["person"] = $people_array[$row["personID"]]["name"];
         $row["status"] = $status_array[$row["status"]];
         $row["customerBilledDollars"] = $t->pay_info["total_customerBilledDollars"];
         $extra["customerBilledDollarsTotal"] += exchangeRate::convert($row["currencyTypeID"], $t->pay_info["total_customerBilledDollars"]);
         $billed_tallies[] = array("amount" => $row["customerBilledDollars"], "currency" => $row["currencyTypeID"]);
         if ($_FORM["showFinances"]) {
             list($pos, $neg) = $t->get_transaction_totals();
             $row["transactionsPos"] = page::money_print($pos);
             $row["transactionsNeg"] = page::money_print($neg);
             foreach ((array) $pos as $v) {
                 $pos_tallies[] = $v;
             }
             foreach ((array) $neg as $v) {
                 $neg_tallies[] = $v;
             }
         }
         $p = new project();
         $p->read_db_record($db);
         $row["projectLink"] = $t->get_link($p->get_name($_FORM));
         $rows[$row["timeSheetID"]] = $row;
     }
     $extra["amount_tallies"] = page::money_print($amount_tallies);
     $extra["billed_tallies"] = page::money_print($billed_tallies);
     $extra["positive_tallies"] = page::money_print($pos_tallies);
     $extra["negative_tallies"] = page::money_print($neg_tallies);
     if (!$_FORM["noextra"]) {
         return array("rows" => (array) $rows, "extra" => $extra);
     } else {
         return (array) $rows;
     }
 }