Pour Tsmr. Premier résultat de mon travail.
Bon je pense qu'il faut faire pas mal de tests mais cela à l'air de fonctionner (chez moi). Donc sur l'onglet "export" il n'y a plus qu'un lien : "Export PDF du projet" Et le PDF généré contient (dernière page) le Gantt du projet. Malheureusement je n'ai pas trouvé comment repasser en paysage lors du changement de page, donc on reste en portrait. On en reparle à l'occasion... A+ P.S. je serais déconnecté à partir de Vendredi soir pour 15 jours...
diff -ur projet.orig/front/plugin_projet.export.php projet/front/plugin_projet.export.php --- projet.orig/front/plugin_projet.export.php 2007-07-26 15:45:59.000000000 +0200 +++ projet/front/plugin_projet.export.php 2007-07-26 19:08:32.000000000 +0200 @@ -42,30 +42,6 @@ plugin_projet_checkRight("projet","r"); -if ($tab["type"]=="G"){ +plugin_projet_generatepdf($tab["ID"]); - //plugin_projet_gantt($tab["ID"],1); - $image = GLPI_PLUGIN_DOC_DIR."/projet/gantt.png"; - $size = GetImageSize($image); - $dst_w='700'; - $dst_h='500'; - $src_w = $size[0]; - $src_h = $size[1]; - // Teste les dimensions tenant dans la zone - $test_h = round(($dst_w / $src_w) * $src_h); - $test_w = round(($dst_h / $src_h) * $src_w); - // Si Height final non précisé (0) - if(!$dst_h) $dst_h = $test_h; - // Sinon si Width final non précisé (0) - elseif(!$dst_w) $dst_w = $test_w; - // Sinon teste quel redimensionnement tient dans la zone - elseif($test_h>$dst_h) $dst_w = $test_w; - else $dst_h = $test_h; - - plugin_projet_generate_gantt_pdf($tab["ID"],$dst_h,$dst_w); -} -else - - plugin_projet_generatepdf($tab["ID"]); - -?> +?> diff -ur projet.orig/inc/plugin_projet.functions_export.php projet/inc/plugin_projet.functions_export.php --- projet.orig/inc/plugin_projet.functions_export.php 2007-07-26 15:45:59.000000000 +0200 +++ projet/inc/plugin_projet.functions_export.php 2007-07-26 19:55:13.000000000 +0200 @@ -41,14 +41,19 @@ echo "<tr>"; $plugin_projet=new plugin_projet(); $plugin_projet->getFromDB($ID); +/* if ($plugin_projet->fields["show_gantt"]!=0){ - echo "<td class='tab_bg_2' align='center'>"; - echo "<a href=\"plugin_projet.export.php?type=G&ID=".$ID."\">".$LANGPROJET["project"][59]."</a>"; - echo " <img src='".$CFG_GLPI["root_doc"]."/pics/aide.png' alt=\"\" onmouseout=\"setdisplay(getElementById('commentsup'),'none')\" onmouseover=\"setdisplay(getElementById('commentsup'),'block')\">"; + echo "<td class='tab_bg_2' align='center'>"; + // PDF Export of Gantt + echo "<a href=\"plugin_projet.export.php?type=G&ID=".$ID."\">".$LANGPROJET["project"][59]."</a>"; + echo " <img src='".$CFG_GLPI["root_doc"]."/pics/aide.png' alt=\"\" onmouseout=\"setdisplay(getElementById('commentsup'),'none')\" onmouseover=\"setdisplay(getElementById('commentsup'),'block')\">"; + + // Thanks to reload Gantt graph before exporting it echo "<span class='over_link' id='commentsup'>".$LANGPROJET["project"][60]."</span>"; - echo "</td>"; + echo "</td>"; } - echo "<td class='tab_bg_2' align='center'>"; +*/ echo "<td class='tab_bg_2' align='center'>"; + // PDF Export of the project echo "<a href=\"plugin_projet.export.php?ID=".$ID."\">".$LANGPROJET["project"][61]."</a>"; echo "</td>"; echo "</tr>"; @@ -56,27 +61,6 @@ echo "</table></div></form>"; } -function plugin_projet_redimage($img_src,$dst_w,$dst_h) { - // Lit les dimensions de l'image - $size = GetImageSize($img_src); - $src_w = $size[0]; $src_h = $size[1]; - // Teste les dimensions tenant dans la zone - $test_h = round(($dst_w / $src_w) * $src_h); - $test_w = round(($dst_h / $src_h) * $src_w); - // Si Height final non précisé (0) - if(!$dst_h) $dst_h = $test_h; - // Sinon si Width final non précisé (0) - elseif(!$dst_w) $dst_w = $test_w; - // Sinon teste quel redimensionnement tient dans la zone - elseif($test_h>$dst_h) $dst_w = $test_w; - else $dst_h = $test_h; - - // Affiche les dimensions optimales - return $H=$dst_h; - return $W=$dst_w; -} - - function plugin_projet_generatepdf($project){ GLOBAL $LANG, $LANGPROJET,$CFG_GLPI, $PDF,$DB,$LINK_ID_TABLE; @@ -1970,61 +1954,55 @@ } } - + + plugin_projet_generate_gantt_pdf($PDF, $name, $project); + $PDF->addInfo('Author', html_clean(utf8_decode(getUserName($_SESSION["glpiID"])))); - - /* - //if(stristr($_SERVER['HTTP_USER_AGENT'],"IE")){ - $fileName=$name.".pdf"; - header("Pragma: public"); - header("Expires: 0"); - header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); - header("Cache-Control: private",false); - header("Content-Type: application/octet-stream"); - header("Content-Transfer-Encoding: binary"); - header("Content-Disposition: attachment; filename=\"".$fileName."\";"); - echo $PDF->output(); - /*} else {*/ + $PDF->ezstream(); - //} } - - -function plugin_projet_generate_gantt_pdf($project,$height,$width){ - - GLOBAL $LANG, $LANGPROJET,$CFG_GLPI, $PDF; - $plugin_projet = new plugin_projet(); - $plugin_projet->getFromDB($project); - $name=utf8_decode($plugin_projet->fields["name"]); - - $PDF =new Cezpdf(); - $PDF->Cezpdf('a4', 'landscape'); + +function plugin_projet_generate_gantt_pdf(&$PDF, $name, $project){ + + global $LANGPROJET,$DB,$LANG,$CFG_GLPI,$gtitle,$gdata,$nbgdata,$gconst,$nbgonst,$gbegin_date,$gend_date; + + $nbgdata=0;$nbgonst=0; + plugin_projet_gantt_project($project,''); + + if (!empty($gbegin_date)&&!empty($gend_date)) { + $gtitle=$gtitle."<DateBeg> / <DateEnd>"; + $gbegin_date=date("Y",$gbegin_date)."-".date("m",$gbegin_date)."-".date("d",$gbegin_date); + $gend_date=date("Y",$gend_date)."-".date("m",$gend_date)."-".date("d",$gend_date); + } + $ImgName=writeGantt($gtitle,$gdata,$gconst,$gbegin_date,$gend_date,0); + + $image = GLPI_PLUGIN_DOC_DIR."/projet/".$ImgName; + $size = GetImageSize($image); + $dst_w='500'; + $dst_h='500'; + $src_w = $size[0]; + $src_h = $size[1]; + // Teste les dimensions tenant dans la zone + $test_h = round(($dst_w / $src_w) * $src_h); + $test_w = round(($dst_h / $src_h) * $src_w); + + // Teste quel redimensionnement tient dans la zone + if ($test_h > $dst_h) { + $pos_w = 50 + ($dst_w - $test_w) /2; + $dst_w = $test_w; + } + else { + $pos_w = 50; + $dst_h = $test_h; + } + + $PDF->ezNewPage(); + $PDF->selectFont(GLPI_ROOT.'/lib/ezpdf/fonts/Helvetica.afm'); - - $PDF->ezText($name." - ".utf8_decode($LANGPROJET["title"][5]),15,array('justification'=>'center')); - - $PDF->ezSetDy(-30); - - if ($height > '499') - $PDF->addPngFromFile('../../../files/_plugins/projet/gantt.png',15,0,$width,$height); - else - $PDF->addPngFromFile('../../../files/_plugins/projet/gantt.png',15,70,$width,$height); - /* - //if(stristr($_SERVER['HTTP_USER_AGENT'],"IE")){ - $fileName="Gantt ".$name.".pdf"; - header("Pragma: public"); - header("Expires: 0"); - header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); - header("Cache-Control: private",false); - header("Content-Type: application/octet-stream"); - header("Content-Transfer-Encoding: binary"); - header("Content-Disposition: attachment; filename=\"".$fileName."\";"); - echo $PDF->output(); - /*} else {*/ - $PDF->ezstream(); - //} - + $PDF->ezText(utf8_decode($name." - ".$LANGPROJET["title"][5]),15,array('justification'=>'center')); + + $PDF->addPngFromFile($image,$pos_w,600,$dst_w,$dst_h); + unlink($image); } - -?> \ Pas de fin de ligne à la fin du fichier. +?> diff -ur projet.orig/inc/plugin_projet.functions_gantt.php projet/inc/plugin_projet.functions_gantt.php --- projet.orig/inc/plugin_projet.functions_gantt.php 2007-07-26 15:45:59.000000000 +0200 +++ projet/inc/plugin_projet.functions_gantt.php 2007-07-26 19:21:19.000000000 +0200 @@ -66,7 +66,9 @@ $gbegin_date=date("Y",$gbegin_date)."-".date("m",$gbegin_date)."-".date("d",$gbegin_date); $gend_date=date("Y",$gend_date)."-".date("m",$gend_date)."-".date("d",$gend_date); } - writeGantt($gtitle,$gdata,$gconst,$gbegin_date,$gend_date,$location); + + $ImgName=writeGantt($gtitle,$gdata,$gconst,$gbegin_date,$gend_date,$location); + echo "<img src='".$CFG_GLPI["root_doc"]."/front/pluginimage.send.php?plugin=projet&name=".$ImgName."&clean=1' alt='Gantt' />";//afficher graphique echo"</div>"; echo "</td></tr></table></div>"; @@ -85,7 +87,8 @@ $gbegin_date=date("Y",$gbegin_date)."-".date("m",$gbegin_date)."-".date("d",$gbegin_date); $gend_date=date("Y",$gend_date)."-".date("m",$gend_date)."-".date("d",$gend_date); } - writeGantt($gtitle,$gdata,$gconst,$gbegin_date,$gend_date,$location); + $ImgName=writeGantt($gtitle,$gdata,$gconst,$gbegin_date,$gend_date,$location); + echo "<img src='".$CFG_GLPI["root_doc"]."/front/pluginimage.send.php?plugin=projet&name=".$ImgName."&clean=1' alt='Gantt' />";//afficher graphique echo"</div>"; echo "</td></tr></table></div>"; @@ -334,7 +337,8 @@ } function writeGantt($title,$gdata,$gconst,$gantt_begin_date,$gantt_end_date,$location){ - + + //error_log("GANTT : title=$title, gantt_begin_date=$gantt_begin_date, gantt_end_date=$gantt_end_date, location=$location"); global $CFG_GLPI,$LANGPROJET; require (GLPI_ROOT."/plugins/projet/inc/gantt.class.php"); @@ -355,13 +359,13 @@ $definitions['groups']['group'][$gdata[$i][1]]['bg_color'] = array($gdata[$i][6][0],$gdata[$i][6][1],$gdata[$i][6][2]); $definitions['groups']['group'][$gdata[$i][1]]['start'] = mktime(0,0,0,substr($gdata[$i][3], 5, 2),substr($gdata[$i][3], 8, 2),substr($gdata[$i][3], 0, 4)); $definitions['groups']['group'][$gdata[$i][1]]['end'] = mktime(0,0,0,substr($gdata[$i][4], 5, 2),substr($gdata[$i][4], 8, 2),substr($gdata[$i][4], 0, 4)); - error_log ("Groupe " . $gdata[$i][2] . " du " . $gdata[$i][3] . " au " . $gdata[$i][4]); + //error_log ("Groupe " . $gdata[$i][2] . " du " . $gdata[$i][3] . " au " . $gdata[$i][4]); if (isset($gdata[$i][5])) $definitions['groups']['group'][$gdata[$i][1]]['progress'] = $gdata[$i][5]; } elseif ($gdata[$i][0]=='phase') { // Tache $definitions['groups']['group'][$gdata[$i][2]]['phase'][$gdata[$i][1]] = $gdata[$i][1]; $definitions['planned']['phase'][$gdata[$i][1]]['name'] = str_sans_accent((strlen($gdata[$i][3])>60) ? substr($gdata[$i][3],0,58)."..." : $gdata[$i][3]); - error_log ("Tache " . $gdata[$i][2] . " du " . $gdata[$i][4] . " au " . $gdata[$i][5]); + //error_log ("Tache " . $gdata[$i][2] . " du " . $gdata[$i][4] . " au " . $gdata[$i][5]); if ($gdata[$i][7]=='1') { $definitions['planned']['phase'][$gdata[$i][1]]['start'] = mktime(0,0,0,substr($gdata[$i][4], 5, 2),substr($gdata[$i][4], 8, 2),substr($gdata[$i][4], 0, 4)); $definitions['planned']['phase'][$gdata[$i][1]]['end'] = mktime(0,0,0,substr($gdata[$i][5], 5, 2),substr($gdata[$i][5], 8, 2),substr($gdata[$i][5], 0, 4)); @@ -390,9 +394,8 @@ $definitions['image']['filename'] = GLPI_PLUGIN_DOC_DIR."/projet/".$ImgName; new gantt($definitions); - - echo "<img src='".$CFG_GLPI["root_doc"]."/front/pluginimage.send.php?plugin=projet&name=".basename($ImgName)."&clean=1' alt='Gantt' />";//afficher graphique - + + return $ImgName; } @@ -403,4 +406,4 @@ return $chaine; } -?> \ Pas de fin de ligne à la fin du fichier. +?>
_______________________________________________ Glpi-dev mailing list Glpi-dev@gna.org https://mail.gna.org/listinfo/glpi-dev