/** * Fonction generant le projet sur le disque * * @param Project $object Object project a generer * @param Translate $outputlangs Lang output object * @return int 1 if OK, <=0 if KO */ function write_file($object, $outputlangs) { global $conf, $hookmanager, $langs, $user; if (!is_object($outputlangs)) { $outputlangs = $langs; } // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (!empty($conf->global->MAIN_USE_FPDF)) { $outputlangs->charset_output = 'ISO-8859-1'; } $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("projects"); if ($conf->projet->dir_output) { //$nblignes = count($object->lines); // This is set later with array of tasks $objectref = dol_sanitizeFileName($object->ref); $dir = $conf->projet->dir_output; if (!preg_match('/specimen/i', $objectref)) { $dir .= "/" . $objectref; } $file = $dir . "/" . $objectref . ".pdf"; if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } } if (file_exists($dir)) { // Add pdfgeneration hook if (!is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; $hookmanager = new HookManager($this->db); } $hookmanager->initHooks(array('pdfgeneration')); $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); global $action; $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $pdf = pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance $heightforinfotot = 50; // Height reserved to output the info and total part $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5; // Height reserved to output the free text on last page $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1, 0); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); // Complete object by loading several other informations $task = new Task($this->db); $tasksarray = $task->getTasksArray(0, 0, $object->id); if (!$object->id > 0) { $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray))); } $object->lines = $tasksarray; $nblignes = count($object->lines); $pdf->Open(); $pagenb = 0; $pdf->SetDrawColor(128, 128, 128); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("Project")); $pdf->SetCreator("Dolibarr " . DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Project")); if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) { $pdf->SetCompression(false); } $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right // New page $pdf->AddPage(); $pagenb++; $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0, 0, 0); $tab_top = 50; $tab_height = 200; $tab_top_newpage = 40; $tab_height_newpage = 210; // Affiche notes if (!empty($object->note_public)) { $pdf->SetFont('', '', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($object->note_public), 0, 1); $nexY = $pdf->GetY(); $height_note = $nexY - ($tab_top - 2); // Rect prend une longueur en 3eme param $pdf->SetDrawColor(192, 192, 192); $pdf->Rect($this->marge_gauche, $tab_top - 3, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1); $tab_height = $tab_height - $height_note; $tab_top = $nexY + 6; } else { $height_note = 0; } $iniY = $tab_top + 7; $curY = $tab_top + 7; $nexY = $tab_top + 7; // Boucle sur les lignes for ($i = 0; $i < $nblignes; $i++) { $curY = $nexY; // Description of ligne $ref = $object->lines[$i]->ref; $libelleline = $object->lines[$i]->label; $progress = $object->lines[$i]->progress . '%'; $datestart = dol_print_date($object->lines[$i]->date_start, 'day'); $dateend = dol_print_date($object->lines[$i]->date_end, 'day'); $planned_workload = convertSecondToTime($object->lines[$i]->planned_workload, 'allhourmin'); $pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page $pdf->SetXY($this->posxref, $curY); $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0, 'L'); $pdf->SetXY($this->posxlabel, $curY); $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L'); $pdf->SetXY($this->posxworkload, $curY); $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload, 0, 'R'); $pdf->SetXY($this->posxprogress, $curY); $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0, 'R'); $pdf->SetXY($this->posxdatestart, $curY); $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0, 'C'); $pdf->SetXY($this->posxdateend, $curY); $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0, 'C'); $pageposafter = $pdf->getPage(); $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut $nexY = $pdf->GetY(); // Add line if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblignes - 1) { $pdf->setPage($pageposafter); $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80))); //$pdf->SetDrawColor(190,190,200); $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1); $pdf->SetLineStyle(array('dash' => 0)); } $nexY += 2; // Passe espace entre les lignes // Detect if some page were added automatically and output _tableau for past pages while ($pagenb < $pageposafter) { $pdf->setPage($pagenb); if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); } $this->_pagefoot($pdf, $object, $outputlangs, 1); $pagenb++; $pdf->setPage($pagenb); $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. } if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); } $this->_pagefoot($pdf, $object, $outputlangs, 1); // New page $pdf->AddPage(); if (!empty($tplidx)) { $pdf->useTemplate($tplidx); } $pagenb++; } } // Show square if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } /* * Pied de page */ $this->_pagefoot($pdf, $object, $outputlangs); if (method_exists($pdf, 'AliasNbPages')) { $pdf->AliasNbPages(); } $pdf->Close(); $pdf->Output($file, 'F'); // Add pdfgeneration hook if (!is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; $hookmanager = new HookManager($this->db); } $hookmanager->initHooks(array('pdfgeneration')); $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); global $action; $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } return 1; // Pas d'erreur } else { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } } $this->error = $langs->transnoentities("ErrorConstantNotDefined", "LIVRAISON_OUTPUTDIR"); return 0; }
print '<br>'; // Link to switch in "my task" / "all task" print '<table width="100%"><tr><td align="right">'; if ($mode == 'mine') { print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">' . $langs->trans("DoNotShowMyTasksOnly") . '</a>'; //print ' - '; //print $langs->trans("ShowMyTaskOnly"); } else { //print $langs->trans("DoNotShowMyTaskOnly"); //print ' - '; print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&mode=mine">' . $langs->trans("ShowMyTasksOnly") . '</a>'; } print '</td></tr></table>'; // Get list of tasks in tasksarray and taskarrayfiltered // We need all tasks (even not limited to a user because a task to user can have a parent that is not affected to him). $tasksarray = $taskstatic->getTasksArray(0, 0, $object->id, $socid, 0); // We load also tasks limited to a particular user $tasksrole = $mode == 'mine' ? $taskstatic->getUserRolesForProjectsOrTasks(0, $user, $object->id, 0) : ''; //var_dump($tasksarray); //var_dump($tasksrole); if (!empty($conf->use_javascript_ajax)) { include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } print '<table id="tablelines" class="noborder" width="100%">'; print '<tr class="liste_titre nodrag nodrop">'; // print '<td>'.$langs->trans("Project").'</td>'; print '<td width="100">' . $langs->trans("RefTask") . '</td>'; print '<td>' . $langs->trans("LabelTask") . '</td>'; print '<td align="center">' . $langs->trans("DateStart") . '</td>'; print '<td align="center">' . $langs->trans("DateEnd") . '</td>'; print '<td align="right">' . $langs->trans("PlannedWorkload") . '</td>';
// Get list of project id allowed to user (in a string list separated by coma) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 1, $socid); //var_dump($projectsListId); // Get list of tasks in tasksarray and taskarrayfiltered // We need all tasks (even not limited to a user because a task assigned to a user can have a parent that is not assigned to him and we need such parents). $morewherefilter = ''; if ($search_all) { $morewherefilter .= natural_search(array_keys($fieldstosearchall), $search_all); } if ($search_task_ref) { $morewherefilter .= natural_search('t.ref', $search_task_ref); } if ($search_task_label) { $morewherefilter .= natural_search('t.label', $search_task_label); } $tasksarray = $taskstatic->getTasksArray(0, 0, $projectstatic->id, $socid, 0, $search_project, $search_status, $morewherefilter, $search_project_user, 0); // We don't use filter on task user. Because sometimes a task is assigned but not the parent one and we want to show also parent, so filtering is done during output $tasksrole = $taskstatic->getUserRolesForProjectsOrTasks(0, $tuser->id ? $tuser : null, $projectstatic->id, 0, $search_status); // We load also tasks limited to a particular user print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">'; if ($optioncss != '') { print '<input type="hidden" name="optioncss" value="' . $optioncss . '">'; } print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; print '<input type="hidden" name="action" value="list">'; print '<input type="hidden" name="sortfield" value="' . $sortfield . '">'; print '<input type="hidden" name="sortorder" value="' . $sortorder . '">'; print '<input type="hidden" name="type" value="' . $type . '">'; if ($search_all) { foreach ($fieldstosearchall as $key => $val) { $fieldstosearchall[$key] = $langs->trans($val);
$next_month = $next['mon']; $next_day = $next['mday']; $title = $langs->trans("TimeSpent"); if ($mine) { $title = $langs->trans("MyTimeSpent"); } $usertoprocess = $user; $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertoprocess, 0, 1); // Return all project i have permission on. I want my tasks and some of my task may be on a public projet that is not my project if ($id) { $project->fetch($id); $project->fetch_thirdparty(); } $onlyopenedproject = 1; // or -1 $tasksarray = $taskstatic->getTasksArray(0, 0, $project->id ? $project->id : 0, $socid, 0, '', $onlyopenedproject); // We want to see all task of opened project i am allowed to see, not only mine. Later only mine will be editable later. $projectsrole = $taskstatic->getUserRolesForProjectsOrTasks($usertoprocess, 0, $project->id ? $project->id : 0, 0, $onlyopenedproject); $tasksrole = $taskstatic->getUserRolesForProjectsOrTasks(0, $usertoprocess, $project->id ? $project->id : 0, 0, $onlyopenedproject); //var_dump($tasksarray); //var_dump($projectsrole); //var_dump($taskrole); llxHeader("", $title, ""); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num, '', 'title_project'); $param = $mode ? '&mode=' . $mode : ''; // Show navigation bar $nav = "<a href=\"?year=" . $prev_year . "&month=" . $prev_month . "&day=" . $prev_day . $param . "\">" . img_previous($langs->trans("Previous")) . "</a>\n"; $nav .= " <span id=\"month_name\">" . dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "day") . " </span>\n"; $nav .= "<a href=\"?year=" . $next_year . "&month=" . $next_month . "&day=" . $next_day . $param . "\">" . img_next($langs->trans("Next")) . "</a>\n"; $nav .= " (<a href=\"?year=" . $nowyear . "&month=" . $nowmonth . "&day=" . $nowday . $param . "\">" . $langs->trans("Today") . "</a>)"; $nav .= '<br>' . $form->select_date(-1, '', 0, 0, 2, "addtime", 1, 0, 1) . ' ';
/** * Fonction generant le projet sur le disque * * @param Project $object Object project a generer * @param Translate $outputlangs Lang output object * @return int 1 if OK, <=0 if KO */ function write_file($object, $outputlangs) { global $user, $langs, $conf; $formproject = new FormProjets($this->db); if (!is_object($outputlangs)) { $outputlangs = $langs; } // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (!empty($conf->global->MAIN_USE_FPDF)) { $outputlangs->charset_output = 'ISO-8859-1'; } $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("projects"); if ($conf->projet->dir_output) { //$nblignes = count($object->lines); // This is set later with array of tasks $objectref = dol_sanitizeFileName($object->ref); $dir = $conf->projet->dir_output; if (!preg_match('/specimen/i', $objectref)) { $dir .= "/" . $objectref; } $file = $dir . "/" . $objectref . ".pdf"; if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } } if (file_exists($dir)) { // Add pdfgeneration hook if (!is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; $hookmanager = new HookManager($this->db); } $hookmanager->initHooks(array('pdfgeneration')); $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); global $action; $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $pdf = pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance $heightforinfotot = 50; // Height reserved to output the info and total part $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5; // Height reserved to output the free text on last page $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1, 0); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); // Complete object by loading several other informations $task = new Task($this->db); $tasksarray = $task->getTasksArray(0, 0, $object->id); $object->lines = $tasksarray; $nblignes = count($object->lines); $pdf->Open(); $pagenb = 0; $pdf->SetDrawColor(128, 128, 128); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("Project")); $pdf->SetCreator("Dolibarr " . DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Project")); if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) { $pdf->SetCompression(false); } $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right // New page $pdf->AddPage(); $pagenb++; $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0, 0, 0); $tab_top = 50; $tab_height = 200; $tab_top_newpage = 40; $tab_height_newpage = 210; // Affiche notes if (!empty($object->note_public)) { $pdf->SetFont('', '', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($object->note_public), 0, 1); $nexY = $pdf->GetY(); $height_note = $nexY - ($tab_top - 2); // Rect prend une longueur en 3eme param $pdf->SetDrawColor(192, 192, 192); $pdf->Rect($this->marge_gauche, $tab_top - 3, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1); $tab_height = $tab_height - $height_note; $tab_top = $nexY + 6; } else { $height_note = 0; } $iniY = $tab_top + 7; $curY = $tab_top + 7; $nexY = $tab_top + 7; $listofreferent = array('propal' => array('name' => "Proposals", 'title' => "ListProposalsAssociatedProject", 'class' => 'Propal', 'table' => 'propal', 'datefieldname' => 'datep', 'test' => $conf->propal->enabled && $user->rights->propale->lire), 'order' => array('name' => "CustomersOrders", 'title' => "ListOrdersAssociatedProject", 'class' => 'Commande', 'table' => 'commande', 'datefieldname' => 'date_commande', 'test' => $conf->commande->enabled && $user->rights->commande->lire), 'invoice' => array('name' => "CustomersInvoices", 'title' => "ListInvoicesAssociatedProject", 'class' => 'Facture', 'margin' => 'add', 'table' => 'facture', 'datefieldname' => 'datef', 'test' => $conf->facture->enabled && $user->rights->facture->lire), 'invoice_predefined' => array('name' => "PredefinedInvoices", 'title' => "ListPredefinedInvoicesAssociatedProject", 'class' => 'FactureRec', 'table' => 'facture_rec', 'datefieldname' => 'datec', 'test' => $conf->facture->enabled && $user->rights->facture->lire), 'order_supplier' => array('name' => "SuppliersOrders", 'title' => "ListSupplierOrdersAssociatedProject", 'class' => 'CommandeFournisseur', 'table' => 'commande_fournisseur', 'datefieldname' => 'date_commande', 'test' => $conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire), 'invoice_supplier' => array('name' => "BillsSuppliers", 'title' => "ListSupplierInvoicesAssociatedProject", 'class' => 'FactureFournisseur', 'margin' => 'minus', 'table' => 'facture_fourn', 'datefieldname' => 'datef', 'test' => $conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire), 'contract' => array('name' => "Contracts", 'title' => "ListContractAssociatedProject", 'class' => 'Contrat', 'table' => 'contrat', 'datefieldname' => 'date_contrat', 'test' => $conf->contrat->enabled && $user->rights->contrat->lire), 'intervention' => array('name' => "Interventions", 'title' => "ListFichinterAssociatedProject", 'class' => 'Fichinter', 'table' => 'fichinter', 'datefieldname' => 'date_valid', 'disableamount' => 1, 'test' => $conf->ficheinter->enabled && $user->rights->ficheinter->lire), 'trip' => array('name' => "TripsAndExpenses", 'title' => "ListTripAssociatedProject", 'class' => 'Deplacement', 'table' => 'deplacement', 'datefieldname' => 'dated', 'margin' => 'minus', 'disableamount' => 1, 'test' => $conf->deplacement->enabled && $user->rights->deplacement->lire), 'agenda' => array('name' => "Agenda", 'title' => "ListActionsAssociatedProject", 'class' => 'ActionComm', 'table' => 'actioncomm', 'datefieldname' => 'datep', 'disableamount' => 1, 'test' => $conf->agenda->enabled && $user->rights->agenda->allactions->lire)); foreach ($listofreferent as $key => $value) { $title = $value['title']; $classname = $value['class']; $tablename = $value['table']; $datefieldname = $value['datefieldname']; $qualified = $value['test']; if ($qualified) { $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee); $num = count($elementarray); if ($num > 0) { $nexY = $pdf->GetY() + 5; $curY = $nexY; $pdf->SetXY($this->posxref, $curY); $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0, 'L'); $selectList = $formproject->select_element($tablename, $project->thirdparty->id); $nexY = $pdf->GetY() + 1; $curY = $nexY; $pdf->SetXY($this->posxref, $curY); $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities("Ref"), 1, 'L'); $pdf->SetXY($this->posxdate, $curY); $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities("Date"), 1, 'C'); $pdf->SetXY($this->posxsociety, $curY); $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $outputlangs->transnoentities("ThirdParty"), 1, 'L'); if (empty($value['disableamount'])) { $pdf->SetXY($this->posxamountht, $curY); $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities("AmountHT"), 1, 'R'); $pdf->SetXY($this->posxamountttc, $curY); $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities("AmountTTC"), 1, 'R'); } else { $pdf->SetXY($this->posxamountht, $curY); $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R'); } $pdf->SetXY($this->posxstatut, $curY); $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Statut"), 1, 'R'); if (is_array($elementarray) && count($elementarray) > 0) { $nexY = $pdf->GetY(); $curY = $nexY; $total_ht = 0; $total_ttc = 0; $num = count($elementarray); for ($i = 0; $i < $num; $i++) { $element = new $classname($this->db); $element->fetch($elementarray[$i]); $element->fetch_thirdparty(); // print $classname; $qualifiedfortotal = true; if ($key == 'invoice') { if ($element->close_code == 'replaced') { $qualifiedfortotal = false; } // Replacement invoice } $pdf->SetXY($this->posxref, $curY); $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L'); // Date if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') { $date = $element->date_commande; } else { $date = $element->date; if (empty($date)) { $date = $element->datep; } if (empty($date)) { $date = $element->date_contrat; } if (empty($date)) { $date = $element->datev; } // Fiche inter } $pdf->SetXY($this->posxdate, $curY); $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, dol_print_date($date, 'day'), 1, 'C'); $pdf->SetXY($this->posxsociety, $curY); if (is_object($element->thirdparty)) { $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $element->thirdparty->name, 1, 'L'); } // Amount without tax if (empty($value['disableamount'])) { $pdf->SetXY($this->posxamountht, $curY); $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, isset($element->total_ht) ? price($element->total_ht) : ' ', 1, 'R'); $pdf->SetXY($this->posxamountttc, $curY); $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, isset($element->total_ttc) ? price($element->total_ttc) : ' ', 1, 'R'); } else { $pdf->SetXY($this->posxamountht, $curY); $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R'); } // Status if ($element instanceof CommonInvoice) { // This applies for Facture and FactureFournisseur $outputstatut = $element->getLibStatut(1, $element->getSommePaiement()); } else { $outputstatut = $element->getLibStatut(1); } $pdf->SetXY($this->posxstatut, $curY); $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1, 'R', false, 1, '', '', true, 0, true); if ($qualifiedfortotal) { $total_ht = $total_ht + $element->total_ht; $total_ttc = $total_ttc + $element->total_ttc; } $nexY = $pdf->GetY(); $curY = $nexY; } if (empty($value['disableamount'])) { $curY = $nexY; $pdf->SetXY($this->posxref, $curY); $pdf->MultiCell($this->posxamountttc - $this->posxref, 3, "TOTAL", 1, 'L'); $pdf->SetXY($this->posxamountht, $curY); $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, isset($element->total_ht) ? price($total_ht) : ' ', 1, 'R'); $pdf->SetXY($this->posxamountttc, $curY); $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, isset($element->total_ttc) ? price($total_ttc) : ' ', 1, 'R'); $pdf->SetXY($this->posxstatut, $curY); $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Nb") . " " . $num, 1, 'L'); } $nexY = $pdf->GetY() + 5; $curY = $nexY; } } } } /* * Pied de page */ $this->_pagefoot($pdf, $object, $outputlangs); if (method_exists($pdf, 'AliasNbPages')) { $pdf->AliasNbPages(); } $pdf->Close(); $pdf->Output($file, 'F'); // Add pdfgeneration hook if (!is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; $hookmanager = new HookManager($this->db); } $hookmanager->initHooks(array('pdfgeneration')); $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); global $action; $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } return 1; // Pas d'erreur } else { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } } $this->error = $langs->transnoentities("ErrorConstantNotDefined", "LIVRAISON_OUTPUTDIR"); return 0; }
/** * Function to build a document on disk using the generic odt module. * * @param Project $object Object source to build document * @param Translate $outputlangs Lang output object * @param string $srctemplatepath Full path of source filename for generator using a template file * @return int 1 if OK, <=0 if KO */ function write_file($object, $outputlangs, $srctemplatepath) { global $user, $langs, $conf, $mysoc, $hookmanager; if (empty($srctemplatepath)) { dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); return -1; } // Add odtgeneration hook if (!is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; $hookmanager = new HookManager($this->db); } $hookmanager->initHooks(array('odtgeneration')); global $action; if (!is_object($outputlangs)) { $outputlangs = $langs; } $sav_charset_output = $outputlangs->charset_output; $outputlangs->charset_output = 'UTF-8'; $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("projects"); if ($conf->projet->dir_output) { // If $object is id instead of object if (!is_object($object)) { $id = $object; $object = new Project($this->db); $result = $object->fetch($id); if ($result < 0) { dol_print_error($this->db, $object->error); return -1; } } $dir = $conf->projet->dir_output; $objectref = dol_sanitizeFileName($object->ref); if (!preg_match('/specimen/i', $objectref)) { $dir .= "/" . $objectref; } $file = $dir . "/" . $objectref . ".odt"; if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return -1; } } if (file_exists($dir)) { //print "srctemplatepath=".$srctemplatepath; // Src filename $newfile = basename($srctemplatepath); $newfiletmp = preg_replace('/\\.od(t|s)/i', '', $newfile); $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); $newfiletmp = $objectref . '_' . $newfiletmp; //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; // Get extension (ods or odt) $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); if (!empty($conf->global->MAIN_DOC_USE_TIMING)) { $filename = $newfiletmp . '.' . dol_print_date(dol_now(), '%Y%m%d%H%M%S') . '.' . $newfileformat; } else { $filename = $newfiletmp . '.' . $newfileformat; } $file = $dir . '/' . $filename; //print "newdir=".$dir; //print "newfile=".$newfile; //print "file=".$file; //print "conf->societe->dir_temp=".$conf->societe->dir_temp; dol_mkdir($conf->projet->dir_temp); $socobject = $object->thirdparty; // Make substitution $substitutionarray = array('__FROM_NAME__' => $this->emetteur->nom, '__FROM_EMAIL__' => $this->emetteur->email); complete_substitutions_array($substitutionarray, $langs, $object); // Open and load template require_once ODTPHP_PATH . 'odf.php'; try { $odfHandler = new odf($srctemplatepath, array('PATH_TO_TMP' => $conf->projet->dir_temp, 'ZIP_PROXY' => 'PclZipProxy', 'DELIMITER_LEFT' => '{', 'DELIMITER_RIGHT' => '}')); } catch (Exception $e) { $this->error = $e->getMessage(); return -1; } // After construction $odfHandler->contentXml contains content and // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by // [!-- BEGIN lines --]*[!-- END lines --] //print html_entity_decode($odfHandler->__toString()); //print exit; // Make substitutions into odt of user info $tmparray = $this->get_substitutionarray_user($user, $outputlangs); foreach ($tmparray as $key => $value) { try { if (preg_match('/logo$/', $key)) { //var_dump($value);exit; if (file_exists($value)) { $odfHandler->setImage($key, $value); } else { $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); } } else { $odfHandler->setVars($key, $value, true, 'UTF-8'); } } catch (OdfException $e) { } } // Make substitutions into odt of mysoc $tmparray = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); //var_dump($tmparray); exit; foreach ($tmparray as $key => $value) { try { if (preg_match('/logo$/', $key)) { //var_dump($value);exit; if (file_exists($value)) { $odfHandler->setImage($key, $value); } else { $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); } } else { $odfHandler->setVars($key, $value, true, 'UTF-8'); } } catch (OdfException $e) { } } // Make substitutions into odt of thirdparty $tmparray = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); foreach ($tmparray as $key => $value) { try { if (preg_match('/logo$/', $key)) { if (file_exists($value)) { $odfHandler->setImage($key, $value); } else { $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); } } else { $odfHandler->setVars($key, $value, true, 'UTF-8'); } } catch (OdfException $e) { } } // Replace tags of object + external modules $tmparray = $this->get_substitutionarray_object($object, $outputlangs); complete_substitutions_array($tmparray, $outputlangs, $object); // Call the ODTSubstitution hook $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray); $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks foreach ($tmparray as $key => $value) { try { if (preg_match('/logo$/', $key)) { if (file_exists($value)) { $odfHandler->setImage($key, $value); } else { $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); } } else { $odfHandler->setVars($key, $value, true, 'UTF-8'); } } catch (OdfException $e) { } } // Replace tags of lines for tasks try { $listlines = $odfHandler->setSegment('tasks'); $taskstatic = new Task($this->db); // Security check $socid = 0; if (!empty($object->fk_soc)) { $socid = $object->fk_soc; } $tasksarray = $taskstatic->getTasksArray(0, 0, $object->id, $socid, 0); foreach ($tasksarray as $task) { $tmparray = $this->get_substitutionarray_tasks($task, $outputlangs); //complete_substitutions_array($tmparray, $outputlangs, $object, $task, "completesubstitutionarray_lines"); foreach ($tmparray as $key => $val) { try { $listlines->setVars($key, $val, true, 'UTF-8'); } catch (OdfException $e) { } catch (SegmentException $e) { } } $taskobj = new Task($this->db); $taskobj->fetch($task->id); // Replace tags of lines for contacts task $sourcearray = array('internal', 'external'); $contact_arrray = array(); foreach ($sourcearray as $source) { $contact_temp = $taskobj->liste_contact(-1, $source); if (is_array($contact_temp) && count($contact_temp) > 0) { $contact_arrray = array_merge($contact_arrray, $contact_temp); } } if (is_array($contact_arrray) && count($contact_arrray) > 0) { $listlinestaskres = $listlines->__get('tasksressources'); foreach ($contact_arrray as $contact) { if ($contact['source'] == 'internal') { $objectdetail = new User($this->db); $objectdetail->fetch($contact['id']); $contact['socname'] = $mysoc->name; } elseif ($contact['source'] == 'external') { $objectdetail = new Contact($this->db); $objectdetail->fetch($contact['id']); $soc = new Societe($this->db); $soc->fetch($contact['socid']); $contact['socname'] = $soc->name; } $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1); $tmparray = $this->get_substitutionarray_tasksressource($contact, $outputlangs); foreach ($tmparray as $key => $val) { try { $listlinestaskres->setVars($key, $val, true, 'UTF-8'); } catch (OdfException $e) { } catch (SegmentException $e) { } } $listlinestaskres->merge(); } } //Time ressources $sql = "SELECT t.rowid, t.task_date, t.task_duration, t.fk_user, t.note"; $sql .= ", u.lastname, u.firstname"; $sql .= " FROM " . MAIN_DB_PREFIX . "projet_task_time as t"; $sql .= " , " . MAIN_DB_PREFIX . "user as u"; $sql .= " WHERE t.fk_task =" . $task->id; $sql .= " AND t.fk_user = u.rowid"; $sql .= " ORDER BY t.task_date DESC"; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; $tasks = array(); $listlinestasktime = $listlines->__get('taskstimes'); while ($i < $num) { $row = $this->db->fetch_array($resql); if (!empty($row['fk_user'])) { $objectdetail = new User($this->db); $objectdetail->fetch($row['fk_user']); $row['fullcivname'] = $objectdetail->getFullName($outputlangs, 1); } else { $row['fullcivname'] = ''; } $tmparray = $this->get_substitutionarray_taskstime($row, $outputlangs); foreach ($tmparray as $key => $val) { try { $listlinestasktime->setVars($key, $val, true, 'UTF-8'); } catch (OdfException $e) { } catch (SegmentException $e) { } } $listlinestasktime->merge(); $i++; } $this->db->free($resql); } // Replace tags of project files $listtasksfiles = $listlines->__get('tasksfiles'); $upload_dir = $conf->projet->dir_output . '/' . dol_sanitizeFileName($object->ref) . '/' . dol_sanitizeFileName($task->ref); $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\\.meta|_preview\\.png)$', 'name', SORT_ASC, 1); foreach ($filearray as $filedetail) { $tmparray = $this->get_substitutionarray_task_file($filedetail, $outputlangs); //dol_syslog(get_class($this).'::main $tmparray'.var_export($tmparray,true)); foreach ($tmparray as $key => $val) { try { $listtasksfiles->setVars($key, $val, true, 'UTF-8'); } catch (OdfException $e) { } catch (SegmentException $e) { } } $listtasksfiles->merge(); } $listlines->merge(); } $odfHandler->mergeSegment($listlines); } catch (OdfException $e) { $this->error = $e->getMessage(); dol_syslog($this->error, LOG_WARNING); return -1; } // Replace tags of project files try { $listlines = $odfHandler->setSegment('projectfiles'); $upload_dir = $conf->projet->dir_output . '/' . dol_sanitizeFileName($object->ref); $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\\.meta|_preview\\.png)$', 'name', SORT_ASC, 1); foreach ($filearray as $filedetail) { //dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true)); $tmparray = $this->get_substitutionarray_project_file($filedetail, $outputlangs); foreach ($tmparray as $key => $val) { try { $listlines->setVars($key, $val, true, 'UTF-8'); } catch (OdfException $e) { } catch (SegmentException $e) { } } $listlines->merge(); } $odfHandler->mergeSegment($listlines); } catch (OdfException $e) { $this->error = $e->getMessage(); dol_syslog($this->error, LOG_WARNING); return -1; } // Replace tags of lines for contacts $sourcearray = array('internal', 'external'); $contact_arrray = array(); foreach ($sourcearray as $source) { $contact_temp = $object->liste_contact(-1, $source); if (is_array($contact_temp) && count($contact_temp) > 0) { $contact_arrray = array_merge($contact_arrray, $contact_temp); } } if (is_array($contact_arrray) && count($contact_arrray) > 0) { try { $listlines = $odfHandler->setSegment('projectcontacts'); foreach ($contact_arrray as $contact) { if ($contact['source'] == 'internal') { $objectdetail = new User($this->db); $objectdetail->fetch($contact['id']); $contact['socname'] = $mysoc->name; } elseif ($contact['source'] == 'external') { $objectdetail = new Contact($this->db); $objectdetail->fetch($contact['id']); $soc = new Societe($this->db); $soc->fetch($contact['socid']); $contact['socname'] = $soc->name; } $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1); $tmparray = $this->get_substitutionarray_project_contacts($contact, $outputlangs); foreach ($tmparray as $key => $val) { try { $listlines->setVars($key, $val, true, 'UTF-8'); } catch (OdfException $e) { } catch (SegmentException $e) { } } $listlines->merge(); } $odfHandler->mergeSegment($listlines); } catch (OdfException $e) { $this->error = $e->getMessage(); dol_syslog($this->error, LOG_WARNING); return -1; } } //List of referent $listofreferent = array('propal' => array('title' => "ListProposalsAssociatedProject", 'class' => 'Propal', 'table' => 'propal', 'test' => $conf->propal->enabled && $user->rights->propale->lire), 'order' => array('title' => "ListOrdersAssociatedProject", 'class' => 'Commande', 'table' => 'commande', 'test' => $conf->commande->enabled && $user->rights->commande->lire), 'invoice' => array('title' => "ListInvoicesAssociatedProject", 'class' => 'Facture', 'table' => 'facture', 'test' => $conf->facture->enabled && $user->rights->facture->lire), 'invoice_predefined' => array('title' => "ListPredefinedInvoicesAssociatedProject", 'class' => 'FactureRec', 'table' => 'facture_rec', 'test' => $conf->facture->enabled && $user->rights->facture->lire), 'order_supplier' => array('title' => "ListSupplierOrdersAssociatedProject", 'table' => 'commande_fournisseur', 'class' => 'CommandeFournisseur', 'test' => $conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire), 'invoice_supplier' => array('title' => "ListSupplierInvoicesAssociatedProject", 'table' => 'facture_fourn', 'class' => 'FactureFournisseur', 'test' => $conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire), 'contract' => array('title' => "ListContractAssociatedProject", 'class' => 'Contrat', 'table' => 'contrat', 'test' => $conf->contrat->enabled && $user->rights->contrat->lire), 'intervention' => array('title' => "ListFichinterAssociatedProject", 'class' => 'Fichinter', 'table' => 'fichinter', 'disableamount' => 1, 'test' => $conf->ficheinter->enabled && $user->rights->ficheinter->lire), 'trip' => array('title' => "ListTripAssociatedProject", 'class' => 'Deplacement', 'table' => 'deplacement', 'disableamount' => 1, 'test' => $conf->deplacement->enabled && $user->rights->deplacement->lire), 'agenda' => array('title' => "ListActionsAssociatedProject", 'class' => 'ActionComm', 'table' => 'actioncomm', 'disableamount' => 1, 'test' => $conf->agenda->enabled && $user->rights->agenda->allactions->lire)); //Insert reference try { $listlines = $odfHandler->setSegment('projectrefs'); foreach ($listofreferent as $keyref => $valueref) { $title = $valueref['title']; $tablename = $valueref['table']; $classname = $valueref['class']; $qualified = $valueref['test']; if ($qualified) { $elementarray = $object->get_element_list($keyref, $tablename); if (count($elementarray) > 0 && is_array($elementarray)) { $var = true; $total_ht = 0; $total_ttc = 0; $num = count($elementarray); for ($i = 0; $i < $num; $i++) { $ref_array = array(); $ref_array['type'] = $langs->trans($classname); $element = new $classname($this->db); $element->fetch($elementarray[$i]); $element->fetch_thirdparty(); //Ref object $ref_array['ref'] = $element->ref; //Date object $dateref = $element->date; if (empty($dateref)) { $dateref = $element->datep; } if (empty($dateref)) { $dateref = $element->date_contrat; } $ref_array['date'] = $dateref; //Soc object if (is_object($element->thirdparty)) { $ref_array['socname'] = $element->thirdparty->name; } else { $ref_array['socname'] = ''; } //Amount object if (empty($valueref['disableamount'])) { if (!empty($element->total_ht)) { $ref_array['amountht'] = $element->total_ht; $ref_array['amountttc'] = $element->total_ttc; } else { $ref_array['amountht'] = 0; $ref_array['amountttc'] = 0; } } else { $ref_array['amountht'] = ''; $ref_array['amountttc'] = ''; } $ref_array['status'] = $element->getLibStatut(0); $tmparray = $this->get_substitutionarray_project_reference($ref_array, $outputlangs); foreach ($tmparray as $key => $val) { try { $listlines->setVars($key, $val, true, 'UTF-8'); } catch (OdfException $e) { } catch (SegmentException $e) { } } $listlines->merge(); } } } $odfHandler->mergeSegment($listlines); } } catch (OdfException $e) { $this->error = $e->getMessage(); dol_syslog($this->error, LOG_WARNING); return -1; } // Replace labels translated $tmparray = $outputlangs->get_translations_for_substitutions(); foreach ($tmparray as $key => $value) { try { $odfHandler->setVars($key, $value, true, 'UTF-8'); } catch (OdfException $e) { } } // Call the beforeODTSave hook $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks // Write new file if (!empty($conf->global->MAIN_ODT_AS_PDF)) { try { $odfHandler->exportAsAttachedPDF($file); } catch (Exception $e) { $this->error = $e->getMessage(); return -1; } } else { try { $odfHandler->saveToDisk($file); } catch (Exception $e) { $this->error = $e->getMessage(); return -1; } } if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } $odfHandler = null; // Destroy object return 1; // Success } else { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return -1; } } return -1; }
$project = new Project($db); $taskstatic = new Task($db); $title = $langs->trans("TimeSpent"); if ($mine) { $title = $langs->trans("MyTimeSpent"); } //$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1); $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1); // Return all project i have permission on. I want my tasks and some of my task may be on a public projet that is not my project if ($id) { $project->fetch($id); $project->fetch_thirdparty(); } $onlyopened = 1; // or -1 $tasksarray = $taskstatic->getTasksArray(0, 0, $project->id ? $project->id : $projectsListId, $socid, 0, '', $onlyopened); // We want to see all task of opened project i am allowed to see, not only mine. Later only mine will be editable later. $projectsrole = $taskstatic->getUserRolesForProjectsOrTasks($user, 0, $project->id ? $project->id : $projectsListId, 0); $tasksrole = $taskstatic->getUserRolesForProjectsOrTasks(0, $user, $project->id ? $project->id : $projectsListId, 0); //var_dump($tasksarray); //var_dump($projectsrole); //var_dump($taskrole); llxHeader("", $title, ""); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num); // Show description of content if ($mine) { print $langs->trans("MyTasksDesc") . ($onlyopened ? ' ' . $langs->trans("OnlyOpenedProject") : '') . '<br><br>'; } else { if ($user->rights->projet->all->lire && !$socid) { print $langs->trans("ProjectsDesc") . ($onlyopened ? ' ' . $langs->trans("OnlyOpenedProject") : '') . '<br><br>'; } else {
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num); // Show description of content if ($mine) print $langs->trans("MyProjectsDesc").'<br><br>'; else { if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'<br><br>'; else print $langs->trans("ProjectsPublicDesc").'<br><br>'; } // Get list of project id allowed to user $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1,$socid); // Get list of tasks in tasksarray and taskarrayfiltered // We need all tasks (even not limited to a user because a task to user // can have a parent that is not affected to him). $tasksarray=$taskstatic->getTasksArray(0, 0, $projectstatic->id, $socid, 0); // We load also tasks limited to a particular user $tasksrole=($mine ? $taskstatic->getUserRolesForProjectsOrTasks(0,$user,$projectstatic->id,0) : ''); print '<table class="noborder" width="100%">'; print '<tr class="liste_titre">'; print '<td>'.$langs->trans("Project").'</td>'; print '<td width="80">'.$langs->trans("RefTask").'</td>'; print '<td>'.$langs->trans("LabelTask").'</td>'; print '<td align="right">'.$langs->trans("Progress").'</td>'; print '<td align="right">'.$langs->trans("TimeSpent").'</td>'; print "</tr>\n"; // Show all lines in taskarray (recursive function to go down on tree) $j=0; $level=0; $nboftaskshown=PLines($j, 0, $tasksarray, $level, true, 1, $tasksrole, $projectsListId); print "</table>";
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'">'.$langs->trans("DoNotShowMyTasksOnly").'</a>'; //print ' - '; //print $langs->trans("ShowMyTaskOnly"); } else { //print $langs->trans("DoNotShowMyTaskOnly"); //print ' - '; print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'&mode=mine">'.$langs->trans("ShowMyTasksOnly").'</a>'; } print '</td></tr></table>'; // Get list of tasks in tasksarray and taskarrayfiltered // We need all tasks (even not limited to a user because a task to user // can have a parent that is not affected to him). $tasksarray=$task->getTasksArray(0, 0, $project->id, $socid, 0); // We load also tasks limited to a particular user $tasksrole=($_REQUEST["mode"]=='mine' ? $task->getUserRolesForProjectsOrTasks(0,$user,$project->id,0) : ''); //var_dump($tasksarray); //var_dump($tasksrole); print '<table class="noborder" width="100%">'; print '<tr class="liste_titre">'; if ($projectstatic->id) print '<td>'.$langs->trans("Project").'</td>'; print '<td width="80">'.$langs->trans("RefTask").'</td>'; print '<td>'.$langs->trans("LabelTask").'</td>'; print '<td align="right">'.$langs->trans("Progress").'</td>'; print '<td align="right">'.$langs->trans("TimeSpent").'</td>'; print "</tr>\n"; if (sizeof($tasksarray) > 0) {
/** * Return list of project and tasks * * @param int $selectedtask Pre-selected task * @param int $projectid Project id * @param string $htmlname Name of html select * @param int $modeproject 1 to restrict on projects owned by user * @param int $modetask 1 to restrict on tasks associated to user * @param int $mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists * @param int $useempty 0=Allow empty values * @param int $disablechildoftaskid 1=Disable task that are child of the provided task id * @return void */ function selectProjectTasks($selectedtask = '', $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0) { global $user, $langs; require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php'; //print $modeproject.'-'.$modetask; $task = new Task($this->db); $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode); if ($tasksarray) { print '<select class="flat" name="' . $htmlname . '">'; if ($useempty) { print '<option value="0"> </option>'; } $j = 0; $level = 0; $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid); print '</select>'; } else { print '<div class="warning">' . $langs->trans("NoProject") . '</div>'; } }
$title=$langs->trans("TimeSpent"); if ($mine) $title=$langs->trans("MyTimeSpent"); $usertoprocess = $user; $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertoprocess,0,1); // Return all project i have permission on. I want my tasks and some of my task may be on a public projet that is not my project if ($id) { $project->fetch($id); $project->fetch_thirdparty(); } $onlyopenedproject=1; // or -1 $tasksarray=$taskstatic->getTasksArray(0, 0, ($project->id?$project->id:0), $socid, 0, '', $onlyopenedproject); // We want to see all task of opened project i am allowed to see, not only mine. Later only mine will be editable later. $projectsrole=$taskstatic->getUserRolesForProjectsOrTasks($usertoprocess, 0, ($project->id?$project->id:0), 0, $onlyopenedproject); $tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0, $usertoprocess, ($project->id?$project->id:0), 0, $onlyopenedproject); //var_dump($tasksarray); //var_dump($projectsrole); //var_dump($taskrole); llxHeader("",$title,""); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num, '', 'title_project'); $param=($mode?'&mode='.$mode:''); // Show navigation bar $nav ="<a href=\"?year=".$prev_year."&month=".$prev_month."&day=".$prev_day.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
/** * Fonction generant le projet sur le disque * * @param Project $object Object project a generer * @param Translate $outputlangs Lang output object * @return int 1 if OK, <=0 if KO */ function write_file($object, $outputlangs) { global $user, $langs, $conf; if (!is_object($outputlangs)) { $outputlangs = $langs; } // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (!empty($conf->global->MAIN_USE_FPDF)) { $outputlangs->charset_output = 'ISO-8859-1'; } $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("projects"); if ($conf->projet->dir_output) { $nblignes = count($object->lines); $default_font_size = pdf_getPDFFontsize($outputlangs); $objectref = dol_sanitizeFileName($object->ref); $dir = $conf->projet->dir_output; if (!preg_match('/specimen/i', $objectref)) { $dir .= "/" . $objectref; } $file = $dir . "/" . $objectref . ".pdf"; if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } } if (file_exists($dir)) { $pdf = pdf_getInstance($this->format); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); // Complete object by loading several other informations $task = new Task($this->db); $tasksarray = $task->getTasksArray(0, 0, $object->id); $object->lines = $tasksarray; $nblignes = count($object->lines); $pdf->Open(); $pagenb = 0; $pdf->SetDrawColor(128, 128, 128); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("Project")); $pdf->SetCreator("Dolibarr " . DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Project")); if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) { $pdf->SetCompression(false); } $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right $pdf->SetAutoPageBreak(1, 0); // New page $pdf->AddPage(); $pagenb++; $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0, 0, 0); $tab_top = 50; $tab_height = 200; $tab_top_newpage = 40; $tab_height_newpage = 210; // Affiche notes if (!empty($object->note_public)) { $pdf->SetFont('', '', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($object->note_public), 0, 1); $nexY = $pdf->GetY(); $height_note = $nexY - ($tab_top - 2); // Rect prend une longueur en 3eme param $pdf->SetDrawColor(192, 192, 192); $pdf->Rect($this->marge_gauche, $tab_top - 3, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1); $tab_height = $tab_height - $height_note; $tab_top = $nexY + 6; } else { $height_note = 0; } $iniY = $tab_top + 7; $curY = $tab_top + 7; $nexY = $tab_top + 7; // Boucle sur les lignes for ($i = 0; $i < $nblignes; $i++) { $curY = $nexY; // Description of ligne $ref = $object->lines[$i]->ref; $libelleline = $object->lines[$i]->label; $progress = $object->lines[$i]->progress . '%'; $datestart = dol_print_date($object->lines[$i]->date_start, 'day'); $dateend = dol_print_date($object->lines[$i]->date_end, 'day'); $pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page $pdf->SetXY($this->posxref, $curY); $pdf->MultiCell(60, 3, $outputlangs->convToOutputCharset($ref), 0, 'L'); $pdf->SetXY($this->posxlabel, $curY); $pdf->MultiCell(108, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L'); $pdf->SetXY($this->posxprogress, $curY); $pdf->MultiCell(16, 3, $progress, 0, 'L'); $pdf->SetXY($this->posxdatestart, $curY); $pdf->MultiCell(20, 3, $datestart, 0, 'L'); $pdf->SetXY($this->posxdateend, $curY); $pdf->MultiCell(20, 3, $dateend, 0, 'L'); $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut $nexY = $pdf->GetY(); $nexY += 2; // Passe espace entre les lignes // Cherche nombre de lignes a venir pour savoir si place suffisante if ($i < $nblignes - 1 && empty($hidedesc)) { //on recupere la description du produit suivant $follow_descproduitservice = $object->lines[$i + 1]->desc; //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres) $nblineFollowDesc = dol_nboflines_bis($follow_descproduitservice, 52, $outputlangs->charset_output) * 4; } else { $nblineFollowDesc = 0; } if ($nexY + $nblineFollowDesc > $tab_top + $tab_height && $i < $nblignes - 1) { $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs); $this->_pagefoot($pdf, $object, $outputlangs); // New page $pdf->AddPage(); $pagenb++; $this->_pagehead($pdf, $object, 0, $outputlangs); $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0, 0, 0); $tab_top = $tab_top_newpage; $tab_height = $tab_height_newpage; $nexY = $tab_top + 7; } } // Show square $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); $bottomlasttab = $tab_top + $tab_height + 1; /* * Pied de page */ $this->_pagefoot($pdf, $object, $outputlangs); $pdf->AliasNbPages(); $pdf->Close(); $pdf->Output($file, 'F'); if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } return 1; // Pas d'erreur } else { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } } $this->error = $langs->transnoentities("ErrorConstantNotDefined", "LIVRAISON_OUTPUTDIR"); return 0; }
$form = new Form($db); $projectstatic = new Project($db); $project = new Project($db); $taskstatic = new Task($db); $title = $langs->trans("TimeSpent"); if ($mine) { $title = $langs->trans("MyTimeSpent"); } //$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1); $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1); // Return all project i have permission on. I want my tasks and some of my task may be on a public projet that is not my project if ($id) { $project->fetch($id); $project->societe->fetch($project->societe->id); } $tasksarray = $taskstatic->getTasksArray(0, 0, $project->id ? $project->id : $projectsListId, $socid, 0); // We want to see all task of project i am allowed to see, not only mine. Later only mine will be editable later. $projectsrole = $taskstatic->getUserRolesForProjectsOrTasks($user, 0, $project->id ? $project->id : $projectsListId, 0); $tasksrole = $taskstatic->getUserRolesForProjectsOrTasks(0, $user, $project->id ? $project->id : $projectsListId, 0); //var_dump($tasksarray); //var_dump($projectsrole); //var_dump($taskrole); llxHeader("", $title, ""); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num); // Filter on user /* dol_fiche_head(''); print '<table class="border" width="100%"><tr><td width="25%">'.$langs->trans("User").'</td>'; print '<td>'; if ($mine) print $user->getLoginUrl(1); print '</td>'; print '</tr></table>';
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num); // Show description of content if ($mine) print $langs->trans("MyProjectsDesc").'<br><br>'; else { if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'<br><br>'; else print $langs->trans("ProjectsPublicDesc").'<br><br>'; } // Get list of project id allowed to user $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1,$socid); // Get list of tasks in tasksarray and taskarrayfiltered // We need all tasks (even not limited to a user because a task to user can have a parent that is not affected to him). $tasksarray=$taskstatic->getTasksArray(0, 0, $projectstatic->id, $socid, 0, $search_product); // We load also tasks limited to a particular user $tasksrole=($mine ? $taskstatic->getUserRolesForProjectsOrTasks(0,$user,$projectstatic->id,0) : ''); print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; print '<input type="hidden" name="mode" value="'.GETPOST('mode').'">'; print '<table class="noborder" width="100%">'; print '<tr class="liste_titre">'; print '<td>'.$langs->trans("Project").'</td>'; print '<td width="80">'.$langs->trans("RefTask").'</td>'; print '<td>'.$langs->trans("LabelTask").'</td>'; print '<td align="center">'.$langs->trans("DateStart").'</td>'; print '<td align="center">'.$langs->trans("DateEnd").'</td>'; print '<td align="right">'.$langs->trans("Progress").'</td>';
/** * Shift project task date from current date to delta * * @param timestamp $old_project_dt_start old project start date * @return int 1 if OK or < 0 if KO */ function shiftTaskDate($old_project_dt_start) { global $user, $langs, $conf; $error = 0; $taskstatic = new Task($this->db); // Security check $socid = 0; if ($user->societe_id > 0) { $socid = $user->societe_id; } $tasksarray = $taskstatic->getTasksArray(0, 0, $this->id, $socid, 0); foreach ($tasksarray as $tasktoshiftdate) { $to_update = false; // Fetch only if update of date will be made if (!empty($tasktoshiftdate->date_start) || !empty($tasktoshiftdate->date_end)) { //dol_syslog(get_class($this)."::shiftTaskDate to_update", LOG_DEBUG); $to_update = true; $task = new Task($this->db); $result = $task->fetch($tasktoshiftdate->id); if (!$result) { $error++; $this->error .= $task->error; } } //print "$this->date_start + $tasktoshiftdate->date_start - $old_project_dt_start";exit; //Calcultate new task start date with difference between old proj start date and origin task start date if (!empty($tasktoshiftdate->date_start)) { $task->date_start = $this->date_start + ($tasktoshiftdate->date_start - $old_project_dt_start); } //Calcultate new task end date with difference between origin proj end date and origin task end date if (!empty($tasktoshiftdate->date_end)) { $task->date_end = $this->date_start + ($tasktoshiftdate->date_end - $old_project_dt_start); } if ($to_update) { $result = $task->update($user); if (!$result) { $error++; $this->error .= $task->error; } } } if ($error != 0) { return -1; } return $result; }
if ($action == 'validate') { print $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ValidateProject'), $langs->trans('ConfirmValidateProject'), 'confirm_validate', '', 0, 1); } // Confirmation close if ($action == 'close') { print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $object->id, $langs->trans("CloseAProject"), $langs->trans("ConfirmCloseAProject"), "confirm_close", '', '', 1); } // Confirmation reopen if ($action == 'reopen') { print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $object->id, $langs->trans("ReOpenAProject"), $langs->trans("ConfirmReOpenAProject"), "confirm_reopen", '', '', 1); } // Confirmation delete if ($action == 'delete') { $text = $langs->trans("ConfirmDeleteAProject"); $task = new Task($db); $taskarray = $task->getTasksArray(0, 0, $object->id, 0, 0); $nboftask = count($taskarray); if ($nboftask) { $text .= '<br>' . img_warning() . ' ' . $langs->trans("ThisWillAlsoRemoveTasks", $nboftask); } print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $object->id, $langs->trans("DeleteAProject"), $text, "confirm_delete", '', '', 1); } // Clone confirmation if ($action == 'clone') { $formquestion = array('text' => $langs->trans("ConfirmClone"), array('type' => 'checkbox', 'name' => 'clone_contacts', 'label' => $langs->trans("CloneContacts"), 'value' => true), array('type' => 'checkbox', 'name' => 'clone_tasks', 'label' => $langs->trans("CloneTasks"), 'value' => true), array('type' => 'checkbox', 'name' => 'move_date', 'label' => $langs->trans("CloneMoveDate"), 'value' => true), array('type' => 'checkbox', 'name' => 'clone_notes', 'label' => $langs->trans("CloneNotes"), 'value' => true), array('type' => 'checkbox', 'name' => 'clone_project_files', 'label' => $langs->trans("CloneProjectFiles"), 'value' => false), array('type' => 'checkbox', 'name' => 'clone_task_files', 'label' => $langs->trans("CloneTaskFiles"), 'value' => false)); print $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $object->id, $langs->trans("CloneProject"), $langs->trans("ConfirmCloneProject"), "confirm_clone", $formquestion, '', 1, 240); } print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">'; print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="id" value="' . $object->id . '">';
$title=$langs->trans("TimeSpent"); if ($mine) $title=$langs->trans("MyTimeSpent"); llxHeader("",$title,""); //$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1); $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1); // Return all project i have permission on. I want my tasks and some of my task may be on a public projet that is not my project if ($_GET["id"]) { $project->fetch($_GET["id"]); $project->societe->fetch($project->societe->id); } $tasksarray=$taskstatic->getTasksArray(0,0,($project->id?$project->id:$projectsListId),$socid,0); // We want to see all task of project i am allowed to see, not only mine. Later only mine will be editable later. $projectsrole=$taskstatic->getUserRolesForProjectsOrTasks($user,0,($project->id?$project->id:$projectsListId),0); $tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0,$user,($project->id?$project->id:$projectsListId),0); //var_dump($tasksarray); //var_dump($projectsrole); //var_dump($taskrole); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num); if ($mesg) print $mesg; print '<form name="addtime" method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="action" value="addtime">';