Ejemplo n.º 1
0
function log_put()
{
    global $_DB, $_STATE;
    global $version;
    require_once "lib/props_send.php";
    //routines for sending property values
    $props_send = new PROPS_SEND(array("a12", "a14", "a21"));
    $sql = "SELECT name, description FROM " . $_DB->prefix . "a00_organization\n\t\t\tWHERE organization_id=" . $_SESSION["organization_id"] . ";";
    $row = $_DB->query($sql)->fetchObject();
    $orgname = $row->name;
    $orgdesc = $row->description;
    $from = $_STATE->from_date->format('Y-m-d');
    $to = $_STATE->to_date->format('Y-m-d');
    $sql = "SELECT * FROM " . $_DB->prefix . "v10_timereport\n\t\t\tWHERE (person_id IN(" . implode($_STATE->person_ids, ",") . "))\n\t\t\tAND (project_id IN (" . implode($_STATE->project_ids, ",") . "))\n\t\t\tAND (logdate BETWEEN :fromdate AND :todate)\n\t\t\tORDER BY logdate LIMIT 1;";
    $stmt = $_DB->prepare($sql);
    $stmt->bindValue(':fromdate', $from, db_connect::PARAM_DATE);
    $stmt->bindValue(':todate', $to, db_connect::PARAM_DATE);
    $stmt->execute();
    if (!($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
        $_STATE->msgStatus = "No logs were downloaded";
        return;
    }
    $filename = "timesheet_" . $orgname . "_" . $from . "_to_" . $to . ".csv";
    //for file_put...
    require_once "lib/file_put.php";
    $out = fopen('php://output', 'w');
    $outline = array();
    $outline[] = "timesheet";
    $outline[] = $version;
    $outline[] = $from;
    $outline[] = $to;
    $outline[] = $orgname;
    $outline[] = $orgdesc;
    fputcsv($out, $outline);
    //ID row
    $outline = array();
    $fields = "";
    foreach ($row as $name => $value) {
        //headings
        if ($name == "project_id" || $name == "lastname" || $name == "firstname" || $name == "extension") {
            continue;
        }
        //don't send
        //activity_id?
        $outline[] = $name;
        $fields .= "," . $name;
    }
    fputcsv($out, $outline);
    $props_send->init($outline);
    //set up to get property values
    $sql_logs = "SELECT " . substr($fields, 1) . " FROM " . $_DB->prefix . "v10_timereport\n\t\t\tWHERE (person_id=:person_id) AND (project_id=:project_id)\n\t\t\tAND (logdate BETWEEN :fromdate AND :todate)\n\t\t\tORDER BY logdate;";
    $stmt_logs = $_DB->prepare($sql_logs);
    foreach ($_STATE->project_ids as $project_id) {
        $sql = "SELECT name, description FROM " . $_DB->prefix . "a10_project\n\t\t\t\tWHERE project_id=" . $project_id . ";";
        $row = $_DB->query($sql)->fetchObject();
        $outline = array();
        $outline[] = "<project>";
        $outline[] = $row->name;
        $outline[] = $row->description;
        $outline[] = $project_id;
        fputcsv($out, $outline);
        //project row
        foreach ($_STATE->person_ids as $person_id) {
            $sql = "SELECT lastname, firstname FROM " . $_DB->prefix . "c00_person\n\t\t\t\t\tWHERE person_id=" . $person_id . ";";
            $row = $_DB->query($sql)->fetchObject();
            $outline = array();
            $outline[] = "<person>";
            $outline[] = $row->lastname;
            $outline[] = $row->firstname;
            $outline[] = $person_id;
            fputcsv($out, $outline);
            //person row
            $stmt_logs->bindvalue(':person_id', $person_id, db_connect::PARAM_INT);
            $stmt_logs->bindvalue(':project_id', $project_id, db_connect::PARAM_INT);
            $stmt_logs->bindValue(':fromdate', $from, db_connect::PARAM_DATE);
            $stmt_logs->bindValue(':todate', $to, db_connect::PARAM_DATE);
            $stmt_logs->execute();
            while ($row_logs = $stmt_logs->fetch(PDO::FETCH_NUM)) {
                $props_send->add_ids($row_logs);
                //add property value ids
                fputcsv($out, $row_logs);
            }
            $stmt_logs->closeCursor();
        }
        //end persons
        $outline = array();
        $outline[] = "<person>";
        $outline[] = "<end>";
        fputcsv($out, $outline);
        //person row
    }
    //end projects
    $outline = array();
    $outline[] = "<project>";
    $outline[] = "<end>";
    fputcsv($out, $outline);
    //project row
    $props_send->send_all($out);
    fclose($out);
    FP_end();
    $_STATE->msgStatus = "Logs successfully downloaded";
}
Ejemplo n.º 2
0
function log_put()
{
    global $_DB, $_STATE, $_PERMITS;
    global $version;
    require_once "lib/props_send.php";
    //routines for sending property values
    $props_send = new PROPS_SEND(array("a21", "a30"));
    $sql = "SELECT name FROM " . $_DB->prefix . "a00_organization\n\t\t\tWHERE organization_id=" . $_SESSION["organization_id"] . ";";
    $row = $_DB->query($sql)->fetchObject();
    $orgname = $row->name;
    $from = $_STATE->from_date->format('Y-m-d');
    $to = $_STATE->to_date->format('Y-m-d');
    $filename = "eventlog_" . $orgname . "_" . $from . "_to_" . $to . ".csv";
    //for file_put...
    require_once "lib/file_put.php";
    $out = fopen('php://output', 'w');
    $outline = array();
    $outline[] = "eventlog";
    $outline[] = $version;
    $outline[] = $from;
    $outline[] = $to;
    $outline[] = $orgname;
    fputcsv($out, $outline);
    //ID row
    $sql_logs = "";
    if (!$_PERMITS->can_pass("project_logs")) {
        $sql_logs = "(b10.person_idref=" . $_SESSION["person_id"] . ") AND ";
    }
    $sql_logs = "SELECT b10.logdate, b10.session_count, b10.attendance,\n\t\t\ta30.event_id AS event_props, a30.name AS event, a30.description AS event_desc,\n\t\t\ta21.account_id AS account_props, a21.name AS account, a21.description AS account_desc,\n\t\t\tb10.comments\n\t\t\tFROM " . $_DB->prefix . "b10_eventlog AS b10\n\t\t\tJOIN " . $_DB->prefix . "a30_event AS a30 ON a30.event_id = b10.event_idref\n\t\t\tJOIN " . $_DB->prefix . "a21_account AS a21 ON a21.account_id = b10.account_idref\n\t\t\tWHERE " . $sql_logs . "(logdate BETWEEN :fromdate AND :todate)";
    $sql = $sql_logs . " AND (a30.project_idref IN (" . implode($_STATE->project_ids, ",") . "))\n\t\t\tORDER BY logdate, a30.event_id, a21.account_id LIMIT 1;";
    $stmt = $_DB->prepare($sql);
    $stmt->bindValue(':fromdate', $from, db_connect::PARAM_DATE);
    $stmt->bindValue(':todate', $to, db_connect::PARAM_DATE);
    $stmt->execute();
    if (!($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
        $_STATE->msgStatus = "No logs were downloaded";
        return;
    }
    $outline = array();
    $fields = "";
    foreach ($row as $name => $value) {
        //headings
        $outline[] = $name;
        $fields .= "," . $name;
    }
    fputcsv($out, $outline);
    $props_send->init($outline);
    //set up to get property values
    $sql_logs = $sql_logs . " AND (a30.project_idref=:project_id)\n\t\tORDER BY logdate;";
    $stmt_logs = $_DB->prepare($sql_logs);
    foreach ($_STATE->project_ids as $project_id) {
        $sql = "SELECT name, description FROM " . $_DB->prefix . "a10_project\n\t\t\t\tWHERE project_id=" . $project_id . ";";
        $row = $_DB->query($sql)->fetchObject();
        $outline = array();
        $outline[] = "<project>";
        $outline[] = $row->name;
        $outline[] = $row->description;
        $outline[] = $project_id;
        fputcsv($out, $outline);
        //project row
        $stmt_logs->bindValue(':fromdate', $from, db_connect::PARAM_DATE);
        $stmt_logs->bindValue(':todate', $to, db_connect::PARAM_DATE);
        $stmt_logs->bindValue(':project_id', $project_id, db_connect::PARAM_INT);
        $stmt_logs->execute();
        while ($row_logs = $stmt_logs->fetch(PDO::FETCH_NUM)) {
            $props_send->add_ids($row_logs);
            //add property value ids
            fputcsv($out, $row_logs);
        }
        $stmt_logs->closeCursor();
    }
    //end projects
    $outline = array();
    $outline[] = "<project>";
    $outline[] = "<end>";
    fputcsv($out, $outline);
    //project row
    $props_send->send_all($out);
    fclose($out);
    FP_end();
    $_STATE->msgStatus = "Logs successfully downloaded";
}