3 * Copyright (C) 2009 Alain Peyrat, Alcatel-Lucent
5 * This file is part of FusionForge.
7 * FusionForge is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License,
10 * or (at your option) any later version.
12 * FusionForge is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with FusionForge; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * Standard Alcatel-Lucent disclaimer for contributing to open source
26 * "The provided file ("Contribution") has not been tested and/or
27 * validated for release as or in products, combinations with products or
28 * other commercial use. Any use of the Contribution is entirely made at
29 * the user's own responsibility and the user can not rely on any features,
30 * functionalities or performances Alcatel-Lucent has attributed to the
33 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
34 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
36 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
37 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
38 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
39 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
41 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
45 require_once $gfcommon.'pm/import_utils.php';
47 $input_file = getUploadedFile('userfile');
48 if (is_uploaded_file($input_file['tmp_name'])) {
49 $handle = fopen($input_file['tmp_name'], 'r');
52 // Detect separator & if headers are present or not.
54 $values = fgetcsv($handle, 4096, $sep);
55 if (count($values) == 1) {
58 $values = fgetcsv($handle, 4096, $sep);
60 $headers = (in_array('project_task_id', $values) && in_array('title', $values));
66 // Headers are given in the file (first line).
67 $headers = array_flip(fgetcsv($handle, 4096, $sep));
68 while (($values = fgetcsv($handle, 4096, $sep)) !== false) {
70 foreach($headers as $name => $id) {
71 if ($name == 'project_task_id') $name = 'id';
72 if ($name == 'title') $name = 'name';
73 $task[$name] = $values[$id];
78 // Original code (default format, no headers)
79 while (($cols = fgetcsv($handle, 4096, $sep)) !== false) {
82 for ($i=12;$i<17;$i++) {
83 if (trim($cols[$i]) != '') {
84 $resources[] = array('user_name'=>$cols[$i]);
88 $dependentOn = array();
90 for ($i=17;$i<30;$i=$i+3) {
91 if (trim($cols[$i]) != '') {
92 $dependentOn[] = array('task_id'=>$cols[$i], 'msproj_id'=>$cols[$i+1], 'task_name'=>'', 'link_type'=>$cols[$i+2]);
96 $tasks[] = array('id'=>$cols[0],
97 'msproj_id'=>$cols[1],
98 'parent_id'=>$cols[2],
99 'parent_msproj_id'=>$cols[3],
101 'duration'=>$cols[5],
103 'start_date'=>$cols[7],
104 'end_date'=>$cols[8],
105 'percent_complete'=>$cols[9],
106 'priority'=>$cols[10],
107 'resources'=>$resources,
108 'dependenton'=>$dependentOn,
112 $res=&pm_import_tasks($group_project_id, $tasks);
114 if ($res['success']) {
115 $feedback .= 'Import Was Successful';
117 $feedback .= $res['errormessage'];