/**
  * Copy a project
  * by: Daniel Tlach <*****@*****.**>,
  * Philipp Kiszka <*****@*****.**>
  *
  * @param int $id ID of project to copy
  * @return int $insid New project's ID
  */
 function makecopy($id)
 {
     // copy project
     $q = mysql_query("INSERT INTO projekte (`name`, `desc`, `end`, `start`, `status`, `budget`) SELECT `name`, `desc`, `end`, `start`, `status`, `budget` FROM projekte WHERE ID = " . (int) $id);
     $insid = mysql_insert_id();
     $uid = $_SESSION['userid'];
     $this->assign($uid, $insid);
     $milesobj = new milestone();
     $objtasklist = new tasklist();
     $objtask = new task();
     if ($q) {
         $pname = $this->getProject($insid);
         $name = $pname["name"] . " Copy";
         mysql_query("UPDATE projekte SET `name` = '{$name}' WHERE ID = " . $insid . " LIMIT 1");
         // now copy the milestones
         $miles = $milesobj->getAllProjectMilestones($id);
         if (!empty($miles)) {
             // go through the milestones
             foreach ($miles as $ms) {
                 // copy milestone
                 $msid = $milesobj->add($insid, $ms["name"], $ms["desc"], $ms["end"], 1);
                 // get all tasklists for milestone
                 $qb = mysql_query("SELECT * FROM tasklist WHERE project = {$id} AND milestone = {$ms['ID']}");
                 if ($qb) {
                     // go through the tasklists
                     while ($tl = mysql_fetch_array($qb)) {
                         // copy tasklist
                         $tlid = $objtasklist->add_liste($insid, $tl["name"], $tl["desc"], 0, $msid);
                         // get tasks for the tasklist
                         $tasks = $objtasklist->getTasksFromList($tl["ID"]);
                         if (!empty($tasks)) {
                             foreach ($tasks as $task) {
                                 $taskobj->add($task["end"], $task["title"], $task["text"], $tlid, $uid, $insid);
                             }
                             // tasks END
                         }
                     }
                     // tasklists END
                 }
             }
             // milestones END
         }
         // get all tasklists and tasks that do not belong to a milestone
         $qb = mysql_query("SELECT * FROM tasklist WHERE project = {$id} AND milestone = 0");
         if ($qb) {
             // go through the tasklists
             while ($tl = mysql_fetch_array($qb)) {
                 // copy tasklist
                 $tlid = $objtasklist->add_liste($insid, $tl["name"], $tl["desc"], 0, $msid);
                 // get tasks for the tasklist
                 $tasks = $objtasklist->getTasksFromList($tl["ID"]);
                 if (!empty($tasks)) {
                     foreach ($tasks as $task) {
                         $taskobj->add($task["end"], $task["title"], $task["text"], $tlid, $uid, $insid);
                     }
                     // tasks END
                 }
             }
             // tasklists END
         }
         mkdir(CL_ROOT . "/files/" . CL_CONFIG . "/{$insid}/", 0777);
         $this->mylog->add($name, 'projekt', 1, $insid);
         return $insid;
     } else {
         return false;
     }
 }
 private function addTasks($project_id, $milestonesHash, $taskListArray)
 {
     $addTaskList = new tasklist();
     $addTask = new task();
     foreach ($taskListArray->{'todo-list'} as $taskList) {
         $name = $taskList->{'name'};
         if (isset($milestonesHash)) {
             $mid = $taskListArray->{'milestone-id'};
             if (strlen($mid) > 0) {
                 $milestoneId = $milestonesHash["{$mid}"];
             } else {
                 $milestoneId = 0;
             }
         }
         $desc = $taskListArray->{'description'};
         $access = 0;
         $tasklistId = $addTaskList->add_liste($project_id, $name, $desc, $access, $milestoneId);
         foreach ($taskList->{'todo-items'}->{'todo-item'} as $todo) {
             //$end = strtotime("+1 month", strtotime($todo->{'created-on'}));
             $end = strtotime($todo->{'created-on'} . " +1month");
             $title = $todo->{'name'};
             $text = $todo->{'content'};
             if (!$title) {
                 $title = $text;
             }
             $uid = $todo->{'responsible-party-id'};
             $assigned = $this->peopleHash["{$uid}"];
             //class.task::add() needed to be modified to pass a timestamp directly.
             if ($addTask->add($end, $title, $text, $tasklistId, $assigned, $project_id)) {
                 ++$this->taskCount;
             }
         }
     }
 }
Beispiel #3
0
 function addProjectFromExcel($inputFileName)
 {
     include "./include/PHPExcel/IOFactory.php";
     $objReader = new PHPExcel_Reader_Excel2007();
     $objPHPExcel = $objReader->load($inputFileName);
     $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
     $limiter = "#";
     $projectObj = new project();
     $userObj = new user();
     $milestoneObj = new milestone();
     $tasklistObj = new tasklist();
     $taskObj = new task();
     $companyObj = new company();
     $projectname = $sheetData[2]["A"];
     $projectdescription = $sheetData[3]["A"];
     $projectdue = $sheetData[4]["A"];
     $projectbudget = $sheetData[5]["A"];
     $projectcustomer = $sheetData[6]["A"];
     $projectpriority = $sheetData[7]["A"];
     $projectId = $projectObj->add($projectname, $projectdescription, $projectdue, $projectbudget, $projectpriority);
     $customer = $companyObj->getCompanyByName($projectcustomer);
     if ($customer) {
         $companyObj->assign($customer["ID"], $projectId);
     }
     // USERS
     for ($i = 1; $i < count($sheetData); $i++) {
         $username = $sheetData[$i]["B"];
         if ($username) {
             $user = $userObj->getUserByName($username);
             if ($user) {
                 $projectObj->assign($user["ID"], $projectId);
             }
         } else {
             break;
         }
     }
     // MILESTONES
     for ($i = 1; $i < count($sheetData); $i++) {
         $milestone = explode($limiter, $sheetData[$i]["C"]);
         if ($milestone) {
             $milestoneObj->add($projectId, $milestone[0], $milestone[1], $milestone[2], $milestone[3]);
         } else {
             break;
         }
     }
     // TASK LISTS
     for ($i = 1; $i < count($sheetData); $i++) {
         $tasklist = explode($limiter, $sheetData[$i]["D"]);
         if ($tasklist) {
             if ($tasklist[3]) {
                 $milestone = $milestoneObj->getMilestoneByName($tasklist[3]);
                 if ($milestone) {
                     $tasklistObj->add_liste($projectId, $tasklist[0], $tasklist[1], $tasklist[2], 0, $milestone["ID"]);
                 }
             } else {
                 $tasklistObj->add_liste($projectId, $tasklist[0], $tasklist[1], $tasklist[2]);
             }
         } else {
             break;
         }
     }
     // TASKS
     for ($i = 1; $i < count($sheetData); $i++) {
         $task = explode($limiter, $sheetData[$i]["E"]);
         if ($task) {
             $tasklist = $tasklistObj->getTasklistByName($task[5]);
             $taskid = $taskObj->add($task[2], $task[3], $task[0], $task[4], $tasklist["ID"], $projectId, $task[6], $task[7]);
             $user = $userObj->getUserByName($task[1]);
             if ($taskid) {
                 if ($user) {
                     $taskObj->assign($taskid, $user["ID"]);
                 }
             }
         } else {
             break;
         }
     }
     return $projectId;
 }