{"id":214,"date":"2011-04-12T15:12:04","date_gmt":"2011-04-12T20:12:04","guid":{"rendered":"http:\/\/xlinesoft.com\/blog\/?p=214"},"modified":"2011-08-17T11:13:32","modified_gmt":"2011-08-17T16:13:32","slug":"adding-gantt-chart-to-phprunnerasprunnerpro-app","status":"publish","type":"post","link":"https:\/\/xlinesoft.com\/blog\/2011\/04\/12\/adding-gantt-chart-to-phprunnerasprunnerpro-app\/","title":{"rendered":"Adding GANTT chart to PHPRunner\/ASPRunnerPro app"},"content":{"rendered":"<p><em>A special thank you to Fred Blau who provided the <a href=\"http:\/\/www.asprunner.com\/forums\/topic\/16717-gantt-chart-for-phprunner\/\">original jsgantt integration sample<\/a>.<\/em><\/p>\n<p>A Gantt chart is a type of bar chart that illustrates a project schedule. Gantt charts illustrate the start and finish dates of the tasks that belong to this project. Some Gantt charts also show the dependency relationships between activities (tasks). Gantt charts can be used to show current schedule status using percent-complete shadings and a vertical &#8220;TODAY&#8221; line.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/asprunner.com\/images\/gantt.jpg\" alt=\"Sample GANTT chart in PHPRunner\" \/><br \/>\n<!--more--><br \/>\nI&#8217;ll show you how to add to GANTT chart to your PHPRunner or ASPRunnerPro project. We are going to use free Javascript <a href=\"http:\/\/www.jsgantt.com\/\">jsgantt<\/a> component for this purpose. You can download PHP and ASP version of all required files at the end of this article.<\/p>\n<p>Jsgantt provides an API to add tasks. It can also load tasks from external XML file which we plan to use in our project.<\/p>\n<p>Sample XML file:<\/p>\n<pre lang=\"xml\"><project>\r\n<task>\r\n\t<pID>10<\/pID>\r\n\t<pName>WCF Changes<\/pName>\r\n\t<pStart><\/pStart>\r\n\t<pEnd><\/pEnd>\r\n\t<pColor>0000ff<\/pColor>\r\n\t<pLink><\/pLink>\r\n\t<pMile>0<\/pMile>\r\n\t<pRes><\/pRes>\r\n\t<pComp>0<\/pComp>\r\n\t<pGroup>1<\/pGroup>\r\n\t<pParent>0<\/pParent>\r\n\t<pOpen>1<\/pOpen>\r\n\t<pDepend \/>\r\n<\/task>\r\n<task>\r\n\t<pID>20<\/pID>\r\n\t<pName>Move to WCF from remoting<\/pName>\r\n\t<pStart>8\/11\/2008<\/pStart>\r\n\t<pEnd>8\/15\/2008<\/pEnd>\r\n\t<pColor>0000ff<\/pColor>\r\n\t<pLink><\/pLink>\r\n\t<pMile>0<\/pMile>\r\n\t<pRes>Rich<\/pRes>\r\n\t<pComp>10<\/pComp>\r\n\t<pGroup>0<\/pGroup>\r\n\t<pParent>10<\/pParent>\r\n\t<pOpen>1<\/pOpen>\r\n\t<pDepend><\/pDepend>\r\n<\/task>\r\n<task>\r\n\t<pID>30<\/pID>\r\n\t<pName>add Auditing<\/pName>\r\n\t<pStart>8\/19\/2008<\/pStart>\r\n\t<pEnd>8\/21\/2008<\/pEnd>\r\n\t<pColor>0000ff<\/pColor>\r\n\t<pLink><\/pLink>\r\n\t<pMile>0<\/pMile>\r\n\t<pRes>Mal<\/pRes>\r\n\t<pComp>50<\/pComp>\r\n\t<pGroup>0<\/pGroup>\r\n\t<pParent>10<\/pParent>\r\n\t<pOpen>1<\/pOpen>\r\n\t<pDepend>20<\/pDepend>\r\n<\/task>\r\n<\/project><\/pre>\n<p><strong>1.<\/strong> We are going to need two tables: tblProjects and tblTasks.<\/p>\n<p><strong>tblProject<\/strong> contains basic project description.<\/p>\n<pre lang=\"sql\">CREATE TABLE `tblProject` (\r\n`ProjectID` int(11) NOT NULL AUTO_INCREMENT,\r\n`ProjectName` varchar(40) DEFAULT NULL,\r\n`StartDate` datetime DEFAULT NULL,\r\n`EndDate` datetime DEFAULT NULL,\r\nPRIMARY KEY (`ProjectID`)\r\n) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;<\/pre>\n<p><strong>tblTasks<\/strong> contains detailed description of each task. Some fields in this table are optional and not being used in our example.<\/p>\n<pre lang=\"sql\">CREATE TABLE `tblTasks` (\r\n`TaskID` int(11) NOT NULL AUTO_INCREMENT,\r\n`ProjectID` int(11) DEFAULT NULL,\r\n`ParentID` int(11) DEFAULT '0',\r\n`TaskName` varchar(60) DEFAULT NULL,\r\n`TaskNumber` varchar(10) DEFAULT NULL,\r\n`AssignedTo` varchar(30) DEFAULT NULL,\r\n`SchedStart` datetime DEFAULT NULL,\r\n`SchedEnd` datetime DEFAULT NULL,\r\n`ActualStart` datetime DEFAULT NULL,\r\n`ActualEnd` datetime DEFAULT NULL,\r\n`EstHours` float DEFAULT NULL,\r\n`TaskStatus` int(11) DEFAULT NULL,\r\n`PercentComplete` tinyint(4) DEFAULT NULL,\r\n`Notes` longtext,\r\n`IsGroup` tinyint(4) DEFAULT '0',\r\n`BarColorHex` varchar(6) DEFAULT '0000FF',\r\n`DependentOn` varchar(10) DEFAULT NULL,\r\nPRIMARY KEY (`TaskID`)\r\n) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;<\/pre>\n<p><strong>2.<\/strong> Add both tables to the project and link them as Master-Details using ProjectID as a link field in both tables. Check off &#8216;Display child records on View page&#8217; option.<\/p>\n<p>We also choose ProjectID as a key column of tblProjects table.<\/p>\n<p><strong>3. <\/strong>In Visual Editor proceed to the page where you want to display the GANTT chart. In our example we add GANTT chart to the tblProjects view page. Right-click where you want to add the chart and choose &#8216;Insert PHP code snippet&#8217;. Paste the following code there:<\/p>\n<pre lang=\"php\">$value =  \"Gantt<BR>\";\r\n\r\n$myFile = \"gantt.php?ProjectID=\".$_REQUEST[\"editid1\"];\r\n\/\/$myFile=\"gantt.xml\";\r\n\r\n$value = $value.\"<link rel='stylesheet' type='text\/css' href='jsgantt.css'\/>\";\r\n$value = $value.\"<script language='javascript' src='jsgantt.js'><\/script>\";\r\n\r\n$value = $value.\"<div style='position:relative' class='gantt' id='GanttChartDIV'><\/div>\\n\";\r\n$value = $value.\"<script  language='javascript'>\\n\";\r\n\r\n\r\n$value = $value.\"var g = new JSGantt.GanttChart('g',document.getElementById('GanttChartDIV'), 'week');\\n\";\r\n\r\n$value = $value.\"g.setShowRes(1);\\n\";\r\n$value = $value.\"g.setShowDur(1);\\n\";\r\n$value = $value.\"g.setShowComp(1);\\n\";\r\n$value = $value.\"g.setCaptionType('Resource');\\n\";\r\n\r\n$value = $value.\"if( g ) {\\n\";\r\n\r\n$value = $value.\"JSGantt.parseXML('\".$myFile.\"',g);\\n\";\r\n\r\n$value = $value.\"}\";\r\n$value = $value.\"else {\";\r\n$value = $value.\" alert('not defined');\";\r\n$value = $value.\" }\";\r\n\r\n$value = $value.\"<\/script>\";\r\n\r\necho $value;<\/pre>\n<p>In this code snippet we include jsgantt.js and jsgantt.css files, create JSGantt object and parse XML file provided by gantt.php file. Note that we pass the current ProjectID as a parameter to gantt.php (&#8220;gantt.php?ProjectID=&#8221;.$_REQUEST[&#8220;editid1&#8221;]);<\/p>\n<p><strong>4.<\/strong> In the output directory create a new file named gantt.php and paste the following code there:<\/p>\n<pre lang=\"php\"><?php\r\ninclude(\"include\/dbcommon.php\");\r\n$out=\"<project>\\n\";\r\n\r\n$sql = \"select * from tblTasks where ProjectID=\".$_REQUEST[\"ProjectID\"].\" Order by TaskNumber\"; \r\n\r\n$rs = db_query($sql,$conn); \r\n\r\nwhile($rdata=db_fetch_array($rs))\r\n{\r\n\r\n$out.=\"<task>\\n\";\r\n$out.=\"<pID>\".$rdata[\"TaskNumber\"].\"<\/pID>\\n\";\r\n$out.=\"<pName>\".$rdata[\"TaskName\"].\"<\/pName>\\n\";\r\n\r\nif ($rdata[\"SchedStart\"] == \"\")\r\n{\r\n$StartDate = \"\";\r\n}\r\nelse\r\n{ \r\n$StartDate = date('m\/d\/Y',strtotime($rdata[\"SchedStart\"]));\r\n}\r\n$out.=\"<pStart>\".$StartDate.\"<\/pStart>\\n\";\r\n\r\nif ($rdata[\"SchedEnd\"] == \"\")\r\n{\r\n$EndDate = \"\";\r\n}\r\nelse\r\n{ \r\n$EndDate = date('m\/d\/Y',strtotime($rdata[\"SchedEnd\"]));\r\n}\r\n$out.=\"<pEnd>\".$EndDate.\"<\/pEnd>\\n\";\r\n$out.=\"<pColor>\".$rdata[\"BarColorHex\"].\"<\/pColor>\\n\";\r\n$out.=\"<pLink><\/pLink>\\n\";\r\n$out.=\"<pMile>0<\/pMile>\\n\";\r\n$out.=\"<pRes>\".$rdata[\"AssignedTo\"].\"<\/pRes>\\n\";\r\n$out.=\"<pComp>\".$rdata[\"PercentComplete\"].\"<\/pComp>\\n\";\r\n$out.=\"<pGroup>\".$rdata[\"IsGroup\"].\"<\/pGroup>\\n\";\r\n$out.=\"<pParent>\".$rdata[\"ParentID\"].\"<\/pParent>\\n\";\r\n$out.=\"<pOpen>1<\/pOpen>\\n\";\r\n$out.=\"<pDepend>\".$rdata[\"DependentOn\"].\"<\/pDepend>\\n\";\r\n$out.=\"<pCaption><\/pCaption>\\n\";\r\n$out.=\"<\/task>\\n\";\r\n}\r\n$out.=\"<\/project>\";\r\n\r\necho $out;\r\n\r\n?><\/pre>\n<p>Make sure to amend table and field names if your database structure is different.<\/p>\n<p>Now build your project and proceed to tblprojects view page. If you done everything right you going to see a GANTT chart. Here is the <a href=\"http:\/\/demo.asprunner.net\/volinrok_yahoo_com\/gantt\/tblproject_view.php?editid1=2\">live demo page<\/a> just in case.<\/p>\n<p>Enjoy!<\/p>\n<p>Download files mentioned in this article: <a href=\"http:\/\/asprunner.com\/images\/gantt.php.zip\">PHP version<\/a> <a href=\"http:\/\/asprunner.com\/images\/gantt.asp.zip\">ASP version<\/a>.<\/p>\n<p>More info on jsgantt:<br \/>\n<a href=\"http:\/\/www.jsgantt.com\/docs\/index.html\">Documentation<\/a><br \/>\n<a href=\"http:\/\/www.jsgantt.com\/#tExamples\">Examples<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A special thank you to Fred Blau who provided the original jsgantt integration sample. A Gantt chart is a type of bar chart that illustrates a project schedule. Gantt charts illustrate the start and finish dates of the tasks that belong to this project. Some Gantt charts also show the dependency relationships between activities (tasks). Gantt charts can be used to show current schedule status using percent-complete shadings and a vertical &#8220;TODAY&#8221; line.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,8],"tags":[],"class_list":["post-214","post","type-post","status-publish","format-standard","hentry","category-php-category","category-php-code-generator","category-tutorials"],"_links":{"self":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/comments?post=214"}],"version-history":[{"count":13,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/214\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/214\/revisions\/223"}],"wp:attachment":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/media?parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/categories?post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/tags?post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}