/** * Download task list as attachment * * @access public * @param void * @return null */ function download() { $project = active_project(); //$times = $project->getTimes(); $times = ProjectTimes::findAll(array('conditions' => array('`project_id` = ?', $project->getId()), 'order' => '`done_date` DESC')); if (!is_array($times)) { flash_error(lang('time dnx')); $this->redirectTo('time'); } // if $this->canGoOn(); $filtered = array(); foreach ($times as $time) { if ($time->canView(logged_user())) { $filtered[] = $time; } } // if $times = null; $output = array_var($_GET, 'output', 'csv'); $project_name = active_project()->getName(); $task_count = 0; if ($output == 'pdf') { Env::useLibrary('fpdf'); $download_name = "{$project_name}-times.pdf"; $download_type = 'application/pdf'; $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetTitle($project_name); $pdf->SetFont('Arial', 'B', 16); $task_lists = active_project()->getOpenTaskLists(); $pdf->Cell(0, 10, lang('project') . ': ' . active_project()->getObjectName(), 'C'); $pdf->Ln(); $w = array(0 => 6, 140, 140); $pdf->SetFont('Arial', 'I', 14); foreach ($filtered as $time) { $line++; $time_id = '' . $time->getId(); $time_done = format_date($time->getDoneDate(), null, 0); if ($time->getIsClosed()) { $time_status = lang('completed'); $time_completion_info = format_date($task->getUpdatedOn()); } else { $time_status = lang('open'); $time_completion_info = ' '; } if ($time->getAssignedTo()) { $time_assignee = $time->getAssignedTo()->getObjectName(); } else { $time_assignee = lang('not assigned'); } $pdf->Cell($w[0], 6, $line); $pdf->Cell($w[1], 6, $time_id . " / " . $time_status . " / " . $time_completion_info . " / " . $time_assignee . " / " . $time_done, "TLRB"); $pdf->Ln(); $pdf->Cell($w[0], 6, ''); $pdf->MultiCell($w[2], 6, $time->getDescription()); $pdf->Ln(); } $pdf->Output($download_name, 'D'); } else { $download_name = "{$project_name}-times.txt"; $download_type = 'text/csv'; $s = "Project name\tId\tDate\tDescription\tHours\tBillable\n"; foreach ($filtered as $time) { $s .= $project_name; $s .= "\t"; $s .= $time->getId(); $s .= "\t"; $s .= format_date($time->getDoneDate(), null, 0); $s .= "\t"; $s .= $time->getDescription(); $s .= "\t"; $s .= $time->getHours(); $s .= "\t"; $s .= $time->getIsBillable(); $s .= "\n"; } $download_contents = $s; download_headers($download_name, $download_type, strlen($download_contents), true); echo $download_contents; } die; }
/** * SAVR 10/20/06 : force file download over SSL for IE * BIP 09/17/07 : inserted and tested for ProjectPier * Was: * function download_contents($content, $type, $name, $size, $force_download = false) { */ function download_contents($content, $type, $name, $size, $force_download = true, $from_filesystem = false) { if (connection_status() != 0) { return false; } // check connection download_headers($name, $type, $size, $force_download); if ($from_filesystem) { if (!is_readable($content)) { return false; } if (!ini_get('safe_mode')) { @set_time_limit(0); } $chunksize = 1 * (1024 * 1024); // how many bytes per chunk $buffer = ''; $handle = fopen($content, 'rb'); if ($handle === false) { return false; } while (!feof($handle)) { $buffer = fread($handle, $chunksize); print $buffer; flush(); ob_flush(); } return fclose($handle); } else { /* print $content; */ header("X-ProjectPier-Storage: mysql"); header("X-ProjectPier-Size: " . $size); // 0.8.8 $content = repository id //print $content; $repository_id = $content; $repo_table = TABLE_PREFIX . 'file_repo'; $query = sprintf("SELECT `content`, `seq` FROM {$repo_table} WHERE `id`='%s' order by `seq` asc", mysql_real_escape_string($repository_id)); trace(__FILE__, $query); header("X-ProjectPier-Debug1: " . $query); $result = mysql_query($query); header("X-ProjectPier-Debug2: " . mysql_error()); while ($row = mysql_fetch_assoc($result)) { trace(__FILE__, $row['seq']); header("X-ProjectPier-Debug3-" . $row['seq'] . ": " . mysql_error()); print $row['content']; flush(); ob_flush(); } header("X-ProjectPier-Debug4: " . mysql_error()); mysql_free_result($result); } return connection_status() == 0 && !connection_aborted(); }
/** * Download task list as attachment * * @access public * @param void * @return null */ function download_list() { $task_list = ProjectTaskLists::findById(get_id()); if (!$task_list instanceof ProjectTaskList) { flash_error(lang('task list dnx')); $this->redirectTo('task'); } // if $this->canGoOn(); if (!$task_list->canView(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('task')); } // if $output = array_var($_GET, 'output', 'csv'); $project_name = active_project()->getName(); $task_list_name = $task_list->getName(); $task_count = 0; if ($output == 'pdf') { Env::useLibrary('fpdf'); $download_name = "{$project_name}-tasks.pdf"; $download_type = 'application/pdf'; $pdf = new FPDF("P", "mm"); $pdf->AddPage(); $pdf->SetTitle($project_name); $pdf->SetCompression(true); $pdf->SetCreator('ProjectPier'); $pdf->SetDisplayMode('fullpage', 'single'); $pdf->SetSubject(active_project()->getObjectName()); $pdf->SetFont('Arial', 'B', 16); $task_lists = active_project()->getOpenTaskLists(); $pdf->Cell(0, 10, lang('project') . ': ' . active_project()->getObjectName(), 'B', 0, 'C'); $pdf->Ln(14); $w = array(0 => 12, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140); foreach ($task_lists as $task_list) { $pdf->SetFont('Arial', 'B', 14); $pdf->Write(10, lang('task list') . ': ' . $task_list->getObjectName()); $pdf->Ln(14); $tasks = $task_list->getTasks(); $pdf->SetFont('Arial', 'I', 14); $pdf->SetFillColor(230, 230, 230); $pdf->Cell($w[1], 6, '#', 1, 0, 'C', true); $pdf->Cell($w[3], 6, lang('status'), 1, 0, 'C', true); $pdf->Cell($w[10], 6, lang('info'), 1, 0, 'C', true); $pdf->Cell(0, 6, lang(user), 1, 0, 'C', true); $pdf->Ln(); foreach ($tasks as $task) { $line++; if ($task->isCompleted()) { $task_status = lang('completed'); $task_status_color_R = 0; $task_status_color_G = 150; $task_status_color_B = 0; $task_completion_info = lang('completed task') . ' : ' . format_date($task->getCompletedOn()) . ' @ ' . format_time($task->getCompletedOn()); } else { $task_status = lang('open'); $task_status_color_R = 200; $task_status_color_G = 0; $task_status_color_B = 0; $task_completion_info = lang('due date') . ' : ' . lang('not assigned'); $task_completion_info_color_R = 200; $task_completion_info_color_G = 0; $task_completion_info_color_B = 0; if ($task->getDueDate()) { $task_completion_info = lang('due date') . ' : ' . format_date($task->getDueDate()) . ' @ ' . format_time($task->getDueDate()); $task_completion_info_color_R = 0; $task_completion_info_color_G = 0; $task_completion_info_color_B = 0; } } if ($task->getAssignedTo()) { $task_assignee = $task->getAssignedTo()->getObjectName(); $task_assignee_color_R = 0; $task_assignee_color_G = 0; $task_assignee_color_B = 0; } else { $task_assignee = lang('not assigned'); $task_assignee_color_R = 200; $task_assignee_color_G = 0; $task_assignee_color_B = 0; } $pdf->SetFillColor(245, 245, 245); $pdf->Cell($w[1], 6, $line, 1, 0, 'C', true); $pdf->SetTextColor($task_status_color_R, $task_status_color_G, $task_status_color_B); $pdf->Cell($w[3], 6, $task_status, 1, 0, 'C', true); $pdf->SetTextColor($task_completion_info_color_R, $task_completion_info_color_G, $task_completion_info_color_B); $pdf->Cell($w[10], 6, $task_completion_info, 1, 0, 'C', true); $pdf->SetTextColor($task_assignee_color_R, $task_assignee_color_G, $task_assignee_color_B); $pdf->Cell(0, 6, $task_assignee, 1, 0, 'C', true); $pdf->SetTextColor(0, 0, 0); $pdf->Ln(); $pdf->MultiCell(0, 6, $task->getText(), 1); //$pdf->Ln(); } } $pdf->Output($download_name, 'I'); } if ($output == 'txt') { $download_name = "{$project_name}-tasks.txt"; $download_type = 'text/csv'; $txt_lang_1 = lang('project'); $txt_lang_2 = lang('milestone'); $txt_lang_3 = lang('task list'); $txt_lang_4 = lang('status'); $txt_lang_5 = lang('description'); $txt_lang_6 = lang('id'); $txt_lang_7 = lang('status'); $txt_lang_8 = lang('completion info'); $txt_lang_9 = lang('assigned to'); $s .= "{$txt_lang_1}\t{$txt_lang_2}\t{$txt_lang_3}\t{$txt_lang_4}\t{$txt_lang_5}\t{$txt_lang_6}\t{$txt_lang_7}\t{$txt_lang_8}\t{$txt_lang_9}"; $s .= "\n"; $task_lists = active_project()->getOpenTaskLists(); foreach ($task_lists as $task_list) { /*$s .= $task_list->getObjectName(); $s .= "\n"; $task_list_desc = $task_list->getDescription(); $task_list_desc = strtr($task_list_desc,"\r\n\t"," "); $task_list_desc_100 = substr($task_list_desc,0,100); $s .= $task_list_desc_100; $s .= "\n";*/ $milestone = $task_list->getMilestone(); $tasks = $task_list->getTasks(); foreach ($tasks as $task) { $s .= $project_name; $s .= "\t"; $milestone_name = lang(none); if ($milestone instanceof ProjectMilestone) { $milestone_name = $milestone->getName(); } $s .= $milestone_name; $s .= "\t"; $s .= $task_list->getObjectName(); $s .= "\t"; $task_list_name = $task_list->getName(); if ($task_list->isCompleted()) { $task_list_status = lang('completed'); } else { $task_list_status = lang('open'); } $s .= $task_list_status; $s .= "\t"; $task_list_desc2 = $task_list->getDescription(); $task_list_desc2 = strtr($task_list_desc2, "\r\n\t", " "); $task_list_desc2_100 = substr($task_list_desc2, 0, 50); $s .= $task_list_desc2_100; $s .= "\t"; $s .= $task->getId(); $s .= "\t"; if ($task->isCompleted()) { $task_status = lang('completed'); $task_completion_info = format_date($task->getCompletedOn()) . " @ " . format_time($task->getCompletedOn()); } else { $task_status = lang('open'); $task_completion_info = format_date($task->getDueDate()) . " @ " . format_time($task->getDueDate()); } $s .= $task_status; $s .= "\t"; $s .= $task_completion_info; $s .= "\t"; if ($task->getAssignedTo()) { $task_assignee = $task->getAssignedTo()->getObjectName(); } else { $task_assignee = lang('not assigned'); } $s .= $task_assignee; $s .= "\n"; } } $download_contents = $s; download_headers($download_name, $download_type, strlen($download_contents), true); echo $download_contents; } else { $download_name = "{$project_name}-{$task_list_name}-tasks.csv"; $download_type = 'text/csv'; $download_contents = $task_list->getDownloadText($task_count, "\t", true); download_contents($download_contents, $download_type, $download_name, strlen($download_contents)); } die; }